📄 input-scrub.c
字号:
input_scrub_include_sb (from, position, is_expansion) sb *from; char *position; int is_expansion;{ if (macro_nest > max_macro_nest) as_fatal (_("macros nested too deeply")); ++macro_nest;#ifdef md_macro_start if (is_expansion) { md_macro_start (); }#endif next_saved_file = input_scrub_push (position); sb_new (&from_sb); from_sb_is_expansion = is_expansion; if (from->len >= 1 && from->ptr[0] != '\n') { /* Add the sentinel required by read.c. */ sb_add_char (&from_sb, '\n'); } sb_add_sb (&from_sb, from); sb_index = 1; /* These variables are reset by input_scrub_push. Restore them since we are, after all, still at the same point in the file. */ logical_input_line = next_saved_file->logical_input_line; logical_input_file = next_saved_file->logical_input_file;}voidinput_scrub_close (){ input_file_close ();}char *input_scrub_next_buffer (bufp) char **bufp;{ register char *limit; /*->just after last char of buffer. */ if (sb_index >= 0) { if (sb_index >= from_sb.len) { sb_kill (&from_sb); if (from_sb_is_expansion ) { cond_finish_check (macro_nest);#ifdef md_macro_end /* Allow the target to clean up per-macro expansion data. */ md_macro_end ();#endif } --macro_nest; partial_where = NULL; if (next_saved_file != NULL) *bufp = input_scrub_pop (next_saved_file); return partial_where; } partial_where = from_sb.ptr + from_sb.len; partial_size = 0; *bufp = from_sb.ptr + sb_index; sb_index = from_sb.len; return partial_where; } *bufp = buffer_start + BEFORE_SIZE; if (partial_size) { memcpy (buffer_start + BEFORE_SIZE, partial_where, (unsigned int) partial_size); memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE); } limit = input_file_give_next_buffer (buffer_start + BEFORE_SIZE + partial_size); if (limit) { register char *p; /* Find last newline. */ for (p = limit - 1; *p != '\n'; --p) ; ++p; while (p <= buffer_start + BEFORE_SIZE) { int limoff; limoff = limit - buffer_start; buffer_length += input_file_buffer_size (); buffer_start = xrealloc (buffer_start, (BEFORE_SIZE + 2 * buffer_length + AFTER_SIZE)); *bufp = buffer_start + BEFORE_SIZE; limit = input_file_give_next_buffer (buffer_start + limoff); if (limit == NULL) { as_warn (_("partial line at end of file ignored")); partial_where = NULL; if (next_saved_file) *bufp = input_scrub_pop (next_saved_file); return NULL; } for (p = limit - 1; *p != '\n'; --p) ; ++p; } partial_where = p; partial_size = limit - p; memcpy (save_source, partial_where, (int) AFTER_SIZE); memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE); } else { partial_where = 0; if (partial_size > 0) { as_warn (_("Partial line at end of file ignored")); } /* Tell the listing we've finished the file. */ LISTING_EOF (); /* If we should pop to another file at EOF, do it. */ if (next_saved_file) { *bufp = input_scrub_pop (next_saved_file); /* Pop state */ /* partial_where is now correct to return, since we popped it. */ } } return (partial_where);}/* The remaining part of this file deals with line numbers, error messages and so on. Return TRUE if we opened any file. */intseen_at_least_1_file (){ return (physical_input_file != NULL);}voidbump_line_counters (){ if (sb_index < 0) { ++physical_input_line; if (logical_input_line >= 0) ++logical_input_line; }}/* Tells us what the new logical line number and file are. If the line_number is -1, we don't change the current logical line number. If it is -2, we decrement the logical line number (this is to support the .appfile pseudo-op inserted into the stream by do_scrub_chars). If the fname is NULL, we don't change the current logical file name. Returns nonzero if the filename actually changes. */intnew_logical_line (fname, line_number) char *fname; /* DON'T destroy it! We point to it! */ int line_number;{ if (line_number >= 0) logical_input_line = line_number; else if (line_number == -2 && logical_input_line > 0) --logical_input_line; if (fname && (logical_input_file == NULL || strcmp (logical_input_file, fname))) { logical_input_file = fname; return 1; } else return 0;}/* Return the current file name and line number. namep should be char * const *, but there are compilers which screw up declarations like that, and it's easier to avoid it. */voidas_where (namep, linep) char **namep; unsigned int *linep;{ if (logical_input_file != NULL && (linep == NULL || logical_input_line >= 0)) { *namep = logical_input_file; if (linep != NULL) *linep = logical_input_line; } else if (physical_input_file != NULL) { *namep = physical_input_file; if (linep != NULL) *linep = physical_input_line; } else { *namep = 0; if (linep != NULL) *linep = 0; }}/* Output to given stream how much of line we have scanned so far. Assumes we have scanned up to and including input_line_pointer. No free '\n' at end of line. */voidas_howmuch (stream) FILE *stream; /* Opened for write please. */{ register char *p; /* Scan input line. */ for (p = input_line_pointer - 1; *p != '\n'; --p) { } ++p; /* p->1st char of line. */ for (; p <= input_line_pointer; p++) { /* Assume ASCII. EBCDIC & other micro-computer char sets ignored. */ as_1_char ((unsigned char) *p, stream); }}static voidas_1_char (c, stream) unsigned int c; FILE *stream;{ if (c > 127) { (void) putc ('%', stream); c -= 128; } if (c < 32) { (void) putc ('^', stream); c += '@'; } (void) putc (c, stream);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -