#include <stdio.h>#include <ctype.h>#include <string.h>Go to the source code of this file.
Defines | |
| #define | NULL (0) |
| #define | is_ascii(c) 1 |
| #define | is_space(c) (is_ascii(c) && isspace(c)) |
| #define | is_alpha(c) (is_ascii(c) && isalpha(c)) |
| #define | is_alnum(c) (is_ascii(c) && isalnum(c)) |
| #define | isidchar(ch) (is_alnum(ch) || (ch) == '_') |
| #define | isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') |
| #define | bufsize 5000 |
Functions | |
| char * | malloc () |
| int | free () |
| char * | ppdirforward () |
| char * | ppdirbackward () |
| char * | skipspace () |
| char * | scanstring () |
| int | writeblanks () |
| int | test1 () |
| int | convert1 () |
| int | main (int argc, argv) |
|
|
Referenced by do_strftime(), and main(). |
|
|
Definition at line 213 of file ansi2knr.c. |
|
|
Definition at line 212 of file ansi2knr.c. |
|
|
Definition at line 206 of file ansi2knr.c. |
|
|
Definition at line 211 of file ansi2knr.c. Referenced by skipspace(). |
|
|
Definition at line 216 of file ansi2knr.c. Referenced by convert1(), and test1(). |
|
|
Definition at line 217 of file ansi2knr.c. Referenced by convert1(), and test1(). |
|
|
|
Referenced by main(). |
|
|
||||||||||||
|
Definition at line 230 of file ansi2knr.c. References bufsize, convert1(), exit, fclose, free(), malloc(), NULL, ppdirforward(), skipspace(), test1(), and usage(). 00233 { FILE *in = stdin; 00234 FILE *out = stdout; 00235 char *filename = 0; 00236 char *program_name = argv[0]; 00237 char *output_name = 0; 00238 #define bufsize 5000 /* arbitrary size */ 00239 char *buf; 00240 char *line; 00241 char *more; 00242 char *usage = 00243 "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n"; 00244 /* 00245 * In previous versions, ansi2knr recognized a --varargs switch. 00246 * If this switch was supplied, ansi2knr would attempt to convert 00247 * a ... argument to va_alist and va_dcl; if this switch was not 00248 * supplied, ansi2knr would simply drop any such arguments. 00249 * Now, ansi2knr always does this conversion, and we only 00250 * check for this switch for backward compatibility. 00251 */ 00252 int convert_varargs = 1; 00253 int output_error; 00254 00255 while ( argc > 1 && argv[1][0] == '-' ) { 00256 if ( !strcmp(argv[1], "--varargs") ) { 00257 convert_varargs = 1; 00258 argc--; 00259 argv++; 00260 continue; 00261 } 00262 if ( !strcmp(argv[1], "--filename") && argc > 2 ) { 00263 filename = argv[2]; 00264 argc -= 2; 00265 argv += 2; 00266 continue; 00267 } 00268 fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name, 00269 argv[1]); 00270 fprintf(stderr, usage); 00271 exit(1); 00272 } 00273 switch ( argc ) 00274 { 00275 default: 00276 fprintf(stderr, usage); 00277 exit(0); 00278 case 3: 00279 output_name = argv[2]; 00280 out = fopen(output_name, "w"); 00281 if ( out == NULL ) { 00282 fprintf(stderr, "%s: Cannot open output file %s\n", 00283 program_name, output_name); 00284 exit(1); 00285 } 00286 /* falls through */ 00287 case 2: 00288 in = fopen(argv[1], "r"); 00289 if ( in == NULL ) { 00290 fprintf(stderr, "%s: Cannot open input file %s\n", 00291 program_name, argv[1]); 00292 exit(1); 00293 } 00294 if ( filename == 0 ) 00295 filename = argv[1]; 00296 /* falls through */ 00297 case 1: 00298 break; 00299 } 00300 if ( filename ) 00301 fprintf(out, "#line 1 \"%s\"\n", filename); 00302 buf = malloc(bufsize); 00303 if ( buf == NULL ) 00304 { 00305 fprintf(stderr, "Unable to allocate read buffer!\n"); 00306 exit(1); 00307 } 00308 line = buf; 00309 while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) 00310 { 00311 test: line += strlen(line); 00312 switch ( test1(buf) ) 00313 { 00314 case 2: /* a function header */ 00315 convert1(buf, out, 1, convert_varargs); 00316 break; 00317 case 1: /* a function */ 00318 /* Check for a { at the start of the next line. */ 00319 more = ++line; 00320 f: if ( line >= buf + (bufsize - 1) ) /* overflow check */ 00321 goto wl; 00322 if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL ) 00323 goto wl; 00324 switch ( *skipspace(ppdirforward(more), 1) ) 00325 { 00326 case '{': 00327 /* Definitely a function header. */ 00328 convert1(buf, out, 0, convert_varargs); 00329 fputs(more, out); 00330 break; 00331 case 0: 00332 /* The next line was blank or a comment: */ 00333 /* keep scanning for a non-comment. */ 00334 line += strlen(line); 00335 goto f; 00336 default: 00337 /* buf isn't a function header, but */ 00338 /* more might be. */ 00339 fputs(buf, out); 00340 strcpy(buf, more); 00341 line = buf; 00342 goto test; 00343 } 00344 break; 00345 case -1: /* maybe the start of a function */ 00346 if ( line != buf + (bufsize - 1) ) /* overflow check */ 00347 continue; 00348 /* falls through */ 00349 default: /* not a function */ 00350 wl: fputs(buf, out); 00351 break; 00352 } 00353 line = buf; 00354 } 00355 if ( line != buf ) 00356 fputs(buf, out); 00357 free(buf); 00358 if ( output_name ) { 00359 output_error = ferror(out); 00360 output_error |= fclose(out); 00361 } else { /* out == stdout */ 00362 fflush(out); 00363 output_error = ferror(out); 00364 } 00365 if ( output_error ) { 00366 fprintf(stderr, "%s: error writing to %s\n", program_name, 00367 (output_name ? output_name : "stdout")); 00368 exit(1); 00369 } 00370 if ( in != stdin ) 00371 fclose(in); 00372 return 0; 00373 }
|
|
|
|
Referenced by test1(). |
|
|
Referenced by main(). |
|
|
Referenced by convert1(). |
|
|
Referenced by convert1(), main(), and test1(). |
|
|
Referenced by main(). |
|
|
Referenced by convert1(). |