static char *read_line(void) { FILE *f; char *line; int newline; re_read: if(file_stack_idx < 0) ICE("file stack idx = 0 on read()"); f = file_stack[file_stack_idx].file; line = fline(f, &newline); if(!line){ if(ferror(f)) die("read():"); fclose(f); if(file_stack_idx > 0){ free(dirname_pop()); preproc_pop(); goto re_read; }else{ if(!prev_newline){ CPP_WARN(WNEWLINE, "no newline at end-of-file"); } } return NULL; } prev_newline = newline; current_line++; return line; }
char *splice_line(void) { static int n_nls; char *last; int join; if(n_nls){ n_nls--; return ustrdup(""); } last = NULL; join = 0; for(;;){ FILE *f; int len; char *line; re_read: if(file_stack_idx < 0) ICE("file stack idx = 0 on read()"); f = file_stack[file_stack_idx].file; line = fline(f); if(!line){ if(ferror(f)) die("read():"); fclose(f); if(file_stack_idx > 0){ free(dirname_pop()); preproc_pop(); goto re_read; } return NULL; } current_line++; if(join){ join = 0; last = urealloc(last, strlen(last) + strlen(line) + 1); strcpy(last + strlen(last), line); free(line); line = last; } len = strlen(line); if(len && line[len - 1] == '\\'){ line[len - 1] = '\0'; join = 1; last = line; n_nls++; }else{ return line; } } }