From 9743c19d618056b3af1f5efe887a1e8a9944e27b Mon Sep 17 00:00:00 2001 From: Andrew Main Date: Sun, 30 Jul 2000 17:03:52 +0000 Subject: 12434: Doc/Zsh/invoke.yo, Src/init.c, Src/options.c, Src/zsh.h, Src/zsh.mdd: Allow options to be specified on the zsh command line in the form of GNU-style long options. Also handle --version and --help. Do not permit extra option letters to be stacked after `-whatever-' (they used to be ignored). Exit if the command line specifies an option name that doesn't exist. --- Src/options.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'Src/options.c') diff --git a/Src/options.c b/Src/options.c index ea3bf13de..0bbe6b844 100644 --- a/Src/options.c +++ b/Src/options.c @@ -694,3 +694,48 @@ dashgetfn(Param pm) *val = '\0'; return buf; } + +/* Print option list for --help */ + +/**/ +void +printoptionlist(void) +{ + short *lp; + char c; + + printf("\nNamed options:\n"); + scanhashtable(optiontab, 1, 0, OPT_ALIAS, printoptionlist_printoption, 0); + printf("\nOption aliases:\n"); + scanhashtable(optiontab, 1, OPT_ALIAS, 0, printoptionlist_printoption, 0); + printf("\nOption letters:\n"); + for(lp = optletters, c = FIRST_OPT; c <= LAST_OPT; lp++, c++) { + if(!*lp) + continue; + printf(" -%c ", c); + printoptionlist_printequiv(*lp); + } +} + +/**/ +static void +printoptionlist_printoption(HashNode hn, int ignored) +{ + Optname on = (Optname) hn; + + if(on->flags & OPT_ALIAS) { + printf(" --%-19s ", on->nam); + printoptionlist_printequiv(on->optno); + } else + printf(" --%s\n", on->nam); +} + +/**/ +static void +printoptionlist_printequiv(int optno) +{ + int isneg = optno < 0; + + optno *= (isneg ? -1 : 1); + printf(" equivalent to --%s%s\n", isneg ? "no-" : "", optns[optno-1].nam); +} -- cgit v1.2.3