2016-01-14 15:23:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1987 Fujitsu
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2014-05-04 05:20:34 +00:00
|
|
|
/*
|
|
|
|
lexer.c -- Lexical scanner for the Macross assembler
|
|
|
|
|
|
|
|
Chip Morningstar -- Lucasfilm Ltd.
|
|
|
|
|
|
|
|
3-November-1984
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "macrossTypes.h"
|
|
|
|
#include "macrossGlobals.h"
|
|
|
|
#include "y.tab.h"
|
2016-01-24 05:50:12 +00:00
|
|
|
#include "debugPrint.h"
|
|
|
|
#include "errorStuff.h"
|
|
|
|
#include "lexer.h"
|
2014-05-04 05:20:34 +00:00
|
|
|
#include "lexerTables.h"
|
2016-01-24 05:50:12 +00:00
|
|
|
#include "listing.h"
|
|
|
|
#include "lookups.h"
|
2016-01-23 11:51:29 +00:00
|
|
|
#include "parserMisc.h"
|
2014-05-04 05:20:34 +00:00
|
|
|
|
|
|
|
extern int yylval;
|
|
|
|
extern int yydebug;
|
|
|
|
|
|
|
|
static char lineBuffer[LINE_BUFFER_SIZE] = { '\0' };
|
|
|
|
static int lineBufferPtr = 0;
|
|
|
|
|
|
|
|
#define getNextChar() (lineBuffer[lineBufferPtr] ? \
|
|
|
|
lineBuffer[lineBufferPtr++] : \
|
|
|
|
readAnotherLine())
|
|
|
|
/*int getNextChar() {int c;c=xgetNextChar();printf("read '%c'\n",c);return(c);}*/
|
|
|
|
|
|
|
|
#define oopsThatWasTheWrongChar(c) { if(lineBufferPtr) \
|
|
|
|
lineBuffer[--lineBufferPtr] = c; }
|
|
|
|
/*oopsThatWasTheWrongChar(c)char c;{printf("ungetting '%c'\n", c);xoopsThatWasTheWrongChar(c);}*/
|
|
|
|
|
|
|
|
#define isAlphabetic(c) (alphabeticCharacterTable[c])
|
|
|
|
#define isNumeric(c) (numericCharacterTable[c])
|
|
|
|
#define isAlphaNumeric(c) (alphaNumericCharacterTable[c])
|
|
|
|
|
2016-01-23 18:18:42 +00:00
|
|
|
int
|
|
|
|
yylex(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = lexer();
|
|
|
|
if (yydebug) {
|
|
|
|
printf("lexer returns ");
|
|
|
|
printToken(result);
|
|
|
|
printf(", value=%d (0x%x)\n", yylval, yylval);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexer(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if ((c = skipWhitespaceAndComments()) == EOF)
|
|
|
|
return(lexLiteral(c));
|
|
|
|
else
|
|
|
|
return((*lexDispatchTable[c])(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
initializeLexDispatchTable(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
for (c = 0; c < LEX_DISPATCH_TABLE_SIZE; c++) {
|
|
|
|
if (isAlphabetic(c) || c=='$')
|
|
|
|
lexDispatchTable[c] = lexIdentifier;
|
|
|
|
else if (isNumeric(c))
|
|
|
|
lexDispatchTable[c] = lexNumber;
|
|
|
|
else if (isMacrossLiteralCharacter(c))
|
|
|
|
lexDispatchTable[c] = lexLiteral;
|
|
|
|
else if (c == '\'')
|
|
|
|
lexDispatchTable[c] = lexCharacterConstant;
|
|
|
|
else if (c == '"')
|
|
|
|
lexDispatchTable[c] = lexStringConstant;
|
|
|
|
else
|
|
|
|
lexDispatchTable[c] = lexOperator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-01-23 18:18:42 +00:00
|
|
|
isMacrossLiteralCharacter(char c)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
return(c==':' || c==',' || c=='@' || c=='#' ||
|
|
|
|
c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' ||
|
|
|
|
c=='\n' || c==EOF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
snarfAlphanumericString(char c, char *buffer)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char *bufferPtr;
|
|
|
|
|
|
|
|
bufferPtr = buffer;
|
|
|
|
do {
|
|
|
|
if (bufferPtr < &buffer[MAX_NAME_SIZE])
|
|
|
|
*bufferPtr++ = c;
|
|
|
|
c = getNextChar();
|
|
|
|
} while (c!=EOF && isAlphaNumeric(c));
|
|
|
|
*bufferPtr = '\0';
|
|
|
|
oopsThatWasTheWrongChar(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
char nameBuffer[MAX_NAME_SIZE+1];
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexIdentifier(char c)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int hashValue;
|
|
|
|
|
|
|
|
snarfAlphanumericString(c, nameBuffer);
|
|
|
|
hashValue = hashString(nameBuffer);
|
|
|
|
if (yylval = lookupOpcode(nameBuffer, hashValue))
|
|
|
|
return(Opcode);
|
|
|
|
else if (yylval = lookupKeyword(nameBuffer, hashValue))
|
|
|
|
return(yylval);
|
|
|
|
else if ((yylval = lookupConditionCode(nameBuffer, hashValue)) !=
|
|
|
|
(int)NOT_FOUND_COND)
|
|
|
|
return(ConditionCode);
|
|
|
|
else if (yylval = lookupMacroName(nameBuffer, hashValue))
|
|
|
|
return(MacroName);
|
|
|
|
else {
|
|
|
|
yylval = (int) saveString(nameBuffer);
|
|
|
|
return(Identifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char numberBuffer[MAX_NAME_SIZE+1];
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexNumber(char c)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int base;
|
|
|
|
int start;
|
|
|
|
|
|
|
|
snarfAlphanumericString(c, numberBuffer);
|
|
|
|
if (numberBuffer[0] != '0') {
|
|
|
|
base = 10;
|
|
|
|
start = 0;
|
|
|
|
} else if (numberBuffer[1]=='b' || numberBuffer[1]=='B') {
|
|
|
|
base = 2;
|
|
|
|
start = 2;
|
|
|
|
} else if (numberBuffer[1]=='q' || numberBuffer[1]=='Q') {
|
|
|
|
base = 4;
|
|
|
|
start = 2;
|
|
|
|
} else if (numberBuffer[1]=='x' || numberBuffer[1]=='X') {
|
|
|
|
base = 16;
|
|
|
|
start = 2;
|
|
|
|
} else {
|
|
|
|
base = 8;
|
|
|
|
start = 1;
|
|
|
|
}
|
|
|
|
yylval = fancyAtoI(&numberBuffer[start], base);
|
|
|
|
return(Number);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
fancyAtoI(char *buffer, int base)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int value;
|
|
|
|
int digit;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
value = 0;
|
|
|
|
while (*buffer != '\0') {
|
|
|
|
if ((digit = digitValue(c = *buffer++)) >= base) {
|
|
|
|
error(DIGIT_OUT_OF_RADIX_ERROR, c, base);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
value = value*base + digit;
|
|
|
|
}
|
|
|
|
return(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
digitValue(char c)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (isNumeric(c))
|
|
|
|
return(c - '0');
|
|
|
|
else
|
|
|
|
return(toLowerCase(c) - 'a' + 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexLiteral(char c)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
static bool passedEnd = FALSE;
|
|
|
|
|
|
|
|
yylval = 0;
|
|
|
|
if (c == '\n') {
|
|
|
|
return(EOL);
|
|
|
|
} else if (c == EOF) {
|
|
|
|
if (passedEnd) {
|
|
|
|
return(0);
|
|
|
|
} else {
|
|
|
|
passedEnd = TRUE;
|
|
|
|
return(ENDFILE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexCharacterConstant(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
yylval = getStringCharacter(input);
|
|
|
|
if (getNextChar() != '\'') {
|
|
|
|
error(UNCLOSED_CHARACTER_CONSTANT_ERROR);
|
|
|
|
while ((c = getNextChar())!='\'' && c!='\n' && c!=EOF)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return(Number);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool escaped; /* true if last string character read was an escape
|
|
|
|
code. */
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
getStringCharacter(FILE *input)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
char *numberPtr;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
escaped = FALSE;
|
|
|
|
c = getNextChar();
|
|
|
|
if (c == '\\') {
|
|
|
|
escaped = TRUE;
|
|
|
|
c = getNextChar();
|
|
|
|
if (c == '^')
|
|
|
|
return(controlCharacter(getNextChar()));
|
|
|
|
else if ('0'<=c && c<='7') {
|
|
|
|
numberPtr = numberBuffer;
|
|
|
|
while ('0'<=c && c<='7') {
|
|
|
|
*numberPtr++ = c;
|
|
|
|
c = getNextChar();
|
|
|
|
}
|
|
|
|
*numberPtr = '\0';
|
|
|
|
oopsThatWasTheWrongChar(c);
|
|
|
|
result = fancyAtoI(numberBuffer, 8);
|
|
|
|
if (result > 0377)
|
|
|
|
error(OCTAL_CHARACTER_TOO_BIG_ERROR, result);
|
|
|
|
return (result % 0377);
|
|
|
|
} else
|
|
|
|
return(escapeCodes[c]);
|
|
|
|
} else
|
|
|
|
return(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
char stringBuffer[MAX_NAME_SIZE + 1];
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexStringConstant(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char *stringPtr;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
stringPtr = stringBuffer;
|
|
|
|
while (((c = getStringCharacter(input))!='"' && c!='\n' && c!=EOF)
|
|
|
|
|| escaped)
|
|
|
|
*stringPtr++ = c;
|
|
|
|
*stringPtr = '\0';
|
|
|
|
if (c=='\n' || c==EOF)
|
|
|
|
error(UNCLOSED_STRING_CONSTANT_ERROR);
|
|
|
|
yylval = (int)saveString(stringBuffer);
|
|
|
|
return(TextString);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
lexOperator(char firstC)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char secondC;
|
|
|
|
char thirdC;
|
|
|
|
int op;
|
|
|
|
int oper;
|
|
|
|
|
|
|
|
secondC = getNextChar();
|
|
|
|
for (op=0; operatorTable[op].first!='\0'; op++) {
|
|
|
|
if (operatorTable[op].first==firstC &&
|
|
|
|
operatorTable[op].second==secondC)
|
|
|
|
break;
|
|
|
|
else if (operatorTable[op].first==firstC &&
|
|
|
|
operatorTable[op].second=='\0') {
|
|
|
|
oopsThatWasTheWrongChar(secondC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (operatorTable[op].first == '\0') {
|
|
|
|
error(UNRECOGNIZED_SOMETHING_OR_OTHER_ERROR, firstC);
|
|
|
|
return(yylex());
|
|
|
|
}
|
|
|
|
/* kludge to deal with the two three-character operators: */
|
|
|
|
if ((oper=operatorTable[op].token)==RIGHT_SHIFT || oper==LEFT_SHIFT) {
|
|
|
|
thirdC = getNextChar();
|
|
|
|
if (thirdC == '=') {
|
|
|
|
yylval = (int)((oper==RIGHT_SHIFT) ?
|
|
|
|
RIGHT_SHIFT_ASSIGN : LEFT_SHIFT_ASSIGN);
|
|
|
|
return(ASSIGN);
|
|
|
|
} else
|
|
|
|
oopsThatWasTheWrongChar(thirdC);
|
|
|
|
}
|
|
|
|
yylval = (int)operatorTable[op].value;
|
|
|
|
return(operatorTable[op].token);
|
|
|
|
}
|
|
|
|
|
|
|
|
char
|
2016-01-23 18:18:42 +00:00
|
|
|
controlCharacter(char c)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
#define CONTROL_CHARACTER_MASK (~0100)
|
|
|
|
|
|
|
|
return(c & CONTROL_CHARACTER_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
char
|
2016-01-23 18:18:42 +00:00
|
|
|
skipWhitespaceAndComments(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while ((c=getNextChar())==' ' || c=='\t' || c=='/') {
|
|
|
|
if (c == '/') {
|
|
|
|
if ((c = getNextChar()) == '*') {
|
|
|
|
while (TRUE) {
|
|
|
|
while ((c = getNextChar()) != '*') {
|
|
|
|
if (c == EOF) {
|
|
|
|
error(UNCLOSED_COMMENT_ERROR);
|
|
|
|
return(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((c = getNextChar()) == '/') {
|
|
|
|
break;
|
|
|
|
} else if (c == '*') {
|
|
|
|
oopsThatWasTheWrongChar(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
oopsThatWasTheWrongChar(c);
|
|
|
|
return('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == ';') {
|
|
|
|
while ((c = getNextChar()) != '\n') {
|
|
|
|
if (c == EOF) {
|
|
|
|
error(UNCLOSED_LINE_COMMENT_ERROR);
|
|
|
|
return(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
popInputFileStack(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
fileNameListType *oldFile;
|
|
|
|
|
|
|
|
if (inputFileStack->nextFileName == NULL)
|
|
|
|
return(EOF);
|
|
|
|
oldFile = inputFileStack;
|
|
|
|
inputFileStack = inputFileStack->nextFileName;
|
|
|
|
qfree(oldFile);
|
|
|
|
currentLineNumber = inputFileStack->lineNumber;
|
|
|
|
currentFileName = inputFileStack->name;
|
|
|
|
cumulativeLineNumber--;
|
|
|
|
fclose(input);
|
|
|
|
if (!inputFileStack->openFlag) {
|
|
|
|
if ((inputFileStack->fildes = fopen(inputFileStack->name,
|
|
|
|
"r")) == NULL) {
|
|
|
|
fatalSystemError(UNABLE_TO_OPEN_INPUT_FILE_ERROR,
|
|
|
|
inputFileStack->name);
|
|
|
|
} else {
|
|
|
|
inputFileStack->openFlag = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input = inputFileStack->fildes;
|
|
|
|
if (includeNestingDepth > 0) {
|
|
|
|
includeNestingDepth--;
|
|
|
|
currentLineNumber--;
|
|
|
|
}
|
|
|
|
return(getNextChar());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
pushInputFileStack(stringType *fileName)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
fileNameListType *newFileName;
|
|
|
|
|
|
|
|
inputFileStack->lineNumber = currentLineNumber;
|
|
|
|
newFileName = typeAlloc(fileNameListType);
|
|
|
|
if ((input = newFileName->fildes = fopen(fileName, "r")) == NULL) {
|
|
|
|
fatalSystemError(UNABLE_TO_OPEN_INCLUDE_FILE_ERROR, fileName);
|
|
|
|
}
|
|
|
|
newFileName->openFlag = TRUE;
|
|
|
|
newFileName->nextFileName = inputFileStack;
|
|
|
|
inputFileStack = newFileName;
|
|
|
|
currentFileName = newFileName->name = fileName;
|
|
|
|
currentLineNumber = newFileName->lineNumber = 1;
|
|
|
|
includeNestingDepth++;
|
|
|
|
if (statementEvaluationDepth == 1)
|
|
|
|
oopsThatWasTheWrongChar('\n'); /* hack for line #'s */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
resynchronizeInput(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
while ((c = getNextChar())!='\n' && c!=EOF)
|
|
|
|
;
|
|
|
|
oopsThatWasTheWrongChar(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool longLineFlag = FALSE;
|
|
|
|
static bool previousLongLineFlag = FALSE;
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
saveLineForListing(stringType *line)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (!previousLongLineFlag) {
|
|
|
|
putw(currentLocationCounter.value, saveFileForPass2);
|
|
|
|
putw(includeNestingDepth, saveFileForPass2);
|
|
|
|
}
|
|
|
|
previousLongLineFlag = longLineFlag;
|
|
|
|
fputs(line, saveFileForPass2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
saveEOLForListing(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putw(-1, saveFileForPass2);
|
|
|
|
putw(includeNestingDepth, saveFileForPass2);
|
|
|
|
fputs("\n", saveFileForPass2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
saveIndexForListing(statementKindType kindOfStatement, int cumulativeLineNumber)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (!amExpanding() || !notListable(kindOfStatement)) {
|
|
|
|
putw(kindOfStatement, indexFileForPass2);
|
|
|
|
putw(currentLocationCounter.value, indexFileForPass2);
|
|
|
|
if (amExpanding())
|
|
|
|
putw(-cumulativeLineNumber, indexFileForPass2);
|
|
|
|
else
|
|
|
|
putw( cumulativeLineNumber, indexFileForPass2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
saveEndMifForListing(int cumulativeLineNumber)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putw(MIF_STATEMENT, indexFileForPass2);
|
|
|
|
putw(-1, indexFileForPass2);
|
|
|
|
if (amExpanding())
|
|
|
|
putw(-cumulativeLineNumber, indexFileForPass2);
|
|
|
|
else
|
|
|
|
putw(cumulativeLineNumber, indexFileForPass2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
saveListingOff(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
saveIndexForListing(-1, cumulativeLineNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-23 18:18:42 +00:00
|
|
|
saveListingOn(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (currentCodeMode == ABSOLUTE_BUFFER)
|
|
|
|
saveIndexForListing(-1, cumulativeLineNumber);
|
|
|
|
else
|
|
|
|
saveIndexForListing(-2, cumulativeLineNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2016-01-23 18:18:42 +00:00
|
|
|
myfgets(char *buffer, int length, FILE *stream)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
result = buffer;
|
|
|
|
while (length-- > 1 && (c = getc(stream)) != EOF && c != '\n')
|
|
|
|
*buffer++ = c;
|
|
|
|
if (c == EOF) {
|
|
|
|
*result = '\0';
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
if (length > 0)
|
|
|
|
*buffer++ = c;
|
|
|
|
if (length == 0 && c != '\n')
|
|
|
|
longLineFlag = TRUE;
|
|
|
|
else
|
|
|
|
longLineFlag = FALSE;
|
|
|
|
*buffer = '\0';
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-01-23 18:18:42 +00:00
|
|
|
readAnotherLine(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (myfgets(lineBuffer, LINE_BUFFER_SIZE, input)) {
|
|
|
|
if (amListing())
|
|
|
|
saveLineForListing(lineBuffer);
|
|
|
|
lineBufferPtr = 1;
|
|
|
|
result = lineBuffer[0];
|
|
|
|
} else {
|
|
|
|
result = popInputFileStack();
|
|
|
|
}
|
|
|
|
currentLineNumber++;
|
|
|
|
cumulativeLineNumber++;
|
|
|
|
return(result);
|
|
|
|
}
|