12159047fSniklas /* input_scrub.c - Break up input buffers into whole numbers of lines. 2*b55d4692Sfgsch Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3*b55d4692Sfgsch 2000 4b305b0f1Sespie Free Software Foundation, Inc. 52159047fSniklas 62159047fSniklas This file is part of GAS, the GNU Assembler. 72159047fSniklas 82159047fSniklas GAS is free software; you can redistribute it and/or modify 92159047fSniklas it under the terms of the GNU General Public License as published by 102159047fSniklas the Free Software Foundation; either version 2, or (at your option) 112159047fSniklas any later version. 122159047fSniklas 132159047fSniklas GAS is distributed in the hope that it will be useful, 142159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of 152159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 162159047fSniklas GNU General Public License for more details. 172159047fSniklas 182159047fSniklas You should have received a copy of the GNU General Public License 19b305b0f1Sespie along with GAS; see the file COPYING. If not, write to the Free 20b305b0f1Sespie Software Foundation, 59 Temple Place - Suite 330, Boston, MA 21b305b0f1Sespie 02111-1307, USA. */ 222159047fSniklas 232159047fSniklas #include <errno.h> /* Need this to make errno declaration right */ 242159047fSniklas #include "as.h" 252159047fSniklas #include "input-file.h" 262159047fSniklas #include "sb.h" 27b305b0f1Sespie #include "listing.h" 282159047fSniklas 292159047fSniklas /* 302159047fSniklas * O/S independent module to supply buffers of sanitised source code 312159047fSniklas * to rest of assembler. We get sanitised input data of arbitrary length. 322159047fSniklas * We break these buffers on line boundaries, recombine pieces that 332159047fSniklas * were broken across buffers, and return a buffer of full lines to 342159047fSniklas * the caller. 352159047fSniklas * The last partial line begins the next buffer we build and return to caller. 362159047fSniklas * The buffer returned to caller is preceeded by BEFORE_STRING and followed 372159047fSniklas * by AFTER_STRING, as sentinels. The last character before AFTER_STRING 382159047fSniklas * is a newline. 392159047fSniklas * Also looks after line numbers, for e.g. error messages. 402159047fSniklas */ 412159047fSniklas 422159047fSniklas /* 432159047fSniklas * We don't care how filthy our buffers are, but our callers assume 442159047fSniklas * that the following sanitation has already been done. 452159047fSniklas * 462159047fSniklas * No comments, reduce a comment to a space. 472159047fSniklas * Reduce a tab to a space unless it is 1st char of line. 482159047fSniklas * All multiple tabs and spaces collapsed into 1 char. Tab only 492159047fSniklas * legal if 1st char of line. 502159047fSniklas * # line file statements converted to .line x;.file y; statements. 512159047fSniklas * Escaped newlines at end of line: remove them but add as many newlines 522159047fSniklas * to end of statement as you removed in the middle, to synch line numbers. 532159047fSniklas */ 542159047fSniklas 552159047fSniklas #define BEFORE_STRING ("\n") 562159047fSniklas #define AFTER_STRING ("\0") /* memcpy of 0 chars might choke. */ 572159047fSniklas #define BEFORE_SIZE (1) 582159047fSniklas #define AFTER_SIZE (1) 592159047fSniklas 602159047fSniklas static char *buffer_start; /*->1st char of full buffer area. */ 612159047fSniklas static char *partial_where; /*->after last full line in buffer. */ 622159047fSniklas static int partial_size; /* >=0. Number of chars in partial line in buffer. */ 63*b55d4692Sfgsch 64*b55d4692Sfgsch /* Because we need AFTER_STRING just after last full line, it clobbers 65*b55d4692Sfgsch 1st part of partial line. So we preserve 1st part of partial line 66*b55d4692Sfgsch here. */ 672159047fSniklas static char save_source[AFTER_SIZE]; 68*b55d4692Sfgsch 69*b55d4692Sfgsch /* What is the largest size buffer that input_file_give_next_buffer() 70*b55d4692Sfgsch could return to us? */ 71*b55d4692Sfgsch static unsigned int buffer_length; 722159047fSniklas 732159047fSniklas /* The index into an sb structure we are reading from. -1 if none. */ 742159047fSniklas static int sb_index = -1; 752159047fSniklas 762159047fSniklas /* If we are reading from an sb structure, this is it. */ 772159047fSniklas static sb from_sb; 782159047fSniklas 79b305b0f1Sespie /* Should we do a conditional check on from_sb? */ 80b305b0f1Sespie static int from_sb_is_expansion = 1; 81b305b0f1Sespie 822159047fSniklas /* The number of nested sb structures we have included. */ 83b305b0f1Sespie int macro_nest; 842159047fSniklas 852159047fSniklas /* We can have more than one source file open at once, though the info for all 862159047fSniklas but the latest one are saved off in a struct input_save. These files remain 872159047fSniklas open, so we are limited by the number of open files allowed by the 882159047fSniklas underlying OS. We may also sequentially read more than one source file in an 892159047fSniklas assembly. */ 902159047fSniklas 912159047fSniklas /* We must track the physical file and line number for error messages. We also 922159047fSniklas track a "logical" file and line number corresponding to (C?) compiler 932159047fSniklas source line numbers. Whenever we open a file we must fill in 942159047fSniklas physical_input_file. So if it is NULL we have not opened any files yet. */ 952159047fSniklas 962159047fSniklas static char *physical_input_file; 972159047fSniklas static char *logical_input_file; 982159047fSniklas 992159047fSniklas typedef unsigned int line_numberT; /* 1-origin line number in a source file. */ 1002159047fSniklas /* A line ends in '\n' or eof. */ 1012159047fSniklas 1022159047fSniklas static line_numberT physical_input_line; 1032159047fSniklas static int logical_input_line; 1042159047fSniklas 1052159047fSniklas /* Struct used to save the state of the input handler during include files */ 106*b55d4692Sfgsch struct input_save { 1072159047fSniklas char * buffer_start; 1082159047fSniklas char * partial_where; 1092159047fSniklas int partial_size; 1102159047fSniklas char save_source[AFTER_SIZE]; 1112159047fSniklas unsigned int buffer_length; 1122159047fSniklas char * physical_input_file; 1132159047fSniklas char * logical_input_file; 1142159047fSniklas line_numberT physical_input_line; 1152159047fSniklas int logical_input_line; 1162159047fSniklas int sb_index; 1172159047fSniklas sb from_sb; 118b305b0f1Sespie int from_sb_is_expansion; /* Should we do a conditional check? */ 119*b55d4692Sfgsch struct input_save * next_saved_file; /* Chain of input_saves. */ 120*b55d4692Sfgsch char * input_file_save; /* Saved state of input routines. */ 121*b55d4692Sfgsch char * saved_position; /* Caller's saved position in buf. */ 1222159047fSniklas }; 1232159047fSniklas 1242159047fSniklas static struct input_save *input_scrub_push PARAMS ((char *saved_position)); 1252159047fSniklas static char *input_scrub_pop PARAMS ((struct input_save *arg)); 1262159047fSniklas static void as_1_char PARAMS ((unsigned int c, FILE * stream)); 1272159047fSniklas 1282159047fSniklas /* Saved information about the file that .include'd this one. When we hit EOF, 1292159047fSniklas we automatically pop to that file. */ 1302159047fSniklas 1312159047fSniklas static struct input_save *next_saved_file; 1322159047fSniklas 1332159047fSniklas /* Push the state of input reading and scrubbing so that we can #include. 1342159047fSniklas The return value is a 'void *' (fudged for old compilers) to a save 1352159047fSniklas area, which can be restored by passing it to input_scrub_pop(). */ 136*b55d4692Sfgsch 1372159047fSniklas static struct input_save * 1382159047fSniklas input_scrub_push (saved_position) 1392159047fSniklas char *saved_position; 1402159047fSniklas { 1412159047fSniklas register struct input_save *saved; 1422159047fSniklas 1432159047fSniklas saved = (struct input_save *) xmalloc (sizeof *saved); 1442159047fSniklas 1452159047fSniklas saved->saved_position = saved_position; 1462159047fSniklas saved->buffer_start = buffer_start; 1472159047fSniklas saved->partial_where = partial_where; 1482159047fSniklas saved->partial_size = partial_size; 1492159047fSniklas saved->buffer_length = buffer_length; 1502159047fSniklas saved->physical_input_file = physical_input_file; 1512159047fSniklas saved->logical_input_file = logical_input_file; 1522159047fSniklas saved->physical_input_line = physical_input_line; 1532159047fSniklas saved->logical_input_line = logical_input_line; 1542159047fSniklas saved->sb_index = sb_index; 1552159047fSniklas saved->from_sb = from_sb; 156b305b0f1Sespie saved->from_sb_is_expansion = from_sb_is_expansion; 1572159047fSniklas memcpy (saved->save_source, save_source, sizeof (save_source)); 1582159047fSniklas saved->next_saved_file = next_saved_file; 1592159047fSniklas saved->input_file_save = input_file_push (); 1602159047fSniklas 1612159047fSniklas input_file_begin (); /* Reinitialize! */ 1622159047fSniklas logical_input_line = -1; 1632159047fSniklas logical_input_file = (char *) NULL; 1642159047fSniklas buffer_length = input_file_buffer_size (); 1652159047fSniklas sb_index = -1; 1662159047fSniklas 1672159047fSniklas buffer_start = xmalloc ((BEFORE_SIZE + buffer_length + buffer_length + AFTER_SIZE)); 1682159047fSniklas memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE); 1692159047fSniklas 1702159047fSniklas return saved; 171*b55d4692Sfgsch } 1722159047fSniklas 1732159047fSniklas static char * 1742159047fSniklas input_scrub_pop (saved) 1752159047fSniklas struct input_save *saved; 1762159047fSniklas { 1772159047fSniklas char *saved_position; 1782159047fSniklas 1792159047fSniklas input_scrub_end (); /* Finish off old buffer */ 1802159047fSniklas 1812159047fSniklas input_file_pop (saved->input_file_save); 1822159047fSniklas saved_position = saved->saved_position; 1832159047fSniklas buffer_start = saved->buffer_start; 1842159047fSniklas buffer_length = saved->buffer_length; 1852159047fSniklas physical_input_file = saved->physical_input_file; 1862159047fSniklas logical_input_file = saved->logical_input_file; 1872159047fSniklas physical_input_line = saved->physical_input_line; 1882159047fSniklas logical_input_line = saved->logical_input_line; 1892159047fSniklas sb_index = saved->sb_index; 1902159047fSniklas from_sb = saved->from_sb; 191b305b0f1Sespie from_sb_is_expansion = saved->from_sb_is_expansion; 1922159047fSniklas partial_where = saved->partial_where; 1932159047fSniklas partial_size = saved->partial_size; 1942159047fSniklas next_saved_file = saved->next_saved_file; 1952159047fSniklas memcpy (save_source, saved->save_source, sizeof (save_source)); 1962159047fSniklas 1972159047fSniklas free (saved); 1982159047fSniklas return saved_position; 1992159047fSniklas } 2002159047fSniklas 2012159047fSniklas void 2022159047fSniklas input_scrub_begin () 2032159047fSniklas { 2042159047fSniklas know (strlen (BEFORE_STRING) == BEFORE_SIZE); 205*b55d4692Sfgsch know (strlen (AFTER_STRING) == AFTER_SIZE 206*b55d4692Sfgsch || (AFTER_STRING[0] == '\0' && AFTER_SIZE == 1)); 2072159047fSniklas 2082159047fSniklas input_file_begin (); 2092159047fSniklas 2102159047fSniklas buffer_length = input_file_buffer_size (); 2112159047fSniklas 2122159047fSniklas buffer_start = xmalloc ((BEFORE_SIZE + buffer_length + buffer_length + AFTER_SIZE)); 2132159047fSniklas memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE); 2142159047fSniklas 2152159047fSniklas /* Line number things. */ 2162159047fSniklas logical_input_line = -1; 2172159047fSniklas logical_input_file = (char *) NULL; 2182159047fSniklas physical_input_file = NULL; /* No file read yet. */ 2192159047fSniklas next_saved_file = NULL; /* At EOF, don't pop to any other file */ 220191aa565Sniklas do_scrub_begin (flag_m68k_mri); 2212159047fSniklas } 2222159047fSniklas 2232159047fSniklas void 2242159047fSniklas input_scrub_end () 2252159047fSniklas { 2262159047fSniklas if (buffer_start) 2272159047fSniklas { 2282159047fSniklas free (buffer_start); 2292159047fSniklas buffer_start = 0; 2302159047fSniklas input_file_end (); 2312159047fSniklas } 2322159047fSniklas } 2332159047fSniklas 234*b55d4692Sfgsch /* Start reading input from a new file. 235*b55d4692Sfgsch Return start of caller's part of buffer. */ 2362159047fSniklas 237*b55d4692Sfgsch char * 2382159047fSniklas input_scrub_new_file (filename) 2392159047fSniklas char *filename; 2402159047fSniklas { 2412159047fSniklas input_file_open (filename, !flag_no_comments); 242b305b0f1Sespie physical_input_file = filename[0] ? filename : _("{standard input}"); 2432159047fSniklas physical_input_line = 0; 2442159047fSniklas 2452159047fSniklas partial_size = 0; 2462159047fSniklas return (buffer_start + BEFORE_SIZE); 2472159047fSniklas } 2482159047fSniklas 2492159047fSniklas /* Include a file from the current file. Save our state, cause it to 2502159047fSniklas be restored on EOF, and begin handling a new file. Same result as 2512159047fSniklas input_scrub_new_file. */ 2522159047fSniklas 2532159047fSniklas char * 2542159047fSniklas input_scrub_include_file (filename, position) 2552159047fSniklas char *filename; 2562159047fSniklas char *position; 2572159047fSniklas { 2582159047fSniklas next_saved_file = input_scrub_push (position); 2592159047fSniklas return input_scrub_new_file (filename); 2602159047fSniklas } 2612159047fSniklas 2622159047fSniklas /* Start getting input from an sb structure. This is used when 2632159047fSniklas expanding a macro. */ 2642159047fSniklas 2652159047fSniklas void 266b305b0f1Sespie input_scrub_include_sb (from, position, is_expansion) 2672159047fSniklas sb *from; 2682159047fSniklas char *position; 269b305b0f1Sespie int is_expansion; 2702159047fSniklas { 2712159047fSniklas if (macro_nest > max_macro_nest) 272*b55d4692Sfgsch as_fatal (_("macros nested too deeply")); 2732159047fSniklas ++macro_nest; 2742159047fSniklas 275b305b0f1Sespie #ifdef md_macro_start 276b305b0f1Sespie if (is_expansion) 277b305b0f1Sespie { 278b305b0f1Sespie md_macro_start (); 279b305b0f1Sespie } 280b305b0f1Sespie #endif 281b305b0f1Sespie 2822159047fSniklas next_saved_file = input_scrub_push (position); 2832159047fSniklas 2842159047fSniklas sb_new (&from_sb); 285b305b0f1Sespie from_sb_is_expansion = is_expansion; 286b305b0f1Sespie if (from->len >= 1 && from->ptr[0] != '\n') 287b305b0f1Sespie { 2882159047fSniklas /* Add the sentinel required by read.c. */ 2892159047fSniklas sb_add_char (&from_sb, '\n'); 290b305b0f1Sespie } 2912159047fSniklas sb_add_sb (&from_sb, from); 2922159047fSniklas sb_index = 1; 2932159047fSniklas 2942159047fSniklas /* These variables are reset by input_scrub_push. Restore them 2952159047fSniklas since we are, after all, still at the same point in the file. */ 2962159047fSniklas logical_input_line = next_saved_file->logical_input_line; 2972159047fSniklas logical_input_file = next_saved_file->logical_input_file; 2982159047fSniklas } 2992159047fSniklas 3002159047fSniklas void 3012159047fSniklas input_scrub_close () 3022159047fSniklas { 3032159047fSniklas input_file_close (); 3042159047fSniklas } 3052159047fSniklas 3062159047fSniklas char * 3072159047fSniklas input_scrub_next_buffer (bufp) 3082159047fSniklas char **bufp; 3092159047fSniklas { 3102159047fSniklas register char *limit; /*->just after last char of buffer. */ 3112159047fSniklas 3122159047fSniklas if (sb_index >= 0) 3132159047fSniklas { 3142159047fSniklas if (sb_index >= from_sb.len) 3152159047fSniklas { 3162159047fSniklas sb_kill (&from_sb); 317*b55d4692Sfgsch if (from_sb_is_expansion 318*b55d4692Sfgsch ) 319b305b0f1Sespie { 320b305b0f1Sespie cond_finish_check (macro_nest); 321b305b0f1Sespie #ifdef md_macro_end 322*b55d4692Sfgsch /* Allow the target to clean up per-macro expansion 323*b55d4692Sfgsch data. */ 324b305b0f1Sespie md_macro_end (); 325b305b0f1Sespie #endif 326b305b0f1Sespie } 3272159047fSniklas --macro_nest; 3282159047fSniklas partial_where = NULL; 3292159047fSniklas if (next_saved_file != NULL) 3302159047fSniklas *bufp = input_scrub_pop (next_saved_file); 3312159047fSniklas return partial_where; 3322159047fSniklas } 3332159047fSniklas 3342159047fSniklas partial_where = from_sb.ptr + from_sb.len; 3352159047fSniklas partial_size = 0; 3362159047fSniklas *bufp = from_sb.ptr + sb_index; 3372159047fSniklas sb_index = from_sb.len; 3382159047fSniklas return partial_where; 3392159047fSniklas } 3402159047fSniklas 3412159047fSniklas *bufp = buffer_start + BEFORE_SIZE; 3422159047fSniklas 3432159047fSniklas if (partial_size) 3442159047fSniklas { 3452159047fSniklas memcpy (buffer_start + BEFORE_SIZE, partial_where, 3462159047fSniklas (unsigned int) partial_size); 3472159047fSniklas memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE); 3482159047fSniklas } 3492159047fSniklas limit = input_file_give_next_buffer (buffer_start 3502159047fSniklas + BEFORE_SIZE 3512159047fSniklas + partial_size); 3522159047fSniklas if (limit) 3532159047fSniklas { 3542159047fSniklas register char *p; /* Find last newline. */ 3552159047fSniklas 356b305b0f1Sespie for (p = limit - 1; *p != '\n'; --p) 357b305b0f1Sespie ; 3582159047fSniklas ++p; 359b305b0f1Sespie 360b305b0f1Sespie while (p <= buffer_start + BEFORE_SIZE) 3612159047fSniklas { 362b305b0f1Sespie int limoff; 363b305b0f1Sespie 364b305b0f1Sespie limoff = limit - buffer_start; 365b305b0f1Sespie buffer_length += input_file_buffer_size (); 366b305b0f1Sespie buffer_start = xrealloc (buffer_start, 367b305b0f1Sespie (BEFORE_SIZE 368b305b0f1Sespie + 2 * buffer_length 369b305b0f1Sespie + AFTER_SIZE)); 370b305b0f1Sespie *bufp = buffer_start + BEFORE_SIZE; 371b305b0f1Sespie limit = input_file_give_next_buffer (buffer_start + limoff); 372b305b0f1Sespie 373b305b0f1Sespie if (limit == NULL) 374b305b0f1Sespie { 375b305b0f1Sespie as_warn (_("partial line at end of file ignored")); 376b305b0f1Sespie partial_where = NULL; 377b305b0f1Sespie if (next_saved_file) 378b305b0f1Sespie *bufp = input_scrub_pop (next_saved_file); 379b305b0f1Sespie return NULL; 3802159047fSniklas } 381b305b0f1Sespie 382b305b0f1Sespie for (p = limit - 1; *p != '\n'; --p) 383b305b0f1Sespie ; 384b305b0f1Sespie ++p; 385b305b0f1Sespie } 386b305b0f1Sespie 3872159047fSniklas partial_where = p; 3882159047fSniklas partial_size = limit - p; 3892159047fSniklas memcpy (save_source, partial_where, (int) AFTER_SIZE); 3902159047fSniklas memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE); 3912159047fSniklas } 3922159047fSniklas else 3932159047fSniklas { 3942159047fSniklas partial_where = 0; 3952159047fSniklas if (partial_size > 0) 3962159047fSniklas { 397b305b0f1Sespie as_warn (_("Partial line at end of file ignored")); 3982159047fSniklas } 399b305b0f1Sespie 400b305b0f1Sespie /* Tell the listing we've finished the file. */ 401b305b0f1Sespie LISTING_EOF (); 402b305b0f1Sespie 4032159047fSniklas /* If we should pop to another file at EOF, do it. */ 4042159047fSniklas if (next_saved_file) 4052159047fSniklas { 4062159047fSniklas *bufp = input_scrub_pop (next_saved_file); /* Pop state */ 4072159047fSniklas /* partial_where is now correct to return, since we popped it. */ 4082159047fSniklas } 4092159047fSniklas } 4102159047fSniklas return (partial_where); 411*b55d4692Sfgsch } 4122159047fSniklas 413*b55d4692Sfgsch /* The remaining part of this file deals with line numbers, error 414*b55d4692Sfgsch messages and so on. Return TRUE if we opened any file. */ 4152159047fSniklas 4162159047fSniklas int 417*b55d4692Sfgsch seen_at_least_1_file () 4182159047fSniklas { 4192159047fSniklas return (physical_input_file != NULL); 4202159047fSniklas } 4212159047fSniklas 4222159047fSniklas void 4232159047fSniklas bump_line_counters () 4242159047fSniklas { 4252159047fSniklas if (sb_index < 0) 4262159047fSniklas { 4272159047fSniklas ++physical_input_line; 4282159047fSniklas if (logical_input_line >= 0) 4292159047fSniklas ++logical_input_line; 4302159047fSniklas } 4312159047fSniklas } 4322159047fSniklas 433*b55d4692Sfgsch /* Tells us what the new logical line number and file are. 434*b55d4692Sfgsch If the line_number is -1, we don't change the current logical line 435*b55d4692Sfgsch number. If it is -2, we decrement the logical line number (this is 436*b55d4692Sfgsch to support the .appfile pseudo-op inserted into the stream by 437*b55d4692Sfgsch do_scrub_chars). 438*b55d4692Sfgsch If the fname is NULL, we don't change the current logical file name. 439*b55d4692Sfgsch Returns nonzero if the filename actually changes. */ 440*b55d4692Sfgsch 441b305b0f1Sespie int 4422159047fSniklas new_logical_line (fname, line_number) 4432159047fSniklas char *fname; /* DON'T destroy it! We point to it! */ 4442159047fSniklas int line_number; 4452159047fSniklas { 4462159047fSniklas if (line_number >= 0) 4472159047fSniklas logical_input_line = line_number; 4482159047fSniklas else if (line_number == -2 && logical_input_line > 0) 4492159047fSniklas --logical_input_line; 450b305b0f1Sespie 451b305b0f1Sespie if (fname 452b305b0f1Sespie && (logical_input_file == NULL 453b305b0f1Sespie || strcmp (logical_input_file, fname))) 454b305b0f1Sespie { 455b305b0f1Sespie logical_input_file = fname; 456b305b0f1Sespie return 1; 457b305b0f1Sespie } 458b305b0f1Sespie else 459b305b0f1Sespie return 0; 460*b55d4692Sfgsch } 4612159047fSniklas 462*b55d4692Sfgsch /* Return the current file name and line number. 463*b55d4692Sfgsch namep should be char * const *, but there are compilers which screw 464*b55d4692Sfgsch up declarations like that, and it's easier to avoid it. */ 465*b55d4692Sfgsch 4662159047fSniklas void 4672159047fSniklas as_where (namep, linep) 4682159047fSniklas char **namep; 4692159047fSniklas unsigned int *linep; 4702159047fSniklas { 4712159047fSniklas if (logical_input_file != NULL 4722159047fSniklas && (linep == NULL || logical_input_line >= 0)) 4732159047fSniklas { 4742159047fSniklas *namep = logical_input_file; 4752159047fSniklas if (linep != NULL) 4762159047fSniklas *linep = logical_input_line; 4772159047fSniklas } 4782159047fSniklas else if (physical_input_file != NULL) 4792159047fSniklas { 4802159047fSniklas *namep = physical_input_file; 4812159047fSniklas if (linep != NULL) 4822159047fSniklas *linep = physical_input_line; 4832159047fSniklas } 4842159047fSniklas else 4852159047fSniklas { 4862159047fSniklas *namep = 0; 4872159047fSniklas if (linep != NULL) 4882159047fSniklas *linep = 0; 4892159047fSniklas } 490*b55d4692Sfgsch } 4912159047fSniklas 492*b55d4692Sfgsch /* Output to given stream how much of line we have scanned so far. 493*b55d4692Sfgsch Assumes we have scanned up to and including input_line_pointer. 494*b55d4692Sfgsch No free '\n' at end of line. */ 4952159047fSniklas 4962159047fSniklas void 4972159047fSniklas as_howmuch (stream) 4982159047fSniklas FILE *stream; /* Opened for write please. */ 4992159047fSniklas { 5002159047fSniklas register char *p; /* Scan input line. */ 5012159047fSniklas 5022159047fSniklas for (p = input_line_pointer - 1; *p != '\n'; --p) 5032159047fSniklas { 5042159047fSniklas } 5052159047fSniklas ++p; /* p->1st char of line. */ 5062159047fSniklas for (; p <= input_line_pointer; p++) 5072159047fSniklas { 5082159047fSniklas /* Assume ASCII. EBCDIC & other micro-computer char sets ignored. */ 5092159047fSniklas as_1_char ((unsigned char) *p, stream); 5102159047fSniklas } 5112159047fSniklas } 5122159047fSniklas 5132159047fSniklas static void 5142159047fSniklas as_1_char (c, stream) 5152159047fSniklas unsigned int c; 5162159047fSniklas FILE *stream; 5172159047fSniklas { 5182159047fSniklas if (c > 127) 5192159047fSniklas { 5202159047fSniklas (void) putc ('%', stream); 5212159047fSniklas c -= 128; 5222159047fSniklas } 5232159047fSniklas if (c < 32) 5242159047fSniklas { 5252159047fSniklas (void) putc ('^', stream); 5262159047fSniklas c += '@'; 5272159047fSniklas } 5282159047fSniklas (void) putc (c, stream); 5292159047fSniklas } 530