Răsfoiți Sursa

fix unsafe strcopy that can cause buffer overflows + fix Makefile clean rule + change from inline to block comments

Noah Vogt 3 ani în urmă
părinte
comite
89f0f78fdc
5 a modificat fișierele cu 114 adăugiri și 112 ștergeri
  1. 2 2
      Makefile
  2. 21 20
      src/main.cpp
  3. 26 26
      src/tibasic.cpp
  4. 8 8
      src/tibasic.h
  5. 57 56
      src/tokens.cpp

+ 2 - 2
Makefile

@@ -13,7 +13,7 @@ DEPFILES := $(patsubst %.cpp,%.d,$(SRCFILES))
 
 .PHONY: all clean
 
-CXXFLAGS := -g -Wall -pedantic -O 
+CXXFLAGS := -g -Wall -pedantic -O -D_FORTIFY_SOURCE=2
 
 CXX := g++
 
@@ -28,7 +28,7 @@ tibasicc: $(OBJFILES)
 	@$(CXX) $(CFLAGS) -MMD -MP -c $< -o $@
 
 clean:
-		rm -f $(OBJFILES)/*.o
+		rm -f $(OBJFILES)
 
 install: all
 	mkdir -p ${PREFIX}/bin

+ 21 - 20
src/main.cpp

@@ -14,8 +14,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-// When VC++ compiles in debug mode, it will set _DEBUG. This sets DEBUG
-// in order to avoid the VC++-ism.
+/* When VC++ compiles in debug mode, it will set _DEBUG. This sets DEBUG */
+/* in order to avoid the VC++-ism. */
 #ifdef _DEBUG
 #define DEBUG
 #endif
@@ -33,7 +33,7 @@
 
 using namespace std;
 
-/// Helper function to convert a string to uppercase.
+/* Helper function to convert a string to uppercase. */
 char* strtoupper(char* str)
 {
 	for( size_t i = 0; i < strlen( str ); i++ )
@@ -44,7 +44,7 @@ char* strtoupper(char* str)
 	return str;
 }
 
-/// Logs output from the build
+/* Logs output from the build */
 void log(LogSeverity severity, const char *out)
 {
     cout << severityToString(severity) << ": " << out << endl;
@@ -58,10 +58,10 @@ void stripExtension(const char *in, char *out, size_t len)
     *strrchr(out, '.') = 0;
 }
 
-// declare global variable to set debug mode later
+/* declare global variable to set debug mode later */
 bool verbose = false;
 
-// define help message
+/* define help message */
 string helpMessage = "\
 Usage: tibasicc [options] filename\n\
 Options:\n\
@@ -72,17 +72,17 @@ Options:\n\
 
 int main( int argc, char* argv[] )
 {
-	// check for valid number of arguments
+	/* check for valid number of arguments */
 	if((argc < 2) || (argv[1] == NULL))
 	{
-		// display error and help message when no arguments given
+		/* display error and help message when no arguments given */
         cout << "Error: " << helpMessage << "\n";
 		return 1;
 	}
 
     if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
     {
-		// display help message when help flag arguments given
+		/* display help message when help flag arguments given */
         cout << helpMessage << "\n";
         return 0;
     }
@@ -93,14 +93,14 @@ int main( int argc, char* argv[] )
 
     bool bDecompile = false;
 
-    // Parse arguments
-    inFile = argv[argc - 1]; // Last argument is always filename
+    /* Parse arguments */
+    inFile = argv[argc - 1]; /* Last argument is always filename */
     for(int i = 1; i < argc - 1; i++)
     {
         if(!strcmp(argv[i], "-o") && !outFile.length())
         {
-            i++; // Next argument is filename
-            // Output filename
+            i++; /* Next argument is filename */
+            /* Output filename */
             if(i >= argc - 1)
             {
                 log(Error, "-o requires a parameter (output filename).");
@@ -124,11 +124,12 @@ int main( int argc, char* argv[] )
         }
     }
 
-    // If no output was given, rename the input with .8xp instead of .tib and
-    // use that as the output.
+    /* If no output was given, rename the input with .8xp instead of .tib and 
+     * use that as the output.
+     */
     if(!outFile.length())
     {
-        // check for file extension and strip it if found
+        /* check for file extension and strip it if found */
         if(strchr(inFile.c_str(), '.'))
         {
             char *tmp = new char[inFile.length()];
@@ -142,21 +143,21 @@ int main( int argc, char* argv[] )
             outFile = inFile;
         }
         
-        // set file extension for the output file
+        /* set file extension for the output file */
         if(bDecompile)
             outFile += ".tib";
         else
             outFile += ".8xp";
 
-        // print that verbose mode is activated
+        /* print that verbose mode is activated */
         if(verbose)
             log(Info, "Verbose Mode successfully activated");
     }
 
-    // Make sure we have tokens to work with!
+    /* Make sure we have tokens to work with! */
     initialiseTokens();
 
-    // Compile time!
+    /* Compile time! */
     if(inFile.length() && outFile.length())
     {
         bool res = false;

+ 26 - 26
src/tibasic.cpp

@@ -26,11 +26,11 @@
 
 using namespace std;
 
-/// \todo More error handling.
+/* \todo More error handling. */
 
 unsigned short Compiler::doChecksum(size_t sum)
 {
-    // Bottom 16 bits of the sum.
+    /* Bottom 16 bits of the sum. */
     return (unsigned short) (sum & 0xFFFF);
 }
 
@@ -61,7 +61,7 @@ bool Compiler::compile(string inFile, string outFile)
 
     string tmpLine;
 
-    // Output information ready for writing the compiled code to a file.
+    /* Output information ready for writing the compiled code to a file. */
     vector<token_t> output;
     unsigned short outputSize = 0;
 
@@ -69,7 +69,7 @@ bool Compiler::compile(string inFile, string outFile)
     {
         getline(f, tmpLine, '\n');
 
-        // ignore empty lines
+        /* ignore empty lines */
         if(!tmpLine.length())
         {
             if(verbose)
@@ -77,14 +77,14 @@ bool Compiler::compile(string inFile, string outFile)
             continue;
         }
 
-        // remove comments
+        /* remove comments */
         tmpLine = tmpLine.substr(0, tmpLine.find("#", 0));
 
-        // strip spaces at the beginning and end of lines
+        /* strip spaces at the beginning and end of lines */
         tmpLine = trim(tmpLine);
 
 
-        // ignore lines with now only whitespaces
+        /* ignore lines with now only whitespaces */
         bool containsSpaces = tmpLine.find_first_not_of(' ') != std::string::npos;
         if(!containsSpaces)
         {
@@ -94,12 +94,12 @@ bool Compiler::compile(string inFile, string outFile)
         }
 
 
-        // Parse.
+        /* Parse. */
         token_t token;
 
         while(tmpLine.length())
         {
-            // Grab the longest possible token we can from the input.
+            /* Grab the longest possible token we can from the input. */
             string s = tmpLine.substr(0, getLongestToken());
 
             bool validToken = false;
@@ -110,7 +110,7 @@ bool Compiler::compile(string inFile, string outFile)
                     s = s.substr(0, s.length() - 1);
             }
 
-            // Special case for alphabet characters
+            /* Special case for alphabet characters */
             if(!s.length() && isalpha(tmpLine[0]))
             {
                 token.token = toupper(tmpLine[0]);
@@ -121,7 +121,7 @@ bool Compiler::compile(string inFile, string outFile)
 
             if(!s.length())
             {
-                // Error, asplode!
+                /* Error, asplode! */
                 log(Error, "Invalid token.");
                 f.close();
                 return false;
@@ -136,7 +136,7 @@ bool Compiler::compile(string inFile, string outFile)
             }
         }
 
-        // Output a newline.
+        /* Output a newline. */
         bool gotNewline = lookupToken("\n", token);
         if(gotNewline)
         {
@@ -145,7 +145,7 @@ bool Compiler::compile(string inFile, string outFile)
         }
     }
 
-    // Have the file read and parsed now. Time to write the output.
+    /* Have the file read and parsed now. Time to write the output. */
     struct ProgramHeader phdr; struct VariableEntry ventry;
     memset(&phdr, 0, sizeof(ProgramHeader));
     memset(&ventry, 0, sizeof(VariableEntry));
@@ -155,12 +155,12 @@ bool Compiler::compile(string inFile, string outFile)
     phdr.extsig[0] = 0x1A; phdr.extsig[1] = 0x0A; phdr.extsig[2] = 0;
     strcpy(phdr.comment, "Generated by the TI-BASIC Compiler.");
 
-    /// \todo Magic numbers!
+    /* \todo Magic numbers! */
     ventry.start = 0x0D;
     ventry.length1 = ventry.length2 = outputSize + sizeof(outputSize);
     ventry.type = 0x05;
 
-    // Convoluted magic to get the filename. Minus the extension. :)
+    /* Convoluted magic to get the filename. Minus the extension. :) */
     size_t i = 0;
     size_t n = outFile.find_last_of('/');
     if(n == inFile.npos) n = outFile.find_last_of('\\');
@@ -172,13 +172,13 @@ bool Compiler::compile(string inFile, string outFile)
         ventry.name[i++] = toupper(outFile[n]);
     }
 
-    // Begin writing to file.
+    /* Begin writing to file. */
     FILE *out = fopen(outFile.c_str(), "wb");
     fwrite(&phdr, sizeof(phdr), 1, out);
     fwrite(&ventry, sizeof(ventry), 1, out);
     fwrite(&outputSize, 2, 1, out);
 
-    // Sum of all bytes for checksum purposes.
+    /* Sum of all bytes for checksum purposes. */
     size_t sum = 0;
 
     for(vector<token_t>::iterator it = output.begin();
@@ -189,7 +189,7 @@ bool Compiler::compile(string inFile, string outFile)
         sum += it->token;
     }
 
-    // Perform a checksum and write to file.
+    /* Perform a checksum and write to file. */
     sum += outputSize;
     sum += sumBytes(reinterpret_cast<const char*>(&ventry), sizeof(ventry));
     unsigned short checksum = doChecksum(sum);
@@ -202,7 +202,7 @@ bool Compiler::compile(string inFile, string outFile)
 
 bool Compiler::decompile(string inFile, string outFile)
 {
-    // Parse the file.
+    /* Parse the file. */
     FILE *fp = fopen(inFile.c_str(), "rb");
     if(!fp)
     {
@@ -210,13 +210,13 @@ bool Compiler::decompile(string inFile, string outFile)
         return false;
     }
 
-    /// \todo Checksum verification.
+    /* \todo Checksum verification. */
 
-    // File header
+    /* File header */
     struct ProgramHeader phdr;
     fread(&phdr, sizeof(phdr), 1, fp);
 
-    // Variable entry
+    /* Variable entry */
     struct VariableEntry ventry;
     fread(&ventry, sizeof(ventry), 1, fp);
 
@@ -234,7 +234,7 @@ bool Compiler::decompile(string inFile, string outFile)
     {
         fread(&temp, 1, 2, fp);
 
-        // If we're in assembly mode, just copy the bytes straight in a numbers.
+        /* If we're in assembly mode, just copy the bytes straight in a numbers. */
         if(bAsmProgram)
         {
             if(((temp & 0xFF) == 0x3F))
@@ -247,7 +247,7 @@ bool Compiler::decompile(string inFile, string outFile)
             continue;
         }
 
-        // Convoluted.
+        /* Convoluted. */
         string conv;
         bool bIsFound = lookupToken(temp, conv);
         if(!bIsFound)
@@ -282,12 +282,12 @@ bool Compiler::decompile(string inFile, string outFile)
 
     fclose(fp);
 
-    // Write the output now.
+    /* Write the output now. */
     ofstream f(outFile.c_str());
     f << sOutput;
     f.close();
 
-    /// \todo error handling for output file.
+    /* \todo error handling for output file. */
 
     return true;
 }

+ 8 - 8
src/tibasic.h

@@ -25,14 +25,14 @@
 #define PACKED __attribute__((packed))
 #endif
 
-/// Stores a token to be written and the size of that token.
+/* Stores a token to be written and the size of that token. */
 typedef struct
 {
     unsigned short token;
     size_t sz;
 } token_t;
 
-/// Log severities
+/* Log severities */
 enum LogSeverity
 {
     Error,
@@ -68,10 +68,10 @@ inline const char *severityToString(LogSeverity s)
     };
 }
 
-/// Log function
+/* Log function */
 void log(LogSeverity, const char *);
 
-/// Compilation class.
+/* Compilation class. */
 class Compiler
 {
     public:
@@ -83,7 +83,7 @@ class Compiler
         bool decompile(std::string inFile, std::string outFile);
 
     private:
-        /// Perform a checksum over a region of data.
+        /* Perform a checksum over a region of data. */
         size_t sumBytes(const char *data, size_t len);
         unsigned short doChecksum(size_t sum);
 
@@ -91,16 +91,16 @@ class Compiler
 #pragma pack(push, 1)
 #endif
 
-        /// 8xp file header
+        /* 8xp file header */
         struct ProgramHeader
         {
-            char sig[8];
+            char sig[9];
             char extsig[3];
             char comment[42];
             unsigned short datalen;
         } PACKED;
 
-        /// Variable entry
+        /* Variable entry */
         struct VariableEntry
         {
             unsigned short start;

+ 57 - 56
src/tokens.cpp

@@ -23,48 +23,48 @@
 
 using namespace std;
 
-/// Describes a potential token to be read by the compiler
+/* Describes a potential token to be read by the compiler */
 struct Token {
-    /// The compiled byte for the token
+    /* The compiled byte for the token */
 	unsigned char data;
 
-    /// The actual text to be converted by the interpreter
+    /* The actual text to be converted by the interpreter */
 	const char* text;
 };
 
-/// A two byte token (0xBB, 0x7E and SysVar)
+/* A two byte token (0xBB, 0x7E and SysVar) */
 struct TwoByte {
 	unsigned short data;
 	const char* text;
 };
 
-/// Direct ASCII character to token conversion.
+/* Direct ASCII character to token conversion. */
 struct ConvertRule {
-	char c;				// the character
-	unsigned char tok;	// the equivalent token
+	char c;				/* the character */
+	unsigned char tok;	/* the equivalent token */
 };
 
-/// References to lists defined after functions.
+/* References to lists defined after functions. */
 extern struct Token StandardTokens[200];
 extern struct TwoByte CalcVars[302];
 extern struct ConvertRule Replacements[39];
 
-/// string -> token mapping
+/* string -> token mapping */
 map<string, token_t> g_TokenLookup;
 
-/// token -> string mapping
+/* token -> string mapping */
 map<unsigned short, string> g_ReverseLookup;
 
-/// Longest input string possible
+/* Longest input string possible */
 size_t g_LongestInput = 0;
 
-/// Shiny little template function that returns the size of an array.
+/* Shiny little template function that returns the size of an array. */
 template <typename T, int N> size_t arrayLen(T(&)[N]){return N;}
 
-/// Initialises the token map
+/* Initialises the token map */
 void initialiseTokens()
 {
-    // Iterate the main token list first.
+    /* Iterate the main token list first. */
     for(size_t i = 0; i < arrayLen(StandardTokens); i++)
     {
         token_t value;
@@ -80,7 +80,7 @@ void initialiseTokens()
         g_ReverseLookup[value.token] = s;
     }
 
-    // Now iterate the two-byte tokens.
+    /* Now iterate the two-byte tokens. */
     for(size_t i = 0; i < (sizeof(CalcVars) / sizeof(Token)); i++)
     {
         token_t value;
@@ -96,7 +96,7 @@ void initialiseTokens()
         g_ReverseLookup[value.token] = s;
     }
 
-    // Finally, iterate single-character tokens.
+    /* Finally, iterate single-character tokens. */
     for(size_t i = 0; i < (sizeof(Replacements) / sizeof(ConvertRule)); i++)
     {
         token_t value;
@@ -116,7 +116,7 @@ size_t getLongestToken()
     return g_LongestInput;
 }
 
-/// Perform a lookup
+/* Perform a lookup */
 bool lookupToken(string in, token_t &ret)
 {
     if(in.length() > g_LongestInput)
@@ -140,7 +140,7 @@ bool lookupToken(unsigned short in, string &out)
     return true;
 }
 
-// Token List
+/* Token List */
 #define TO_DMS			0x01
 #define TO_DEC			0x02
 #define TO_FRAC			0x03
@@ -392,7 +392,7 @@ bool lookupToken(unsigned short in, string &out)
 
 /** SYSTEM VARIABLES **/
 
-// Matrices
+/* Matrices */
 #define MAT_A			0x005C
 #define MAT_B			0x015C
 #define MAT_C			0x025C
@@ -404,7 +404,7 @@ bool lookupToken(unsigned short in, string &out)
 #define MAT_I			0x085C
 #define MAT_J			0x095C
 
-// Lists
+/* Lists */
 #define L1				0x005D
 #define L2				0x015D
 #define L3				0x025D
@@ -416,7 +416,7 @@ bool lookupToken(unsigned short in, string &out)
 #define L9				0x085D
 #define L0				0x095D
 
-// Graph (function)
+/* Graph (function) */
 #define Y1				0x105E
 #define Y2				0x115E
 #define Y3				0x125E
@@ -428,7 +428,7 @@ bool lookupToken(unsigned short in, string &out)
 #define Y9				0x185E
 #define Y0				0x195E
 
-// Graph (parametric)
+/* Graph (parametric) */
 #define X1T				0x205E
 #define Y1T				0x215E
 #define X2T				0x225E
@@ -442,7 +442,7 @@ bool lookupToken(unsigned short in, string &out)
 #define X6T				0x2A5E
 #define Y6T				0x2B5E
 
-// Graph (polar)
+/* Graph (polar) */
 #define R1				0x405E
 #define R2				0x415E
 #define R3				0x425E
@@ -452,7 +452,7 @@ bool lookupToken(unsigned short in, string &out)
 #define SYSVAR_U		0x805E
 #define SYSVAR_V		0x815E
 
-// Pictures
+/* Pictures */
 #define PIC1			0x0060
 #define PIC2			0x0160
 #define PIC3			0x0260
@@ -464,7 +464,7 @@ bool lookupToken(unsigned short in, string &out)
 #define PIC9			0x0860
 #define PIC0			0x0960
 
-// Graph databases
+/* Graph databases */
 #define GDB1			0x0061
 #define GDB2			0x0161
 #define GDB3			0x0261
@@ -476,7 +476,7 @@ bool lookupToken(unsigned short in, string &out)
 #define GDB9			0x0861
 #define GDB0			0x0961
 
-// Stat data
+/* Stat data */
 #define REGEQ			0x0162
 #define STAT_N			0x0262
 #define MEANX			0x0362
@@ -531,14 +531,14 @@ bool lookupToken(unsigned short in, string &out)
 #define SYSVAR_S		0x3462
 #define RSQUARED		0x3562
 #define CAPRSQUARED		0x3662
-#define DF2				0x3762 // not sure about this one
+#define DF2				0x3762 /* not sure about this one */
 #define SS				0x3862
 #define MS				0x3962
-#define DF3				0x3A62 // again here?
-#define SS1				0x3B62 // another double
-#define MS1				0x3C62 //   "       "
+#define DF3				0x3A62 /* again here? */
+#define SS1				0x3B62 /* another double */
+#define MS1				0x3C62 /*   "       " */
 
-// Graph data
+/* Graph data */
 #define ZXSCL			0x0063
 #define ZYSCL			0x0163
 #define XSCL			0x0263
@@ -590,7 +590,7 @@ bool lookupToken(unsigned short in, string &out)
 #define XRES			0x3063
 #define ZXRES			0x3163
 
-// Strings
+/* Strings */
 #define STR1			0x00AA
 #define STR2			0x01AA
 #define STR3			0x02AA
@@ -717,7 +717,7 @@ bool lookupToken(unsigned short in, string &out)
 #define MODBOXPLOT		0x5ABB
 #define NORMPROBPLOT	0x5BBB
 
-// Standard Tokens are any token that can be used anywhere in the line.
+/* Standard Tokens are any token that can be used anywhere in the line. */
 struct Token StandardTokens[] = {
 	/** CONTROL page of PROGRAM EDITOR (press PRGM when EDITING a program) **/
 	{ LOGIC_IF,			"If "		},
@@ -728,7 +728,7 @@ struct Token StandardTokens[] = {
 	{ CTL_REPEAT,		"Repeat "	},
 	{ CTL_END,			"End"		},
 	{ CTL_PAUSE,		"Pause "	},
-	{ CTL_PAUSE,		"Pause"		}, // note the space above
+	{ CTL_PAUSE,		"Pause"		}, /* note the space above */
 	{ LABEL,			"Lbl "		},
 	{ CTL_GOTO,			"Goto "		},
 	{ INCSKIPIFHIGH,	"IS>("		},
@@ -932,13 +932,13 @@ struct Token StandardTokens[] = {
 	{ RAND,				"rand"			},
 };
 
-// two-byte variables
+/* two-byte variables */
 struct TwoByte CalcVars[] = {
-	// AsmPrgm (uncompiled)
+	/* AsmPrgm (uncompiled) */
 	{ 0x6CBB,			"AsmPrgm"	},
-	{ 0x6DBB,			"AsmPrgm"	}, // this means decompilation works, but compilation won't hit this
+	{ 0x6DBB,			"AsmPrgm"	}, /* this means decompilation works, but compilation won't hit this */
 
-	// SysVar
+	/* SysVar */
 	{ MAT_A,			"[A]"		},
 	{ MAT_B,			"[B]"		},
 	{ MAT_C,			"[C]"		},
@@ -1009,7 +1009,7 @@ struct TwoByte CalcVars[] = {
 	{ GDB8,				"GDB8"		},
 	{ GDB9,				"GDB9"		},
 	{ GDB0,				"GDB0"		},
-	// finally, StatVars
+	/* finally, StatVars */
 	{ SX1,				"Sx1"		},
 	{ SX2,				"Sx2"		},
 	{ SXP,				"Sxp"		},
@@ -1038,14 +1038,14 @@ struct TwoByte CalcVars[] = {
 	{ SYSVAR_B,			"[b]"		},
 	{ SYSVAR_C,			"[c]"		},
 	{ SYSVAR_D,			"[d]"		},
-	{ SYSVAR_E,			"[stat_e]"	}, // because '[e]' refers to the constant e
+	{ SYSVAR_E,			"[stat_e]"	}, /* because '[e]' refers to the constant e */
 	{ X1,				"x1"		},
 	{ X2,				"x2"		},
 	{ X3,				"x3"		},
 	{ Y1_1,				"y1"		},
 	{ Y2_1,				"y2"		},
 	{ Y3_1,				"y3"		},
-	{ SYSVAR_N,			"[n]"		}, // somebody please tell me why there are so many variations on n
+	{ SYSVAR_N,			"[n]"		}, /* somebody please tell me why there are so many variations on n */
 	{ SYSVAR_P,			"[p]"		},
 	{ SYSVAR_Z,			"[z]"		},
 	{ SYSVAR_T,			"[t]"		},
@@ -1064,12 +1064,12 @@ struct TwoByte CalcVars[] = {
 	{ SYSVAR_S,			"[s]"		},
 	{ RSQUARED,			"r^2"		},
 	{ CAPRSQUARED,		"R^2"		},
-	{ DF2,				"[df]"		}, // somebody was high when they invented the token tables
+	{ DF2,				"[df]"		}, /* somebody was high when they invented the token tables */
 	{ SS,				"SS"		},
-	{ DF3,				"[df]"		}, // see previous comment
-	{ SS1,				"SS"		}, // again...
-	{ MS1,				"MS"		}, // and again!
-	// graph data
+	{ DF3,				"[df]"		}, /* see previous comment */
+	{ SS1,				"SS"		}, /* again... */
+	{ MS1,				"MS"		}, /* and again! */
+	/* graph data */
 	{ ZXSCL,			"ZXscl"		},
 	{ ZYSCL,			"ZYscl"		},
 	{ XSCL,				"Xscl"		},
@@ -1078,8 +1078,8 @@ struct TwoByte CalcVars[] = {
 	{ ZVNSTART,			"ZVnStart"	},
 	{ UNSTART,			"UnStart"	},
 	{ VNSTART,			"VnStart"	},
-	{ UNINVERSE,		"Un-1"		}, // i read a ^-1, but it's actually a -1...
-	{ VNINVERSE,		"Vn-1"		}, // same as above
+	{ UNINVERSE,		"Un-1"		}, /* i read a ^-1, but it's actually a -1... */
+	{ VNINVERSE,		"Vn-1"		}, /* same as above */
 	{ ZXMIN,			"ZXmin"		},
 	{ ZXMAX,			"ZXmax"		},
 	{ ZYMIN,			"ZYmin"		},
@@ -1113,15 +1113,15 @@ struct TwoByte CalcVars[] = {
 	{ XFACT,			"XFact"		},
 	{ YFACT,			"YFact"		},
 	{ TBLINPUT,			"TblInput"	},
-	// finance app
-	{ SYSVAR_CAPN,		"[N]"		}, // this is the N in the Finance app
+	/* finance app */
+	{ SYSVAR_CAPN,		"[N]"		}, /* this is the N in the Finance app */
 	{ IPERCENT,			"I%"		},
 	{ PV,				"PV"		},
 	{ PMT,				"PMT"		},
 	{ FV,				"FV"		},
 	{ ZXRES,			"ZXres"		},
 	{ XRES,				"Xres"		},
-	// strings
+	/* strings */
 	{ STR1,				"STR1"		},
 	{ STR2,				"STR2"		},
 	{ STR3,				"STR3"		},
@@ -1132,7 +1132,7 @@ struct TwoByte CalcVars[] = {
 	{ STR8,				"STR8"		},
 	{ STR9,				"STR9"		},
 	{ STR0,				"STR0"		},
-	// 7E Variables
+	/* 7E Variables */
 	{ SEQ,				"Sequential"	},
 	{ SIMUL,			"Simul"			},
 	{ POLARGC,			"PolarGC"		},
@@ -1152,7 +1152,7 @@ struct TwoByte CalcVars[] = {
 	{ UVAXES,			"uvAxes"		},
 	{ VWAXES,			"vwAxes"		},
 	{ UWAXES,			"uwAxes"		},
-	// BB Variables
+	/* BB Variables */
 	{ NPV,				"npv("			},
 	{ IRR,				"irr("			},
 	{ BAL,				"bal("			},
@@ -1202,7 +1202,7 @@ struct TwoByte CalcVars[] = {
 	{ RREF,				"rref("			},
 	{ TORECT,			"->Rect"		},
 	{ TOPOLAR,			"->Polar"		},
-	{ VAR_E,			"[e]"			}, // e by itself is impossible, and dangerous (imagine Disp "Hello"!)
+	{ VAR_E,			"[e]"			}, /* e by itself is impossible, and dangerous (imagine Disp "Hello"!) */
 	{ SINREG,			"SinReg "		},
 	{ LOGISTIC,			"Logistic "		},
 	{ LINREGTTEST,		"LinRegTTest "	},
@@ -1247,8 +1247,9 @@ struct TwoByte CalcVars[] = {
 	{ NORMPROBPLOT,		"NormProbPlot"	},
 };
 
-// Replacements
-// Replacements are rules that define special characters that must be replaced with a token.
+/* Replacements
+ * Replacements are rules that define special characters that must be replaced with a token.
+ */
 struct ConvertRule Replacements[] = {
 	{ '"', DOUBLEQUOTE },
 	{ '\'', APOSTROPHE },