mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Fix loader usage, shave off a few bytes (#1016)
* Remove -f from loader usage -f was removed in 1.5. As there is now only one flag, a couple more bytes can be shaved off as well. * Further loader golf Shaves off a few bytes, paying for the cost of `RealPath` and then some on x86_64 and offsetting some of the cost to aarch64. * Shave off a few more bytes Removes `-h` and flags from usage. Keeps flag-parsing logic the same, i.e. still accepts `-h` / `--help`. Only difference is what fd and rc the usage uses. Still over 1k north of 8192.
This commit is contained in:
parent
10b4693e37
commit
c9550afe5e
1 changed files with 8 additions and 23 deletions
31
ape/loader.c
31
ape/loader.c
|
@ -901,13 +901,8 @@ __attribute__((__noreturn__)) static void ShowUsage(int os, int fd, int rc) {
|
|||
"\n"
|
||||
"USAGE\n"
|
||||
"\n"
|
||||
" ape [FLAGS] PROG [ARGV1,ARGV2,...]\n"
|
||||
" ape [FLAGS] - PROG [ARGV0,ARGV1,...]\n"
|
||||
"\n"
|
||||
"FLAGS\n"
|
||||
"\n"
|
||||
" -h show this help\n"
|
||||
" -f force loading of program (do not use execve)\n"
|
||||
" ape PROG [ARGV1,ARGV2,...]\n"
|
||||
" ape - PROG [ARGV0,ARGV1,...]\n"
|
||||
"\n",
|
||||
0l);
|
||||
Exit(rc, os);
|
||||
|
@ -982,20 +977,6 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
|
|||
os = LINUX;
|
||||
}
|
||||
|
||||
/* parse flags */
|
||||
while (argc > 1) {
|
||||
if (argv[1][0] != '-') break; /* normal argument */
|
||||
if (!argv[1][1]) break; /* hyphen argument */
|
||||
if (!StrCmp(argv[1], "-h") || !StrCmp(argv[1], "--help")) {
|
||||
ShowUsage(os, 1, 0);
|
||||
} else {
|
||||
Print(os, 2, ape, ": invalid flag (pass -h for help)\n", 0l);
|
||||
Exit(1, os);
|
||||
}
|
||||
*++sp = --argc;
|
||||
++argv;
|
||||
}
|
||||
|
||||
/* we can load via shell, shebang, or binfmt_misc */
|
||||
if ((literally = argc >= 3 && !StrCmp(argv[1], "-"))) {
|
||||
/* if the first argument is a hyphen then we give the user the
|
||||
|
@ -1006,9 +987,13 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
|
|||
argc = sp[3] = sp[0] - 3;
|
||||
argv = (char **)((sp += 3) + 1);
|
||||
} else if (argc < 2) {
|
||||
Print(os, 2, ape, ": missing command name (pass -h for help)\n", 0l);
|
||||
Exit(1, os);
|
||||
ShowUsage(os, 2, 1);
|
||||
} else {
|
||||
if (argv[1][0] == '-') {
|
||||
rc = !(argv[1][1] == 'h' && !argv[1][2]) || !StrCmp(argv[1] + 1,
|
||||
"-help");
|
||||
ShowUsage(os, 1 + rc, rc);
|
||||
}
|
||||
prog = (char *)sp[2];
|
||||
argc = sp[1] = sp[0] - 1;
|
||||
argv = (char **)((sp += 1) + 1);
|
||||
|
|
Loading…
Reference in a new issue