pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/bootstrap/bmake Replace getopt with equivalent code. T...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/68ec6b34fd7e
branches:  trunk
changeset: 500098:68ec6b34fd7e
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Oct 02 11:43:34 2005 +0000

description:
Replace getopt with equivalent code. This unbreaks bmake on DragonFly.

Obtained-from: src/usr.bin/make/main.c, rev 1.98

diffstat:

 bootstrap/bmake/main.c |  75 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 59 insertions(+), 16 deletions(-)

diffs (133 lines):

diff -r fc9bc1af415b -r 68ec6b34fd7e bootstrap/bmake/main.c
--- a/bootstrap/bmake/main.c    Sun Oct 02 11:23:08 2005 +0000
+++ b/bootstrap/bmake/main.c    Sun Oct 02 11:43:34 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.2 2005/01/05 21:54:40 tv Exp $      */
+/*     $NetBSD: main.c,v 1.3 2005/10/02 11:43:34 joerg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -39,7 +39,7 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: main.c,v 1.2 2005/01/05 21:54:40 tv Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.3 2005/10/02 11:43:34 joerg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -51,13 +51,13 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.2 2005/01/05 21:54:40 tv Exp $");
+__RCSID("$NetBSD: main.c,v 1.3 2005/10/02 11:43:34 joerg Exp $");
 #endif
 #endif /* not lint */
 #endif
 
 #if !defined(MAKE_BOOTSTRAP) && !defined(lint)
-__IDSTRING(rcs_id,"$Id: main.c,v 1.2 2005/01/05 21:54:40 tv Exp $");
+__IDSTRING(rcs_id,"$Id: main.c,v 1.3 2005/10/02 11:43:34 joerg Exp $");
 #endif
 
 /*-
@@ -194,6 +194,11 @@
        char **argv;
 {
        char *p;
+       int arginc;
+       char *argvalue;
+       const char *getopt_def;
+       char *optscan;
+       Boolean inOption;
        int c;
 
        if (argv[0] == 0)
@@ -205,8 +210,49 @@
 #else
 # define OPTFLAGS "BD:I:J:NPST:V:Wd:ef:ij:km:nqrst"
 #endif
-rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
+#undef optarg
+#define optarg argvalue        
+/* Can't actually use getopt(3) because rescanning is not portable */
+
+       getopt_def = OPTFLAGS;
+rearg: 
+       inOption = FALSE;
+       while(argc > 1) {
+               char *getopt_spec;
+               if(!inOption)
+                       optscan = argv[1];
+               c = *optscan++;
+               arginc = 0;
+               if(inOption) {
+                       if(c == '\0') {
+                               ++argv;
+                               --argc;
+                               inOption = FALSE;
+                               continue;
+                       }
+               } else {
+                       if (c != '-')
+                               break;
+                       inOption = TRUE;
+                       c = *optscan++;
+               }
+               /* '-' found at some earlier point */
+               getopt_spec = strchr(getopt_def, c);
+               if(c != '\0' && getopt_spec != NULL && getopt_spec[1] == ':') {
+                       /* -<something> found, and <something> should have an arg */
+                       inOption = FALSE;
+                       arginc = 1;
+                       argvalue = optscan;
+                       if(*argvalue == '\0') {
+                               argvalue = argv[2];
+                               arginc = 2;
+                       }
+               }
                switch(c) {
+               case '\0':
+                       arginc = 1;
+                       inOption = FALSE;
+                       break;
                case 'D':
                        Var_Set(optarg, "1", VAR_GLOBAL, 0);
                        Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL);
@@ -404,6 +450,8 @@
 #endif
                        usage();
                }
+               argv += arginc;
+               argc -= arginc;
        }
 
        oldVars = TRUE;
@@ -413,20 +461,15 @@
         * perform them if so. Else take them to be targets and stuff them
         * on the end of the "create" list.
         */
-       for (argv += optind, argc -= optind; *argv; ++argv, --argc)
-               if (Parse_IsVar(*argv)) {
-                       Parse_DoVar(*argv, VAR_CMD);
+       for (; argc > 1; ++argv, --argc)
+               if (Parse_IsVar(argv[1])) {
+                       Parse_DoVar(argv[1], VAR_CMD);
                } else {
-                       if (!**argv)
+                       if (!*argv[1])
                                Punt("illegal (null) argument.");
-                       if (**argv == '-') {
-                               if ((*argv)[1])
-                                       optind = 0;     /* -flag... */
-                               else
-                                       optind = 1;     /* - */
+                       if (*argv[1] == '-')
                                goto rearg;
-                       }
-                       (void)Lst_AtEnd(create, (ClientData)estrdup(*argv));
+                       (void)Lst_AtEnd(create, (ClientData)estrdup(argv[1]));
                }
 }
 



Home | Main Index | Thread Index | Old Index