Remove an unneccesary forward declaration for MainParseArgs().
getopt() may be called several times - make sure to set optreset to reset it. Cleanup handling of non-option arguments. Remove some misleading comments. Patch: 7.171 Submitted by: Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
parent
8f5850c6f4
commit
9e1e6570f3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=144896
@ -138,7 +138,6 @@ Lst envFirstVars = Lst_Initializer(envFirstVars);
|
||||
|
||||
Boolean jobsRunning; /* TRUE if the jobs might be running */
|
||||
|
||||
static void MainParseArgs(int, char **);
|
||||
char *chdir_verify_path(const char *, char *);
|
||||
static int ReadMakefile(const char *);
|
||||
static void usage(void);
|
||||
@ -186,9 +185,11 @@ MainParseArgs(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
|
||||
rearg:
|
||||
optind = 1; /* since we're called more than once */
|
||||
optreset = 1;
|
||||
#define OPTFLAGS "ABC:D:E:I:PSV:Xd:ef:ij:km:nqrstv"
|
||||
rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
|
||||
while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
|
||||
switch(c) {
|
||||
|
||||
case 'A':
|
||||
@ -349,34 +350,50 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
oldVars = TRUE;
|
||||
|
||||
/*
|
||||
* See if the rest of the arguments are variable assignments and
|
||||
* perform them if so. Else take them to be targets and stuff them
|
||||
* on the end of the "create" list.
|
||||
* Parse the rest of the arguments.
|
||||
* o Check for variable assignments and perform them if so.
|
||||
* o Check for more flags and restart getopt if so.
|
||||
* o Anything else is taken to be a target and added
|
||||
* to the end of the "create" list.
|
||||
*/
|
||||
for (argv += optind, argc -= optind; *argv; ++argv, --argc)
|
||||
for (; *argv != NULL; ++argv, --argc) {
|
||||
if (Parse_IsVar(*argv)) {
|
||||
char *ptr = MAKEFLAGS_quote(*argv);
|
||||
|
||||
Var_Append(MAKEFLAGS, ptr, VAR_GLOBAL);
|
||||
Parse_DoVar(*argv, VAR_CMD);
|
||||
free(ptr);
|
||||
|
||||
Parse_DoVar(*argv, VAR_CMD);
|
||||
} else {
|
||||
if (!**argv)
|
||||
Punt("illegal (null) argument.");
|
||||
if (**argv == '-') {
|
||||
if ((*argv)[1])
|
||||
optind = 0; /* -flag... */
|
||||
else
|
||||
optind = 1; /* - */
|
||||
} else if ((*argv)[0] == '-') {
|
||||
if ((*argv)[1] == '\0') {
|
||||
/*
|
||||
* (*argv) is a single dash, so we
|
||||
* just ignore it.
|
||||
*/
|
||||
} else {
|
||||
/*
|
||||
* (*argv) is a -flag, so backup argv
|
||||
* and argc, since getopt() expects
|
||||
* options to start in the 2nd position.
|
||||
*/
|
||||
argc++;
|
||||
argv--;
|
||||
goto rearg;
|
||||
}
|
||||
|
||||
} else if ((*argv)[0] == '\0') {
|
||||
Punt("illegal (null) argument.");
|
||||
|
||||
} else {
|
||||
Lst_AtEnd(&create, estrdup(*argv));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -639,9 +656,8 @@ main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* First snag any flags out of the MAKE environment variable.
|
||||
* (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
|
||||
* in a different format).
|
||||
* First snag things out of the MAKEFLAGS environment
|
||||
* variable. Then parse the command line arguments.
|
||||
*/
|
||||
Main_ParseArgLine(getenv("MAKEFLAGS"), 1);
|
||||
|
||||
@ -649,8 +665,6 @@ main(int argc, char **argv)
|
||||
|
||||
/*
|
||||
* Find where we are...
|
||||
* All this code is so that we know where we are when we start up
|
||||
* on a different machine with pmake.
|
||||
*/
|
||||
curdir = cdpath;
|
||||
if (getcwd(curdir, MAXPATHLEN) == NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user