12159047fSniklas /* input_scrub.c - Break up input buffers into whole numbers of lines. 2b55d4692Sfgsch Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3b55d4692Sfgsch 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. 36*007c2a45Smiod * The buffer returned to caller is preceded 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. */ 63b55d4692Sfgsch 64b55d4692Sfgsch /* Because we need AFTER_STRING just after last full line, it clobbers 65b55d4692Sfgsch 1st part of partial line. So we preserve 1st part of partial line 66b55d4692Sfgsch here. */ 672159047fSniklas static char save_source[AFTER_SIZE]; 68b55d4692Sfgsch 69b55d4692Sfgsch /* What is the largest size buffer that input_file_give_next_buffer() 70b55d4692Sfgsch could return to us? */ 71b55d4692Sfgsch 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 */ 106b55d4692Sfgsch 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? */ 119b55d4692Sfgsch struct input_save * next_saved_file; /* Chain of input_saves. */ 120b55d4692Sfgsch char * input_file_save; /* Saved state of input routines. */ 121b55d4692Sfgsch char * saved_position; /* Caller's saved position in buf. */ 1222159047fSniklas }; 1232159047fSniklas 124*007c2a45Smiod static struct input_save *input_scrub_push (char *saved_position); 125*007c2a45Smiod static char *input_scrub_pop (struct input_save *arg); 126*007c2a45Smiod static void as_1_char (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(). */ 136b55d4692Sfgsch 1372159047fSniklas static struct input_save * 138*007c2a45Smiod input_scrub_push (char *saved_position) 1392159047fSniklas { 1402159047fSniklas register struct input_save *saved; 1412159047fSniklas 1422159047fSniklas saved = (struct input_save *) xmalloc (sizeof *saved); 1432159047fSniklas 1442159047fSniklas saved->saved_position = saved_position; 1452159047fSniklas saved->buffer_start = buffer_start; 1462159047fSniklas saved->partial_where = partial_where; 1472159047fSniklas saved->partial_size = partial_size; 1482159047fSniklas saved->buffer_length = buffer_length; 1492159047fSniklas saved->physical_input_file = physical_input_file; 1502159047fSniklas saved->logical_input_file = logical_input_file; 1512159047fSniklas saved->physical_input_line = physical_input_line; 1522159047fSniklas saved->logical_input_line = logical_input_line; 1532159047fSniklas saved->sb_index = sb_index; 1542159047fSniklas saved->from_sb = from_sb; 155b305b0f1Sespie saved->from_sb_is_expansion = from_sb_is_expansion; 1562159047fSniklas memcpy (saved->save_source, save_source, sizeof (save_source)); 1572159047fSniklas saved->next_saved_file = next_saved_file; 1582159047fSniklas saved->input_file_save = input_file_push (); 1592159047fSniklas 1602159047fSniklas input_file_begin (); /* Reinitialize! */ 1612159047fSniklas logical_input_line = -1; 1622159047fSniklas logical_input_file = (char *) NULL; 1632159047fSniklas buffer_length = input_file_buffer_size (); 1642159047fSniklas sb_index = -1; 1652159047fSniklas 1662159047fSniklas buffer_start = xmalloc ((BEFORE_SIZE + buffer_length + buffer_length + AFTER_SIZE)); 1672159047fSniklas memcpy (buffer_start, BEFORE_STRING, (int) BEFORE_SIZE); 1682159047fSniklas 1692159047fSniklas return saved; 170b55d4692Sfgsch } 1712159047fSniklas 1722159047fSniklas static char * 173*007c2a45Smiod input_scrub_pop (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; 189b305b0f1Sespie 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 void 200*007c2a45Smiod input_scrub_begin (void) 2012159047fSniklas { 2022159047fSniklas know (strlen (BEFORE_STRING) == BEFORE_SIZE); 203b55d4692Sfgsch know (strlen (AFTER_STRING) == AFTER_SIZE 204b55d4692Sfgsch || (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 222*007c2a45Smiod input_scrub_end (void) 2232159047fSniklas { 2242159047fSniklas if (buffer_start) 2252159047fSniklas { 2262159047fSniklas free (buffer_start); 2272159047fSniklas buffer_start = 0; 2282159047fSniklas input_file_end (); 2292159047fSniklas } 2302159047fSniklas } 2312159047fSniklas 232b55d4692Sfgsch /* Start reading input from a new file. 233b55d4692Sfgsch Return start of caller's part of buffer. */ 2342159047fSniklas 235b55d4692Sfgsch char * 236*007c2a45Smiod input_scrub_new_file (char *filename) 2372159047fSniklas { 2382159047fSniklas input_file_open (filename, !flag_no_comments); 239b305b0f1Sespie 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 /* Include a file from the current file. Save our state, cause it to 2472159047fSniklas be restored on EOF, and begin handling a new file. Same result as 2482159047fSniklas input_scrub_new_file. */ 2492159047fSniklas 2502159047fSniklas char * 251*007c2a45Smiod input_scrub_include_file (char *filename, char *position) 2522159047fSniklas { 2532159047fSniklas next_saved_file = input_scrub_push (position); 2542159047fSniklas return input_scrub_new_file (filename); 2552159047fSniklas } 2562159047fSniklas 2572159047fSniklas /* Start getting input from an sb structure. This is used when 2582159047fSniklas expanding a macro. */ 2592159047fSniklas 2602159047fSniklas void 261*007c2a45Smiod input_scrub_include_sb (sb *from, char *position, int is_expansion) 2622159047fSniklas { 2632159047fSniklas if (macro_nest > max_macro_nest) 264b55d4692Sfgsch as_fatal (_("macros nested too deeply")); 2652159047fSniklas ++macro_nest; 2662159047fSniklas 267b305b0f1Sespie #ifdef md_macro_start 268b305b0f1Sespie if (is_expansion) 269b305b0f1Sespie { 270b305b0f1Sespie md_macro_start (); 271b305b0f1Sespie } 272b305b0f1Sespie #endif 273b305b0f1Sespie 2742159047fSniklas next_saved_file = input_scrub_push (position); 2752159047fSniklas 2762159047fSniklas sb_new (&from_sb); 277b305b0f1Sespie from_sb_is_expansion = is_expansion; 278b305b0f1Sespie if (from->len >= 1 && from->ptr[0] != '\n') 279b305b0f1Sespie { 2802159047fSniklas /* Add the sentinel required by read.c. */ 2812159047fSniklas sb_add_char (&from_sb, '\n'); 282b305b0f1Sespie } 2832159047fSniklas sb_add_sb (&from_sb, from); 2842159047fSniklas sb_index = 1; 2852159047fSniklas 2862159047fSniklas /* These variables are reset by input_scrub_push. Restore them 2872159047fSniklas since we are, after all, still at the same point in the file. */ 2882159047fSniklas logical_input_line = next_saved_file->logical_input_line; 2892159047fSniklas logical_input_file = next_saved_file->logical_input_file; 2902159047fSniklas } 2912159047fSniklas 2922159047fSniklas void 293*007c2a45Smiod input_scrub_close (void) 2942159047fSniklas { 2952159047fSniklas input_file_close (); 2962159047fSniklas } 2972159047fSniklas 2982159047fSniklas char * 299*007c2a45Smiod input_scrub_next_buffer (char **bufp) 3002159047fSniklas { 3012159047fSniklas register char *limit; /*->just after last char of buffer. */ 3022159047fSniklas 3032159047fSniklas if (sb_index >= 0) 3042159047fSniklas { 3052159047fSniklas if (sb_index >= from_sb.len) 3062159047fSniklas { 3072159047fSniklas sb_kill (&from_sb); 308b55d4692Sfgsch if (from_sb_is_expansion 309b55d4692Sfgsch ) 310b305b0f1Sespie { 311b305b0f1Sespie cond_finish_check (macro_nest); 312b305b0f1Sespie #ifdef md_macro_end 313b55d4692Sfgsch /* Allow the target to clean up per-macro expansion 314b55d4692Sfgsch data. */ 315b305b0f1Sespie md_macro_end (); 316b305b0f1Sespie #endif 317b305b0f1Sespie } 3182159047fSniklas --macro_nest; 3192159047fSniklas partial_where = NULL; 3202159047fSniklas if (next_saved_file != NULL) 3212159047fSniklas *bufp = input_scrub_pop (next_saved_file); 3222159047fSniklas return partial_where; 3232159047fSniklas } 3242159047fSniklas 3252159047fSniklas partial_where = from_sb.ptr + from_sb.len; 3262159047fSniklas partial_size = 0; 3272159047fSniklas *bufp = from_sb.ptr + sb_index; 3282159047fSniklas sb_index = from_sb.len; 3292159047fSniklas return partial_where; 3302159047fSniklas } 3312159047fSniklas 3322159047fSniklas *bufp = buffer_start + BEFORE_SIZE; 3332159047fSniklas 3342159047fSniklas if (partial_size) 3352159047fSniklas { 3362159047fSniklas memcpy (buffer_start + BEFORE_SIZE, partial_where, 3372159047fSniklas (unsigned int) partial_size); 3382159047fSniklas memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE); 3392159047fSniklas } 3402159047fSniklas limit = input_file_give_next_buffer (buffer_start 3412159047fSniklas + BEFORE_SIZE 3422159047fSniklas + partial_size); 3432159047fSniklas if (limit) 3442159047fSniklas { 3452159047fSniklas register char *p; /* Find last newline. */ 3462159047fSniklas 347b305b0f1Sespie for (p = limit - 1; *p != '\n'; --p) 348b305b0f1Sespie ; 3492159047fSniklas ++p; 350b305b0f1Sespie 351b305b0f1Sespie while (p <= buffer_start + BEFORE_SIZE) 3522159047fSniklas { 353b305b0f1Sespie int limoff; 354b305b0f1Sespie 355b305b0f1Sespie limoff = limit - buffer_start; 356b305b0f1Sespie buffer_length += input_file_buffer_size (); 357b305b0f1Sespie buffer_start = xrealloc (buffer_start, 358b305b0f1Sespie (BEFORE_SIZE 359b305b0f1Sespie + 2 * buffer_length 360b305b0f1Sespie + AFTER_SIZE)); 361b305b0f1Sespie *bufp = buffer_start + BEFORE_SIZE; 362b305b0f1Sespie limit = input_file_give_next_buffer (buffer_start + limoff); 363b305b0f1Sespie 364b305b0f1Sespie if (limit == NULL) 365b305b0f1Sespie { 366b305b0f1Sespie as_warn (_("partial line at end of file ignored")); 367b305b0f1Sespie partial_where = NULL; 368b305b0f1Sespie if (next_saved_file) 369b305b0f1Sespie *bufp = input_scrub_pop (next_saved_file); 370b305b0f1Sespie return NULL; 3712159047fSniklas } 372b305b0f1Sespie 373b305b0f1Sespie for (p = limit - 1; *p != '\n'; --p) 374b305b0f1Sespie ; 375b305b0f1Sespie ++p; 376b305b0f1Sespie } 377b305b0f1Sespie 3782159047fSniklas partial_where = p; 3792159047fSniklas partial_size = limit - p; 3802159047fSniklas memcpy (save_source, partial_where, (int) AFTER_SIZE); 3812159047fSniklas memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE); 3822159047fSniklas } 3832159047fSniklas else 3842159047fSniklas { 3852159047fSniklas partial_where = 0; 3862159047fSniklas if (partial_size > 0) 3872159047fSniklas { 388c074d1c9Sdrahn as_warn (_("partial line at end of file ignored")); 3892159047fSniklas } 390b305b0f1Sespie 391b305b0f1Sespie /* Tell the listing we've finished the file. */ 392b305b0f1Sespie LISTING_EOF (); 393b305b0f1Sespie 3942159047fSniklas /* If we should pop to another file at EOF, do it. */ 3952159047fSniklas if (next_saved_file) 3962159047fSniklas { 3972159047fSniklas *bufp = input_scrub_pop (next_saved_file); /* Pop state */ 3982159047fSniklas /* partial_where is now correct to return, since we popped it. */ 3992159047fSniklas } 4002159047fSniklas } 4012159047fSniklas return (partial_where); 402b55d4692Sfgsch } 4032159047fSniklas 404b55d4692Sfgsch /* The remaining part of this file deals with line numbers, error 405b55d4692Sfgsch messages and so on. Return TRUE if we opened any file. */ 4062159047fSniklas 4072159047fSniklas int 408*007c2a45Smiod seen_at_least_1_file (void) 4092159047fSniklas { 4102159047fSniklas return (physical_input_file != NULL); 4112159047fSniklas } 4122159047fSniklas 4132159047fSniklas void 414*007c2a45Smiod bump_line_counters (void) 4152159047fSniklas { 4162159047fSniklas if (sb_index < 0) 4172159047fSniklas { 4182159047fSniklas ++physical_input_line; 4192159047fSniklas if (logical_input_line >= 0) 4202159047fSniklas ++logical_input_line; 4212159047fSniklas } 4222159047fSniklas } 4232159047fSniklas 424b55d4692Sfgsch /* Tells us what the new logical line number and file are. 425b55d4692Sfgsch If the line_number is -1, we don't change the current logical line 426b55d4692Sfgsch number. If it is -2, we decrement the logical line number (this is 427b55d4692Sfgsch to support the .appfile pseudo-op inserted into the stream by 428b55d4692Sfgsch do_scrub_chars). 429b55d4692Sfgsch If the fname is NULL, we don't change the current logical file name. 430b55d4692Sfgsch Returns nonzero if the filename actually changes. */ 431b55d4692Sfgsch 432b305b0f1Sespie int 433*007c2a45Smiod new_logical_line (char *fname, /* DON'T destroy it! We point to it! */ 434*007c2a45Smiod int line_number) 4352159047fSniklas { 4362159047fSniklas if (line_number >= 0) 4372159047fSniklas logical_input_line = line_number; 4382159047fSniklas else if (line_number == -2 && logical_input_line > 0) 4392159047fSniklas --logical_input_line; 440b305b0f1Sespie 441b305b0f1Sespie if (fname 442b305b0f1Sespie && (logical_input_file == NULL 443b305b0f1Sespie || strcmp (logical_input_file, fname))) 444b305b0f1Sespie { 445b305b0f1Sespie logical_input_file = fname; 446b305b0f1Sespie return 1; 447b305b0f1Sespie } 448b305b0f1Sespie else 449b305b0f1Sespie return 0; 450b55d4692Sfgsch } 4512159047fSniklas 452b55d4692Sfgsch /* Return the current file name and line number. 453b55d4692Sfgsch namep should be char * const *, but there are compilers which screw 454b55d4692Sfgsch up declarations like that, and it's easier to avoid it. */ 455b55d4692Sfgsch 4562159047fSniklas void 457*007c2a45Smiod as_where (char **namep, unsigned int *linep) 4582159047fSniklas { 4592159047fSniklas if (logical_input_file != NULL 4602159047fSniklas && (linep == NULL || logical_input_line >= 0)) 4612159047fSniklas { 4622159047fSniklas *namep = logical_input_file; 4632159047fSniklas if (linep != NULL) 4642159047fSniklas *linep = logical_input_line; 4652159047fSniklas } 4662159047fSniklas else if (physical_input_file != NULL) 4672159047fSniklas { 4682159047fSniklas *namep = physical_input_file; 4692159047fSniklas if (linep != NULL) 4702159047fSniklas *linep = physical_input_line; 4712159047fSniklas } 4722159047fSniklas else 4732159047fSniklas { 4742159047fSniklas *namep = 0; 4752159047fSniklas if (linep != NULL) 4762159047fSniklas *linep = 0; 4772159047fSniklas } 478b55d4692Sfgsch } 4792159047fSniklas 480b55d4692Sfgsch /* Output to given stream how much of line we have scanned so far. 481b55d4692Sfgsch Assumes we have scanned up to and including input_line_pointer. 482b55d4692Sfgsch No free '\n' at end of line. */ 4832159047fSniklas 4842159047fSniklas void 485*007c2a45Smiod as_howmuch (FILE *stream /* Opened for write please. */) 4862159047fSniklas { 4872159047fSniklas register char *p; /* Scan input line. */ 4882159047fSniklas 4892159047fSniklas for (p = input_line_pointer - 1; *p != '\n'; --p) 4902159047fSniklas { 4912159047fSniklas } 4922159047fSniklas ++p; /* p->1st char of line. */ 4932159047fSniklas for (; p <= input_line_pointer; p++) 4942159047fSniklas { 4952159047fSniklas /* Assume ASCII. EBCDIC & other micro-computer char sets ignored. */ 4962159047fSniklas as_1_char ((unsigned char) *p, stream); 4972159047fSniklas } 4982159047fSniklas } 4992159047fSniklas 5002159047fSniklas static void 501*007c2a45Smiod as_1_char (unsigned int c, FILE *stream) 5022159047fSniklas { 5032159047fSniklas if (c > 127) 5042159047fSniklas { 5052159047fSniklas (void) putc ('%', stream); 5062159047fSniklas c -= 128; 5072159047fSniklas } 5082159047fSniklas if (c < 32) 5092159047fSniklas { 5102159047fSniklas (void) putc ('^', stream); 5112159047fSniklas c += '@'; 5122159047fSniklas } 5132159047fSniklas (void) putc (c, stream); 5142159047fSniklas } 515