zsh-workers
 help / color / mirror / code / Atom feed
* more metafied options
@ 1996-12-01 15:46 Zefram
  0 siblings, 0 replies; only message in thread
From: Zefram @ 1996-12-01 15:46 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

Grr.  set, setopt, ulimit, compctl and getopts all have their own option
processing code, all of which need fixing to handle metafied options.
In the case of getopts, slightly more extensive modification is necessary
in order to make it fully 8-bit clean.  This patch also regularises the
"bad option" error messages, which were previously evenly divided between
"-%c" and "%c" for reporting the option letter.

 -zefram

      Index: Src/builtin.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/builtin.c,v
      retrieving revision 1.37
      diff -c -r1.37 builtin.c
      *** Src/builtin.c	1996/11/29 15:18:27	1.37
      --- Src/builtin.c	1996/11/30 23:30:47
      ***************
      *** 112,118 ****
        	    if (*arg) {
        		if(*arg == Meta)
        		    *++arg ^= 32;
      ! 		zerr("bad option: %c", NULL, *arg);
        		zsfree(xarg);
        		return 1;
        	    }
      --- 112,118 ----
        	    if (*arg) {
        		if(*arg == Meta)
        		    *++arg ^= 32;
      ! 		zerr("bad option: -%c", NULL, *arg);
        		zsfree(xarg);
        		return 1;
        	    }
      ***************
      *** 289,294 ****
      --- 289,296 ----
        	if(!args[0][1])
        	    *args = "--";
        	while (*++*args) {
      + 	    if(**args == Meta)
      + 		*++*args ^= 32;
        	    if(**args != '-' || action)
        		hadopt = 1;
        	    /* The pseudo-option `--' signifies the end of options. */
      ***************
      *** 394,399 ****
      --- 396,403 ----
        	if(!args[0][1])
        	    *args = "--";
        	while (*++*args) {
      + 	    if(**args == Meta)
      + 		*++*args ^= 32;
        	    /* The pseudo-option `--' signifies the end of options. */
        	    if (**args == '-') {
        		args++;
      ***************
      *** 1542,1548 ****
            for (; !ready && argv[0] && argv[0][0] == '-' && (argv[0][1] || !first);) {
        	if (!argv[0][1])
        	    *argv = "-+";
      ! 	while (!ready && *++(*argv))
        	    switch (**argv) {
        	    case 'f':
        		cct.mask |= CC_FILES;
      --- 1546,1554 ----
            for (; !ready && argv[0] && argv[0][0] == '-' && (argv[0][1] || !first);) {
        	if (!argv[0][1])
        	    *argv = "-+";
      ! 	while (!ready && *++(*argv)) {
      ! 	    if(**argv == Meta)
      ! 		*++*argv ^= 32;
        	    switch (**argv) {
        	    case 'f':
        		cct.mask |= CC_FILES;
      ***************
      *** 1813,1822 ****
        		if (!first && (**argv == '-' || **argv == '+'))
        		    (*argv)--, argv--, ready = 1;
        		else {
      ! 		    zwarnnam(name, "bad option: %c", NULL, **argv);
        		    return 1;
        		}
        	    }
        
        	if (*++argv && (!ready || ready == 2) &&
        	    **argv == '+' && !argv[0][1]) {
      --- 1819,1829 ----
        		if (!first && (**argv == '-' || **argv == '+'))
        		    (*argv)--, argv--, ready = 1;
        		else {
      ! 		    zwarnnam(name, "bad option: -%c", NULL, **argv);
        		    return 1;
        		}
        	    }
      + 	}
        
        	if (*++argv && (!ready || ready == 2) &&
        	    **argv == '+' && !argv[0][1]) {
      ***************
      *** 3893,3898 ****
      --- 3900,3907 ----
        	if (options && *options == '-') {
        	    argv++;
        	    while (*++options) {
      + 		if(*options == Meta)
      + 		    *++options ^= 32;
        		res = -1;
        		switch (*options) {
        		case 'H':
      ***************
      *** 3952,3958 ****
        # endif /* RLIMIT_VMEM */
        		default:
        		    /* unrecognised limit */
      ! 		    zwarnnam(name, "bad option: %c", NULL, *options);
        		    return 1;
        		}
        		if (options[1]) {
      --- 3961,3967 ----
        # endif /* RLIMIT_VMEM */
        		default:
        		    /* unrecognised limit */
      ! 		    zwarnnam(name, "bad option: -%c", NULL, *options);
        		    return 1;
        		}
        		if (options[1]) {
      ***************
      *** 4516,4525 ****
        int
        bin_getopts(char *name, char **argv, char *ops, int func)
        {
      !     char *optstr = *argv++, *var = *argv++;
            char **args = (*argv) ? argv : pparams;
            static int optcind = 1, quiet;
      !     char *str, optbuf[3], *opch = optbuf + 1;
        
            /* zoptind keeps count of the current argument number */
            if (zoptind < 1)
      --- 4525,4535 ----
        int
        bin_getopts(char *name, char **argv, char *ops, int func)
        {
      !     int lenstr, lenoptstr, i;
      !     char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
            char **args = (*argv) ? argv : pparams;
            static int optcind = 1, quiet;
      !     char *str, optbuf[2], *opch = optbuf + 1;
        
            /* zoptind keeps count of the current argument number */
            if (zoptind < 1)
      ***************
      *** 4528,4534 ****
            if (zoptind == 1)
        	quiet = 0;
            optbuf[0] = '+';
      -     optbuf[1] = optbuf[2] = '\0';
            zsfree(zoptarg);
            zoptarg = ztrdup("");
            setsparam(var, ztrdup(""));
      --- 4538,4543 ----
      ***************
      *** 4538,4546 ****
            }
            if (zoptind > arrlen(args))
        	return 1;
      !     str = args[zoptind - 1];
      !     if ((*str != '+' && *str != '-') || optcind >= (int)strlen(str) ||
      ! 	!strcmp("--", str)) {
        	/* current argument doesn't contain options, or optcind is impossibly
        	large */
        	if (*str == '+' || *str == '-')
      --- 4547,4555 ----
            }
            if (zoptind > arrlen(args))
        	return 1;
      !     str = unmetafy(args[zoptind - 1], &lenstr);
      !     if ((*str != '+' && *str != '-') || optcind >= lenstr ||
      ! 	(lenstr == 2 && str[0] == '-' && str[1] == '-')) {
        	/* current argument doesn't contain options, or optcind is impossibly
        	large */
        	if (*str == '+' || *str == '-')
      ***************
      *** 4553,4598 ****
            if (!optcind)
        	optcind = 1;
            *opch = str[optcind++];
      !     if (!args[zoptind - 1][optcind]) {
      ! 	zoptind++;
        	optcind = 0;
            }
            /* look for option in the provided optstr */
      !     for (; *optstr; optstr++)
      ! 	if (*opch == *optstr)
        	    break;
      !     if (!*optstr) {
        	/* not a valid option */
        	setsparam(var, ztrdup("?"));
        	if (quiet) {
        	    zsfree(zoptarg);
      ! 	    zoptarg = ztrdup(opch);
        	    return 0;
        	}
      ! 	zerr("bad option: %c", NULL, *opch);
        	errflag = 0;
        	return 0;
            }
            /* copy option into specified parameter, with + if required */
      !     setsparam(var, ztrdup(opch - (*str == '+')));
            /* handle case of an expected extra argument */
            if (optstr[1] == ':') {
        	if (!args[zoptind - 1]) {
        	    /* no extra argument was provided */
        	    if (quiet) {
        		zsfree(zoptarg);
      ! 		zoptarg = ztrdup(opch);
        		setsparam(var, ztrdup(":"));
        		return 0;
        	    }
        	    setsparam(var, ztrdup("?"));
      ! 	    zerr("argument expected after %c option", NULL, *opch);
        	    errflag = 0;
        	    return 0;
        	}
        	/* skip over the extra argument */
        	zsfree(zoptarg);
      ! 	zoptarg = ztrdup(args[zoptind - 1] + optcind);
        	zoptind++;
        	optcind = 0;
            }
      --- 4562,4608 ----
            if (!optcind)
        	optcind = 1;
            *opch = str[optcind++];
      !     if (optcind == lenstr) {
      ! 	if(args[zoptind++])
      ! 	    str = unmetafy(args[zoptind - 1], &lenstr);
        	optcind = 0;
            }
            /* look for option in the provided optstr */
      !     for (i = 0; i != lenoptstr; i++)
      ! 	if (*opch == optstr[i])
        	    break;
      !     if (i == lenoptstr) {
        	/* not a valid option */
        	setsparam(var, ztrdup("?"));
        	if (quiet) {
        	    zsfree(zoptarg);
      ! 	    zoptarg = metafy(opch, 1, META_DUP);
        	    return 0;
        	}
      ! 	zerr("bad option: -%c", NULL, *opch);
        	errflag = 0;
        	return 0;
            }
            /* copy option into specified parameter, with + if required */
      !     setsparam(var, metafy(opch - (*str == '+'), 1 + (*str == '+'), META_DUP));
            /* handle case of an expected extra argument */
            if (optstr[1] == ':') {
        	if (!args[zoptind - 1]) {
        	    /* no extra argument was provided */
        	    if (quiet) {
        		zsfree(zoptarg);
      ! 		zoptarg = metafy(opch, 1, META_DUP);
        		setsparam(var, ztrdup(":"));
        		return 0;
        	    }
        	    setsparam(var, ztrdup("?"));
      ! 	    zerr("argument expected after -%c option", NULL, *opch);
        	    errflag = 0;
        	    return 0;
        	}
        	/* skip over the extra argument */
        	zsfree(zoptarg);
      ! 	zoptarg = metafy(str + optcind, lenstr - optcind, META_DUP);
        	zoptind++;
        	optcind = 0;
            }

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMqDEc3D/+HJTpU/hAQGLpQP7BV7tKjdTykU6Fk7HH6lXamn+mP7s1gde
Ny8c4fTH3+ZGRo+xbPC6+2rnfXFPadrECqaOsPHXJduNh6IH4JG5j0s5RKG7Dpmw
t2KJ4wDadHZDJqMqV1nsn9JUADuuVbIzjbdsEEF0bORVVk2psAlIyLlmWYacU8Hv
ZzdeSzXtRMg=
=J8JO
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-12-01 16:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-01 15:46 more metafied options Zefram

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).