src/Tools/qed.cc
author lcp
Fri, 13 Jan 1995 02:02:00 +0100
changeset 863 67692db44c70
parent 813 4a266c3d4cc0
child 902 cc80f53b28c6
permissions -rw-r--r--
empty_def typo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
813
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     1
// Little utility to convert result() -> qed ... in Isabelle's files
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     2
// Written in 1994 by Carsten Clasohm (clasohm@informatik.tu-muenchen.de)
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     3
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     4
#define LIN_LEN   1000		// maximal length of lines in sourcefile
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     5
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     6
#include <iostream.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     7
#include <fstream.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     8
#include <string.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
     9
#include <assert.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    10
#include <stdio.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    11
#include <unistd.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    12
#include <ctype.h>
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    13
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    14
main(int argc, char *argv[])
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    15
{
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    16
    char l[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    17
    int lines = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    18
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    19
    // Open input and output files
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    20
    ifstream in(argv[1]);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    21
    ofstream out(argv[2]);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    22
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    23
    if (in.bad() || out.bad())
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    24
    {
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    25
        cerr << "qed version 1.00, Written in 1994 by Carsten Clasohm"
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    26
                "(clasohm@informatik.tu-muenchen.de)\n\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    27
	cerr << "Usage: qed <infile> <outfile>\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    28
	exit(1);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    29
    }
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    30
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    31
#ifdef DEBUG
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    32
    cerr << "Processing file " << argv[1] << '\n';
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    33
#endif
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    34
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    35
    // Process each line separatly
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    36
    in.getline(l, LIN_LEN);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    37
    while (!in.eof())
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    38
    {
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    39
	char *rPos;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    40
	char *valPos;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    41
	char *eqPos;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    42
	char *tmp;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    43
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    44
	if ((rPos = strstr(l, "result()")) && (!isalpha(*(rPos-1)))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    45
	    && (valPos = strstr(l, "val ")) && (eqPos = strstr(l, "=")))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    46
	{                            // does line contain "result()" and "val"?
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    47
	    char name[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    48
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    49
	    assert(eqPos-(valPos+4) > 0);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    50
	    strncpy(name, valPos+4, eqPos-(valPos+4));
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    51
	    name[eqPos-(valPos+4)] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    52
	    if (!isalpha(name[eqPos-(valPos+4)-1]))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    53
	        name[eqPos-(valPos+4)-1] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    54
#ifdef DEBUG
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    55
	    cerr << "Found result: \"" << name << "\"\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    56
#endif
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    57
	    char prefix[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    58
	    char arg[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    59
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    60
	    if ((rPos - eqPos < 5) && (rPos == strstr(l, "result();")))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    61
	    {                                              // replace by "qed"?
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    62
		strncpy(prefix, l, valPos-l);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    63
		prefix[valPos-l] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    64
		out << prefix << "qed \"" << name << "\";" << '\n';
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    65
	    }
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    66
	    else				         // replace by bind_thm
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    67
	    {                                           
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    68
		int d = (*(eqPos+1) == ' ') ? 2 : 1;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    69
		strcpy(arg, eqPos+d);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    70
		arg[strlen(arg)-1] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    71
		strcpy(prefix, l);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    72
		prefix[valPos-l] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    73
		out << prefix << "bind_thm(\"" << name << "\", "
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    74
		    << arg << ");\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    75
	    }
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    76
	}
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    77
	else if ((rPos = strstr(l, "prove_goal")) 
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    78
		 && (!isalpha(*(rPos-1))) 
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    79
		 && (!isalpha(*(rPos+10)) || (*(rPos+10) == 'w'))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    80
		 && (valPos = strstr(l, "val ")) 
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    81
		 && (eqPos = strstr(l, "="))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    82
                 && (rPos - eqPos < 5))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    83
	{                                    // replace prove_goal by qed_goal?
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    84
	    char name[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    85
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    86
	    assert(eqPos-(valPos+4) > 0);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    87
	    strncpy(name, valPos+4, eqPos-(valPos+4));
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    88
	    name[eqPos-(valPos+4)] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    89
	    if (!isalpha(name[eqPos-(valPos+4)-1]))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    90
	        name[eqPos-(valPos+4)-1] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    91
#ifdef DEBUG
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    92
	    cerr << "Found prove_goal: \"" << name << "\"\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    93
#endif
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    94
	    char prefix[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    95
	    char arg[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    96
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    97
	    strncpy(prefix, l, valPos-l);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    98
	    prefix[valPos-l] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
    99
	    out << prefix << "qed_goal" << ((*(rPos+10) == 'w') ? "w " : " ")
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   100
		<< '\"' << name << '\"' << strchr(rPos, ' ') << '\n';
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   101
	}
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   102
	else if ((rPos = strstr(l, "standard"))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   103
		 && (!isalpha(*(rPos-1))) 
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   104
		 && (!isalpha(*(rPos+8))) 
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   105
		 && (valPos = strstr(l, "val ")) 
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   106
		 && (eqPos = strstr(l, "="))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   107
                 && (rPos - eqPos < 5)
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   108
                 && (l[strlen(l)-1] == ';'))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   109
	{                                                   // insert bind_thm?
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   110
	    char name[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   111
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   112
	    assert(eqPos-(valPos+4) > 0);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   113
	    strncpy(name, valPos+4, eqPos-(valPos+4));
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   114
	    name[eqPos-(valPos+4)] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   115
	    if (!isalpha(name[eqPos-(valPos+4)-1]))
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   116
	        name[eqPos-(valPos+4)-1] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   117
#ifdef DEBUG
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   118
	    cerr << "Found standard: \"" << name << "\"\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   119
#endif
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   120
	    char prefix[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   121
	    char arg[LIN_LEN];
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   122
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   123
	    strncpy(prefix, l, valPos-l);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   124
	    prefix[valPos-l] = 0;
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   125
	    strcpy(l+strlen(l)-1, ");");        // insert ")" before line's ';'
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   126
	    out << prefix << "bind_thm (\"" << name << "\","
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   127
	        << strchr(rPos, ' ') << '\n';
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   128
	}
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   129
	else                                           // output line unchanged
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   130
	    out << l << '\n';
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   131
	in.getline(l, LIN_LEN);
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   132
    }
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   133
    in.close();
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   134
    out.close();
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   135
#ifdef DEBUG
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   136
    cerr << "Done\n";
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   137
#endif
4a266c3d4cc0 qed is a utility that makes ML files store the defined theories in Isabelle's
clasohm
parents:
diff changeset
   138
}