summaryrefslogtreecommitdiffstats
path: root/source/ap/ash/patches/ash-getopt.patch
diff options
context:
space:
mode:
author Patrick J Volkerding <volkerdi@slackware.com>2009-08-26 10:00:38 -0500
committer Eric Hameleers <alien@slackware.com>2018-05-31 22:41:17 +0200
commit5a12e7c134274dba706667107d10d231517d3e05 (patch)
tree55718d5acb710fde798d9f38d0bbaf594ed4b296 /source/ap/ash/patches/ash-getopt.patch
downloadcurrent-5a12e7c134274dba706667107d10d231517d3e05.tar.gz
current-5a12e7c134274dba706667107d10d231517d3e05.tar.xz
Slackware 13.0slackware-13.0
Wed Aug 26 10:00:38 CDT 2009 Slackware 13.0 x86_64 is released as stable! Thanks to everyone who helped make this release possible -- see the RELEASE_NOTES for the credits. The ISOs are off to the replicator. This time it will be a 6 CD-ROM 32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD. We're taking pre-orders now at store.slackware.com. Please consider picking up a copy to help support the project. Once again, thanks to the entire Slackware community for all the help testing and fixing things and offering suggestions during this development cycle. As always, have fun and enjoy! -P.
Diffstat (limited to 'source/ap/ash/patches/ash-getopt.patch')
-rw-r--r--source/ap/ash/patches/ash-getopt.patch198
1 files changed, 198 insertions, 0 deletions
diff --git a/source/ap/ash/patches/ash-getopt.patch b/source/ap/ash/patches/ash-getopt.patch
new file mode 100644
index 000000000..df88ba0df
--- /dev/null
+++ b/source/ap/ash/patches/ash-getopt.patch
@@ -0,0 +1,198 @@
+diff -urN netbsd-sh/options.c ash-0.3.7.orig/options.c
+--- netbsd-sh/options.c Fri Jul 9 13:02:07 1999
++++ ash-0.3.7.orig/options.c Mon Apr 23 22:16:46 2001
+@@ -79,7 +79,7 @@
+ STATIC void options __P((int));
+ STATIC void minus_o __P((char *, int));
+ STATIC void setoption __P((int, int));
+-STATIC int getopts __P((char *, char *, char **, char ***, char **));
++STATIC int getopts __P((char *, char *, char **, int *, int *));
+
+
+ /*
+@@ -118,7 +118,8 @@
+ arg0 = *argptr++;
+
+ shellparam.p = argptr;
+- shellparam.reset = 1;
++ shellparam.optind = 1;
++ shellparam.optoff = -1;
+ /* assert(shellparam.malloc == 0 && shellparam.nparam == 0); */
+ while (*argptr) {
+ shellparam.nparam++;
+@@ -282,7 +283,8 @@
+ shellparam.malloc = 1;
+ shellparam.nparam = nparam;
+ shellparam.p = newparam;
+- shellparam.optnext = NULL;
++ shellparam.optind = 1;
++ shellparam.optoff = -1;
+ }
+
+
+@@ -330,7 +332,8 @@
+ }
+ ap2 = shellparam.p;
+ while ((*ap2++ = *ap1++) != NULL);
+- shellparam.optnext = NULL;
++ shellparam.optind = 1;
++ shellparam.optoff = -1;
+ INTON;
+ return 0;
+ }
+@@ -363,10 +366,8 @@
+ getoptsreset(value)
+ const char *value;
+ {
+- if (number(value) == 1) {
+- shellparam.optnext = NULL;
+- shellparam.reset = 1;
+- }
++ shellparam.optind = number(value);
++ shellparam.optoff = -1;
+ }
+
+ /*
+@@ -385,50 +386,58 @@
+
+ if (argc < 3)
+ error("Usage: getopts optstring var [arg]");
+- else if (argc == 3)
++ else if (argc == 3) {
+ optbase = shellparam.p;
+- else
++ if (shellparam.optind > shellparam.nparam + 1) {
++ shellparam.optind = 1;
++ shellparam.optoff = -1;
++ }
++ }
++ else {
+ optbase = &argv[3];
+-
+- if (shellparam.reset == 1) {
+- shellparam.optnext = optbase;
+- shellparam.optptr = NULL;
+- shellparam.reset = 0;
++ if (shellparam.optind > argc - 2) {
++ shellparam.optind = 1;
++ shellparam.optoff = -1;
++ }
+ }
+
+- return getopts(argv[1], argv[2], optbase, &shellparam.optnext,
+- &shellparam.optptr);
++ return getopts(argv[1], argv[2], optbase, &shellparam.optind,
++ &shellparam.optoff);
+ }
+
+ STATIC int
+-getopts(optstr, optvar, optfirst, optnext, optpptr)
++getopts(optstr, optvar, optfirst, optind, optoff)
+ char *optstr;
+ char *optvar;
+ char **optfirst;
+- char ***optnext;
+- char **optpptr;
++ int *optind;
++ int *optoff;
+ {
+ char *p, *q;
+ char c = '?';
+ int done = 0;
+- int ind = 0;
+ int err = 0;
+ char s[10];
++ char **optnext = optfirst + *optind - 1;
+
+- if ((p = *optpptr) == NULL || *p == '\0') {
++ if (*optind <= 1 || *optoff < 0 || !(*(optnext - 1)) ||
++ strlen(*(optnext - 1)) < *optoff)
++ p = NULL;
++ else
++ p = *(optnext - 1) + *optoff;
++ if (p == NULL || *p == '\0') {
+ /* Current word is done, advance */
+- if (*optnext == NULL)
++ if (optnext == NULL)
+ return 1;
+- p = **optnext;
++ p = *optnext;
+ if (p == NULL || *p != '-' || *++p == '\0') {
+ atend:
+- ind = *optnext - optfirst + 1;
+- *optnext = NULL;
++ *optind = optnext - optfirst + 1;
+ p = NULL;
+ done = 1;
+ goto out;
+ }
+- (*optnext)++;
++ optnext++;
+ if (p[0] == '-' && p[1] == '\0') /* check for "--" */
+ goto atend;
+ }
+@@ -453,7 +462,7 @@
+ }
+
+ if (*++q == ':') {
+- if (*p == '\0' && (p = **optnext) == NULL) {
++ if (*p == '\0' && (p = *optnext) == NULL) {
+ if (optstr[0] == ':') {
+ s[0] = c;
+ s[1] = '\0';
+@@ -468,30 +477,29 @@
+ goto bad;
+ }
+
+- if (p == **optnext)
+- (*optnext)++;
++ if (p == *optnext)
++ optnext++;
+ setvarsafe("OPTARG", p, 0);
+ p = NULL;
+ }
+ else
+ setvarsafe("OPTARG", "", 0);
+- ind = *optnext - optfirst + 1;
++ *optind = optnext - optfirst + 1;
+ goto out;
+
+ bad:
+- ind = 1;
+- *optnext = NULL;
++ *optind = 1;
+ p = NULL;
+ out:
+- *optpptr = p;
+- fmtstr(s, sizeof(s), "%d", ind);
++ *optoff = p ? p - *(optnext - 1) : -1;
++ fmtstr(s, sizeof(s), "%d", *optind);
+ err |= setvarsafe("OPTIND", s, VNOFUNC);
+ s[0] = c;
+ s[1] = '\0';
+ err |= setvarsafe(optvar, s, 0);
+ if (err) {
+- *optnext = NULL;
+- *optpptr = NULL;
++ *optind = 1;
++ *optoff = -1;
+ flushall();
+ exraise(EXERROR);
+ }
+diff -urN netbsd-sh/options.h ash-0.3.7.orig/options.h
+--- netbsd-sh/options.h Fri Jul 9 13:02:07 1999
++++ ash-0.3.7.orig/options.h Mon Apr 23 22:16:46 2001
+@@ -41,10 +41,9 @@
+ struct shparam {
+ int nparam; /* # of positional parameters (without $0) */
+ unsigned char malloc; /* if parameter list dynamically allocated */
+- unsigned char reset; /* if getopts has been reset */
+ char **p; /* parameter list */
+- char **optnext; /* next parameter to be processed by getopts */
+- char *optptr; /* used by getopts */
++ int optind; /* next parameter to be processed by getopts */
++ int optoff; /* used by getopts */
+ };
+
+
+