This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR bootstrap/10169: Use getopt_long in mips-tfile.c (take3)


The following is a revision of my patch to fix GNAT PR bootstrap/10169.
http://gcc.gnu.org/ml/gcc-patches/2003-05/msg01752.html

On Tue, 20 May 2003, Joseph S. Myers wrote:
> See what e.g. gcc --version does for examples of the correct format.
gcc is actually a poor example because it breaks the argv[0] rule!


To appease Cantabrigian pedantry, mips-tfile and mips-tdump now support
implementations of --version that conform to the relevant GNU coding
standards:

alpha% mips-tfile --version
mips-tfile (GCC) 3.4 20030520 (experimental)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Unfortunately, the requirement to write to standard out rather than
standard error, and to terminate immediately means that --version isn't
suitable for mips-tfile's previous use of -v anyway.  gcc passes -v
to mips-tfile when it is invoked with -v, hence this option more
accurately corresponds to --verbose.  Doh!

So we now support both --version and --verbose, mysteriously in an
attempt to fix to fix a bootstrap failure on Tru64 caused by getopt
being used without a function prototype caused by a mix-up in libiberty's
include paths. Not to mention the bug fixes to gcov.c and gcov-dump.c.

Don't ask me how we got here, and don't even think to suggest that I
break up the patch to ease the review process :>


The following patch has been tested on alphaev67-dec-osf5.1 with a full
"make bootstrap", all languages except ada and treelang, and regression
checked with a top-level "make -k check" with no new failures.

Ok for mainline?


2003-05-21  Roger Sayle  <roger@eyesopen.com>
	    Kaveh Ghazi  <ghazi@caip.rutgers.edu>

	PR bootstrap/10169
	* mips-tfile.c (main): Use getopt_long instead of getopt.
	Add new command line option --version to display version.
	Treat --verbose like -v to report a single line version.
	(options): New global variable for getopt_long.
	* mips-tdump.c (main): Use getopt_long instead of getopt.
	New command line options -v, --version and -verbose to display
	the program version number (to match mips-tfile's behavior).
	(options): New global variable for getopt_long.

	* gcov.c (options): Zero-terminate getopt_long array.
	* gcov-dump.c (options): Likewise.

	* Makefile.in (mips-tdump.o): Add dependency on version.h.


Index: mips-tfile.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/mips-tfile.c,v
retrieving revision 1.52
diff -c -3 -p -r1.52 mips-tfile.c
*** mips-tfile.c	17 May 2003 22:21:32 -0000	1.52
--- mips-tfile.c	21 May 2003 03:56:26 -0000
*************** Software Foundation, 59 Temple Place - S
*** 611,616 ****
--- 611,619 ----
  #define saber_stop()
  #endif

+ /* Include getopt.h for the sake of getopt_long.  */
+ #include "getopt.h"
+
  #ifndef __LINE__
  #define __LINE__ 0
  #endif
*************** static unsigned	cur_line_alloc	= 0;		/*
*** 1510,1515 ****
--- 1513,1519 ----
  static long	line_number	= 0;		/* current input line number */
  static int	debug		= 0; 		/* trace functions */
  static int	version		= 0; 		/* print version # */
+ static int	verbose		= 0;
  static int	had_errors	= 0;		/* != 0 if errors were found */
  static int	rename_output	= 0;		/* != 0 if rename output file*/
  static int	delete_input	= 0;		/* != 0 if delete input after done */
*************** static const pseudo_ops_t pseudo_ops[] =
*** 1664,1669 ****
--- 1668,1682 ----
  };


+ /* Command line options for getopt_long.  */
+
+ static const struct option options[] =
+ {
+   { "version", 0, 0, 'V' },
+   { "verbose", 0, 0, 'v' },
+   { 0, 0, 0, 0 }
+ };
+
  /* Add a page to a varray object.  */

  STATIC void
*************** main (argc, argv)
*** 4809,4815 ****
    void_type_info = type_info_init;
    void_type_info.basic_type = bt_Void;

!   while ((option = getopt (argc, argv, "d:i:I:o:v")) != EOF)
      switch (option)
        {
        default:
--- 4822,4828 ----
    void_type_info = type_info_init;
    void_type_info.basic_type = bt_Void;

!   while ((option = getopt_long (argc, argv, "d:i:I:o:v", options, NULL)) != -1)
      switch (option)
        {
        default:
*************** main (argc, argv)
*** 4849,4858 ****
--- 4862,4885 ----
  	break;

        case 'v':
+ 	verbose++;
+ 	break;
+
+       case 'V':
  	version++;
  	break;
        }

+   if (version)
+     {
+       printf (_("mips-tfile (GCC) %s\n"), version_string);
+       fputs (_("Copyright (C) 2003 Free Software Foundation, Inc.\n"), stdout);
+       fputs (_("This is free software; see the source for copying conditions.  There is NO\n\
+ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
+      	     stdout);
+       exit (0);
+     }
+
    if (obj_in_name == (char *) 0 && optind <= argc - 2)
      obj_in_name = argv[--argc];

*************** main (argc, argv)
*** 4868,4874 ****
        delete_input = 1;
      }

!   if (object_name == (char *) 0 || had_errors || optind != argc - 1)
      {
        fprintf (stderr, _("Calling Sequence:\n"));
        fprintf (stderr, _("\tmips-tfile [-d <num>] [-v] [-i <o-in-file>] -o <o-out-file> <s-file> (or)\n"));
--- 4895,4913 ----
        delete_input = 1;
      }

!   if (optind != argc - 1)
!     had_errors++;
!
!   if (verbose || had_errors)
!     {
!       fprintf (stderr, _("mips-tfile (GCC) %s"), version_string);
! #ifdef TARGET_VERSION
!       TARGET_VERSION;
! #endif
!       fputc ('\n', stderr);
!     }
!
!   if (object_name == (char *) 0 || had_errors)
      {
        fprintf (stderr, _("Calling Sequence:\n"));
        fprintf (stderr, _("\tmips-tfile [-d <num>] [-v] [-i <o-in-file>] -o <o-out-file> <s-file> (or)\n"));
*************** main (argc, argv)
*** 4881,4896 ****
        fprintf (stderr, _("    3\tDebug level 2 + trace all symbols.\n"));
        fprintf (stderr, _("    4\tDebug level 3 + trace memory allocations.\n"));
        return 1;
-     }
-
-
-   if (version)
-     {
-       fprintf (stderr, _("mips-tfile version %s"), version_string);
- #ifdef TARGET_VERSION
-       TARGET_VERSION;
- #endif
-       fputc ('\n', stderr);
      }

    if (obj_in_name == (char *) 0)
--- 4920,4925 ----
Index: mips-tdump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/mips-tdump.c,v
retrieving revision 1.25
diff -c -3 -p -r1.25 mips-tdump.c
*** mips-tdump.c	16 Dec 2002 18:19:43 -0000	1.25
--- mips-tdump.c	21 May 2003 03:56:27 -0000
***************
*** 1,5 ****
  /* Read and manage MIPS symbol tables from object modules.
!    Copyright (C) 1991, 1994, 1995, 1997, 1998, 1999, 2000, 2001
     Free Software Foundation, Inc.
     Contributed by hartzell@boulder.colorado.edu,
     Rewritten by meissner@osf.org.
--- 1,5 ----
  /* Read and manage MIPS symbol tables from object modules.
!    Copyright (C) 1991, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2003
     Free Software Foundation, Inc.
     Contributed by hartzell@boulder.colorado.edu,
     Rewritten by meissner@osf.org.
*************** Software Foundation, 59 Temple Place - S
*** 25,30 ****
--- 25,31 ----
  #include "system.h"
  #include "coretypes.h"
  #include "tm.h"
+ #include "version.h"
  #ifdef index
  #undef index
  #endif
*************** Software Foundation, 59 Temple Place - S
*** 34,39 ****
--- 35,43 ----
  #include "mips/a.out.h"
  #endif /* CROSS_COMPILE */

+ /* Include getopt.h for the sake of getopt_long.  */
+ #include "getopt.h"
+
  #ifndef MIPS_IS_STAB
  /* Macros for mips-tfile.c to encapsulate stabs in ECOFF, and for
     and mips-tdump.c to print them out.  This is used on the Alpha,
*************** int	 want_line	= 0;	/* print line number
*** 209,214 ****
--- 213,220 ----
  int	 want_rfd	= 0;	/* print relative file desc's */
  int	 want_scope	= 0;	/* print scopes for every symbol */
  int	 tfile		= 0;	/* no global header file */
+ int	 version	= 0;    /* print version # */
+ int	 verbose	= 0;
  int	 tfile_fd;		/* file descriptor of .T file */
  off_t	 tfile_offset;		/* current offset in .T file */
  scope_t	*cur_scope	= 0;	/* list of active scopes */
*************** const struct {const short code; const ch
*** 254,259 ****
--- 260,273 ----
  #undef __define_stab
  };

+ /* Command line options for getopt_long.  */
+
+ static const struct option options[] =
+ {
+   { "version", 0, 0, 'V' },
+   { "verbose", 0, 0, 'v' },
+   { 0, 0, 0, 0 }
+ };

  /* Read some bytes at a specified location, and return a pointer.  */

*************** main (argc, argv)
*** 1434,1440 ****
    /*
     * Process arguments
     */
!   while ((opt = getopt (argc, argv, "alrst")) != EOF)
      switch (opt)
        {
        default:	errors++;	break;
--- 1448,1454 ----
    /*
     * Process arguments
     */
!   while ((opt = getopt_long (argc, argv, "alrsvt", options, NULL)) != -1)
      switch (opt)
        {
        default:	errors++;	break;
*************** main (argc, argv)
*** 1442,1451 ****
        case 'l': want_line++;	break;	/* print line numbers */
        case 'r': want_rfd++;	break;	/* print relative fd's */
        case 's':	want_scope++;	break;	/* print scope info */
!       case 't': tfile++;	break;	/* this is a tfile (without header), and not a .o */
        }

!   if (errors || optind != argc - 1)
      {
        fprintf (stderr, "Calling Sequence:\n");
        fprintf (stderr, "\t%s [-alrst] <object-or-T-file>\n", argv[0]);
--- 1456,1490 ----
        case 'l': want_line++;	break;	/* print line numbers */
        case 'r': want_rfd++;	break;	/* print relative fd's */
        case 's':	want_scope++;	break;	/* print scope info */
!       case 'v': verbose++;	break;  /* print version # */
!       case 'V': version++;	break;  /* print version # */
!       case 't': tfile++;	break;	/* this is a tfile (without header),
! 					   and not a .o */
        }

!   if (version)
!     {
!       printf ("mips-tdump (GCC) %s\n", version_string);
!       fputs ("Copyright (C) 2003 Free Software Foundation, Inc.\n", stdout);
!       fputs ("This is free software; see the source for copying conditions.  There is NO\n\
! warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n",
!              stdout);
!       exit (0);
!     }
!
!   if (optind != argc - 1)
!     errors++;
!
!   if (verbose || errors)
!     {
!       fprintf (stderr, "mips-tdump (GCC) %s", version_string);
! #ifdef TARGET_VERSION
!       TARGET_VERSION;
! #endif
!       fputc ('\n', stderr);
!     }
!
!   if (errors)
      {
        fprintf (stderr, "Calling Sequence:\n");
        fprintf (stderr, "\t%s [-alrst] <object-or-T-file>\n", argv[0]);
*************** main (argc, argv)
*** 1456,1461 ****
--- 1495,1501 ----
        fprintf (stderr, "\t-r Print out relative file descriptors.\n");
        fprintf (stderr, "\t-s Print out the current scopes for an item.\n");
        fprintf (stderr, "\t-t Assume there is no global header (ie, a T-file).\n");
+       fprintf (stderr, "\t-v Print program version.\n");
        return 1;
      }

Index: gcov.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov.c,v
retrieving revision 1.65
diff -c -3 -p -r1.65 gcov.c
*** gcov.c	17 May 2003 22:21:31 -0000	1.65
--- gcov.c	21 May 2003 03:56:27 -0000
*************** static const struct option options[] =
*** 445,450 ****
--- 445,451 ----
    { "object-directory",     required_argument, NULL, 'o' },
    { "object-file",          required_argument, NULL, 'o' },
    { "unconditional-branches", no_argument,     NULL, 'u' },
+   { 0, 0, 0, 0 }
  };

  /* Process args, return index to first non-arg.  */
Index: gcov-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov-dump.c,v
retrieving revision 1.13
diff -c -3 -p -r1.13 gcov-dump.c
*** gcov-dump.c	14 May 2003 16:01:19 -0000	1.13
--- gcov-dump.c	21 May 2003 03:56:28 -0000
*************** static const struct option options[] =
*** 55,60 ****
--- 55,61 ----
    { "version",              no_argument,       NULL, 'v' },
    { "long",                 no_argument,       NULL, 'l' },
    { "positions",	    no_argument,       NULL, 'o' },
+   { 0, 0, 0, 0 }
  };

  static const tag_format_t tag_table[] =
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1056
diff -c -3 -p -r1.1056 Makefile.in
*** Makefile.in	14 May 2003 15:29:07 -0000	1.1056
--- Makefile.in	21 May 2003 03:56:29 -0000
*************** mips-tfile.o : mips-tfile.c $(CONFIG_H)
*** 1793,1799 ****
  mips-tdump: mips-tdump.o version.o $(LIBDEPS)
  	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tdump.o version.o $(LIBS)

! mips-tdump.o : mips-tdump.c $(CONFIG_H) $(RTL_H) $(SYSTEM_H) coretypes.h $(TM_H)

  #
  # Generate header and source files from the machine description,
--- 1793,1799 ----
  mips-tdump: mips-tdump.o version.o $(LIBDEPS)
  	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tdump.o version.o $(LIBS)

! mips-tdump.o : mips-tdump.c $(CONFIG_H) $(RTL_H) $(SYSTEM_H) coretypes.h $(TM_H) version.h

  #
  # Generate header and source files from the machine description,


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]