char *DEH_ReadLine(deh_context_t *context) { int c; int pos; for (pos = 0;;) { c = DEH_GetChar(context); if (c < 0) { // end of file return NULL; } // cope with lines of any length: increase the buffer size if (pos >= context->readbuffer_size) { IncreaseReadBuffer(context); } if (c == '\n') { // end of line: a full line has been read context->readbuffer[pos] = '\0'; break; } else if (c != '\0') { // normal character; don't allow NUL characters to be // added. context->readbuffer[pos] = (char) c; ++pos; } } return context->readbuffer; }
static void *DEH_TextStart(deh_context_t *context, char *line) { char *repl_text; char *orig_text; int orig_offset, repl_len; int i; if (sscanf(line, "Text %i %i", &orig_offset, &repl_len) != 2) { DEH_Warning(context, "Parse error on section start"); return NULL; } repl_text = malloc(repl_len + 1); // read in the "to" text for (i=0; i<repl_len; ++i) { int c; c = DEH_GetChar(context); repl_text[i] = c; } repl_text[repl_len] = '\0'; // We don't support all strings, but at least recognise them: if (StringIsUnsupported(orig_offset)) { DEH_Warning(context, "Unsupported string replacement: %i", orig_offset); } // Find the string to replace: else if (!GetStringByOffset(orig_offset, &orig_text)) { SuggestOtherVersions(orig_offset); DEH_Error(context, "Unknown string offset: %i", orig_offset); } // Only allow string replacements that are possible in Vanilla Doom. // Chocolate Doom is unforgiving! else if (!deh_allow_long_strings && repl_len > MaxStringLength(strlen(orig_text))) { DEH_Error(context, "Replacement string is longer than the maximum " "possible in heretic.exe"); } else { // Success. DEH_AddStringReplacement(orig_text, repl_text); } // We must always free the replacement text. free(repl_text); return NULL; }
char *DEH_ReadLine(deh_context_t *context, boolean extended) { int c; int pos; boolean escaped = false; for (pos = 0;;) { c = DEH_GetChar(context); if (c < 0 && pos == 0) { // end of file return NULL; } // cope with lines of any length: increase the buffer size if (pos >= context->readbuffer_size) { IncreaseReadBuffer(context); } // extended string support if (extended && c == '\\') { c = DEH_GetChar(context); // "\n" in the middle of a string indicates an internal linefeed if (c == 'n') { context->readbuffer[pos] = '\n'; ++pos; continue; } // values to be assigned may be split onto multiple lines by ending // each line that is to be continued with a backslash if (c == '\n') { escaped = true; continue; } } // blanks before the backslash are included in the string // but indentation after the linefeed is not if (escaped && c >= 0 && isspace(c) && c != '\n') { continue; } else { escaped = false; } if (c == '\n' || c < 0) { // end of line: a full line has been read context->readbuffer[pos] = '\0'; break; } else if (c != '\0') { // normal character; don't allow NUL characters to be // added. context->readbuffer[pos] = (char) c; ++pos; } } return context->readbuffer; }