int test_charutil(void) { char *v = strdup("abc#def"); StripComment(v); if (strcmp(v, "abc#def") != 0) { printf("FAILURE: comment stripper stripped when it shouldn't\n"); return 1; } v = strdup("abc #def"); StripComment(v); if (strcmp(v, "abc ") != 0) { printf("FAILURE: comment stripper should've stripped\n"); return 1; } return 0; }
bool ppFile::GetLine(std::string &line) { line = std::string(""); while (true) { char buf[LINE_WIDTH]; errlineno = lineno + 1; if (!ReadLine(buf)) { cond.CheckErrors(); return false; } StripComment(buf); if (trigraphs) StripTrigraphs(buf); char *p = strrchr(buf, '\\'); if (p) { char *q = p; p++; while (*p) { if (!isspace(*p)) { break; } p++; } if (*p) { line= line + buf; break; } *q = '\0'; line = line + buf; } else { line = line + buf; if (!inComment) break; } } line = line + " ";// trailing spaced needed for function argument matching in replacesegment return true; }
bool InputFile::GetLine(std::string &line) { char buf[LINE_WIDTH]; while (inComment) { int m = ReadLine(buf); if (!m) return false; m = StripComment(buf); if (m) { buf[m] = 0; break; } } line = std::string(buf); return true; }
/************************************************************************** * * EZParseGetLine * * SYNOPSIS * short EZParseGetLine (FILE *fp, char *linebuff, short maxline) * * PURPOSE * Get a line from specfied file. Strip ';' comments. * Skip blank lines and lines that start with '*' or '#'. * Also remove end-of-line. * * INPUT * * * EFFECTS * * * RETURN VALUE * > 0 = okay. * = 0 = End of File. * < 0 = error. * * BUGS * * * HISTORY * * * SEE ALSO * */ short EZParseGetLine (FILE *fp, char *linebuff, short maxline, short strip) { char *s; char *d; char *newline; short len; len = 0; newline = linebuff; while (fgets (newline, maxline - len, fp)) { ezpt->LineNo++; s = linebuff; len = strlen (s); if (len) { if (len > 1 && s[len-2] == '\\') { s[len-2] = '\0'; newline = s+len-2; } else { if (strip) { StripComment (s); } d = TrimWhiteSpace (s); if (strip) { s = d; } if ((ezpt->KeepBlanks || strlen (s)) && ((*s != '*' && *s != '#') || !strip)) { d = linebuff; while (*s) { *d++ = *s++; } *d = '\0'; return 1; } len = 0; newline = linebuff; } } } if (feof (fp)) { return 0; } return (-1); } /* EZParseGetLine */
T_void CompileFile(T_byte8 *p_filename) { FILE *fp ; T_byte8 buffer[300] ; T_word16 place ; T_byte8 firstWord[80] ; printf("Compiling %s:\n", p_filename) ; fp = fopen(p_filename, "r") ; if (fp == NULL) { printf("Cannot open file %s\n", p_filename) ; exit(2) ; } fgets(buffer, 300, fp) ; while (!feof(fp)) { StripComment(buffer) ; printf("[%s]\n", buffer) ; if (buffer[0]) { if (isspace(buffer[0])) { /* Command. */ CompileCommand(buffer) ; } else if (isdigit(buffer[0])) { /* place. */ place = atoi(buffer) ; printf("place: %d\n", place) ; if (place >= MAX_PLACES) { printf("Error! Place %d too big on line %d\n", place, G_line) ; G_errors++ ; } else { if (G_places[place] == 0xFFFF) { G_places[place] = G_place ; } else { printf("Error! Place %d already taken (line %d)\n", place, G_line) ; G_errors++ ; } } } else { /* event or directive. */ firstWord[0] = '\0' ; sscanf(buffer, "%s", firstWord) ; if (strcmp(firstWord, "defvar")==0) { CompileDefvar(buffer) ; } else if (strcmp(firstWord, "defnum") == 0) { CompileDefnum(buffer) ; } else if (strcmp(firstWord, "include") == 0) { CompileInclude(buffer) ; } else { if (firstWord[strlen(firstWord)-1] == ':') { CompileEvent(firstWord) ; } else { printf("Error! Unknown directive, line %d\n", G_line) ; G_errors++ ; } } } } fgets(buffer, 300, fp) ; G_line++ ; } fclose(fp) ; }