diff options
author | Tom Tromey <tromey@redhat.com> | 1999-04-12 15:15:03 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 1999-04-12 15:15:03 +0000 |
commit | 6900e1aa4f949fc55e1daa60d1a5094d2d6deb7d (patch) | |
tree | d2df8306558302b5b2dbda268799cb8ed4acb5f7 | |
parent | c2704136296089eb6898ef65e70f2645e5cd520b (diff) | |
download | automake-6900e1aa4f949fc55e1daa60d1a5094d2d6deb7d.tar.gz |
* ansi2knr.c: New version from Pavel Roskin (via ansi2knr.c
maintainer).
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | ansi2knr.c | 45 | ||||
-rw-r--r-- | lib/ansi2knr.c | 45 |
4 files changed, 73 insertions, 24 deletions
@@ -1,3 +1,8 @@ +1999-04-12 Tom Tromey <tromey@cygnus.com> + + * ansi2knr.c: New version from Pavel Roskin (via ansi2knr.c + maintainer). + 1999-04-11 Tom Tromey <tromey@cygnus.com> * automake.in (handle_dist): Use AMTAR. @@ -7,6 +7,8 @@ try to find a losing compiler and see if it really works. (actually: hack config.cache and do it) +* test `make clean' with subdir-objects + * Test nodist_SOURCES with lex, yacc, etc. * Support subdir-objects with fortran diff --git a/ansi2knr.c b/ansi2knr.c index 061f69678..41425eca7 100644 --- a/ansi2knr.c +++ b/ansi2knr.c @@ -1,6 +1,6 @@ /* Copyright (C) 1989, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. */ -/*$Id: ansi2knr.c,v 1.11 1999/01/29 14:22:15 tromey Exp $*/ +/*$Id: ansi2knr.c,v 1.12 1999/04/12 15:15:03 tromey Exp $*/ /* Convert ANSI C function definitions to K&R ("traditional C") syntax */ /* @@ -44,7 +44,10 @@ program under the GPL. * consisting of only * identifier1(identifier2) * will not be considered a function definition unless identifier2 is - * the word "void". ansi2knr will recognize a multi-line header provided + * the word "void", and a line consisting of + * identifier1(identifier2, <<arbitrary>>) + * will not be considered a function definition. + * ansi2knr will recognize a multi-line header provided * that no intervening line ends with a left or right brace or a semicolon. * These algorithms ignore whitespace and comments, except that * the function name must be the first thing on the line. @@ -58,6 +61,12 @@ program under the GPL. * The original and principal author of ansi2knr is L. Peter Deutsch * <ghost@aladdin.com>. Other authors are noted in the change history * that follows (in reverse chronological order): + lpd 1999-04-12 added minor fixes from Pavel Roskin + <pavel_roskin@geocities.com> for clean compilation with + gcc -W -Wall + lpd 1999-03-22 added hack to recognize lines consisting of + identifier1(identifier2, xxx) as *not* being procedures + lpd 1999-02-03 made indentation of preprocessor commands consistent lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an endless loop; quoted strings within an argument list confused the parser @@ -158,19 +167,24 @@ program under the GPL. #endif +/* Define NULL (for *very* old compilers). */ +#ifndef NULL +# define NULL (0) +#endif + /* * The ctype macros don't always handle 8-bit characters correctly. * Compensate for this here. */ #ifdef isascii -# undef HAVE_ISASCII /* just in case */ -# define HAVE_ISASCII 1 +# undef HAVE_ISASCII /* just in case */ +# define HAVE_ISASCII 1 #else #endif #if STDC_HEADERS || !HAVE_ISASCII -# define is_ascii(c) 1 +# define is_ascii(c) 1 #else -# define is_ascii(c) isascii(c) +# define is_ascii(c) isascii(c) #endif #define is_space(c) (is_ascii(c) && isspace(c)) @@ -263,6 +277,11 @@ main(argc, argv) if ( filename ) fprintf(out, "#line 1 \"%s\"\n", filename); buf = malloc(bufsize); + if ( buf == NULL ) + { + fprintf(stderr, "Unable to allocate read buffer!\n"); + exit(1); + } line = buf; while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) { @@ -430,7 +449,7 @@ test1(buf) }; char **key = words; char *kp; - int len = endfn - buf; + unsigned len = endfn - buf; while ( (kp = *key) != 0 ) { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) @@ -443,14 +462,16 @@ test1(buf) int len; /* * Check for identifier1(identifier2) and not - * identifier1(void). + * identifier1(void), or identifier1(identifier2, xxxx). */ while ( isidchar(*p) ) p++; len = p - id; p = skipspace(p, 1); - if ( *p == ')' && (len != 4 || strncmp(id, "void", 4)) ) + if (*p == ',' || + (*p == ')' && (len != 4 || strncmp(id, "void", 4))) + ) return 0; /* not a function */ } /* @@ -495,7 +516,7 @@ convert1(buf, out, header, convert_varargs) ; top: p = endfn; breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); - if ( breaks == 0 ) + if ( breaks == NULL ) { /* Couldn't allocate break table, give up */ fprintf(stderr, "Unable to allocate break table!\n"); fputs(buf, out); @@ -507,7 +528,7 @@ top: p = endfn; do { int level = 0; char *lp = NULL; - char *rp; + char *rp = NULL; char *end = NULL; if ( bp >= btop ) @@ -545,7 +566,7 @@ top: p = endfn; } } /* Erase any embedded prototype parameters. */ - if ( lp ) + if ( lp && rp ) writeblanks(lp + 1, rp); p--; /* back up over terminator */ /* Find the name being declared. */ diff --git a/lib/ansi2knr.c b/lib/ansi2knr.c index 061f69678..41425eca7 100644 --- a/lib/ansi2knr.c +++ b/lib/ansi2knr.c @@ -1,6 +1,6 @@ /* Copyright (C) 1989, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. */ -/*$Id: ansi2knr.c,v 1.11 1999/01/29 14:22:15 tromey Exp $*/ +/*$Id: ansi2knr.c,v 1.12 1999/04/12 15:15:03 tromey Exp $*/ /* Convert ANSI C function definitions to K&R ("traditional C") syntax */ /* @@ -44,7 +44,10 @@ program under the GPL. * consisting of only * identifier1(identifier2) * will not be considered a function definition unless identifier2 is - * the word "void". ansi2knr will recognize a multi-line header provided + * the word "void", and a line consisting of + * identifier1(identifier2, <<arbitrary>>) + * will not be considered a function definition. + * ansi2knr will recognize a multi-line header provided * that no intervening line ends with a left or right brace or a semicolon. * These algorithms ignore whitespace and comments, except that * the function name must be the first thing on the line. @@ -58,6 +61,12 @@ program under the GPL. * The original and principal author of ansi2knr is L. Peter Deutsch * <ghost@aladdin.com>. Other authors are noted in the change history * that follows (in reverse chronological order): + lpd 1999-04-12 added minor fixes from Pavel Roskin + <pavel_roskin@geocities.com> for clean compilation with + gcc -W -Wall + lpd 1999-03-22 added hack to recognize lines consisting of + identifier1(identifier2, xxx) as *not* being procedures + lpd 1999-02-03 made indentation of preprocessor commands consistent lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an endless loop; quoted strings within an argument list confused the parser @@ -158,19 +167,24 @@ program under the GPL. #endif +/* Define NULL (for *very* old compilers). */ +#ifndef NULL +# define NULL (0) +#endif + /* * The ctype macros don't always handle 8-bit characters correctly. * Compensate for this here. */ #ifdef isascii -# undef HAVE_ISASCII /* just in case */ -# define HAVE_ISASCII 1 +# undef HAVE_ISASCII /* just in case */ +# define HAVE_ISASCII 1 #else #endif #if STDC_HEADERS || !HAVE_ISASCII -# define is_ascii(c) 1 +# define is_ascii(c) 1 #else -# define is_ascii(c) isascii(c) +# define is_ascii(c) isascii(c) #endif #define is_space(c) (is_ascii(c) && isspace(c)) @@ -263,6 +277,11 @@ main(argc, argv) if ( filename ) fprintf(out, "#line 1 \"%s\"\n", filename); buf = malloc(bufsize); + if ( buf == NULL ) + { + fprintf(stderr, "Unable to allocate read buffer!\n"); + exit(1); + } line = buf; while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) { @@ -430,7 +449,7 @@ test1(buf) }; char **key = words; char *kp; - int len = endfn - buf; + unsigned len = endfn - buf; while ( (kp = *key) != 0 ) { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) @@ -443,14 +462,16 @@ test1(buf) int len; /* * Check for identifier1(identifier2) and not - * identifier1(void). + * identifier1(void), or identifier1(identifier2, xxxx). */ while ( isidchar(*p) ) p++; len = p - id; p = skipspace(p, 1); - if ( *p == ')' && (len != 4 || strncmp(id, "void", 4)) ) + if (*p == ',' || + (*p == ')' && (len != 4 || strncmp(id, "void", 4))) + ) return 0; /* not a function */ } /* @@ -495,7 +516,7 @@ convert1(buf, out, header, convert_varargs) ; top: p = endfn; breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); - if ( breaks == 0 ) + if ( breaks == NULL ) { /* Couldn't allocate break table, give up */ fprintf(stderr, "Unable to allocate break table!\n"); fputs(buf, out); @@ -507,7 +528,7 @@ top: p = endfn; do { int level = 0; char *lp = NULL; - char *rp; + char *rp = NULL; char *end = NULL; if ( bp >= btop ) @@ -545,7 +566,7 @@ top: p = endfn; } } /* Erase any embedded prototype parameters. */ - if ( lp ) + if ( lp && rp ) writeblanks(lp + 1, rp); p--; /* back up over terminator */ /* Find the name being declared. */ |