Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
metamath
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wlammen writes:

OK, see here (https://stackoverflow.com/questions/6626136/best-practice-for-adding-gitignore-to-repo)
Maybe one should put this info into the README?

I'm not sure which info you would like to add to the README.
There is a standard .gitignore file for C projects here, we could give it a try.
Maybe better in a separate PR?

Copy link
Contributor

@wlammen wlammen Dec 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I added this comment is, because the metamath sources are distributed via a tar archive as well. Obviously you wont need the gitignore in this case. I think, some kind of distribution how-to is finally called for. That are my thoughts. I was curious why you added the file. Separate PR is fine with me.

6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ noinst_HEADERS = \
mmveri.h \
mmvstr.h \
mmword.h \
mmwtex.h
mmwtex.h \
mmhtbl.h \
mmwsts.h

metamath_SOURCES = \
metamath.c \
Expand All @@ -34,6 +36,8 @@ metamath_SOURCES = \
mmvstr.c \
mmword.c \
mmwtex.c \
mmhtbl.c \
mmwsts.c \
$(noinst_HEADERS)


Expand Down
86 changes: 67 additions & 19 deletions metamath.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@
#include "mmunif.h"
#include "mmword.h"
#include "mmwtex.h"
#include "mmwsts.h"
#ifdef THINK_C
#include "mmmaci.h"
#endif
Expand Down Expand Up @@ -2375,14 +2376,25 @@ void command(int argc, char *argv[])
g_htmlFlag = 1;
/* If not specified, for backwards compatibility in scripts
leave g_altHtmlFlag at current value */
/* 7-Jul-17 - MathML/STS handling */
if (switchPos("/ HTML") != 0) {
if (switchPos("/ ALT_HTML") != 0) {
print2("?Please specify only one of / HTML and / ALT_HTML.\n");
if (switchPos("/ ALT_HTML") != 0 || switchPos("/ STS") != 0 ) {
print2("?Please specify only one of / HTML , / ALT_HTML and / STS.\n");
Comment on lines +2141 to +2142
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wlammen wrote:

optimization: The function switchPos("/ STS") is called three times more or less in succession. Consider evaluating the result once and use a local variable to recall the result within the if conditions.

I don't think this is called 3 times. There are 3 else..if branches, and it is called one time in each, to ensure only one HTML output formatting option is chosen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It still looks awkward since the call and the parameter is coded several times.

continue;
}
g_altHtmlFlag = 0;
} else {
if (switchPos("/ ALT_HTML") != 0) g_altHtmlFlag = 1;
} else if (switchPos("/ ALT_HTML") != 0) {
if (switchPos ("/ STS") != 0) {
print2 ("?Please specify only one of / HTML , / ALT_HTML and / STS.\n");
continue;
}
g_altHtmlFlag = 1;
} else if (switchPos ("/ STS") != 0) {
stsFlag = 1;
let(&stsOutput, g_fullArg[5]);

/* Parse the STS rules corresponding to the expected output . */
parsetSTSRules(stsOutput);
}

if (2/*error*/ == readTexDefs(0 /* 1 = check errors only */,
Expand Down Expand Up @@ -2947,6 +2959,8 @@ void command(int argc, char *argv[])
switchPos("/ HTML")
|| switchPos("/ BRIEF_HTML")
|| switchPos("/ ALT_HTML")
/* 7-Jul-2017 added MathML/STS */
|| switchPos("/ STS")
|| switchPos("/ BRIEF_ALT_HTML"))) {
/* Special processing for the / HTML qualifiers - for each matching
statement, a .html file is opened, the statement is output,
Expand All @@ -2959,6 +2973,8 @@ void command(int argc, char *argv[])
i = 5; /* # arguments with only / HTML or / ALT_HTML */
if (noVersioning) i = i + 2;
if (switchPos("/ TIME")) i = i + 2;
/* 7-Jul-2017 added MathML/STS */
if (switchPos("/ STS")) i = i + 1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wlammen wrote:

Suspicious value of i. The other options / TIME or / NO_VERSIONING add 2 to the number of options, seemingly counting the slash and the tag as different entries. Why is this not done for / STS? If the count is correct, IMO a comment should clarify the underlying logic.

Interesting. So, a typical SHOW STATEMENT command looks like this:
SHOW STATEMENT syl / HTML
That would be g_rawArgs = 5, which already includes 2 arguments for the / HTML.
As you correctly guessed, for / NO_VERSIONING and / TIME, there are two more arguments, therefore the +2.
In the case of STS, the / STS would already be accounted for in the 5 (taking the place of the / HTML), so that's not why the +1 is for. Rather, in the case of STS, there is one more argument, namely the name of the output processing, e.g. mathml. That is what the +1 is for.

I'll add a comment to make that clearer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am subject to a learning curve as well while reviewing, wrt both to your source code and the review style.

if (g_rawArgs != i) {
printLongLine(cat("?The HTML qualifiers may not be combined with",
" others except / NO_VERSIONING and / TIME.\n", NULL), " ", " ");
Expand Down Expand Up @@ -3011,6 +3027,15 @@ void command(int argc, char *argv[])
g_altHtmlFlag = 0;
}

/* 7-Jul-2017 added MathML/STS */
if (switchPos("/ STS")) {
stsFlag = 1;
let(&stsOutput, g_fullArg[5]);

/* Parse the STS rules corresponding to the expected output. */
parsetSTSRules(stsOutput);
}

q = 0;

/* Special feature: if the match statement starts with "*", we
Expand Down Expand Up @@ -3082,20 +3107,32 @@ void command(int argc, char *argv[])
let(&g_texFileName, cat(g_Statement[g_showStatement].labelName, ".html",
NULL));
}
print2("Creating HTML file \"%s\"...\n", g_texFileName);
g_texFilePtr = fSafeOpen(g_texFileName, "w", /* 17-Jul-2019 nm */
noVersioning /*noVersioningFlag*/);
/****** old code before 17-Jul-2019 *******
if (switchPos("/ NO_VERSIONING") == 0) {
g_texFilePtr = fSafeOpen(g_texFileName, "w", 0/@noVersioningFlag@/);
} else {
/@ 6-Jul-2008 nm Added / NO_VERSIONING @/
/@ Don't create the backup versions ~1, ~2,... @/
g_texFilePtr = fopen(g_texFileName, "w");
if (!g_texFilePtr) print2("?Could not open the file \"%s\".\n",
g_texFileName);
/* 29-Sep-17 Thierry Arnoux - Post processing (for pre-rendering) */
if(stsFlag && strlen(postProcess) != 0) {
vstring pipeCommand = "";
print2("Creating and processing HTML file \"%s\"...\n", g_texFileName);
let(&pipeCommand, cat(postProcess, " > ", g_texFileName, NULL));
g_texFilePtr = popen(pipeCommand, "w");
if (!g_texFilePtr) print2("?Could not execute the command \"%s\".\n",
pipeCommand);
let(&pipeCommand, "");
}
else {
print2("Creating HTML file \"%s\"...\n", g_texFileName);
g_texFilePtr = fSafeOpen(g_texFileName, "w", /* 17-Jul-2019 nm */
noVersioning /*noVersioningFlag*/);
/****** old code before 17-Jul-2019 *******
if (switchPos("/ NO_VERSIONING") == 0) {
g_texFilePtr = fSafeOpen(g_texFileName, "w", 0/@noVersioningFlag@/);
} else {
/@ 6-Jul-2008 nm Added / NO_VERSIONING @/
/@ Don't create the backup versions ~1, ~2,... @/
g_texFilePtr = fopen(g_texFileName, "w");
if (!g_texFilePtr) print2("?Could not open the file \"%s\".\n",
g_texFileName);
}
********* end of old code before 17-Jul-2019 *******/
}
********* end of old code before 17-Jul-2019 *******/
if (!g_texFilePtr) goto htmlDone; /* Couldn't open it (err msg was
provided) */
g_texFileOpenFlag = 1;
Expand Down Expand Up @@ -3230,7 +3267,10 @@ void command(int argc, char *argv[])
if (!instr(1, str3, cat(" ", str1, " ", NULL))) {
let(&str3, cat(str3, " ", str1, " ", NULL));
let(&str2, "");
str2 = tokenToTex(g_MathToken[(g_Statement[i].mathString)[j]
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str2 = stsToken((g_Statement[i].mathString)[j], i);
else
str2 = tokenToTex(g_MathToken[(g_Statement[i].mathString)[j]
].tokenName, i/*stmt# for error msgs*/);
/* 2/9/02 Skip any tokens (such as |- in QL Explorer) that
may be suppressed */
Expand Down Expand Up @@ -3380,7 +3420,8 @@ void command(int argc, char *argv[])
ABORT_S:
/*** Close the html file ***/
printTexTrailer(1 /*texHeaderFlag*/);
fclose(g_texFilePtr);
if(stsFlag && strlen(postProcess) != 0) pclose(g_texFilePtr);
else fclose(g_texFilePtr);
g_texFileOpenFlag = 0;
let(&g_texFileName,"");

Expand Down Expand Up @@ -8093,6 +8134,13 @@ void command(int argc, char *argv[])
continue;
}

if (cmdMatches("VERIFY STS")) {
/* 12-Dec-17 - Go through all non-definition axioms,
* and check whether there is a corresponding STS scheme */
verifySts(g_fullArg[2]);
continue;
}

print2("?This command has not been implemented.\n");
continue;

Expand Down
35 changes: 31 additions & 4 deletions mmcmdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ flag processCommandLine(void)
"MARKUP|ASSIGN|REPLACE|MATCH|UNIFY|LET|INITIALIZE|DELETE|IMPROVE|",
/* 11-Sep-2016 nm Added EXPAND */
"MINIMIZE_WITH|EXPAND|UNDO|REDO|SAVE|DEMO|INVOKE|CLI|EXPLORE|TEX|",
"LATEX|HTML|COMMENTS|BIBLIOGRAPHY|MORE|",
"LATEX|HTML|STS|COMMENTS|BIBLIOGRAPHY|MORE|",
"TOOLS|MIDI|$|<$>", NULL))) goto pclbad;
if (cmdMatches("HELP OPEN")) {
/*if (!getFullArg(2, "LOG|TEX|HTML|<LOG>")) goto pclbad;*/
Expand Down Expand Up @@ -124,7 +124,7 @@ flag processCommandLine(void)
goto pclgood;
}
if (cmdMatches("HELP VERIFY")) {
if (!getFullArg(2, "PROOF|MARKUP|<PROOF>"))
if (!getFullArg(2, "PROOF|MARKUP|STS|<PROOF>"))
goto pclbad;
goto pclgood;
}
Expand Down Expand Up @@ -577,8 +577,20 @@ flag processCommandLine(void)
if (!getFullArg(i, cat(
"FULL|COMMENT|TEX|OLD_TEX|HTML|ALT_HTML|TIME|BRIEF_HTML",
/* 12-May-2009 sa Added MNEMONICS */
"|BRIEF_ALT_HTML|MNEMONICS|NO_VERSIONING|<FULL>", NULL)))
"|BRIEF_ALT_HTML|MNEMONICS|NO_VERSIONING|<FULL>"
/* 7-Jul-2017 added MATHML/STS */
"|STS", NULL)))
goto pclbad;
if (lastArgMatches("STS")) {
i++;
if (strlen(stsOutput)) {
if (!getFullArg(i,cat("* Using which output mode <",stsOutput,">? ",NULL)))
Copy link
Contributor

@wlammen wlammen Dec 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation

goto pclbad;
} else {
if (!getFullArg(i,"* Using which output mode <mathml>? "))
goto pclbad;
}
}
} else {
break;
}
Expand Down Expand Up @@ -1353,7 +1365,7 @@ flag processCommandLine(void)

if (cmdMatches("VERIFY")) {
if (!getFullArg(1,
"PROOF|MARKUP|<PROOF>"))
"PROOF|MARKUP|STS|<PROOF>"))
goto pclbad;
if (cmdMatches("VERIFY PROOF")) {
if (g_sourceHasBeenRead == 0) {
Expand Down Expand Up @@ -1413,6 +1425,21 @@ flag processCommandLine(void)

goto pclgood;
}

if (cmdMatches("VERIFY STS")) {
if (g_statements == 0) {
print2("?No source file has been read in. Use READ first.\n");
goto pclbad;
}
if (strlen(stsOutput)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code from line 586 (with i == 2)

if (!getFullArg(2,cat("* Using which output mode <",stsOutput,">? ",NULL)))
goto pclbad;
} else {
if (!getFullArg(2,"* Using which output mode <mathml>? "))
goto pclbad;
}
goto pclgood;
}
}

if (cmdMatches("DBG")) {
Expand Down
39 changes: 28 additions & 11 deletions mmcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "mmpfas.h"
#include "mmunif.h" /* 26-Sep-2010 nm For g_bracketMatchInit, g_minSubstLen */
/* 1-Oct-2017 nm ...and g_firstConst */
#include "mmwsts.h" /* 27 Jul 2017 tar For MathML/STS */

/* 12-Nov-2018 nm */
/* Local prototypes */
Expand Down Expand Up @@ -352,10 +353,11 @@ void typeStatement(long showStmt,
}
htmlDistinctVarsCommaFlag = 1;
let(&str2, "");
str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str2 = stsToken(nmbrTmpPtr1[k], showStmt);
else str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt);
/* tokenToTex allocates str2; we must deallocate it */
let(&htmlDistinctVars, cat(htmlDistinctVars, str2, NULL));

}
nmbrLet(&nmbrDDList, nmbrAddElement(nmbrDDList, nmbrTmpPtr1[k]));
}
Expand All @@ -371,7 +373,9 @@ void typeStatement(long showStmt,
}
htmlDistinctVarsCommaFlag = 1;
let(&str2, "");
str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str2 = stsToken(nmbrTmpPtr2[k], showStmt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code from line 357

else str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt);
/* tokenToTex allocates str2; we must deallocate it */
let(&htmlDistinctVars, cat(htmlDistinctVars, str2, NULL));

Expand Down Expand Up @@ -630,11 +634,15 @@ void typeStatement(long showStmt,
} else {
if (htmlFlg && texFlag) {
let(&str2, "");
str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str2 = stsToken(nmbrTmpPtr1[k], showStmt);
else str2 = tokenToTex(g_MathToken[nmbrTmpPtr1[k]].tokenName, showStmt);
/* tokenToTex allocates str2; we must deallocate it */
let(&str1, cat(str1, " &nbsp; ", str2, NULL));
let(&str2, "");
str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str2 = stsToken(nmbrTmpPtr2[k], showStmt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code from line 377

else str2 = tokenToTex(g_MathToken[nmbrTmpPtr2[k]].tokenName, showStmt);
let(&str1, cat(str1, ",", str2, NULL));
}
}
Expand Down Expand Up @@ -1312,7 +1320,9 @@ vstring htmlDummyVars(long showStmt)
/* tokenToTex allocates str1; must deallocate it first */
let(&str1, "");
/* Convert token to htmldef/althtmldef string */
str1 = tokenToTex(g_MathToken[dummyVar].tokenName,
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str1 = stsToken(dummyVar, showStmt);
else str1 = tokenToTex(g_MathToken[dummyVar].tokenName,
showStmt);
let(&htmlDummyVarList, cat(htmlDummyVarList, " ", str1, NULL));
break; /* Found a match, so stop further checking */
Expand Down Expand Up @@ -1493,7 +1503,9 @@ vstring htmlAllowedSubst(long showStmt)
if (found == 0) continue; /* All set vars have $d with this wff or class */

let(&str1, "");
str1 = tokenToTex(g_MathToken[wffOrClassVar].tokenName, showStmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str1 = stsToken(wffOrClassVar, showStmt);
else str1 = tokenToTex(g_MathToken[wffOrClassVar].tokenName, showStmt);
/* tokenToTex allocates str1; we must deallocate it eventually */
countInfo++;
let(&htmlAllowedList, cat(htmlAllowedList, " &nbsp; ",
Expand All @@ -1502,7 +1514,9 @@ vstring htmlAllowedSubst(long showStmt)
for (j = 0; j < setVars; j++) {
if (setVarDVFlag[j] == 'N') {
let(&str1, "");
str1 = tokenToTex(g_MathToken[setVar[j]].tokenName, showStmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) str1 = stsToken(setVar[j], showStmt);
else str1 = tokenToTex(g_MathToken[setVar[j]].tokenName, showStmt);
let(&htmlAllowedList, cat(htmlAllowedList,
(first == 0) ? "," : "", str1, NULL));
if (first == 0) countInfo++;
Expand Down Expand Up @@ -2449,9 +2463,12 @@ void typeProof(long statemNum,
&& (!strcmp(g_Statement[stmt].labelName, "cmpt")
|| !strcmp(g_Statement[stmt].labelName, "cmpt2")))
) {
tmpStr1 =
tokenToTex(g_MathToken[(g_Statement[stmt].mathString)[i]
].tokenName, stmt);
/* 27 Jul 2017 tar For MathML/STS */
if(stsFlag) tmpStr1 =
stsToken((g_Statement[stmt].mathString)[i], stmt);
else tmpStr1 =
tokenToTex(g_MathToken[(g_Statement[stmt].mathString)[i]
].tokenName, stmt);
/* 14-Jan-2016 nm */
let(&tmpStr1, cat(
(g_altHtmlFlag ? cat("<SPAN ", g_htmlFont, ">", NULL) : ""),
Expand Down
Loading