12159047fSniklas /* input_scrub.c - Break up input buffers into whole numbers of lines. 2*b305b0f1Sespie Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 1997 3*b305b0f1Sespie Free Software Foundation, Inc. 42159047fSniklas 52159047fSniklas This file is part of GAS, the GNU Assembler. 62159047fSniklas 72159047fSniklas GAS is free software; you can redistribute it and/or modify 82159047fSniklas it under the terms of the GNU General Public License as published by 92159047fSniklas the Free Software Foundation; either version 2, or (at your option) 102159047fSniklas any later version. 112159047fSniklas 122159047fSniklas GAS is distributed in the hope that it will be useful, 132159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of 142159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 152159047fSniklas GNU General Public License for more details. 162159047fSniklas 172159047fSniklas You should have received a copy of the GNU General Public License 18*b305b0f1Sespie along with GAS; see the file COPYING. If not, write to the Free 19*b305b0f1Sespie Software Foundation, 59 Temple Place - Suite 330, Boston, MA 20*b305b0f1Sespie 02111-1307, USA. */ 212159047fSniklas 222159047fSniklas #include <errno.h> /* Need this to make errno declaration right */ 232159047fSniklas #include "as.h" 242159047fSniklas #include "input-file.h" 252159047fSniklas #include "sb.h" 26*b305b0f1Sespie #include "listing.h" 272159047fSniklas 282159047fSniklas /* 292159047fSniklas * O/S independent module to supply buffers of sanitised source code 302159047fSniklas * to rest of assembler. We get sanitised input data of arbitrary length. 312159047fSniklas * We break these buffers on line boundaries, recombine pieces that 322159047fSniklas * were broken across buffers, and return a buffer of full lines to 332159047fSniklas * the caller. 342159047fSniklas * The last partial line begins the next buffer we build and return to caller. 352159047fSniklas * The buffer returned to caller is preceeded by BEFORE_STRING and followed 362159047fSniklas * by AFTER_STRING, as sentinels. The last character before AFTER_STRING 372159047fSniklas * is a newline. 382159047fSniklas * Also looks after line numbers, for e.g. error messages. 392159047fSniklas */ 402159047fSniklas 412159047fSniklas /* 422159047fSniklas * We don't care how filthy our buffers are, but our callers assume 432159047fSniklas * that the following sanitation has already been done. 442159047fSniklas * 452159047fSniklas * No comments, reduce a comment to a space. 462159047fSniklas * Reduce a tab to a space unless it is 1st char of line. 472159047fSniklas * All multiple tabs and spaces collapsed into 1 char. Tab only 482159047fSniklas * legal if 1st char of line. 492159047fSniklas * # line file statements converted to .line x;.file y; statements. 502159047fSniklas * Escaped newlines at end of line: remove them but add as many newlines 512159047fSniklas * to end of statement as you removed in the middle, to synch line numbers. 522159047fSniklas */ 532159047fSniklas 542159047fSniklas #define BEFORE_STRING ("\n") 552159047fSniklas #define AFTER_STRING ("\0") /* memcpy of 0 chars might choke. */ 562159047fSniklas #define BEFORE_SIZE (1) 572159047fSniklas #define AFTER_SIZE (1) 582159047fSniklas 592159047fSniklas static char *buffer_start; /*->1st char of full buffer area. */ 602159047fSniklas static char *partial_where; /*->after last full line in buffer. */ 612159047fSniklas static int partial_size; /* >=0. Number of chars in partial line in buffer. */ 622159047fSniklas static char save_source[AFTER_SIZE]; 632159047fSniklas /* Because we need AFTER_STRING just after last */ 642159047fSniklas /* full line, it clobbers 1st part of partial */ 652159047fSniklas /* line. So we preserve 1st part of partial */ 662159047fSniklas /* line here. */ 672159047fSniklas static unsigned int buffer_length; /* What is the largest size buffer that */ 682159047fSniklas /* input_file_give_next_buffer() could */ 692159047fSniklas /* return to us? */ 702159047fSniklas 712159047fSniklas /* The index into an sb structure we are reading from. -1 if none. */ 722159047fSniklas static int sb_index = -1; 732159047fSniklas 742159047fSniklas /* If we are reading from an sb structure, this is it. */ 752159047fSniklas static sb from_sb; 762159047fSniklas 77*b305b0f1Sespie /* Should we do a conditional check on from_sb? */ 78*b305b0f1Sespie static int from_sb_is_expansion = 1; 79*b305b0f1Sespie 802159047fSniklas /* The number of nested sb structures we have included. */ 81*b305b0f1Sespie int macro_nest; 822159047fSniklas 832159047fSniklas /* We can have more than one source file open at once, though the info for all 842159047fSniklas but the latest one are saved off in a struct input_save. These files remain 852159047fSniklas open, so we are limited by the number of open files allowed by the 862159047fSniklas underlying OS. We may also sequentially read more than one source file in an 872159047fSniklas assembly. */ 882159047fSniklas 892159047fSniklas /* We must track the physical file and line number for error messages. We also 902159047fSniklas track a "logical" file and line number corresponding to (C?) compiler 912159047fSniklas source line numbers. Whenever we open a file we must fill in 922159047fSniklas physical_input_file. So if it is NULL we have not opened any files yet. */ 932159047fSniklas 942159047fSniklas static char *physical_input_file; 952159047fSniklas static char *logical_input_file; 962159047fSniklas 972159047fSniklas typedef unsigned int line_numberT; /* 1-origin line number in a source file. */ 982159047fSniklas /* A line ends in '\n' or eof. */ 992159047fSniklas 1002159047fSniklas static line_numberT physical_input_line; 1012159047fSniklas static int logical_input_line; 1022159047fSniklas 1032159047fSniklas /* Struct used to save the state of the input handler during include files */ 1042159047fSniklas struct input_save 1052159047fSniklas { 1062159047fSniklas char *buffer_start; 1072159047fSniklas char *partial_where; 1082159047fSniklas int partial_size; 1092159047fSniklas char save_source[AFTER_SIZE]; 1102159047fSniklas unsigned int buffer_length; 1112159047fSniklas char *physical_input_file; 1122159047fSniklas char *logical_input_file; 1132159047fSniklas line_numberT physical_input_line; 1142159047fSniklas int logical_input_line; 1152159047fSniklas int sb_index; 1162159047fSniklas sb from_sb; 117*b305b0f1Sespie int from_sb_is_expansion; /* Should we do a conditional check? */ 1182159047fSniklas struct input_save *next_saved_file; /* Chain of input_saves */ 1192159047fSniklas char *input_file_save; /* Saved state of input routines */ 1202159047fSniklas char *saved_position; /* Caller's saved position in buf */ 1212159047fSniklas }; 1222159047fSniklas 1232159047fSniklas static struct input_save *input_scrub_push PARAMS ((char *saved_position)); 1242159047fSniklas static char *input_scrub_pop PARAMS ((struct input_save *arg)); 1252159047fSniklas static void as_1_char PARAMS ((unsigned int c, FILE * stream)); 1262159047fSniklas 1272159047fSniklas /* Saved information about the file that .include'd this one. When we hit EOF, 1282159047fSniklas we automatically pop to that file. */ 1292159047fSniklas 1302159047fSniklas static struct input_save *next_saved_file; 1312159047fSniklas 1322159047fSniklas /* Push the state of input reading and scrubbing so that we can #include. 1332159047fSniklas The return value is a 'void *' (fudged for old compilers) to a save 1342159047fSniklas area, which can be restored by passing it to input_scrub_pop(). */ 1352159047fSniklas static struct input_save * 1362159047fSniklas input_scrub_push (saved_position) 1372159047fSniklas char *saved_position; 1382159047fSniklas { 1392159047fSniklas register struct input_save *saved; 1402159047fSniklas 1412159047fSniklas saved = (struct input_save *) xmalloc (sizeof *saved); 1422159047fSniklas 1432159047fSniklas saved->saved_position = saved_position; 1442159047fSniklas saved->buffer_start = buffer_start; 1452159047fSniklas saved->partial_where = partial_where; 1462159047fSniklas saved->partial_size = partial_size; 1472159047fSniklas saved->buffer_length = buffer_length; 1482159047fSniklas saved->physical_input_file = physical_input_file; 1492159047fSniklas saved->logical_input_file = logical_input_file; 1502159047fSniklas saved->physical_input_line = physical_input_line; 1512159047fSniklas saved->logical_input_line = logical_input_line; 1522159047fSniklas saved->sb_index = sb_index; 1532159047fSniklas saved->from_sb = from_sb; 154*b305b0f1Sespie saved->from_sb_is_expansion = from_sb_is_expansion; 1552159047fSniklas memcpy (saved->save_source, save_source, sizeof (save_source)); 1562159047fSniklas saved->next_saved_file = next_saved_file; 1572159047fSniklas saved->input_file_save = input_file_push (); 1582159047fSniklas 1592159047fSniklas input_file_begin (); /* Reinitialize! */ 1602159047fSniklas logical_input_line = -1; 1612159047fSniklas logical_input_file = (char *) NULL; 1622159047fSniklas buffer_length = input_file_buffer_size (); 1632159047fSniklas sb_index = -1; 1642159047fSniklas 1652159047fSniklas buffer_start = xmalloc ((BEFORE_SIZE + buffer_length + buffer_length + AFTER_SIZE)); 1662159047fSniklas memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE); 1672159047fSniklas 1682159047fSniklas return saved; 1692159047fSniklas } /* input_scrub_push() */ 1702159047fSniklas 1712159047fSniklas static char * 1722159047fSniklas input_scrub_pop (saved) 1732159047fSniklas struct input_save *saved; 1742159047fSniklas { 1752159047fSniklas char *saved_position; 1762159047fSniklas 1772159047fSniklas input_scrub_end (); /* Finish off old buffer */ 1782159047fSniklas 1792159047fSniklas input_file_pop (saved->input_file_save); 1802159047fSniklas saved_position = saved->saved_position; 1812159047fSniklas buffer_start = saved->buffer_start; 1822159047fSniklas buffer_length = saved->buffer_length; 1832159047fSniklas physical_input_file = saved->physical_input_file; 1842159047fSniklas logical_input_file = saved->logical_input_file; 1852159047fSniklas physical_input_line = saved->physical_input_line; 1862159047fSniklas logical_input_line = saved->logical_input_line; 1872159047fSniklas sb_index = saved->sb_index; 1882159047fSniklas from_sb = saved->from_sb; 189*b305b0f1Sespie from_sb_is_expansion = saved->from_sb_is_expansion; 1902159047fSniklas partial_where = saved->partial_where; 1912159047fSniklas partial_size = saved->partial_size; 1922159047fSniklas next_saved_file = saved->next_saved_file; 1932159047fSniklas memcpy (save_source, saved->save_source, sizeof (save_source)); 1942159047fSniklas 1952159047fSniklas free (saved); 1962159047fSniklas return saved_position; 1972159047fSniklas } 1982159047fSniklas 1992159047fSniklas 2002159047fSniklas void 2012159047fSniklas input_scrub_begin () 2022159047fSniklas { 2032159047fSniklas know (strlen (BEFORE_STRING) == BEFORE_SIZE); 2042159047fSniklas know (strlen (AFTER_STRING) == AFTER_SIZE || (AFTER_STRING[0] == '\0' && AFTER_SIZE == 1)); 2052159047fSniklas 2062159047fSniklas input_file_begin (); 2072159047fSniklas 2082159047fSniklas buffer_length = input_file_buffer_size (); 2092159047fSniklas 2102159047fSniklas buffer_start = xmalloc ((BEFORE_SIZE + buffer_length + buffer_length + AFTER_SIZE)); 2112159047fSniklas memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE); 2122159047fSniklas 2132159047fSniklas /* Line number things. */ 2142159047fSniklas logical_input_line = -1; 2152159047fSniklas logical_input_file = (char *) NULL; 2162159047fSniklas physical_input_file = NULL; /* No file read yet. */ 2172159047fSniklas next_saved_file = NULL; /* At EOF, don't pop to any other file */ 218191aa565Sniklas do_scrub_begin (flag_m68k_mri); 2192159047fSniklas } 2202159047fSniklas 2212159047fSniklas void 2222159047fSniklas input_scrub_end () 2232159047fSniklas { 2242159047fSniklas if (buffer_start) 2252159047fSniklas { 2262159047fSniklas free (buffer_start); 2272159047fSniklas buffer_start = 0; 2282159047fSniklas input_file_end (); 2292159047fSniklas } 2302159047fSniklas } 2312159047fSniklas 2322159047fSniklas /* Start reading input from a new file. */ 2332159047fSniklas 2342159047fSniklas char * /* Return start of caller's part of buffer. */ 2352159047fSniklas input_scrub_new_file (filename) 2362159047fSniklas char *filename; 2372159047fSniklas { 2382159047fSniklas input_file_open (filename, !flag_no_comments); 239*b305b0f1Sespie physical_input_file = filename[0] ? filename : _("{standard input}"); 2402159047fSniklas physical_input_line = 0; 2412159047fSniklas 2422159047fSniklas partial_size = 0; 2432159047fSniklas return (buffer_start + BEFORE_SIZE); 2442159047fSniklas } 2452159047fSniklas 2462159047fSniklas 2472159047fSniklas /* Include a file from the current file. Save our state, cause it to 2482159047fSniklas be restored on EOF, and begin handling a new file. Same result as 2492159047fSniklas input_scrub_new_file. */ 2502159047fSniklas 2512159047fSniklas char * 2522159047fSniklas input_scrub_include_file (filename, position) 2532159047fSniklas char *filename; 2542159047fSniklas char *position; 2552159047fSniklas { 2562159047fSniklas next_saved_file = input_scrub_push (position); 2572159047fSniklas return input_scrub_new_file (filename); 2582159047fSniklas } 2592159047fSniklas 2602159047fSniklas /* Start getting input from an sb structure. This is used when 2612159047fSniklas expanding a macro. */ 2622159047fSniklas 2632159047fSniklas void 264*b305b0f1Sespie input_scrub_include_sb (from, position, is_expansion) 2652159047fSniklas sb *from; 2662159047fSniklas char *position; 267*b305b0f1Sespie int is_expansion; 2682159047fSniklas { 2692159047fSniklas if (macro_nest > max_macro_nest) 270*b305b0f1Sespie as_fatal (_("buffers nested too deeply")); 2712159047fSniklas ++macro_nest; 2722159047fSniklas 273*b305b0f1Sespie #ifdef md_macro_start 274*b305b0f1Sespie if (is_expansion) 275*b305b0f1Sespie { 276*b305b0f1Sespie md_macro_start (); 277*b305b0f1Sespie } 278*b305b0f1Sespie #endif 279*b305b0f1Sespie 2802159047fSniklas next_saved_file = input_scrub_push (position); 2812159047fSniklas 2822159047fSniklas sb_new (&from_sb); 283*b305b0f1Sespie from_sb_is_expansion = is_expansion; 284*b305b0f1Sespie if (from->len >= 1 && from->ptr[0] != '\n') 285*b305b0f1Sespie { 2862159047fSniklas /* Add the sentinel required by read.c. */ 2872159047fSniklas sb_add_char (&from_sb, '\n'); 288*b305b0f1Sespie } 2892159047fSniklas sb_add_sb (&from_sb, from); 2902159047fSniklas sb_index = 1; 2912159047fSniklas 2922159047fSniklas /* These variables are reset by input_scrub_push. Restore them 2932159047fSniklas since we are, after all, still at the same point in the file. */ 2942159047fSniklas logical_input_line = next_saved_file->logical_input_line; 2952159047fSniklas logical_input_file = next_saved_file->logical_input_file; 2962159047fSniklas } 2972159047fSniklas 2982159047fSniklas void 2992159047fSniklas input_scrub_close () 3002159047fSniklas { 3012159047fSniklas input_file_close (); 3022159047fSniklas } 3032159047fSniklas 3042159047fSniklas char * 3052159047fSniklas input_scrub_next_buffer (bufp) 3062159047fSniklas char **bufp; 3072159047fSniklas { 3082159047fSniklas register char *limit; /*->just after last char of buffer. */ 3092159047fSniklas 3102159047fSniklas if (sb_index >= 0) 3112159047fSniklas { 3122159047fSniklas if (sb_index >= from_sb.len) 3132159047fSniklas { 3142159047fSniklas sb_kill (&from_sb); 315*b305b0f1Sespie if (from_sb_is_expansion) 316*b305b0f1Sespie { 317*b305b0f1Sespie cond_finish_check (macro_nest); 318*b305b0f1Sespie #ifdef md_macro_end 319*b305b0f1Sespie /* allow the target to clean up per-macro expansion data */ 320*b305b0f1Sespie md_macro_end (); 321*b305b0f1Sespie #endif 322*b305b0f1Sespie } 3232159047fSniklas --macro_nest; 3242159047fSniklas partial_where = NULL; 3252159047fSniklas if (next_saved_file != NULL) 3262159047fSniklas *bufp = input_scrub_pop (next_saved_file); 3272159047fSniklas return partial_where; 3282159047fSniklas } 3292159047fSniklas 3302159047fSniklas partial_where = from_sb.ptr + from_sb.len; 3312159047fSniklas partial_size = 0; 3322159047fSniklas *bufp = from_sb.ptr + sb_index; 3332159047fSniklas sb_index = from_sb.len; 3342159047fSniklas return partial_where; 3352159047fSniklas } 3362159047fSniklas 3372159047fSniklas *bufp = buffer_start + BEFORE_SIZE; 3382159047fSniklas 3392159047fSniklas if (partial_size) 3402159047fSniklas { 3412159047fSniklas memcpy (buffer_start + BEFORE_SIZE, partial_where, 3422159047fSniklas (unsigned int) partial_size); 3432159047fSniklas memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE); 3442159047fSniklas } 3452159047fSniklas limit = input_file_give_next_buffer (buffer_start 3462159047fSniklas + BEFORE_SIZE 3472159047fSniklas + partial_size); 3482159047fSniklas if (limit) 3492159047fSniklas { 3502159047fSniklas register char *p; /* Find last newline. */ 3512159047fSniklas 352*b305b0f1Sespie for (p = limit - 1; *p != '\n'; --p) 353*b305b0f1Sespie ; 3542159047fSniklas ++p; 355*b305b0f1Sespie 356*b305b0f1Sespie while (p <= buffer_start + BEFORE_SIZE) 3572159047fSniklas { 358*b305b0f1Sespie int limoff; 359*b305b0f1Sespie 360*b305b0f1Sespie limoff = limit - buffer_start; 361*b305b0f1Sespie buffer_length += input_file_buffer_size (); 362*b305b0f1Sespie buffer_start = xrealloc (buffer_start, 363*b305b0f1Sespie (BEFORE_SIZE 364*b305b0f1Sespie + 2 * buffer_length 365*b305b0f1Sespie + AFTER_SIZE)); 366*b305b0f1Sespie *bufp = buffer_start + BEFORE_SIZE; 367*b305b0f1Sespie limit = input_file_give_next_buffer (buffer_start + limoff); 368*b305b0f1Sespie 369*b305b0f1Sespie if (limit == NULL) 370*b305b0f1Sespie { 371*b305b0f1Sespie as_warn (_("partial line at end of file ignored")); 372*b305b0f1Sespie partial_where = NULL; 373*b305b0f1Sespie if (next_saved_file) 374*b305b0f1Sespie *bufp = input_scrub_pop (next_saved_file); 375*b305b0f1Sespie return NULL; 3762159047fSniklas } 377*b305b0f1Sespie 378*b305b0f1Sespie for (p = limit - 1; *p != '\n'; --p) 379*b305b0f1Sespie ; 380*b305b0f1Sespie ++p; 381*b305b0f1Sespie } 382*b305b0f1Sespie 3832159047fSniklas partial_where = p; 3842159047fSniklas partial_size = limit - p; 3852159047fSniklas memcpy (save_source, partial_where, (int) AFTER_SIZE); 3862159047fSniklas memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE); 3872159047fSniklas } 3882159047fSniklas else 3892159047fSniklas { 3902159047fSniklas partial_where = 0; 3912159047fSniklas if (partial_size > 0) 3922159047fSniklas { 393*b305b0f1Sespie as_warn (_("Partial line at end of file ignored")); 3942159047fSniklas } 395*b305b0f1Sespie 396*b305b0f1Sespie /* Tell the listing we've finished the file. */ 397*b305b0f1Sespie LISTING_EOF (); 398*b305b0f1Sespie 3992159047fSniklas /* If we should pop to another file at EOF, do it. */ 4002159047fSniklas if (next_saved_file) 4012159047fSniklas { 4022159047fSniklas *bufp = input_scrub_pop (next_saved_file); /* Pop state */ 4032159047fSniklas /* partial_where is now correct to return, since we popped it. */ 4042159047fSniklas } 4052159047fSniklas } 4062159047fSniklas return (partial_where); 4072159047fSniklas } /* input_scrub_next_buffer() */ 4082159047fSniklas 4092159047fSniklas /* 4102159047fSniklas * The remaining part of this file deals with line numbers, error 4112159047fSniklas * messages and so on. 4122159047fSniklas */ 4132159047fSniklas 4142159047fSniklas 4152159047fSniklas int 4162159047fSniklas seen_at_least_1_file () /* TRUE if we opened any file. */ 4172159047fSniklas { 4182159047fSniklas return (physical_input_file != NULL); 4192159047fSniklas } 4202159047fSniklas 4212159047fSniklas void 4222159047fSniklas bump_line_counters () 4232159047fSniklas { 4242159047fSniklas if (sb_index < 0) 4252159047fSniklas { 4262159047fSniklas ++physical_input_line; 4272159047fSniklas if (logical_input_line >= 0) 4282159047fSniklas ++logical_input_line; 4292159047fSniklas } 4302159047fSniklas } 4312159047fSniklas 4322159047fSniklas /* 4332159047fSniklas * new_logical_line() 4342159047fSniklas * 4352159047fSniklas * Tells us what the new logical line number and file are. 4362159047fSniklas * If the line_number is -1, we don't change the current logical line 4372159047fSniklas * number. If it is -2, we decrement the logical line number (this is 4382159047fSniklas * to support the .appfile pseudo-op inserted into the stream by 4392159047fSniklas * do_scrub_chars). 4402159047fSniklas * If the fname is NULL, we don't change the current logical file name. 441*b305b0f1Sespie * Returns nonzero if the filename actually changes. 4422159047fSniklas */ 443*b305b0f1Sespie int 4442159047fSniklas new_logical_line (fname, line_number) 4452159047fSniklas char *fname; /* DON'T destroy it! We point to it! */ 4462159047fSniklas int line_number; 4472159047fSniklas { 4482159047fSniklas if (line_number >= 0) 4492159047fSniklas logical_input_line = line_number; 4502159047fSniklas else if (line_number == -2 && logical_input_line > 0) 4512159047fSniklas --logical_input_line; 452*b305b0f1Sespie 453*b305b0f1Sespie if (fname 454*b305b0f1Sespie && (logical_input_file == NULL 455*b305b0f1Sespie || strcmp (logical_input_file, fname))) 456*b305b0f1Sespie { 457*b305b0f1Sespie logical_input_file = fname; 458*b305b0f1Sespie return 1; 459*b305b0f1Sespie } 460*b305b0f1Sespie else 461*b305b0f1Sespie return 0; 4622159047fSniklas } /* new_logical_line() */ 4632159047fSniklas 4642159047fSniklas /* 4652159047fSniklas * a s _ w h e r e () 4662159047fSniklas * 4672159047fSniklas * Return the current file name and line number. 4682159047fSniklas * namep should be char * const *, but there are compilers which screw 4692159047fSniklas * up declarations like that, and it's easier to avoid it. 4702159047fSniklas */ 4712159047fSniklas void 4722159047fSniklas as_where (namep, linep) 4732159047fSniklas char **namep; 4742159047fSniklas unsigned int *linep; 4752159047fSniklas { 4762159047fSniklas if (logical_input_file != NULL 4772159047fSniklas && (linep == NULL || logical_input_line >= 0)) 4782159047fSniklas { 4792159047fSniklas *namep = logical_input_file; 4802159047fSniklas if (linep != NULL) 4812159047fSniklas *linep = logical_input_line; 4822159047fSniklas } 4832159047fSniklas else if (physical_input_file != NULL) 4842159047fSniklas { 4852159047fSniklas *namep = physical_input_file; 4862159047fSniklas if (linep != NULL) 4872159047fSniklas *linep = physical_input_line; 4882159047fSniklas } 4892159047fSniklas else 4902159047fSniklas { 4912159047fSniklas *namep = 0; 4922159047fSniklas if (linep != NULL) 4932159047fSniklas *linep = 0; 4942159047fSniklas } 4952159047fSniklas } /* as_where() */ 4962159047fSniklas 4972159047fSniklas 4982159047fSniklas 4992159047fSniklas 5002159047fSniklas /* 5012159047fSniklas * a s _ h o w m u c h () 5022159047fSniklas * 5032159047fSniklas * Output to given stream how much of line we have scanned so far. 5042159047fSniklas * Assumes we have scanned up to and including input_line_pointer. 5052159047fSniklas * No free '\n' at end of line. 5062159047fSniklas */ 5072159047fSniklas void 5082159047fSniklas as_howmuch (stream) 5092159047fSniklas FILE *stream; /* Opened for write please. */ 5102159047fSniklas { 5112159047fSniklas register char *p; /* Scan input line. */ 5122159047fSniklas /* register char c; JF unused */ 5132159047fSniklas 5142159047fSniklas for (p = input_line_pointer - 1; *p != '\n'; --p) 5152159047fSniklas { 5162159047fSniklas } 5172159047fSniklas ++p; /* p->1st char of line. */ 5182159047fSniklas for (; p <= input_line_pointer; p++) 5192159047fSniklas { 5202159047fSniklas /* Assume ASCII. EBCDIC & other micro-computer char sets ignored. */ 5212159047fSniklas as_1_char ((unsigned char) *p, stream); 5222159047fSniklas } 5232159047fSniklas } 5242159047fSniklas 5252159047fSniklas static void 5262159047fSniklas as_1_char (c, stream) 5272159047fSniklas unsigned int c; 5282159047fSniklas FILE *stream; 5292159047fSniklas { 5302159047fSniklas if (c > 127) 5312159047fSniklas { 5322159047fSniklas (void) putc ('%', stream); 5332159047fSniklas c -= 128; 5342159047fSniklas } 5352159047fSniklas if (c < 32) 5362159047fSniklas { 5372159047fSniklas (void) putc ('^', stream); 5382159047fSniklas c += '@'; 5392159047fSniklas } 5402159047fSniklas (void) putc (c, stream); 5412159047fSniklas } 5422159047fSniklas 5432159047fSniklas /* end of input_scrub.c */ 544