/*****************************************************************************/ /* Program name: metamath */ /* Copyright (C) 2008 NORMAN MEGILL nm at alum.mit.edu http://metamath.org */ /* License terms: GNU General Public License Version 2 or any later version */ /*****************************************************************************/ /*34567890123456 (79-character line to adjust editor window) 2345678901234567*/ #define MVERSION "0.07.38 26-Apr-2008" /* 0.07.38 26-Apr-2008 nm metamath.c, mmdata.h, mmdata.c, mmvstr.c, mmhlpb.c - Enhanced / EXCLUDE qualifier for MINIMIZE_WITH to handle comma-separated wildcard list. */ /* 0.07.37 14-Apr-2008 nm metamath.c, mmcmdl.c, mmhlpb.c - Added / JOIN qualifier to SEARCH. */ /* 0.07.36 7-Jan-2008 nm metamath.c, mmcmdl.c, mmhlpb.c - Added wildcard handling for labels in SHOW USAGE. */ /* 0.07.35 2-Jan-2008 nm mmcmdl.c, metamath.c, mmhlpb.c - Changed keywords COMPACT to PACKED and COLUMN to START_COLUMN so that SAVE/SHOW proof can use C to abbreviate COMPRESSED. (PACKED format is supported but "unofficial," used mainly for debugging purposes, and is not listed in HELP SAVE PROOF.) */ /* 0.07.34 19-Nov-2007 nm mmwtex.c, mminou.c - Added tooltips to proof step hyperlinks in SHOW STATEMENT.../HTML,ALT_HTML output (suggested by Reinder Verlinde) */ /* 0.07.33 19-Jul-2007 nm mminou.c, mmvstr.c, mmdata.c, mmword.c - added fflush after each printf() call for proper behavior inside emacs (suggested by Frederic Line) */ /* 0.07.32 29-Apr-2007 nm mminou.c - fSafeOpen now stops at gap; e.g. if ~2 doesn't exist, ~1 will be renamed to ~2, but any ~3, etc. are not touched */ /* 0.07.31 5-Apr-2007 nm mmwtex.c - Don't make "_" in hyperlink a subscript */ /* 0.07.30 8-Feb-2007 nm mmcmds.c, mmwtex.c Added HTML statement number info to SHOW STATEMENT.../FULL; friendlier "Contents+1" link in mmtheorems*.html */ /* 0.07.29 6-Feb-2007 Jason Orendorff mmpfas.c - Patch to eliminate the duplicate "Exceeded trial limit at step n" messages */ /* 0.07.28 22-Dec-2006 nm mmhlpb.c - Added info on quotes to HELP LET */ /* 0.07.27 23-Oct-2006 nm metamath.c, mminou.c, mmhlpa.c, mmhlpb.c - Added / SILENT qualifier to SUBMIT command */ /* 0.07.26 12-Oct-2006 nm mminou.c - Fixed bug when SUBMIT file was missing a new-line at end of file (reported by Marnix Klooster) */ /* 0.07.25 10-Oct-2006 nm metamath.c - Fixed bug invoking TOOLS as a ./metamath command-line argument */ /* 0.07.24 25-Sep-2006 nm mmcmdl.c Fixed bug in SHOW NEW_PROOF/START_COLUMN nn/LEM */ /* 0.07.23 31-Aug-2006 nm mmwtex.c - Added Home and Contents links to bottom of WRITE THEOREM_LIST pages */ /* 0.07.22 26-Aug-2006 nm metamath.c, mmcmdl.c, mmhlpb.c - Changed "IMPROVE STEP " to "IMPROVE " for user convenience and to be consistent with "ASSIGN " */ /* 0.07.21 20-Aug-2006 nm mmwtex.c - Revised small colored numbers so that all colors have the same grayscale brightness.. */ /* 0.07.20 19-Aug-2006 nm mmpars.c - Made the error "Required hypotheses may not be explicitly declared" in a compressed proof non-severe, so that we can still SAVE the proof to reformat and recover it. */ /* 0.07.19 11-Aug-06 nm mmcmds.c - "Distinct variable group(s)" is now "group" or "groups" as appropriate. */ /* 0.07.18 31-Jul-06 nm mmwtex.c - added table to contents to p.1 of output of WRITE THEOREM_LIST command. */ /* 0.07.17 4-Jun-06 nm mmpars.c - do not allow labels to match math symbols (new spec proposed by O'Cat). mmwtex.c - made theorem name 1st in title, for readability in Firefox tabs. */ /* 0.07.16 16-Apr-06 nm metamath.c, mmcmdl.c, mmpfas.c, mmhlpb.c - allow step to be negative (relative to end of proof) for ASSIGN, UNIFY, and LET STEP (see their HELPs). Added INITIALIZE USER to delete LET STEP assignments (see HELP INITIALIZE). Fixed bug in LET STEP (mmpfas.c). */ /* 0.07.15 10-Apr-06 nm metamath.c, mmvstr.c - change dates from 2-digit to 4-digit year; make compatible with older 2-digit year. */ /* 0.07.14 21-Mar-06 nm mmpars.c - fix bug 1722 when compressed proof has "Z" at beginning of proof instead of after a proof step. */ /* 0.07.13 3-Feb-06 nm mmpfas.c - minor improvement to MINIMIZE_WITH */ /* 0.07.12 30-Jan-06 nm metamath.c, mmcmds.c, mmdata.c, mmdata.h, mmhlpa.c, mmhlpb.c - added "?" wildcard to match single character. See HELP SEARCH. */ /* 0.07.11 7-Jan-06 nm metamath.c, mmcmdl.c, mmhlpb.c - added EXCEPT qualifier to MINIMIZE_WITH */ /* 0.07.10 28-Dec-05 nm metamath.c, mmcmds.c - cosmetic tweaks */ /* 0.07.10 11-Dec-05 nm metamath.c, mmcmdl.c, mmhlpb.c - added ASSIGN FIRST and IMPROVE FIRST commands. Also enhanced READ error message */ /* 0.07.9 1-Dec-05 nm mmvstr.c - added comment on how to make portable */ /* 0.07.9 18-Nov-05 nm metamath.c, mminou.c, mminou.h, mmcmdl.c, mmhlpb.c - added SET HEIGHT command; changed SET SCREEN_WIDTH to SET WIDTH; changed SET HENTY_FILTER to SET JEREMY_HENTY_FILTER (to make H for HEIGHT unambiguous); added HELP for SET JEREMY_HENTY_FILTER */ /* 0.07.8 15-Nov-05 nm mmunif.c - now detects wrong order in bracket matching heuristic to further reduce ambiguous unifications in Proof Assistant */ /* 0.07.7 12-Nov-05 nm mmunif.c - add "[","]" and "[_","]_" bracket matching heuristic to reduce ambiguous unifications in Proof Assistant. mmwtex.c - added heuristic for HTML spacing after "sum_" token. */ /* 0.07.6 15-Oct-05 nm mmcmds.c,mmpars.c - fixed compressed proof algorithm to match spec in book (with new algorithm due to Marnix Klooster). Users are warned to convert proofs when the old compression is found. */ /* 0.07.5 6-Oct-05 nm mmpars.c - fixed bug that reset "severe error in proof" flag when a proof with severe error also had unknown steps */ /* 0.07.4 1-Oct-05 nm mmcmds.c - ignored bug 235, which could happen for non-standard logics */ /* 0.07.3 17-Sep-05 nm mmpars.c - reinstated duplicate local label checking to conform to strict spec */ /* 0.07.2 19-Aug-05 nm mmwtex.c - suppressed math content for lemmas in WRITE THEOREMS output */ /* 0.07.1 28-Jul-05 nm Added SIMPLE_TEX qualifier to SHOW STATEMENT */ /* 0.07: Official 0.07 22-Jun-05 corresponding to Metamath book */ /* 0.07x: Fixed to work with AMD64 with 64-bit longs by Waldek Hebisch; deleted unused stuff in mmdata.c */ /* 0.07w: .mm date format like "$( [7-Sep-04] $)" is now generated and permitted (old one is tolerated too for compatibility) */ /* Metamath Proof Verifier - main program */ /* See the book "Metamath" for description of Metamath and run instructions */ /* The overall functionality of the modules is as follows: metamath.c - Contains main(); executes or calls commands mmcmdl.c - Command line interpreter mmcmds.c - Extends metamath.c command() to execute SHOW and other commands; added after command() became too bloated (still is:) mmdata.c - Defines global data structures and manipulates arrays with functions similar to BASIC string functions; memory management; converts between proof formats mmhlpa.c - The help file, part 1. mmhlpb.c - The help file, part 2. mminou.c - Basic input and output interface mmmaci.c - THINK C Macintosh interface (probably obsolete now) mmpars.c - Parses the source file mmpfas.c - Proof Assistant mmunif.c - Unification algorithm for Proof Assistant mmutil.c - Miscellaneous I/O utilities for non-ANSI compilers (has become obsolete and is now an empty shell) mmveri.c - Proof verifier for source file mmvstr.c - BASIC-like string functions mmwtex.c - LaTeX/HTML source generation mmword.c - File revision utility (for TOOLS> TAG) (not generally useful) */ /*****************************************************************************/ /* ------------- Compilation Instructions ---------------------------------- */ /*****************************************************************************/ /* These are the instructions for the gcc compiler (standard in Linux and Cygwin for Windows). 1. Make sure each .c file above is present in the compilation directory and that each .c file (except metamath.c) has its corresponding .h file present. 2. In the directory where these files are present, type: gcc metamath.c m*.c -o metamath 3. For better speed and error checking, use these gcc options: gcc m*.c -o metamath -O3 -funroll-loops -finline-functions \ -fomit-frame-pointer -Wall -ansi -pedantic 4. The Windows version in the download was compiled with LCC-Win32: lc -O m*.c -o metamath.exe */ /*****************************************************************************/ /*----------------------------------------------------------------------*/ #include #include #include #include #include #include #ifdef THINK_C #include #endif #include "mmutil.h" #include "mmvstr.h" #include "mmdata.h" #include "mmcmdl.h" #include "mmcmds.h" #include "mmhlpa.h" #include "mmhlpb.h" #include "mminou.h" #include "mmpars.h" #include "mmveri.h" #include "mmpfas.h" #include "mmunif.h" #include "mmword.h" #include "mmwtex.h" #ifdef THINK_C #include "mmmaci.h" #endif void command(int argc, char *argv[]); int qsortStringCmp(const void *p1, const void *p2); vstring qsortKey; /* Pointer only; do not deallocate */ int main(int argc, char *argv[]) { /* argc is the number of arguments; argv points to an array containing them */ #ifdef THINK_C /* Set console attributes */ console_options.pause_atexit = 0; /* No pause at exit */ console_options.title = (unsigned char*)"\pMetamath"; #endif #ifdef THINK_C /* The standard stream triggers the console package to initialize the Macintosh Toolbox managers and use the console interface. cshow must be called before using our own window to prevent crashing (THINK C Standard Library Reference p. 43). */ cshow(stdout); /* Initialize MacIntosh interface */ /*ToolBoxInit(); */ /* cshow did this automatically */ /* Display opening window */ /* WindowInit(); DrawMyPicture(); */ /* Wait for mouse click or key */ /*while (!Button());*/ #endif /****** If listMode is set to 1 here, the startup will be Text Tools utilities, and Metamath will be disabled ***************************/ /* (Historically, this mode was used for the creation of a stand-alone "TOOLS>" utility for people not interested in Metamath. This utility was named "LIST.EXE", "tools.exe", and "tools" on VMS, DOS, and Unix platforms respectively. The TAG command of TOOLS (mmword.c) was custom- written in accordance with the version control requirements of a company that used it; it documents the differences between two versions of a program as C-style comments embedded in the newer version.) */ listMode = 0; /* Force Metamath mode as startup */ toolsMode = listMode; if (!listMode) { /*print2("Metamath - Version %s\n", MVERSION);*/ print2("Metamath - Version %s%s", MVERSION, space(27 - strlen(MVERSION))); } /* if (argc < 2) */ print2("Type HELP for help, EXIT to exit.\n"); /* Allocate big arrays */ initBigArrays(); /* Process a command line until EXIT */ command(argc, argv); /* Close logging command file */ if (listMode && listFile_fp != NULL) { fclose(listFile_fp); } return 0; } void command(int argc, char *argv[]) { /* Command line user interface -- this is an infinite loop; it fetches and processes a command; returns only if the command is 'EXIT' or 'QUIT' and never returns otherwise. */ long argsProcessed = 0; /* Number of argv initial command-line arguments processed so far */ /* The variables in command() are static so that they won't be destroyed by a longjmp return to setjmp. */ long e, i, j, k, m, l, n, p, q, s /*,tokenNum*/; vstring str1 = "", str2 = "", str3 = "", str4 = "", str5= ""; nmbrString *nmbrTmpPtr; /* Pointer only; not allocated directly */ nmbrString *nmbrTmp = NULL_NMBRSTRING; nmbrString *nmbrSaveProof = NULL_NMBRSTRING; /*pntrString *pntrTmpPtr;*/ /* Pointer only; not allocated directly */ /*pntrString *pntrTmpPtr1;*/ /* Pointer only; not allocated directly */ /*pntrString *pntrTmpPtr2;*/ /* Pointer only; not allocated directly */ pntrString *pntrTmp = NULL_PNTRSTRING; pntrString *expandedProof = NULL_PNTRSTRING; flag tmpFlag; /* Variables for SHOW PROOF */ flag pipFlag; /* Proof-in-progress flag */ long startStep; long endStep; long startIndent; long endIndent; /* Also for SHOW TRACE_BACK */ flag essentialFlag; /* Also for SHOW TRACE_BACK */ flag renumberFlag; /* Flag to use essential step numbering */ flag unknownFlag; flag notUnifiedFlag; flag reverseFlag; long detailStep; flag noIndentFlag; /* Flag to use non-indented display */ long splitColumn; /* Column at which formula starts in nonindented display */ flag texFlag; /* Flag for TeX */ flag saveFlag; /* Flag to save in source */ long indentation; /* Number of spaces to indent proof */ vstring labelMatch = ""; /* SHOW PROOF