diff options
Diffstat (limited to 'engines/glk/alan3/scan.cpp')
-rw-r--r-- | engines/glk/alan3/scan.cpp | 276 |
1 files changed, 138 insertions, 138 deletions
diff --git a/engines/glk/alan3/scan.cpp b/engines/glk/alan3/scan.cpp index 9eb40d99a6..8f823def98 100644 --- a/engines/glk/alan3/scan.cpp +++ b/engines/glk/alan3/scan.cpp @@ -54,189 +54,189 @@ static char *token = NULL; /*======================================================================*/ void forceNewPlayerInput() { - setEndOfArray(&playerWords[currentWordIndex]); + setEndOfArray(&playerWords[currentWordIndex]); } /*----------------------------------------------------------------------*/ static void unknown(char tok[]) { - char *str = strdup(tok); - Parameter *messageParameters = newParameterArray(); + char *str = strdup(tok); + Parameter *messageParameters = newParameterArray(); - addParameterForString(messageParameters, str); - printMessageWithParameters(M_UNKNOWN_WORD, messageParameters); + addParameterForString(messageParameters, str); + printMessageWithParameters(M_UNKNOWN_WORD, messageParameters); deallocate(messageParameters); - free(str); - abortPlayerCommand(); + free(str); + abortPlayerCommand(); } /*----------------------------------------------------------------------*/ static int number(char tok[]) { - int i; - - (void)sscanf(tok, "%d", &i); - return i; + int i; + + (void)sscanf(tok, "%d", &i); + return i; } /*----------------------------------------------------------------------*/ static int lookup(char wrd[]) { - int i; - - for (i = 0; !isEndOfArray(&dictionary[i]); i++) { - if (compareStrings(wrd, (char *) pointerTo(dictionary[i].string)) == 0) { - return (i); - } - } - unknown(wrd); - return (int)EOD; + int i; + + for (i = 0; !isEndOfArray(&dictionary[i]); i++) { + if (compareStrings(wrd, (char *) pointerTo(dictionary[i].string)) == 0) { + return (i); + } + } + unknown(wrd); + return (int)EOD; } /*----------------------------------------------------------------------*/ static bool isWordCharacter(int ch) { - return isISOLetter(ch) || isdigit(ch) || ch == '\'' || ch == '-' || ch == '_'; + return isISOLetter(ch) || isdigit(ch) || ch == '\'' || ch == '-' || ch == '_'; } /*----------------------------------------------------------------------*/ static char *gettoken(char *txtBuf) { - static char *marker; - static char oldch; - - if (txtBuf == NULL) - *marker = oldch; - else - marker = txtBuf; - while (*marker != '\0' && isSpace(*marker) && *marker != '\n') - marker++; - txtBuf = marker; - if (isISOLetter(*marker)) - while (*marker && isWordCharacter(*marker)) - marker++; - else if (isdigit((int)*marker)) - while (isdigit((int)*marker)) - marker++; - else if (*marker == '\"') { - marker++; - while (*marker != '\"') - marker++; - marker++; - } else if (*marker == '\0' || *marker == '\n' || *marker == ';') - return NULL; - else - marker++; - oldch = *marker; - *marker = '\0'; - return txtBuf; + static char *marker; + static char oldch; + + if (txtBuf == NULL) + *marker = oldch; + else + marker = txtBuf; + while (*marker != '\0' && isSpace(*marker) && *marker != '\n') + marker++; + txtBuf = marker; + if (isISOLetter(*marker)) + while (*marker && isWordCharacter(*marker)) + marker++; + else if (isdigit((int)*marker)) + while (isdigit((int)*marker)) + marker++; + else if (*marker == '\"') { + marker++; + while (*marker != '\"') + marker++; + marker++; + } else if (*marker == '\0' || *marker == '\n' || *marker == ';') + return NULL; + else + marker++; + oldch = *marker; + *marker = '\0'; + return txtBuf; } /*----------------------------------------------------------------------*/ // TODO replace dependency to exe.c with injection of quitGame() and undo() static void getLine(void) { - para(); - do { - statusline(); - if (header->prompt) { - anyOutput = FALSE; - interpret(header->prompt); - if (anyOutput) - printAndLog(" "); - needSpace = FALSE; - } else - printAndLog("> "); - - if (!readline(buf)) { - newline(); - quitGame(); - } - - getPageSize(); - anyOutput = FALSE; - if (transcriptOption || logOption) { - // TODO: Refactor out the logging to log.c? + para(); + do { + statusline(); + if (header->prompt) { + anyOutput = FALSE; + interpret(header->prompt); + if (anyOutput) + printAndLog(" "); + needSpace = FALSE; + } else + printAndLog("> "); + + if (!readline(buf)) { + newline(); + quitGame(); + } + + getPageSize(); + anyOutput = FALSE; + if (transcriptOption || logOption) { + // TODO: Refactor out the logging to log.c? g_vm->glk_put_string_stream(logFile, buf); g_vm->glk_put_char_stream(logFile, '\n'); - } - /* If the player input an empty command he forfeited his command */ + } + /* If the player input an empty command he forfeited his command */ #ifdef TODO if (strlen(buf) == 0) { - clearWordList(playerWords); - longjmp(forfeitLabel, 0); - } + clearWordList(playerWords); + longjmp(forfeitLabel, 0); + } #else ::error("TODO: empty command"); #endif - - strcpy(isobuf, buf); - token = gettoken(isobuf); - if (token != NULL) { - if (strcmp("debug", token) == 0 && header->debug) { - debugOption = TRUE; - debug(FALSE, 0, 0); - token = NULL; - } else if (strcmp("undo", token) == 0) { - token = gettoken(NULL); - if (token != NULL) /* More tokens? */ - error(M_WHAT); - undo(); - } - } - } while (token == NULL); - eol = FALSE; + + strcpy(isobuf, buf); + token = gettoken(isobuf); + if (token != NULL) { + if (strcmp("debug", token) == 0 && header->debug) { + debugOption = TRUE; + debug(FALSE, 0, 0); + token = NULL; + } else if (strcmp("undo", token) == 0) { + token = gettoken(NULL); + if (token != NULL) /* More tokens? */ + error(M_WHAT); + undo(); + } + } + } while (token == NULL); + eol = FALSE; } /*======================================================================*/ void scan(void) { - int i; - int w; - - if (continued) { - /* Player used '.' to separate commands. Read next */ - para(); - token = gettoken(NULL); /* Or did he just finish the command with a full stop? */ - if (token == NULL) - getLine(); - continued = FALSE; - } else - getLine(); - - freeLiterals(); - playerWords[0].code = 0; // TODO This means what? - i = 0; - do { - ensureSpaceForPlayerWords(i+1); - playerWords[i].start = token; - playerWords[i].end = strchr(token, '\0'); - if (isISOLetter(token[0])) { - w = lookup(token); - if (!isNoise(w)) - playerWords[i++].code = w; - } else if (isdigit((int)token[0]) || token[0] == '\"') { - if (isdigit((int)token[0])) { - createIntegerLiteral(number(token)); - } else { - char *unquotedString = strdup(token); - unquotedString[strlen(token) - 1] = '\0'; - createStringLiteral(&unquotedString[1]); - free(unquotedString); - } - playerWords[i++].code = dictionarySize + litCount; /* Word outside dictionary = literal */ - } else if (token[0] == ',') { - playerWords[i++].code = conjWord; - } else if (token[0] == '.') { - continued = TRUE; - setEndOfArray(&playerWords[i]); - eol = TRUE; - break; - } else - unknown(token); - setEndOfArray(&playerWords[i]); - eol = (token = gettoken(NULL)) == NULL; - } while (!eol); + int i; + int w; + + if (continued) { + /* Player used '.' to separate commands. Read next */ + para(); + token = gettoken(NULL); /* Or did he just finish the command with a full stop? */ + if (token == NULL) + getLine(); + continued = FALSE; + } else + getLine(); + + freeLiterals(); + playerWords[0].code = 0; // TODO This means what? + i = 0; + do { + ensureSpaceForPlayerWords(i + 1); + playerWords[i].start = token; + playerWords[i].end = strchr(token, '\0'); + if (isISOLetter(token[0])) { + w = lookup(token); + if (!isNoise(w)) + playerWords[i++].code = w; + } else if (isdigit((int)token[0]) || token[0] == '\"') { + if (isdigit((int)token[0])) { + createIntegerLiteral(number(token)); + } else { + char *unquotedString = strdup(token); + unquotedString[strlen(token) - 1] = '\0'; + createStringLiteral(&unquotedString[1]); + free(unquotedString); + } + playerWords[i++].code = dictionarySize + litCount; /* Word outside dictionary = literal */ + } else if (token[0] == ',') { + playerWords[i++].code = conjWord; + } else if (token[0] == '.') { + continued = TRUE; + setEndOfArray(&playerWords[i]); + eol = TRUE; + break; + } else + unknown(token); + setEndOfArray(&playerWords[i]); + eol = (token = gettoken(NULL)) == NULL; + } while (!eol); } } // End of namespace Alan3 |