Changeset 609 for branches/GNU/src/binutils/gas/input-file.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/gas/input-file.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* input_file.c - Deal with Input Files - 2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000 2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001 3 3 Free Software Foundation, Inc. 4 4 … … 20 20 02111-1307, USA. */ 21 21 22 /* 23 * Confines all details of reading source bytes to this module. 24 * All O/S specific crocks should live here. 25 * What we lose in "efficiency" we gain in modularity. 26 * Note we don't need to #include the "as.h" file. No common coupling! 27 */ 22 /* Confines all details of reading source bytes to this module. 23 All O/S specific crocks should live here. 24 What we lose in "efficiency" we gain in modularity. 25 Note we don't need to #include the "as.h" file. No common coupling! */ 28 26 29 27 #include <stdio.h> 30 28 #include <string.h> 31 32 29 #include "as.h" 33 30 #include "input-file.h" 31 #include "safe-ctype.h" 34 32 35 33 static int input_file_get PARAMS ((char *, int)); 36 34 37 35 /* This variable is non-zero if the file currently being read should be 38 preprocessed by app. It is zero if the file can be read straight in. 39 */ 36 preprocessed by app. It is zero if the file can be read straight in. */ 40 37 int preprocess = 0; 41 38 42 /* 43 * This code opens a file, then delivers BUFFER_SIZE character 44 * chunks of the file on demand. 45 * BUFFER_SIZE is supposed to be a number chosen for speed. 46 * The caller only asks once what BUFFER_SIZE is, and asks before 47 * the nature of the input files (if any) is known. 48 */ 39 /* This code opens a file, then delivers BUFFER_SIZE character 40 chunks of the file on demand. 41 BUFFER_SIZE is supposed to be a number chosen for speed. 42 The caller only asks once what BUFFER_SIZE is, and asks before 43 the nature of the input files (if any) is known. */ 49 44 50 45 #define BUFFER_SIZE (32 * 1024) 51 46 52 /* 53 * We use static data: the data area is not sharable. 54 */ 47 /* We use static data: the data area is not sharable. */ 55 48 56 49 static FILE *f_in; … … 58 51 59 52 /* Struct for saving the state of this module for file includes. */ 60 struct saved_file { 61 FILE *f_in; 62 char *file_name; 63 int preprocess; 64 char *app_save; 65 }; 53 struct saved_file 54 { 55 FILE * f_in; 56 char * file_name; 57 int preprocess; 58 char * app_save; 59 }; 66 60 67 61 … … 94 88 /* Push the state of our input, returning a pointer to saved info that 95 89 can be restored with input_file_pop (). */ 90 96 91 char * 97 92 input_file_push () … … 107 102 saved->app_save = app_push (); 108 103 109 input_file_begin (); /* Initialize for new file */ 104 /* Initialize for new file. */ 105 input_file_begin (); 110 106 111 107 return (char *) saved; … … 118 114 register struct saved_file *saved = (struct saved_file *) arg; 119 115 120 input_file_end (); /* Close out old file */116 input_file_end (); /* Close out old file. */ 121 117 122 118 f_in = saved->f_in; … … 143 139 if (filename[0]) 144 140 { /* We have a file name. Suck it and see. */ 145 f_in = fopen (filename, "r");141 f_in = fopen (filename, FOPEN_RT); 146 142 file_name = filename; 147 143 } … … 153 149 if (f_in == (FILE *) 0) 154 150 { 155 as_bad (_(" Can't open %s for reading."), file_name);151 as_bad (_("can't open %s for reading"), file_name); 156 152 as_perror ("%s", file_name); 157 153 return; … … 160 156 c = getc (f_in); 161 157 if (c == '#') 162 { /* Begins with comment, may not want to preprocess */ 158 { 159 /* Begins with comment, may not want to preprocess. */ 163 160 c = getc (f_in); 164 161 if (c == 'N') 165 162 { 166 163 fgets (buf, 80, f_in); 167 if (!str cmp (buf, "O_APP\n"))164 if (!strncmp (buf, "O_APP", 5) && ISSPACE (buf[5])) 168 165 preprocess = 0; 169 166 if (!strchr (buf, '\n')) 170 ungetc ('#', f_in); /* It was longer */ 167 ungetc ('#', f_in); /* It was longer. */ 168 else 169 ungetc ('\n', f_in); 170 } 171 else if (c == 'A') 172 { 173 fgets (buf, 80, f_in); 174 if (!strncmp (buf, "PP", 2) && ISSPACE (buf[2])) 175 preprocess = 1; 176 if (!strchr (buf, '\n')) 177 ungetc ('#', f_in); 171 178 else 172 179 ungetc ('\n', f_in); … … 182 189 183 190 /* Close input file. */ 191 184 192 void 185 193 input_file_close () 186 194 { 195 /* Don't close a null file pointer. */ 187 196 if (f_in != NULL) 188 { 189 fclose (f_in); 190 } /* don't close a null file pointer */ 197 fclose (f_in); 198 191 199 f_in = 0; 192 200 } … … 221 229 if (f_in == (FILE *) 0) 222 230 return 0; 223 /* 224 * fflush (stdin); could be done here if you want to synchronise 225 * stdin and stdout, for the case where our input file is stdin. 226 * Since the assembler shouldn't do any output to stdout, we 227 * don't bother to synch output and input. 228 */ 231 /* fflush (stdin); could be done here if you want to synchronise 232 stdin and stdout, for the case where our input file is stdin. 233 Since the assembler shouldn't do any output to stdout, we 234 don't bother to synch output and input. */ 229 235 if (preprocess) 230 236 size = do_scrub_chars (input_file_get, where, BUFFER_SIZE); … … 245 251 return_value = 0; 246 252 } 247 return (return_value); 248 } 253 254 return return_value; 255 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.