diff options
author | Nathan Angelacos <nangel@alpinelinux.org> | 2008-12-16 23:20:46 +0000 |
---|---|---|
committer | Nathan Angelacos <nangel@alpinelinux.org> | 2008-12-16 23:20:46 +0000 |
commit | 2f6c83feed1d0b5c37de085b2662edb2a72b8435 (patch) | |
tree | f020b1ebfe1573fbcafc4511f6bbb2f9488bd917 /src | |
parent | bf7b2fbe64c6fa27b094dd7e0b739a9674d9c17c (diff) | |
download | haserl-2f6c83feed1d0b5c37de085b2662edb2a72b8435.tar.bz2 haserl-2f6c83feed1d0b5c37de085b2662edb2a72b8435.tar.xz |
Commit Mark Blythe's OSX argv[1] handling fix
Diffstat (limited to 'src')
-rw-r--r-- | src/haserl.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/haserl.c b/src/haserl.c index 59b38d6..1d0a46d 100644 --- a/src/haserl.c +++ b/src/haserl.c @@ -142,7 +142,7 @@ struct option ga_long_options[] = { {0, 0, 0, 0} }; -const char *gs_short_options = "vhdu:U:H:ans:S"; +const char *gs_short_options = "+vhdu:U:H:ans:S"; /* * Convert 2 char hex string into char it represents @@ -567,7 +567,7 @@ parseCommandLine (int argc, char *argv[]) case 'v': case 'h': printf ("This is " PACKAGE_NAME " version " PACKAGE_VERSION "" - "(http://haserl.sourceforge.net)"); + " (http://haserl.sourceforge.net)\n"); exit (0); break; } @@ -652,7 +652,8 @@ main (int argc, char *argv[]) char *filename = NULL; argv_t *av = NULL; - char **av2; + char **av2 = argv; + int av2c = argc; int command; int count; @@ -685,26 +686,39 @@ main (int argc, char *argv[]) ); return (0); break; - case 2: - filename = argv[1]; - break; - default: /* more than two */ + default: /* more than one */ + /* split combined #! args - linux bundles them as one */ command = argc_argv (argv[1], &av, ""); - /* and we need to add the original argv[0] command for optarg to work */ - av2 = xmalloc (sizeof (char *) * (command + 2)); - av2[0] = argv[0]; - for (count = 0; count < command; count++) - { - av2[count + 1] = av[count].string; - } - parseCommandLine (command + 1, av2); - argv[1] = av[1].string; + if (command > 1) + { + /* rebuild argv into new av2 */ + av2c = argc - 1 + command; + av2 = xmalloc (sizeof (char *) * av2c); + av2[0] = argv[0]; + for (count = 1; count <= command; count++) + { + av2[count] = av[count-1].string; + } + for (; count < av2c; count++) { + av2[count] = argv[count - command + 1]; + } + } + + parseCommandLine (av2c, av2); free (av); - free (av2); - filename = argv[2]; + if (av2 != argv) free (av2); + + if (optind < av2c) + { + filename = av2[optind]; + } + else + { + die_with_message (NULL, NULL, "No script file specified"); + } + break; - /* we silently ignore 3,4,etc. */ } |