=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/patch.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/patch/patch.c 1995/10/18 08:45:55 1.1 --- src/usr.bin/patch/patch.c 1996/06/10 11:21:31 1.2 *************** *** 1,3 **** --- 1,5 ---- + /* $OpenBSD: patch.c,v 1.2 1996/06/10 11:21:31 niklas Exp $ */ + /* patch - a program to apply diffs to original files * * Copyright 1986, Larry Wall *************** *** 7,13 **** */ #ifndef lint ! static char rcsid[] = "$Id: patch.c,v 1.1 1995/10/18 08:45:55 deraadt Exp $"; #endif /* not lint */ #include "INTERN.h" --- 9,15 ---- */ #ifndef lint ! static char rcsid[] = "$OpenBSD: patch.c,v 1.2 1996/06/10 11:21:31 niklas Exp $"; #endif /* not lint */ #include "INTERN.h" *************** *** 367,372 **** --- 369,432 ---- 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 be handled later anyway. */ + 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,396 **** filearg[filec++] = savestr(s); } else { ! switch (*++s) { case 'b': simple_backup_suffix = savestr(nextarg()); break; --- 450,464 ---- filearg[filec++] = savestr(s); } else { ! 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; *************** *** 426,432 **** force = TRUE; break; case 'F': ! if (*++s == '=') s++; maxfuzz = atoi(s); break; --- 494,502 ---- force = TRUE; break; case 'F': ! if (!*++s) ! s = nextarg(); ! else if (*s == '=') s++; maxfuzz = atoi(s); break; *************** *** 443,449 **** outname = savestr(nextarg()); break; case 'p': ! if (*++s == '=') s++; strippath = atoi(s); break; --- 513,521 ---- outname = savestr(nextarg()); break; case 'p': ! if (!*++s) ! s = nextarg(); ! else if (*s == '=') s++; strippath = atoi(s); break; *************** *** 476,482 **** break; #ifdef DEBUGGING case 'x': ! debug = atoi(s+1); break; #endif default: --- 548,556 ---- break; #ifdef DEBUGGING case 'x': ! if (!*++s) ! s = nextarg(); ! debug = atoi(s); break; #endif default: