summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-04-11 07:32:49 +0000
committerharti <harti@FreeBSD.org>2005-04-11 07:32:49 +0000
commit6a44af4932eddc7dbc1c5ba0a714322faf4a78dc (patch)
treea098d26efdbd140eda22f2fc614c955d9bc49c5f /usr.bin/make
parent31837fbbe6b2e2bc00f1f13b99e53fd052e247b6 (diff)
downloadFreeBSD-src-6a44af4932eddc7dbc1c5ba0a714322faf4a78dc.zip
FreeBSD-src-6a44af4932eddc7dbc1c5ba0a714322faf4a78dc.tar.gz
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>
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/main.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 1e20813..e031760 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -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)
OpenPOWER on IntegriCloud