Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenansi2knr.c
Go to the documentation of this file.
00001 /* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved. */ 00002 00003 /*$Id: ansi2knr.c,v 1.14 2003/09/06 05:36:56 eggert Exp $*/ 00004 /* Convert ANSI C function definitions to K&R ("traditional C") syntax */ 00005 00006 /* 00007 ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY. No author or distributor accepts responsibility to anyone for the 00009 consequences of using it or for whether it serves any particular purpose or 00010 works at all, unless he says so in writing. Refer to the GNU General Public 00011 License (the "GPL") for full details. 00012 00013 Everyone is granted permission to copy, modify and redistribute ansi2knr, 00014 but only under the conditions described in the GPL. A copy of this license 00015 is supposed to have been given to you along with ansi2knr so you can know 00016 your rights and responsibilities. It should be in a file named COPYLEFT, 00017 or, if there is no file named COPYLEFT, a file named COPYING. Among other 00018 things, the copyright notice and this notice must be preserved on all 00019 copies. 00020 00021 We explicitly state here what we believe is already implied by the GPL: if 00022 the ansi2knr program is distributed as a separate set of sources and a 00023 separate executable file which are aggregated on a storage medium together 00024 with another program, this in itself does not bring the other program under 00025 the GPL, nor does the mere fact that such a program or the procedures for 00026 constructing it invoke the ansi2knr executable bring any other part of the 00027 program under the GPL. 00028 */ 00029 00030 /* 00031 * Usage: 00032 ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]] 00033 * --filename provides the file name for the #line directive in the output, 00034 * overriding input_file (if present). 00035 * If no input_file is supplied, input is read from stdin. 00036 * If no output_file is supplied, output goes to stdout. 00037 * There are no error messages. 00038 * 00039 * ansi2knr recognizes function definitions by seeing a non-keyword 00040 * identifier at the left margin, followed by a left parenthesis, with a 00041 * right parenthesis as the last character on the line, and with a left 00042 * brace as the first token on the following line (ignoring possible 00043 * intervening comments and/or preprocessor directives), except that a line 00044 * consisting of only 00045 * identifier1(identifier2) 00046 * will not be considered a function definition unless identifier2 is 00047 * the word "void", and a line consisting of 00048 * identifier1(identifier2, <<arbitrary>>) 00049 * will not be considered a function definition. 00050 * ansi2knr will recognize a multi-line header provided that no intervening 00051 * line ends with a left or right brace or a semicolon. These algorithms 00052 * ignore whitespace, comments, and preprocessor directives, except that 00053 * the function name must be the first thing on the line. The following 00054 * constructs will confuse it: 00055 * - Any other construct that starts at the left margin and 00056 * follows the above syntax (such as a macro or function call). 00057 * - Some macros that tinker with the syntax of function headers. 00058 */ 00059 00060 /* 00061 * The original and principal author of ansi2knr is L. Peter Deutsch 00062 * <ghost@aladdin.com>. Other authors are noted in the change history 00063 * that follows (in reverse chronological order): 00064 00065 lpd 2000-04-12 backs out Eggert's changes because of bugs: 00066 - concatlits didn't declare the type of its bufend argument; 00067 - concatlits didn't recognize when it was inside a comment; 00068 - scanstring could scan backward past the beginning of the string; when 00069 - the check for \ + newline in scanstring was unnecessary. 00070 00071 2000-03-05 Paul Eggert <eggert@twinsun.com> 00072 00073 Add support for concatenated string literals. 00074 * ansi2knr.c (concatlits): New decl. 00075 (main): Invoke concatlits to concatenate string literals. 00076 (scanstring): Handle backslash-newline correctly. Work with 00077 character constants. Fix bug when scanning backwards through 00078 backslash-quote. Check for unterminated strings. 00079 (convert1): Parse character constants, too. 00080 (appendline, concatlits): New functions. 00081 * ansi2knr.1: Document this. 00082 00083 lpd 1999-08-17 added code to allow preprocessor directives 00084 wherever comments are allowed 00085 lpd 1999-04-12 added minor fixes from Pavel Roskin 00086 <pavel_roskin@geocities.com> for clean compilation with 00087 gcc -W -Wall 00088 lpd 1999-03-22 added hack to recognize lines consisting of 00089 identifier1(identifier2, xxx) as *not* being procedures 00090 lpd 1999-02-03 made indentation of preprocessor commands consistent 00091 lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an 00092 endless loop; quoted strings within an argument list 00093 confused the parser 00094 lpd 1999-01-24 added a check for write errors on the output, 00095 suggested by Jim Meyering <meyering@ascend.com> 00096 lpd 1998-11-09 added further hack to recognize identifier(void) 00097 as being a procedure 00098 lpd 1998-10-23 added hack to recognize lines consisting of 00099 identifier1(identifier2) as *not* being procedures 00100 lpd 1997-12-08 made input_file optional; only closes input and/or 00101 output file if not stdin or stdout respectively; prints 00102 usage message on stderr rather than stdout; adds 00103 --filename switch (changes suggested by 00104 <ceder@lysator.liu.se>) 00105 lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with 00106 compilers that don't understand void, as suggested by 00107 Tom Lane 00108 lpd 1996-01-15 changed to require that the first non-comment token 00109 on the line following a function header be a left brace, 00110 to reduce sensitivity to macros, as suggested by Tom Lane 00111 <tgl@sss.pgh.pa.us> 00112 lpd 1995-06-22 removed #ifndefs whose sole purpose was to define 00113 undefined preprocessor symbols as 0; changed all #ifdefs 00114 for configuration symbols to #ifs 00115 lpd 1995-04-05 changed copyright notice to make it clear that 00116 including ansi2knr in a program does not bring the entire 00117 program under the GPL 00118 lpd 1994-12-18 added conditionals for systems where ctype macros 00119 don't handle 8-bit characters properly, suggested by 00120 Francois Pinard <pinard@iro.umontreal.ca>; 00121 removed --varargs switch (this is now the default) 00122 lpd 1994-10-10 removed CONFIG_BROKETS conditional 00123 lpd 1994-07-16 added some conditionals to help GNU `configure', 00124 suggested by Francois Pinard <pinard@iro.umontreal.ca>; 00125 properly erase prototype args in function parameters, 00126 contributed by Jim Avera <jima@netcom.com>; 00127 correct error in writeblanks (it shouldn't erase EOLs) 00128 lpd 1989-xx-xx original version 00129 */ 00130 00131 /* Most of the conditionals here are to make ansi2knr work with */ 00132 /* or without the GNU configure machinery. */ 00133 00134 #if HAVE_CONFIG_H 00135 # include <config.h> 00136 #endif 00137 00138 #include <stdio.h> 00139 #include <ctype.h> 00140 00141 #if HAVE_CONFIG_H 00142 00143 /* 00144 For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h). 00145 This will define HAVE_CONFIG_H and so, activate the following lines. 00146 */ 00147 00148 # if STDC_HEADERS || HAVE_STRING_H 00149 # include <string.h> 00150 # else 00151 # include <strings.h> 00152 # endif 00153 00154 #else /* not HAVE_CONFIG_H */ 00155 00156 /* Otherwise do it the hard way */ 00157 00158 # ifdef BSD 00159 # include <strings.h> 00160 # else 00161 # ifdef VMS 00162 extern int strlen(), strncmp(); 00163 # else 00164 # include <string.h> 00165 # endif 00166 # endif 00167 00168 #endif /* not HAVE_CONFIG_H */ 00169 00170 #if STDC_HEADERS 00171 # include <stdlib.h> 00172 #else 00173 /* 00174 malloc and free should be declared in stdlib.h, 00175 but if you've got a K&R compiler, they probably aren't. 00176 */ 00177 # ifdef MSDOS 00178 # include <malloc.h> 00179 # else 00180 # ifdef VMS 00181 extern char *malloc(); 00182 extern void free(); 00183 # else 00184 extern char *malloc(); 00185 extern int free(); 00186 # endif 00187 # endif 00188 00189 #endif 00190 00191 /* Define NULL (for *very* old compilers). */ 00192 #ifndef NULL 00193 # define NULL (0) 00194 #endif 00195 00196 /* 00197 * The ctype macros don't always handle 8-bit characters correctly. 00198 * Compensate for this here. 00199 */ 00200 #ifdef isascii 00201 # undef HAVE_ISASCII /* just in case */ 00202 # define HAVE_ISASCII 1 00203 #else 00204 #endif 00205 #if STDC_HEADERS || !HAVE_ISASCII 00206 # define is_ascii(c) 1 00207 #else 00208 # define is_ascii(c) isascii(c) 00209 #endif 00210 00211 #define is_space(c) (is_ascii(c) && isspace(c)) 00212 #define is_alpha(c) (is_ascii(c) && isalpha(c)) 00213 #define is_alnum(c) (is_ascii(c) && isalnum(c)) 00214 00215 /* Scanning macros */ 00216 #define isidchar(ch) (is_alnum(ch) || (ch) == '_') 00217 #define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') 00218 00219 /* Forward references */ 00220 char *ppdirforward(); 00221 char *ppdirbackward(); 00222 char *skipspace(); 00223 char *scanstring(); 00224 int writeblanks(); 00225 int test1(); 00226 int convert1(); 00227 00228 /* The main program */ 00229 int 00230 main(argc, argv) 00231 int argc; 00232 char *argv[]; 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 } 00374 00375 /* 00376 * Skip forward or backward over one or more preprocessor directives. 00377 */ 00378 char * 00379 ppdirforward(p) 00380 char *p; 00381 { 00382 for (; *p == '#'; ++p) { 00383 for (; *p != '\r' && *p != '\n'; ++p) 00384 if (*p == 0) 00385 return p; 00386 if (*p == '\r' && p[1] == '\n') 00387 ++p; 00388 } 00389 return p; 00390 } 00391 char * 00392 ppdirbackward(p, limit) 00393 char *p; 00394 char *limit; 00395 { 00396 char *np = p; 00397 00398 for (;; p = --np) { 00399 if (*np == '\n' && np[-1] == '\r') 00400 --np; 00401 for (; np > limit && np[-1] != '\r' && np[-1] != '\n'; --np) 00402 if (np[-1] == 0) 00403 return np; 00404 if (*np != '#') 00405 return p; 00406 } 00407 } 00408 00409 /* 00410 * Skip over whitespace, comments, and preprocessor directives, 00411 * in either direction. 00412 */ 00413 char * 00414 skipspace(p, dir) 00415 char *p; 00416 int dir; /* 1 for forward, -1 for backward */ 00417 { 00418 for ( ; ; ) { 00419 while ( is_space(*p) ) 00420 p += dir; 00421 if ( !(*p == '/' && p[dir] == '*') ) 00422 break; 00423 p += dir; p += dir; 00424 while ( !(*p == '*' && p[dir] == '/') ) { 00425 if ( *p == 0 ) 00426 return p; /* multi-line comment?? */ 00427 p += dir; 00428 } 00429 p += dir; p += dir; 00430 } 00431 return p; 00432 } 00433 00434 /* Scan over a quoted string, in either direction. */ 00435 char * 00436 scanstring(p, dir) 00437 char *p; 00438 int dir; 00439 { 00440 for (p += dir; ; p += dir) 00441 if (*p == '"' && p[-dir] != '\\') 00442 return p + dir; 00443 } 00444 00445 /* 00446 * Write blanks over part of a string. 00447 * Don't overwrite end-of-line characters. 00448 */ 00449 int 00450 writeblanks(start, end) 00451 char *start; 00452 char *end; 00453 { char *p; 00454 for ( p = start; p < end; p++ ) 00455 if ( *p != '\r' && *p != '\n' ) 00456 *p = ' '; 00457 return 0; 00458 } 00459 00460 /* 00461 * Test whether the string in buf is a function definition. 00462 * The string may contain and/or end with a newline. 00463 * Return as follows: 00464 * 0 - definitely not a function definition; 00465 * 1 - definitely a function definition; 00466 * 2 - definitely a function prototype (NOT USED); 00467 * -1 - may be the beginning of a function definition, 00468 * append another line and look again. 00469 * The reason we don't attempt to convert function prototypes is that 00470 * Ghostscript's declaration-generating macros look too much like 00471 * prototypes, and confuse the algorithms. 00472 */ 00473 int 00474 test1(buf) 00475 char *buf; 00476 { char *p = buf; 00477 char *bend; 00478 char *endfn; 00479 int contin; 00480 00481 if ( !isidfirstchar(*p) ) 00482 return 0; /* no name at left margin */ 00483 bend = skipspace(ppdirbackward(buf + strlen(buf) - 1, buf), -1); 00484 switch ( *bend ) 00485 { 00486 case ';': contin = 0 /*2*/; break; 00487 case ')': contin = 1; break; 00488 case '{': return 0; /* not a function */ 00489 case '}': return 0; /* not a function */ 00490 default: contin = -1; 00491 } 00492 while ( isidchar(*p) ) 00493 p++; 00494 endfn = p; 00495 p = skipspace(p, 1); 00496 if ( *p++ != '(' ) 00497 return 0; /* not a function */ 00498 p = skipspace(p, 1); 00499 if ( *p == ')' ) 00500 return 0; /* no parameters */ 00501 /* Check that the apparent function name isn't a keyword. */ 00502 /* We only need to check for keywords that could be followed */ 00503 /* by a left parenthesis (which, unfortunately, is most of them). */ 00504 { static char *words[] = 00505 { "asm", "auto", "case", "char", "const", "double", 00506 "extern", "float", "for", "if", "int", "long", 00507 "register", "return", "short", "signed", "sizeof", 00508 "static", "switch", "typedef", "unsigned", 00509 "void", "volatile", "while", 0 00510 }; 00511 char **key = words; 00512 char *kp; 00513 unsigned len = endfn - buf; 00514 00515 while ( (kp = *key) != 0 ) 00516 { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) 00517 return 0; /* name is a keyword */ 00518 key++; 00519 } 00520 } 00521 { 00522 char *id = p; 00523 int len; 00524 /* 00525 * Check for identifier1(identifier2) and not 00526 * identifier1(void), or identifier1(identifier2, xxxx). 00527 */ 00528 00529 while ( isidchar(*p) ) 00530 p++; 00531 len = p - id; 00532 p = skipspace(p, 1); 00533 if (*p == ',' || 00534 (*p == ')' && (len != 4 || strncmp(id, "void", 4))) 00535 ) 00536 return 0; /* not a function */ 00537 } 00538 /* 00539 * If the last significant character was a ), we need to count 00540 * parentheses, because it might be part of a formal parameter 00541 * that is a procedure. 00542 */ 00543 if (contin > 0) { 00544 int level = 0; 00545 00546 for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1)) 00547 level += (*p == '(' ? 1 : *p == ')' ? -1 : 0); 00548 if (level > 0) 00549 contin = -1; 00550 } 00551 return contin; 00552 } 00553 00554 /* Convert a recognized function definition or header to K&R syntax. */ 00555 int 00556 convert1(buf, out, header, convert_varargs) 00557 char *buf; 00558 FILE *out; 00559 int header; /* Boolean */ 00560 int convert_varargs; /* Boolean */ 00561 { char *endfn; 00562 char *p; 00563 /* 00564 * The breaks table contains pointers to the beginning and end 00565 * of each argument. 00566 */ 00567 char **breaks; 00568 unsigned num_breaks = 2; /* for testing */ 00569 char **btop; 00570 char **bp; 00571 char **ap; 00572 char *vararg = 0; 00573 00574 /* Pre-ANSI implementations don't agree on whether strchr */ 00575 /* is called strchr or index, so we open-code it here. */ 00576 for ( endfn = buf; *(endfn++) != '('; ) 00577 ; 00578 top: p = endfn; 00579 breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); 00580 if ( breaks == NULL ) 00581 { /* Couldn't allocate break table, give up */ 00582 fprintf(stderr, "Unable to allocate break table!\n"); 00583 fputs(buf, out); 00584 return -1; 00585 } 00586 btop = breaks + num_breaks * 2 - 2; 00587 bp = breaks; 00588 /* Parse the argument list */ 00589 do 00590 { int level = 0; 00591 char *lp = NULL; 00592 char *rp = NULL; 00593 char *end = NULL; 00594 00595 if ( bp >= btop ) 00596 { /* Filled up break table. */ 00597 /* Allocate a bigger one and start over. */ 00598 free((char *)breaks); 00599 num_breaks <<= 1; 00600 goto top; 00601 } 00602 *bp++ = p; 00603 /* Find the end of the argument */ 00604 for ( ; end == NULL; p++ ) 00605 { switch(*p) 00606 { 00607 case ',': 00608 if ( !level ) end = p; 00609 break; 00610 case '(': 00611 if ( !level ) lp = p; 00612 level++; 00613 break; 00614 case ')': 00615 if ( --level < 0 ) end = p; 00616 else rp = p; 00617 break; 00618 case '/': 00619 if (p[1] == '*') 00620 p = skipspace(p, 1) - 1; 00621 break; 00622 case '"': 00623 p = scanstring(p, 1) - 1; 00624 break; 00625 default: 00626 ; 00627 } 00628 } 00629 /* Erase any embedded prototype parameters. */ 00630 if ( lp && rp ) 00631 writeblanks(lp + 1, rp); 00632 p--; /* back up over terminator */ 00633 /* Find the name being declared. */ 00634 /* This is complicated because of procedure and */ 00635 /* array modifiers. */ 00636 for ( ; ; ) 00637 { p = skipspace(p - 1, -1); 00638 switch ( *p ) 00639 { 00640 case ']': /* skip array dimension(s) */ 00641 case ')': /* skip procedure args OR name */ 00642 { int level = 1; 00643 while ( level ) 00644 switch ( *--p ) 00645 { 00646 case ']': case ')': 00647 level++; 00648 break; 00649 case '[': case '(': 00650 level--; 00651 break; 00652 case '/': 00653 if (p > buf && p[-1] == '*') 00654 p = skipspace(p, -1) + 1; 00655 break; 00656 case '"': 00657 p = scanstring(p, -1) + 1; 00658 break; 00659 default: ; 00660 } 00661 } 00662 if ( *p == '(' && *skipspace(p + 1, 1) == '*' ) 00663 { /* We found the name being declared */ 00664 while ( !isidfirstchar(*p) ) 00665 p = skipspace(p, 1) + 1; 00666 goto found; 00667 } 00668 break; 00669 default: 00670 goto found; 00671 } 00672 } 00673 found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' ) 00674 { if ( convert_varargs ) 00675 { *bp++ = "va_alist"; 00676 vararg = p-2; 00677 } 00678 else 00679 { p++; 00680 if ( bp == breaks + 1 ) /* sole argument */ 00681 writeblanks(breaks[0], p); 00682 else 00683 writeblanks(bp[-1] - 1, p); 00684 bp--; 00685 } 00686 } 00687 else 00688 { while ( isidchar(*p) ) p--; 00689 *bp++ = p+1; 00690 } 00691 p = end; 00692 } 00693 while ( *p++ == ',' ); 00694 *bp = p; 00695 /* Make a special check for 'void' arglist */ 00696 if ( bp == breaks+2 ) 00697 { p = skipspace(breaks[0], 1); 00698 if ( !strncmp(p, "void", 4) ) 00699 { p = skipspace(p+4, 1); 00700 if ( p == breaks[2] - 1 ) 00701 { bp = breaks; /* yup, pretend arglist is empty */ 00702 writeblanks(breaks[0], p + 1); 00703 } 00704 } 00705 } 00706 /* Put out the function name and left parenthesis. */ 00707 p = buf; 00708 while ( p != endfn ) putc(*p, out), p++; 00709 /* Put out the declaration. */ 00710 if ( header ) 00711 { fputs(");", out); 00712 for ( p = breaks[0]; *p; p++ ) 00713 if ( *p == '\r' || *p == '\n' ) 00714 putc(*p, out); 00715 } 00716 else 00717 { for ( ap = breaks+1; ap < bp; ap += 2 ) 00718 { p = *ap; 00719 while ( isidchar(*p) ) 00720 putc(*p, out), p++; 00721 if ( ap < bp - 1 ) 00722 fputs(", ", out); 00723 } 00724 fputs(") ", out); 00725 /* Put out the argument declarations */ 00726 for ( ap = breaks+2; ap <= bp; ap += 2 ) 00727 (*ap)[-1] = ';'; 00728 if ( vararg != 0 ) 00729 { *vararg = 0; 00730 fputs(breaks[0], out); /* any prior args */ 00731 fputs("va_dcl", out); /* the final arg */ 00732 fputs(bp[0], out); 00733 } 00734 else 00735 fputs(breaks[0], out); 00736 } 00737 free((char *)breaks); 00738 return 0; 00739 } Generated on Sat May 26 2012 04:18:09 for ReactOS by
1.7.6.1
|