From bc876efb37b95a12ad4d9ea027697e48b1f8d7fb Mon Sep 17 00:00:00 2001 From: joerg Date: Sun, 2 Oct 2005 11:43:34 +0000 Subject: Replace getopt with equivalent code. This unbreaks bmake on DragonFly. Obtained-from: src/usr.bin/make/main.c, rev 1.98 --- bootstrap/bmake/main.c | 75 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 16 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap/bmake/main.c b/bootstrap/bmake/main.c index c331b7a66d9..bd7a765202e 100644 --- a/bootstrap/bmake/main.c +++ b/bootstrap/bmake/main.c @@ -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 #ifndef lint @@ -51,13 +51,13 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\ #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 @@ MainParseArgs(argc, argv) 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 @@ MainParseArgs(argc, argv) #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] == ':') { + /* - found, and 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 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { #endif usage(); } + argv += arginc; + argc -= arginc; } oldVars = TRUE; @@ -413,20 +461,15 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { * 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])); } } -- cgit v1.2.3