diff options
| author | thorpej <thorpej@NetBSD.org> | 1996-09-19 06:10:02 +0000 |
|---|---|---|
| committer | thorpej <thorpej@NetBSD.org> | 1996-09-19 06:10:02 +0000 |
| commit | 0b02f897d7098ffed3b392dbe5ac04d15c57a9cf (patch) | |
| tree | 8ffe140df06a2887129b4feac2b4036276c942ad /usr.bin/patch/patch.c | |
| parent | 16fe807b60f74b1e55351c5e8c7377fd89a80008 (diff) | |
Decode long (GNU-style) options. Changes originally from Niklas Hallqvist,
but modified some by me.
Diffstat (limited to 'usr.bin/patch/patch.c')
| -rw-r--r-- | usr.bin/patch/patch.c | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index 89f911512d2..658714e36d6 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: patch.c,v 1.2 1993/08/02 17:55:19 mycroft Exp $"; +static char rcsid[] = "$Id: patch.c,v 1.3 1996/09/19 06:10:04 thorpej Exp $"; #endif /* not lint */ #include "INTERN.h" @@ -19,6 +19,8 @@ static char rcsid[] = "$Id: patch.c,v 1.2 1993/08/02 17:55:19 mycroft Exp $"; #include "inp.h" #include "backupfile.h" +#include <stdlib.h> + /* procedures */ void reinitialize_almost_everything(); @@ -367,6 +369,67 @@ nextarg() return *++Argv; } +/* Module for handling of long options. */ + +struct option { + char *long_opt; + char short_opt; +}; + +int +optcmp(a, b) + struct option *a, *b; +{ + return strcmp (a->long_opt, b->long_opt); +} + +/* Decode Long options beginning with "--" to their short equivalents. */ + +char +decode_long_option(opt) + char *opt; +{ + /* + * This table must be sorted on the first field. We also decode + * unimplemented options as those will probably be dealt with + * later, anyhow. + */ + static struct option options[] = { + { "batch", 't' }, + { "check", 'C' }, + { "context", 'c' }, + { "debug", 'x' }, + { "directory", 'd' }, + { "ed", 'e' }, + { "force", 'f' }, + { "forward", 'N' }, + { "fuzz", 'F' }, + { "ifdef", 'D' }, + { "ignore-whitespace", 'l' }, + { "normal", 'n' }, + { "output", 'o' }, + { "prefix", 'B' }, + { "quiet", 's' }, + { "reject-file", 'r' }, + { "remove-empty-files", 'E' }, + { "reverse", 'R' }, + { "silent", 's' }, + { "skip", 'S' }, + { "strip", 'p' }, + { "suffix", 'b' }, + { "unified", 'u' }, + { "version", 'v' }, + { "version-control", 'V' }, + }; + struct option key, *found; + + key.long_opt = opt; + found = (struct option *)bsearch(&key, options, + sizeof(options) / sizeof(options[0]), sizeof(options[0]), optcmp); + + return found ? found->short_opt : '\0'; +} + /* Process switches and filenames up to next '+' or end of list. */ void @@ -390,7 +453,16 @@ get_some_switches() filearg[filec++] = savestr(s); } else { - switch (*++s) { + char opt; + + if (*(s + 1) == '-') { + opt = decode_long_option(s + 2); + s += strlen(s) - 1; + } + else + opt = *++s; + + switch (opt) { case 'b': simple_backup_suffix = savestr(nextarg()); break; |
