new ansi2knr
authorTom Tromey <tromey@redhat.com>
Wed, 1 Apr 1998 04:10:39 +0000 (04:10 +0000)
committerTom Tromey <tromey@redhat.com>
Wed, 1 Apr 1998 04:10:39 +0000 (04:10 +0000)
ChangeLog
THANKS
ansi2knr.c
automake.in
lib/ansi2knr.c

index 880967c..054ab13 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Mar 31 21:07:42 1998  Tom Tromey  <tromey@cygnus.com>
+
+       * automake.in (handle_yacc_lex_cxx): Changed to use new version of
+       ansi2knr.
+       * ansi2knr.c: New version from L. Peter Deutsch.
+
 Thu Mar 26 11:00:04 1998  Tom Tromey  <tromey@cygnus.com>
 
        * m4/exeext.m4: Correctly eliminate bad cases when computing
diff --git a/THANKS b/THANKS
index b38d9cc..1ba9a32 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -40,6 +40,7 @@ Joshua Cowan          jcowan@jcowan.reslife.okstate.edu
 Juergen A. Erhard      jae@laden.ilk.de
 Karl Berry             kb@cs.umb.edu
 Kevin Dalley           kevin@aimnet.com
+L. Peter Deutsch       ghost@aladdin.com
 Maciej W. Rozycki      macro@ds2.pg.gda.pl
 Marius Vollmer         mvo@zagadka.ping.de
 Mark Eichin            eichin@cygnus.com
index 791eee0..3dd5086 100644 (file)
@@ -1,6 +1,3 @@
-/* ansi2knr.c */
-/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
-
 /*
 ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
 WARRANTY.  No author or distributor accepts responsibility to anyone for the
@@ -11,9 +8,10 @@ License (the "GPL") for full details.
 Everyone is granted permission to copy, modify and redistribute ansi2knr,
 but only under the conditions described in the GPL.  A copy of this license
 is supposed to have been given to you along with ansi2knr so you can know
-your rights and responsibilities.  It should be in a file named COPYLEFT.
-Among other things, the copyright notice and this notice must be preserved
-on all copies.
+your rights and responsibilities.  It should be in a file named COPYLEFT,
+or, if there is no file named COPYLEFT, a file named COPYING.  Among other
+things, the copyright notice and this notice must be preserved on all
+copies.
 
 We explicitly state here what we believe is already implied by the GPL: if
 the ansi2knr program is distributed as a separate set of sources and a
@@ -26,7 +24,10 @@ program under the GPL.
 
 /*
  * Usage:
-       ansi2knr input_file [output_file]
+       ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]
+ * --filename provides the file name for the #line directive in the output,
+ * overriding input_file (if present).
+ * If no input_file is supplied, input is read from stdin.
  * If no output_file is supplied, output goes to stdout.
  * There are no error messages.
  *
@@ -49,6 +50,11 @@ 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 97-12-08 made input_file optional; only closes input and/or
+               output file if not stdin or stdout respectively; prints
+               usage message on stderr rather than stdout; adds
+               --filename switch (changes suggested by
+               <ceder@lysator.liu.se>)
        lpd 96-01-21 added code to cope with not HAVE_CONFIG_H and with
                compilers that don't understand void, as suggested by
                Tom Lane
@@ -169,11 +175,15 @@ int
 main(argc, argv)
     int argc;
     char *argv[];
-{      FILE *in, *out;
+{      FILE *in = stdin;
+       FILE *out = stdout;
+       char *filename = 0;
 #define bufsize 5000                   /* arbitrary size */
        char *buf;
        char *line;
        char *more;
+       char *usage =
+         "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
        /*
         * In previous versions, ansi2knr recognized a --varargs switch.
         * If this switch was supplied, ansi2knr would attempt to convert
@@ -184,41 +194,49 @@ main(argc, argv)
         */
        int convert_varargs = 1;
 
-       if ( argc > 1 && argv[1][0] == '-' && argv[1][1] )
-         {     if ( !strcmp(argv[1], "--varargs") )
-                 {     convert_varargs = 1;
-                       argc--;
-                       argv++;
-                 }
-               else
-                 {     fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
-                       exit(1);
-                 }
+       while ( argc > 1 && argv[1][0] == '-' ) {
+         if ( !strcmp(argv[1], "--varargs") ) {
+           convert_varargs = 1;
+           argc--;
+           argv++;
+           continue;
+         }
+         if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
+           filename = argv[2];
+           argc -= 2;
+           argv += 2;
+           continue;
          }
+         fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
+         fprintf(stderr, usage);
+         exit(1);
+       }
        switch ( argc )
           {
        default:
-               printf("Usage: ansi2knr input_file [output_file]\n");
+               fprintf(stderr, usage);
                exit(0);
-       case 2:
-               out = stdout;
-               break;
        case 3:
                out = fopen(argv[2], "w");
-               if ( out == NULL )
-                  {    fprintf(stderr, "Cannot open output file %s\n", argv[2]);
-                       exit(1);
-                  }
-          }
-       if ( argv[1][0] == '-' && !argv[1][1] )
-          in = stdin;
-       else
-          in = fopen(argv[1], "r");
-       if ( in == NULL )
-          {    fprintf(stderr, "Cannot open input file %s\n", argv[1]);
-               exit(1);
+               if ( out == NULL ) {
+                 fprintf(stderr, "Cannot open output file %s\n", argv[2]);
+                 exit(1);
+               }
+               /* falls through */
+       case 2:
+               in = fopen(argv[1], "r");
+               if ( in == NULL ) {
+                 fprintf(stderr, "Cannot open input file %s\n", argv[1]);
+                 exit(1);
+               }
+               if ( filename == 0 )
+                 filename = argv[1];
+               /* falls through */
+       case 1:
+               break;
           }
-       fprintf(out, "#line 1 \"%s\"\n", argv[1]);
+       if ( filename )
+         fprintf(out, "#line 1 \"%s\"\n", filename);
        buf = malloc(bufsize);
        line = buf;
        while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
@@ -270,8 +288,10 @@ wl:                        fputs(buf, out);
        if ( line != buf )
          fputs(buf, out);
        free(buf);
-       fclose(out);
-       fclose(in);
+       if ( out != stdout )
+         fclose(out);
+       if ( in != stdin )
+         fclose(in);
        return 0;
 }
 
index 41ce3d5..091ce4c 100755 (executable)
@@ -1016,7 +1016,7 @@ sub handle_yacc_lex_cxx
                              . '`if test -f $(srcdir)/' . $base . '.c'
                              . '; then echo $(srcdir)/' . $base . '.c'
                              . '; else echo ' . $base . '.c; fi` '
-                             . '| $(ANSI2KNR) ' . $base . "_.c\n");
+                             . '| $(ANSI2KNR) ' . $base . "_.c\n");
            push (@objects, $base . '_.o');
            push (@objects, $base . '_.lo') if $seen_libtool;
        }
index 791eee0..3dd5086 100644 (file)
@@ -1,6 +1,3 @@
-/* ansi2knr.c */
-/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
-
 /*
 ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
 WARRANTY.  No author or distributor accepts responsibility to anyone for the
@@ -11,9 +8,10 @@ License (the "GPL") for full details.
 Everyone is granted permission to copy, modify and redistribute ansi2knr,
 but only under the conditions described in the GPL.  A copy of this license
 is supposed to have been given to you along with ansi2knr so you can know
-your rights and responsibilities.  It should be in a file named COPYLEFT.
-Among other things, the copyright notice and this notice must be preserved
-on all copies.
+your rights and responsibilities.  It should be in a file named COPYLEFT,
+or, if there is no file named COPYLEFT, a file named COPYING.  Among other
+things, the copyright notice and this notice must be preserved on all
+copies.
 
 We explicitly state here what we believe is already implied by the GPL: if
 the ansi2knr program is distributed as a separate set of sources and a
@@ -26,7 +24,10 @@ program under the GPL.
 
 /*
  * Usage:
-       ansi2knr input_file [output_file]
+       ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]
+ * --filename provides the file name for the #line directive in the output,
+ * overriding input_file (if present).
+ * If no input_file is supplied, input is read from stdin.
  * If no output_file is supplied, output goes to stdout.
  * There are no error messages.
  *
@@ -49,6 +50,11 @@ 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 97-12-08 made input_file optional; only closes input and/or
+               output file if not stdin or stdout respectively; prints
+               usage message on stderr rather than stdout; adds
+               --filename switch (changes suggested by
+               <ceder@lysator.liu.se>)
        lpd 96-01-21 added code to cope with not HAVE_CONFIG_H and with
                compilers that don't understand void, as suggested by
                Tom Lane
@@ -169,11 +175,15 @@ int
 main(argc, argv)
     int argc;
     char *argv[];
-{      FILE *in, *out;
+{      FILE *in = stdin;
+       FILE *out = stdout;
+       char *filename = 0;
 #define bufsize 5000                   /* arbitrary size */
        char *buf;
        char *line;
        char *more;
+       char *usage =
+         "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
        /*
         * In previous versions, ansi2knr recognized a --varargs switch.
         * If this switch was supplied, ansi2knr would attempt to convert
@@ -184,41 +194,49 @@ main(argc, argv)
         */
        int convert_varargs = 1;
 
-       if ( argc > 1 && argv[1][0] == '-' && argv[1][1] )
-         {     if ( !strcmp(argv[1], "--varargs") )
-                 {     convert_varargs = 1;
-                       argc--;
-                       argv++;
-                 }
-               else
-                 {     fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
-                       exit(1);
-                 }
+       while ( argc > 1 && argv[1][0] == '-' ) {
+         if ( !strcmp(argv[1], "--varargs") ) {
+           convert_varargs = 1;
+           argc--;
+           argv++;
+           continue;
+         }
+         if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
+           filename = argv[2];
+           argc -= 2;
+           argv += 2;
+           continue;
          }
+         fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
+         fprintf(stderr, usage);
+         exit(1);
+       }
        switch ( argc )
           {
        default:
-               printf("Usage: ansi2knr input_file [output_file]\n");
+               fprintf(stderr, usage);
                exit(0);
-       case 2:
-               out = stdout;
-               break;
        case 3:
                out = fopen(argv[2], "w");
-               if ( out == NULL )
-                  {    fprintf(stderr, "Cannot open output file %s\n", argv[2]);
-                       exit(1);
-                  }
-          }
-       if ( argv[1][0] == '-' && !argv[1][1] )
-          in = stdin;
-       else
-          in = fopen(argv[1], "r");
-       if ( in == NULL )
-          {    fprintf(stderr, "Cannot open input file %s\n", argv[1]);
-               exit(1);
+               if ( out == NULL ) {
+                 fprintf(stderr, "Cannot open output file %s\n", argv[2]);
+                 exit(1);
+               }
+               /* falls through */
+       case 2:
+               in = fopen(argv[1], "r");
+               if ( in == NULL ) {
+                 fprintf(stderr, "Cannot open input file %s\n", argv[1]);
+                 exit(1);
+               }
+               if ( filename == 0 )
+                 filename = argv[1];
+               /* falls through */
+       case 1:
+               break;
           }
-       fprintf(out, "#line 1 \"%s\"\n", argv[1]);
+       if ( filename )
+         fprintf(out, "#line 1 \"%s\"\n", filename);
        buf = malloc(bufsize);
        line = buf;
        while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
@@ -270,8 +288,10 @@ wl:                        fputs(buf, out);
        if ( line != buf )
          fputs(buf, out);
        free(buf);
-       fclose(out);
-       fclose(in);
+       if ( out != stdout )
+         fclose(out);
+       if ( in != stdin )
+         fclose(in);
        return 0;
 }