summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING7
-rw-r--r--ChangeLog703
-rw-r--r--EXTERN.h21
-rw-r--r--INSTALL299
-rw-r--r--INTERN.h19
-rw-r--r--Makefile.in149
-rw-r--r--NEWS69
-rw-r--r--README87
-rw-r--r--acconfig.h7
-rw-r--r--addext.c89
-rw-r--r--alloca.c475
-rw-r--r--argmatch.c87
-rw-r--r--argmatch.h12
-rw-r--r--backupfile.c407
-rw-r--r--backupfile.h30
-rw-r--r--basename.c24
-rw-r--r--common.h349
-rw-r--r--config.h.in80
-rw-r--r--config.hin108
-rwxr-xr-xconfigure2756
-rw-r--r--configure.in63
-rw-r--r--getopt.c399
-rw-r--r--getopt.h15
-rw-r--r--getopt1.c13
-rw-r--r--inp.c672
-rw-r--r--inp.h22
-rw-r--r--install-sh250
-rw-r--r--memchr.c199
-rw-r--r--mkinstalldirs40
-rw-r--r--patch.c1256
-rw-r--r--patch.man947
-rw-r--r--patchlevel.h1
-rw-r--r--pch.c1318
-rw-r--r--pch.h55
-rw-r--r--util.c902
-rw-r--r--util.h115
-rw-r--r--version.c39
-rw-r--r--version.h12
38 files changed, 7579 insertions, 4517 deletions
diff --git a/COPYING b/COPYING
index a43ea21..60549be 100644
--- a/COPYING
+++ b/COPYING
@@ -2,7 +2,7 @@
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 675 Mass Ave, Cambridge, MA 02139, USA
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -279,7 +279,7 @@ POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
- Appendix: How to Apply These Terms to Your New Programs
+ How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
@@ -305,7 +305,8 @@ the "copyright" line and a pointer to where the full notice is found.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
Also add information on how to contact you by electronic and paper mail.
diff --git a/ChangeLog b/ChangeLog
index 8ce76da..0ff3627 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,599 @@
+1997-04-17 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Version 2.2 released.
+
+ * Makefile.in (config.hin):
+ Remove before building; we always want the timestamp updated.
+
+ * inp.c (get_input_file):
+ Look for RCS files only if backup_type == numbered_existing.
+
+ * NEWS, patch.man:
+ Remove mention of never-implemented -V rcs and -V sccs options.
+ * patch.man: `pathname' -> `file name'
+ Correct the description of how file names are found in diff headers.
+ Clarify the distinction between ordinary and unified context diffs.
+
+1997-04-13 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Update to 2.1.7.
+
+ * patch.c (numeric_optarg): New function.
+ (get_some_switches): Use it.
+
+ * pch.c (intuit_diff_type): When creating a file, prefer a name whose
+ existing dir prefix is the longest.
+
+ * util.h (countdirs): New function.
+ * util.c (replace_slashes, countdirs): New functions.
+ (makedirs): Use replace_slashes, to be more like countdirs.
+
+ * patch.man: Explain -pN vs -p N. Recommend --new-file.
+ Explain possible incompatibility with strip count.
+
+1997-04-10 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.1.6.
+ (AC_CHECK_HEADERS): Remove stdlib.h (i.e. remove HAVE_STDLIB_H).
+
+ * Makefile.in: (HDRS, patchlevel.h, TAGS, distclean, maintainer-clean):
+ Don't distribute patchlevel.h; let the user do it.
+ This works around some obscure (possibly nonexistent?) `make' bugs.
+
+ * common.h (program_name): extern, not XTERN.
+ (<stdlib.h>): Include if STDC_HEADERS, not if HAVE_STDLIB_H.
+ (atol, getenv, malloc, realloc): Don't worry whether they're #defined.
+
+ * patch.c (get_some_switches):
+ Add special hack for backwards compatibility with CVS 1.9.
+ (-B, -Y, -z): Now set backup_type = simple.
+
+ * NEWS: Fix misspellings; minor reformatting.
+ * README: Report POSIX.2 compliance.
+
+1997-04-06 Paul Eggert <eggert@twinsun.com>
+
+ Move all old RCS $Log entries into ChangeLog.
+ #include all files with < >, not " ".
+
+ * addext.c, argmatch.c, argmatch.h, memchr.c, install-sh:
+ New files.
+ * EXTERN.h, INTERN.h: Removed.
+ * config.hin: Renamed from config.h.in.
+
+ * acconfig.h (NODIR): Remove.
+ (HAVE_MEMCHR): Add.
+
+ * configure.in (AC_ARG_PROGRAM, AC_PROG_MAKE_SET, HAVE_MEMCHR): Add.
+ (AC_CHECK_HEADERS): Replaces obsolescent AC_HAVE_HEADERS.
+ Add stdlib.h, string.h, unistd.h, varargs.h.
+ Delete obsolete call to AC_UNISTD_H.
+ (AC_CONFIG_HEADER): Rename config.h.in to config.hin.
+ (AC_C_CONST): Replaces obsolescent AC_CONST.
+ (AC_CHECK_FUNC): Check for getopt_long; define LIBOBJS and substitute
+ for it accordingly.
+ (AC_CHECK_FUNCS): Replaces obsolescent AC_HAVE_FUNCS.
+ Add _doprintf, isascii, mktemp, sigaction, sigprocmask, sigsetmask.
+ Remove strerror.
+ (AC_FUNC_CLOSEDIR_VOID, AC_FUNC_VPRINTF): Add.
+ (AC_HEADER_DIRENT): Replaces obsolescent AC_DIR_HEADER.
+ (AC_HEADER_STDC): Replaces obsolescent AC_STDC_HEADERS.
+ (AC_SYS_LONG_FILE_NAMES): Replaces obsolescent AC_LONG_FILE_NAMES.
+ (AC_TYPE_OFF_T): Replaces obsolescent AC_OFF_T.
+ (AC_TYPE_SIGNAL): Replaces obsolescent AC_RETSIGTYPE.
+ (AC_TYPE_SIZE_T): Replaces obsolescent AC_SIZE_T.
+ (AC_XENIX_DIR): Remove.
+ (ED_PROGRAM): New var.
+ (NODIR): Remove.
+ (PACKAGE, VERSION): New vars; substitute them with AC_SUBST.
+
+ * Makefile.in: Conform to current GNU build standards.
+ Redo dependencies. Use library getopt_long if available.
+ Use `&&' instead of `;' inside shell commands where applicable;
+ GNU make requires this.
+ Use double-colon rules for actions that do not build files.
+ (@SET_MAKE@): Added.
+ (CFLAGS, LDFLAGS, prefix, exec_prefix): Base on @ versions of symbols.
+ (COMPILE, CPPFLAGS, DEFS, ED_PROGRAM, LIBOBJS, LIBSRCS, PACKAGE,
+ VERSION): New symbols.
+ (SRCS, OBJS, HDRS, MISC): Add new files.
+ (man1dir): Renamed from mandir.
+ (man1ext): Renamed from manext.
+ (patch): Put -o first.
+ (install): Use $(transform) to allow program to be renamed by configure.
+ (patchlevel.h): Build from $(VERSION).
+ (dist): Get version number from $(VERSION) and package name from
+ $(PACKAGE).
+ (TAGS): Scan $(HDRS).
+ (maintainer-clean): Renamed from realclean. Remove patchlevel.h.
+
+ * backupfile.h (simple_backup_suffix): Now const *.
+ (find_backup_file_name, base_name, get_version): Args are now const *.
+ (base_name): New decl.
+ * backupfile.c (<config.h>): Include only if HAVE_CONFIG_H.
+ (<argmatch.h>): Include.
+ (<string.h>): Include if HAVE_STRING_H, not if STDC_HEADERS.
+ (<strings.h>): Include if !HAVE_STRING_H.
+ (<unistd.h>): Do not include.
+ (<dirent.h>): Redo include as per current autoconf standards.
+ (<limits.h>): Include if HAVE_LIMITS_H. Define CHAR_BIT if not defined.
+ (NLENGTH): Now returns size_t.
+ (CLOSEDIR, INT_STRLEN_BOUND): New macros.
+ (ISDIGIT): Use faster method.
+ (find_backup_file_name): No longer depends on NODIR.
+ Remove redundant code.
+ (make_version_name): Remove; do it more portably.
+ (max_backup_version): Args are now const *.
+ (version_number): Simplify digit checking.
+ (basename, concat, dirname): Remove.
+ (argmatch, invalid_arg): Move to argmatch.c. Simplify test for
+ ambiguous args. When reporting an error, use program_name not "patch".
+ (addext): Move to addext.c. Treat all negative values from pathconf
+ like -1. Always use long extension if it fits, even if the filesystem
+ does not support long file names.
+ (backup_types): Now const.
+
+ * common.h, inp.h (XTERN): Renamed from EXT to avoid collision
+ with errno.h reserved name space.
+
+ * common.h (DEBUGGING): Now an integer; default is 1.
+ (enum diff): New type.
+ (diff_type): Use it instead of small integers.
+ (CONTEXT_DIFF, NORMAL_DIFF, ED_DIFF, NEW_CONTEXT_DIFF, UNI_DIFF):
+ Now enumerated values instead of macros.
+ (NO_DIFF): New enumerated value (used instead of 0).
+ (volatile): Default to the empty string if __STDC__ is not defined.
+ (<signal.h>): Do not include.
+ (Chmod, Close, Fclose, Fflush, Fputc, Signal, Sprintf, Strcat,
+ Strcpy, Unlink, Write): Remove these macros; casts to void are
+ not needed for GNU coding standards.
+ (INITHUNKMAX): Move to pch.c.
+ (malloc, realloc, INT_MIN, MAXLINELEN, strNE, strnNE,
+ Reg1, Reg2, Reg3, Reg4, Reg5, Reg6, Reg7, Reg8, Reg9, Reg10, Reg11,
+ Reg12, Reg13, Reg14, Reg15, Reg16): Remove these macros.
+ (S_IXOTH, S_IWOTH, S_IROTH, S_IXGRP, S_IWGRP,
+ S_IRGRP, S_IXUSR, S_IWUSR, S_IRUSR, O_RDONLY, O_RDWR):
+ Define these macros, if not defined.
+ (CTYPE_DOMAIN, ISLOWER, ISSPACE, ISDIGIT, PARAMS): New macros.
+ (instat): Renamed from filestat; used for input file now.
+ (bufsize, using_plan_a, debug, strippath): Not statically initialized.
+ (debug): #define to 0 if not DEBUGGING, so that users of `debug'
+ no longer need to be surrounded by `#if DEBUGGING'.
+ (out_of_mem, filec, filearg, outname, toutkeep, trejkeep): Remove.
+ (inname, inerrno, dry_run, origbase): New variables.
+ (origprae): Now const*.
+ (TMPOUTNAME, TMPINNAME, TMPPATNAME): Now const*volatile.
+ (verbosity): New variable; subsumes `verbose'.
+ (DEFAULT_VERBOSITY, SILENT, VERBOSE): Values in a new enum.
+ (verbose): Removed.
+ (VOID): Use `#ifdef __STDC__' instead of`#if __STDC__',
+ for consistency elsewhere.
+ (__attribute__): New macro (empty if not a recent GCC).
+ (fatal_exit): Renamed from my_exit.
+ (errno): Don't define if STDC_HEADERS.
+ (<string.h>): Include if either STDC_HEADERS or HAVE_STRING_H.
+ (memcmp, memcpy): Define if !STDC_HEADERS && !HAVE_STRING_H
+ && !HAVE_MEMCHR.
+ (<stdlib.h>): Include if HAVE_STDLIB_H, not if STDC_HEADERS.
+ (atol, getenv, malloc, realloc, lseek): Declare only if not defined
+ as a macro.
+ (popen, strcpy, strcat, mktemp): Do not declare.
+ (lseek): Declare to yield off_t, not long.
+ (<fcntl.h>): Include only if HAVE_FCNTL_H.
+
+ * inp.h (get_input_file): New decl.
+ * inp.c (SCCSPREFIX, GET, GET_LOCKED, SCCSDIFF, RCSSUFFIX, CHECKOUT,
+ CHECKOUT_LOCKED, RCSDIFF): Moved here from common.h.
+ (i_ptr): Now char const **.
+ (i_size): Remove.
+ (TIBUFSIZE_MINIMUM): Define only if not already defined.
+ (plan_a, plan_b): Arg is now const *.
+ (report_revision): Declare before use. It's now the caller's
+ responsibility to test whether revision is 0.
+ (scan_input, report_revision, get_input_file):
+ Be less chatty unless --verbose.
+ (get_input_file): New function, split off from plan_a.
+ Reuse file status gotten by pch if possible. Allow for dry run.
+ Use POSIX bits for creat, not number. Check for creation and
+ close failure, and use fstat not stat. Use memcpy not strncpy.
+ (plan_a): Rewrite for speed.
+ Caller now assigns result to using_plan_a.
+ Don't bother reading empty files; during dry runs they might not exist.
+ Use ISSPACE, not isspace.
+ (plan_b): Allow for dry runs. Use ISSPACE, and handle sign extension
+ correctly on arg. Use POSIX symbol for open arg.
+
+ * patch.c (backup, output, patchname, program_name): New vars.
+ (last_frozen_line): Moved here from inp.h.
+ (TMPREJNAME): Moved here from common.h.
+ (optind_last): Removed.
+ (do_defines, if_defined, not_defined, else_defined, end_defined):
+ Now char const. Prepend with \n (except for not_defined) to
+ allow for files ending in non-newline.
+ (Argv): Now char*const*.
+ (main, get_some_switches): Exit status 0 means success,
+ 1 means hunks were rejected, 2 means trouble.
+ (main, locate_hunk, patch_match): Keep track of patch prefix context
+ separately from suffix context; this fixes several bugs.
+ (main): Initialize bufsize, strippath.
+ Be less chatty unless --verbose.
+ No more NODIR; always have version control available.
+ Require environment variables to be nonempty to have effect.
+ Add support for --dry-run, --output, --verbose.
+ Invoke get_input_file first, before deciding among do_ed_script,
+ plan_a, or plan_b.
+ Clear ofp after closing it, to keep discipline that ofp is either
+ 0 or open, to avoid file descriptor leaks. Conversely, rejfp doesn't
+ need this trick since static analysis is enough to show when it
+ needs to be closed.
+ Don't allow file-creation patches to be applied to existing files.
+ Misordered hunks are now not fatal errors; just go on to the next file.
+ It's a fatal error to fall back on plan B when --output is given,
+ since the moving hand has writ.
+ Add support for binary files.
+ Check for I/O errors.
+ chmod output file ourselves, rather than letting move_file do it;
+ this saves global state.
+ Use better grammar when outputting hunks messages, e.g. avoid
+ `1 hunks'.
+ (main, reinitialize_almost_everything):
+ Remove support for multiple file arguments.
+ Move get_some_switches call from reinitialize_almost_everything
+ to main.
+ (reinitialize_almost_everything): No need to reinitialize things
+ that are no longer global variables, e.g. outname.
+ (shortopts): Remove leading "-"; it's no longer important to
+ return options and arguments in order. '-b' no longer takes operand.
+ -p's operand is no longer optional. Add -i, -Y, -z. Remove -S.
+ (longopts): --suffix is now pared with -z, not -b. --backup now
+ means -b. Add --input, --basename-prefix, --dry-run, --verbose.
+ Remove --skip. --strip's operand is now required.
+ (option_help): New variable. Use style of current coding standards.
+ Change to match current option set.
+ (usage): Use it.
+ (get_some_switches): Get all switches, since `+' is defunct.
+ New options -i, -Y, -z, --verbose, --dry-run.
+ Option -S removed.
+ -b now means backup (backup_type == simple), not simple_backup_suffix.
+ -B now implies backup, and requires nonempty operand.
+ -D no longer requires first char of argument to be an identifier.
+ `-o -' is now disallowed (formerly output to regular file named "-").
+ -p operand is now required.
+ -v no longer needs to cleanup (no temp files can exist at that point).
+ -V now implies backup.
+ Set inname, patchname from file name arguments, if any;
+ do not set filearg. It's now an error if extra operands are given.
+ (abort_junk): Check for write errors in reject file.
+ (apply_hunk, copy_till): Return error flag, so that failure to apply
+ out-of-order hunk is no longer fatal.
+ (apply_hunk): New arg after_newline,
+ for patching files not ending in newline.
+ Cache ofp for speed. Check for write errors.
+ (OUTSIDE, IN_IFNDEF, IN_IFDEF, IN_ELSE): Now part of an enumerated type
+ instead of being #defined to small integers.
+ Change while-do to do-while when copying !-part for R_do_defines,
+ since condition is always true the first time through the loop.
+ (init_output, init_reject): Arg is now const *.
+ (copy_till, spew_output): Do not insert ``missing'' newlines;
+ propagate them via new after_newline argument.
+ (spew_output): Nothing to copy if last_frozen_line == input lines.
+ Do not close (ofp) if it's null.
+ (dump_line): Remove.
+ (similar): Ignore presence or absence of trailing newlines.
+ Check for only ' ' or '\t', not isspace (as per POSIX.2).
+ (make_temp): Use tmpnam if mktemp is not available.
+ (cleanup): New function.
+ (fatal_exit): Use it. Renamed from my_exit.
+ Take signal to exit with, not exit status (which is now always 2).
+
+ * pch.h, pch.c (pch_prefix_context, pch_suffix_context):
+ New fns replacing pch_context.
+ (another_hunk): Now yields int, not bool; -1 means out of memory.
+ Now takes difftype as argument.
+ (pch_write_line): Now returns boolean indicating whether we're after
+ a newline just after the write, for supporting non-text files.
+ * pch.c (isdigit): Remove; use ISDIGIT instead.
+ (INITHUNKMAX): Moved here from common.h.
+ (p_context): Removed. We need to keep track of the pre- and post-
+ context separately, in:
+ (p_prefix_context, p_suffix_context): New variables.
+ (bestguess): Remove.
+ (open_patch_file): Arg is now char const *.
+ Copy file a buffer at a time, not a char at a time, for speed.
+ (grow_hunkmax): Now returns success indicator.
+ (there_is_another_patch, skip_to, another_hunk, do_ed_script):
+ Be less chatty unless --verbose.
+ (there_is_another_patch):
+ Avoid infinite loop if user input keeps yielding EOF.
+ (intuit_diff_type): New returns enum diff, not int.
+ Strip paths as they're being fetched.
+ Set ok_to_create_file correctly even if patch is reversed.
+ Set up file names correctly with unidiff output.
+ Use algorithm specified by POSIX 1003.2b/D11 to deduce
+ name of file to patch, with the exception of patches
+ that can create files.
+ (skip_to): Be verbose if !inname, since we're about to ask the
+ user for a file name and the context will help the user choose.
+ (another_hunk): Keep context as LINENUM, not int.
+ If the replacement is missing, calculate its context correctly.
+ Don't assume input ends in newline.
+ Keep track of patch prefix context separately from suffix context;
+ this fixes several bugs.
+ Don't assume blank lines got chopped if the replacement is missing.
+ Report poorly-formed hunks instead of aborting.
+ Do not use strcpy on overlapping strings; it's not portable.
+ Work even if lines are incomplete.
+ Fix bugs associated with context-less context hunks,
+ particularly when patching in reverse.
+ (pget_line): Now takes just 1 arg; instead of second arg,
+ just examine using_plan_a global. Return -1 if we ran out
+ of memory.
+ (do_ed_script): Now takes output FILE * argument.
+ Take name of editor from ED_PROGRAM instead of hardwiring /bin/ed.
+ Don't bother unlinking TMPOUTNAME.
+ Check for popen failure.
+ Flush pipe to check for output errors.
+ If ofp is nonzero, copy result to it, instead of trying to
+ move the result.
+
+ * util.h, util.c (say1, say2, say3, say4, fatal1, fatal2, fatal3,
+ fatal4, pfatal1, pfatal2, pfatal3, pfatal4, ask1, ask2, ask3, ask4):
+ Remove; replaced with following.
+ (ask, say, fatal, pfatal): New stdarg functions.
+ (fetchname): Remove last, `assume_exists' parameter.
+ (savebuf, savestr, move_file, copy_file): Args are now const *.
+ (exit_with_signal): New function, for proper process status if
+ a signal is received as per POSIX.2.
+ (basename): Rename to `base_name' and move to backupfile.
+ * util.c (<signal.h>): Include here, not in common.h.
+ (vararg_start): New macro.
+ (va_dcl, va_start, va_arg, va_end): Define if neither <stdarg.h>
+ nor <varargs.h> are available.
+ (SIGCHLD): Define to SIGCLD if SIGCLD is defined and
+ SIGCHLD isn't.
+ (private_strerror): Remove.
+ (move_file): Remove option of moving to stdout.
+ Add support for -Y, -z.
+ Don't assume chars in file name are nonnegative.
+ Use copy_file if rename fails due to EXDEV;
+ report failure if rename fails for any other reason.
+ (copy_file, makedirs): Use POSIX symbols for permissions.
+ (copy_file): Open source before destination.
+ (remove_prefix): New function.
+ (vfprintf): New function, if !HAVE_VPRINTF.
+ (afatal, apfatal, zfatal, zpfatal, errnum): Remove.
+ (fatal, pfatal, say): New functions that use stdarg.
+ All callers changed.
+ (zask): Renamed from `ask'. Now uses stdarg. Output to stdout,
+ and read from /dev/tty, or if that cannot be opened, from
+ stderr, stdout, stdin, whichever is first a tty.
+ Print "EOF" when an EOF is read. Do not echo input.
+ (sigs): New array.
+ (sigset_t, sigemptyset, sigmask, sigaddset, sigismember, SIG_BLOCK,
+ SIG_UNBLOCK, SIG_SETMASK, sigprocmask, sigblock, sigsetmask):
+ Define substitutes if not available.
+ (initial_signal_mask, signals_to_block): New vars.
+ (fatal_exit_handler): New function, if !HAVE_SIGACTION.
+ (set_signals, ignore_signals): Use sigaction and sigprocmask style
+ signal-handling if possible; it doesn't lose signals.
+ (set_signals): Default SIGCHLD to work around SysV fork+wait bug.
+ (mkdir): First arg is now const *.
+ (makedirs): Handle multiple adjacent slashes correctly.
+ (fetchname): Do not worry about whether the file exists
+ (that is now the caller's responsibility).
+ Treat a sequence of one or more slashes like one slash.
+ Do not unstrip leading directories if they all exist and if
+ no -p option was given; POSIX doesn't allow this.
+ (memcmp): Remove (now a macro in common.h).
+
+ * version.c (copyright_string, free_software_msgid, authorship_msgid):
+ New constants.
+ (version): Use them. Use program_name instead of hardwiring it.
+
+ * patch.man: Generate date from RCS Id.
+ Rewrite to match the above changes.
+
+Fri Jul 30 02:02:51 1993 Paul Eggert (eggert@twinsun.com)
+
+ * configure.in (AC_HAVE_FUNCS): Add mkdir.
+
+ * common.h (Chmod, Fputc, Write, VOID): New macros.
+ (malloc, realloc): Yield `VOID *', not `char *'.
+
+ * util.h (makedirs): Omit `striplast' argument. Remove `aask'.
+
+ * inp.c (plan_a): Remove fixed internal buffer. Remove lint.
+
+ * util.c (set_signals, ignore_signals): Trap SIGTERM, too.
+ (makedirs): Removed fixed internal buffer. Omit `striplast' argument.
+ (mkdir): New function, if !HAVE_MKDIR.
+ (fetchname): Remove fixed internal buffer.
+ Remove lint from various functions.
+
+ * patch.c, pch.c: Remove lint.
+
+Thu Jul 29 20:52:07 1993 David J. MacKenzie (djm@wookumz.gnu.ai.mit.edu)
+
+ * Makefile.in (config.status): Run config.status --recheck, not
+ configure, to get the right args passed.
+
+Thu Jul 29 07:46:16 1993 Paul Eggert (eggert@twinsun.com)
+
+ * The following changes remove all remaining fixed limits on memory,
+ and fix bugs in patch's handling of null bytes and files that do not
+ end in newline. `Patch' now works on binary files.
+
+ * backupfile.c (find_backup_file_name): Don't dump core if malloc fails.
+
+ * EXTERN.h, INTERN.h (EXITING): New macro.
+ * backupfile.[ch], patch.c, pch.c: Add PARAMS to function declarations.
+
+ * common.h (bool): Change to int, so ANSI C prototype promotion works.
+ (CANVARARG): Remove varargs hack; it wasn't portable.
+ (filearg): Now a pointer, not an array, so that it can be reallocated.
+ (GET*, SCCSDIFF, CHECKOUT*, RCSDIFF): Quote operands to commands.
+ (my_exit): Declare here.
+ (BUFFERSIZE, Ctl, filemode, Fseek, Fstat, Lseek, MAXFILEC, MAXHUNKSIZE,
+ Mktemp, myuid, Null, Nullch, Nullfp, Nulline, Pclose, VOIDUSED): Remove.
+ All invokers changed.
+ (Argc, Argv, *define[sd], last_offset, maxfuzz, noreverse, ofp,
+ optind_last, rejfp, rejname): No longer externally visible; all
+ definers changed.
+ (INT_MAX, INT_MIN, STD*_FILENO, SEEK_SET): Define if the underlying
+ system doesn't. Include <limits.h> for this.
+
+ * configure.in: Add limits.h, memcmp. Delete getline.
+
+ * inp.c (tibufsize): New variable; buffers grow as needed.
+ (TIBUFSIZE_MINIMUM): New macro.
+ (report_revision): New function.
+ (plan_a): Do not search patch as a big string, since that fails
+ if it contains null bytes.
+ Prepend `./' to filenames starting with `-', for RCS and SCCS.
+ If file does not match default RCS/SCCS version, go ahead and patch
+ it anyway; warn about the problem but do not report a fatal error.
+ (plan_b): Do not use a fixed buffer to read lines; read byte by byte
+ instead, so that the lines can be arbitrarily long. Do not search
+ lines as strings, since they may contain null bytes.
+ (plan_a, plan_b): Report I/O errors.
+
+ * inp.c, inp.h (rev_in_string): Remove.
+ (ifetch): Yield size of line too, since strlen no longer applies.
+ (plan_a, plan_b): No longer exported.
+
+ * patch.c (abort_hunk, apply_hunk, patch_match, similar):
+ Lines may contain NUL and need not end in newline.
+ (copy_till, dump_line): Insert newline if appending after partial line.
+ All invokers changed.
+ (main, get_some_switches, apply_hunk): Allocate *_define[ds], filearg,
+ rejname dynamically.
+ (make_temp): New function.
+ (main): Use it.
+ (main, spew_output, dump_line) Check for I/O errors.
+
+ * pch.c (open_patch_file): Don't copy stdin to a temporary file if
+ it's a regular file, since we can seek on it directly.
+ (open_patch_file, skip_to, another_hunk): The patch file may contain
+ NULs.
+ (another_hunk): The patch file may contain lines starting with '\',
+ which means the preceding line lacked a trailing newline.
+ (pgetline): Rename to pget_line.
+ (get_line, incomplete_line, pch_write_line): New functions.
+ (pch_line_len): Return size_t, not short; lines may be very long.
+ (do_ed_script): Check for I/O errors. Allow scripts to contain
+ 'i' and 's' commands, too.
+
+ * pch.h (pfp, grow_hunkmax, intuit_diff_type, next_intuit_at, skip_to,
+ pfetch, pgetline): No longer exported.
+ (pch_write_line): New declaration.
+ (getline): Removed.
+
+ * util.c (move_file, fetchname): Use private stat buffer, so that
+ filestat isn't lost. Check for I/O errors.
+ (savestr): Use savebuf.
+ (zask): Use STD*_FILENO instead of 0, 1, 2.
+ (fetchname): strip_leading defaults to INT_MAX instead of 957 (!).
+ (memcmp): Define if !HAVE_MEMCMP.
+
+ * util.c, util.h (say*, fatal*, pfatal*, ask*): Delete; these
+ pseudo-varargs functions weren't ANSI C. Replace by macros
+ that invoke [fs]printf directly, and invoke new functions
+ [az]{say,fatal,pfatal,ask} before and after.
+ (savebuf, read_fatal, write_fatal, memory_fatal, Fseek): New functions.
+ (fatal*): Output trailing newline after message. All invokers changed.
+
+ * version.c (version): Don't exit.
+
+ * Makefile.in (SRCS): Remove getline.c.
+
+Thu Jul 22 15:24:24 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * EXTERN.h, INTERN.h (PARAMS): Define.
+ * backupfile.h, common.h, inp.h, pch.h, util.h: Use.
+ * backupfile.c: Include EXTERN.h.
+
+Wed Jul 21 13:14:05 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * getline.c: New file.
+ * configure.in: Check for getline (GNU libc has it).
+ * pch.c: Use it instead of fgets.
+ (pgetline): Renamed from pgets. Change callers.
+ * pch.h: Change decl.
+
+ * pch.c (pgets): Tab adjusts by 8 - (indent % 8), not % 7.
+ Be consistent with similar code in pch.c::intuit_diff_type.
+
+ * common.h (MEM): Typedef removed.
+ inp.c, pch.c, util.c: Use size_t instead of MEM.
+ inp.c, pch.c: Use off_t.
+ configure.in: Add AC_SIZE_T and AC_OFF_T.
+
+ * common.h: Make buf a pointer and add a bufsize variable.
+ * util.c, pch.c, inp.c: Replace sizeof buf with bufsize.
+ * patch.c: malloc buf to bufsize bytes.
+
+Tue Jul 20 20:40:03 1993 Paul Eggert (eggert@twinsun.com)
+
+ * common.h (BUFFERSIZE): Grow it to 8k too, just in case.
+ (buf): Turn `buf' back into an array; making it a pointer broke
+ things seriously.
+ * patch.c (main): Likewise.
+
+Tue Jul 20 20:02:40 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * Move Reg[1-16] and CANVARARG decls from config.h.in to common.h.
+ * acconfig.h: New file.
+ * Makefile (HDRS): Add it.
+
+Tue Jul 20 16:35:27 1993 Paul Eggert (eggert@twinsun.com)
+
+ * Makefile.in: Remove alloca.[co]; getopt no longer needs it.
+ * configure.in (AC_ALLOCA): Remove.
+
+ * util.c (set_signals, ignore_signals): Do nothing if SIGHUP
+ and SIGINT aren't defined.
+
+Tue Jul 20 17:59:56 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * patch.c (main): Call xmalloc, not malloc. xmalloc buf.
+ * common.h: Declare xmalloc. Make buf a pointer, not an array.
+
+ * util.c (xmalloc): Call fatal1, not fatal.
+
+ * common.h [MAXLINELEN]: Bump from 1k to 8k.
+
+Thu Jul 8 19:56:16 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * Makefile.in (installdirs): New target.
+ (install): Use it.
+ (Makefile, config.status, configure): New targets.
+
+Wed Jul 7 13:25:40 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * patch.c (get_some_switches, longopts): Recognize --help
+ option, and call usage.
+ (usage): New function.
+
+Fri Jun 25 07:49:45 1993 Paul Eggert (eggert@twinsun.com)
+
+ * backupfile.c (find_backup_file_name): Don't use .orig if
+ numbered_existing with no existing numbered backup.
+ (addext): Don't use ext if !HAVE_LONG_FILE_NAMES,
+ even if it would fit. This matches patch's historical behavior.
+ (simple_backup_suffix): Default to ".orig".
+ * patch.c (main): Just use that default.
+
+Tue Jun 15 22:32:14 1993 Paul Eggert (eggert@twinsun.com)
+
+ * config.h.in (HAVE_ALLOCA_H): This #undef was missing.
+ * Makefile.in (info, check, installcheck): New rules.
+
+Sun Jun 13 14:31:29 1993 Paul Eggert (eggert@twinsun.com)
+
+ * config.h.in (index, rindex): Remove unused macro
+ definitions; they get in the way when porting to AIX.
+ * config.h.in, configure.in (HAVE_STRING_H): Remove unused defn.
+
Thu Jun 10 21:13:47 1993 Paul Eggert (eggert@twinsun.com)
* patchlevel.h: PATCH_VERSION 2.1.
@@ -176,7 +772,7 @@ Mon Jul 6 13:01:52 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
config.h.in, configure, configure.in, getopt.[ch], getopt1.c,
rename.c: New files.
* Configure, MANIFEST, Makefile.SH, config.H, config.h.SH,
- malloc.c: Files removed.
+ malloc.c: Files removed.
* version.c (version): Don't print the RCS stuff, since we're
not updating it regularly.
@@ -219,9 +815,9 @@ Wed Apr 29 10:19:33 1992 David J. MacKenzie (djm@churchy.gnu.ai.mit.edu)
Fri Mar 27 09:57:14 1992 Karl Berry (karl at hayley)
- * common.h (S_ISDIR, S_ISREG): define these.
- * inp.c (plan_a): use S_ISREG, not S_IFREG.
- * util.c (fetchname): use S_ISDIR, not S_IFDIR.
+ * common.h (S_ISDIR, S_ISREG): define these.
+ * inp.c (plan_a): use S_ISREG, not S_IFREG.
+ * util.c (fetchname): use S_ISDIR, not S_IFDIR.
Mon Mar 16 14:10:42 1992 David J. MacKenzie (djm@wookumz.gnu.ai.mit.edu)
@@ -326,7 +922,7 @@ Mon Jan 7 06:25:11 1991 David J. MacKenzie (djm at geech.ai.mit.edu)
Mon Dec 3 00:14:25 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
* patch.c (get_some_switches): Make the usage message more
- informative.
+ informative.
Sun Dec 2 23:20:18 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
@@ -335,7 +931,8 @@ Sun Dec 2 23:20:18 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
* Apply fix for -D from ksb@mentor.cc.purdue.edu (Kevin Braunsdorf).
- * Apply unidiff patches from davison@dri.com (Wayne Davison).
+1990-05-01 Wayne Davison <davison@dri.com>
+ * patch.c, pch.c: unidiff support added
Wed Mar 7 23:47:25 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
@@ -352,6 +949,100 @@ Sun Dec 17 17:29:48 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu)
* patch.c (reverse_flag_specified): New variable.
(get_some_switches, reinitialize_almost_everything): Use it.
+
+1988-06-22 Larry Wall <sdcrdcf!lwall>
+ patch12:
+ * common.h: sprintf was declared wrong
+ * patch.c: rindex() wasn't declared
+ * patch.man: now avoids Bell System Logo
+
+1988-06-03 Larry Wall <sdcrdcf!lwall>
+ patch10:
+ * common.h: support for shorter extensions.
+ * inp.c: made a little smarter about sccs files
+ * patch.c: exit code improved.
+ better support for non-flexfilenames.
+ * patch.man: -B switch was contributed.
+ * pch.c: Can now find patches in shar scripts.
+ Hunks that swapped and then swapped back could core dump.
+
+1987-06-04 Larry Wall <sdcrdcf!lwall>
+ * pch.c: pch_swap didn't swap p_bfake and p_efake.
+
+1987-02-16 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Short replacement caused spurious "Out of sync" message.
+
+1987-01-30 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Improved diagnostic on sync error.
+ Moved do_ed_script() to pch.c.
+ * pch.c: Improved responses to mangled patches.
+ * pch.h: Added do_ed_script().
+
+1987-01-05 Larry Wall <sdcrdcf!lwall>
+ * pch.c: New-style context diffs caused double call to free().
+
+1986-11-21 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Fuzz factor caused offset of installed lines.
+
+1986-11-14 Larry Wall <sdcrdcf!lwall>
+ * pch.c: Fixed problem where a long pattern wouldn't grow the hunk.
+ Also restored p_input_line when backtracking so error messages are
+ right.
+
+1986-11-03 Larry Wall <sdcrdcf!lwall>
+ * pch.c: New-style delete triggers spurious assertion error.
+
+1986-10-29 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Backwards search could terminate prematurely.
+ * pch.c: Could falsely report new-style context diff.
+
+1986-09-17 Larry Wall <sdcrdcf!lwall>
+ * common.h, inp.c, inp.h, patch.c, patch.man, pch.c, pch.h,
+ util.h, version.c, version.h: Baseline for netwide release.
+
+1986-08-01 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Fixes for machines that can't vararg.
+ Added fuzz factor. Generalized -p. General cleanup.
+ Changed some %d's to %ld's. Linted.
+ * patch.man: Documented -v, -p, -F.
+ Added notes to patch senders.
+
+1985-08-15 van%ucbmonet@berkeley
+ Changes for 4.3bsd diff -c.
+
+1985-03-26 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Frozen.
+ * patch.man: Frozen.
+
+1985-03-12 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Now checks for normalness of file to patch.
+ Check i_ptr and i_womp to make sure they aren't null before freeing.
+ Also allow ed output to be suppressed.
+ Changed pfp->_file to fileno(pfp).
+ Added -p option from jromine@uci-750a.
+ Added -D (#ifdef) option from joe@fluke.
+ * patch.man: Documented -p, -D.
+
+1984-12-06 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Made smarter about SCCS subdirectories.
+
+1984-12-05 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Added -l switch to do loose string comparison.
+ * patch.man: Added -l switch, and noted bistability bug.
+
+1984-12-04 Larry Wall <sdcrdcf!lwall>
+ Branch for sdcrdcf changes.
+ * patch.c: Failed hunk count not reset on multiple patch file.
+ * patch.man: Baseline version.
+
+1984-11-29 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Linted. Identifiers uniquified. Fixed i_ptr malloc() bug.
+ Fixed multiple calls to mktemp(). Will now work on machines that can
+ only read 32767 chars. Added -R option for diffs with new and old
+ swapped. Various cosmetic changes.
+
+1984-11-09 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Initial revision
Local Variables:
mode: indented-text
diff --git a/EXTERN.h b/EXTERN.h
deleted file mode 100644
index bdc1ef9..0000000
--- a/EXTERN.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* $Header: EXTERN.h,v 2.0 86/09/17 15:35:37 lwall Exp $
- *
- * $Log: EXTERN.h,v $
- * Revision 2.0 86/09/17 15:35:37 lwall
- * Baseline for netwide release.
- *
- */
-
-#ifdef EXT
-#undef EXT
-#endif
-#define EXT extern
-
-#ifdef INIT
-#undef INIT
-#endif
-#define INIT(x)
-
-#ifdef DOINIT
-#undef DOINIT
-#endif
diff --git a/INSTALL b/INSTALL
index f448317..50dbe43 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,118 +1,183 @@
-This is a generic INSTALL file for utilities distributions.
-If this package does not come with, e.g., installable documentation or
-data files, please ignore the references to them below.
-
-To compile this package:
-
-1. Configure the package for your system. In the directory that this
-file is in, type `./configure'. If you're using `csh' on an old
-version of System V, you might need to type `sh configure' instead to
-prevent `csh' from trying to execute `configure' itself.
-
-The `configure' shell script attempts to guess correct values for
-various system-dependent variables used during compilation, and
-creates the Makefile(s) (one in each subdirectory of the source
-directory). In some packages it creates a C header file containing
-system-dependent definitions. It also creates a file `config.status'
-that you can run in the future to recreate the current configuration.
-
-Running `configure' takes a minute or two. While it is running, it
-prints some messages that tell what it is doing. If you don't want to
-see the messages, run `configure' with its standard output redirected
-to `/dev/null'; for example, `./configure >/dev/null'.
-
-To compile the package in a different directory from the one
-containing the source code, you must use a version of `make' that
-supports the VPATH variable, such as GNU `make'. `cd' to the directory
-where you want the object files and executables to go and run
-`configure'. `configure' automatically checks for the source code in
-the directory that `configure' is in and in `..'. If for some reason
-`configure' is not in the source code directory that you are
-configuring, then it will report that it can't find the source code.
-In that case, run `configure' with the option `--srcdir=DIR', where
-DIR is the directory that contains the source code.
-
-By default, `make install' will install the package's files in
-/usr/local/bin, /usr/local/lib, /usr/local/man, etc. You can specify an
-installation prefix other than /usr/local by giving `configure' the option
-`--prefix=PATH'. Alternately, you can do so by consistently giving a value
-for the `prefix' variable when you run `make', e.g.,
- make prefix=/usr/gnu
- make prefix=/usr/gnu install
-
-You can specify separate installation prefixes for
-architecture-specific files and architecture-independent files. If
-you give `configure' the option `--exec-prefix=PATH' or set the
-`make' variable `exec_prefix' to PATH, the package will use PATH as
-the prefix for installing programs and libraries. Data files and
-documentation will still use the regular prefix. Normally, all files
-are installed using the regular prefix.
-
-Another `configure' option is useful mainly in `Makefile' rules for
-updating `config.status' and `Makefile'. The `--no-create' option
-figures out the configuration for your system and records it in
-`config.status', without actually configuring the package (creating
-`Makefile's and perhaps a configuration header file). Later, you can
-run `./config.status' to actually configure the package. You can also
-give `config.status' the `--recheck' option, which makes it re-run
-`configure' with the same arguments you used before. This option is
-useful if you change `configure'.
-
-Some packages pay attention to `--with-PACKAGE' options to `configure',
-where PACKAGE is something like `gnu-libc' or `x' (for the X Window System).
-The README should mention any --with- options that the package recognizes.
-
-`configure' ignores any other arguments that you give it.
-
-If your system requires unusual options for compilation or linking
-that `configure' doesn't know about, you can give `configure' initial
-values for some variables by setting them in the environment. In
-Bourne-compatible shells, you can do that on the command line like
+Basic Installation
+==================
+
+ These are generic installation instructions.
+
+ The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, a file
+`config.cache' that saves the results of its tests to speed up
+reconfiguring, and a file `config.log' containing compiler output
+(useful mainly for debugging `configure').
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If at some point `config.cache'
+contains results you don't want to keep, you may remove or edit it.
+
+ The file `configure.in' is used to create `configure' by a program
+called `autoconf'. You only need `configure.in' if you want to change
+it or regenerate `configure' using a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
+
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
+
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+Compilers and Options
+=====================
+
+ Some systems require unusual options for compilation or linking that
+the `configure' script does not know about. You can give `configure'
+initial values for variables by setting them in the environment. Using
+a Bourne-compatible shell, you can do that on the command line like
this:
- CC='gcc -traditional' DEFS=-D_POSIX_SOURCE ./configure
-
-The `make' variables that you might want to override with environment
-variables when running `configure' are:
-
-(For these variables, any value given in the environment overrides the
-value that `configure' would choose:)
-CC C compiler program.
- Default is `cc', or `gcc' if `gcc' is in your PATH.
-INSTALL Program to use to install files.
- Default is `install' if you have it, `cp' otherwise.
-
-(For these variables, any value given in the environment is added to
-the value that `configure' chooses:)
-DEFS Configuration options, in the form `-Dfoo -Dbar ...'
- Do not use this variable in packages that create a
- configuration header file.
-LIBS Libraries to link with, in the form `-lfoo -lbar ...'
-
-If you need to do unusual things to compile the package, we encourage
-you to figure out how `configure' could check whether to do them, and
-mail diffs or instructions to the address given in the README so we
-can include them in the next release.
-
-2. Type `make' to compile the package. If you want, you can override
-the `make' variables CFLAGS and LDFLAGS like this:
-
- make CFLAGS=-O2 LDFLAGS=-s
-
-3. If the package comes with self-tests and you want to run them,
-type `make check'. If you're not sure whether there are any, try it;
-if `make' responds with something like
- make: *** No way to make target `check'. Stop.
-then the package does not come with self-tests.
-
-4. Type `make install' to install programs, data files, and
-documentation.
-
-5. You can remove the program binaries and object files from the
-source directory by typing `make clean'. To also remove the
-Makefile(s), the header file containing system-dependent definitions
-(if the package uses one), and `config.status' (all the files that
-`configure' created), type `make distclean'.
-
-The file `configure.in' is used as a template to create `configure' by
-a program called `autoconf'. You will only need it if you want to
-regenerate `configure' using a newer version of `autoconf'.
+ CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+
+Or on systems that have the `env' program, you can do it like this:
+ env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+
+Compiling For Multiple Architectures
+====================================
+
+ You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script. `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not supports the `VPATH'
+variable, you have to compile the package for one architecture at a time
+in the source code directory. After you have installed the package for
+one architecture, use `make distclean' before reconfiguring for another
+architecture.
+
+Installation Names
+==================
+
+ By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc. You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+ You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files. If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+ Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+ There may be some features `configure' can not figure out
+automatically, but needs to determine by the type of host the package
+will run on. Usually `configure' can figure that out, but if it prints
+a message saying it can not guess the host type, give it the
+`--host=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name with three fields:
+ CPU-COMPANY-SYSTEM
+
+See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the host type.
+
+ If you are building compiler tools for cross-compiling, you can also
+use the `--target=TYPE' option to select the type of system they will
+produce code for and the `--build=TYPE' option to select the type of
+system on which you are compiling the package.
+
+Sharing Defaults
+================
+
+ If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Operation Controls
+==================
+
+ `configure' recognizes the following options to control how it
+operates.
+
+`--cache-file=FILE'
+ Use and save the results of the tests in FILE instead of
+ `./config.cache'. Set FILE to `/dev/null' to disable caching, for
+ debugging `configure'.
+
+`--help'
+ Print a summary of the options to `configure', and exit.
+
+`--quiet'
+`--silent'
+`-q'
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
+
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
+
+`--version'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
+`configure' also accepts some other, not widely useful, options.
+
diff --git a/INTERN.h b/INTERN.h
deleted file mode 100644
index 38574ef..0000000
--- a/INTERN.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* $Header: INTERN.h,v 2.0 86/09/17 15:35:58 lwall Exp $
- *
- * $Log: INTERN.h,v $
- * Revision 2.0 86/09/17 15:35:58 lwall
- * Baseline for netwide release.
- *
- */
-
-#ifdef EXT
-#undef EXT
-#endif
-#define EXT
-
-#ifdef INIT
-#undef INIT
-#endif
-#define INIT(x) = x
-
-#define DOINIT
diff --git a/Makefile.in b/Makefile.in
index 1a2b094..38982aa 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,88 +1,141 @@
# Makefile for GNU patch.
+# Copyright 1993, 1997 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.
+# If not, write to the Free Software Foundation,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#### Start of system configuration section. ####
srcdir = @srcdir@
VPATH = @srcdir@
-CC = @CC@
+@SET_MAKE@
+CC = @CC@
+ED_PROGRAM = @ED_PROGRAM@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+DEFS = @DEFS@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
-CFLAGS = -g
-LDFLAGS = -g
-
-prefix = /usr/local
-exec_prefix = $(prefix)
+prefix = @prefix@
+exec_prefix = @exec_prefix@
bindir = $(exec_prefix)/bin
# Where to put the manual pages.
-mandir = $(prefix)/man/man1
+man1dir = $(prefix)/man/man1
# Extension (not including `.') for the manual page filenames.
-manext = 1
+man1ext = .1
#### End of system configuration section. ####
SHELL = /bin/sh
-SRCS = backupfile.c getopt.c getopt1.c inp.c patch.c pch.c util.c \
- version.c rename.c alloca.c
-OBJS = backupfile.o getopt.o getopt1.o inp.o patch.o pch.o util.o \
- version.o @LIBOBJS@ @ALLOCA@
-HDRS = EXTERN.h INTERN.h backupfile.h common.h getopt.h \
- inp.h patchlevel.h pch.h util.h version.h
-MISC = COPYING ChangeLog INSTALL Makefile.in README NEWS \
- configure configure.in config.h.in patch.man
+LIBSRCS = getopt.c getopt1.c memchr.c rename.c
+SRCS = addext.c argmatch.c backupfile.c basename.c inp.c \
+ patch.c pch.c util.c version.c $(LIBSRCS)
+OBJS = addext.o argmatch.o backupfile.o basename.o inp.o \
+ patch.o pch.o util.o version.o $(LIBOBJS)
+HDRS = argmatch.h backupfile.h common.h getopt.h \
+ inp.h pch.h util.h version.h
+MISC = COPYING ChangeLog INSTALL Makefile.in NEWS README \
+ acconfig.h config.hin configure configure.in \
+ install-sh mkinstalldirs patch.man
DISTFILES = $(MISC) $(SRCS) $(HDRS)
-all: patch
+all:: patch
+
+info::
+check::
+installcheck::
+
+COMPILE = $(CC) -c $(CPPFLAGS) $(DEFS) -DED_PROGRAM=\"$(ED_PROGRAM)\" \
+ -I. -I$(srcdir) $(CFLAGS)
.c.o:
- $(CC) -c -DHAVE_CONFIG_H -I. $(CPPFLAGS) $(CFLAGS) $<
+ $(COMPILE) $<
patch: $(OBJS)
- $(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
+ $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS)
+
+install:: all installdirs
+ $(INSTALL_PROGRAM) patch $(bindir)/`echo patch | sed '$(transform)'`
+ -$(INSTALL_DATA) $(srcdir)/patch.man \
+ $(man1dir)/`echo patch | sed '$(transform)'`$(man1ext)
+
+installdirs::
+ $(SHELL) $(srcdir)/mkinstalldirs $(bindir) $(man1dir)
+
+uninstall::
+ rm -f $(bindir)/patch $(man1dir)/patch$(man1ext)
-install: all
- $(INSTALL_PROGRAM) patch $(bindir)/patch
- -$(INSTALL_DATA) $(srcdir)/patch.man $(mandir)/patch.$(manext)
+Makefile: Makefile.in config.status
+ $(SHELL) config.status
+config.status: configure
+ $(SHELL) config.status --recheck
+configure: configure.in
+ cd $(srcdir) && autoconf
+config.hin: configure.in acconfig.h
+ cd $(srcdir) && rm -f config.hin && autoheader
-uninstall:
- rm -f $(bindir)/patch $(mandir)/patch.$(manext)
+patchlevel.h: Makefile
+ echo '#define PATCH_VERSION "$(VERSION)"' >patchlevel.h
-TAGS: $(SRCS)
- etags $(SRCS)
+TAGS: $(HDRS) patchlevel.h $(SRCS)
+ etags $(HDRS) patchlevel.h $(SRCS)
-clean:
+clean::
rm -f patch *.o core
-mostlyclean: clean
+mostlyclean:: clean
-distclean: clean
- rm -f Makefile config.status config.h
+distclean:: clean
+ rm -f Makefile config.cache config.log config.status config.h
+ rm -f patchlevel.h
-realclean: distclean
+maintainer-clean::
+ @echo "This command is intended for maintainers to use;"
+ @echo "rebuilding the deleted files requires special tools."
+ $(MAKE) distclean
rm -f TAGS
-dist: $(DISTFILES)
- echo patch-`sed -e '/PATCH_VERSION/!d' -e 's/[^0-9]*\([0-9a-z.]*\).*/\1/' -e q patchlevel.h` > .fname
- rm -rf `cat .fname`
- mkdir `cat .fname`
- ln $(DISTFILES) `cat .fname`
- tar -chf - `cat .fname` | gzip >`cat .fname`.tar.gz
- rm -rf `cat .fname` .fname
-
-backupfile.o: config.h backupfile.h
-getopt.o getopt1.o: config.h getopt.h
-inp.o: config.h common.h inp.h util.h EXTERN.h INTERN.h pch.h
-patch.o: config.h common.h inp.h pch.h util.h version.h backupfile.h \
- INTERN.h EXTERN.h getopt.h
-pch.o: config.h common.h pch.h util.h EXTERN.h INTERN.h
-util.o: config.h common.h util.h backupfile.h EXTERN.h INTERN.h
-version.o: config.h common.h version.h patchlevel.h util.h \
- EXTERN.h INTERN.h
+dist:: $(DISTFILES)
+ rm -rf $(PACKAGE)-$(VERSION)
+ mkdir $(PACKAGE)-$(VERSION)
+ ln $(DISTFILES) $(PACKAGE)-$(VERSION)
+ tar -chf - $(PACKAGE)-$(VERSION) | \
+ gzip -9 >$(PACKAGE)-$(VERSION).tar.gz
+ rm -rf $(PACKAGE)-$(VERSION)
+
+$(OBJS): config.h
+addext.o: backupfile.h
+argmatch.o: argmatch.h
+backupfile.o: argmatch.h backupfile.h
+basename.o: backupfile.h
+getopt.o getopt1.o: getopt.h
+inp.o: backupfile.h common.h inp.h util.h pch.h
+patch.o: argmatch.h backupfile.h common.h getopt.h inp.h pch.h util.h version.h
+pch.o: common.h inp.h pch.h util.h
+util.o: backupfile.h common.h util.h version.h
+version.o: common.h patchlevel.h util.h version.h
diff --git a/NEWS b/NEWS
index dff4c74..7022862 100644
--- a/NEWS
+++ b/NEWS
@@ -1,17 +1,80 @@
+Known problems:
+
+* The diffutils 2.7 documentation for `patch' is obsolete; this should be
+ fixed in diffutils 2.8. Until then, see `patch --help' or `man patch'.
+
+Changes in version 2.2:
+
+* Arbitrary limits removed (e.g. line length, file name length).
+
+* On POSIX.1-compliant hosts, you can now patch binary files using the output
+ of GNU `diff -a'.
+
+* New options:
+ --dry-run
+ --help
+ --verbose
+ -i FILE or --input=FILE
+ -y PREF or --basename-prefix=PREF
+
+* patch is now quieter by default; use --verbose for the old chatty behavior.
+
+* Patch now complies better with POSIX.2 if your host complies with POSIX.1.
+
+ Therefore:
+ - By default, no backups are made. Set the VERSION_CONTROL environment
+ variable to "existing" if you prefer patch's traditional behavior.
+ - The simple backup file name for F defaults to F.orig
+ regardless of whether the file system supports long file names,
+ and F~ is used only if F.orig is too long for that particular file.
+ - Similarly for the reject file names F.rej and F#.
+
+ Also:
+ - The pseudo-option `+' has been withdrawn.
+ - -b is equivalent to --version-control=simple;
+ `-z SUFF' has the meaning that `-b SUFF' used to.
+ - Names of files to be patched are taken first from *** line and then from
+ --- line of context diffs; then from Index: line; /dev/tty is
+ consulted if none of the above files exist. However, if the patch
+ appears to create a file, the file does not have to exist: instead,
+ the first name with the longest existing directory prefix is taken.
+ - Exit status 0 means success, 1 means hunks were rejected, 2 means trouble.
+ - `-l' ignores changes only in spaces and tabs, not in other white space.
+ - If no `-p' option is given, `-pINFINITY' is assumed, instead of trying
+ to guess the proper value.
+ - `-p' now requires an operand; use `-p 0' to get the effect of the old plain
+ `-p' option.
+ - `-p' treats two or more adjacent slashes as if it were one slash.
+ - The TERM signal is caught.
+ - New option `-i F' reads patch from F instead of stdin.
+
+* The `patch' options and build procedure conform to current GNU standards.
+ For example, the `--version' option now outputs copyright information.
+
+* When the patch is creating a file, but a nonempty file of that name already
+ exists, `patch' now asks for confirmation before patching.
+
+* RCS is used only if the version control method is `existing'
+ and there is already an RCS file. Similarly for SCCS.
+
+* Copyright notices have been clarified. Every file in this version of `patch'
+ can be distributed under the GNU General Public License. See README for
+ details.
+
Changes in version 2.1:
* A few more portability bugs have been fixed. The version number has
been changed from 2.0.12g11 to 2.1, because the name
`patch-2.0.12g10' was too long for traditional Unix file systems.
-
+
Versions 2.0.12g9 through 2.0.12g11 fix various portability bugs.
-
+
Changes in version 2.0.12g8:
* Start of the 12g series, with a GNU-style configure script and
long-named options.
* Added the -t --batch option, similar to -f.
-* Improved detection of files that are locked under RCS or SCCS.
+* Improved detection of files that are locked under RCS or SCCS.
* Reinstate the -E option to remove output files that are empty after
being patched.
* Print the system error message when system calls fail.
diff --git a/README b/README
index cc788f9..609221b 100644
--- a/README
+++ b/README
@@ -1,45 +1,52 @@
-This version of patch contains modifications made by the Free Software
-Foundation, summarized in the file ChangeLog. Primarily they are to
-support the unified context diff format that GNU diff can produce, to
-support making GNU Emacs-style backup files, and to support the GNU
-conventions for option parsing and configuring and compilation. They
-also include fixes for some bugs.
-
-The FSF is distributing this version of patch independently because as
-of this writing, Larry Wall has not released a new version of patch
-since mid-1988. I have heard that he has been too busy working on
-other things, like Perl.
-
-Here is a wish list of some projects to improve patch:
-
-1. Correctly handle files and patchfiles that contain NUL characters.
-This is hard to do straightforwardly; it would be less work to
-adopt a kind of escape encoding internally.
-Let ESC be a "control prefix". ESC @ stands for NUL. ESC [ stands for ESC.
-You need to crunch this when reading input (replace fgets),
-and when writing the output file (replace fputs),
-but otherwise everything can go along as it does now.
-Be careful to handle reject files correctly;
-I think they are currently created using `write', not `fputs'.
-
-2. Correctly handle patches produced by GNU diff for files that do
-not end with a newline.
-
-Please send bug reports for this version of patch to
-bug-gnu-utils@prep.ai.mit.edu as well as to Larry Wall (lwall@netlabs.com).
- --djm@gnu.ai.mit.edu (David MacKenzie)
-
- Patch Kit, Version 2.0
-
- Copyright (c) 1988, Larry Wall
-
-You may copy the patch kit in whole or in part as long as you don't try to
-make money off it, or pretend that you wrote it.
---------------------------------------------------------------------------
+This version of `patch' has many changes made by the Free Software Foundation.
+They add support for:
+ * handling arbitrary binary data and large files
+ * the unified context diff format that GNU diff can produce
+ * making GNU Emacs-style backup files
+ * improved interaction with RCS and SCCS
+ * the GNU conventions for option parsing and configuring and compilation.
+ * better POSIX.2 compliance
+They also fix some bugs. See the NEWS and ChangeLog files for details.
+
+Tutorial-style documentation for patch is included in the GNU
+diffutils package. Unfortunately, the diffutils 2.7 documentation
+for `patch' is obsolete; this should be fixed in diffutils 2.8.
+In the mean time, see `patch --help', or consult the man page
+in this distribution.
See the file INSTALL for compilation and installation instructions for Unix.
-For non-Unix systems, copy config.h.in to config.h and change
+For non-Unix systems, copy config.hin to config.h and change
#undef statements in it to #define as appropriate for your system,
and copy Makefile.in to Makefile and set the variables that are
-enclosed in @ signs appropriate for your system.
+enclosed in @ signs as appropriate for your system.
+
+Please send bug reports for this version of patch to
+bug-gnu-utils@prep.ai.mit.edu.
+
+The Free Software Foundation is distributing this version of patch
+independently because as of this writing, Larry Wall has not released a
+new version of patch since mid-1988. We have heard that he has been
+too busy working on other things, like Perl. He has graciously agreed
+to let GNU `patch' be distributed under the terms of the GNU General
+Public License.
+
+------
+
+Copyright 1984, 1985, 1986, 1987, 1988 Larry Wall
+Copyright 1989, 1990, 1991, 1992, 1993, 1997 Free Software Foundation, Inc.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this file; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
diff --git a/acconfig.h b/acconfig.h
new file mode 100644
index 0000000..4033163
--- /dev/null
+++ b/acconfig.h
@@ -0,0 +1,7 @@
+/* Local acconfig.h for autoheader.
+ Descriptive text for the C preprocessor macros that
+ the patch configure.in can define.
+ autoheader copies the comments into config.hin. */
+
+/* Define if memchr works. */
+#undef HAVE_MEMCHR
diff --git a/addext.c b/addext.c
new file mode 100644
index 0000000..b32a90d
--- /dev/null
+++ b/addext.c
@@ -0,0 +1,89 @@
+/* addext.c -- add an extension to a file name
+ Copyright (C) 1990, 1997 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and Paul Eggert */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef HAVE_LONG_FILE_NAMES
+#define HAVE_LONG_FILE_NAMES 0
+#endif
+
+#include <backupfile.h>
+
+#include <sys/types.h>
+#if HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+/* Append to FILENAME the extension EXT, unless the result would be too long,
+ in which case just append the character E. */
+
+void
+addext (filename, ext, e)
+ char *filename;
+ char const *ext;
+ int e;
+{
+ char *s = base_name (filename);
+ size_t slen = strlen (s), extlen = strlen (ext);
+ long slen_max = -1;
+
+#if HAVE_PATHCONF && defined _PC_NAME_MAX
+#ifndef _POSIX_NAME_MAX
+#define _POSIX_NAME_MAX 14
+#endif
+ if (slen + extlen <= _POSIX_NAME_MAX)
+ /* The file name is so short there's no need to call pathconf. */
+ slen_max = _POSIX_NAME_MAX;
+ else if (s == filename)
+ slen_max = pathconf (".", _PC_NAME_MAX);
+ else
+ {
+ char c = *s;
+ *s = 0;
+ slen_max = pathconf (filename, _PC_NAME_MAX);
+ *s = c;
+ }
+#endif
+ if (slen_max < 0)
+ slen_max = HAVE_LONG_FILE_NAMES ? 255 : 14;
+
+ if (slen + extlen <= slen_max)
+ strcpy (s + slen, ext);
+ else
+ {
+ if (slen_max <= slen) {
+ /* Try to preserve difference between .h .c etc. */
+ if (slen == slen_max && s[slen - 2] == '.')
+ s[slen - 2] = s[slen - 1];
+
+ slen = slen_max - 1;
+ }
+ s[slen] = e;
+ s[slen + 1] = 0;
+ }
+}
diff --git a/alloca.c b/alloca.c
deleted file mode 100644
index c04c0ef..0000000
--- a/alloca.c
+++ /dev/null
@@ -1,475 +0,0 @@
-/* alloca.c -- allocate automatically reclaimed memory
- (Mostly) portable public-domain implementation -- D A Gwyn
-
- This implementation of the PWB library alloca function,
- which is used to allocate space off the run-time stack so
- that it is automatically reclaimed upon procedure exit,
- was inspired by discussions with J. Q. Johnson of Cornell.
- J.Otto Tennant <jot@cray.com> contributed the Cray support.
-
- There are some preprocessor constants that can
- be defined when compiling for your specific system, for
- improved efficiency; however, the defaults should be okay.
-
- The general concept of this implementation is to keep
- track of all alloca-allocated blocks, and reclaim any
- that are found to be deeper in the stack than the current
- invocation. This heuristic does not reclaim storage as
- soon as it becomes invalid, but it will do so eventually.
-
- As a special case, alloca(0) reclaims storage without
- allocating any. It is a good idea to use alloca(0) in
- your main control loop, etc. to force garbage collection. */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-/* If compiling with GCC, this file's not needed. */
-#ifndef alloca
-
-#ifdef emacs
-#ifdef static
-/* actually, only want this if static is defined as ""
- -- this is for usg, in which emacs must undefine static
- in order to make unexec workable
- */
-#ifndef STACK_DIRECTION
-you
-lose
--- must know STACK_DIRECTION at compile-time
-#endif /* STACK_DIRECTION undefined */
-#endif /* static */
-#endif /* emacs */
-
-/* If your stack is a linked list of frames, you have to
- provide an "address metric" ADDRESS_FUNCTION macro. */
-
-#ifdef CRAY
-long i00afunc ();
-#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
-#else
-#define ADDRESS_FUNCTION(arg) &(arg)
-#endif
-
-#if __STDC__
-typedef void *pointer;
-#else
-typedef char *pointer;
-#endif
-
-#define NULL 0
-
-/* Different portions of Emacs need to call different versions of
- malloc. The Emacs executable needs alloca to call xmalloc, because
- ordinary malloc isn't protected from input signals. On the other
- hand, the utilities in lib-src need alloca to call malloc; some of
- them are very simple, and don't have an xmalloc routine.
-
- Non-Emacs programs expect this to call use xmalloc.
-
- Callers below should use malloc. */
-
-#ifndef emacs
-#define malloc xmalloc
-extern pointer xmalloc ();
-#endif
-
-/* Define STACK_DIRECTION if you know the direction of stack
- growth for your system; otherwise it will be automatically
- deduced at run-time.
-
- STACK_DIRECTION > 0 => grows toward higher addresses
- STACK_DIRECTION < 0 => grows toward lower addresses
- STACK_DIRECTION = 0 => direction of growth unknown */
-
-#ifndef STACK_DIRECTION
-#define STACK_DIRECTION 0 /* Direction unknown. */
-#endif
-
-#if STACK_DIRECTION != 0
-
-#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
-
-#else /* STACK_DIRECTION == 0; need run-time code. */
-
-static int stack_dir; /* 1 or -1 once known. */
-#define STACK_DIR stack_dir
-
-static void
-find_stack_direction ()
-{
- static char *addr = NULL; /* Address of first `dummy', once known. */
- auto char dummy; /* To get stack address. */
-
- if (addr == NULL)
- { /* Initial entry. */
- addr = ADDRESS_FUNCTION (dummy);
-
- find_stack_direction (); /* Recurse once. */
- }
- else
- {
- /* Second entry. */
- if (ADDRESS_FUNCTION (dummy) > addr)
- stack_dir = 1; /* Stack grew upward. */
- else
- stack_dir = -1; /* Stack grew downward. */
- }
-}
-
-#endif /* STACK_DIRECTION == 0 */
-
-/* An "alloca header" is used to:
- (a) chain together all alloca'ed blocks;
- (b) keep track of stack depth.
-
- It is very important that sizeof(header) agree with malloc
- alignment chunk size. The following default should work okay. */
-
-#ifndef ALIGN_SIZE
-#define ALIGN_SIZE sizeof(double)
-#endif
-
-typedef union hdr
-{
- char align[ALIGN_SIZE]; /* To force sizeof(header). */
- struct
- {
- union hdr *next; /* For chaining headers. */
- char *deep; /* For stack depth measure. */
- } h;
-} header;
-
-static header *last_alloca_header = NULL; /* -> last alloca header. */
-
-/* Return a pointer to at least SIZE bytes of storage,
- which will be automatically reclaimed upon exit from
- the procedure that called alloca. Originally, this space
- was supposed to be taken from the current stack frame of the
- caller, but that method cannot be made to work for some
- implementations of C, for example under Gould's UTX/32. */
-
-pointer
-alloca (size)
- unsigned size;
-{
- auto char probe; /* Probes stack depth: */
- register char *depth = ADDRESS_FUNCTION (probe);
-
-#if STACK_DIRECTION == 0
- if (STACK_DIR == 0) /* Unknown growth direction. */
- find_stack_direction ();
-#endif
-
- /* Reclaim garbage, defined as all alloca'd storage that
- was allocated from deeper in the stack than currently. */
-
- {
- register header *hp; /* Traverses linked list. */
-
- for (hp = last_alloca_header; hp != NULL;)
- if ((STACK_DIR > 0 && hp->h.deep > depth)
- || (STACK_DIR < 0 && hp->h.deep < depth))
- {
- register header *np = hp->h.next;
-
- free ((pointer) hp); /* Collect garbage. */
-
- hp = np; /* -> next header. */
- }
- else
- break; /* Rest are not deeper. */
-
- last_alloca_header = hp; /* -> last valid storage. */
- }
-
- if (size == 0)
- return NULL; /* No allocation required. */
-
- /* Allocate combined header + user data storage. */
-
- {
- register pointer new = malloc (sizeof (header) + size);
- /* Address of header. */
-
- ((header *) new)->h.next = last_alloca_header;
- ((header *) new)->h.deep = depth;
-
- last_alloca_header = (header *) new;
-
- /* User storage begins just after header. */
-
- return (pointer) ((char *) new + sizeof (header));
- }
-}
-
-#ifdef CRAY
-
-#ifdef DEBUG_I00AFUNC
-#include <stdio.h>
-#endif
-
-#ifndef CRAY_STACK
-#define CRAY_STACK
-#ifndef CRAY2
-/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
-struct stack_control_header
- {
- long shgrow:32; /* Number of times stack has grown. */
- long shaseg:32; /* Size of increments to stack. */
- long shhwm:32; /* High water mark of stack. */
- long shsize:32; /* Current size of stack (all segments). */
- };
-
-/* The stack segment linkage control information occurs at
- the high-address end of a stack segment. (The stack
- grows from low addresses to high addresses.) The initial
- part of the stack segment linkage control information is
- 0200 (octal) words. This provides for register storage
- for the routine which overflows the stack. */
-
-struct stack_segment_linkage
- {
- long ss[0200]; /* 0200 overflow words. */
- long sssize:32; /* Number of words in this segment. */
- long ssbase:32; /* Offset to stack base. */
- long:32;
- long sspseg:32; /* Offset to linkage control of previous
- segment of stack. */
- long:32;
- long sstcpt:32; /* Pointer to task common address block. */
- long sscsnm; /* Private control structure number for
- microtasking. */
- long ssusr1; /* Reserved for user. */
- long ssusr2; /* Reserved for user. */
- long sstpid; /* Process ID for pid based multi-tasking. */
- long ssgvup; /* Pointer to multitasking thread giveup. */
- long sscray[7]; /* Reserved for Cray Research. */
- long ssa0;
- long ssa1;
- long ssa2;
- long ssa3;
- long ssa4;
- long ssa5;
- long ssa6;
- long ssa7;
- long sss0;
- long sss1;
- long sss2;
- long sss3;
- long sss4;
- long sss5;
- long sss6;
- long sss7;
- };
-
-#else /* CRAY2 */
-/* The following structure defines the vector of words
- returned by the STKSTAT library routine. */
-struct stk_stat
- {
- long now; /* Current total stack size. */
- long maxc; /* Amount of contiguous space which would
- be required to satisfy the maximum
- stack demand to date. */
- long high_water; /* Stack high-water mark. */
- long overflows; /* Number of stack overflow ($STKOFEN) calls. */
- long hits; /* Number of internal buffer hits. */
- long extends; /* Number of block extensions. */
- long stko_mallocs; /* Block allocations by $STKOFEN. */
- long underflows; /* Number of stack underflow calls ($STKRETN). */
- long stko_free; /* Number of deallocations by $STKRETN. */
- long stkm_free; /* Number of deallocations by $STKMRET. */
- long segments; /* Current number of stack segments. */
- long maxs; /* Maximum number of stack segments so far. */
- long pad_size; /* Stack pad size. */
- long current_address; /* Current stack segment address. */
- long current_size; /* Current stack segment size. This
- number is actually corrupted by STKSTAT to
- include the fifteen word trailer area. */
- long initial_address; /* Address of initial segment. */
- long initial_size; /* Size of initial segment. */
- };
-
-/* The following structure describes the data structure which trails
- any stack segment. I think that the description in 'asdef' is
- out of date. I only describe the parts that I am sure about. */
-
-struct stk_trailer
- {
- long this_address; /* Address of this block. */
- long this_size; /* Size of this block (does not include
- this trailer). */
- long unknown2;
- long unknown3;
- long link; /* Address of trailer block of previous
- segment. */
- long unknown5;
- long unknown6;
- long unknown7;
- long unknown8;
- long unknown9;
- long unknown10;
- long unknown11;
- long unknown12;
- long unknown13;
- long unknown14;
- };
-
-#endif /* CRAY2 */
-#endif /* not CRAY_STACK */
-
-#ifdef CRAY2
-/* Determine a "stack measure" for an arbitrary ADDRESS.
- I doubt that "lint" will like this much. */
-
-static long
-i00afunc (long *address)
-{
- struct stk_stat status;
- struct stk_trailer *trailer;
- long *block, size;
- long result = 0;
-
- /* We want to iterate through all of the segments. The first
- step is to get the stack status structure. We could do this
- more quickly and more directly, perhaps, by referencing the
- $LM00 common block, but I know that this works. */
-
- STKSTAT (&status);
-
- /* Set up the iteration. */
-
- trailer = (struct stk_trailer *) (status.current_address
- + status.current_size
- - 15);
-
- /* There must be at least one stack segment. Therefore it is
- a fatal error if "trailer" is null. */
-
- if (trailer == 0)
- abort ();
-
- /* Discard segments that do not contain our argument address. */
-
- while (trailer != 0)
- {
- block = (long *) trailer->this_address;
- size = trailer->this_size;
- if (block == 0 || size == 0)
- abort ();
- trailer = (struct stk_trailer *) trailer->link;
- if ((block <= address) && (address < (block + size)))
- break;
- }
-
- /* Set the result to the offset in this segment and add the sizes
- of all predecessor segments. */
-
- result = address - block;
-
- if (trailer == 0)
- {
- return result;
- }
-
- do
- {
- if (trailer->this_size <= 0)
- abort ();
- result += trailer->this_size;
- trailer = (struct stk_trailer *) trailer->link;
- }
- while (trailer != 0);
-
- /* We are done. Note that if you present a bogus address (one
- not in any segment), you will get a different number back, formed
- from subtracting the address of the first block. This is probably
- not what you want. */
-
- return (result);
-}
-
-#else /* not CRAY2 */
-/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
- Determine the number of the cell within the stack,
- given the address of the cell. The purpose of this
- routine is to linearize, in some sense, stack addresses
- for alloca. */
-
-static long
-i00afunc (long address)
-{
- long stkl = 0;
-
- long size, pseg, this_segment, stack;
- long result = 0;
-
- struct stack_segment_linkage *ssptr;
-
- /* Register B67 contains the address of the end of the
- current stack segment. If you (as a subprogram) store
- your registers on the stack and find that you are past
- the contents of B67, you have overflowed the segment.
-
- B67 also points to the stack segment linkage control
- area, which is what we are really interested in. */
-
- stkl = CRAY_STACKSEG_END ();
- ssptr = (struct stack_segment_linkage *) stkl;
-
- /* If one subtracts 'size' from the end of the segment,
- one has the address of the first word of the segment.
-
- If this is not the first segment, 'pseg' will be
- nonzero. */
-
- pseg = ssptr->sspseg;
- size = ssptr->sssize;
-
- this_segment = stkl - size;
-
- /* It is possible that calling this routine itself caused
- a stack overflow. Discard stack segments which do not
- contain the target address. */
-
- while (!(this_segment <= address && address <= stkl))
- {
-#ifdef DEBUG_I00AFUNC
- fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
-#endif
- if (pseg == 0)
- break;
- stkl = stkl - pseg;
- ssptr = (struct stack_segment_linkage *) stkl;
- size = ssptr->sssize;
- pseg = ssptr->sspseg;
- this_segment = stkl - size;
- }
-
- result = address - this_segment;
-
- /* If you subtract pseg from the current end of the stack,
- you get the address of the previous stack segment's end.
- This seems a little convoluted to me, but I'll bet you save
- a cycle somewhere. */
-
- while (pseg != 0)
- {
-#ifdef DEBUG_I00AFUNC
- fprintf (stderr, "%011o %011o\n", pseg, size);
-#endif
- stkl = stkl - pseg;
- ssptr = (struct stack_segment_linkage *) stkl;
- size = ssptr->sssize;
- pseg = ssptr->sspseg;
- result += size;
- }
- return (result);
-}
-
-#endif /* not CRAY2 */
-#endif /* CRAY */
-
-#endif /* no alloca */
diff --git a/argmatch.c b/argmatch.c
new file mode 100644
index 0000000..51d8b95
--- /dev/null
+++ b/argmatch.c
@@ -0,0 +1,87 @@
+/* argmatch.c -- find a match for a string in an array
+ Copyright (C) 1990, 1997 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu> */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <argmatch.h>
+
+#include <stdio.h>
+#include <sys/types.h>
+#if HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
+
+/* If ARG is an unambiguous match for an element of the
+ null-terminated array OPTLIST, return the index in OPTLIST
+ of the matched element, else -1 if it does not match any element
+ or -2 if it is ambiguous (is a prefix of more than one element). */
+
+int
+argmatch (arg, optlist)
+ char const *arg;
+ char const * const *optlist;
+{
+ int i; /* Temporary index in OPTLIST. */
+ size_t arglen; /* Length of ARG. */
+ int matchind = -1; /* Index of first nonexact match. */
+
+ arglen = strlen (arg);
+
+ /* Test all elements for either exact match or abbreviated matches. */
+ for (i = 0; optlist[i]; i++)
+ {
+ if (!strncmp (optlist[i], arg, arglen))
+ {
+ if (strlen (optlist[i]) == arglen)
+ /* Exact match found. */
+ return i;
+ else if (matchind == -1)
+ /* First nonexact match found. */
+ matchind = i;
+ else
+ /* Subsequent nonexact match found. */
+ matchind = -2;
+ }
+ }
+ return matchind;
+}
+
+/* Error reporting for argmatch.
+ KIND is a description of the type of entity that was being matched.
+ VALUE is the invalid value that was given.
+ PROBLEM is the return value from argmatch. */
+
+void
+invalid_arg (kind, value, problem)
+ char const *kind;
+ char const *value;
+ int problem;
+{
+ fprintf (stderr, "%s: ", program_name);
+ if (problem == -1)
+ fprintf (stderr, "invalid");
+ else /* Assume -2. */
+ fprintf (stderr, "ambiguous");
+ fprintf (stderr, " %s `%s'\n", kind, value);
+}
diff --git a/argmatch.h b/argmatch.h
new file mode 100644
index 0000000..e95ff62
--- /dev/null
+++ b/argmatch.h
@@ -0,0 +1,12 @@
+/* argmatch.h -- declarations for matching arguments against option lists */
+
+#if defined __STDC__ || __GNUC__
+# define __ARGMATCH_P(args) args
+#else
+# define __ARGMATCH_P(args) ()
+#endif
+
+int argmatch __ARGMATCH_P ((const char *, const char * const *));
+void invalid_arg __ARGMATCH_P ((const char *, const char *, int));
+
+extern char const program_name[];
diff --git a/backupfile.c b/backupfile.c
index b58e674..266d392 100644
--- a/backupfile.c
+++ b/backupfile.c
@@ -1,5 +1,5 @@
/* backupfile.c -- make Emacs style backup file names
- Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1990,1991,1992,1993,1995,1997 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -12,57 +12,83 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program; see the file COPYING.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>.
Some algorithms adapted from GNU Emacs. */
-#include "config.h"
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <argmatch.h>
+#include <backupfile.h>
+
#include <stdio.h>
-#include <ctype.h>
#include <sys/types.h>
-#include "backupfile.h"
-#ifdef STDC_HEADERS
-#include <string.h>
-#include <stdlib.h>
+#if HAVE_STRING_H
+# include <string.h>
#else
-char *malloc ();
+# include <strings.h>
#endif
-#if defined (HAVE_UNISTD_H)
-#include <unistd.h>
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NLENGTH(direct) strlen ((direct)->d_name)
+#else
+# define dirent direct
+# define NLENGTH(direct) ((size_t) (direct)->d_namlen)
+# if HAVE_SYS_NDIR_H
+# include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+# include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+# include <ndir.h>
+# endif
#endif
-#if defined(DIRENT) || defined(_POSIX_VERSION)
-#include <dirent.h>
-#define NLENGTH(direct) (strlen((direct)->d_name))
-#else /* not (DIRENT or _POSIX_VERSION) */
-#define dirent direct
-#define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef SYSNDIR
-#include <sys/ndir.h>
-#endif /* SYSNDIR */
-#ifdef SYSDIR
-#include <sys/dir.h>
-#endif /* SYSDIR */
-#ifdef NDIR
-#include <ndir.h>
-#endif /* NDIR */
-#endif /* DIRENT or _POSIX_VERSION */
-
-#ifndef isascii
-#define ISDIGIT(c) (isdigit ((unsigned char) (c)))
+#if CLOSEDIR_VOID
+/* Fake a return value. */
+# define CLOSEDIR(d) (closedir (d), 0)
#else
-#define ISDIGIT(c) (isascii (c) && isdigit (c))
+# define CLOSEDIR(d) closedir (d)
#endif
-#if defined (_POSIX_VERSION)
+#if STDC_HEADERS
+# include <stdlib.h>
+#else
+char *malloc ();
+#endif
+
+#if HAVE_DIRENT_H || HAVE_NDIR_H || HAVE_SYS_DIR_H || HAVE_SYS_NDIR_H
+# define HAVE_DIR 1
+#else
+# define HAVE_DIR 0
+#endif
+
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifndef CHAR_BIT
+#define CHAR_BIT 8
+#endif
+/* Upper bound on the string length of an integer converted to string.
+ 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
+ add 1 for integer division truncation; add 1 more for a minus sign. */
+#define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
+
+#define ISDIGIT(c) (((unsigned) (c) - '0') <= 9)
+
+#ifdef _POSIX_VERSION
/* POSIX does not require that the d_ino field be present, and some
systems do not provide it. */
-#define REAL_DIR_ENTRY(dp) 1
+# define REAL_DIR_ENTRY(dp) 1
#else
-#define REAL_DIR_ENTRY(dp) ((dp)->d_ino != 0)
+# define REAL_DIR_ENTRY(dp) ((dp)->d_ino != 0)
#endif
/* Which type of backup file names are generated. */
@@ -70,31 +96,11 @@ enum backup_type backup_type = none;
/* The extension added to file names to produce a simple (as opposed
to numbered) backup file name. */
-char *simple_backup_suffix = "~";
-
-char *basename ();
-char *dirname ();
-static char *concat ();
-char *find_backup_file_name ();
-static char *make_version_name ();
-static int max_backup_version ();
-static int version_number ();
-
-/* Return NAME with any leading path stripped off. */
-
-char *
-basename (name)
- char *name;
-{
- char *r = name, *p = name;
+char const *simple_backup_suffix = ".orig";
- while (*p)
- if (*p++ == '/')
- r = p;
- return r;
-}
+static int max_backup_version __BACKUPFILE_P ((char const *, char const *));
+static int version_number __BACKUPFILE_P ((char const *, char const *, size_t));
-#ifndef NODIR
/* Return the name of the new backup file for file FILE,
allocated with malloc. Return 0 if out of memory.
FILE must not end with a '/' unless it is the root directory.
@@ -102,230 +108,112 @@ basename (name)
char *
find_backup_file_name (file)
- char *file;
+ char const *file;
{
- char *dir;
- char *base_versions;
- int highest_backup;
+ size_t backup_suffix_size_max;
+ char *s;
+
+ /* Allow room for simple or `.~N~' backups. */
+ backup_suffix_size_max = strlen (simple_backup_suffix) + 1;
+ if (HAVE_DIR && backup_suffix_size_max < INT_STRLEN_BOUND (int) + 4)
+ backup_suffix_size_max = INT_STRLEN_BOUND (int) + 4;
- if (backup_type == simple)
+ s = malloc (strlen (file) + backup_suffix_size_max);
+ if (s)
{
- char *s = malloc (strlen (file) + strlen (simple_backup_suffix) + 1);
strcpy (s, file);
+
+#if HAVE_DIR
+ if (backup_type != simple)
+ {
+ int highest_backup;
+ size_t dir_len = base_name (s) - s;
+
+ strcpy (s + dir_len, ".");
+ highest_backup = max_backup_version (file + dir_len, s);
+ if (! (backup_type == numbered_existing && highest_backup == 0))
+ {
+ sprintf (s, "%s.~%d~", file, highest_backup + 1);
+ return s;
+ }
+ strcpy (s, file);
+ }
+#endif /* HAVE_DIR */
+
addext (s, simple_backup_suffix, '~');
- return s;
}
- base_versions = concat (basename (file), ".~");
- if (base_versions == 0)
- return 0;
- dir = dirname (file);
- if (dir == 0)
- {
- free (base_versions);
- return 0;
- }
- highest_backup = max_backup_version (base_versions, dir);
- free (base_versions);
- free (dir);
- if (backup_type == numbered_existing && highest_backup == 0)
- return concat (file, simple_backup_suffix);
- return make_version_name (file, highest_backup + 1);
+ return s;
}
+#if HAVE_DIR
+
/* Return the number of the highest-numbered backup file for file
FILE in directory DIR. If there are no numbered backups
- of FILE in DIR, or an error occurs reading DIR, return 0.
- FILE should already have ".~" appended to it. */
+ of FILE in DIR, or an error occurs reading DIR, return 0. */
static int
max_backup_version (file, dir)
- char *file, *dir;
+ char const *file, *dir;
{
DIR *dirp;
struct dirent *dp;
int highest_version;
int this_version;
- int file_name_length;
-
+ size_t file_name_length;
+
dirp = opendir (dir);
if (!dirp)
return 0;
-
+
highest_version = 0;
file_name_length = strlen (file);
while ((dp = readdir (dirp)) != 0)
{
- if (!REAL_DIR_ENTRY (dp) || NLENGTH (dp) <= file_name_length)
+ if (!REAL_DIR_ENTRY (dp) || NLENGTH (dp) < file_name_length + 4)
continue;
-
+
this_version = version_number (file, dp->d_name, file_name_length);
if (this_version > highest_version)
highest_version = this_version;
}
- closedir (dirp);
- return highest_version;
-}
-
-/* Return a string, allocated with malloc, containing
- "FILE.~VERSION~". Return 0 if out of memory. */
-
-static char *
-make_version_name (file, version)
- char *file;
- int version;
-{
- char *backup_name;
-
- backup_name = malloc (strlen (file) + 16);
- if (backup_name == 0)
+ if (CLOSEDIR (dirp) != 0)
return 0;
- sprintf (backup_name, "%s.~%d~", file, version);
- return backup_name;
+ return highest_version;
}
/* If BACKUP is a numbered backup of BASE, return its version number;
- otherwise return 0. BASE_LENGTH is the length of BASE.
- BASE should already have ".~" appended to it. */
+ otherwise return 0. BASE_LENGTH is the length of BASE. */
static int
version_number (base, backup, base_length)
- char *base;
- char *backup;
- int base_length;
+ char const *base;
+ char const *backup;
+ size_t base_length;
{
int version;
- char *p;
-
+ char const *p;
+
version = 0;
- if (!strncmp (base, backup, base_length) && ISDIGIT (backup[base_length]))
+ if (strncmp (base, backup, base_length) == 0
+ && backup[base_length] == '.'
+ && backup[base_length + 1] == '~')
{
- for (p = &backup[base_length]; ISDIGIT (*p); ++p)
+ for (p = &backup[base_length + 2]; ISDIGIT (*p); ++p)
version = version * 10 + *p - '0';
if (p[0] != '~' || p[1])
version = 0;
}
return version;
}
+#endif /* HAVE_DIR */
-/* Return the newly-allocated concatenation of STR1 and STR2.
- If out of memory, return 0. */
-
-static char *
-concat (str1, str2)
- char *str1, *str2;
-{
- char *newstr;
- char str1_length = strlen (str1);
-
- newstr = malloc (str1_length + strlen (str2) + 1);
- if (newstr == 0)
- return 0;
- strcpy (newstr, str1);
- strcpy (newstr + str1_length, str2);
- return newstr;
-}
-
-/* Return the leading directories part of PATH,
- allocated with malloc. If out of memory, return 0.
- Assumes that trailing slashes have already been
- removed. */
-
-char *
-dirname (path)
- char *path;
-{
- char *newpath;
- char *slash;
- int length; /* Length of result, not including NUL. */
-
- slash = basename (path);
- if (slash == path)
- {
- /* File is in the current directory. */
- path = ".";
- length = 1;
- }
- else
- {
- /* Remove any trailing slashes from result. */
- while (*--slash == '/' && slash > path)
- ;
-
- length = slash - path + 1;
- }
- newpath = malloc (length + 1);
- if (newpath == 0)
- return 0;
- strncpy (newpath, path, length);
- newpath[length] = 0;
- return newpath;
-}
-
-/* If ARG is an unambiguous match for an element of the
- null-terminated array OPTLIST, return the index in OPTLIST
- of the matched element, else -1 if it does not match any element
- or -2 if it is ambiguous (is a prefix of more than one element). */
-
-int
-argmatch (arg, optlist)
- char *arg;
- char **optlist;
-{
- int i; /* Temporary index in OPTLIST. */
- int arglen; /* Length of ARG. */
- int matchind = -1; /* Index of first nonexact match. */
- int ambiguous = 0; /* If nonzero, multiple nonexact match(es). */
-
- arglen = strlen (arg);
-
- /* Test all elements for either exact match or abbreviated matches. */
- for (i = 0; optlist[i]; i++)
- {
- if (!strncmp (optlist[i], arg, arglen))
- {
- if (strlen (optlist[i]) == arglen)
- /* Exact match found. */
- return i;
- else if (matchind == -1)
- /* First nonexact match found. */
- matchind = i;
- else
- /* Second nonexact match found. */
- ambiguous = 1;
- }
- }
- if (ambiguous)
- return -2;
- else
- return matchind;
-}
-
-/* Error reporting for argmatch.
- KIND is a description of the type of entity that was being matched.
- VALUE is the invalid value that was given.
- PROBLEM is the return value from argmatch. */
-
-void
-invalid_arg (kind, value, problem)
- char *kind;
- char *value;
- int problem;
-{
- fprintf (stderr, "patch: ");
- if (problem == -1)
- fprintf (stderr, "invalid");
- else /* Assume -2. */
- fprintf (stderr, "ambiguous");
- fprintf (stderr, " %s `%s'\n", kind, value);
-}
-
-static char *backup_args[] =
+static char const * const backup_args[] =
{
"never", "simple", "nil", "existing", "t", "numbered", 0
};
-static enum backup_type backup_types[] =
+static enum backup_type const backup_types[] =
{
simple, simple, numbered_existing, numbered_existing, numbered, numbered
};
@@ -335,68 +223,17 @@ static enum backup_type backup_types[] =
enum backup_type
get_version (version)
- char *version;
+ char const *version;
{
int i;
if (version == 0 || *version == 0)
return numbered_existing;
i = argmatch (version, backup_args);
- if (i >= 0)
- return backup_types[i];
- invalid_arg ("version control type", version, i);
- exit (1);
-}
-#endif /* NODIR */
-
-/* Append to FILENAME the extension EXT, unless the result would be too long,
- in which case just append the character E. */
-
-void
-addext (filename, ext, e)
- char *filename, *ext;
- int e;
-{
- char *s = basename (filename);
- int slen = strlen (s), extlen = strlen (ext);
- long slen_max = -1;
-
-#if HAVE_PATHCONF && defined (_PC_NAME_MAX)
-#ifndef _POSIX_NAME_MAX
-#define _POSIX_NAME_MAX 14
-#endif
- if (slen + extlen <= _POSIX_NAME_MAX)
- /* The file name is so short there's no need to call pathconf. */
- slen_max = _POSIX_NAME_MAX;
- else if (s == filename)
- slen_max = pathconf (".", _PC_NAME_MAX);
- else
- {
- char c = *s;
- *s = 0;
- slen_max = pathconf (filename, _PC_NAME_MAX);
- *s = c;
- }
-#endif
- if (slen_max == -1) {
-#if HAVE_LONG_FILE_NAMES
- slen_max = 255;
-#else
- slen_max = 14;
-#endif
- }
- if (slen + extlen <= slen_max)
- strcpy (s + slen, ext);
- else
+ if (i < 0)
{
- if (slen_max <= slen) {
- /* Try to preserve difference between .h .c etc. */
- if (slen == slen_max && s[slen - 2] == '.')
- s[slen - 2] = s[slen - 1];
-
- slen = slen_max - 1;
- }
- s[slen] = e;
- s[slen + 1] = 0;
+ invalid_arg ("version control type", version, i);
+ exit (2);
}
+ return backup_types[i];
}
diff --git a/backupfile.h b/backupfile.h
index dfd1fc4..dad1984 100644
--- a/backupfile.h
+++ b/backupfile.h
@@ -1,5 +1,5 @@
/* backupfile.h -- declarations for making Emacs style backup file names
- Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1991, 1992, 1997 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -12,8 +12,9 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program; see the file COPYING.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* When to make backup files. */
enum backup_type
@@ -33,14 +34,17 @@ enum backup_type
};
extern enum backup_type backup_type;
-extern char *simple_backup_suffix;
-
-#ifdef __STDC__
-char *find_backup_file_name (char *file);
-enum backup_type get_version (char *version);
-void addext (char *, char *, int);
-#else
-char *find_backup_file_name ();
-enum backup_type get_version ();
-void addext ();
+extern char const *simple_backup_suffix;
+
+#ifndef __BACKUPFILE_P
+# if defined __STDC__ || __GNUC__
+# define __BACKUPFILE_P(args) args
+# else
+# define __BACKUPFILE_P(args) ()
+# endif
#endif
+
+char *base_name __BACKUPFILE_P ((char const *));
+char *find_backup_file_name __BACKUPFILE_P ((char const *));
+enum backup_type get_version __BACKUPFILE_P ((char const *));
+void addext __BACKUPFILE_P ((char *, char const *, int));
diff --git a/basename.c b/basename.c
new file mode 100644
index 0000000..1cc7854
--- /dev/null
+++ b/basename.c
@@ -0,0 +1,24 @@
+/* basename.c -- return the last element in a path */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <backupfile.h>
+
+/* In general, we can't use the builtin `basename' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `basename' modifies its argument. */
+
+char *
+base_name (name)
+ char const *name;
+{
+ char const *base = name;
+
+ while (*name)
+ if (*name++ == '/')
+ base = name;
+
+ return (char *) base;
+}
diff --git a/common.h b/common.h
index d1906fd..4b67425 100644
--- a/common.h
+++ b/common.h
@@ -1,50 +1,105 @@
-/* $Header: common.h,v 2.0.1.2 88/06/22 20:44:53 lwall Locked $
- *
- * $Log: common.h,v $
- * Revision 2.0.1.2 88/06/22 20:44:53 lwall
- * patch12: sprintf was declared wrong
- *
- * Revision 2.0.1.1 88/06/03 15:01:56 lwall
- * patch10: support for shorter extensions.
- *
- * Revision 2.0 86/09/17 15:36:39 lwall
- * Baseline for netwide release.
- *
- */
-
-#define DEBUGGING
-
-#define VOIDUSED 7
-#include "config.h"
-
-/* shut lint up about the following when return value ignored */
-
-#define Signal (void)signal
-#define Unlink (void)unlink
-#define Lseek (void)lseek
-#define Fseek (void)fseek
-#define Fstat (void)fstat
-#define Pclose (void)pclose
-#define Close (void)close
-#define Fclose (void)fclose
-#define Fflush (void)fflush
-#define Sprintf (void)sprintf
-#define Mktemp (void)mktemp
-#define Strcpy (void)strcpy
-#define Strcat (void)strcat
-
-/* NeXT declares malloc and realloc incompatibly from us in some of
- these files. Temporarily redefine them to prevent errors. */
-#define malloc system_malloc
-#define realloc system_realloc
-#include <stdio.h>
+/* common definitions for `patch' */
+
+/* $Id: common.h,v 1.10 1997/04/10 05:09:53 eggert Exp $ */
+
+/*
+Copyright 1986, 1988 Larry Wall
+Copyright 1990, 1991, 1992, 1993, 1997 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef DEBUGGING
+#define DEBUGGING 1
+#endif
+
+/* We must define `volatile' and `const' first (the latter inside config.h),
+ so that they're used consistently in all system includes. */
+#ifndef __STDC__
+# ifndef volatile
+# define volatile
+# endif
+#endif
+#include <config.h>
+
#include <assert.h>
+#include <stdio.h>
#include <sys/types.h>
+
#include <sys/stat.h>
+#if ! defined S_ISDIR && defined S_IFDIR
+# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#endif
+#if ! defined S_ISREG && defined S_IFREG
+# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#endif
+#ifndef S_IXOTH
+#define S_IXOTH 1
+#endif
+#ifndef S_IWOTH
+#define S_IWOTH 2
+#endif
+#ifndef S_IROTH
+#define S_IROTH 4
+#endif
+#ifndef S_IXGRP
+#define S_IXGRP (S_IXOTH << 3)
+#endif
+#ifndef S_IWGRP
+#define S_IWGRP (S_IWOTH << 3)
+#endif
+#ifndef S_IRGRP
+#define S_IRGRP (S_IROTH << 3)
+#endif
+#ifndef S_IXUSR
+#define S_IXUSR (S_IXOTH << 6)
+#endif
+#ifndef S_IWUSR
+#define S_IWUSR (S_IWOTH << 6)
+#endif
+#ifndef S_IRUSR
+#define S_IRUSR (S_IROTH << 6)
+#endif
+
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifndef INT_MAX
+#define INT_MAX 2147483647
+#endif
+
#include <ctype.h>
-#include <signal.h>
-#undef malloc
-#undef realloc
+/* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
+ as an argument to <ctype.h> macros like `isspace'. */
+#if STDC_HEADERS
+#define CTYPE_DOMAIN(c) 1
+#else
+#define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
+#endif
+#ifndef ISLOWER
+#define ISLOWER(c) (CTYPE_DOMAIN (c) && islower (c))
+#endif
+#ifndef ISSPACE
+#define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
+#endif
+
+#ifndef ISDIGIT
+#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
+#endif
+
/* constants */
@@ -55,136 +110,138 @@
#ifdef FALSE
#undef FALSE
#endif
-#define TRUE (1)
-#define FALSE (0)
-
-#define MAXHUNKSIZE 100000 /* is this enough lines? */
-#define INITHUNKMAX 125 /* initial dynamic allocation size */
-#define MAXLINELEN 1024
-#define BUFFERSIZE 1024
-
-#define SCCSPREFIX "s."
-#define GET "get %s"
-#define GET_LOCKED "get -e %s"
-#define SCCSDIFF "get -p %s | diff - %s >/dev/null"
-
-#define RCSSUFFIX ",v"
-#define CHECKOUT "co %s"
-#define CHECKOUT_LOCKED "co -l %s"
-#define RCSDIFF "rcsdiff %s > /dev/null"
+#define TRUE 1
+#define FALSE 0
/* handy definitions */
-#define Null(t) ((t)0)
-#define Nullch Null(char *)
-#define Nullfp Null(FILE *)
-#define Nulline Null(LINENUM)
-
-#define Ctl(ch) ((ch) & 037)
-
-#define strNE(s1,s2) (strcmp(s1, s2))
#define strEQ(s1,s2) (!strcmp(s1, s2))
-#define strnNE(s1,s2,l) (strncmp(s1, s2, l))
#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
/* typedefs */
-typedef char bool;
+typedef int bool; /* must promote to itself */
typedef long LINENUM; /* must be signed */
-typedef unsigned MEM; /* what to feed malloc */
/* globals */
-EXT int Argc; /* guess */
-EXT char **Argv;
-EXT int optind_last; /* for restarting plan_b */
+extern char const program_name[];
-EXT struct stat filestat; /* file statistics area */
-EXT int filemode INIT(0644);
+XTERN char *buf; /* general purpose buffer */
+XTERN size_t bufsize; /* allocated size of buf */
-EXT char buf[MAXLINELEN]; /* general purpose buffer */
-EXT FILE *ofp INIT(Nullfp); /* output file pointer */
-EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */
+XTERN bool using_plan_a; /* try to keep everything in memory */
-EXT int myuid; /* cache getuid return value */
+XTERN char *inname;
+XTERN int inerrno;
+XTERN struct stat instat;
+XTERN bool ok_to_create_file;
+XTERN bool dry_run;
-EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */
-EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */
+XTERN char const *origprae;
+XTERN char const *origbase;
-#define MAXFILEC 2
-EXT int filec INIT(0); /* how many file arguments? */
-EXT char *filearg[MAXFILEC];
-EXT bool ok_to_create_file INIT(FALSE);
-EXT char *bestguess INIT(Nullch); /* guess at correct filename */
+XTERN char const * volatile TMPOUTNAME;
+XTERN char const * volatile TMPINNAME;
+XTERN char const * volatile TMPPATNAME;
-EXT char *outname INIT(Nullch);
-EXT char rejname[128];
+#ifdef DEBUGGING
+XTERN int debug;
+#else
+# define debug 0
+#endif
+XTERN bool force;
+XTERN bool batch;
+XTERN bool reverse;
+XTERN enum { DEFAULT_VERBOSITY, SILENT, VERBOSE } verbosity;
+XTERN bool skip_rest_of_patch;
+XTERN int strippath;
+XTERN bool canonicalize;
+
+enum diff
+ {
+ NO_DIFF,
+ CONTEXT_DIFF,
+ NORMAL_DIFF,
+ ED_DIFF,
+ NEW_CONTEXT_DIFF,
+ UNI_DIFF
+ };
+
+XTERN enum diff diff_type;
+
+XTERN char *revision; /* prerequisite revision, if any */
+
+#ifdef __STDC__
+# define VOID void
+#else
+# define VOID char
+#endif
-EXT char *origprae INIT(Nullch);
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
+# define __attribute__(x)
+#endif
-EXT char *TMPOUTNAME;
-EXT char *TMPINNAME;
-EXT char *TMPREJNAME;
-EXT char *TMPPATNAME;
-EXT bool toutkeep INIT(FALSE);
-EXT bool trejkeep INIT(FALSE);
+#ifndef PARAMS
+# ifdef __STDC__
+# define PARAMS(args) args
+# else
+# define PARAMS(args) ()
+# endif
+#endif
-EXT LINENUM last_offset INIT(0);
-#ifdef DEBUGGING
-EXT int debug INIT(0);
-#endif
-EXT LINENUM maxfuzz INIT(2);
-EXT bool force INIT(FALSE);
-EXT bool batch INIT(FALSE);
-EXT bool verbose INIT(TRUE);
-EXT bool reverse INIT(FALSE);
-EXT bool noreverse INIT(FALSE);
-EXT bool skip_rest_of_patch INIT(FALSE);
-EXT int strippath INIT(957);
-EXT bool canonicalize INIT(FALSE);
-
-#define CONTEXT_DIFF 1
-#define NORMAL_DIFF 2
-#define ED_DIFF 3
-#define NEW_CONTEXT_DIFF 4
-#define UNI_DIFF 5
-EXT int diff_type INIT(0);
-
-EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */
-EXT char if_defined[128]; /* #ifdef xyzzy */
-EXT char not_defined[128]; /* #ifndef xyzzy */
-EXT char else_defined[] INIT("#else\n");/* #else */
-EXT char end_defined[128]; /* #endif xyzzy */
-
-EXT char *revision INIT(Nullch); /* prerequisite revision, if any */
+VOID *xmalloc PARAMS ((size_t));
+void fatal_exit PARAMS ((int)) __attribute__ ((noreturn));
#include <errno.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#include <string.h>
-#else
+#if !STDC_HEADERS && !defined errno
extern int errno;
-FILE *popen();
-char *malloc();
-char *realloc();
-long atol();
-char *getenv();
-char *strcpy();
-char *strcat();
-#endif
-char *mktemp();
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+#endif
+
+#if STDC_HEADERS || HAVE_STRING_H
+# include <string.h>
#else
-long lseek();
+# if !HAVE_MEMCHR
+# define memcmp(s1, s2, n) bcmp (s1, s2, n)
+# define memcpy(d, s, n) bcopy (s, d, n)
+VOID *memchr ();
+# endif
#endif
-#if defined(_POSIX_VERSION) || defined(HAVE_FCNTL_H)
-#include <fcntl.h>
+
+#if STDC_HEADERS
+# include <stdlib.h>
+#else
+long atol ();
+char *getenv ();
+VOID *malloc ();
+VOID *realloc ();
#endif
-#if !defined(S_ISDIR) && defined(S_IFDIR)
-#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifndef lseek
+off_t lseek ();
+#endif
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+
+#if HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#ifndef O_RDONLY
+#define O_RDONLY 0
#endif
-#if !defined(S_ISREG) && defined(S_IFREG)
-#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#ifndef O_RDWR
+#define O_RDWR 2
#endif
diff --git a/config.h.in b/config.h.in
deleted file mode 100644
index 41761aa..0000000
--- a/config.h.in
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Portability variables. -*- C -*- */
-
-/* Define if the system does not support the `const' keyword. */
-#undef const
-
-/* Define if the system supports file names longer than 14 characters. */
-#undef HAVE_LONG_FILE_NAMES
-
-/* Define if the system has pathconf(). */
-#undef HAVE_PATHCONF
-
-/* Define if the system has strerror(). */
-#undef HAVE_STRERROR
-
-/* Define if the system has ANSI C header files and library functions. */
-#undef STDC_HEADERS
-
-/* Define if the system uses strchr instead of index
- and strrchr instead of rindex. */
-#undef HAVE_STRING_H
-
-#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
-#define index strchr
-#define rindex strrchr
-#endif
-
-/* Define if the system has unistd.h. */
-#undef HAVE_UNISTD_H
-
-/* Define if the system has fcntl.h. */
-#undef HAVE_FCNTL_H
-
-/* Define as either int or void -- the type that signal handlers return. */
-#undef RETSIGTYPE
-
-#ifndef RETSIGTYPE
-#define RETSIGTYPE void
-#endif
-
-/* Which directory library header to use. */
-#undef DIRENT /* dirent.h */
-#undef SYSNDIR /* sys/ndir.h */
-#undef SYSDIR /* sys/dir.h */
-#undef NDIR /* ndir.h */
-#undef NODIR /* none -- don't make numbered backup files */
-
-/* Define if the system lets you pass fewer arguments to a function
- than the function actually accepts (in the absence of a prototype).
- Defining it makes I/O calls slightly more efficient.
- You need not bother defining it unless your C preprocessor chokes on
- multi-line arguments to macros. */
-#undef CANVARARG
-
-/* Define Reg* as either `register' or nothing, depending on whether
- the C compiler pays attention to this many register declarations.
- The intent is that you don't have to order your register declarations
- in the order of importance, so you can freely declare register variables
- in sub-blocks of code and as function parameters.
- Do not use Reg<n> more than once per routine.
-
- These don't really matter a lot, since most modern C compilers ignore
- register declarations and often do a better job of allocating
- registers than people do. */
-
-#define Reg1 register
-#define Reg2 register
-#define Reg3 register
-#define Reg4 register
-#define Reg5 register
-#define Reg6 register
-#define Reg7
-#define Reg8
-#define Reg9
-#define Reg10
-#define Reg11
-#define Reg12
-#define Reg13
-#define Reg14
-#define Reg15
-#define Reg16
diff --git a/config.hin b/config.hin
new file mode 100644
index 0000000..83c7fc5
--- /dev/null
+++ b/config.hin
@@ -0,0 +1,108 @@
+/* config.hin. Generated automatically from configure.in by autoheader. */
+
+/* Define if on AIX 3.
+ System headers sometimes define this.
+ We just want to avoid a redefinition error message. */
+#ifndef _ALL_SOURCE
+#undef _ALL_SOURCE
+#endif
+
+/* Define if the closedir function returns void instead of int. */
+#undef CLOSEDIR_VOID
+
+/* Define to empty if the keyword does not work. */
+#undef const
+
+/* Define if you don't have vprintf but do have _doprnt. */
+#undef HAVE_DOPRNT
+
+/* Define if you support file names longer than 14 characters. */
+#undef HAVE_LONG_FILE_NAMES
+
+/* Define if you have the vprintf function. */
+#undef HAVE_VPRINTF
+
+/* Define if on MINIX. */
+#undef _MINIX
+
+/* Define to `long' if <sys/types.h> doesn't define. */
+#undef off_t
+
+/* Define if the system does not provide POSIX.1 features except
+ with this defined. */
+#undef _POSIX_1_SOURCE
+
+/* Define if you need to in order for stat and other things to work. */
+#undef _POSIX_SOURCE
+
+/* Define as the return type of signal handlers (int or void). */
+#undef RETSIGTYPE
+
+/* Define to `unsigned' if <sys/types.h> doesn't define. */
+#undef size_t
+
+/* Define if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define if memchr works. */
+#undef HAVE_MEMCHR
+
+/* Define if you have the _doprintf function. */
+#undef HAVE__DOPRINTF
+
+/* Define if you have the isascii function. */
+#undef HAVE_ISASCII
+
+/* Define if you have the memchr function. */
+#undef HAVE_MEMCHR
+
+/* Define if you have the memcmp function. */
+#undef HAVE_MEMCMP
+
+/* Define if you have the mkdir function. */
+#undef HAVE_MKDIR
+
+/* Define if you have the mktemp function. */
+#undef HAVE_MKTEMP
+
+/* Define if you have the pathconf function. */
+#undef HAVE_PATHCONF
+
+/* Define if you have the rename function. */
+#undef HAVE_RENAME
+
+/* Define if you have the sigaction function. */
+#undef HAVE_SIGACTION
+
+/* Define if you have the sigprocmask function. */
+#undef HAVE_SIGPROCMASK
+
+/* Define if you have the sigsetmask function. */
+#undef HAVE_SIGSETMASK
+
+/* Define if you have the <dirent.h> header file. */
+#undef HAVE_DIRENT_H
+
+/* Define if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
+/* Define if you have the <ndir.h> header file. */
+#undef HAVE_NDIR_H
+
+/* Define if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define if you have the <sys/dir.h> header file. */
+#undef HAVE_SYS_DIR_H
+
+/* Define if you have the <sys/ndir.h> header file. */
+#undef HAVE_SYS_NDIR_H
+
+/* Define if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define if you have the <varargs.h> header file. */
+#undef HAVE_VARARGS_H
diff --git a/configure b/configure
index 3fb5ed6..c234335 100755
--- a/configure
+++ b/configure
@@ -1,271 +1,1038 @@
-#!/bin/sh
-# Guess values for system-dependent variables and create Makefiles.
-# Generated automatically using autoconf.
-# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
+#! /bin/sh
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
+# Guess values for system-dependent variables and create Makefiles.
+# Generated automatically using autoconf version 2.12
+# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+
+# Defaults:
+ac_help=
+ac_default_prefix=/usr/local
+# Any additions from configure.in:
+
+# Initialize some variables set by options.
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+build=NONE
+cache_file=./config.cache
+exec_prefix=NONE
+host=NONE
+no_create=
+nonopt=NONE
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+target=NONE
+verbose=
+x_includes=NONE
+x_libraries=NONE
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+# Initialize some other variables.
+subdirs=
+MFLAGS= MAKEFLAGS=
+# Maximum number of lines to put in a shell here document.
+ac_max_here_lines=12
+
+ac_prev=
+for ac_option
+do
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval "$ac_prev=\$ac_option"
+ ac_prev=
+ continue
+ fi
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ case "$ac_option" in
+ -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) ac_optarg= ;;
+ esac
-# Usage: configure [--srcdir=DIR] [--host=HOST] [--gas] [--nfp] [--no-create]
-# [--prefix=PREFIX] [--exec-prefix=PREFIX] [--with-PACKAGE] [TARGET]
-# Ignores all args except --srcdir, --prefix, --exec-prefix, --no-create, and
-# --with-PACKAGE unless this script has special code to handle it.
+ # Accept the important Cygnus configure options, so we can diagnose typos.
+
+ case "$ac_option" in
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir="$ac_optarg" ;;
+
+ -build | --build | --buil | --bui | --bu)
+ ac_prev=build ;;
+ -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+ build="$ac_optarg" ;;
+
+ -cache-file | --cache-file | --cache-fil | --cache-fi \
+ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+ ac_prev=cache_file ;;
+ -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+ cache_file="$ac_optarg" ;;
+
+ -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+ | --da=*)
+ datadir="$ac_optarg" ;;
+
+ -disable-* | --disable-*)
+ ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+ fi
+ ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+ eval "enable_${ac_feature}=no" ;;
+
+ -enable-* | --enable-*)
+ ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
+ { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+ fi
+ ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+ case "$ac_option" in
+ *=*) ;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "enable_${ac_feature}='$ac_optarg'" ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix="$ac_optarg" ;;
+
+ -gas | --gas | --ga | --g)
+ # Obsolete; use --with-gas.
+ with_gas=yes ;;
+
+ -help | --help | --hel | --he)
+ # Omit some internal or obsolete options to make the list less imposing.
+ # This message is too long to be a string in the A/UX 3.1 sh.
+ cat << EOF
+Usage: configure [options] [host]
+Options: [defaults in brackets after descriptions]
+Configuration:
+ --cache-file=FILE cache test results in FILE
+ --help print this message
+ --no-create do not create output files
+ --quiet, --silent do not print \`checking...' messages
+ --version print the version of autoconf that created configure
+Directory and file names:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [$ac_default_prefix]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [same as prefix]
+ --bindir=DIR user executables in DIR [EPREFIX/bin]
+ --sbindir=DIR system admin executables in DIR [EPREFIX/sbin]
+ --libexecdir=DIR program executables in DIR [EPREFIX/libexec]
+ --datadir=DIR read-only architecture-independent data in DIR
+ [PREFIX/share]
+ --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data in DIR
+ [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var]
+ --libdir=DIR object code libraries in DIR [EPREFIX/lib]
+ --includedir=DIR C header files in DIR [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include]
+ --infodir=DIR info documentation in DIR [PREFIX/info]
+ --mandir=DIR man documentation in DIR [PREFIX/man]
+ --srcdir=DIR find the sources in DIR [configure dir or ..]
+ --program-prefix=PREFIX prepend PREFIX to installed program names
+ --program-suffix=SUFFIX append SUFFIX to installed program names
+ --program-transform-name=PROGRAM
+ run sed PROGRAM on installed program names
+EOF
+ cat << EOF
+Host type:
+ --build=BUILD configure for building on BUILD [BUILD=HOST]
+ --host=HOST configure for HOST [guessed]
+ --target=TARGET configure for TARGET [TARGET=HOST]
+Features and packages:
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --x-includes=DIR X include files are in DIR
+ --x-libraries=DIR X library files are in DIR
+EOF
+ if test -n "$ac_help"; then
+ echo "--enable and --with options recognized:$ac_help"
+ fi
+ exit 0 ;;
+
+ -host | --host | --hos | --ho)
+ ac_prev=host ;;
+ -host=* | --host=* | --hos=* | --ho=*)
+ host="$ac_optarg" ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir="$ac_optarg" ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir="$ac_optarg" ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir="$ac_optarg" ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir="$ac_optarg" ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst \
+ | --locals | --local | --loca | --loc | --lo)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+ localstatedir="$ac_optarg" ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir="$ac_optarg" ;;
+
+ -nfp | --nfp | --nf)
+ # Obsolete; use --without-fp.
+ with_fp=no ;;
+
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c)
+ no_create=yes ;;
+
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+ no_recursion=yes ;;
+
+ -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+ | --oldin | --oldi | --old | --ol | --o)
+ ac_prev=oldincludedir ;;
+ -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+ oldincludedir="$ac_optarg" ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix="$ac_optarg" ;;
+
+ -program-prefix | --program-prefix | --program-prefi | --program-pref \
+ | --program-pre | --program-pr | --program-p)
+ ac_prev=program_prefix ;;
+ -program-prefix=* | --program-prefix=* | --program-prefi=* \
+ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+ program_prefix="$ac_optarg" ;;
+
+ -program-suffix | --program-suffix | --program-suffi | --program-suff \
+ | --program-suf | --program-su | --program-s)
+ ac_prev=program_suffix ;;
+ -program-suffix=* | --program-suffix=* | --program-suffi=* \
+ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+ program_suffix="$ac_optarg" ;;
+
+ -program-transform-name | --program-transform-name \
+ | --program-transform-nam | --program-transform-na \
+ | --program-transform-n | --program-transform- \
+ | --program-transform | --program-transfor \
+ | --program-transfo | --program-transf \
+ | --program-trans | --program-tran \
+ | --progr-tra | --program-tr | --program-t)
+ ac_prev=program_transform_name ;;
+ -program-transform-name=* | --program-transform-name=* \
+ | --program-transform-nam=* | --program-transform-na=* \
+ | --program-transform-n=* | --program-transform-=* \
+ | --program-transform=* | --program-transfor=* \
+ | --program-transfo=* | --program-transf=* \
+ | --program-trans=* | --program-tran=* \
+ | --progr-tra=* | --program-tr=* | --program-t=*)
+ program_transform_name="$ac_optarg" ;;
+
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ silent=yes ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir="$ac_optarg" ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir="$ac_optarg" ;;
+
+ -site | --site | --sit)
+ ac_prev=site ;;
+ -site=* | --site=* | --sit=*)
+ site="$ac_optarg" ;;
+
+ -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+ ac_prev=srcdir ;;
+ -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+ srcdir="$ac_optarg" ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir="$ac_optarg" ;;
+
+ -target | --target | --targe | --targ | --tar | --ta | --t)
+ ac_prev=target ;;
+ -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+ target="$ac_optarg" ;;
+
+ -v | -verbose | --verbose | --verbos | --verbo | --verb)
+ verbose=yes ;;
+
+ -version | --version | --versio | --versi | --vers)
+ echo "configure generated by autoconf version 2.12"
+ exit 0 ;;
+
+ -with-* | --with-*)
+ ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
+ { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+ fi
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ case "$ac_option" in
+ *=*) ;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "with_${ac_package}='$ac_optarg'" ;;
+ -without-* | --without-*)
+ ac_package=`echo $ac_option|sed -e 's/-*without-//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+ fi
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ eval "with_${ac_package}=no" ;;
+
+ --x)
+ # Obsolete; use --with-x.
+ with_x=yes ;;
+
+ -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+ | --x-incl | --x-inc | --x-in | --x-i)
+ ac_prev=x_includes ;;
+ -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+ x_includes="$ac_optarg" ;;
+
+ -x-libraries | --x-libraries | --x-librarie | --x-librari \
+ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+ ac_prev=x_libraries ;;
+ -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+ x_libraries="$ac_optarg" ;;
+
+ -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
+ ;;
+
+ *)
+ if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
+ echo "configure: warning: $ac_option: invalid host type" 1>&2
+ fi
+ if test "x$nonopt" != xNONE; then
+ { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
+ fi
+ nonopt="$ac_option"
+ ;;
-for arg
-do
- # Handle --exec-prefix with a space before the argument.
- if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix=
- # Handle --host with a space before the argument.
- elif test x$next_host = xyes; then next_host=
- # Handle --prefix with a space before the argument.
- elif test x$next_prefix = xyes; then prefix=$arg; next_prefix=
- # Handle --srcdir with a space before the argument.
- elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
- else
- case $arg in
- # For backward compatibility, also recognize exact --exec_prefix.
- -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*)
- exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
- -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e)
- next_exec_prefix=yes ;;
-
- -gas | --gas | --ga | --g) ;;
-
- -host=* | --host=* | --hos=* | --ho=* | --h=*) ;;
- -host | --host | --hos | --ho | --h)
- next_host=yes ;;
-
- -nfp | --nfp | --nf) ;;
-
- -no-create | --no-create | --no-creat | --no-crea | --no-cre | --no-cr | --no-c | --no- | --no)
- no_create=1 ;;
-
- -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
- prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
- -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
- next_prefix=yes ;;
-
- -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*)
- srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
- -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s)
- next_srcdir=yes ;;
-
- -with-* | --with-*)
- package=`echo $arg|sed 's/-*with-//'`
- # Delete all the valid chars; see if any are left.
- if test -n "`echo $package|sed 's/[-a-zA-Z0-9_]*//g'`"; then
- echo "configure: $package: invalid package name" >&2; exit 1
- fi
- eval "with_`echo $package|sed s/-/_/g`=1" ;;
-
- -v | -verbose | --verbose | --verbos | --verbo | --verb | --ver | --ve | --v)
- verbose=yes ;;
-
- *) ;;
- esac
- fi
+ esac
done
-trap 'rm -f conftest* core; exit 1' 1 3 15
+if test -n "$ac_prev"; then
+ { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
+fi
-# Needed for some versions of `tr' so that character classes in `[]' work.
-if test "${LANG+set}" = "set" ; then
- LANG=C
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+# File descriptor usage:
+# 0 standard input
+# 1 file creation
+# 2 errors and warnings
+# 3 some systems may open it to /dev/tty
+# 4 used on the Kubota Titan
+# 6 checking for... messages and results
+# 5 compiler messages saved in config.log
+if test "$silent" = yes; then
+ exec 6>/dev/null
+else
+ exec 6>&1
fi
+exec 5>./config.log
-rm -f conftest*
-compile='${CC-cc} $CFLAGS $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1'
+echo "\
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+" 1>&5
+
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Also quote any args containing shell metacharacters.
+ac_configure_args=
+for ac_arg
+do
+ case "$ac_arg" in
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c) ;;
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
+ *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
+ ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+ *) ac_configure_args="$ac_configure_args $ac_arg" ;;
+ esac
+done
+
+# NLS nuisances.
+# Only set these to C if already set. These must not be set unconditionally
+# because not all systems understand e.g. LANG=C (notably SCO).
+# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
+# Non-C LC_CTYPE values break the ctype check.
+if test "${LANG+set}" = set; then LANG=C; export LANG; fi
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
+if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo > confdefs.h
# A filename unique to this package, relative to the directory that
# configure is in, which we can look for to find out if srcdir is correct.
-unique_file=patch.c
+ac_unique_file=patch.c
# Find the source files, if location was not specified.
if test -z "$srcdir"; then
- srcdirdefaulted=yes
- # Try the directory containing this script, then `..'.
- prog=$0
- confdir=`echo $prog|sed 's%/[^/][^/]*$%%'`
- test "X$confdir" = "X$prog" && confdir=.
- srcdir=$confdir
- if test ! -r $srcdir/$unique_file; then
+ ac_srcdir_defaulted=yes
+ # Try the directory containing this script, then its parent.
+ ac_prog=$0
+ ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
+ test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
+ srcdir=$ac_confdir
+ if test ! -r $srcdir/$ac_unique_file; then
srcdir=..
fi
+else
+ ac_srcdir_defaulted=no
fi
-if test ! -r $srcdir/$unique_file; then
- if test x$srcdirdefaulted = xyes; then
- echo "configure: Can not find sources in \`${confdir}' or \`..'." 1>&2
+if test ! -r $srcdir/$ac_unique_file; then
+ if test "$ac_srcdir_defaulted" = yes; then
+ { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
else
- echo "configure: Can not find sources in \`${srcdir}'." 1>&2
+ { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
fi
- exit 1
fi
-# Preserve a srcdir of `.' to avoid automounter screwups with pwd.
-# But we can't avoid them for `..', to make subdirectories work.
-case $srcdir in
- .|/*|~*) ;;
- *) srcdir=`cd $srcdir; pwd` ;; # Make relative path absolute.
-esac
+srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
-# Save the original args to write them into config.status later.
-configure_args="$*"
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+ if test "x$prefix" != xNONE; then
+ CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+ else
+ CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+ fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+ if test -r "$ac_site_file"; then
+ echo "loading site script $ac_site_file"
+ . "$ac_site_file"
+ fi
+done
+
+if test -r "$cache_file"; then
+ echo "loading cache $cache_file"
+ . $cache_file
+else
+ echo "creating cache $cache_file"
+ > $cache_file
+fi
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
+ # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
+ if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
+ ac_n= ac_c='
+' ac_t=' '
+ else
+ ac_n=-n ac_c= ac_t=
+ fi
+else
+ ac_n= ac_c='\c' ac_t=
+fi
+
+
+
+if test "$program_transform_name" = s,x,x,; then
+ program_transform_name=
+else
+ # Double any \ or $. echo might interpret backslashes.
+ cat <<\EOF_SED > conftestsed
+s,\\,\\\\,g; s,\$,$$,g
+EOF_SED
+ program_transform_name="`echo $program_transform_name|sed -f conftestsed`"
+ rm -f conftestsed
+fi
+test "$program_prefix" != NONE &&
+ program_transform_name="s,^,${program_prefix},; $program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+ program_transform_name="s,\$\$,${program_suffix},; $program_transform_name"
+
+# sed with no file args requires a program.
+test "$program_transform_name" = "" && program_transform_name="s,x,x,"
+PACKAGE=patch
+VERSION=2.2
+
+
+
+# Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:551: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_CC="gcc"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
if test -z "$CC"; then
- # Extract the first word of `gcc', so it can be a program name with args.
- set dummy gcc; word=$2
- echo checking for $word
- IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:"
- for dir in $PATH; do
- test -z "$dir" && dir=.
- if test -f $dir/$word; then
- CC="gcc"
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:580: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ ac_prog_rejected=no
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
+ ac_prog_rejected=yes
+ continue
+ fi
+ ac_cv_prog_CC="cc"
break
fi
done
- IFS="$saveifs"
+ IFS="$ac_save_ifs"
+if test $ac_prog_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $ac_cv_prog_CC
+ shift
+ if test $# -gt 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same basename, so the bogon will be chosen
+ # first if we set CC to just the basename; use the full file name.
+ shift
+ set dummy "$ac_dir/$ac_word" "$@"
+ shift
+ ac_cv_prog_CC="$@"
+ fi
+fi
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
fi
-test -z "$CC" && CC="cc"
-test -n "$CC" -a -n "$verbose" && echo " setting CC to $CC"
-# Find out if we are using GNU C, under whatever name.
-cat > conftest.c <<EOF
+ test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
+fi
+
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
+echo "configure:628: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+cat > conftest.$ac_ext <<EOF
+#line 638 "configure"
+#include "confdefs.h"
+main(){return(0);}
+EOF
+if { (eval echo configure:642: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ ac_cv_prog_cc_works=yes
+ # If we can't run a trivial program, we are probably using a cross compiler.
+ if (./conftest; exit) 2>/dev/null; then
+ ac_cv_prog_cc_cross=no
+ else
+ ac_cv_prog_cc_cross=yes
+ fi
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ ac_cv_prog_cc_works=no
+fi
+rm -fr conftest*
+
+echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
+if test $ac_cv_prog_cc_works = no; then
+ { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
+fi
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
+echo "configure:662: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
+cross_compiling=$ac_cv_prog_cc_cross
+
+echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
+echo "configure:667: checking whether we are using GNU C" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.c <<EOF
#ifdef __GNUC__
- yes
+ yes;
#endif
EOF
-${CC-cc} -E conftest.c > conftest.out 2>&1
-if egrep yes conftest.out >/dev/null 2>&1; then
- GCC=1 # For later tests.
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:676: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+ ac_cv_prog_gcc=yes
+else
+ ac_cv_prog_gcc=no
+fi
+fi
+
+echo "$ac_t""$ac_cv_prog_gcc" 1>&6
+
+if test $ac_cv_prog_gcc = yes; then
+ GCC=yes
+ ac_test_CFLAGS="${CFLAGS+set}"
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS=
+ echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
+echo "configure:691: checking whether ${CC-cc} accepts -g" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ echo 'void f(){}' > conftest.c
+if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
+ ac_cv_prog_cc_g=yes
+else
+ ac_cv_prog_cc_g=no
fi
rm -f conftest*
-echo checking how to run the C preprocessor
+fi
+
+echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
+ if test "$ac_test_CFLAGS" = set; then
+ CFLAGS="$ac_save_CFLAGS"
+ elif test $ac_cv_prog_cc_g = yes; then
+ CFLAGS="-g -O2"
+ else
+ CFLAGS="-O2"
+ fi
+else
+ GCC=
+ test "${CFLAGS+set}" = set || CFLAGS="-g"
+fi
+
+echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
+echo "configure:719: checking how to run the C preprocessor" >&5
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+ CPP=
+fi
if test -z "$CPP"; then
- CPP='${CC-cc} -E'
- cat > conftest.c <<EOF
-#include <stdio.h>
+if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ # This must be in double quotes, not single quotes, because CPP may get
+ # substituted into the Makefile and "${CC-cc}" will confuse make.
+ CPP="${CC-cc} -E"
+ # On the NeXT, cc -E runs the code through the compiler's parser,
+ # not just through cpp.
+ cat > conftest.$ac_ext <<EOF
+#line 734 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:740: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ :
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ CPP="${CC-cc} -E -traditional-cpp"
+ cat > conftest.$ac_ext <<EOF
+#line 751 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
EOF
-err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
-if test -z "$err"; then
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:757: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
:
else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
CPP=/lib/cpp
fi
rm -f conftest*
fi
+rm -f conftest*
+ ac_cv_prog_CPP="$CPP"
+fi
+ CPP="$ac_cv_prog_CPP"
+else
+ ac_cv_prog_CPP="$CPP"
+fi
+echo "$ac_t""$CPP" 1>&6
+
+ac_aux_dir=
+for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+ if test -f $ac_dir/install-sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install-sh -c"
+ break
+ elif test -f $ac_dir/install.sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install.sh -c"
+ break
+ fi
+done
+if test -z "$ac_aux_dir"; then
+ { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; }
+fi
+ac_config_guess=$ac_aux_dir/config.guess
+ac_config_sub=$ac_aux_dir/config.sub
+ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
+
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# ./install, which can be erroneously created by make from ./install.sh.
+echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
+echo "configure:809: checking for a BSD compatible install" >&5
+if test -z "$INSTALL"; then
+if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ # Account for people who put trailing slashes in PATH elements.
+ case "$ac_dir/" in
+ /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ for ac_prog in ginstall installbsd scoinst install; do
+ if test -f $ac_dir/$ac_prog; then
+ if test $ac_prog = install &&
+ grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ # OSF/1 installbsd also uses dspmsg, but is usable.
+ :
+ else
+ ac_cv_path_install="$ac_dir/$ac_prog -c"
+ break 2
+ fi
+ fi
+ done
+ ;;
+ esac
+ done
+ IFS="$ac_save_IFS"
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL="$ac_cv_path_install"
+ else
+ # As a last resort, use the slow shell script. We don't cache a
+ # path for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the path is relative.
+ INSTALL="$ac_install_sh"
+ fi
+fi
+echo "$ac_t""$INSTALL" 1>&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
+echo "configure:859: checking whether ${MAKE-make} sets \${MAKE}" >&5
+set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftestmake <<\EOF
+all:
+ @echo 'ac_maketemp="${MAKE}"'
+EOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=`
+if test -n "$ac_maketemp"; then
+ eval ac_cv_prog_make_${ac_make}_set=yes
+else
+ eval ac_cv_prog_make_${ac_make}_set=no
+fi
+rm -f conftestmake
+fi
+if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ SET_MAKE=
+else
+ echo "$ac_t""no" 1>&6
+ SET_MAKE="MAKE=${MAKE-make}"
+fi
-echo checking for AIX
-cat > conftest.c <<EOF
+# Extract the first word of "ed", so it can be a program name with args.
+set dummy ed; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:888: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_path_ED_PROGRAM'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ case "$ED_PROGRAM" in
+ /*)
+ ac_cv_path_ED_PROGRAM="$ED_PROGRAM" # Let the user override the test with a path.
+ ;;
+ *)
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+ for ac_dir in $PATH; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_path_ED_PROGRAM="$ac_dir/$ac_word"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+ test -z "$ac_cv_path_ED_PROGRAM" && ac_cv_path_ED_PROGRAM="ed"
+ ;;
+esac
+fi
+ED_PROGRAM="$ac_cv_path_ED_PROGRAM"
+if test -n "$ED_PROGRAM"; then
+ echo "$ac_t""$ED_PROGRAM" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+
+echo $ac_n "checking for AIX""... $ac_c" 1>&6
+echo "configure:919: checking for AIX" >&5
+cat > conftest.$ac_ext <<EOF
+#line 921 "configure"
+#include "confdefs.h"
#ifdef _AIX
yes
#endif
EOF
-eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
-if egrep "yes" conftest.out >/dev/null 2>&1; then
- {
-test -n "$verbose" && \
-echo ' defining' _ALL_SOURCE
-DEFS="$DEFS -D_ALL_SOURCE=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}_ALL_SOURCE\${SEDdB}_ALL_SOURCE\${SEDdC}1\${SEDdD}
-\${SEDuA}_ALL_SOURCE\${SEDuB}_ALL_SOURCE\${SEDuC}1\${SEDuD}
-\${SEDeA}_ALL_SOURCE\${SEDeB}_ALL_SOURCE\${SEDeC}1\${SEDeD}
-"
-}
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "yes" >/dev/null 2>&1; then
+ rm -rf conftest*
+ echo "$ac_t""yes" 1>&6; cat >> confdefs.h <<\EOF
+#define _ALL_SOURCE 1
+EOF
+else
+ rm -rf conftest*
+ echo "$ac_t""no" 1>&6
fi
rm -f conftest*
-echo checking for minix/config.h
-cat > conftest.c <<EOF
+ac_safe=`echo "minix/config.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for minix/config.h""... $ac_c" 1>&6
+echo "configure:944: checking for minix/config.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 949 "configure"
+#include "confdefs.h"
#include <minix/config.h>
EOF
-err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
-if test -z "$err"; then
- MINIX=1
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:954: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
fi
rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ MINIX=yes
+else
+ echo "$ac_t""no" 1>&6
+MINIX=
+fi
-# The Minix shell can't assign to the same variable on the same line!
-if test -n "$MINIX"; then
- {
-test -n "$verbose" && \
-echo ' defining' _POSIX_SOURCE
-DEFS="$DEFS -D_POSIX_SOURCE=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}_POSIX_SOURCE\${SEDdB}_POSIX_SOURCE\${SEDdC}1\${SEDdD}
-\${SEDuA}_POSIX_SOURCE\${SEDuB}_POSIX_SOURCE\${SEDuC}1\${SEDuD}
-\${SEDeA}_POSIX_SOURCE\${SEDeB}_POSIX_SOURCE\${SEDeC}1\${SEDeD}
-"
-}
+if test "$MINIX" = yes; then
+ cat >> confdefs.h <<\EOF
+#define _POSIX_SOURCE 1
+EOF
- {
-test -n "$verbose" && \
-echo ' defining' _POSIX_1_SOURCE to be '2'
-DEFS="$DEFS -D_POSIX_1_SOURCE=2"
-SEDDEFS="${SEDDEFS}\${SEDdA}_POSIX_1_SOURCE\${SEDdB}_POSIX_1_SOURCE\${SEDdC}2\${SEDdD}
-\${SEDuA}_POSIX_1_SOURCE\${SEDuB}_POSIX_1_SOURCE\${SEDuC}2\${SEDuD}
-\${SEDeA}_POSIX_1_SOURCE\${SEDeB}_POSIX_1_SOURCE\${SEDeC}2\${SEDeD}
-"
-}
+ cat >> confdefs.h <<\EOF
+#define _POSIX_1_SOURCE 2
+EOF
- {
-test -n "$verbose" && \
-echo ' defining' _MINIX
-DEFS="$DEFS -D_MINIX=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}_MINIX\${SEDdB}_MINIX\${SEDdC}1\${SEDdD}
-\${SEDuA}_MINIX\${SEDuB}_MINIX\${SEDuC}1\${SEDuD}
-\${SEDeA}_MINIX\${SEDeB}_MINIX\${SEDeC}1\${SEDeD}
-"
-}
+ cat >> confdefs.h <<\EOF
+#define _MINIX 1
+EOF
fi
-echo checking for POSIXized ISC
+echo $ac_n "checking for POSIXized ISC""... $ac_c" 1>&6
+echo "configure:992: checking for POSIXized ISC" >&5
if test -d /etc/conf/kconfig.d &&
grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1
then
- ISC=1 # If later tests want to check for ISC.
- {
-test -n "$verbose" && \
-echo ' defining' _POSIX_SOURCE
-DEFS="$DEFS -D_POSIX_SOURCE=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}_POSIX_SOURCE\${SEDdB}_POSIX_SOURCE\${SEDdC}1\${SEDdD}
-\${SEDuA}_POSIX_SOURCE\${SEDuB}_POSIX_SOURCE\${SEDuC}1\${SEDuD}
-\${SEDeA}_POSIX_SOURCE\${SEDeB}_POSIX_SOURCE\${SEDeC}1\${SEDeD}
-"
-}
+ echo "$ac_t""yes" 1>&6
+ ISC=yes # If later tests want to check for ISC.
+ cat >> confdefs.h <<\EOF
+#define _POSIX_SOURCE 1
+EOF
- if test -n "$GCC"; then
+ if test "$GCC" = yes; then
CC="$CC -posix"
else
CC="$CC -Xp"
fi
+else
+ echo "$ac_t""no" 1>&6
+ ISC=
fi
-prog='/* Ultrix mips cc rejects this. */
+
+echo $ac_n "checking for working const""... $ac_c" 1>&6
+echo "configure:1014: checking for working const" >&5
+if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1019 "configure"
+#include "confdefs.h"
+
+int main() {
+
+/* Ultrix mips cc rejects this. */
typedef int charset[2]; const charset x;
/* SunOS 4.1.1 cc rejects this. */
char const *const *ccp;
char **p;
+/* NEC SVR4.0.2 mips cc rejects this. */
+struct point {int x, y;};
+static struct point const zero = {0,0};
/* AIX XL C 1.02.0.0 rejects this.
It does not let you subtract one const X* pointer from another in an arm
of an if-expression whose if-part is not a constant expression */
const char *g = "string";
-p = &g + (g ? g-g : 0);
+ccp = &g + (g ? g-g : 0);
/* HPUX 7.0 cc rejects these. */
++ccp;
p = (char**) ccp;
@@ -277,7 +1044,7 @@ ccp = (char const *const *) p;
*t++ = 0;
}
{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
- int x[] = {25,17};
+ int x[] = {25, 17};
const int *foo = &x[0];
++foo;
}
@@ -290,836 +1057,1155 @@ ccp = (char const *const *) p;
"k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
struct s { int j; const int *ap[3]; };
struct s *b; b->j = 5;
-}'
-echo checking for working const
-cat > conftest.c <<EOF
+}
+{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+ const int foo = 10;
+}
-int main() { exit(0); }
-int t() { $prog }
+; return 0; }
EOF
-if eval $compile; then
- :
+if { (eval echo configure:1068: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ac_cv_c_const=yes
else
- {
-test -n "$verbose" && \
-echo ' defining' const to be 'empty'
-DEFS="$DEFS -Dconst="
-SEDDEFS="${SEDDEFS}\${SEDdA}const\${SEDdB}const\${SEDdC}\${SEDdD}
-\${SEDuA}const\${SEDuB}const\${SEDuC}\${SEDuD}
-\${SEDeA}const\${SEDeB}const\${SEDeC}\${SEDeD}
-"
-}
-
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ ac_cv_c_const=no
fi
rm -f conftest*
+fi
+
+echo "$ac_t""$ac_cv_c_const" 1>&6
+if test $ac_cv_c_const = no; then
+ cat >> confdefs.h <<\EOF
+#define const
+EOF
-# Make sure to not get the incompatible SysV /etc/install and
-# /usr/sbin/install, which might be in PATH before a BSD-like install,
-# or the SunOS /usr/etc/install directory, or the AIX /bin/install,
-# or the AFS install, which mishandles nonexistent args, or
-# /usr/ucb/install on SVR4, which tries to use the nonexistent group
-# `staff'. On most BSDish systems install is in /usr/bin, not /usr/ucb
-# anyway. Sigh.
-if test "z${INSTALL}" = "z" ; then
- echo checking for install
- IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:"
- for dir in $PATH; do
- test -z "$dir" && dir=.
- case $dir in
- /etc|/usr/sbin|/usr/etc|/usr/afsws/bin|/usr/ucb) ;;
- *)
- if test -f $dir/installbsd; then
- INSTALL="$dir/installbsd -c" # OSF1
- INSTALL_PROGRAM='$(INSTALL)'
- INSTALL_DATA='$(INSTALL) -m 644'
- break
- fi
- if test -f $dir/install; then
- if grep dspmsg $dir/install >/dev/null 2>&1; then
- : # AIX
- else
- INSTALL="$dir/install -c"
- INSTALL_PROGRAM='$(INSTALL)'
- INSTALL_DATA='$(INSTALL) -m 644'
- break
- fi
- fi
- ;;
- esac
- done
- IFS="$saveifs"
fi
-INSTALL=${INSTALL-cp}
-INSTALL_PROGRAM=${INSTALL_PROGRAM-'$(INSTALL)'}
-INSTALL_DATA=${INSTALL_DATA-'$(INSTALL)'}
-echo checking for directory library header
-dirheader=
-if test -z "$dirheader"; then
- echo checking for dirent.h
-cat > conftest.c <<EOF
+
+ac_header_dirent=no
+for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr that defines DIR""... $ac_c" 1>&6
+echo "configure:1094: checking for $ac_hdr that defines DIR" >&5
+if eval "test \"`echo '$''{'ac_cv_header_dirent_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1099 "configure"
+#include "confdefs.h"
#include <sys/types.h>
-#include <dirent.h>
-int main() { exit(0); }
-int t() { DIR *dirp = opendir ("/"); }
+#include <$ac_hdr>
+int main() {
+DIR *dirp = 0;
+; return 0; }
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' DIRENT
-DEFS="$DEFS -DDIRENT=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}DIRENT\${SEDdB}DIRENT\${SEDdC}1\${SEDdD}
-\${SEDuA}DIRENT\${SEDuB}DIRENT\${SEDuC}1\${SEDuD}
-\${SEDeA}DIRENT\${SEDeB}DIRENT\${SEDeC}1\${SEDeD}
-"
-}
- dirheader=dirent.h
+if { (eval echo configure:1107: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ eval "ac_cv_header_dirent_$ac_safe=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_dirent_$ac_safe=no"
fi
rm -f conftest*
fi
-if test -z "$dirheader"; then
- echo checking for sys/ndir.h
-cat > conftest.c <<EOF
-#include <sys/types.h>
-#include <sys/ndir.h>
-int main() { exit(0); }
-int t() { DIR *dirp = opendir ("/"); }
+if eval "test \"`echo '$ac_cv_header_dirent_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' SYSNDIR
-DEFS="$DEFS -DSYSNDIR=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}SYSNDIR\${SEDdB}SYSNDIR\${SEDdC}1\${SEDdD}
-\${SEDuA}SYSNDIR\${SEDuB}SYSNDIR\${SEDuC}1\${SEDuD}
-\${SEDeA}SYSNDIR\${SEDeB}SYSNDIR\${SEDeC}1\${SEDeD}
-"
-}
- dirheader=sys/ndir.h
+ ac_header_dirent=$ac_hdr; break
+else
+ echo "$ac_t""no" 1>&6
+fi
+done
+# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
+if test $ac_header_dirent = dirent.h; then
+echo $ac_n "checking for opendir in -ldir""... $ac_c" 1>&6
+echo "configure:1132: checking for opendir in -ldir" >&5
+ac_lib_var=`echo dir'_'opendir | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ ac_save_LIBS="$LIBS"
+LIBS="-ldir $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1140 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char opendir();
+
+int main() {
+opendir()
+; return 0; }
+EOF
+if { (eval echo configure:1151: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_lib_$ac_lib_var=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f conftest*
+LIBS="$ac_save_LIBS"
+
fi
-if test -z "$dirheader"; then
- echo checking for sys/dir.h
-cat > conftest.c <<EOF
-#include <sys/types.h>
-#include <sys/dir.h>
-int main() { exit(0); }
-int t() { DIR *dirp = opendir ("/"); }
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ LIBS="$LIBS -ldir"
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+else
+echo $ac_n "checking for opendir in -lx""... $ac_c" 1>&6
+echo "configure:1173: checking for opendir in -lx" >&5
+ac_lib_var=`echo x'_'opendir | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ ac_save_LIBS="$LIBS"
+LIBS="-lx $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 1181 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char opendir();
+
+int main() {
+opendir()
+; return 0; }
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' SYSDIR
-DEFS="$DEFS -DSYSDIR=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}SYSDIR\${SEDdB}SYSDIR\${SEDdC}1\${SEDdD}
-\${SEDuA}SYSDIR\${SEDuB}SYSDIR\${SEDuC}1\${SEDuD}
-\${SEDeA}SYSDIR\${SEDeB}SYSDIR\${SEDeC}1\${SEDeD}
-"
-}
- dirheader=sys/dir.h
+if { (eval echo configure:1192: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_lib_$ac_lib_var=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_lib_$ac_lib_var=no"
fi
rm -f conftest*
+LIBS="$ac_save_LIBS"
+
fi
-if test -z "$dirheader"; then
- echo checking for ndir.h
-cat > conftest.c <<EOF
-#include <sys/types.h>
-#include <ndir.h>
-int main() { exit(0); }
-int t() { DIR *dirp = opendir ("/"); }
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ LIBS="$LIBS -lx"
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+fi
+
+echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
+echo "configure:1215: checking for ANSI C header files" >&5
+if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1220 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' NDIR
-DEFS="$DEFS -DNDIR=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}NDIR\${SEDdB}NDIR\${SEDdC}1\${SEDdD}
-\${SEDuA}NDIR\${SEDuB}NDIR\${SEDuC}1\${SEDuD}
-\${SEDeA}NDIR\${SEDeB}NDIR\${SEDeC}1\${SEDeD}
-"
-}
- dirheader=ndir.h
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1228: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ ac_cv_header_stdc=yes
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ ac_cv_header_stdc=no
fi
rm -f conftest*
-fi
-echo checking for closedir return value
-cat > conftest.c <<EOF
-#include <sys/types.h>
-#include <$dirheader>
-int closedir(); main() { exit(closedir(opendir(".")) != 0); }
+if test $ac_cv_header_stdc = yes; then
+ # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+cat > conftest.$ac_ext <<EOF
+#line 1245 "configure"
+#include "confdefs.h"
+#include <string.h>
EOF
-eval $compile
-if test -s conftest && (./conftest; exit) 2>/dev/null; then
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "memchr" >/dev/null 2>&1; then
:
else
- {
-test -n "$verbose" && \
-echo ' defining' VOID_CLOSEDIR
-DEFS="$DEFS -DVOID_CLOSEDIR=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}VOID_CLOSEDIR\${SEDdB}VOID_CLOSEDIR\${SEDdC}1\${SEDdD}
-\${SEDuA}VOID_CLOSEDIR\${SEDuB}VOID_CLOSEDIR\${SEDuC}1\${SEDuD}
-\${SEDeA}VOID_CLOSEDIR\${SEDeB}VOID_CLOSEDIR\${SEDeC}1\${SEDeD}
-"
-}
-
+ rm -rf conftest*
+ ac_cv_header_stdc=no
fi
rm -f conftest*
-if test -z "$dirheader"; then
- {
-test -n "$verbose" && \
-echo ' defining' NODIR
-DEFS="$DEFS -DNODIR=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}NODIR\${SEDdB}NODIR\${SEDdC}1\${SEDdD}
-\${SEDuA}NODIR\${SEDuB}NODIR\${SEDuC}1\${SEDuD}
-\${SEDeA}NODIR\${SEDeB}NODIR\${SEDeC}1\${SEDeD}
-"
-}
-
fi
-echo checking for return type of signal handlers
-cat > conftest.c <<EOF
-#include <sys/types.h>
-#include <signal.h>
-#ifdef signal
-#undef signal
-#endif
-extern void (*signal ()) ();
-int main() { exit(0); }
-int t() { int i; }
-EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' RETSIGTYPE to be 'void'
-DEFS="$DEFS -DRETSIGTYPE=void"
-SEDDEFS="${SEDDEFS}\${SEDdA}RETSIGTYPE\${SEDdB}RETSIGTYPE\${SEDdC}void\${SEDdD}
-\${SEDuA}RETSIGTYPE\${SEDuB}RETSIGTYPE\${SEDuC}void\${SEDuD}
-\${SEDeA}RETSIGTYPE\${SEDeB}RETSIGTYPE\${SEDeC}void\${SEDeD}
-"
-}
+if test $ac_cv_header_stdc = yes; then
+ # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+cat > conftest.$ac_ext <<EOF
+#line 1263 "configure"
+#include "confdefs.h"
+#include <stdlib.h>
+EOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "free" >/dev/null 2>&1; then
+ :
else
- {
-test -n "$verbose" && \
-echo ' defining' RETSIGTYPE to be 'int'
-DEFS="$DEFS -DRETSIGTYPE=int"
-SEDDEFS="${SEDDEFS}\${SEDdA}RETSIGTYPE\${SEDdB}RETSIGTYPE\${SEDdC}int\${SEDdD}
-\${SEDuA}RETSIGTYPE\${SEDuB}RETSIGTYPE\${SEDuC}int\${SEDuD}
-\${SEDeA}RETSIGTYPE\${SEDeB}RETSIGTYPE\${SEDeC}int\${SEDeD}
-"
-}
-
+ rm -rf conftest*
+ ac_cv_header_stdc=no
fi
rm -f conftest*
+fi
-echo checking for ANSI C header files
-cat > conftest.c <<EOF
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <float.h>
-EOF
-err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
-if test -z "$err"; then
- # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
-echo '#include <string.h>' > conftest.c
-eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
-if egrep "memchr" conftest.out >/dev/null 2>&1; then
- # SGI's /bin/cc from Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
-cat > conftest.c <<EOF
+if test $ac_cv_header_stdc = yes; then
+ # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+if test "$cross_compiling" = yes; then
+ :
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1284 "configure"
+#include "confdefs.h"
#include <ctype.h>
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
-#define XOR(e,f) (((e) && !(f)) || (!(e) && (f)))
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
int main () { int i; for (i = 0; i < 256; i++)
if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
exit (0); }
EOF
-eval $compile
-if test -s conftest && (./conftest; exit) 2>/dev/null; then
- {
-test -n "$verbose" && \
-echo ' defining' STDC_HEADERS
-DEFS="$DEFS -DSTDC_HEADERS=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}STDC_HEADERS\${SEDdB}STDC_HEADERS\${SEDdC}1\${SEDdD}
-\${SEDuA}STDC_HEADERS\${SEDuB}STDC_HEADERS\${SEDuC}1\${SEDuD}
-\${SEDeA}STDC_HEADERS\${SEDeB}STDC_HEADERS\${SEDeC}1\${SEDeD}
-"
-}
-
+if { (eval echo configure:1295: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+then
+ :
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ ac_cv_header_stdc=no
fi
-rm -f conftest*
+rm -fr conftest*
fi
-rm -f conftest*
fi
-rm -f conftest*
+fi
-echo checking for unistd.h
-cat > conftest.c <<EOF
-#include <unistd.h>
+echo "$ac_t""$ac_cv_header_stdc" 1>&6
+if test $ac_cv_header_stdc = yes; then
+ cat >> confdefs.h <<\EOF
+#define STDC_HEADERS 1
EOF
-err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
-if test -z "$err"; then
- {
-test -n "$verbose" && \
-echo ' defining' HAVE_UNISTD_H
-DEFS="$DEFS -DHAVE_UNISTD_H=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}HAVE_UNISTD_H\${SEDdB}HAVE_UNISTD_H\${SEDdC}1\${SEDdD}
-\${SEDuA}HAVE_UNISTD_H\${SEDuB}HAVE_UNISTD_H\${SEDuC}1\${SEDuD}
-\${SEDeA}HAVE_UNISTD_H\${SEDeB}HAVE_UNISTD_H\${SEDeC}1\${SEDeD}
-"
-}
fi
-rm -f conftest*
-for hdr in string.h fcntl.h
+for ac_hdr in fcntl.h limits.h string.h unistd.h varargs.h
do
-trhdr=HAVE_`echo $hdr | tr '[a-z]./' '[A-Z]__'`
-echo checking for ${hdr}
-cat > conftest.c <<EOF
-#include <${hdr}>
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:1322: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1327 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
EOF
-err=`eval "($CPP \$DEFS conftest.c >/dev/null) 2>&1"`
-if test -z "$err"; then
- {
-test -n "$verbose" && \
-echo ' defining' ${trhdr}
-DEFS="$DEFS -D${trhdr}=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}${trhdr}\${SEDdB}${trhdr}\${SEDdC}1\${SEDdD}
-\${SEDuA}${trhdr}\${SEDuB}${trhdr}\${SEDuC}1\${SEDuD}
-\${SEDeA}${trhdr}\${SEDeB}${trhdr}\${SEDeC}1\${SEDeD}
-"
-}
-
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1332: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
fi
rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+fi
done
-for func in rename
-do
-echo checking for ${func}
-cat > conftest.c <<EOF
-int main() { exit(0); }
-int t() { /* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_${func}) || defined (__stub___${func})
-choke me
-#else
-/* Override any gcc2 internal prototype to avoid an error. */
-extern char ${func}(); ${func}();
+echo $ac_n "checking for off_t""... $ac_c" 1>&6
+echo "configure:1360: checking for off_t" >&5
+if eval "test \"`echo '$''{'ac_cv_type_off_t'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1365 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#if STDC_HEADERS
+#include <stdlib.h>
+#include <stddef.h>
#endif
- }
EOF
-if eval $compile; then
- :
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "off_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+ rm -rf conftest*
+ ac_cv_type_off_t=yes
else
- LIBOBJS="$LIBOBJS ${func}.o"
-test -n "$verbose" && echo " using ${func}.o instead"
+ rm -rf conftest*
+ ac_cv_type_off_t=no
fi
rm -f conftest*
-done
+fi
+echo "$ac_t""$ac_cv_type_off_t" 1>&6
+if test $ac_cv_type_off_t = no; then
+ cat >> confdefs.h <<\EOF
+#define off_t long
+EOF
-for func in pathconf strerror
-do
-trfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
-echo checking for ${func}
-cat > conftest.c <<EOF
-#include <ctype.h>
-int main() { exit(0); }
-int t() {
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_${func}) || defined (__stub___${func})
-choke me
+fi
+
+echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
+echo "configure:1393: checking return type of signal handlers" >&5
+if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1398 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+#undef signal
+#endif
+#ifdef __cplusplus
+extern "C" void (*signal (int, void (*)(int)))(int);
#else
-/* Override any gcc2 internal prototype to avoid an error. */
-extern char ${func}(); ${func}();
+void (*signal ()) ();
#endif
- }
-EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' ${trfunc}
-DEFS="$DEFS -D${trfunc}=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
-\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
-\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
-"
-}
+int main() {
+int i;
+; return 0; }
+EOF
+if { (eval echo configure:1415: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ac_cv_type_signal=void
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ ac_cv_type_signal=int
fi
rm -f conftest*
-done
+fi
-# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
-# for constant arguments. Useless!
-echo checking for working alloca.h
-cat > conftest.c <<EOF
-#include <alloca.h>
-int main() { exit(0); }
-int t() { char *p = alloca(2 * sizeof(int)); }
+echo "$ac_t""$ac_cv_type_signal" 1>&6
+cat >> confdefs.h <<EOF
+#define RETSIGTYPE $ac_cv_type_signal
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' HAVE_ALLOCA_H
-DEFS="$DEFS -DHAVE_ALLOCA_H=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}HAVE_ALLOCA_H\${SEDdB}HAVE_ALLOCA_H\${SEDdC}1\${SEDdD}
-\${SEDuA}HAVE_ALLOCA_H\${SEDuB}HAVE_ALLOCA_H\${SEDuC}1\${SEDuD}
-\${SEDeA}HAVE_ALLOCA_H\${SEDeB}HAVE_ALLOCA_H\${SEDeC}1\${SEDeD}
-"
-}
-fi
-rm -f conftest*
-decl="#ifdef __GNUC__
-#define alloca __builtin_alloca
-#else
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#else
-char *alloca ();
-#endif
-#endif
+echo $ac_n "checking for size_t""... $ac_c" 1>&6
+echo "configure:1434: checking for size_t" >&5
+if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1439 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#if STDC_HEADERS
+#include <stdlib.h>
+#include <stddef.h>
#endif
-"
-echo checking for alloca
-cat > conftest.c <<EOF
-$decl
-int main() { exit(0); }
-int t() { char *p = (char *) alloca(1); }
EOF
-if eval $compile; then
- :
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+ egrep "size_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+ rm -rf conftest*
+ ac_cv_type_size_t=yes
else
- alloca_missing=1
-cat > conftest.c <<EOF
+ rm -rf conftest*
+ ac_cv_type_size_t=no
+fi
+rm -f conftest*
-#if defined(CRAY) && ! defined(CRAY2)
-winnitude
-#else
-lossage
-#endif
+fi
+echo "$ac_t""$ac_cv_type_size_t" 1>&6
+if test $ac_cv_type_size_t = no; then
+ cat >> confdefs.h <<\EOF
+#define size_t unsigned
+EOF
+
+fi
+
+# Check for NetBSD 1.0 bug, where memchr(..., 0) returns nonzero.
+echo $ac_n "checking for working memchr""... $ac_c" 1>&6
+echo "configure:1469: checking for working memchr" >&5
+if eval "test \"`echo '$''{'ac_cv_func_memchr'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test "$cross_compiling" = yes; then
+ echo "configure: warning: We are cross-compiling so we assume memchr does not work." 1>&2
+ ac_cv_func_memchr=no
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1478 "configure"
+#include "confdefs.h"
+#include <string.h>
+main () { exit (memchr ("", 0, 0) != 0 || memchr ("", 1, 0) != 0); }
EOF
-eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
-if egrep "winnitude" conftest.out >/dev/null 2>&1; then
- echo checking for _getb67
-cat > conftest.c <<EOF
-#include <ctype.h>
-int main() { exit(0); }
-int t() {
+if { (eval echo configure:1483: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+then
+ ac_cv_func_memchr=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ ac_cv_func_memchr=no
+fi
+rm -fr conftest*
+fi
+
+fi
+echo "$ac_t""$ac_cv_func_memchr" 1>&6
+if test $ac_cv_func_memchr = yes; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_MEMCHR 1
+EOF
+
+fi
+
+echo $ac_n "checking for getopt_long""... $ac_c" 1>&6
+echo "configure:1505: checking for getopt_long" >&5
+if eval "test \"`echo '$''{'ac_cv_func_getopt_long'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1510 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char getopt_long(); below. */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char getopt_long();
+
+int main() {
+
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
-#if defined (__stub__getb67) || defined (__stub____getb67)
+#if defined (__stub_getopt_long) || defined (__stub___getopt_long)
choke me
#else
-/* Override any gcc2 internal prototype to avoid an error. */
-extern char _getb67(); _getb67();
+getopt_long();
#endif
- }
+
+; return 0; }
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' CRAY_STACKSEG_END to be '_getb67'
-DEFS="$DEFS -DCRAY_STACKSEG_END=_getb67"
-SEDDEFS="${SEDDEFS}\${SEDdA}CRAY_STACKSEG_END\${SEDdB}CRAY_STACKSEG_END\${SEDdC}_getb67\${SEDdD}
-\${SEDuA}CRAY_STACKSEG_END\${SEDuB}CRAY_STACKSEG_END\${SEDuC}_getb67\${SEDuD}
-\${SEDeA}CRAY_STACKSEG_END\${SEDeB}CRAY_STACKSEG_END\${SEDeC}_getb67\${SEDeD}
-"
-}
+if { (eval echo configure:1533: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_func_getopt_long=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_func_getopt_long=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_func_'getopt_long`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ :
else
- echo checking for GETB67
-cat > conftest.c <<EOF
-#include <ctype.h>
-int main() { exit(0); }
-int t() {
+ echo "$ac_t""no" 1>&6
+LIBOBJS="$LIBOBJS getopt1.o getopt.o"
+fi
+
+
+for ac_func in _doprintf isascii memcmp mkdir mktemp pathconf sigaction sigprocmask sigsetmask
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:1557: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1562 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $ac_func(); below. */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char $ac_func();
+
+int main() {
+
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
-#if defined (__stub_GETB67) || defined (__stub___GETB67)
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
-/* Override any gcc2 internal prototype to avoid an error. */
-extern char GETB67(); GETB67();
+$ac_func();
#endif
- }
+
+; return 0; }
EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' CRAY_STACKSEG_END to be 'GETB67'
-DEFS="$DEFS -DCRAY_STACKSEG_END=GETB67"
-SEDDEFS="${SEDDEFS}\${SEDdA}CRAY_STACKSEG_END\${SEDdB}CRAY_STACKSEG_END\${SEDdC}GETB67\${SEDdD}
-\${SEDuA}CRAY_STACKSEG_END\${SEDuB}CRAY_STACKSEG_END\${SEDuC}GETB67\${SEDuD}
-\${SEDeA}CRAY_STACKSEG_END\${SEDeB}CRAY_STACKSEG_END\${SEDeC}GETB67\${SEDeD}
-"
-}
+if { (eval echo configure:1585: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_func_$ac_func=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_func_$ac_func=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+
else
- echo checking for getb67
-cat > conftest.c <<EOF
-#include <ctype.h>
-int main() { exit(0); }
-int t() {
+ echo "$ac_t""no" 1>&6
+fi
+done
+
+for ac_func in memchr rename
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:1612: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1617 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $ac_func(); below. */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char $ac_func();
+
+int main() {
+
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
-#if defined (__stub_getb67) || defined (__stub___getb67)
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
-/* Override any gcc2 internal prototype to avoid an error. */
-extern char getb67(); getb67();
+$ac_func();
#endif
- }
-EOF
-if eval $compile; then
- {
-test -n "$verbose" && \
-echo ' defining' CRAY_STACKSEG_END to be 'getb67'
-DEFS="$DEFS -DCRAY_STACKSEG_END=getb67"
-SEDDEFS="${SEDDEFS}\${SEDdA}CRAY_STACKSEG_END\${SEDdB}CRAY_STACKSEG_END\${SEDdC}getb67\${SEDdD}
-\${SEDuA}CRAY_STACKSEG_END\${SEDuB}CRAY_STACKSEG_END\${SEDuC}getb67\${SEDuD}
-\${SEDeA}CRAY_STACKSEG_END\${SEDeB}CRAY_STACKSEG_END\${SEDeC}getb67\${SEDeD}
-"
-}
+; return 0; }
+EOF
+if { (eval echo configure:1640: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_func_$ac_func=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_func_$ac_func=no"
fi
rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+LIBOBJS="$LIBOBJS ${ac_func}.o"
fi
-rm -f conftest*
+done
+
+echo $ac_n "checking whether closedir returns void""... $ac_c" 1>&6
+echo "configure:1667: checking whether closedir returns void" >&5
+if eval "test \"`echo '$''{'ac_cv_func_closedir_void'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test "$cross_compiling" = yes; then
+ ac_cv_func_closedir_void=yes
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1675 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+#include <$ac_header_dirent>
+int closedir(); main() { exit(closedir(opendir(".")) != 0); }
+EOF
+if { (eval echo configure:1681: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+then
+ ac_cv_func_closedir_void=no
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -fr conftest*
+ ac_cv_func_closedir_void=yes
+fi
+rm -fr conftest*
fi
-rm -f conftest*
fi
-rm -f conftest*
+echo "$ac_t""$ac_cv_func_closedir_void" 1>&6
+if test $ac_cv_func_closedir_void = yes; then
+ cat >> confdefs.h <<\EOF
+#define CLOSEDIR_VOID 1
+EOF
fi
-rm -f conftest*
-if test -n "$alloca_missing"; then
- # The SVR3 libPW and SVR4 libucb both contain incompatible functions
- # that cause trouble. Some versions do not even contain alloca or
- # contain a buggy version. If you still want to use their alloca,
- # use ar to extract alloca.o from them instead of compiling alloca.c.
- ALLOCA=alloca.o
-
- echo 'checking stack direction for C alloca'
- echo checking whether cross-compiling
-# If we cannot run a trivial program, we must be cross compiling.
-cat > conftest.c <<EOF
-main(){exit(0);}
+echo $ac_n "checking for vprintf""... $ac_c" 1>&6
+echo "configure:1704: checking for vprintf" >&5
+if eval "test \"`echo '$''{'ac_cv_func_vprintf'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1709 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char vprintf(); below. */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char vprintf();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined (__stub_vprintf) || defined (__stub___vprintf)
+choke me
+#else
+vprintf();
+#endif
+
+; return 0; }
EOF
-eval $compile
-if test -s conftest && (./conftest; exit) 2>/dev/null; then
- :
+if { (eval echo configure:1732: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_func_vprintf=yes"
else
- cross_compiling=1
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_func_vprintf=no"
fi
rm -f conftest*
+fi
-if test -n "$cross_compiling"
-then
- {
-test -n "$verbose" && \
-echo ' defining' STACK_DIRECTION to be '0'
-DEFS="$DEFS -DSTACK_DIRECTION=0"
-SEDDEFS="${SEDDEFS}\${SEDdA}STACK_DIRECTION\${SEDdB}STACK_DIRECTION\${SEDdC}0\${SEDdD}
-\${SEDuA}STACK_DIRECTION\${SEDuB}STACK_DIRECTION\${SEDuC}0\${SEDuD}
-\${SEDeA}STACK_DIRECTION\${SEDeB}STACK_DIRECTION\${SEDeC}0\${SEDeD}
-"
-}
+if eval "test \"`echo '$ac_cv_func_'vprintf`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ cat >> confdefs.h <<\EOF
+#define HAVE_VPRINTF 1
+EOF
else
-cat > conftest.c <<EOF
-find_stack_direction ()
-{
- static char *addr = 0;
- auto char dummy;
- if (addr == 0)
- {
- addr = &dummy;
- return find_stack_direction ();
- }
- else
- return (&dummy > addr) ? 1 : -1;
-}
-main ()
-{
- exit (find_stack_direction() < 0);
-}
-EOF
-eval $compile
-if test -s conftest && (./conftest; exit) 2>/dev/null; then
- {
-test -n "$verbose" && \
-echo ' defining' STACK_DIRECTION to be '1'
-DEFS="$DEFS -DSTACK_DIRECTION=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}STACK_DIRECTION\${SEDdB}STACK_DIRECTION\${SEDdC}1\${SEDdD}
-\${SEDuA}STACK_DIRECTION\${SEDuB}STACK_DIRECTION\${SEDuC}1\${SEDuD}
-\${SEDeA}STACK_DIRECTION\${SEDeB}STACK_DIRECTION\${SEDeC}1\${SEDeD}
-"
-}
+ echo "$ac_t""no" 1>&6
+fi
+if test "$ac_cv_func_vprintf" != yes; then
+echo $ac_n "checking for _doprnt""... $ac_c" 1>&6
+echo "configure:1756: checking for _doprnt" >&5
+if eval "test \"`echo '$''{'ac_cv_func__doprnt'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
else
- {
-test -n "$verbose" && \
-echo ' defining' STACK_DIRECTION to be '-1'
-DEFS="$DEFS -DSTACK_DIRECTION=-1"
-SEDDEFS="${SEDDEFS}\${SEDdA}STACK_DIRECTION\${SEDdB}STACK_DIRECTION\${SEDdC}-1\${SEDdD}
-\${SEDuA}STACK_DIRECTION\${SEDuB}STACK_DIRECTION\${SEDuC}-1\${SEDuD}
-\${SEDeA}STACK_DIRECTION\${SEDeB}STACK_DIRECTION\${SEDeC}-1\${SEDeD}
-"
-}
+ cat > conftest.$ac_ext <<EOF
+#line 1761 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char _doprnt(); below. */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char _doprnt();
-fi
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined (__stub__doprnt) || defined (__stub____doprnt)
+choke me
+#else
+_doprnt();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:1784: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+ rm -rf conftest*
+ eval "ac_cv_func__doprnt=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_func__doprnt=no"
fi
rm -f conftest*
fi
-echo checking for long file names
-lost=false
+if eval "test \"`echo '$ac_cv_func_'_doprnt`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ cat >> confdefs.h <<\EOF
+#define HAVE_DOPRNT 1
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+fi
+
+
+echo $ac_n "checking for long file names""... $ac_c" 1>&6
+echo "configure:1810: checking for long file names" >&5
+if eval "test \"`echo '$''{'ac_cv_sys_long_file_names'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ ac_cv_sys_long_file_names=yes
# Test for long file names in all the places we know might matter:
# . the current directory, where building will happen
+# $prefix/lib where we will be installing things
+# $exec_prefix/lib likewise
+# eval it to expand exec_prefix.
+# $TMPDIR if set, where it might want to write temporary files
+# if $TMPDIR is not set:
# /tmp where it might want to write temporary files
+# /var/tmp likewise
# /usr/tmp likewise
-# $prefix where we will be installing things
-# $exec_prefix likewise
-for dir in . /tmp /usr/tmp $prefix $exec_prefix ; do
- (echo 1 > $dir/conftest9012345) 2>/dev/null
- (echo 2 > $dir/conftest9012346) 2>/dev/null
- val=`cat $dir/conftest9012345 2>/dev/null`
- test -f $dir/conftest9012345 && test "$val" = 1 || lost=true
- rm -f $dir/conftest9012345 $dir/conftest9012346
+if test -n "$TMPDIR" && test -d "$TMPDIR" && test -w "$TMPDIR"; then
+ ac_tmpdirs="$TMPDIR"
+else
+ ac_tmpdirs='/tmp /var/tmp /usr/tmp'
+fi
+for ac_dir in . $ac_tmpdirs `eval echo $prefix/lib $exec_prefix/lib` ; do
+ test -d $ac_dir || continue
+ test -w $ac_dir || continue # It is less confusing to not echo anything here.
+ (echo 1 > $ac_dir/conftest9012345) 2>/dev/null
+ (echo 2 > $ac_dir/conftest9012346) 2>/dev/null
+ val=`cat $ac_dir/conftest9012345 2>/dev/null`
+ if test ! -f $ac_dir/conftest9012345 || test "$val" != 1; then
+ ac_cv_sys_long_file_names=no
+ rm -f $ac_dir/conftest9012345 $ac_dir/conftest9012346 2>/dev/null
+ break
+ fi
+ rm -f $ac_dir/conftest9012345 $ac_dir/conftest9012346 2>/dev/null
done
-$lost || {
-test -n "$verbose" && \
-echo ' defining' HAVE_LONG_FILE_NAMES
-DEFS="$DEFS -DHAVE_LONG_FILE_NAMES=1"
-SEDDEFS="${SEDDEFS}\${SEDdA}HAVE_LONG_FILE_NAMES\${SEDdB}HAVE_LONG_FILE_NAMES\${SEDdC}1\${SEDdD}
-\${SEDuA}HAVE_LONG_FILE_NAMES\${SEDuB}HAVE_LONG_FILE_NAMES\${SEDuC}1\${SEDuD}
-\${SEDeA}HAVE_LONG_FILE_NAMES\${SEDeB}HAVE_LONG_FILE_NAMES\${SEDeC}1\${SEDeD}
-"
-}
+fi
+echo "$ac_t""$ac_cv_sys_long_file_names" 1>&6
+if test $ac_cv_sys_long_file_names = yes; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_LONG_FILE_NAMES 1
+EOF
+
+fi
-echo checking for Xenix
-cat > conftest.c <<EOF
-#if defined(M_XENIX) && !defined(M_UNIX)
- yes
-#endif
+trap '' 1 2 15
+cat > confcache <<\EOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs. It is not useful on other systems.
+# If it contains results you don't want to keep, you may remove or edit it.
+#
+# By default, configure uses ./config.cache as the cache file,
+# creating it if it does not exist already. You can give configure
+# the --cache-file=FILE option to use a different cache file; that is
+# what configure does when it calls configure scripts in
+# subdirectories, so they share the cache.
+# Giving --cache-file=/dev/null disables caching, for debugging configure.
+# config.status only pays attention to the cache file if you give it the
+# --recheck option to rerun configure.
+#
EOF
-eval "$CPP \$DEFS conftest.c > conftest.out 2>&1"
-if egrep "yes" conftest.out >/dev/null 2>&1; then
- XENIX=1
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(set) 2>&1 |
+ case `(ac_space=' '; set | grep ac_space) 2>&1` in
+ *ac_space=\ *)
+ # `set' does not quote correctly, so add quotes (double-quote substitution
+ # turns \\\\ into \\, and sed turns \\ into \).
+ sed -n \
+ -e "s/'/'\\\\''/g" \
+ -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p"
+ ;;
+ *)
+ # `set' quotes correctly as required by POSIX, so do not add quotes.
+ sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p'
+ ;;
+ esac >> confcache
+if cmp -s $cache_file confcache; then
+ :
+else
+ if test -w $cache_file; then
+ echo "updating cache $cache_file"
+ cat confcache > $cache_file
+ else
+ echo "not updating unwritable cache $cache_file"
+ fi
fi
-rm -f conftest*
+rm -f confcache
-if test -n "$XENIX"; then
- LIBS="$LIBS -lx"
- case "$DEFS" in
- *SYSNDIR*) ;;
- *) LIBS="-ldir $LIBS" ;; # Make sure -ldir precedes any -lx.
- esac
-fi
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
-if test -n "$prefix"; then
- test -z "$exec_prefix" && exec_prefix='${prefix}'
- prsub="s%^prefix\\([ ]*\\)=\\([ ]*\\).*$%prefix\\1=\\2$prefix%"
-fi
-if test -n "$exec_prefix"; then
- prsub="$prsub
-s%^exec_prefix\\([ ]*\\)=\\([ ]*\\).*$%exec_prefix\\1=\\2$exec_prefix%"
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Any assignment to VPATH causes Sun make to only execute
+# the first set of double-colon rules, so remove it if not needed.
+# If there is a colon in the path, we need to keep it.
+if test "x$srcdir" = x.; then
+ ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d'
fi
-cat >conftest.def <<EOF
-$DEFS
-EOF
-escape_ampersand_and_backslash='s%[&\\]%\\&%g'
-DEFS=`sed "$escape_ampersand_and_backslash" <conftest.def`
-rm -f conftest.def
-
-trap 'rm -f config.status; exit 1' 1 3 15
-echo creating config.status
-rm -f config.status
-cat > config.status <<EOF
-#!/bin/sh
+
+trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15
+
+DEFS=-DHAVE_CONFIG_H
+
+# Without the "./", some shells look in PATH for config.status.
+: ${CONFIG_STATUS=./config.status}
+
+echo creating $CONFIG_STATUS
+rm -f $CONFIG_STATUS
+cat > $CONFIG_STATUS <<EOF
+#! /bin/sh
# Generated automatically by configure.
# Run this file to recreate the current configuration.
# This directory was configured as follows,
# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
#
-# $0 $configure_args
+# $0 $ac_configure_args
+#
+# Compiler output produced by configure, useful for debugging
+# configure, is in ./config.log if it exists.
-for arg
+ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]"
+for ac_option
do
- case "\$arg" in
- -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
- exec /bin/sh $0 $configure_args ;;
- *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;;
+ case "\$ac_option" in
+ -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+ echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
+ exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
+ -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
+ echo "$CONFIG_STATUS generated by autoconf version 2.12"
+ exit 0 ;;
+ -help | --help | --hel | --he | --h)
+ echo "\$ac_cs_usage"; exit 0 ;;
+ *) echo "\$ac_cs_usage"; exit 1 ;;
esac
done
-trap 'rm -f Makefile config.h conftest*; exit 1' 1 3 15
-CC='$CC'
-CPP='$CPP'
-INSTALL='$INSTALL'
-INSTALL_PROGRAM='$INSTALL_PROGRAM'
-INSTALL_DATA='$INSTALL_DATA'
-LIBOBJS='$LIBOBJS'
-ALLOCA='$ALLOCA'
-LIBS='$LIBS'
-srcdir='$srcdir'
-prefix='$prefix'
-exec_prefix='$exec_prefix'
-prsub='$prsub'
-EOF
-cat >> config.status <<\EOF
+ac_given_srcdir=$srcdir
+ac_given_INSTALL="$INSTALL"
-top_srcdir=$srcdir
-
-# Allow make-time overrides of the generated file list.
-test -n "$gen_files" || gen_files="Makefile"
-
-for file in .. $gen_files; do if [ "x$file" != "x.." ]; then
- srcdir=$top_srcdir
- # Remove last slash and all that follows it. Not all systems have dirname.
- dir=`echo $file|sed 's%/[^/][^/]*$%%'`
- if test "$dir" != "$file"; then
- test "$top_srcdir" != . && srcdir=$top_srcdir/$dir
- test ! -d $dir && mkdir $dir
- fi
- echo creating $file
- rm -f $file
- echo "# Generated automatically from `echo $file|sed 's|.*/||'`.in by configure." > $file
- sed -e "
-$prsub
+trap 'rm -fr `echo "Makefile config.h:config.hin" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+# Protect against being on the right side of a sed subst in config.status.
+sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
+ s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
+$ac_vpsub
+$extrasub
+s%@CFLAGS@%$CFLAGS%g
+s%@CPPFLAGS@%$CPPFLAGS%g
+s%@CXXFLAGS@%$CXXFLAGS%g
+s%@DEFS@%$DEFS%g
+s%@LDFLAGS@%$LDFLAGS%g
+s%@LIBS@%$LIBS%g
+s%@exec_prefix@%$exec_prefix%g
+s%@prefix@%$prefix%g
+s%@program_transform_name@%$program_transform_name%g
+s%@bindir@%$bindir%g
+s%@sbindir@%$sbindir%g
+s%@libexecdir@%$libexecdir%g
+s%@datadir@%$datadir%g
+s%@sysconfdir@%$sysconfdir%g
+s%@sharedstatedir@%$sharedstatedir%g
+s%@localstatedir@%$localstatedir%g
+s%@libdir@%$libdir%g
+s%@includedir@%$includedir%g
+s%@oldincludedir@%$oldincludedir%g
+s%@infodir@%$infodir%g
+s%@mandir@%$mandir%g
+s%@PACKAGE@%$PACKAGE%g
+s%@VERSION@%$VERSION%g
s%@CC@%$CC%g
s%@CPP@%$CPP%g
-s%@INSTALL@%$INSTALL%g
s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
s%@INSTALL_DATA@%$INSTALL_DATA%g
+s%@SET_MAKE@%$SET_MAKE%g
+s%@ED_PROGRAM@%$ED_PROGRAM%g
s%@LIBOBJS@%$LIBOBJS%g
-s%@ALLOCA@%$ALLOCA%g
-s%@LIBS@%$LIBS%g
+
+CEOF
+EOF
+
+cat >> $CONFIG_STATUS <<\EOF
+
+# Split the substitutions into bite-sized pieces for seds with
+# small command number limits, like on Digital OSF/1 and HP-UX.
+ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script.
+ac_file=1 # Number of current file.
+ac_beg=1 # First line for current file.
+ac_end=$ac_max_sed_cmds # Line after last line for current file.
+ac_more_lines=:
+ac_sed_cmds=""
+while $ac_more_lines; do
+ if test $ac_beg -gt 1; then
+ sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file
+ else
+ sed "${ac_end}q" conftest.subs > conftest.s$ac_file
+ fi
+ if test ! -s conftest.s$ac_file; then
+ ac_more_lines=false
+ rm -f conftest.s$ac_file
+ else
+ if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds="sed -f conftest.s$ac_file"
+ else
+ ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file"
+ fi
+ ac_file=`expr $ac_file + 1`
+ ac_beg=$ac_end
+ ac_end=`expr $ac_end + $ac_max_sed_cmds`
+ fi
+done
+if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds=cat
+fi
+EOF
+
+cat >> $CONFIG_STATUS <<EOF
+
+CONFIG_FILES=\${CONFIG_FILES-"Makefile"}
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
+ # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+ case "$ac_file" in
+ *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+ ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+ *) ac_file_in="${ac_file}.in" ;;
+ esac
+
+ # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
+
+ # Remove last slash and all that follows it. Not all systems have dirname.
+ ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+ if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+ # The file is in a subdirectory.
+ test ! -d "$ac_dir" && mkdir "$ac_dir"
+ ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
+ # A "../" for each directory in $ac_dir_suffix.
+ ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
+ else
+ ac_dir_suffix= ac_dots=
+ fi
+
+ case "$ac_given_srcdir" in
+ .) srcdir=.
+ if test -z "$ac_dots"; then top_srcdir=.
+ else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
+ /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
+ *) # Relative path.
+ srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
+ top_srcdir="$ac_dots$ac_given_srcdir" ;;
+ esac
+
+ case "$ac_given_INSTALL" in
+ [/$]*) INSTALL="$ac_given_INSTALL" ;;
+ *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
+ esac
+
+ echo creating "$ac_file"
+ rm -f "$ac_file"
+ configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
+ case "$ac_file" in
+ *Makefile*) ac_comsub="1i\\
+# $configure_input" ;;
+ *) ac_comsub= ;;
+ esac
+
+ ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+ sed -e "$ac_comsub
+s%@configure_input@%$configure_input%g
s%@srcdir@%$srcdir%g
-s%@DEFS@%-DHAVE_CONFIG_H%" $top_srcdir/${file}.in >> $file
+s%@top_srcdir@%$top_srcdir%g
+s%@INSTALL@%$INSTALL%g
+" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file
fi; done
-test -n "$gen_config" || gen_config=config.h
-echo creating $gen_config
-# These sed commands are put into SEDDEFS when defining a macro.
-# They are broken into pieces to make the sed script easier to manage.
-# They are passed to sed as "A NAME B NAME C VALUE D", where NAME
-# is the cpp macro being defined and VALUE is the value it is being given.
-# Each defining turns into a single global substitution command.
+rm -f conftest.s*
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
#
-# SEDd sets the value in "#define NAME VALUE" lines.
-SEDdA='s@^\([ ]*\)#\([ ]*define[ ][ ]*\)'
-SEDdB='\([ ][ ]*\)[^ ]*@\1#\2'
-SEDdC='\3'
-SEDdD='@g'
-# SEDu turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
-SEDuA='s@^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
-SEDuB='\([ ]\)@\1#\2define\3'
-SEDuC=' '
-SEDuD='\4@g'
-# SEDe turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
-SEDeA='s@^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
-SEDeB='$@\1#\2define\3'
-SEDeC=' '
-SEDeD='@g'
-rm -f conftest.sed
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)'
+ac_dB='\([ ][ ]*\)[^ ]*%\1#\2'
+ac_dC='\3'
+ac_dD='%g'
+# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
+ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
+ac_uB='\([ ]\)%\1#\2define\3'
+ac_uC=' '
+ac_uD='\4%g'
+# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
+ac_eB='$%\1#\2define\3'
+ac_eC=' '
+ac_eD='%g'
+
+if test "${CONFIG_HEADERS+set}" != set; then
EOF
-# Turn off quoting long enough to insert the sed commands.
-rm -f conftest.sh
-cat > conftest.sh <<EOF
-$SEDDEFS
+cat >> $CONFIG_STATUS <<EOF
+ CONFIG_HEADERS="config.h:config.hin"
EOF
+cat >> $CONFIG_STATUS <<\EOF
+fi
+for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
+ # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+ case "$ac_file" in
+ *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+ ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+ *) ac_file_in="${ac_file}.in" ;;
+ esac
-# Maximum number of lines to put in a single here document.
-maxshlines=9
+ echo creating $ac_file
-# Break up $SEDDEFS (now in conftest.sh) because some shells have a limit
-# on the size of here documents.
+ rm -f conftest.frag conftest.in conftest.out
+ ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+ cat $ac_file_inputs > conftest.in
-while :
-do
- lines=`grep -c . conftest.sh`
- if test -z "$lines" || test "$lines" -eq 0; then break; fi
- rm -f conftest.s1 conftest.s2
- sed ${maxshlines}q conftest.sh > conftest.s1 # Like head -20.
- sed 1,${maxshlines}d conftest.sh > conftest.s2 # Like tail +21.
- # Write a limited-size here document to append to conftest.sed.
- echo 'cat >> conftest.sed <<CONFEOF' >> config.status
- cat conftest.s1 >> config.status
- echo 'CONFEOF' >> config.status
- rm -f conftest.s1 conftest.sh
- mv conftest.s2 conftest.sh
-done
-rm -f conftest.sh
+EOF
+
+# Transform confdefs.h into a sed script conftest.vals that substitutes
+# the proper values into config.h.in to produce config.h. And first:
+# Protect against being on the right side of a sed subst in config.status.
+# Protect against being in an unquoted here document in config.status.
+rm -f conftest.vals
+cat > conftest.hdr <<\EOF
+s/[\\&%]/\\&/g
+s%[\\$`]%\\&%g
+s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
+s%ac_d%ac_u%gp
+s%ac_u%ac_e%gp
+EOF
+sed -n -f conftest.hdr confdefs.h > conftest.vals
+rm -f conftest.hdr
-# Now back to your regularly scheduled config.status.
-cat >> config.status <<\EOF
-# This sed command replaces #undef's with comments. This is necessary, for
+# This sed command replaces #undef with comments. This is necessary, for
# example, in the case of _POSIX_SOURCE, which is predefined and required
-# on some systems where configure will not decide to define it in
-# config.h.
-cat >> conftest.sed <<\CONFEOF
-s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
-CONFEOF
-rm -f conftest.h
-# Break up the sed commands because old seds have small limits.
-maxsedlines=20
-cp $top_srcdir/$gen_config.in conftest.h1
+# on some systems where configure will not decide to define it.
+cat >> conftest.vals <<\EOF
+s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */%
+EOF
+
+# Break up conftest.vals because some shells have a limit on
+# the size of here documents, and old seds have small limits too.
+
+rm -f conftest.tail
while :
do
- lines=`grep -c . conftest.sed`
- if test -z "$lines" || test "$lines" -eq 0; then break; fi
- rm -f conftest.s1 conftest.s2 conftest.h2
- sed ${maxsedlines}q conftest.sed > conftest.s1 # Like head -20.
- sed 1,${maxsedlines}d conftest.sed > conftest.s2 # Like tail +21.
- sed -f conftest.s1 < conftest.h1 > conftest.h2
- rm -f conftest.s1 conftest.h1 conftest.sed
- mv conftest.h2 conftest.h1
- mv conftest.s2 conftest.sed
+ ac_lines=`grep -c . conftest.vals`
+ # grep -c gives empty output for an empty file on some AIX systems.
+ if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
+ # Write a limited-size here document to conftest.frag.
+ echo ' cat > conftest.frag <<CEOF' >> $CONFIG_STATUS
+ sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS
+ echo 'CEOF
+ sed -f conftest.frag conftest.in > conftest.out
+ rm -f conftest.in
+ mv conftest.out conftest.in
+' >> $CONFIG_STATUS
+ sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail
+ rm -f conftest.vals
+ mv conftest.tail conftest.vals
done
-rm -f conftest.sed conftest.h
-echo "/* $gen_config. Generated automatically by configure. */" > conftest.h
-cat conftest.h1 >> conftest.h
-rm -f conftest.h1
-if cmp -s $gen_config conftest.h 2>/dev/null; then
- # The file exists and we would not be changing it.
- rm -f conftest.h
-else
- rm -f $gen_config
- mv conftest.h $gen_config
-fi
+rm -f conftest.vals
+
+cat >> $CONFIG_STATUS <<\EOF
+ rm -f conftest.frag conftest.h
+ echo "/* $ac_file. Generated automatically by configure. */" > conftest.h
+ cat conftest.in >> conftest.h
+ rm -f conftest.in
+ if cmp -s $ac_file conftest.h 2>/dev/null; then
+ echo "$ac_file is unchanged"
+ rm -f conftest.h
+ else
+ # Remove last slash and all that follows it. Not all systems have dirname.
+ ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+ if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+ # The file is in a subdirectory.
+ test ! -d "$ac_dir" && mkdir "$ac_dir"
+ fi
+ rm -f $ac_file
+ mv conftest.h $ac_file
+ fi
+fi; done
+
+EOF
+cat >> $CONFIG_STATUS <<EOF
+EOF
+cat >> $CONFIG_STATUS <<\EOF
exit 0
EOF
-chmod +x config.status
-test -n "$no_create" || ./config.status
+chmod +x $CONFIG_STATUS
+rm -fr confdefs* $ac_clean_files
+test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
diff --git a/configure.in b/configure.in
index 9b338ea..3c674ec 100644
--- a/configure.in
+++ b/configure.in
@@ -1,24 +1,57 @@
+# Configure `patch'.
+# Copyright 1993, 1997 Free Software Foundation, Inc.
dnl Process this file with autoconf to produce a configure script.
+
AC_INIT(patch.c)
-AC_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADER(config.h:config.hin)
+AC_ARG_PROGRAM
+
+PACKAGE=patch
+VERSION=2.2
+AC_SUBST(PACKAGE)
+AC_SUBST(VERSION)
+
AC_PROG_CC
AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+AC_PATH_PROG(ED_PROGRAM, ed, ed)
+
AC_AIX
AC_MINIX
AC_ISC_POSIX
-AC_CONST
-AC_PROG_INSTALL
-AC_DIR_HEADER
-if test -z "$dirheader"; then
- AC_DEFINE(NODIR)
+
+AC_C_CONST
+
+AC_HEADER_DIRENT
+AC_HEADER_STDC
+AC_CHECK_HEADERS(fcntl.h limits.h string.h unistd.h varargs.h)
+
+AC_TYPE_OFF_T
+AC_TYPE_SIGNAL
+AC_TYPE_SIZE_T
+
+# Check for NetBSD 1.0 bug, where memchr(..., 0) returns nonzero.
+AC_MSG_CHECKING(for working memchr)
+AC_CACHE_VAL(ac_cv_func_memchr,
+[AC_TRY_RUN([#include <string.h>
+main () { exit (memchr ("", 0, 0) != 0 || memchr ("", 1, 0) != 0); }],
+ ac_cv_func_memchr=yes,
+ ac_cv_func_memchr=no,
+ AC_MSG_WARN([We are cross-compiling so we assume memchr does not work.])
+ ac_cv_func_memchr=no)])dnl
+AC_MSG_RESULT($ac_cv_func_memchr)
+if test $ac_cv_func_memchr = yes; then
+ AC_DEFINE(HAVE_MEMCHR)
fi
-AC_RETSIGTYPE
-AC_STDC_HEADERS
-AC_UNISTD_H
-AC_HAVE_HEADERS(string.h fcntl.h)
-AC_REPLACE_FUNCS(rename)
-AC_HAVE_FUNCS(pathconf strerror)
-AC_ALLOCA
-AC_LONG_FILE_NAMES
-AC_XENIX_DIR
+
+AC_CHECK_FUNC(getopt_long, , [LIBOBJS="$LIBOBJS getopt1.o getopt.o"])
+AC_SUBST(LIBOBJS)
+AC_CHECK_FUNCS(_doprintf isascii memcmp mkdir mktemp pathconf sigaction sigprocmask sigsetmask)
+AC_REPLACE_FUNCS(memchr rename)
+AC_FUNC_CLOSEDIR_VOID
+AC_FUNC_VPRINTF
+
+AC_SYS_LONG_FILE_NAMES
+
AC_OUTPUT(Makefile)
diff --git a/getopt.c b/getopt.c
index a59a013..56ab9f2 100644
--- a/getopt.c
+++ b/getopt.c
@@ -3,7 +3,7 @@
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
- Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 1996
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -18,37 +18,25 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
-/* NOTE!!! AIX requires this to be the first thing in the file.
- Do not put ANYTHING before it! */
-#if !defined (__GNUC__) && defined (_AIX)
- #pragma alloca
+/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
+ Ditto for AIX 3.2 and <stdlib.h>. */
+#ifndef _NO_PROTO
+#define _NO_PROTO
#endif
#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef __GNUC__
-#define alloca __builtin_alloca
-#else /* not __GNUC__ */
-#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
-#include <alloca.h>
-#else
-#ifndef _AIX
-char *alloca ();
+#include <config.h>
#endif
-#endif /* alloca.h */
-#endif /* not __GNUC__ */
-#if !__STDC__ && !defined(const) && IN_GCC
+#if !defined (__STDC__) || !__STDC__
+/* This is a separate conditional since some stdc systems
+ reject `defined (const)'. */
+#ifndef const
#define const
#endif
-
-/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. */
-#ifndef _NO_PROTO
-#define _NO_PROTO
#endif
#include <stdio.h>
@@ -67,18 +55,35 @@ char *alloca ();
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
-#undef alloca
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
-#else /* Not GNU C library. */
-#define __alloca alloca
+#include <unistd.h>
#endif /* GNU C library. */
-/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
- long-named option. Because this is not POSIX.2 compliant, it is
- being phased out. */
-/* #define GETOPT_COMPAT */
+#ifdef VMS
+#include <unixlib.h>
+#if HAVE_STRING_H - 0
+#include <string.h>
+#endif
+#endif
+
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+/* It's not Unix, really. See? Capital letters. */
+#include <windows.h>
+#define getpid() GetCurrentProcessId()
+#endif
+
+#ifndef _
+/* This is for other GNU distributions with internationalized messages.
+ When compiling libc, the _ macro is predefined. */
+#ifdef HAVE_LIBINTL_H
+# include <libintl.h>
+# define _(msgid) gettext (msgid)
+#else
+# define _(msgid) (msgid)
+#endif
+#endif
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
@@ -102,7 +107,7 @@ char *alloca ();
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
-char *optarg = 0;
+char *optarg = NULL;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
@@ -172,6 +177,9 @@ static enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
+
+/* Value of POSIXLY_CORRECT environment variable. */
+static char *posixly_correct;
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
@@ -180,7 +188,6 @@ static enum
in GCC. */
#include <string.h>
#define my_index strchr
-#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
#else
/* Avoid depending on library functions or files
@@ -202,17 +209,19 @@ my_index (str, chr)
return 0;
}
-static void
-my_bcopy (from, to, size)
- const char *from;
- char *to;
- int size;
-{
- int i;
- for (i = 0; i < size; i++)
- to[i] = from[i];
-}
-#endif /* GNU C library. */
+/* If using GCC, we can safely declare strlen this way.
+ If not using GCC, it is ok not to declare it. */
+#ifdef __GNUC__
+/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
+ That was relevant to code that was here before. */
+#if !defined (__STDC__) || !__STDC__
+/* gcc with -traditional declares the built-in strlen to return int,
+ and has done so at least since version 2.4.5. -- rms. */
+extern int strlen (const char *);
+#endif /* not __STDC__ */
+#endif /* __GNUC__ */
+
+#endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */
@@ -223,6 +232,12 @@ my_bcopy (from, to, size)
static int first_nonopt;
static int last_nonopt;
+/* Bash 2.0 gives us an environment variable containing flags
+ indicating ARGV elements that should not be considered arguments. */
+
+static const char *nonoption_flags;
+static int nonoption_flags_len;
+
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
@@ -232,27 +247,119 @@ static int last_nonopt;
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
+#if defined (__STDC__) && __STDC__
+static void exchange (char **);
+#endif
+
static void
exchange (argv)
char **argv;
{
- int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
- char **temp = (char **) __alloca (nonopts_size);
+ int bottom = first_nonopt;
+ int middle = last_nonopt;
+ int top = optind;
+ char *tem;
+
+ /* Exchange the shorter segment with the far end of the longer segment.
+ That puts the shorter segment into the right place.
+ It leaves the longer segment in the right place overall,
+ but it consists of two parts that need to be swapped next. */
- /* Interchange the two blocks of data in ARGV. */
+ while (top > middle && middle > bottom)
+ {
+ if (top - middle > middle - bottom)
+ {
+ /* Bottom segment is the short one. */
+ int len = middle - bottom;
+ register int i;
- my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
- my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
- (optind - last_nonopt) * sizeof (char *));
- my_bcopy ((char *) temp,
- (char *) &argv[first_nonopt + optind - last_nonopt],
- nonopts_size);
+ /* Swap it with the top part of the top segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[top - (middle - bottom) + i];
+ argv[top - (middle - bottom) + i] = tem;
+ }
+ /* Exclude the moved bottom segment from further swapping. */
+ top -= len;
+ }
+ else
+ {
+ /* Top segment is the short one. */
+ int len = top - middle;
+ register int i;
+
+ /* Swap it with the bottom part of the bottom segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[middle + i];
+ argv[middle + i] = tem;
+ }
+ /* Exclude the moved top segment from further swapping. */
+ bottom += len;
+ }
+ }
/* Update records for the slots the non-options now occupy. */
first_nonopt += (optind - last_nonopt);
last_nonopt = optind;
}
+
+/* Initialize the internal data when the first call is made. */
+
+#if defined (__STDC__) && __STDC__
+static const char *_getopt_initialize (const char *);
+#endif
+static const char *
+_getopt_initialize (optstring)
+ const char *optstring;
+{
+ /* Start processing options with ARGV-element 1 (since ARGV-element 0
+ is the program name); the sequence of previously skipped
+ non-option ARGV-elements is empty. */
+
+ first_nonopt = last_nonopt = optind = 1;
+
+ nextchar = NULL;
+
+ posixly_correct = getenv ("POSIXLY_CORRECT");
+
+ /* Determine how to handle the ordering of options and nonoptions. */
+
+ if (optstring[0] == '-')
+ {
+ ordering = RETURN_IN_ORDER;
+ ++optstring;
+ }
+ else if (optstring[0] == '+')
+ {
+ ordering = REQUIRE_ORDER;
+ ++optstring;
+ }
+ else if (posixly_correct != NULL)
+ ordering = REQUIRE_ORDER;
+ else
+ ordering = PERMUTE;
+
+ if (posixly_correct == NULL)
+ {
+ /* Bash 2.0 puts a special variable in the environment for each
+ command it runs, specifying which ARGV elements are the results of
+ file name wildcard expansion and therefore should not be
+ considered as options. */
+ char var[100];
+ sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ());
+ nonoption_flags = getenv (var);
+ if (nonoption_flags == NULL)
+ nonoption_flags_len = 0;
+ else
+ nonoption_flags_len = strlen (nonoption_flags);
+ }
+
+ return optstring;
+}
/* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING.
@@ -319,41 +426,32 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
int *longind;
int long_only;
{
- int option_index;
-
- optarg = 0;
-
- /* Initialize the internal data when the first call is made.
- Start processing options with ARGV-element 1 (since ARGV-element 0
- is the program name); the sequence of previously skipped
- non-option ARGV-elements is empty. */
+ optarg = NULL;
if (optind == 0)
{
- first_nonopt = last_nonopt = optind = 1;
-
- nextchar = NULL;
-
- /* Determine how to handle the ordering of options and nonoptions. */
-
- if (optstring[0] == '-')
- {
- ordering = RETURN_IN_ORDER;
- ++optstring;
- }
- else if (optstring[0] == '+')
- {
- ordering = REQUIRE_ORDER;
- ++optstring;
- }
- else if (getenv ("POSIXLY_CORRECT") != NULL)
- ordering = REQUIRE_ORDER;
- else
- ordering = PERMUTE;
+ optstring = _getopt_initialize (optstring);
+ optind = 1; /* Don't scan ARGV[0], the program name. */
}
+ /* Test whether ARGV[optind] points to a non-option argument.
+ Either it does not have option syntax, or there is an environment flag
+ from the shell indicating it is not an option. */
+#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
+ || (optind < nonoption_flags_len \
+ && nonoption_flags[optind] == '1'))
+
if (nextchar == NULL || *nextchar == '\0')
{
+ /* Advance to the next ARGV-element. */
+
+ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
+ moved back by the user (who may also have changed the arguments). */
+ if (last_nonopt > optind)
+ last_nonopt = optind;
+ if (first_nonopt > optind)
+ first_nonopt = optind;
+
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
@@ -364,21 +462,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else if (last_nonopt != optind)
first_nonopt = optind;
- /* Now skip any additional non-options
+ /* Skip any additional non-options
and extend the range of non-options previously skipped. */
- while (optind < argc
- && (argv[optind][0] != '-' || argv[optind][1] == '\0')
-#ifdef GETOPT_COMPAT
- && (longopts == NULL
- || argv[optind][0] != '+' || argv[optind][1] == '\0')
-#endif /* GETOPT_COMPAT */
- )
+ while (optind < argc && NONOPTION_P)
optind++;
last_nonopt = optind;
}
- /* Special ARGV-element `--' means premature end of options.
+ /* The special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
@@ -411,12 +503,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
- if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
-#ifdef GETOPT_COMPAT
- && (longopts == NULL
- || argv[optind][0] != '+' || argv[optind][1] == '\0')
-#endif /* GETOPT_COMPAT */
- )
+ if (NONOPTION_P)
{
if (ordering == REQUIRE_ORDER)
return EOF;
@@ -425,36 +512,48 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
}
/* We have found another option-ARGV-element.
- Start decoding its characters. */
+ Skip the initial punctuation. */
nextchar = (argv[optind] + 1
+ (longopts != NULL && argv[optind][1] == '-'));
}
+ /* Decode the current option-ARGV-element. */
+
+ /* Check whether the ARGV-element is a long option.
+
+ If long_only and the ARGV-element has the form "-f", where f is
+ a valid short option, don't consider it an abbreviated form of
+ a long option that starts with f. Otherwise there would be no
+ way to give the -f short option.
+
+ On the other hand, if there's a long option "fubar" and
+ the ARGV-element is "-fu", do consider that an abbreviation of
+ the long option, just like "--fu", and not "-f" with arg "u".
+
+ This distinction seems to be the most useful approach. */
+
if (longopts != NULL
- && ((argv[optind][0] == '-'
- && (argv[optind][1] == '-' || long_only))
-#ifdef GETOPT_COMPAT
- || argv[optind][0] == '+'
-#endif /* GETOPT_COMPAT */
- ))
+ && (argv[optind][1] == '-'
+ || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
{
+ char *nameend;
const struct option *p;
- char *s = nextchar;
+ const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
- const struct option *pfound = NULL;
int indfound;
+ int option_index;
- while (*s && *s != '=')
- s++;
+ for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
- /* Test all options for either exact match or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name;
- p++, option_index++)
- if (!strncmp (p->name, nextchar, s - nextchar))
+ /* Test all long options for either exact match
+ or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
{
- if (s - nextchar == strlen (p->name))
+ if (nameend - nextchar == strlen (p->name))
{
/* Exact match found. */
pfound = p;
@@ -469,17 +568,18 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
indfound = option_index;
}
else
- /* Second nonexact match found. */
+ /* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (opterr)
- fprintf (stderr, "%s: option `%s' is ambiguous\n",
+ fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
+ optopt = 0;
return '?';
}
@@ -487,28 +587,29 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
option_index = indfound;
optind++;
- if (*s)
+ if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
- optarg = s + 1;
+ optarg = nameend + 1;
else
{
if (opterr)
- {
- if (argv[optind - 1][1] == '-')
- /* --option */
- fprintf (stderr,
- "%s: option `--%s' doesn't allow an argument\n",
- argv[0], pfound->name);
- else
- /* +option or -option */
- fprintf (stderr,
- "%s: option `%c%s' doesn't allow an argument\n",
- argv[0], argv[optind - 1][0], pfound->name);
- }
+ if (argv[optind - 1][1] == '-')
+ /* --option */
+ fprintf (stderr,
+ _("%s: option `--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+ else
+ /* +option or -option */
+ fprintf (stderr,
+ _("%s: option `%c%s' doesn't allow an argument\n"),
+ argv[0], argv[optind - 1][0], pfound->name);
+
nextchar += strlen (nextchar);
+
+ optopt = pfound->val;
return '?';
}
}
@@ -519,9 +620,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else
{
if (opterr)
- fprintf (stderr, "%s: option `%s' requires an argument\n",
- argv[0], argv[optind - 1]);
+ fprintf (stderr,
+ _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
+ optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
@@ -535,34 +638,33 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
}
return pfound->val;
}
+
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-'
-#ifdef GETOPT_COMPAT
- || argv[optind][0] == '+'
-#endif /* GETOPT_COMPAT */
|| my_index (optstring, *nextchar) == NULL)
{
if (opterr)
{
if (argv[optind][1] == '-')
/* --option */
- fprintf (stderr, "%s: unrecognized option `--%s'\n",
+ fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
argv[0], nextchar);
else
/* +option or -option */
- fprintf (stderr, "%s: unrecognized option `%c%s'\n",
+ fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *) "";
optind++;
+ optopt = 0;
return '?';
}
}
- /* Look at and handle the next option-character. */
+ /* Look at and handle the next short option-character. */
{
char c = *nextchar++;
@@ -576,16 +678,13 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (opterr)
{
-#if 0
- if (c < 040 || c >= 0177)
- fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
+ if (posixly_correct)
+ /* 1003.2 specifies the format of this message. */
+ fprintf (stderr, _("%s: illegal option -- %c\n"),
argv[0], c);
else
- fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
-#else
- /* 1003.2 specifies the format of this message. */
- fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
-#endif
+ fprintf (stderr, _("%s: invalid option -- %c\n"),
+ argv[0], c);
}
optopt = c;
return '?';
@@ -601,7 +700,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
optind++;
}
else
- optarg = 0;
+ optarg = NULL;
nextchar = NULL;
}
else
@@ -618,14 +717,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (opterr)
{
-#if 0
- fprintf (stderr, "%s: option `-%c' requires an argument\n",
- argv[0], c);
-#else
/* 1003.2 specifies the format of this message. */
- fprintf (stderr, "%s: option requires an argument -- %c\n",
- argv[0], c);
-#endif
+ fprintf (stderr,
+ _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
diff --git a/getopt.h b/getopt.h
index 45541f5..0de1881 100644
--- a/getopt.h
+++ b/getopt.h
@@ -1,5 +1,5 @@
/* Declarations for getopt.
- Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+ Copyright (C) 1989, 90, 91, 92, 93, 94 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -13,7 +13,8 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
@@ -76,7 +77,7 @@ extern int optopt;
struct option
{
-#if __STDC__
+#if defined (__STDC__) && __STDC__
const char *name;
#else
char *name;
@@ -94,15 +95,15 @@ struct option
#define required_argument 1
#define optional_argument 2
-#if __STDC__
-#if defined(__GNU_LIBRARY__)
+#if defined (__STDC__) && __STDC__
+#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
#else /* not __GNU_LIBRARY__ */
extern int getopt ();
-#endif /* not __GNU_LIBRARY__ */
+#endif /* __GNU_LIBRARY__ */
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
@@ -120,7 +121,7 @@ extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
-#endif /* not __STDC__ */
+#endif /* __STDC__ */
#ifdef __cplusplus
}
diff --git a/getopt1.c b/getopt1.c
index a32615c..9d394e6 100644
--- a/getopt1.c
+++ b/getopt1.c
@@ -1,5 +1,5 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
- Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 1993, 1994
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
@@ -14,17 +14,22 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include "getopt.h"
-#if !__STDC__ && !defined(const) && IN_GCC
+#if !defined (__STDC__) || !__STDC__
+/* This is a separate conditional since some stdc systems
+ reject `defined (const)'. */
+#ifndef const
#define const
#endif
+#endif
#include <stdio.h>
diff --git a/inp.c b/inp.c
index c99054f..7bf497f 100644
--- a/inp.c
+++ b/inp.c
@@ -1,32 +1,64 @@
-/* $Header: inp.c,v 2.0.1.1 88/06/03 15:06:13 lwall Locked $
- *
- * $Log: inp.c,v $
- * Revision 2.0.1.1 88/06/03 15:06:13 lwall
- * patch10: made a little smarter about sccs files
- *
- * Revision 2.0 86/09/17 15:37:02 lwall
- * Baseline for netwide release.
- *
- */
-
-#include "EXTERN.h"
-#include "common.h"
-#include "util.h"
-#include "pch.h"
-#include "INTERN.h"
-#include "inp.h"
+/* inputting files to be patched */
+
+/* $Id: inp.c,v 1.9 1997/04/17 16:15:48 eggert Exp $ */
+
+/*
+Copyright 1986, 1988 Larry Wall
+Copyright 1991, 1992, 1993, 1997 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#define XTERN extern
+#include <common.h>
+#include <backupfile.h>
+#include <pch.h>
+#include <util.h>
+#undef XTERN
+#define XTERN
+#include <inp.h>
+
+#define SCCSPREFIX "s."
+#define GET "get '%s'"
+#define GET_LOCKED "get -e '%s'"
+#define SCCSDIFF "get -p '%s' | diff - '%s%s' >/dev/null"
+
+#define RCSSUFFIX ",v"
+#define CHECKOUT "co '%s%s'"
+#define CHECKOUT_LOCKED "co -l '%s%s'"
+#define RCSDIFF "rcsdiff '%s%s' > /dev/null"
/* Input-file-with-indexable-lines abstract type */
-static long i_size; /* size of the input file */
-static char *i_womp; /* plan a buffer for entire file */
-static char **i_ptr; /* pointers to lines in i_womp */
+static char const **i_ptr; /* pointers to lines in plan A buffer */
+static size_t tibufsize; /* size of plan b buffers */
+#ifndef TIBUFSIZE_MINIMUM
+#define TIBUFSIZE_MINIMUM (8 * 1024) /* minimum value for tibufsize */
+#endif
static int tifd = -1; /* plan b virtual string array */
static char *tibuf[2]; /* plan b buffers */
static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */
static LINENUM lines_per_buf; /* how many lines per buffer */
-static int tireclen; /* length of records in tmp file */
+static size_t tireclen; /* length of records in tmp file */
+static size_t last_line_size; /* size of last input line */
+
+static bool plan_a PARAMS ((char const *));/* yield FALSE if memory runs out */
+static void plan_b PARAMS ((char const *));
+static void report_revision PARAMS ((int));
/* New patch--prepare to edit another file. */
@@ -34,23 +66,16 @@ void
re_input()
{
if (using_plan_a) {
- i_size = 0;
-#ifndef lint
- if (i_ptr != Null(char**))
- free((char *)i_ptr);
-#endif
- if (i_womp != Nullch)
- free(i_womp);
- i_womp = Nullch;
- i_ptr = Null(char **);
+ if (i_ptr) {
+ free (i_ptr);
+ i_ptr = 0;
+ }
}
else {
- using_plan_a = TRUE; /* maybe the next one is smaller */
- Close(tifd);
+ close (tifd);
tifd = -1;
free(tibuf[0]);
- free(tibuf[1]);
- tibuf[0] = tibuf[1] = Nullch;
+ tibuf[0] = 0;
tiline[0] = tiline[1] = -1;
tireclen = 0;
}
@@ -62,270 +87,393 @@ void
scan_input(filename)
char *filename;
{
- if (!plan_a(filename))
+ using_plan_a = plan_a (filename);
+ if (!using_plan_a)
plan_b(filename);
- if (verbose) {
- say3("Patching file %s using Plan %s...\n", filename,
- (using_plan_a ? "A" : "B") );
+ switch (verbosity)
+ {
+ case SILENT:
+ break;
+
+ case VERBOSE:
+ say ("Patching file %s using Plan %s...\n",
+ filename, using_plan_a ? "A" : "B");
+ break;
+
+ case DEFAULT_VERBOSITY:
+ say ("patching file %s\n", filename);
+ break;
+ }
+}
+
+/* Report whether a desired revision was found. */
+
+static void
+report_revision (found_revision)
+ int found_revision;
+{
+ if (found_revision)
+ {
+ if (verbosity == VERBOSE)
+ say ("Good. This file appears to be the %s version.\n", revision);
+ }
+ else if (force)
+ {
+ if (verbosity != SILENT)
+ say ("Warning: this file doesn't appear to be the %s version--patching anyway.\n",
+ revision);
+ }
+ else if (batch)
+ {
+ fatal ("this file doesn't appear to be the %s version--aborting.",
+ revision);
+ }
+ else
+ {
+ ask ("This file doesn't appear to be the %s version--patch anyway? [n] ",
+ revision);
+ if (*buf != 'y')
+ fatal ("aborted");
}
}
-/* Try keeping everything in memory. */
-bool
-plan_a(filename)
-char *filename;
+void
+get_input_file (filename, outname)
+ char const *filename;
+ char const *outname;
{
- int ifd, statfailed;
- Reg1 char *s;
- Reg2 LINENUM iline;
- char lbuf[MAXLINELEN];
- int output_elsewhere = strcmp(filename, outname);
-
- statfailed = stat(filename, &filestat);
- if (statfailed && ok_to_create_file) {
- if (verbose)
- say2("(Creating file %s...)\n",filename);
- makedirs(filename, TRUE);
- close(creat(filename, 0666));
- statfailed = stat(filename, &filestat);
+ int elsewhere = strcmp (filename, outname);
+ char const *dotslash;
+
+ if (inerrno == -1)
+ inerrno = stat (inname, &instat) == 0 ? 0 : errno;
+ if (inerrno && ok_to_create_file) {
+ int fd;
+ if (verbosity == VERBOSE)
+ say ("(Creating file %s...)\n", inname);
+ if (dry_run) {
+ inerrno = 0;
+ instat.st_mode = 0;
+ instat.st_size = 0;
+ return;
+ }
+ makedirs (inname);
+ fd = creat (inname, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+ if (fd < 0)
+ inerrno = errno;
+ else {
+ inerrno = fstat (fd, &instat) == 0 ? 0 : errno;
+ if (close (fd) != 0)
+ inerrno = errno;
+ }
}
+
/* For nonexistent or read-only files, look for RCS or SCCS versions. */
- if (statfailed
- || (! output_elsewhere
- && (/* No one can write to it. */
- (filestat.st_mode & 0222) == 0
- /* I can't write to it. */
- || ((filestat.st_mode & 0022) == 0
- && filestat.st_uid != myuid)))) {
+ if (backup_type == numbered_existing
+ && (inerrno
+ || (! elsewhere
+ && (/* No one can write to it. */
+ (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0
+ /* I can't write to it. */
+ || ((instat.st_mode & (S_IWGRP|S_IWOTH)) == 0
+ && instat.st_uid != getuid ()))))) {
+ register char *s;
struct stat cstat;
- char *cs = Nullch;
- char *filebase;
- int pathlen;
+ char const *cs = 0;
+ char const *filebase;
+ size_t dir_len;
+ char *lbuf = xmalloc (strlen (filename) + 100);
- filebase = basename(filename);
- pathlen = filebase - filename;
+ strcpy (lbuf, filename);
+ dir_len = base_name (lbuf) - lbuf;
+ filebase = filename + dir_len;
/* Put any leading path into `s'.
Leave room in lbuf for the diff command. */
s = lbuf + 20;
- strncpy(s, filename, pathlen);
+ memcpy (s, filename, dir_len);
+ dotslash = *filename=='-' ? "./" : "";
-#define try(f,a1,a2) (Sprintf(s + pathlen, f, a1, a2), stat(s, &cstat) == 0)
- if (( try("RCS/%s%s", filebase, RCSSUFFIX)
- || try("RCS/%s" , filebase, 0)
- || try( "%s%s", filebase, RCSSUFFIX))
+#define try1(f,a1) (sprintf (s + dir_len, f, a1), stat (s, &cstat) == 0)
+#define try2(f,a1,a2) (sprintf (s + dir_len, f, a1,a2), stat (s, &cstat) == 0)
+ if (( try2 ("RCS/%s%s", filebase, RCSSUFFIX)
+ || try1 ("RCS/%s" , filebase)
+ || try2 ( "%s%s", filebase, RCSSUFFIX))
&&
/* Check that RCS file is not working file.
Some hosts don't report file name length errors. */
- (statfailed
- || ( (filestat.st_dev ^ cstat.st_dev)
- | (filestat.st_ino ^ cstat.st_ino)))) {
- Sprintf(buf, output_elsewhere?CHECKOUT:CHECKOUT_LOCKED, filename);
- Sprintf(lbuf, RCSDIFF, filename);
+ (inerrno
+ || ( (instat.st_dev ^ cstat.st_dev)
+ | (instat.st_ino ^ cstat.st_ino)))) {
+ sprintf (buf, elsewhere ? CHECKOUT : CHECKOUT_LOCKED,
+ dotslash, filename);
+ sprintf (lbuf, RCSDIFF, dotslash, filename);
cs = "RCS";
- } else if ( try("SCCS/%s%s", SCCSPREFIX, filebase)
- || try( "%s%s", SCCSPREFIX, filebase)) {
- Sprintf(buf, output_elsewhere?GET:GET_LOCKED, s);
- Sprintf(lbuf, SCCSDIFF, s, filename);
+ } else if ( try2 ("SCCS/%s%s", SCCSPREFIX, filebase)
+ || try2 ( "%s%s", SCCSPREFIX, filebase)) {
+ sprintf (buf, elsewhere ? GET : GET_LOCKED, s);
+ sprintf (lbuf, SCCSDIFF, s, dotslash, filename);
cs = "SCCS";
- } else if (statfailed)
- fatal2("can't find %s\n", filename);
+ } else if (inerrno)
+ fatal ("can't find %s", filename);
/* else we can't write to it but it's not under a version
control system, so just proceed. */
if (cs) {
- if (!statfailed) {
- if ((filestat.st_mode & 0222) != 0)
+ if (!inerrno) {
+ if ((instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0)
/* The owner can write to it. */
- fatal3("file %s seems to be locked by somebody else under %s\n",
+ fatal ("file %s seems to be locked by somebody else under %s",
filename, cs);
/* It might be checked out unlocked. See if it's safe to
check out the default version locked. */
- if (verbose)
- say3("Comparing file %s to default %s version...\n",
+ if (verbosity == VERBOSE)
+ say ("Comparing file %s to default %s version...\n",
filename, cs);
- if (system(lbuf))
- fatal3("can't check out file %s: differs from default %s version\n",
- filename, cs);
+ if (system (lbuf) != 0)
+ {
+ say ("warning: patching file %s, which does not match default %s version\n",
+ filename, cs);
+ cs = 0;
+ }
}
- if (verbose)
- say3("Checking out file %s from %s...\n", filename, cs);
- if (system(buf) || stat(filename, &filestat))
- fatal3("can't check out file %s from %s\n", filename, cs);
+ if (cs)
+ {
+ if (dry_run)
+ {
+ if (inerrno)
+ fatal ("Cannot dry run on nonexistent version-controlled file `%s'; invoke `%s' and try again.",
+ filename, buf);
+ }
+ else
+ {
+ if (verbosity == VERBOSE)
+ say ("Checking out file %s from %s...\n", filename, cs);
+ if (system (buf) != 0 || stat (filename, &instat) != 0)
+ fatal ("can't check out file %s from %s", filename, cs);
+ inerrno = 0;
+ }
+ }
}
+ free (lbuf);
}
- filemode = filestat.st_mode;
- if (!S_ISREG(filemode))
- fatal2("%s is not a normal file--can't patch\n", filename);
- i_size = filestat.st_size;
- if (out_of_mem) {
- set_hunkmax(); /* make sure dynamic arrays are allocated */
- out_of_mem = FALSE;
- return FALSE; /* force plan b because plan a bombed */
- }
-#ifdef lint
- i_womp = Nullch;
-#else
- i_womp = malloc((MEM)(i_size+2)); /* lint says this may alloc less than */
- /* i_size, but that's okay, I think. */
-#endif
- if (i_womp == Nullch)
- return FALSE;
- if ((ifd = open(filename, 0)) < 0)
- pfatal2("can't open file %s", filename);
-#ifndef lint
- if (read(ifd, i_womp, (int)i_size) != i_size) {
- Close(ifd); /* probably means i_size > 15 or 16 bits worth */
- free(i_womp); /* at this point it doesn't matter if i_womp was */
- return FALSE; /* undersized. */
- }
-#endif
- Close(ifd);
- if (i_size && i_womp[i_size-1] != '\n')
- i_womp[i_size++] = '\n';
- i_womp[i_size] = '\0';
+ if (!S_ISREG (instat.st_mode))
+ fatal ("%s is not a regular file--can't patch", filename);
+}
- /* count the lines in the buffer so we know how many pointers we need */
- iline = 0;
- for (s=i_womp; *s; s++) {
- if (*s == '\n')
- iline++;
- }
-#ifdef lint
- i_ptr = Null(char**);
-#else
- i_ptr = (char **)malloc((MEM)((iline + 2) * sizeof(char *)));
-#endif
- if (i_ptr == Null(char **)) { /* shucks, it was a near thing */
- free((char *)i_womp);
- return FALSE;
+/* Try keeping everything in memory. */
+
+static bool
+plan_a(filename)
+ char const *filename;
+{
+ register char const *s;
+ register char const *lim;
+ register char const **ptr;
+ register char *buffer;
+ register LINENUM iline;
+ size_t size = instat.st_size;
+ size_t allocated_bytes_per_input_byte = sizeof *i_ptr + sizeof (char);
+ size_t allocated_bytes = (size + 2) * allocated_bytes_per_input_byte;
+
+ /* Fail if arithmetic overflow occurs during size calculations,
+ or if storage isn't available. */
+ if (size != instat.st_size
+ || size + 2 < 2
+ || allocated_bytes / allocated_bytes_per_input_byte != size + 2
+ || ! (ptr = (char const **) malloc (allocated_bytes)))
+ return FALSE;
+
+ buffer = (char *) (ptr + (size + 2));
+
+ /* Read the input file, but don't bother reading it if it's empty.
+ During dry runs, empty files may not actually exist. */
+ if (size)
+ {
+ int ifd = open (filename, O_RDONLY);
+ if (ifd < 0)
+ pfatal ("can't open file %s", filename);
+ if (read (ifd, buffer, size) != size)
+ {
+ /* Perhaps size is too large for this host. */
+ close (ifd);
+ free (ptr);
+ return FALSE;
+ }
+ if (close (ifd) != 0)
+ read_fatal ();
}
-
- /* now scan the buffer and build pointer array */
-
- iline = 1;
- i_ptr[iline] = i_womp;
- for (s=i_womp; *s; s++) {
- if (*s == '\n')
- i_ptr[++iline] = s+1; /* these are NOT null terminated */
+
+ /* Scan the buffer and build array of pointers to lines. */
+ iline = 0;
+ lim = buffer + size;
+ for (s = buffer; ; s++)
+ {
+ ptr[++iline] = s;
+ if (! (s = (char *) memchr (s, '\n', lim - s)))
+ break;
}
- input_lines = iline - 1;
+ if (size && lim[-1] != '\n')
+ ptr[++iline] = lim;
+ input_lines = iline - 1;
- /* now check for revision, if any */
+ if (revision)
+ {
+ char const *rev = revision;
+ int rev0 = rev[0];
+ int found_revision = 0;
+ size_t revlen = strlen (rev);
- if (revision != Nullch) {
- if (!rev_in_string(i_womp)) {
- if (force) {
- if (verbose)
- say2(
-"Warning: this file doesn't appear to be the %s version--patching anyway.\n",
- revision);
- }
- else if (batch) {
- fatal2(
-"this file doesn't appear to be the %s version--aborting.\n", revision);
- }
- else {
- ask2(
-"This file doesn't appear to be the %s version--patch anyway? [n] ",
- revision);
- if (*buf != 'y')
- fatal1("aborted\n");
- }
+ if (revlen <= size)
+ {
+ char const *limrev = lim - revlen;
+
+ for (s = buffer; (s = (char *) memchr (s, rev0, limrev - s)); s++)
+ if (memcmp (s, rev, revlen) == 0
+ && (s == buffer || ISSPACE ((unsigned char) s[-1]))
+ && (s + 1 == limrev || ISSPACE ((unsigned char) s[revlen])))
+ {
+ found_revision = 1;
+ break;
+ }
}
- else if (verbose)
- say2("Good. This file appears to be the %s version.\n",
- revision);
+
+ report_revision (found_revision);
}
- return TRUE; /* plan a will work */
+
+ /* Plan A will work. */
+ i_ptr = ptr;
+ return TRUE;
}
/* Keep (virtually) nothing in memory. */
-void
+static void
plan_b(filename)
-char *filename;
+ char const *filename;
{
- Reg3 FILE *ifp;
- Reg1 int i = 0;
- Reg2 int maxlen = 1;
- Reg4 bool found_revision = (revision == Nullch);
-
- using_plan_a = FALSE;
- if ((ifp = fopen(filename, "r")) == Nullfp)
- pfatal2("can't open file %s", filename);
- if ((tifd = creat(TMPINNAME, 0666)) < 0)
- pfatal2("can't open file %s", TMPINNAME);
- while (fgets(buf, sizeof buf, ifp) != Nullch) {
- if (revision != Nullch && !found_revision && rev_in_string(buf))
- found_revision = TRUE;
- if ((i = strlen(buf)) > maxlen)
- maxlen = i; /* find longest line */
- }
- if (revision != Nullch) {
- if (!found_revision) {
- if (force) {
- if (verbose)
- say2(
-"Warning: this file doesn't appear to be the %s version--patching anyway.\n",
- revision);
- }
- else if (batch) {
- fatal2(
-"this file doesn't appear to be the %s version--aborting.\n", revision);
- }
- else {
- ask2(
-"This file doesn't appear to be the %s version--patch anyway? [n] ",
- revision);
- if (*buf != 'y')
- fatal1("aborted\n");
+ register FILE *ifp;
+ register int c;
+ register size_t len;
+ register size_t maxlen;
+ register int found_revision;
+ register size_t i;
+ register char const *rev;
+ register size_t revlen;
+ register LINENUM line;
+
+ if (dry_run)
+ filename = "/dev/null";
+ if (! (ifp = fopen (filename, "r")))
+ pfatal ("can't open file %s", filename);
+ tifd = creat (TMPINNAME, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+ if (tifd < 0)
+ pfatal ("can't open file %s", TMPINNAME);
+ i = 0;
+ len = 0;
+ maxlen = 1;
+ rev = revision;
+ found_revision = !rev;
+ revlen = rev ? strlen (rev) : 0;
+
+ while ((c = getc (ifp)) != EOF)
+ {
+ len++;
+
+ if (c == '\n')
+ {
+ if (maxlen < len)
+ maxlen = len;
+ len = 0;
+ }
+
+ if (!found_revision)
+ {
+ if (i == revlen)
+ {
+ found_revision = ISSPACE ((unsigned char) c);
+ i = (size_t) -1;
}
+ else if (i != (size_t) -1)
+ i = rev[i]==c ? i + 1 : (size_t) -1;
+
+ if (i == (size_t) -1 && ISSPACE ((unsigned char) c))
+ i = 0;
}
- else if (verbose)
- say2("Good. This file appears to be the %s version.\n",
- revision);
}
- Fseek(ifp, 0L, 0); /* rewind file */
- lines_per_buf = BUFFERSIZE / maxlen;
- tireclen = maxlen;
- tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
- tibuf[1] = malloc((MEM)(BUFFERSIZE + 1));
- if (tibuf[1] == Nullch)
- fatal1("out of memory\n");
- for (i=1; ; i++) {
- if (! (i % lines_per_buf)) /* new block */
- if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
- pfatal1("can't write temp file");
- if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp)
- == Nullch) {
- input_lines = i - 1;
- if (i % lines_per_buf)
- if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
- pfatal1("can't write temp file");
- break;
+
+ if (revision)
+ report_revision (found_revision);
+ Fseek (ifp, (off_t) 0, SEEK_SET); /* rewind file */
+ for (tibufsize = TIBUFSIZE_MINIMUM; tibufsize < maxlen; tibufsize <<= 1)
+ continue;
+ lines_per_buf = tibufsize / maxlen;
+ tireclen = maxlen;
+ tibuf[0] = xmalloc (2 * tibufsize);
+ tibuf[1] = tibuf[0] + tibufsize;
+
+ for (line = 1; ; line++)
+ {
+ char *p = tibuf[0] + maxlen * (line % lines_per_buf);
+ char const *p0 = p;
+ if (! (line % lines_per_buf)) /* new block */
+ if (write (tifd, tibuf[0], tibufsize) != tibufsize)
+ write_fatal ();
+ if ((c = getc (ifp)) == EOF)
+ break;
+
+ for (;;)
+ {
+ *p++ = c;
+ if (c == '\n')
+ {
+ last_line_size = p - p0;
+ break;
+ }
+
+ if ((c = getc (ifp)) == EOF)
+ {
+ last_line_size = p - p0;
+ line++;
+ goto EOF_reached;
+ }
}
}
- Fclose(ifp);
- Close(tifd);
- if ((tifd = open(TMPINNAME, 0)) < 0) {
- pfatal2("can't reopen file %s", TMPINNAME);
- }
+ EOF_reached:
+ if (ferror (ifp) || fclose (ifp) != 0)
+ read_fatal ();
+
+ if (line % lines_per_buf != 0)
+ if (write (tifd, tibuf[0], tibufsize) != tibufsize)
+ write_fatal ();
+ input_lines = line - 1;
+ if (close (tifd) != 0)
+ write_fatal ();
+ if ((tifd = open (TMPINNAME, O_RDONLY)) < 0)
+ pfatal ("can't reopen file %s", TMPINNAME);
}
-/* Fetch a line from the input file, \n terminated, not necessarily \0. */
+/* Fetch a line from the input file. */
-char *
-ifetch(line,whichbuf)
-Reg1 LINENUM line;
+char const *
+ifetch (line, whichbuf, psize)
+register LINENUM line;
int whichbuf; /* ignored when file in memory */
+size_t *psize;
{
- if (line < 1 || line > input_lines)
+ register char const *q;
+ register char const *p;
+
+ if (line < 1 || line > input_lines) {
+ *psize = 0;
return "";
- if (using_plan_a)
- return i_ptr[line];
- else {
+ }
+ if (using_plan_a) {
+ p = i_ptr[line];
+ *psize = i_ptr[line + 1] - p;
+ return p;
+ } else {
LINENUM offline = line % lines_per_buf;
LINENUM baseline = line - offline;
@@ -335,35 +483,19 @@ int whichbuf; /* ignored when file in memory */
whichbuf = 1;
else {
tiline[whichbuf] = baseline;
-#ifndef lint /* complains of long accuracy */
- Lseek(tifd, (long)baseline / lines_per_buf * BUFFERSIZE, 0);
-#endif
- if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
- pfatal2("error reading tmp file %s", TMPINNAME);
+ if (lseek (tifd, (off_t) (baseline/lines_per_buf * tibufsize),
+ SEEK_SET) == -1
+ || read (tifd, tibuf[whichbuf], tibufsize) < 0)
+ read_fatal ();
}
- return tibuf[whichbuf] + (tireclen*offline);
- }
-}
-
-/* True if the string argument contains the revision number we want. */
-
-bool
-rev_in_string(string)
-char *string;
-{
- Reg1 char *s;
- Reg2 int patlen;
-
- if (revision == Nullch)
- return TRUE;
- patlen = strlen(revision);
- if (strnEQ(string,revision,patlen) && isspace(string[patlen]))
- return TRUE;
- for (s = string; *s; s++) {
- if (isspace(*s) && strnEQ(s+1, revision, patlen) &&
- isspace(s[patlen+1] )) {
- return TRUE;
+ p = tibuf[whichbuf] + (tireclen*offline);
+ if (line == input_lines)
+ *psize = last_line_size;
+ else {
+ for (q = p; *q++ != '\n'; )
+ continue;
+ *psize = q - p;
}
+ return p;
}
- return FALSE;
}
diff --git a/inp.h b/inp.h
index c6d2a91..fd636bf 100644
--- a/inp.h
+++ b/inp.h
@@ -1,18 +1,10 @@
-/* $Header: inp.h,v 2.0 86/09/17 15:37:25 lwall Exp $
- *
- * $Log: inp.h,v $
- * Revision 2.0 86/09/17 15:37:25 lwall
- * Baseline for netwide release.
- *
- */
+/* inputting files to be patched */
-EXT LINENUM input_lines INIT(0); /* how long is input file in lines */
-EXT LINENUM last_frozen_line INIT(0); /* how many input lines have been */
- /* irretractibly output */
+/* $Id: inp.h,v 1.4 1997/04/07 01:07:00 eggert Exp $ */
-bool rev_in_string();
-void scan_input();
-bool plan_a(); /* returns false if insufficient memory */
-void plan_b();
-char *ifetch();
+XTERN LINENUM input_lines; /* how long is input file in lines */
+char const *ifetch PARAMS ((LINENUM, int, size_t *));
+void get_input_file PARAMS ((char const *, char const *));
+void re_input PARAMS ((void));
+void scan_input PARAMS ((char *));
diff --git a/install-sh b/install-sh
new file mode 100644
index 0000000..2c212cc
--- /dev/null
+++ b/install-sh
@@ -0,0 +1,250 @@
+#! /bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission. M.I.T. makes no representations about the
+# suitability of this software for any purpose. It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+#
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+ case $1 in
+ -c) instcmd="$cpprog"
+ shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd="$stripprog"
+ shift
+ continue;;
+
+ -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+ shift
+ continue;;
+
+ -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+ shift
+ continue;;
+
+ *) if [ x"$src" = x ]
+ then
+ src=$1
+ else
+ # this colon is to work around a 386BSD /bin/sh bug
+ :
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if [ x"$src" = x ]
+then
+ echo "install: no input file specified"
+ exit 1
+else
+ true
+fi
+
+if [ x"$dir_arg" != x ]; then
+ dst=$src
+ src=""
+
+ if [ -d $dst ]; then
+ instcmd=:
+ else
+ instcmd=mkdir
+ fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad
+# if $src (and thus $dsttmp) contains '*'.
+
+ if [ -f $src -o -d $src ]
+ then
+ true
+ else
+ echo "install: $src does not exist"
+ exit 1
+ fi
+
+ if [ x"$dst" = x ]
+ then
+ echo "install: no destination specified"
+ exit 1
+ else
+ true
+ fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+ if [ -d $dst ]
+ then
+ dst="$dst"/`basename $src`
+ else
+ true
+ fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+# this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+ pathcomp="${pathcomp}${1}"
+ shift
+
+ if [ ! -d "${pathcomp}" ] ;
+ then
+ $mkdirprog "${pathcomp}"
+ else
+ true
+ fi
+
+ pathcomp="${pathcomp}/"
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+ $doit $instcmd $dst &&
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+ if [ x"$transformarg" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ dstfile=`basename $dst $transformbasename |
+ sed $transformarg`$transformbasename
+ fi
+
+# don't allow the sed command to completely eliminate the filename
+
+ if [ x"$dstfile" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ true
+ fi
+
+# Make a temp file name in the proper directory.
+
+ dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+ $doit $instcmd $src $dsttmp &&
+
+ trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing. If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+
+# Now rename the file to the real destination.
+
+ $doit $rmcmd -f $dstdir/$dstfile &&
+ $doit $mvcmd $dsttmp $dstdir/$dstfile
+
+fi &&
+
+
+exit 0
diff --git a/memchr.c b/memchr.c
new file mode 100644
index 0000000..c75217f
--- /dev/null
+++ b/memchr.c
@@ -0,0 +1,199 @@
+/* Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.
+ Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
+ with help from Dan Sahlin (dan@sics.se) and
+ commentary by Jim Blandy (jimb@ai.mit.edu);
+ adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
+ and implemented by Roland McGrath (roland@ai.mit.edu).
+
+NOTE: The canonical source of this file is maintained with the GNU C Library.
+Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+USA. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#undef __ptr_t
+#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
+# define __ptr_t void *
+#else /* Not C++ or ANSI C. */
+# define __ptr_t char *
+#endif /* C++ or ANSI C. */
+
+#if defined (_LIBC)
+# include <string.h>
+#endif
+
+#if defined (HAVE_LIMITS_H) || defined (_LIBC)
+# include <limits.h>
+#endif
+
+#define LONG_MAX_32_BITS 2147483647
+
+#ifndef LONG_MAX
+#define LONG_MAX LONG_MAX_32_BITS
+#endif
+
+#include <sys/types.h>
+
+
+/* Search no more than N bytes of S for C. */
+
+__ptr_t
+memchr (s, c, n)
+ const __ptr_t s;
+ int c;
+ size_t n;
+{
+ const unsigned char *char_ptr;
+ const unsigned long int *longword_ptr;
+ unsigned long int longword, magic_bits, charmask;
+
+ c = (unsigned char) c;
+
+ /* Handle the first few characters by reading one character at a time.
+ Do this until CHAR_PTR is aligned on a longword boundary. */
+ for (char_ptr = (const unsigned char *) s;
+ n > 0 && ((unsigned long int) char_ptr
+ & (sizeof (longword) - 1)) != 0;
+ --n, ++char_ptr)
+ if (*char_ptr == c)
+ return (__ptr_t) char_ptr;
+
+ /* All these elucidatory comments refer to 4-byte longwords,
+ but the theory applies equally well to 8-byte longwords. */
+
+ longword_ptr = (unsigned long int *) char_ptr;
+
+ /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
+ the "holes." Note that there is a hole just to the left of
+ each byte, with an extra at the end:
+
+ bits: 01111110 11111110 11111110 11111111
+ bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
+
+ The 1-bits make sure that carries propagate to the next 0-bit.
+ The 0-bits provide holes for carries to fall into. */
+
+ if (sizeof (longword) != 4 && sizeof (longword) != 8)
+ abort ();
+
+#if LONG_MAX <= LONG_MAX_32_BITS
+ magic_bits = 0x7efefeff;
+#else
+ magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
+#endif
+
+ /* Set up a longword, each of whose bytes is C. */
+ charmask = c | (c << 8);
+ charmask |= charmask << 16;
+#if LONG_MAX > LONG_MAX_32_BITS
+ charmask |= charmask << 32;
+#endif
+
+ /* Instead of the traditional loop which tests each character,
+ we will test a longword at a time. The tricky part is testing
+ if *any of the four* bytes in the longword in question are zero. */
+ while (n >= sizeof (longword))
+ {
+ /* We tentatively exit the loop if adding MAGIC_BITS to
+ LONGWORD fails to change any of the hole bits of LONGWORD.
+
+ 1) Is this safe? Will it catch all the zero bytes?
+ Suppose there is a byte with all zeros. Any carry bits
+ propagating from its left will fall into the hole at its
+ least significant bit and stop. Since there will be no
+ carry from its most significant bit, the LSB of the
+ byte to the left will be unchanged, and the zero will be
+ detected.
+
+ 2) Is this worthwhile? Will it ignore everything except
+ zero bytes? Suppose every byte of LONGWORD has a bit set
+ somewhere. There will be a carry into bit 8. If bit 8
+ is set, this will carry into bit 16. If bit 8 is clear,
+ one of bits 9-15 must be set, so there will be a carry
+ into bit 16. Similarly, there will be a carry into bit
+ 24. If one of bits 24-30 is set, there will be a carry
+ into bit 31, so all of the hole bits will be changed.
+
+ The one misfire occurs when bits 24-30 are clear and bit
+ 31 is set; in this case, the hole at bit 31 is not
+ changed. If we had access to the processor carry flag,
+ we could close this loophole by putting the fourth hole
+ at bit 32!
+
+ So it ignores everything except 128's, when they're aligned
+ properly.
+
+ 3) But wait! Aren't we looking for C, not zero?
+ Good point. So what we do is XOR LONGWORD with a longword,
+ each of whose bytes is C. This turns each byte that is C
+ into a zero. */
+
+ longword = *longword_ptr++ ^ charmask;
+
+ /* Add MAGIC_BITS to LONGWORD. */
+ if ((((longword + magic_bits)
+
+ /* Set those bits that were unchanged by the addition. */
+ ^ ~longword)
+
+ /* Look at only the hole bits. If any of the hole bits
+ are unchanged, most likely one of the bytes was a
+ zero. */
+ & ~magic_bits) != 0)
+ {
+ /* Which of the bytes was C? If none of them were, it was
+ a misfire; continue the search. */
+
+ const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);
+
+ if (cp[0] == c)
+ return (__ptr_t) cp;
+ if (cp[1] == c)
+ return (__ptr_t) &cp[1];
+ if (cp[2] == c)
+ return (__ptr_t) &cp[2];
+ if (cp[3] == c)
+ return (__ptr_t) &cp[3];
+#if LONG_MAX > 2147483647
+ if (cp[4] == c)
+ return (__ptr_t) &cp[4];
+ if (cp[5] == c)
+ return (__ptr_t) &cp[5];
+ if (cp[6] == c)
+ return (__ptr_t) &cp[6];
+ if (cp[7] == c)
+ return (__ptr_t) &cp[7];
+#endif
+ }
+
+ n -= sizeof (longword);
+ }
+
+ char_ptr = (const unsigned char *) longword_ptr;
+
+ while (n-- > 0)
+ {
+ if (*char_ptr == c)
+ return (__ptr_t) char_ptr;
+ else
+ ++char_ptr;
+ }
+
+ return 0;
+}
diff --git a/mkinstalldirs b/mkinstalldirs
new file mode 100644
index 0000000..a01481b
--- /dev/null
+++ b/mkinstalldirs
@@ -0,0 +1,40 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain
+
+# $Id: mkinstalldirs,v 1.10 1996/05/03 07:37:52 friedman Exp $
+
+errstatus=0
+
+for file
+do
+ set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+ shift
+
+ pathcomp=
+ for d
+ do
+ pathcomp="$pathcomp$d"
+ case "$pathcomp" in
+ -* ) pathcomp=./$pathcomp ;;
+ esac
+
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp" 1>&2
+
+ mkdir "$pathcomp" || lasterr=$?
+
+ if test ! -d "$pathcomp"; then
+ errstatus=$lasterr
+ fi
+ fi
+
+ pathcomp="$pathcomp/"
+ done
+done
+
+exit $errstatus
+
+# mkinstalldirs ends here
diff --git a/patch.c b/patch.c
index 77d98e7..daf6342 100644
--- a/patch.c
+++ b/patch.c
@@ -1,303 +1,255 @@
-char rcsid[] =
- "$Header: patch.c,v 2.0.2.0 90/05/01 22:17:50 davison Locked $";
-
-/* patch - a program to apply diffs to original files
- *
- * Copyright 1986, Larry Wall
- *
- * This program may be copied as long as you don't try to make any
- * money off of it, or pretend that you wrote it.
- *
- * $Log: patch.c,v $
- * Revision 2.0.2.0 90/05/01 22:17:50 davison
- * patch12u: unidiff support added
- *
- * Revision 2.0.1.6 88/06/22 20:46:39 lwall
- * patch12: rindex() wasn't declared
- *
- * Revision 2.0.1.5 88/06/03 15:09:37 lwall
- * patch10: exit code improved.
- * patch10: better support for non-flexfilenames.
- *
- * Revision 2.0.1.4 87/02/16 14:00:04 lwall
- * Short replacement caused spurious "Out of sync" message.
- *
- * Revision 2.0.1.3 87/01/30 22:45:50 lwall
- * Improved diagnostic on sync error.
- * Moved do_ed_script() to pch.c.
- *
- * Revision 2.0.1.2 86/11/21 09:39:15 lwall
- * Fuzz factor caused offset of installed lines.
- *
- * Revision 2.0.1.1 86/10/29 13:10:22 lwall
- * Backwards search could terminate prematurely.
- *
- * Revision 2.0 86/09/17 15:37:32 lwall
- * Baseline for netwide release.
- *
- * Revision 1.5 86/08/01 20:53:24 lwall
- * Changed some %d's to %ld's.
- * Linted.
- *
- * Revision 1.4 86/08/01 19:17:29 lwall
- * Fixes for machines that can't vararg.
- * Added fuzz factor.
- * Generalized -p.
- * General cleanup.
- *
- * 85/08/15 van%ucbmonet@berkeley
- * Changes for 4.3bsd diff -c.
- *
- * Revision 1.3 85/03/26 15:07:43 lwall
- * Frozen.
- *
- * Revision 1.2.1.9 85/03/12 17:03:35 lwall
- * Changed pfp->_file to fileno(pfp).
- *
- * Revision 1.2.1.8 85/03/12 16:30:43 lwall
- * Check i_ptr and i_womp to make sure they aren't null before freeing.
- * Also allow ed output to be suppressed.
- *
- * Revision 1.2.1.7 85/03/12 15:56:13 lwall
- * Added -p option from jromine@uci-750a.
- *
- * Revision 1.2.1.6 85/03/12 12:12:51 lwall
- * Now checks for normalness of file to patch.
- *
- * Revision 1.2.1.5 85/03/12 11:52:12 lwall
- * Added -D (#ifdef) option from joe@fluke.
- *
- * Revision 1.2.1.4 84/12/06 11:14:15 lwall
- * Made smarter about SCCS subdirectories.
- *
- * Revision 1.2.1.3 84/12/05 11:18:43 lwall
- * Added -l switch to do loose string comparison.
- *
- * Revision 1.2.1.2 84/12/04 09:47:13 lwall
- * Failed hunk count not reset on multiple patch file.
- *
- * Revision 1.2.1.1 84/12/04 09:42:37 lwall
- * Branch for sdcrdcf changes.
- *
- * Revision 1.2 84/11/29 13:29:51 lwall
- * Linted. Identifiers uniqified. Fixed i_ptr malloc() bug. Fixed
- * multiple calls to mktemp(). Will now work on machines that can only
- * read 32767 chars. Added -R option for diffs with new and old swapped.
- * Various cosmetic changes.
- *
- * Revision 1.1 84/11/09 17:03:58 lwall
- * Initial revision
- *
- */
-
-#include "INTERN.h"
-#include "common.h"
-#include "EXTERN.h"
-#include "version.h"
-#include "util.h"
-#include "pch.h"
-#include "inp.h"
-#include "backupfile.h"
-#include "getopt.h"
+/* patch - a program to apply diffs to original files */
+
+/* $Id: patch.c,v 1.11 1997/04/14 05:32:30 eggert Exp $ */
+
+/*
+Copyright 1984, 1985, 1986, 1987, 1988 Larry Wall
+Copyright 1989, 1990, 1991, 1992, 1993, 1997 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#define XTERN
+#include <common.h>
+#undef XTERN
+#define XTERN extern
+#include <argmatch.h>
+#include <backupfile.h>
+#include <getopt.h>
+#include <inp.h>
+#include <pch.h>
+#include <util.h>
+#include <version.h>
/* procedures */
-void reinitialize_almost_everything();
-void get_some_switches();
-LINENUM locate_hunk();
-void abort_hunk();
-void apply_hunk();
-void init_output();
-void init_reject();
-void copy_till();
-void spew_output();
-void dump_line();
-bool patch_match();
-bool similar();
-void re_input();
-void my_exit();
+static LINENUM locate_hunk PARAMS ((LINENUM, LINENUM));
+static bool apply_hunk PARAMS ((bool *, LINENUM));
+static bool copy_till PARAMS ((bool *, LINENUM));
+static bool patch_match PARAMS ((LINENUM, LINENUM, LINENUM, LINENUM));
+static bool similar PARAMS ((char const *, size_t, char const *, size_t));
+static bool spew_output PARAMS ((bool *));
+static char const *make_temp PARAMS ((int));
+static int numeric_optarg PARAMS ((char const *));
+static void abort_hunk PARAMS ((void));
+static void cleanup PARAMS ((void));
+static void get_some_switches PARAMS ((void));
+static void init_output PARAMS ((char const *));
+static void init_reject PARAMS ((char const *));
+static void reinitialize_almost_everything PARAMS ((void));
+static void usage PARAMS ((FILE *, int)) __attribute__((noreturn));
/* TRUE if -E was specified on command line. */
-static int remove_empty_files = FALSE;
+static int remove_empty_files;
/* TRUE if -R was specified on command line. */
-static int reverse_flag_specified = FALSE;
+static int reverse_flag_specified;
+
+static bool backup;
+static bool noreverse;
+
+/* how many input lines have been irretractably output */
+static LINENUM last_frozen_line;
+
+static char const *do_defines; /* symbol to patch using ifdef, ifndef, etc. */
+static char const if_defined[] = "\n#ifdef %s\n";
+static char const not_defined[] = "#ifndef %s\n";
+static char const else_defined[] = "\n#else\n";
+static char const end_defined[] = "\n#endif /* %s */\n";
+
+static int Argc;
+static char * const *Argv;
+
+static FILE *ofp; /* output file pointer */
+static FILE *rejfp; /* reject file pointer */
+
+static char *output;
+static char const *patchname;
+static char *rejname;
+static char const * volatile TMPREJNAME;
+
+static LINENUM last_offset;
+static LINENUM maxfuzz = 2;
+
+static char serrbuf[BUFSIZ];
+
+char const program_name[] = "patch";
/* Apply a set of diffs as appropriate. */
+int main PARAMS ((int, char **));
+
int
main(argc,argv)
int argc;
char **argv;
{
- LINENUM where;
- LINENUM newwhere;
- LINENUM fuzz;
- LINENUM mymaxfuzz;
- int hunk = 0;
- int failed = 0;
- int failtotal = 0;
- bool rev_okayed = 0;
- int i;
+ bool somefailed = FALSE;
setbuf(stderr, serrbuf);
- for (i = 0; i<MAXFILEC; i++)
- filearg[i] = Nullch;
-
- myuid = getuid();
- /* Cons up the names of the temporary files. */
- {
- /* Directory for temporary files. */
- char *tmpdir;
- int tmpname_len;
+ bufsize = 8 * 1024;
+ buf = xmalloc (bufsize);
- tmpdir = getenv ("TMPDIR");
- if (tmpdir == NULL) {
- tmpdir = "/tmp";
- }
- tmpname_len = strlen (tmpdir) + 20;
-
- TMPOUTNAME = (char *) malloc (tmpname_len);
- strcpy (TMPOUTNAME, tmpdir);
- strcat (TMPOUTNAME, "/patchoXXXXXX");
- Mktemp(TMPOUTNAME);
-
- TMPINNAME = (char *) malloc (tmpname_len);
- strcpy (TMPINNAME, tmpdir);
- strcat (TMPINNAME, "/patchiXXXXXX");
- Mktemp(TMPINNAME);
-
- TMPREJNAME = (char *) malloc (tmpname_len);
- strcpy (TMPREJNAME, tmpdir);
- strcat (TMPREJNAME, "/patchrXXXXXX");
- Mktemp(TMPREJNAME);
-
- TMPPATNAME = (char *) malloc (tmpname_len);
- strcpy (TMPPATNAME, tmpdir);
- strcat (TMPPATNAME, "/patchpXXXXXX");
- Mktemp(TMPPATNAME);
- }
+ strippath = INT_MAX;
{
- char *v;
+ char const *v;
v = getenv ("SIMPLE_BACKUP_SUFFIX");
- if (v)
- simple_backup_suffix = v;
- else
- simple_backup_suffix = ".orig";
-#ifndef NODIR
+ if (v && *v)
+ {
+ simple_backup_suffix = v;
+ backup = TRUE;
+ }
v = getenv ("VERSION_CONTROL");
+ if (v && *v)
+ backup = TRUE;
backup_type = get_version (v); /* OK to pass NULL. */
-#endif
}
/* parse switches */
Argc = argc;
Argv = argv;
get_some_switches();
-
- /* make sure we clean up /tmp in case of disaster */
+
+ /* Cons up the names of the global temporary files. */
+ TMPOUTNAME = make_temp ('o');
+ TMPINNAME = make_temp ('i');
+ TMPREJNAME = make_temp ('r');
+ TMPPATNAME = make_temp ('p');
+
+ if (output)
+ init_output (output);
+
+ /* Make sure we clean up in case of disaster. */
set_signals(0);
for (
- open_patch_file(filearg[1]);
+ open_patch_file (patchname);
there_is_another_patch();
reinitialize_almost_everything()
) { /* for each patch in patch file */
+ int hunk = 0;
+ int failed = 0;
+ char const *outname = output ? output : inname;
+
+ if (!skip_rest_of_patch)
+ get_input_file (inname, outname);
+
+ if (diff_type == ED_DIFF) {
+ if (! dry_run)
+ do_ed_script (ofp);
+ } else {
+ int got_hunk;
+ bool rev_okayed = FALSE;
+ bool after_newline = TRUE;
- if (outname == Nullch)
- outname = savestr(filearg[0]);
-
- /* for ed script just up and do it and exit */
- if (diff_type == ED_DIFF) {
- do_ed_script();
- continue;
- }
-
/* initialize the patched file */
- if (!skip_rest_of_patch)
+ if (!skip_rest_of_patch && !output)
init_output(TMPOUTNAME);
-
+
/* initialize reject file */
init_reject(TMPREJNAME);
-
+
/* find out where all the lines are */
if (!skip_rest_of_patch)
- scan_input(filearg[0]);
-
+ scan_input (inname);
+
/* from here on, open no standard i/o files, because malloc */
/* might misfire and we can't catch it easily */
-
+
/* apply each hunk of patch */
- hunk = 0;
- failed = 0;
- rev_okayed = FALSE;
- out_of_mem = FALSE;
- while (another_hunk()) {
+ while (0 < (got_hunk = another_hunk (diff_type))) {
+ LINENUM where = 0; /* Pacify `gcc -Wall'. */
+ LINENUM newwhere;
+ LINENUM fuzz = 0;
+ LINENUM max_prefix_fuzz = pch_prefix_context ();
+ LINENUM max_suffix_fuzz = pch_suffix_context ();
hunk++;
- fuzz = Nulline;
- mymaxfuzz = pch_context();
- if (maxfuzz < mymaxfuzz)
- mymaxfuzz = maxfuzz;
+ if (maxfuzz < max_prefix_fuzz)
+ max_prefix_fuzz = maxfuzz;
+ if (maxfuzz < max_suffix_fuzz)
+ max_suffix_fuzz = maxfuzz;
if (!skip_rest_of_patch) {
do {
- where = locate_hunk(fuzz);
- if (hunk == 1 && where == Nulline && !(force|rev_okayed)) {
+ LINENUM prefix_fuzz =
+ fuzz < max_prefix_fuzz ? fuzz : max_prefix_fuzz;
+ LINENUM suffix_fuzz =
+ fuzz < max_suffix_fuzz ? fuzz : max_suffix_fuzz;
+ where = locate_hunk (prefix_fuzz, suffix_fuzz);
+ if (hunk == 1 && !where && !(force|rev_okayed)) {
/* dwim for reversed patch? */
if (!pch_swap()) {
- if (fuzz == Nulline)
- say1(
+ if (!fuzz)
+ say (
"Not enough memory to try swapped hunk! Assuming unswapped.\n");
continue;
}
reverse = !reverse;
- where = locate_hunk(fuzz); /* try again */
- if (where == Nulline) { /* didn't find it swapped */
- if (!pch_swap()) /* put it back to normal */
- fatal1("lost hunk on alloc error!\n");
+ /* Try again. */
+ where = locate_hunk (prefix_fuzz, suffix_fuzz);
+ if (!where) { /* didn't find it swapped */
+ if (!pch_swap()) /* put it back to normal */
+ fatal ("lost hunk on alloc error!");
reverse = !reverse;
}
else if (noreverse) {
- if (!pch_swap()) /* put it back to normal */
- fatal1("lost hunk on alloc error!\n");
+ if (!pch_swap()) /* put it back to normal */
+ fatal ("lost hunk on alloc error!");
reverse = !reverse;
- say1(
+ say (
"Ignoring previously applied (or reversed) patch.\n");
skip_rest_of_patch = TRUE;
}
else if (batch) {
- if (verbose)
- say3(
-"%seversed (or previously applied) patch detected! %s -R.",
+ if (verbosity != SILENT)
+ say (
+"%seversed (or previously applied) patch detected! %s -R.\n",
reverse ? "R" : "Unr",
reverse ? "Assuming" : "Ignoring");
}
else {
- ask3(
+ ask (
"%seversed (or previously applied) patch detected! %s -R? [y] ",
reverse ? "R" : "Unr",
reverse ? "Assume" : "Ignore");
if (*buf == 'n') {
- ask1("Apply anyway? [n] ");
+ ask ("Apply anyway? [n] ");
if (*buf == 'y')
rev_okayed = TRUE;
else
skip_rest_of_patch = TRUE;
- where = Nulline;
+ where = 0;
reverse = !reverse;
if (!pch_swap()) /* put it back to normal */
- fatal1("lost hunk on alloc error!\n");
+ fatal ("lost hunk on alloc error!");
}
}
}
- } while (!skip_rest_of_patch && where == Nulline &&
- ++fuzz <= mymaxfuzz);
+ } while (!skip_rest_of_patch && !where
+ && (++fuzz <= max_prefix_fuzz
+ || fuzz <= max_suffix_fuzz));
if (skip_rest_of_patch) { /* just got decided */
- Fclose(ofp);
- ofp = Nullfp;
+ if (ofp && !output)
+ {
+ fclose (ofp);
+ ofp = 0;
+ }
}
}
@@ -305,95 +257,115 @@ char **argv;
if (skip_rest_of_patch) {
abort_hunk();
failed++;
- if (verbose)
- say3("Hunk #%d ignored at %ld.\n", hunk, newwhere);
+ if (verbosity != SILENT)
+ say ("Hunk #%d ignored at %ld.\n", hunk, newwhere);
}
- else if (where == Nulline) {
+ else if (!where
+ || (where == 1 && ok_to_create_file && input_lines)) {
+ if (where)
+ say ("\nPatch attempted to create file `%s', which already exists.\n", inname);
abort_hunk();
failed++;
- if (verbose)
- say3("Hunk #%d failed at %ld.\n", hunk, newwhere);
+ if (verbosity != SILENT)
+ say ("Hunk #%d FAILED at %ld.\n", hunk, newwhere);
}
else {
- apply_hunk(where);
- if (verbose) {
- say3("Hunk #%d succeeded at %ld", hunk, newwhere);
+ if (! apply_hunk (&after_newline, where)) {
+ abort_hunk ();
+ failed++;
+ if (verbosity != SILENT)
+ say ("Hunk #%d FAILED at %ld.\n", hunk, newwhere);
+ } else if (verbosity == VERBOSE) {
+ say ("Hunk #%d succeeded at %ld", hunk, newwhere);
if (fuzz)
- say2(" with fuzz %ld", fuzz);
+ say (" with fuzz %ld", fuzz);
if (last_offset)
- say3(" (offset %ld line%s)",
- last_offset, last_offset==1L?"":"s");
- say1(".\n");
+ say (" (offset %ld line%s)",
+ last_offset, last_offset==1?"":"s");
+ say (".\n");
}
}
}
- if (out_of_mem && using_plan_a) {
- optind = optind_last;
- say1("\n\nRan out of memory using Plan A--trying again...\n\n");
+ if (got_hunk < 0 && using_plan_a) {
+ if (output)
+ fatal ("out of memory using Plan A");
+ say ("\n\nRan out of memory using Plan A--trying again...\n\n");
if (ofp)
- Fclose(ofp);
- ofp = Nullfp;
- if (rejfp)
- Fclose(rejfp);
- rejfp = Nullfp;
+ {
+ fclose (ofp);
+ ofp = 0;
+ }
+ fclose (rejfp);
continue;
}
-
+
assert(hunk);
-
+
/* finish spewing out the new file */
if (!skip_rest_of_patch)
- spew_output();
-
- /* and put the output where desired */
- ignore_signals();
- if (!skip_rest_of_patch) {
- struct stat statbuf;
- char *realout = outname;
-
- if (move_file(TMPOUTNAME, outname) < 0) {
- toutkeep = TRUE;
- realout = TMPOUTNAME;
- chmod(TMPOUTNAME, filemode);
- }
- else
- chmod(outname, filemode);
+ skip_rest_of_patch = ! spew_output (&after_newline);
+ }
- if (remove_empty_files && stat(realout, &statbuf) == 0
- && statbuf.st_size == 0) {
- if (verbose)
- say2("Removing %s (empty after patching).\n", realout);
- while (unlink(realout) >= 0) ; /* while is for Eunice. */
+ /* and put the output where desired */
+ ignore_signals ();
+ if (!skip_rest_of_patch && !output) {
+ struct stat statbuf;
+
+ if (remove_empty_files
+ && stat (TMPOUTNAME, &statbuf) == 0
+ && statbuf.st_size == 0)
+ {
+ if (verbosity == VERBOSE)
+ say ("Removing %s (empty after patching).\n", outname);
+ if (! dry_run)
+ unlink (outname);
}
- }
- Fclose(rejfp);
- rejfp = Nullfp;
- if (failed) {
- failtotal += failed;
- if (!*rejname) {
- Strcpy(rejname, outname);
- addext(rejname, ".rej", '#');
- }
- if (skip_rest_of_patch) {
- say4("%d out of %d hunks ignored--saving rejects to %s\n",
- failed, hunk, rejname);
+ else
+ {
+ if (! dry_run)
+ {
+ move_file (TMPOUTNAME, outname, backup);
+ chmod (outname, instat.st_mode);
+ }
}
- else {
- say4("%d out of %d hunks failed--saving rejects to %s\n",
- failed, hunk, rejname);
+ }
+ if (diff_type != ED_DIFF) {
+ if (fclose (rejfp) != 0)
+ write_fatal ();
+ if (failed) {
+ somefailed = TRUE;
+ say ("%d out of %d hunk%s %s", failed, hunk, "s" + (hunk == 1),
+ skip_rest_of_patch ? "ignored" : "FAILED");
+ if (outname) {
+ char *rej = rejname;
+ if (!rejname) {
+ rej = xmalloc (strlen (outname) + 5);
+ strcpy (rej, outname);
+ addext (rej, ".rej", '#');
+ }
+ say ("--saving rejects to %s", rej);
+ if (! dry_run)
+ move_file (TMPREJNAME, rej, FALSE);
+ if (!rejname)
+ free (rej);
}
- if (move_file(TMPREJNAME, rejname) < 0)
- trejkeep = TRUE;
+ say ("\n");
}
- set_signals(1);
+ }
+ set_signals (1);
}
- my_exit(failtotal);
+ if (ofp && (ferror (ofp) || fclose (ofp) != 0))
+ write_fatal ();
+ cleanup ();
+ if (somefailed)
+ exit (1);
+ return 0;
}
/* Prepare to find the next patch to do in the patch file. */
-void
+static void
reinitialize_almost_everything()
{
re_patch();
@@ -402,107 +374,182 @@ reinitialize_almost_everything()
input_lines = 0;
last_frozen_line = 0;
- filec = 0;
- if (filearg[0] != Nullch && !out_of_mem) {
- free(filearg[0]);
- filearg[0] = Nullch;
- }
-
- if (outname != Nullch) {
- free(outname);
- outname = Nullch;
+ if (inname) {
+ free (inname);
+ inname = 0;
}
last_offset = 0;
- diff_type = 0;
+ diff_type = NO_DIFF;
- if (revision != Nullch) {
+ if (revision) {
free(revision);
- revision = Nullch;
+ revision = 0;
}
reverse = reverse_flag_specified;
skip_rest_of_patch = FALSE;
-
- get_some_switches();
-
- if (filec >= 2)
- fatal1("you may not change to a different patch file\n");
}
-static char *shortopts = "-b:B:cd:D:eEfF:lnNo:p::r:RsStuvV:x:";
-static struct option longopts[] =
+static char const shortopts[] = "bB:cd:D:eEfF:i:lnNo:p:r:RstuvV:x:Y:z:";
+static struct option const longopts[] =
{
- {"suffix", 1, NULL, 'b'},
- {"prefix", 1, NULL, 'B'},
- {"context", 0, NULL, 'c'},
- {"directory", 1, NULL, 'd'},
- {"ifdef", 1, NULL, 'D'},
- {"ed", 0, NULL, 'e'},
- {"remove-empty-files", 0, NULL, 'E'},
- {"force", 0, NULL, 'f'},
- {"fuzz", 1, NULL, 'F'},
- {"ignore-whitespace", 0, NULL, 'l'},
- {"normal", 0, NULL, 'n'},
- {"forward", 0, NULL, 'N'},
- {"output", 1, NULL, 'o'},
- {"strip", 2, NULL, 'p'},
- {"reject-file", 1, NULL, 'r'},
- {"reverse", 0, NULL, 'R'},
- {"quiet", 0, NULL, 's'},
- {"silent", 0, NULL, 's'},
- {"skip", 0, NULL, 'S'},
- {"batch", 0, NULL, 't'},
- {"unified", 0, NULL, 'u'},
- {"version", 0, NULL, 'v'},
- {"version-control", 1, NULL, 'V'},
- {"debug", 1, NULL, 'x'},
- {0, 0, 0, 0}
+ {"backup", no_argument, NULL, 'b'},
+ {"prefix", required_argument, NULL, 'B'},
+ {"context", no_argument, NULL, 'c'},
+ {"directory", required_argument, NULL, 'd'},
+ {"ifdef", required_argument, NULL, 'D'},
+ {"ed", no_argument, NULL, 'e'},
+ {"remove-empty-files", no_argument, NULL, 'E'},
+ {"force", no_argument, NULL, 'f'},
+ {"fuzz", required_argument, NULL, 'F'},
+ {"help", no_argument, NULL, 'h'},
+ {"input", required_argument, NULL, 'i'},
+ {"ignore-whitespace", no_argument, NULL, 'l'},
+ {"normal", no_argument, NULL, 'n'},
+ {"forward", no_argument, NULL, 'N'},
+ {"output", required_argument, NULL, 'o'},
+ {"strip", required_argument, NULL, 'p'},
+ {"reject-file", required_argument, NULL, 'r'},
+ {"reverse", no_argument, NULL, 'R'},
+ {"quiet", no_argument, NULL, 's'},
+ {"silent", no_argument, NULL, 's'},
+ {"batch", no_argument, NULL, 't'},
+ {"unified", no_argument, NULL, 'u'},
+ {"version", no_argument, NULL, 'v'},
+ {"version-control", required_argument, NULL, 'V'},
+ {"debug", required_argument, NULL, 'x'},
+ {"basename-prefix", required_argument, NULL, 'Y'},
+ {"suffix", required_argument, NULL, 'z'},
+ {"dry-run", no_argument, NULL, 129},
+ {"verbose", no_argument, NULL, 130},
+ {NULL, no_argument, NULL, 0}
};
-/* Process switches and filenames up to next '+' or end of list. */
+static char const * const option_help[] = {
+"Input options:",
+"",
+" -p NUM --strip=NUM Strip NUM leading components from file names.",
+" -F LINES --fuzz LINES Set the fuzz factor to LINES for inexact matching.",
+" -l --ignore-whitespace Ignore white space changes between patch and input.",
+"",
+" -c --context Interpret the patch as a context difference.",
+" -e --ed Interpret the patch as an ed script.",
+" -n --normal Interpret the patch as a normal difference.",
+" -u --unified Interpret the patch as a unified difference.",
+"",
+" -N --forward Ignore patches that appear to be reversed or already applied.",
+" -R --reverse Assume patches were created with old and new files swapped.",
+"",
+" -i PATCHFILE --input=PATCHFILE Read patch from PATCHFILE instead of stdin.",
+"",
+"Output options:",
+"",
+" -o FILE --output=FILE Output patched files to FILE.",
+" -r FILE --reject-file=FILE Output rejects to FILE.",
+"",
+" -D NAME --ifdef=NAME Make merged if-then-else output using NAME.",
+" -E --remove-empty-files Remove output files that are empty after patching.",
+"",
+"Backup file options:",
+"",
+" -V STYLE --version-control=STYLE Use STYLE version control.",
+" STYLE is either 'simple', 'numbered', or 'existing'.",
+"",
+" -b --backup Save the original contents of each file F into F.orig.",
+" -B PREFIX --prefix=PREFIX Prepend PREFIX to backup file names.",
+" -Y PREFIX --basename-prefix=PREFIX Prepend PREFIX to backup file basenames.",
+" -z SUFFIX --suffix=SUFFIX Append SUFFIX to backup file names.",
+"",
+"Miscellaneous options:",
+"",
+" -t --batch Ask no questions; skip bad-Prereq patches; assume reversed.",
+" -f --force Like -t, but ignore bad-Prereq patches, and assume unreversed.",
+" -s --quiet --silent Work silently unless an error occurs.",
+" --verbose Output extra information about the work being done.",
+" --dry-run Do not actually change any files; just print what would happen.",
+"",
+" -d DIR --directory=DIR Change the working directory to DIR first.",
+"",
+" -v --version Output version info.",
+" --help Output this help.",
+0
+};
-void
+static void
+usage (stream, status)
+ FILE *stream;
+ int status;
+{
+ char const * const *p;
+
+ if (status != 0)
+ {
+ fprintf (stream, "%s: Try `%s --help' for more information.\n",
+ program_name, Argv[0]);
+ }
+ else
+ {
+ fprintf (stream, "Usage: %s [OPTION]... [ORIGFILE [PATCHFILE]]\n\n",
+ Argv[0]);
+ for (p = option_help; *p; p++)
+ fprintf (stream, "%s\n", *p);
+ }
+
+ exit (status);
+}
+
+/* Process switches and filenames. */
+
+static void
get_some_switches()
{
- Reg1 int optc;
+ register int optc;
- rejname[0] = '\0';
- optind_last = optind;
+ if (rejname)
+ free (rejname);
+ rejname = 0;
if (optind == Argc)
return;
while ((optc = getopt_long (Argc, Argv, shortopts, longopts, (int *) 0))
!= -1) {
- if (optc == 1) {
- if (strEQ(optarg, "+"))
- return;
- if (filec == MAXFILEC)
- fatal1("too many file arguments\n");
- filearg[filec++] = savestr(optarg);
- }
- else {
- switch (optc) {
+ switch (optc) {
case 'b':
- simple_backup_suffix = savestr(optarg);
+ /* Special hack for backward compatibility with CVS 1.9.
+ If the last 4 args are `-b SUFFIX ORIGFILE PATCHFILE',
+ treat `-b' as if it were `-z'. */
+ if (Argc - optind == 3
+ && strcmp (Argv[optind - 1], "-b") == 0
+ && ! (Argv[optind + 0][0] == '-' && Argv[optind + 0][1])
+ && ! (Argv[optind + 1][0] == '-' && Argv[optind + 1][1])
+ && ! (Argv[optind + 2][0] == '-' && Argv[optind + 2][1]))
+ {
+ optarg = Argv[optind++];
+ if (verbosity != SILENT)
+ say ("warning: the `-b %s' option is obsolete; use `-z %s' instead\n",
+ optarg, optarg);
+ goto case_z;
+ }
+ backup = TRUE;
+ backup_type = simple;
break;
case 'B':
- origprae = savestr(optarg);
+ if (!*optarg)
+ pfatal ("backup prefix is empty");
+ origprae = savestr (optarg);
+ backup = TRUE;
+ backup_type = simple;
break;
case 'c':
diff_type = CONTEXT_DIFF;
break;
case 'd':
if (chdir(optarg) < 0)
- pfatal2("can't cd to %s", optarg);
+ pfatal ("can't cd to %s", optarg);
break;
case 'D':
- do_defines = TRUE;
- if (!isalpha(*optarg) && '_' != *optarg)
- fatal1("argument to -D is not an identifier\n");
- Sprintf(if_defined, "#ifdef %s\n", optarg);
- Sprintf(not_defined, "#ifndef %s\n", optarg);
- Sprintf(end_defined, "#endif /* %s */\n", optarg);
+ do_defines = savestr (optarg);
break;
case 'e':
diff_type = ED_DIFF;
@@ -514,7 +561,12 @@ get_some_switches()
force = TRUE;
break;
case 'F':
- maxfuzz = atoi(optarg);
+ maxfuzz = numeric_optarg ("fuzz factor");
+ break;
+ case 'h':
+ usage (stdout, 0);
+ case 'i':
+ patchname = savestr (optarg);
break;
case 'l':
canonicalize = TRUE;
@@ -526,26 +578,22 @@ get_some_switches()
noreverse = TRUE;
break;
case 'o':
- outname = savestr(optarg);
+ if (strcmp (optarg, "-") == 0)
+ fatal ("cannot output patches to standard output");
+ output = savestr (optarg);
break;
case 'p':
- if (optarg)
- strippath = atoi(optarg);
- else
- strippath = 0;
+ strippath = numeric_optarg ("strip count");
break;
case 'r':
- Strcpy(rejname, optarg);
+ rejname = savestr (optarg);
break;
case 'R':
reverse = TRUE;
reverse_flag_specified = TRUE;
break;
case 's':
- verbose = FALSE;
- break;
- case 'S':
- skip_rest_of_patch = TRUE;
+ verbosity = SILENT;
break;
case 't':
batch = TRUE;
@@ -555,105 +603,149 @@ get_some_switches()
break;
case 'v':
version();
+ exit (0);
break;
case 'V':
-#ifndef NODIR
+ backup = TRUE;
backup_type = get_version (optarg);
-#endif
break;
-#ifdef DEBUGGING
+#if DEBUGGING
case 'x':
- debug = atoi(optarg);
+ debug = numeric_optarg ("debugging option");
break;
#endif
+ case 'Y':
+ if (!*optarg)
+ pfatal ("backup basename prefix is empty");
+ origbase = savestr (optarg);
+ backup = TRUE;
+ backup_type = simple;
+ break;
+ case 'z':
+ case_z:
+ if (!*optarg)
+ pfatal ("backup suffix is empty");
+ simple_backup_suffix = savestr (optarg);
+ backup = TRUE;
+ backup_type = simple;
+ break;
+ case 129:
+ dry_run = TRUE;
+ break;
+ case 130:
+ verbosity = VERBOSE;
+ break;
default:
- fprintf(stderr, "\
-Usage: %s [options] [origfile [patchfile]] [+ [options] [origfile]]...\n",
- Argv[0]);
- fprintf(stderr, "\
-Options:\n\
- [-ceEflnNRsStuv] [-b backup-ext] [-B backup-prefix] [-d directory]\n\
- [-D symbol] [-F max-fuzz] [-o out-file] [-p[strip-count]]\n\
- [-r rej-name] [-V {numbered,existing,simple}] [--context]\n\
- [--prefix=backup-prefix] [--suffix=backup-ext] [--ifdef=symbol]\n\
- [--directory=directory] [--ed] [--fuzz=max-fuzz] [--force] [--batch]\n\
- [--ignore-whitespace] [--forward] [--reverse] [--output=out-file]\n");
- fprintf(stderr, "\
- [--strip[=strip-count]] [--normal] [--reject-file=rej-name] [--skip]\n\
- [--remove-empty-files] [--quiet] [--silent] [--unified] [--version]\n\
- [--version-control={numbered,existing,simple}]\n");
- my_exit(1);
- }
+ usage (stderr, 2);
}
}
- /* Process any filename args given after "--". */
- for (; optind < Argc; ++optind) {
- if (filec == MAXFILEC)
- fatal1("too many file arguments\n");
- filearg[filec++] = savestr(Argv[optind]);
+ /* Process any filename args. */
+ if (optind < Argc)
+ {
+ inname = savestr (Argv[optind++]);
+ if (optind < Argc)
+ {
+ patchname = savestr (Argv[optind++]);
+ if (optind < Argc)
+ {
+ fprintf (stderr, "%s: extra operand `%s'\n",
+ program_name, Argv[optind]);
+ usage (stderr, 2);
+ }
+ }
+ }
+}
+
+/* Handle a numeric option of type ARGTYPE_MSGID by converting
+ optarg to a nonnegative integer, returning the result. */
+static int
+numeric_optarg (argtype_msgid)
+ char const *argtype_msgid;
+{
+ int value = 0;
+ char const *p = optarg;
+
+ do
+ {
+ int v10 = value * 10;
+ int digit = *p - '0';
+
+ if (9 < (unsigned) digit)
+ fatal ("%s `%s' is not a number", argtype_msgid, optarg);
+
+ if (v10 / 10 != value || v10 + digit < v10)
+ fatal ("%s `%s' is too large", argtype_msgid, optarg);
+
+ value = v10 + digit;
}
+ while (*++p);
+
+ return value;
}
/* Attempt to find the right place to apply this hunk of patch. */
-LINENUM
-locate_hunk(fuzz)
-LINENUM fuzz;
+static LINENUM
+locate_hunk (prefix_fuzz, suffix_fuzz)
+ LINENUM prefix_fuzz;
+ LINENUM suffix_fuzz;
{
- Reg1 LINENUM first_guess = pch_first() + last_offset;
- Reg2 LINENUM offset;
+ register LINENUM first_guess = pch_first () + last_offset;
+ register LINENUM offset;
LINENUM pat_lines = pch_ptrn_lines();
- Reg3 LINENUM max_pos_offset = input_lines - first_guess
- - pat_lines + 1;
- Reg4 LINENUM max_neg_offset = first_guess - last_frozen_line - 1
- + pch_context();
+ register LINENUM max_pos_offset
+ = input_lines - first_guess - pat_lines + 1;
+ register LINENUM max_neg_offset
+ = first_guess - last_frozen_line - 1 + pch_prefix_context ();
if (!pat_lines) /* null range matches always */
return first_guess;
if (max_neg_offset >= first_guess) /* do not try lines < 0 */
max_neg_offset = first_guess - 1;
- if (first_guess <= input_lines && patch_match(first_guess, Nulline, fuzz))
+ if (first_guess <= input_lines
+ && patch_match (first_guess, (LINENUM) 0, prefix_fuzz, suffix_fuzz))
return first_guess;
for (offset = 1; ; offset++) {
- Reg5 bool check_after = (offset <= max_pos_offset);
- Reg6 bool check_before = (offset <= max_neg_offset);
+ register bool check_after = offset <= max_pos_offset;
+ register bool check_before = offset <= max_neg_offset;
- if (check_after && patch_match(first_guess, offset, fuzz)) {
-#ifdef DEBUGGING
+ if (check_after
+ && patch_match (first_guess, offset, prefix_fuzz, suffix_fuzz)) {
if (debug & 1)
- say3("Offset changing from %ld to %ld\n", last_offset, offset);
-#endif
+ say ("Offset changing from %ld to %ld\n", last_offset, offset);
last_offset = offset;
return first_guess+offset;
}
- else if (check_before && patch_match(first_guess, -offset, fuzz)) {
-#ifdef DEBUGGING
+ else if (check_before
+ && patch_match (first_guess, -offset,
+ prefix_fuzz, suffix_fuzz)) {
if (debug & 1)
- say3("Offset changing from %ld to %ld\n", last_offset, -offset);
-#endif
+ say ("Offset changing from %ld to %ld\n", last_offset, -offset);
last_offset = -offset;
return first_guess-offset;
}
else if (!check_before && !check_after)
- return Nulline;
+ return 0;
}
}
/* We did not find the pattern, dump out the hunk so they can handle it. */
-void
+static void
abort_hunk()
{
- Reg1 LINENUM i;
- Reg2 LINENUM pat_end = pch_end();
+ register LINENUM i;
+ register LINENUM pat_end = pch_end ();
/* add in last_offset to guess the same as the previous successful hunk */
LINENUM oldfirst = pch_first() + last_offset;
LINENUM newfirst = pch_newfirst() + last_offset;
LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
LINENUM newlast = newfirst + pch_repl_lines() - 1;
- char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
- char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
+ char const *stars =
+ (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ****" : "";
+ char const *minuses =
+ (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----";
fprintf(rejfp, "***************\n");
for (i=0; i<=pat_end; i++) {
@@ -674,52 +766,56 @@ abort_hunk()
else
fprintf(rejfp, "--- %ld,%ld%s\n", newfirst, newlast, minuses);
break;
- case '\n':
- fprintf(rejfp, "%s", pfetch(i));
- break;
case ' ': case '-': case '+': case '!':
- fprintf(rejfp, "%c %s", pch_char(i), pfetch(i));
+ fprintf (rejfp, "%c ", pch_char (i));
+ /* fall into */
+ case '\n':
+ pch_write_line (i, rejfp);
break;
default:
- fatal1("fatal internal error in abort_hunk\n");
+ fatal ("fatal internal error in abort_hunk");
}
+ if (ferror (rejfp))
+ write_fatal ();
}
}
/* We found where to apply it (we hope), so do it. */
-void
-apply_hunk(where)
+static bool
+apply_hunk (after_newline, where)
+bool *after_newline;
LINENUM where;
{
- Reg1 LINENUM old = 1;
- Reg2 LINENUM lastline = pch_ptrn_lines();
- Reg3 LINENUM new = lastline+1;
-#define OUTSIDE 0
-#define IN_IFNDEF 1
-#define IN_IFDEF 2
-#define IN_ELSE 3
- Reg4 int def_state = OUTSIDE;
- Reg5 bool R_do_defines = do_defines;
- Reg6 LINENUM pat_end = pch_end();
+ register LINENUM old = 1;
+ register LINENUM lastline = pch_ptrn_lines ();
+ register LINENUM new = lastline+1;
+ register enum {OUTSIDE, IN_IFNDEF, IN_IFDEF, IN_ELSE} def_state = OUTSIDE;
+ register char const *R_do_defines = do_defines;
+ register LINENUM pat_end = pch_end ();
+ register FILE *fp = ofp;
where--;
while (pch_char(new) == '=' || pch_char(new) == '\n')
new++;
-
+
while (old <= lastline) {
if (pch_char(old) == '-') {
- copy_till(where + old - 1);
+ assert (*after_newline);
+ if (! copy_till (after_newline, where + old - 1))
+ return FALSE;
if (R_do_defines) {
if (def_state == OUTSIDE) {
- fputs(not_defined, ofp);
+ fprintf (fp, *after_newline + if_defined, R_do_defines);
def_state = IN_IFNDEF;
}
else if (def_state == IN_IFDEF) {
- fputs(else_defined, ofp);
+ fprintf (fp, *after_newline + else_defined);
def_state = IN_ELSE;
}
- fputs(pfetch(old), ofp);
+ if (ferror (fp))
+ write_fatal ();
+ *after_newline = pch_write_line (old, fp);
}
last_frozen_line++;
old++;
@@ -728,172 +824,216 @@ LINENUM where;
break;
}
else if (pch_char(new) == '+') {
- copy_till(where + old - 1);
+ if (! copy_till (after_newline, where + old - 1))
+ return FALSE;
if (R_do_defines) {
if (def_state == IN_IFNDEF) {
- fputs(else_defined, ofp);
+ fprintf (fp, *after_newline + else_defined);
def_state = IN_ELSE;
}
else if (def_state == OUTSIDE) {
- fputs(if_defined, ofp);
+ fprintf (fp, *after_newline + if_defined, R_do_defines);
def_state = IN_IFDEF;
}
+ if (ferror (fp))
+ write_fatal ();
}
- fputs(pfetch(new), ofp);
+ *after_newline = pch_write_line (new, fp);
new++;
}
else if (pch_char(new) != pch_char(old)) {
- say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
+ if (debug & 1)
+ say ("oldchar = '%c', newchar = '%c'\n",
+ pch_char (old), pch_char (new));
+ fatal ("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?",
pch_hunk_beg() + old,
pch_hunk_beg() + new);
-#ifdef DEBUGGING
- say3("oldchar = '%c', newchar = '%c'\n",
- pch_char(old), pch_char(new));
-#endif
- my_exit(1);
}
else if (pch_char(new) == '!') {
- copy_till(where + old - 1);
+ assert (*after_newline);
+ if (! copy_till (after_newline, where + old - 1))
+ return FALSE;
+ assert (*after_newline);
if (R_do_defines) {
- fputs(not_defined, ofp);
+ fprintf (fp, not_defined, R_do_defines);
+ if (ferror (fp))
+ write_fatal ();
def_state = IN_IFNDEF;
}
- while (pch_char(old) == '!') {
+
+ do
+ {
if (R_do_defines) {
- fputs(pfetch(old), ofp);
+ *after_newline = pch_write_line (old, fp);
}
last_frozen_line++;
old++;
- }
+ }
+ while (pch_char (old) == '!');
+
if (R_do_defines) {
- fputs(else_defined, ofp);
+ fprintf (fp, *after_newline + else_defined);
+ if (ferror (fp))
+ write_fatal ();
def_state = IN_ELSE;
}
- while (pch_char(new) == '!') {
- fputs(pfetch(new), ofp);
+
+ do
+ {
+ *after_newline = pch_write_line (new, fp);
new++;
- }
+ }
+ while (pch_char (new) == '!');
}
else {
assert(pch_char(new) == ' ');
old++;
new++;
if (R_do_defines && def_state != OUTSIDE) {
- fputs(end_defined, ofp);
+ fprintf (fp, *after_newline + end_defined, R_do_defines);
+ if (ferror (fp))
+ write_fatal ();
+ *after_newline = TRUE;
def_state = OUTSIDE;
}
}
}
if (new <= pat_end && pch_char(new) == '+') {
- copy_till(where + old - 1);
+ if (! copy_till (after_newline, where + old - 1))
+ return FALSE;
if (R_do_defines) {
if (def_state == OUTSIDE) {
- fputs(if_defined, ofp);
+ fprintf (fp, *after_newline + if_defined, R_do_defines);
def_state = IN_IFDEF;
}
else if (def_state == IN_IFNDEF) {
- fputs(else_defined, ofp);
+ fprintf (fp, *after_newline + else_defined);
def_state = IN_ELSE;
}
+ if (ferror (fp))
+ write_fatal ();
}
- while (new <= pat_end && pch_char(new) == '+') {
- fputs(pfetch(new), ofp);
+
+ do
+ {
+ if (!*after_newline && putc ('\n', fp) == EOF)
+ write_fatal ();
+ *after_newline = pch_write_line (new, fp);
new++;
- }
+ }
+ while (new <= pat_end && pch_char (new) == '+');
}
if (R_do_defines && def_state != OUTSIDE) {
- fputs(end_defined, ofp);
+ fprintf (fp, *after_newline + end_defined, R_do_defines);
+ if (ferror (fp))
+ write_fatal ();
+ *after_newline = TRUE;
}
+ return TRUE;
}
/* Open the new file. */
-void
+static void
init_output(name)
-char *name;
+ char const *name;
{
ofp = fopen(name, "w");
- if (ofp == Nullfp)
- pfatal2("can't create %s", name);
+ if (! ofp)
+ pfatal ("can't create %s", name);
}
/* Open a file to put hunks we can't locate. */
-void
+static void
init_reject(name)
-char *name;
+ char const *name;
{
rejfp = fopen(name, "w");
- if (rejfp == Nullfp)
- pfatal2("can't create %s", name);
+ if (!rejfp)
+ pfatal ("can't create %s", name);
}
/* Copy input file to output, up to wherever hunk is to be applied. */
-void
-copy_till(lastline)
-Reg1 LINENUM lastline;
+static bool
+copy_till (after_newline, lastline)
+ register bool *after_newline;
+ register LINENUM lastline;
{
- Reg2 LINENUM R_last_frozen_line = last_frozen_line;
+ register LINENUM R_last_frozen_line = last_frozen_line;
+ register FILE *fp = ofp;
+ register char const *s;
+ size_t size;
if (R_last_frozen_line > lastline)
- fatal1("misordered hunks! output would be garbled\n");
- while (R_last_frozen_line < lastline) {
- dump_line(++R_last_frozen_line);
- }
+ {
+ say ("misordered hunks! output would be garbled\n");
+ return FALSE;
+ }
+ while (R_last_frozen_line < lastline)
+ {
+ s = ifetch (++R_last_frozen_line, 0, &size);
+ if (size)
+ {
+ if ((!*after_newline && putc ('\n', fp) == EOF)
+ || ! fwrite (s, sizeof *s, size, fp))
+ write_fatal ();
+ *after_newline = s[size - 1] == '\n';
+ }
+ }
last_frozen_line = R_last_frozen_line;
+ return TRUE;
}
/* Finish copying the input file to the output file. */
-void
-spew_output()
+static bool
+spew_output (after_newline)
+ bool *after_newline;
{
-#ifdef DEBUGGING
if (debug & 256)
- say3("il=%ld lfl=%ld\n",input_lines,last_frozen_line);
-#endif
- if (input_lines)
- copy_till(input_lines); /* dump remainder of file */
- Fclose(ofp);
- ofp = Nullfp;
-}
+ say ("il=%ld lfl=%ld\n", input_lines, last_frozen_line);
-/* Copy one line from input to output. */
+ if (last_frozen_line < input_lines)
+ if (! copy_till (after_newline, input_lines))
+ return FALSE;
-void
-dump_line(line)
-LINENUM line;
-{
- Reg1 char *s;
- Reg2 char R_newline = '\n';
+ if (ofp && !output)
+ {
+ if (fclose (ofp) != 0)
+ write_fatal ();
+ ofp = 0;
+ }
- /* Note: string is not null terminated. */
- for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) ;
+ return TRUE;
}
/* Does the patch pattern match at line base+offset? */
-bool
-patch_match(base, offset, fuzz)
+static bool
+patch_match (base, offset, prefix_fuzz, suffix_fuzz)
LINENUM base;
LINENUM offset;
-LINENUM fuzz;
+LINENUM prefix_fuzz;
+LINENUM suffix_fuzz;
{
- Reg1 LINENUM pline = 1 + fuzz;
- Reg2 LINENUM iline;
- Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz;
-
- for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) {
+ register LINENUM pline = 1 + prefix_fuzz;
+ register LINENUM iline;
+ register LINENUM pat_lines = pch_ptrn_lines () - suffix_fuzz;
+ size_t size;
+ register char const *p;
+
+ for (iline=base+offset+prefix_fuzz; pline <= pat_lines; pline++,iline++) {
+ p = ifetch (iline, offset >= 0, &size);
if (canonicalize) {
- if (!similar(ifetch(iline, (offset >= 0)),
+ if (!similar(p, size,
pfetch(pline),
pch_line_len(pline) ))
return FALSE;
}
- else if (strnNE(ifetch(iline, (offset >= 0)),
- pfetch(pline),
- pch_line_len(pline) ))
+ else if (size != pch_line_len (pline)
+ || memcmp (p, pfetch (pline), size) != 0)
return FALSE;
}
return TRUE;
@@ -901,45 +1041,87 @@ LINENUM fuzz;
/* Do two lines match with canonicalized white space? */
-bool
-similar(a,b,len)
-Reg1 char *a;
-Reg2 char *b;
-Reg3 int len;
+static bool
+similar (a, alen, b, blen)
+ register char const *a;
+ register size_t alen;
+ register char const *b;
+ register size_t blen;
{
- while (len) {
- if (isspace(*b)) { /* whitespace (or \n) to match? */
- if (!isspace(*a)) /* no corresponding whitespace? */
+ /* Ignore presence or absence of trailing newlines. */
+ alen -= alen && a[alen - 1] == '\n';
+ blen -= blen && b[blen - 1] == '\n';
+
+ for (;;)
+ {
+ if (!blen || (*b == ' ' || *b == '\t'))
+ {
+ while (blen && (*b == ' ' || *b == '\t'))
+ b++, blen--;
+ if (alen)
+ {
+ if (!(*a == ' ' || *a == '\t'))
return FALSE;
- while (len && isspace(*b) && *b != '\n')
- b++,len--; /* skip pattern whitespace */
- while (isspace(*a) && *a != '\n')
- a++; /* skip target whitespace */
- if (*a == '\n' || *b == '\n')
- return (*a == *b); /* should end in sync */
+ do a++, alen--;
+ while (alen && (*a == ' ' || *a == '\t'));
+ }
+ if (!alen || !blen)
+ return alen == blen;
}
- else if (*a++ != *b++) /* match non-whitespace chars */
- return FALSE;
- else
- len--; /* probably not necessary */
+ else if (!alen || *a++ != *b++)
+ return FALSE;
+ else
+ alen--, blen--;
}
- return TRUE; /* actually, this is not reached */
- /* since there is always a \n */
}
-/* Exit with cleanup. */
+/* Make a temporary file. */
+
+#if HAVE_MKTEMP
+char *mktemp PARAMS ((char *));
+#endif
+
+static char const *
+make_temp (letter)
+ int letter;
+{
+ char *r;
+#if HAVE_MKTEMP
+ char const *tmpdir = getenv ("TMPDIR");
+ if (!tmpdir)
+ tmpdir = "/tmp";
+ r = xmalloc (strlen (tmpdir) + 14);
+ sprintf (r, "%s/patch%cXXXXXX", tmpdir, letter);
+ mktemp (r);
+ if (!*r)
+ pfatal ("mktemp");
+#else
+ r = xmalloc (L_tmpnam);
+ if (! (tmpnam (r) == r && *r))
+ pfatal ("tmpnam");
+#endif
+ return r;
+}
+
+/* Fatal exit with cleanup. */
void
-my_exit(status)
-int status;
+fatal_exit (sig)
+ int sig;
{
- Unlink(TMPINNAME);
- if (!toutkeep) {
- Unlink(TMPOUTNAME);
- }
- if (!trejkeep) {
- Unlink(TMPREJNAME);
- }
- Unlink(TMPPATNAME);
- exit(status);
+ cleanup ();
+
+ if (sig)
+ exit_with_signal (sig);
+
+ exit (2);
+}
+
+static void
+cleanup ()
+{
+ unlink (TMPINNAME);
+ unlink (TMPOUTNAME);
+ unlink (TMPPATNAME);
+ unlink (TMPREJNAME);
}
diff --git a/patch.man b/patch.man
index bf20668..6b2fcfb 100644
--- a/patch.man
+++ b/patch.man
@@ -1,159 +1,85 @@
-.\" -*- nroff -*-
-.rn '' }`
-'\" $Header: patch.man,v 2.0.1.2 88/06/22 20:47:18 lwall Locked $
-'\"
-'\" $Log: patch.man,v $
-'\" Revision 2.0.1.2 88/06/22 20:47:18 lwall
-'\" patch12: now avoids Bell System Logo
-'\"
-'\" Revision 2.0.1.1 88/06/03 15:12:51 lwall
-'\" patch10: -B switch was contributed.
-'\"
-'\" Revision 2.0 86/09/17 15:39:09 lwall
-'\" Baseline for netwide release.
-'\"
-'\" Revision 1.4 86/08/01 19:23:22 lwall
-'\" Documented -v, -p, -F.
-'\" Added notes to patch senders.
-'\"
-'\" Revision 1.3 85/03/26 15:11:06 lwall
-'\" Frozen.
-'\"
-'\" Revision 1.2.1.4 85/03/12 16:14:27 lwall
-'\" Documented -p.
-'\"
-'\" Revision 1.2.1.3 85/03/12 16:09:41 lwall
-'\" Documented -D.
-'\"
-'\" Revision 1.2.1.2 84/12/05 11:06:55 lwall
-'\" Added -l switch, and noted bistability bug.
-'\"
-'\" Revision 1.2.1.1 84/12/04 17:23:39 lwall
-'\" Branch for sdcrdcf changes.
-'\"
-'\" Revision 1.2 84/12/04 17:22:02 lwall
-'\" Baseline version.
-'\"
-.de Sh
-.br
-.ne 5
-.PP
-\fB\\$1\fR
-.PP
+.\" patch man page
+.de Id
+.ds Dt \\$4
..
+.Id $Id: patch.man,v 1.8 1997/04/17 17:08:15 eggert Exp $
+.ds = \-\^\-
.de Sp
-.if t .sp .5v
+.if t .sp .3
.if n .sp
..
-'\"
-'\" Set up \*(-- to give an unbreakable dash;
-'\" string Tr holds user defined translation string.
-'\" Bell System Logo is used as a dummy character.
-'\"
-.ie n \{\
-.tr \(*W-\*(Tr
-.ds -- \(*W-
-.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-.ds L" ""
-.ds R" ""
-.ds L' '
-.ds R' '
-'br \}
-.el \{\
-.ds -- \(em\|
-.tr \*(Tr
-.ds L" ``
-.ds R" ''
-.ds L' `
-.ds R' '
-'br\}
-.TH PATCH 1 LOCAL
+.TH PATCH 1 \*(Dt GNU
+.ta 3n
.SH NAME
-patch - apply a diff file to an original
+patch \- apply a diff file to an original
.SH SYNOPSIS
.B patch
-[options] [origfile [patchfile]] [+ [options] [origfile]]...
-.sp
+.RI [ options ]
+.RI [ originalfile
+.RI [ patchfile ]]
+.Sp
but usually just
-.sp
-.B patch
-<patchfile
+.Sp
+.BI "patch \-p" number
+.BI < patchfile
.SH DESCRIPTION
-.I Patch
-will take a patch file containing any of the four forms of difference
-listing produced by the
-.I diff
-program and apply those differences to an original file, producing a patched
-version.
-By default, the patched version is put in place of the original, with
-the original file backed up to the same name with the
-extension \*(L".orig\*(R" (\*(L"~\*(R" on systems that do not
-support long file names), or as specified by the
-\fB\-b\fP (\fB\-\-suffix\fP),
-\fB\-B\fP (\fB\-\-prefix\fP),
-or
-\fB\-V\fP (\fB\-\-version\-control\fP)
-options.
-The extension used for making backup files may also be specified in the
-.B SIMPLE_BACKUP_SUFFIX
-environment variable, which is overridden by the above options.
-.PP
-If the backup file already exists,
.B patch
-creates a new backup file name by changing the first lowercase letter
-in the last component of the file's name into uppercase. If there are
-no more lowercase letters in the name, it removes the first character
-from the name. It repeats this process until it comes up with a
-backup file that does not already exist.
-.PP
-You may also specify where you want the output to go with a
-\fB\-o\fP (\fB\-\-output\fP)
-option; if that file already exists, it is backed up first.
-.PP
-If
+takes a patch file
.I patchfile
-is omitted, or is a hyphen, the patch will be read from standard input.
+containing a difference listing produced by the
+.B diff
+program and applies those differences to one or more original files,
+producing patched versions.
+Normally the patched versions are put in place of the originals.
+Backups can be made; see the
+.B \-V
+or
+.B \*=version\-control
+option.
+The names of the files to be patched are usually taken from the patch file,
+but if there's just one file to be patched it can specified on the
+command line as
+.IR originalfile .
.PP
-Upon startup, patch will attempt to determine the type of the diff listing,
-unless over-ruled by a
-\fB\-c\fP (\fB\-\-context\fP),
-\fB\-e\fP (\fB\-\-ed\fP),
-\fB\-n\fP (\fB\-\-normal\fP),
+Upon startup, patch attempts to determine the type of the diff listing,
+unless overruled by a
+\fB\-c\fP (\fB\*=context\fP),
+\fB\-e\fP (\fB\*=ed\fP),
+\fB\-n\fP (\fB\*=normal\fP),
or
-\fB\-u\fP (\fB\-\-unified\fP)
+\fB\-u\fP (\fB\*=unified\fP)
option.
Context diffs (old-style, new-style, and unified) and
normal diffs are applied by the
-.I patch
+.B patch
program itself, while
-.I ed
+.B ed
diffs are simply fed to the
-.I ed
+.BR ed (1)
editor via a pipe.
.PP
-.I Patch
-will try to skip any leading garbage, apply the diff,
+.B patch
+tries to skip any leading garbage, apply the diff,
and then skip any trailing garbage.
Thus you could feed an article or message containing a
diff listing to
-.IR patch ,
+.BR patch ,
and it should work.
If the entire diff is indented by a consistent amount,
-this will be taken into account.
+this is taken into account.
.PP
With context diffs, and to a lesser extent with normal diffs,
-.I patch
+.B patch
can detect when the line numbers mentioned in the patch are incorrect,
-and will attempt to find the correct place to apply each hunk of the patch.
+and attempts to find the correct place to apply each hunk of the patch.
As a first guess, it takes the line number mentioned for the hunk, plus or
minus any offset used in applying the previous hunk.
If that is not the correct place,
-.I patch
-will scan both forwards and backwards for a set of lines matching the context
+.B patch
+scans both forwards and backwards for a set of lines matching the context
given in the hunk.
First
-.I patch
+.B patch
looks for a place where all lines of the context match.
If no such place is found, and it's a context diff, and the maximum fuzz factor
is set to 1 or more, then another scan takes place ignoring the first and last
@@ -163,408 +89,617 @@ the first two and last two lines of context are ignored,
and another scan is made.
(The default maximum fuzz factor is 2.)
If
-.I patch
-cannot find a place to install that hunk of the patch, it will put the
+.B patch
+cannot find a place to install that hunk of the patch, it puts the
hunk out to a reject file, which normally is the name of the output file
-plus \*(L".rej\*(R" (\*(L"#\*(R" on systems that do not support
-long file names).
-(Note that the rejected hunk will come out in context diff form whether the
-input patch was a context diff or a normal diff.
-If the input was a normal diff, many of the contexts will simply be null.)
+plus a
+.B \&.rej
+suffix
+(or
+.B #
+if
+.B \&.rej
+would generate a file name that is too long).
+(The rejected hunk comes out in ordinary context diff form regardless of
+the input patch's form.
+If the input was a normal diff, many of the contexts are simply null.)
The line numbers on the hunks in the reject file may be different than
in the patch file: they reflect the approximate location patch thinks the
failed hunks belong in the new file rather than the old one.
.PP
-As each hunk is completed, you will be told whether the hunk succeeded or
-failed, and which line (in the new file)
-.I patch
+As each hunk is completed, you are told if the hunk
+failed, and if so which line (in the new file)
+.B patch
thought the hunk should go on.
-If this is different from the line number specified in the diff you will
-be told the offset.
-A single large offset MAY be an indication that a hunk was installed in the
+If the
+.B \*=verbose
+option is given, you are also told about hunks that succeeded.
+If the hunk is installed at a different line
+from the line number specified in the diff you
+are told the offset.
+A single large offset
+.I may
+indicate that a hunk was installed in the
wrong place.
-You will also be told if a fuzz factor was used to make the match, in which
+You are also told if a fuzz factor was used to make the match, in which
case you should also be slightly suspicious.
.PP
-If no original file is specified on the command line,
-.I patch
-will try to figure out from the leading garbage what the name of the file
+If no original file
+.I origfile
+is specified on the command line,
+.B patch
+tries to figure out from the leading garbage what the name of the file
to edit is.
-In the header of a context diff, the file name is found from lines beginning
-with \*(L"***\*(R" or \*(L"---\*(R", with the shortest name of an existing
-file winning.
-Only context diffs have lines like that, but if there is an \*(L"Index:\*(R"
+If the header is that of a context diff,
+.B patch
+tests for the existence of the old and new files named in the header.
+If there is an
+.B Index:
line in the leading garbage,
-.I patch
-will try to use the file name from that line.
-The context diff header takes precedence over an Index line.
-If no file name can be intuited from the leading garbage, you will be asked
+.B patch
+tests for the existence of the file named in that line.
+If none of the file names refer to existing files, but the patch appears
+to create a file, then
+.B patch
+tries the same file names again, this time testing only for the
+existence of the file names' directory prefix;
+.B patch
+uses the first name with the longest existing prefix.
+If no file name can be intuited from the leading garbage, you are asked
for the name of the file to patch.
.PP
-If the original file cannot be found or is read-only, but a suitable
-SCCS or RCS file is handy,
-.I patch
-will attempt to get or check out the file.
-.PP
-Additionally, if the leading garbage contains a \*(L"Prereq: \*(R" line,
-.I patch
-will take the first word from the prerequisites line (normally a version
-number) and check the input file to see if that word can be found.
+Additionally, if the leading garbage contains a
+.B Prereq:
+line,
+.B patch
+takes the first word from the prerequisites line (normally a version
+number) and checks the original file to see if that word can be found.
If not,
-.I patch
-will ask for confirmation before proceeding.
+.B patch
+asks for confirmation before proceeding.
+.PP
+If the original file cannot be found or is read-only, but a suitable
+\s-1RCS\s0 file is handy,
+and if version control
+(see the
+.B \-V
+or
+.B \*=version\-control
+option)
+is set to
+.BR existing ,
+.B patch
+attempts to check out and lock the file.
+\s-1SCCS\s0 is treated in a similar way.
.PP
The upshot of all this is that you should be able to say, while in a news
-interface, the following:
+interface, something like the following:
.Sp
- | patch -d /usr/src/local/blurfl
+ \fB| patch \-d /usr/src/local/blurfl\fP
.Sp
-and patch a file in the blurfl directory directly from the article containing
+and patch a file in the
+.B blurfl
+directory directly from the article containing
the patch.
.PP
If the patch file contains more than one patch,
-.I patch
-will try to apply each of them as if they came from separate patch files.
+.B patch
+tries to apply each of them as if they came from separate patch files.
This means, among other things, that it is assumed that the name of the file
to patch must be determined for each diff listing,
-and that the garbage before each diff listing will
-be examined for interesting things such as file names and revision level, as
+and that the garbage before each diff listing
+contains interesting things such as file names and revision level, as
mentioned previously.
-You can give options (and another original file name) for the second and
-subsequent patches by separating the corresponding argument lists
-by a \*(L'+\*(R'.
-(The argument list for a second or subsequent patch may not specify a new
-patch file, however.)
-.PP
-.I Patch
-recognizes the following options:
-.TP 5
-.B "\-b suff, \-\-suffix=suff"
-causes
-.B suff
-to be interpreted as the backup extension, to be
-used in place of \*(L".orig\*(R" or \*(L"~\*(R".
-.TP 5
-.B "\-B pref, \-\-prefix=pref"
-causes
-.B pref
-to be interpreted as a prefix to the backup file
-name. If this argument is specified, any argument from
-.B \-b
-will be ignored.
-.TP 5
-.B "\-c, \-\-context"
-forces
-.I patch
-to interpret the patch file as a context diff.
-.TP 5
-.B "\-d dir, \-\-directory=dir"
-causes
-.I patch
-to interpret
-.B dir
-as a directory, and cd to it before doing
+.SH OPTIONS
+.TP 3
+\fB\-b\fP or \fB\*=backup\fP
+Make backup files.
+This option is equivalent to
+.BR \*=version\-control=simple ;
+see the
+.B \-V
+or
+.B \*=version\-control
+option for details.
+In older versions of
+.BR patch ,
+this option had an argument specifying the simple backup suffix;
+this argument has been moved to the
+.B \-z
+option.
+.TP
+\fB\-B\fP \fIpref\fP or \fB\*=prefix=\fP\fIpref\fP
+Prefix simple backup file names with
+.IR pref .
+For example, with
+.B "\-B /junk/"
+the simple backup file name for
+.B src/patch/util.c
+is
+.BR /junk/src/patch/util.c .
+.TP
+\fB\-c\fP or \fB\*=context\fP
+Interpret the patch file as a ordinary context diff.
+.TP
+\fB\*=verbose\fP
+Output extra information about the work being done.
+.TP
+\fB\-d\fP \fIdir\fP or \fB\*=directory=\fP\fIdir\fP
+Change to the directory
+.I dir
+immediately, before doing
anything else.
-.TP 5
-.B "\-D sym, \-\-ifdef=sym"
-causes
-.I patch
-to use the "#ifdef...#endif" construct to mark changes.
-.B sym
-will be used as the differentiating symbol.
-.TP 5
-.B "\-e, \-\-ed"
-forces
-.I patch
-to interpret the patch file as an
-.I ed
+.TP
+\fB\-D\fP \fIsym\fP or \fB\*=ifdef=\fP\fIsym\fP
+Use the
+.B "#ifdef .\|.\|. #endif"
+construct to mark changes, with
+.I sym
+as the differentiating symbol.
+.TP
+.B "\*=dry\-run"
+Print the results of applying the patches without actually changing any files.
+.TP
+\fB\-e\fP or \fB\*=ed\fP
+Interpret the patch file as an
+.B ed
script.
-.TP 5
-.B "\-E, \-\-remove\-empty\-files"
-causes
-.I patch
-to remove output files that are empty after the patches have been applied.
-.TP 5
-.B "\-f, \-\-force"
-forces
-.I patch
-to assume that the user knows exactly what he or she is doing, and to not
-ask any questions. It assumes the following: skip patches for which a
-file to patch can't be found; patch files even though they have the
-wrong version for the ``Prereq:'' line in the patch; and assume that
+.TP
+\fB\-E\fP or \fB\*=remove\-empty\-files\fP
+Remove output files that are empty after the patches have been applied.
+.TP
+\fB\-f\fP or \fB\*=force\fP
+Assume that the user knows exactly what he or she is doing, and do not
+ask any questions. Skip patches whose headers
+do not say which file is to be patched; patch files even though they have the
+wrong version for the
+.B Prereq:
+line in the patch; and assume that
patches are not reversed even if they look like they are.
This option does not suppress commentary; use
.B \-s
for that.
-.TP 5
-.B "\-t, \-\-batch"
-similar to
-.BR \-f ,
-in that it suppresses questions, but makes some different assumptions:
-skip patches for which a file to patch can't be found (the same as \fB\-f\fP);
-skip patches for which the file has the wrong version for the ``Prereq:'' line
-in the patch; and assume that patches are reversed if they look like
-they are.
-.TP 5
-.B "\-F number, \-\-fuzz=number"
-sets the maximum fuzz factor.
-This option only applies to context diffs, and causes
-.I patch
+.TP
+\fB\-F\fP \fInumber\fP or \fB\*=fuzz=\fP\fInumber\fP
+Set the maximum fuzz factor.
+This option only applies to diffs that have context, and causes
+.B patch
to ignore up to that many lines in looking for places to install a hunk.
Note that a larger fuzz factor increases the odds of a faulty patch.
The default fuzz factor is 2, and it may not be set to more than
the number of lines of context in the context diff, ordinarily 3.
-.TP 5
-.B "\-l, \-\-ignore\-whitespace"
-causes the pattern matching to be done loosely, in case the tabs and
-spaces have been munged in your input file.
-Any sequence of whitespace in the pattern line will match any sequence
-in the input file.
+.TP
+.B "\*=help"
+Print a summary of options and exit.
+.TP
+\fB\-i\fP \fIpatchfile\fP or \fB\*=input=\fP\fIpatchfile\fP
+Read the patch from
+.IR patchfile .
+If
+.I patchfile
+is
+.BR \- ,
+read from standard input, the default.
+.TP
+\fB\-l\fP or \fB\*=ignore\-whitespace\fP
+Match patterns loosely, in case tabs or spaces
+have been munged in your files.
+Any sequence of one or more blanks in the patch file matches any sequence
+in the original file, and sequences of blanks at the ends of lines are ignored.
Normal characters must still match exactly.
-Each line of the context must still match a line in the input file.
-.TP 5
-.B "\-n, \-\-normal"
-forces
-.I patch
-to interpret the patch file as a normal diff.
-.TP 5
-.B "\-N, \-\-forward"
-causes
-.I patch
-to ignore patches that it thinks are reversed or already applied.
+Each line of the context must still match a line in the original file.
+.TP
+\fB\-n\fP or \fB\*=normal\fP
+Interpret the patch file as a normal diff.
+.TP
+\fB\-N\fP or \fB\*=forward\fP
+Ignore patches that seem to be reversed or already applied.
See also
.B \-R .
-.TP 5
-.B "\-o file, \-\-output=file"
-causes
-.B file
-to be interpreted as the output file name.
-.TP 5
-.B "\-p[number], \-\-strip[=number]"
-sets the pathname strip count,
-which controls how pathnames found in the patch file are treated, in case
-the you keep your files in a different directory than the person who sent
+.TP
+\fB\-o\fP \fIfile\fP or \fB\*=output=\fP\fIfile\fP
+Send output to
+.I file
+instead of patching files in place.
+.TP
+\fB\-p\fP\fInumber\fP or \fB\*=strip\fP\fB=\fP\fInumber\fP
+Strip the smallest prefix containing
+.I number
+leading slashes from each file name found in the patch file.
+A sequence of one or more adjacent slashes is counted as a single slash.
+This controls how file names found in the patch file are treated, in case
+you keep your files in a different directory than the person who sent
out the patch.
-The strip count specifies how many slashes are to be stripped from
-the front of the pathname.
-(Any intervening directory names also go away.)
For example, supposing the file name in the patch file was
-.sp
- /u/howard/src/blurfl/blurfl.c
-.sp
+.Sp
+ \fB/u/howard/src/blurfl/blurfl.c\fP
+.Sp
setting
-.B \-p
-or
.B \-p0
-gives the entire pathname unmodified,
+gives the entire file name unmodified,
.B \-p1
gives
-.sp
- u/howard/src/blurfl/blurfl.c
-.sp
+.Sp
+ \fBu/howard/src/blurfl/blurfl.c\fP
+.Sp
without the leading slash,
.B \-p4
gives
-.sp
- blurfl/blurfl.c
-.sp
+.Sp
+ \fBblurfl/blurfl.c\fP
+.Sp
and not specifying
.B \-p
-at all just gives you "blurfl.c", unless all of the directories in the
-leading path (u/howard/src/blurfl) exist and that path is relative,
-in which case you get the entire pathname unmodified.
+at all just gives you \fBblurfl.c\fP.
Whatever you end up with is looked for either in the current directory,
or the directory specified by the
.B \-d
option.
-.TP 5
-.B "\-r file, \-\-reject\-file=file"
-causes
-.B file
-to be interpreted as the reject file name.
-.TP 5
-.B "\-R, \-\-reverse"
-tells
-.I patch
-that this patch was created with the old and new files swapped.
+With GNU
+.BR patch ,
+the two-argument
+.BI "\-p " N
+form of this option is equivalent to one-argument
+.BI \-p N
+form, but this is not true of traditional
+.BR patch ,
+so the one-argument form is recommended for portability.
+.TP
+\fB\-r\fP \fIfile\fP or \fB\*=reject\-file=\fP\fIfile\fP
+Put rejects into
+.I file
+instead of the default
+.B \&.rej
+file.
+.TP
+\fB\-R\fP or \fB\*=reverse\fP
+Assume that this patch was created with the old and new files swapped.
(Yes, I'm afraid that does happen occasionally, human nature being what it
is.)
-.I Patch
-will attempt to swap each hunk around before applying it.
-Rejects will come out in the swapped format.
+.B patch
+attempts to swap each hunk around before applying it.
+Rejects come out in the swapped format.
The
.B \-R
-option will not work with
-.I ed
+option does not work with
+.B ed
diff scripts because there is too little
information to reconstruct the reverse operation.
.Sp
If the first hunk of a patch fails,
-.I patch
-will reverse the hunk to see if it can be applied that way.
-If it can, you will be asked if you want to have the
+.B patch
+reverses the hunk to see if it can be applied that way.
+If it can, you are asked if you want to have the
.B \-R
option set.
-If it can't, the patch will continue to be applied normally.
+If it can't, the patch continues to be applied normally.
(Note: this method cannot detect a reversed patch if it is a normal diff
and if the first command is an append (i.e. it should have been a delete)
-since appends always succeed, due to the fact that a null context will match
+since appends always succeed, due to the fact that a null context matches
anywhere.
Luckily, most patches add or change lines rather than delete them, so most
-reversed normal diffs will begin with a delete, which will fail, triggering
+reversed normal diffs begin with a delete, which fails, triggering
the heuristic.)
-.TP 5
-.B "\-s, \-\-silent, \-\-quiet"
-makes
-.I patch
-do its work silently, unless an error occurs.
-.TP 5
-.B "\-S, \-\-skip"
-causes
-.I patch
-to ignore this patch from the patch file, but continue on looking
-for the next patch in the file.
-Thus
-.sp
- patch -S + -S + <patchfile
-.sp
-will ignore the first and second of three patches.
-.TP 5
-.B "\-u, \-\-unified"
-forces
-.I patch
-to interpret the patch file as a unified context diff (a unidiff).
-.TP 5
-.B "\-v, \-\-version"
-causes
-.I patch
-to print out its revision header and patch level.
-.TP 5
-.B "\-V method, \-\-version\-\-control=method"
-causes
-.B method
-to be interpreted as a method for creating
+.TP
+\fB\-s\fP or \fB\*=silent\fP or \fB\*=quiet\fP
+Work silently, unless an error occurs.
+.TP
+\fB\-t\fP or \fB\*=batch\fP
+Suppress questions like
+.BR \-f ,
+but make some different assumptions:
+skip patches whose headers do not contain file names (the same as \fB\-f\fP);
+skip patches for which the file has the wrong version for the
+.B Prereq:
+line
+in the patch; and assume that patches are reversed if they look like
+they are.
+.TP
+\fB\-u\fP or \fB\*=unified\fP
+Interpret the patch file as a unified context diff.
+.TP
+\fB\-v\fP or \fB\*=version\fP
+Print out
+.BR patch 's
+revision header and patch level, and exit.
+.TP
+\fB\-V\fP \fImethod\fP or \fB\*=version\-control=\fP\fImethod\fP
+Use
+.I method
+when creating
backup file names. The type of backups made can also be given in the
.B VERSION_CONTROL
environment variable, which is overridden by this option.
-The
-.B -B
-option overrides this option, causing the prefix to always be used for
-making backup file names.
-The value of the
-.B VERSION_CONTROL
-environment variable and the argument to the
-.B -V
-option are like the GNU
-Emacs `version-control' variable; they also recognize synonyms that
-are more descriptive. The valid values are (unique abbreviations are
+.Sp
+The value of
+.I method
+is like the GNU
+Emacs `version-control' variable;
+.B patch
+also recognizes synonyms that
+are more descriptive. The valid values for
+.I method
+are (unique abbreviations are
accepted):
.RS
+.TP 3
+\fBexisting\fP or \fBnil\fP
+Make numbered backups of files that already have them,
+otherwise simple backups.
+If a file is read-only or does not exist,
+check it out from \s-1RCS\s0 if it is under \s-2RCS\s0 control;
+similarly for \s-1SCCS\s0.
.TP
-`t' or `numbered'
-Always make numbered backups.
-.TP
-`nil' or `existing'
-Make numbered backups of files that already
-have them, simple backups of the others.
+\fBnone\fP
+Do not make backups.
This is the default.
.TP
-`never' or `simple'
-Always make simple backups.
+\fBnumbered\fP or \fBt\fP
+Make numbered backups. The numbered backup file name for
+.I F
+is
+.IB F .~ N ~
+where
+.I N
+is the version number.
+.TP
+\fBsimple\fP or \fBnever\fP
+Make simple backups. That is, when patching a file
+.IR F ,
+rename or copy the original instead of removing it.
+The
+.B \-B
+or
+.BR \*=prefix ,
+.B \-y
+or
+.BR \*=basename\-prefix ,
+and
+.B \-z
+or
+.BR \*=suffix
+options specify the simple backup file name.
+If none of these options are given, then a simple backup suffix is used;
+it is the value of the
+.B SIMPLE_BACKUP_SUFFIX
+environment variable if set, and is
+.B \&.orig
+otherwise.
+.PP
+With numbered or simple backups,
+if the backup file name is just another name for the original file,
+.B patch
+creates a new backup file name by changing the first lowercase letter
+in the last component of the file's name into uppercase. If there are
+no more lowercase letters in the name, it removes the first character
+from the name. It repeats this process until it fails, or comes up with a
+backup file that is not just another name for the original file.
.RE
-.TP 5
-.B "\-x number, \-\-debug=number"
-sets internal debugging flags, and is of interest only to
-.I patch
+.TP
+\fB\-x\fP \fInumber\fP or \fB\*=debug=\fP\fInumber\fP
+Set internal debugging flags of interest only to
+.B patch
patchers.
-.SH AUTHOR
-Larry Wall <lwall@netlabs.com>
-.br
-with many other contributors.
+.TP
+\fB\-y\fP \fIpref\fP or \fB\*=basename\-prefix=\fP\fIpref\fP
+Prefix the basename of the simple backup file name with
+.IR pref .
+For example, with
+.B "\-y .del/"
+the backup file name for
+.B src/patch/util.c
+is
+.BR src/patch/.del/util.c .
+.TP
+\fB\-z\fP \fIsuff\fP or \fB\*=suffix=\fP\fIsuff\fP
+Use
+.I suff
+as the simple backup suffix.
+The backup extension may also be specified by the
+.B SIMPLE_BACKUP_SUFFIX
+environment variable, which is overridden by this option.
+If the backup suffix would create a file name that is too long,
+the backup suffix
+.B ~
+is used instead.
.SH ENVIRONMENT
+.TP 3
+.B POSIXLY_CORRECT
+If set,
+.B patch
+conforms more strictly to the Posix standard:
+i.e. it requires that all options precede the
+files in the command line.
.TP
.B TMPDIR
-Directory to put temporary files in; default is /tmp.
+Directory to put temporary files in; default is
+.BR /tmp .
.TP
.B SIMPLE_BACKUP_SUFFIX
-Extension to use for backup file names instead of \*(L".orig\*(R" or
-\*(L"~\*(R".
+Extension to use for simple backup file names instead of
+.BR \&.orig .
.TP
.B VERSION_CONTROL
-Selects when numbered backup files are made.
+Selects version control style; see the
+.B \-v
+or
+.B \*=version_control
+option.
.SH FILES
-$TMPDIR/patch*
-.SH SEE ALSO
-diff(1)
-.SH NOTES FOR PATCH SENDERS
+.IB $TMPDIR "/patch\(**"
+.SH "SEE ALSO"
+.BR diff (1),
+.BR ed (1)
+.SH "NOTES FOR PATCH SENDERS"
There are several things you should bear in mind if you are going to
be sending out patches.
-First, you can save people a lot of grief by keeping a patchlevel.h file
-which is patched to increment the patch level as the first diff in the
-patch file you send out.
-If you put a Prereq: line in with the patch, it won't let them apply
+.PP
+Tell your recipients how to apply the patches.
+This should include which directory to
+.B cd
+to, and which
+.B patch
+options to use. Normally you should specify the
+.BI \-p N
+option with the proper value of
+.IR N .
+The
+.B \-E
+and
+.B \-N
+options are also common.
+Test your procedure by pretending to be a recipient and applying
+your patches to a copy of the original files.
+.PP
+You can save people a lot of grief by keeping a
+.B patchlevel.h
+file which is patched to increment the patch level
+as the first diff in the patch file you send out.
+If you put a
+.B Prereq:
+line in with the patch, it won't let them apply
patches out of order without some warning.
-Second, make sure you've specified the file names right, either in a
-context diff header, or with an Index: line.
-If you are patching something in a subdirectory, be sure to tell the patch
-user to specify a
-.B \-p
-option as needed.
-Third, you can create a file by sending out a diff that compares a
-null file to the file you want to create.
-This will only work if the file you want to create doesn't exist already in
+.PP
+Make sure you've specified the file names right, either in a
+context diff header, or with an
+.B Index:
+line.
+.PP
+You can create a file by sending out a diff that compares an
+empty file (such as
+.BR /dev/null )
+to the file you want to create.
+This only works if the file you want to create doesn't exist already in
the target directory.
-Fourth, take care not to send out reversed patches, since it makes people wonder
+Conversely, you can remove a file by sending out a diff that compares the
+file to be deleted with an empty file.
+The file will be left empty, but not actually be removed unless the
+.B \-E
+or
+.B \*=remove\-empty\-files
+option is given.
+An easy way to generate patches that create and remove files is to use GNU
+.BR diff 's
+.B \*=new\-file
+option.
+.PP
+If the recipient is supposed to use the
+.BI \-p N
+option, do not send output that looks like this:
+.Sp
+.ft B
+ diff \-uNR v2.0.29/prog/README prog/README
+.br
+ \-\-\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+.br
+ +++ prog/README Mon Mar 17 14:58:22 1997
+.ft
+.Sp
+because the two file names have different numbers of slashes,
+and different versions of
+.B patch
+interpret the file names differently.
+To avoid confusion, send output that looks like this instead:
+.Sp
+.ft B
+ diff \-uNR v2.0.29/prog/README v2.0.30/prog/README
+.br
+ \-\-\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
+.br
+ +++ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
+.ft
+.Sp
+.PP
+Take care not to send out reversed patches, since it makes people wonder
whether they already applied the patch.
-Fifth, while you may be able to get away with putting 582 diff listings into
+.PP
+While you may be able to get away with putting 582 diff listings into
one file, it is probably wiser to group related patches into separate files in
case something goes haywire.
.SH DIAGNOSTICS
-Too many to list here, but generally indicative that
-.I patch
+Diagnostics generally indicate that
+.B patch
couldn't parse your patch file.
.PP
-The message \*(L"Hmm...\*(R" indicates that there is unprocessed text in
+If the
+.B \*=verbose
+option is given, the message
+.B Hmm.\|.\|.\&
+indicates that there is unprocessed text in
the patch file and that
-.I patch
+.B patch
is attempting to intuit whether there is a patch in that text and, if so,
what kind of patch it is.
.PP
-.I Patch
-will exit with a non-zero status if any reject files were created.
+.BR patch 's
+exit status is
+0 if all hunks are applied successfully,
+1 if some hunks cannot be applied,
+and 2 if there is more serious trouble.
When applying a set of patches in a loop it behooves you to check this
exit status so you don't apply a later patch to a partially patched file.
.SH CAVEATS
-.I Patch
+.B patch
cannot tell if the line numbers are off in an
-.I ed
-script, and can only detect
-bad line numbers in a normal diff when it finds a \*(L"change\*(R" or
-a \*(L"delete\*(R" command.
+.B ed
+script, and can detect
+bad line numbers in a normal diff only when it finds a change or deletion.
A context diff using fuzz factor 3 may have the same problem.
Until a suitable interactive interface is added, you should probably do
a context diff in these cases to see if the changes made sense.
Of course, compiling without errors is a pretty good indication that the patch
worked, but not always.
.PP
-.I Patch
+.B patch
usually produces the correct results, even when it has to do a lot of
guessing.
However, the results are guaranteed to be correct only when the patch is
applied to exactly the same version of the file that the patch was
generated from.
.SH BUGS
-Could be smarter about partial matches, excessively \&deviant offsets and
+.B patch
+could be smarter about partial matches, excessively deviant offsets and
swapped code, but that would take an extra pass.
.PP
-If code has been duplicated (for instance with #ifdef OLDCODE ... #else ...
-#endif),
-.I patch
+If code has been duplicated (for instance with
+.BR "#ifdef OLDCODE .\|.\|. #else .\|.\|. #endif" ),
+.B patch
is incapable of patching both versions, and, if it works at all, will likely
patch the wrong one, and tell you that it succeeded to boot.
.PP
If you apply a patch you've already applied,
-.I patch
-will think it is a reversed patch, and offer to un-apply the patch.
+.B patch
+thinks it is a reversed patch, and offers to un-apply the patch.
This could be construed as a feature.
-.rn }` ''
+.SH COPYING
+Copyright
+.if t \(co
+1984, 1985, 1986, 1988 Larry Wall.
+.br
+Copyright
+.if t \(co
+1997 Free Software Foundation, Inc.
+.PP
+Permission is granted to make and distribute verbatim copies of
+this manual provided the copyright notice and this permission notice
+are preserved on all copies.
+.PP
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the
+entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+.PP
+Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be included in
+translations approved by the copyright holders instead of in
+the original English.
+.SH AUTHORS
+Larry Wall wrote the original version of
+.BR patch .
+Paul Eggert removed
+.BR patch 's
+arbitrary limits, added support for binary files,
+and made it conform better to Posix.
+Other contributors include Wayne Davison, who added unidiff support,
+and David MacKenzie, who added configuration and backup support.
diff --git a/patchlevel.h b/patchlevel.h
deleted file mode 100644
index d5de3a9..0000000
--- a/patchlevel.h
+++ /dev/null
@@ -1 +0,0 @@
-#define PATCH_VERSION "2.1"
diff --git a/pch.c b/pch.c
index 6b7d77d..f9d2d73 100644
--- a/pch.c
+++ b/pch.c
@@ -1,78 +1,82 @@
-/* $Header: pch.c,v 2.0.1.7 88/06/03 15:13:28 lwall Locked $
- *
- * $Log: pch.c,v $
- * Revision 2.0.2.0 90/05/01 22:17:51 davison
- * patch12u: unidiff support added
- *
- * Revision 2.0.1.7 88/06/03 15:13:28 lwall
- * patch10: Can now find patches in shar scripts.
- * patch10: Hunks that swapped and then swapped back could core dump.
- *
- * Revision 2.0.1.6 87/06/04 16:18:13 lwall
- * pch_swap didn't swap p_bfake and p_efake.
- *
- * Revision 2.0.1.5 87/01/30 22:47:42 lwall
- * Improved responses to mangled patches.
- *
- * Revision 2.0.1.4 87/01/05 16:59:53 lwall
- * New-style context diffs caused double call to free().
- *
- * Revision 2.0.1.3 86/11/14 10:08:33 lwall
- * Fixed problem where a long pattern wouldn't grow the hunk.
- * Also restored p_input_line when backtracking so error messages are right.
- *
- * Revision 2.0.1.2 86/11/03 17:49:52 lwall
- * New-style delete triggers spurious assertion error.
- *
- * Revision 2.0.1.1 86/10/29 15:52:08 lwall
- * Could falsely report new-style context diff.
- *
- * Revision 2.0 86/09/17 15:39:37 lwall
- * Baseline for netwide release.
- *
- */
-
-#include "EXTERN.h"
-#include "common.h"
-#include "util.h"
-#include "INTERN.h"
-#include "pch.h"
+/* reading patches */
+
+/* $Id: pch.c,v 1.7 1997/04/14 05:32:30 eggert Exp $ */
+
+/*
+Copyright 1986, 1987, 1988 Larry Wall
+Copyright 1990, 1991, 1992, 1993, 1997 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#define XTERN extern
+#include <common.h>
+#include <inp.h>
+#include <util.h>
+#undef XTERN
+#define XTERN
+#include <pch.h>
+
+#define INITHUNKMAX 125 /* initial dynamic allocation size */
/* Patch (diff listing) abstract type. */
-static long p_filesize; /* size of the patch file */
+static FILE *pfp; /* patch file pointer */
+static off_t p_filesize; /* size of the patch file */
static LINENUM p_first; /* 1st line number */
static LINENUM p_newfirst; /* 1st line number of replacement */
static LINENUM p_ptrn_lines; /* # lines in pattern */
static LINENUM p_repl_lines; /* # lines in replacement text */
static LINENUM p_end = -1; /* last line in hunk */
static LINENUM p_max; /* max allowed value of p_end */
-static LINENUM p_context = 3; /* # of context lines */
-static LINENUM p_input_line = 0; /* current line # from patch file */
-static char **p_line = Null(char**); /* the text of the hunk */
-static short *p_len = Null(short*); /* length of each line */
-static char *p_Char = Nullch; /* +, -, and ! */
-static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */
+static LINENUM p_prefix_context; /* # of prefix context lines */
+static LINENUM p_suffix_context; /* # of suffix context lines */
+static LINENUM p_input_line; /* current line # from patch file */
+static char **p_line; /* the text of the hunk */
+static size_t *p_len; /* line length including \n if any */
+static char *p_Char; /* +, -, and ! */
+static size_t hunkmax = INITHUNKMAX; /* size of above arrays */
static int p_indent; /* indent to patch */
-static LINENUM p_base; /* where to intuit this time */
+static long p_base; /* where to intuit this time */
static LINENUM p_bline; /* line # of p_base */
-static LINENUM p_start; /* where intuit found a patch */
+static long p_start; /* where intuit found a patch */
static LINENUM p_sline; /* and the line number for it */
static LINENUM p_hunk_beg; /* line number of current hunk */
static LINENUM p_efake = -1; /* end of faked up lines--don't free */
static LINENUM p_bfake = -1; /* beg of faked up lines */
+static enum diff intuit_diff_type PARAMS ((void));
+static size_t pget_line PARAMS ((int));
+static size_t get_line PARAMS ((void));
+static bool incomplete_line PARAMS ((void));
+static bool grow_hunkmax PARAMS ((void));
+static void next_intuit_at PARAMS ((long, LINENUM));
+static void skip_to PARAMS ((long, LINENUM));
+
/* Prepare to look for the next patch in the patch file. */
void
re_patch()
{
- p_first = Nulline;
- p_newfirst = Nulline;
- p_ptrn_lines = Nulline;
- p_repl_lines = Nulline;
- p_end = (LINENUM)-1;
- p_max = Nulline;
+ p_first = 0;
+ p_newfirst = 0;
+ p_ptrn_lines = 0;
+ p_repl_lines = 0;
+ p_end = -1;
+ p_max = 0;
p_indent = 0;
}
@@ -80,23 +84,45 @@ re_patch()
void
open_patch_file(filename)
-char *filename;
+ char const *filename;
{
- if (filename == Nullch || !*filename || strEQ(filename, "-")) {
- pfp = fopen(TMPPATNAME, "w");
- if (pfp == Nullfp)
- pfatal2("can't create %s", TMPPATNAME);
- while (fgets(buf, sizeof buf, stdin) != Nullch)
- fputs(buf, pfp);
- Fclose(pfp);
- filename = TMPPATNAME;
+ long file_pos = 0;
+ struct stat st;
+ if (!filename || !*filename || strEQ (filename, "-"))
+ {
+ if (fstat (STDIN_FILENO, &st) != 0)
+ pfatal ("fstat");
+ if (S_ISREG (st.st_mode))
+ {
+ pfp = stdin;
+ file_pos = ftell (stdin);
+ filename = 0;
+ }
+ else
+ {
+ size_t charsread;
+ pfp = fopen (TMPPATNAME, "w");
+ if (!pfp)
+ pfatal ("can't create %s", TMPPATNAME);
+ while ((charsread = fread (buf, 1, bufsize, stdin)) != 0)
+ if (fwrite (buf, 1, charsread, pfp) != charsread)
+ write_fatal ();
+ if (ferror (stdin) || fclose (stdin) != 0)
+ read_fatal ();
+ if (fclose (pfp) != 0)
+ write_fatal ();
+ filename = TMPPATNAME;
+ }
+ }
+ if (filename) {
+ pfp = fopen (filename, "r");
+ if (!pfp)
+ pfatal ("patch file %s not found", filename);
+ if (fstat (fileno (pfp), &st) != 0)
+ pfatal ("fstat");
}
- pfp = fopen(filename, "r");
- if (pfp == Nullfp)
- pfatal2("patch file %s not found", filename);
- Fstat(fileno(pfp), &filestat);
- p_filesize = filestat.st_size;
- next_intuit_at(0L,1L); /* start at the beginning */
+ p_filesize = st.st_size;
+ next_intuit_at (file_pos, (LINENUM) 1);
set_hunkmax();
}
@@ -105,39 +131,32 @@ char *filename;
void
set_hunkmax()
{
-#ifndef lint
- if (p_line == Null(char**))
- p_line = (char**) malloc((MEM)hunkmax * sizeof(char *));
- if (p_len == Null(short*))
- p_len = (short*) malloc((MEM)hunkmax * sizeof(short));
-#endif
- if (p_Char == Nullch)
- p_Char = (char*) malloc((MEM)hunkmax * sizeof(char));
+ if (!p_line)
+ p_line = (char **) malloc (hunkmax * sizeof *p_line);
+ if (!p_len)
+ p_len = (size_t *) malloc (hunkmax * sizeof *p_len);
+ if (!p_Char)
+ p_Char = malloc (hunkmax * sizeof *p_Char);
}
/* Enlarge the arrays containing the current hunk of patch. */
-void
+static bool
grow_hunkmax()
{
hunkmax *= 2;
- /*
- * Note that on most systems, only the p_line array ever gets fresh memory
- * since p_len can move into p_line's old space, and p_Char can move into
- * p_len's old space. Not on PDP-11's however. But it doesn't matter.
- */
- assert(p_line != Null(char**) && p_len != Null(short*) && p_Char != Nullch);
-#ifndef lint
- p_line = (char**) realloc((char*)p_line, (MEM)hunkmax * sizeof(char *));
- p_len = (short*) realloc((char*)p_len, (MEM)hunkmax * sizeof(short));
- p_Char = (char*) realloc((char*)p_Char, (MEM)hunkmax * sizeof(char));
-#endif
- if (p_line != Null(char**) && p_len != Null(short*) && p_Char != Nullch)
- return;
+ assert (p_line && p_len && p_Char);
+ if ((p_line = (char **) realloc (p_line, hunkmax * sizeof (*p_line)))
+ && (p_len = (size_t *) realloc (p_len, hunkmax * sizeof (*p_len)))
+ && (p_Char = realloc (p_Char, hunkmax * sizeof (*p_Char))))
+ return TRUE;
if (!using_plan_a)
- fatal1("out of memory\n");
- out_of_mem = TRUE; /* whatever is null will be allocated again */
- /* from within plan_a(), of all places */
+ memory_fatal ();
+ /* Don't free previous values of p_line etc.,
+ since some broken implementations free them for us.
+ Whatever is null will be allocated again from within plan_a (),
+ of all places. */
+ return FALSE;
}
/* True if the remainder of the patch file contains a diff of some sort. */
@@ -145,55 +164,47 @@ grow_hunkmax()
bool
there_is_another_patch()
{
- if (p_base != 0L && p_base >= p_filesize) {
- if (verbose)
- say1("done\n");
+ if (p_base != 0 && p_base >= p_filesize) {
+ if (verbosity == VERBOSE)
+ say ("done\n");
return FALSE;
}
- if (verbose)
- say1("Hmm...");
+ if (verbosity == VERBOSE)
+ say ("Hmm...");
diff_type = intuit_diff_type();
- if (!diff_type) {
- if (p_base != 0L) {
- if (verbose)
- say1(" Ignoring the trailing garbage.\ndone\n");
- }
- else
- say1(" I can't seem to find a patch in there anywhere.\n");
+ if (diff_type == NO_DIFF) {
+ if (verbosity == VERBOSE)
+ say (p_base
+ ? " Ignoring the trailing garbage.\ndone\n"
+ : " I can't seem to find a patch in there anywhere.\n");
return FALSE;
}
- if (verbose)
- say3(" %sooks like %s to me...\n",
- (p_base == 0L ? "L" : "The next patch l"),
+ if (verbosity == VERBOSE)
+ say (" %sooks like %s to me...\n",
+ (p_base == 0 ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
diff_type == NORMAL_DIFF ? "a normal diff" :
"an ed script" );
- if (p_indent && verbose)
- say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
+ if (p_indent && verbosity != SILENT)
+ say ("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
skip_to(p_start,p_sline);
- while (filearg[0] == Nullch) {
+ while (!inname) {
if (force || batch) {
- say1("No file to patch. Skipping...\n");
- filearg[0] = savestr(bestguess);
+ say ("No file to patch. Skipping...\n");
+ skip_rest_of_patch = TRUE;
return TRUE;
}
- ask1("File to patch: ");
- if (*buf != '\n') {
- if (bestguess)
- free(bestguess);
- bestguess = savestr(buf);
- filearg[0] = fetchname(buf, 0, FALSE);
- }
- if (filearg[0] == Nullch) {
- ask1("No file found--skip this patch? [n] ");
- if (*buf != 'y') {
+ ask ("File to patch: ");
+ inname = fetchname (buf, 0);
+ if (!inname) {
+ ask ("Skip this patch? [y] ");
+ if (*buf == 'n') {
continue;
}
- if (verbose)
- say1("Skipping patch...\n");
- filearg[0] = fetchname(bestguess, 0, TRUE);
+ if (verbosity != SILENT)
+ say ("Skipping patch...\n");
skip_rest_of_patch = TRUE;
return TRUE;
}
@@ -203,31 +214,30 @@ there_is_another_patch()
/* Determine what kind of diff is in the remaining part of the patch file. */
-int
+static enum diff
intuit_diff_type()
{
- Reg4 long this_line = 0;
- Reg5 long previous_line;
- Reg6 long first_command_line = -1;
- long fcl_line;
- Reg7 bool last_line_was_command = FALSE;
- Reg8 bool this_is_a_command = FALSE;
- Reg9 bool stars_last_line = FALSE;
- Reg10 bool stars_this_line = FALSE;
- Reg3 int indent;
- Reg1 char *s;
- Reg2 char *t;
- char *indtmp = Nullch;
- char *oldtmp = Nullch;
- char *newtmp = Nullch;
- char *indname = Nullch;
- char *oldname = Nullch;
- char *newname = Nullch;
- Reg11 int retval;
- bool no_filearg = (filearg[0] == Nullch);
-
+ register char *s;
+ register char *t;
+ register int indent;
+ register long this_line = 0;
+ register long previous_line;
+ register long first_command_line = -1;
+ LINENUM fcl_line = 0; /* Pacify `gcc -W'. */
+ register bool last_line_was_command = FALSE;
+ register bool this_is_a_command = FALSE;
+ register bool stars_last_line = FALSE;
+ register bool stars_this_line = FALSE;
+ enum nametype { OLD, NEW, INDEX, NONE } i;
+ char *name[3];
+ struct stat st[3];
+ int stat_errno[3];
+ int dir_count[3];
+ register enum diff retval;
+
+ name[OLD] = name[NEW] = name[INDEX] = 0;
ok_to_create_file = FALSE;
- Fseek(pfp, p_base, 0);
+ Fseek (pfp, p_base, SEEK_SET);
p_input_line = p_bline - 1;
for (;;) {
previous_line = this_line;
@@ -235,9 +245,8 @@ intuit_diff_type()
stars_last_line = stars_this_line;
this_line = ftell(pfp);
indent = 0;
- p_input_line++;
- if (fgets(buf, sizeof buf, pfp) == Nullch) {
- if (first_command_line >= 0L) {
+ if (! pget_line (0)) {
+ if (first_command_line >= 0) {
/* nothing but deletes!? */
p_start = first_command_line;
p_sline = fcl_line;
@@ -247,44 +256,50 @@ intuit_diff_type()
else {
p_start = this_line;
p_sline = p_input_line;
- retval = 0;
+ retval = NO_DIFF;
goto scan_exit;
}
}
for (s = buf; *s == ' ' || *s == '\t' || *s == 'X'; s++) {
if (*s == '\t')
- indent += 8 - (indent % 8);
+ indent = (indent + 8) & ~7;
else
indent++;
}
- for (t=s; isdigit(*t) || *t == ','; t++) ;
- this_is_a_command = (isdigit(*s) &&
+ for (t = s; ISDIGIT (*t) || *t == ','; t++)
+ continue;
+ this_is_a_command = (ISDIGIT (*s) &&
(*t == 'd' || *t == 'c' || *t == 'a') );
- if (first_command_line < 0L && this_is_a_command) {
+ if (first_command_line < 0 && this_is_a_command) {
first_command_line = this_line;
fcl_line = p_input_line;
p_indent = indent; /* assume this for now */
}
if (!stars_last_line && strnEQ(s, "*** ", 4))
- oldtmp = savestr(s+4);
+ name[OLD] = fetchname (s+4, strippath);
else if (strnEQ(s, "--- ", 4))
- newtmp = savestr(s+4);
+ name[NEW] = fetchname (s+4, strippath);
else if (strnEQ(s, "+++ ", 4))
- oldtmp = savestr(s+4); /* pretend it is the old name */
+ name[OLD] = fetchname (s+4, strippath); /* Swap with NEW below. */
else if (strnEQ(s, "Index:", 6))
- indtmp = savestr(s+6);
+ name[INDEX] = fetchname (s+6, strippath);
else if (strnEQ(s, "Prereq:", 7)) {
- for (t=s+7; isspace(*t); t++) ;
- revision = savestr(t);
- for (t=revision; *t && !isspace(*t); t++) ;
- *t = '\0';
- if (!*revision) {
- free(revision);
- revision = Nullch;
+ for (t = s + 7; ISSPACE ((unsigned char) *t); t++)
+ continue;
+ revision = t;
+ for (t = revision; *t && !ISSPACE ((unsigned char) *t); t++)
+ continue;
+ if (t == revision)
+ revision = 0;
+ else {
+ char oldc = *t;
+ *t = '\0';
+ revision = savestr (revision);
+ *t = oldc;
}
}
- if ((!diff_type || diff_type == ED_DIFF) &&
- first_command_line >= 0L &&
+ if ((diff_type == NO_DIFF || diff_type == ED_DIFF) &&
+ first_command_line >= 0 &&
strEQ(s, ".\n") ) {
p_indent = indent;
p_start = first_command_line;
@@ -292,19 +307,34 @@ intuit_diff_type()
retval = ED_DIFF;
goto scan_exit;
}
- if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) {
- if (!atol(s+3))
+ if ((diff_type == NO_DIFF || diff_type == UNI_DIFF)
+ && strnEQ(s, "@@ -", 4)) {
+ s += 3;
+ if (reverse)
+ {
+ while (*s != ' ' && *s != '\n')
+ s++;
+ while (*s == ' ')
+ s++;
+ }
+ if (!atol(s))
ok_to_create_file = TRUE;
p_indent = indent;
p_start = this_line;
p_sline = p_input_line;
retval = UNI_DIFF;
+ t = name[OLD];
+ name[OLD] = name[NEW];
+ name[NEW] = t;
goto scan_exit;
}
stars_this_line = strnEQ(s, "********", 8);
- if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
- strnEQ(s, "*** ", 4)) {
- if (!atol(s+4))
+ if ((diff_type == NO_DIFF
+ || diff_type == CONTEXT_DIFF
+ || diff_type == NEW_CONTEXT_DIFF)
+ && stars_last_line && strnEQ (s, "*** ", 4)) {
+ if (! reverse)
+ if (! atol (s + 4))
ok_to_create_file = TRUE;
/* if this is a new context diff the character just before */
/* the newline is a '*'. */
@@ -314,9 +344,22 @@ intuit_diff_type()
p_start = previous_line;
p_sline = p_input_line - 1;
retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF);
+ if (reverse)
+ {
+ /* If the patch is a reversed context diff,
+ scan the entire first hunk to see whether
+ it's OK to create the file. */
+ long saved_p_base = p_base;
+ LINENUM saved_p_bline = p_bline;
+ p_input_line = p_sline;
+ Fseek (pfp, previous_line, SEEK_SET);
+ if (another_hunk (retval) && ! p_ptrn_lines && p_first == 1)
+ ok_to_create_file = TRUE;
+ next_intuit_at (saved_p_base, saved_p_bline);
+ }
goto scan_exit;
}
- if ((!diff_type || diff_type == NORMAL_DIFF) &&
+ if ((diff_type == NO_DIFF || diff_type == NORMAL_DIFF) &&
last_line_was_command &&
(strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) {
p_start = previous_line;
@@ -326,72 +369,68 @@ intuit_diff_type()
goto scan_exit;
}
}
+
scan_exit:
- if (no_filearg) {
- if (indtmp != Nullch)
- indname = fetchname(indtmp, strippath, ok_to_create_file);
- if (oldtmp != Nullch)
- oldname = fetchname(oldtmp, strippath, ok_to_create_file);
- if (newtmp != Nullch)
- newname = fetchname(newtmp, strippath, ok_to_create_file);
- if (oldname && newname) {
- if (strlen(oldname) < strlen(newname))
- filearg[0] = savestr(oldname);
- else
- filearg[0] = savestr(newname);
- }
- else if (oldname)
- filearg[0] = savestr(oldname);
- else if (newname)
- filearg[0] = savestr(newname);
- else if (indname)
- filearg[0] = savestr(indname);
- }
- if (bestguess) {
- free(bestguess);
- bestguess = Nullch;
- }
- if (filearg[0] != Nullch)
- bestguess = savestr(filearg[0]);
- else if (indtmp != Nullch)
- bestguess = fetchname(indtmp, strippath, TRUE);
- else {
- if (oldtmp != Nullch)
- oldname = fetchname(oldtmp, strippath, TRUE);
- if (newtmp != Nullch)
- newname = fetchname(newtmp, strippath, TRUE);
- if (oldname && newname) {
- if (strlen(oldname) < strlen(newname))
- bestguess = savestr(oldname);
- else
- bestguess = savestr(newname);
+
+ /* Use algorithm specified by POSIX 1003.2b/D11 to deduce `inname',
+ the name of the file to patch; except that if the patch syntactically
+ can create a file, before asking the user for a file name
+ redo the earlier steps in sequence, this time ignoring the
+ nonexistence of a file if the path length of the existing directory
+ in the file name is a maximum among all the candidate file names. */
+
+ for (i = OLD; i <= INDEX; i++)
+ if (!inname && name[i])
+ {
+ if (stat (name[i], &st[i]) != 0)
+ stat_errno[i] = errno;
+ else
+ {
+ stat_errno[i] = 0;
+ break;
+ }
}
- else if (oldname)
- bestguess = savestr(oldname);
- else if (newname)
- bestguess = savestr(newname);
- }
- if (indtmp != Nullch)
- free(indtmp);
- if (oldtmp != Nullch)
- free(oldtmp);
- if (newtmp != Nullch)
- free(newtmp);
- if (indname != Nullch)
- free(indname);
- if (oldname != Nullch)
- free(oldname);
- if (newname != Nullch)
- free(newname);
+
+ if (i == NONE && !inname && ok_to_create_file)
+ {
+ int dir_count_max = 0;
+
+ for (i = OLD; i <= INDEX; i++)
+ if (name[i])
+ {
+ dir_count[i] = countdirs (name[i]);
+ if (dir_count_max < dir_count[i])
+ dir_count_max = dir_count[i];
+ }
+
+ for (i = OLD; i <= INDEX; i++)
+ if (name[i] && dir_count[i] == dir_count_max)
+ break;
+ }
+
+ if (i == NONE)
+ inerrno = -1;
+ else
+ {
+ inname = name[i];
+ name[i] = 0;
+ inerrno = stat_errno[i];
+ instat = st[i];
+ }
+
+ for (i = OLD; i <= INDEX; i++)
+ if (name[i])
+ free (name[i]);
+
return retval;
}
/* Remember where this patch ends so we know where to start up again. */
-void
+static void
next_intuit_at(file_pos,file_line)
long file_pos;
-long file_line;
+LINENUM file_line;
{
p_base = file_pos;
p_bline = file_line;
@@ -399,26 +438,36 @@ long file_line;
/* Basically a verbose fseek() to the actual diff listing. */
-void
+static void
skip_to(file_pos,file_line)
long file_pos;
-long file_line;
+LINENUM file_line;
{
- char *ret;
+ register FILE *i = pfp;
+ register FILE *o = stdout;
+ register int c;
assert(p_base <= file_pos);
- if (verbose && p_base < file_pos) {
- Fseek(pfp, p_base, 0);
- say1("The text leading up to this was:\n--------------------------\n");
- while (ftell(pfp) < file_pos) {
- ret = fgets(buf, sizeof buf, pfp);
- assert(ret != Nullch);
- say2("|%s", buf);
- }
- say1("--------------------------\n");
+ if ((verbosity == VERBOSE || !inname) && p_base < file_pos) {
+ Fseek (i, p_base, SEEK_SET);
+ say ("The text leading up to this was:\n--------------------------\n");
+
+ while (ftell (i) < file_pos)
+ {
+ putc ('|', o);
+ do
+ {
+ if ((c = getc (i)) == EOF)
+ read_fatal ();
+ putc (c, o);
+ }
+ while (c != '\n');
+ }
+
+ say ("--------------------------\n");
}
else
- Fseek(pfp, file_pos, 0);
+ Fseek (i, file_pos, SEEK_SET);
p_input_line = file_line - 1;
}
@@ -426,18 +475,20 @@ long file_line;
static void
malformed ()
{
- fatal3("malformed patch at line %ld: %s", p_input_line, buf);
+ fatal ("malformed patch at line %ld: %s", p_input_line, buf);
/* about as informative as "Syntax error" in C */
}
-/* True if there is more of the current diff listing to process. */
+/* 1 if there is more of the current diff listing to process;
+ 0 if not; -1 if ran out of memory. */
-bool
-another_hunk()
+int
+another_hunk (difftype)
+ enum diff difftype;
{
- Reg1 char *s;
- Reg8 char *ret;
- Reg2 int context = 0;
+ register char *s;
+ register LINENUM context = 0;
+ register size_t chars_read;
while (p_end >= 0) {
if (p_end == p_efake)
@@ -450,54 +501,60 @@ another_hunk()
p_efake = -1;
p_max = hunkmax; /* gets reduced when --- found */
- if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) {
+ if (difftype == CONTEXT_DIFF || difftype == NEW_CONTEXT_DIFF) {
long line_beginning = ftell(pfp);
/* file pos of the current line */
LINENUM repl_beginning = 0; /* index of --- line */
- Reg4 LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */
- Reg5 LINENUM fillsrc; /* index of first line to copy */
- Reg6 LINENUM filldst; /* index of first missing line */
+ register LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */
+ register LINENUM fillsrc; /* index of first line to copy */
+ register LINENUM filldst; /* index of first missing line */
bool ptrn_spaces_eaten = FALSE; /* ptrn was slightly misformed */
- Reg9 bool repl_could_be_missing = TRUE;
- /* no + or ! lines in this hunk */
+ bool some_context = FALSE; /* (perhaps internal) context seen */
+ register bool repl_could_be_missing = TRUE;
bool repl_missing = FALSE; /* we are now backtracking */
long repl_backtrack_position = 0;
/* file pos of first repl line */
LINENUM repl_patch_line; /* input line number for same */
- Reg7 LINENUM ptrn_copiable = 0;
+ LINENUM repl_context; /* context for same */
+ register LINENUM ptrn_copiable = 0;
/* # of copiable lines in ptrn */
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch || strnNE(buf, "********", 8)) {
+ /* Pacify `gcc -Wall'. */
+ fillsrc = filldst = repl_patch_line = repl_context = 0;
+
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1
+ || chars_read <= 8
+ || strncmp (buf, "********", 8) != 0) {
next_intuit_at(line_beginning,p_input_line);
- return FALSE;
+ return chars_read == (size_t) -1 ? -1 : 0;
}
- p_context = 100;
+ p_prefix_context = -1;
p_hunk_beg = p_input_line + 1;
while (p_end < p_max) {
- line_beginning = ftell(pfp);
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch) {
- if (p_max - p_end < 4)
- Strcpy(buf, " \n"); /* assume blank lines got chopped */
- else {
- if (repl_beginning && repl_could_be_missing) {
- repl_missing = TRUE;
- goto hunk_done;
- }
- fatal1("unexpected end of file in patch\n");
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1)
+ return -1;
+ if (!chars_read) {
+ if (repl_beginning && repl_could_be_missing) {
+ repl_missing = TRUE;
+ goto hunk_done;
+ }
+ if (p_max - p_end < 4) {
+ strcpy (buf, " \n"); /* assume blank lines got chopped */
+ chars_read = 3;
+ } else {
+ fatal ("unexpected end of file in patch");
}
}
p_end++;
+ if (p_end == hunkmax)
+ fatal ("unterminated hunk starting at line %ld; giving up at line %ld: %s",
+ pch_hunk_beg (), p_input_line, buf);
assert(p_end < hunkmax);
p_Char[p_end] = *buf;
-#ifdef zilog
- p_line[(short)p_end] = Nullch;
-#else
- p_line[p_end] = Nullch;
-#endif
+ p_len[p_end] = 0;
+ p_line[p_end] = 0;
switch (*buf) {
case '*':
if (strnEQ(buf, "********", 8)) {
@@ -506,7 +563,7 @@ another_hunk()
goto hunk_done;
}
else
- fatal2("unexpected end of hunk at line %ld\n",
+ fatal ("unexpected end of hunk at line %ld",
p_input_line);
}
if (p_end != 0) {
@@ -514,23 +571,27 @@ another_hunk()
repl_missing = TRUE;
goto hunk_done;
}
- fatal3("unexpected *** at line %ld: %s", p_input_line, buf);
+ fatal ("unexpected `***' at line %ld: %s",
+ p_input_line, buf);
}
context = 0;
- p_line[p_end] = savestr(buf);
- if (out_of_mem) {
+ p_len[p_end] = strlen (buf);
+ if (! (p_line[p_end] = savestr (buf))) {
p_end--;
- return FALSE;
+ return -1;
}
- for (s=buf; *s && !isdigit(*s); s++) ;
+ for (s = buf; *s && !ISDIGIT (*s); s++)
+ continue;
if (!*s)
malformed ();
if (strnEQ(s,"0,0",3))
- strcpy(s,s+2);
+ remove_prefix (s, 2);
p_first = (LINENUM) atol(s);
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
if (*s == ',') {
- for (; *s && !isdigit(*s); s++) ;
+ while (*s && !ISDIGIT (*s))
+ s++;
if (!*s)
malformed ();
p_ptrn_lines = ((LINENUM)atol(s)) - p_first + 1;
@@ -543,11 +604,14 @@ another_hunk()
}
p_max = p_ptrn_lines + 6; /* we need this much at least */
while (p_max >= hunkmax)
- grow_hunkmax();
+ if (! grow_hunkmax ())
+ return -1;
p_max = hunkmax;
break;
case '-':
if (buf[1] == '-') {
+ if (p_prefix_context == -1)
+ p_prefix_context = context;
if (repl_beginning ||
(p_end != p_ptrn_lines + 1 + (p_Char[p_end-1] == '\n')))
{
@@ -565,13 +629,13 @@ another_hunk()
repl_missing = TRUE;
goto hunk_done;
}
- fatal3(
-"duplicate \"---\" at line %ld--check line numbers at line %ld\n",
+ fatal (
+"duplicate \"---\" at line %ld--check line numbers at line %ld",
p_input_line, p_hunk_beg + repl_beginning);
}
else {
- fatal4(
-"%s \"---\" at line %ld--check line numbers at line %ld\n",
+ fatal (
+"%s \"---\" at line %ld--check line numbers at line %ld",
(p_end <= p_ptrn_lines
? "Premature"
: "Overdue" ),
@@ -582,21 +646,27 @@ another_hunk()
repl_beginning = p_end;
repl_backtrack_position = ftell(pfp);
repl_patch_line = p_input_line;
- p_line[p_end] = savestr(buf);
- if (out_of_mem) {
+ repl_context = context;
+ p_len[p_end] = strlen (buf);
+ if (! (p_line[p_end] = savestr (buf))) {
p_end--;
- return FALSE;
+ return -1;
}
p_Char[p_end] = '=';
- for (s=buf; *s && !isdigit(*s); s++) ;
+ for (s = buf; *s && !ISDIGIT (*s); s++)
+ continue;
if (!*s)
malformed ();
p_newfirst = (LINENUM) atol(s);
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
if (*s == ',') {
- for (; *s && !isdigit(*s); s++) ;
- if (!*s)
- malformed ();
+ do
+ {
+ if (!*++s)
+ malformed ();
+ }
+ while (!ISDIGIT (*s));
p_repl_lines = ((LINENUM)atol(s)) - p_newfirst + 1;
}
else if (p_newfirst)
@@ -606,51 +676,70 @@ another_hunk()
p_newfirst = 1;
}
p_max = p_repl_lines + p_end;
- if (p_max > MAXHUNKSIZE)
- fatal4("hunk too large (%ld lines) at line %ld: %s",
- p_max, p_input_line, buf);
while (p_max >= hunkmax)
- grow_hunkmax();
+ if (! grow_hunkmax ())
+ return -1;
if (p_repl_lines != ptrn_copiable
- && (p_context != 0 || p_repl_lines != 1))
+ && (p_prefix_context != 0
+ || context != 0
+ || p_repl_lines != 1))
repl_could_be_missing = FALSE;
+ context = 0;
break;
}
goto change_line;
case '+': case '!':
repl_could_be_missing = FALSE;
change_line:
- if (buf[1] == '\n' && canonicalize)
- strcpy(buf+1," \n");
- if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' &&
- repl_beginning && repl_could_be_missing) {
+ s = buf + 1;
+ chars_read--;
+ if (*s == '\n' && canonicalize) {
+ strcpy (s, " \n");
+ chars_read = 2;
+ }
+ if (*s == ' ' || *s == '\t') {
+ s++;
+ chars_read--;
+ } else if (repl_beginning && repl_could_be_missing) {
repl_missing = TRUE;
goto hunk_done;
}
- if (context >= 0) {
- if (context < p_context)
- p_context = context;
- context = -1000;
- }
- p_line[p_end] = savestr(buf+2);
- if (out_of_mem) {
+ if (p_prefix_context == -1)
+ p_prefix_context = context;
+ chars_read -=
+ (1 < chars_read
+ && p_end == (repl_beginning ? p_max : p_ptrn_lines)
+ && incomplete_line ());
+ p_len[p_end] = chars_read;
+ if (! (p_line[p_end] = savebuf (s, chars_read))) {
p_end--;
- return FALSE;
+ return -1;
}
+ context = 0;
break;
- case '\t': case '\n': /* assume the 2 spaces got eaten */
+ case '\t': case '\n': /* assume spaces got eaten */
+ s = buf;
+ if (*buf == '\t') {
+ s++;
+ chars_read--;
+ }
if (repl_beginning && repl_could_be_missing &&
- (!ptrn_spaces_eaten || diff_type == NEW_CONTEXT_DIFF) ) {
+ (!ptrn_spaces_eaten || difftype == NEW_CONTEXT_DIFF) ) {
repl_missing = TRUE;
goto hunk_done;
}
- p_line[p_end] = savestr(buf);
- if (out_of_mem) {
+ chars_read -=
+ (1 < chars_read
+ && p_end == (repl_beginning ? p_max : p_ptrn_lines)
+ && incomplete_line ());
+ p_len[p_end] = chars_read;
+ if (! (p_line[p_end] = savebuf (buf, chars_read))) {
p_end--;
- return FALSE;
+ return -1;
}
if (p_end != p_ptrn_lines + 1) {
ptrn_spaces_eaten |= (repl_beginning != 0);
+ some_context = TRUE;
context++;
if (!repl_beginning)
ptrn_copiable++;
@@ -658,18 +747,31 @@ another_hunk()
}
break;
case ' ':
- if (!isspace(buf[1]) &&
- repl_beginning && repl_could_be_missing) {
+ s = buf + 1;
+ chars_read--;
+ if (*s == '\n' && canonicalize) {
+ strcpy (s, "\n");
+ chars_read = 2;
+ }
+ if (*s == ' ' || *s == '\t') {
+ s++;
+ chars_read--;
+ } else if (repl_beginning && repl_could_be_missing) {
repl_missing = TRUE;
goto hunk_done;
}
+ some_context = TRUE;
context++;
if (!repl_beginning)
ptrn_copiable++;
- p_line[p_end] = savestr(buf+2);
- if (out_of_mem) {
+ chars_read -=
+ (1 < chars_read
+ && p_end == (repl_beginning ? p_max : p_ptrn_lines)
+ && incomplete_line ());
+ p_len[p_end] = chars_read;
+ if (! (p_line[p_end] = savebuf (buf + 2, chars_read))) {
p_end--;
- return FALSE;
+ return -1;
}
break;
default:
@@ -679,38 +781,29 @@ another_hunk()
}
malformed ();
}
- /* set up p_len for strncmp() so we don't have to */
- /* assume null termination */
- if (p_line[p_end])
- p_len[p_end] = strlen(p_line[p_end]);
- else
- p_len[p_end] = 0;
}
-
+
hunk_done:
if (p_end >=0 && !repl_beginning)
- fatal2("no --- found in patch at line %ld\n", pch_hunk_beg());
+ fatal ("no --- found in patch at line %ld", pch_hunk_beg ());
if (repl_missing) {
-
+
/* reset state back to just after --- */
p_input_line = repl_patch_line;
+ context = repl_context;
for (p_end--; p_end > repl_beginning; p_end--)
free(p_line[p_end]);
- Fseek(pfp, repl_backtrack_position, 0);
-
+ Fseek (pfp, repl_backtrack_position, SEEK_SET);
+
/* redundant 'new' context lines were omitted - set */
/* up to fill them in from the old file context */
- if (!p_context && p_repl_lines == 1) {
- p_repl_lines = 0;
- p_max--;
- }
fillsrc = 1;
filldst = repl_beginning+1;
fillcnt = p_repl_lines;
p_end = p_max;
}
- else if (!p_context && fillcnt == 1) {
+ else if (!some_context && fillcnt == 1) {
/* the first hunk was a null hunk with no context */
/* and we were expecting one line -- fix it up. */
while (filldst < p_end) {
@@ -728,74 +821,86 @@ another_hunk()
p_ptrn_lines = 0;
}
- if (diff_type == CONTEXT_DIFF &&
- (fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) {
- if (verbose)
- say4("%s\n%s\n%s\n",
+ p_suffix_context = context;
+
+ if (difftype == CONTEXT_DIFF
+ && (fillcnt
+ || (p_first > 1
+ && p_prefix_context + p_suffix_context < ptrn_copiable))) {
+ if (verbosity == VERBOSE)
+ say ("%s\n%s\n%s\n",
"(Fascinating--this is really a new-style context diff but without",
"the telltale extra asterisks on the *** line that usually indicate",
"the new style...)");
- diff_type = NEW_CONTEXT_DIFF;
+ diff_type = difftype = NEW_CONTEXT_DIFF;
}
-
+
/* if there were omitted context lines, fill them in now */
if (fillcnt) {
p_bfake = filldst; /* remember where not to free() */
p_efake = filldst + fillcnt - 1;
while (fillcnt-- > 0) {
- while (fillsrc <= p_end && p_Char[fillsrc] != ' ')
+ while (fillsrc <= p_end && fillsrc != repl_beginning
+ && p_Char[fillsrc] != ' ')
fillsrc++;
- if (fillsrc > p_end)
- fatal2("replacement text or line numbers mangled in hunk at line %ld\n",
+ if (p_end < fillsrc || fillsrc == repl_beginning)
+ fatal ("replacement text or line numbers mangled in hunk at line %ld",
p_hunk_beg);
p_line[filldst] = p_line[fillsrc];
p_Char[filldst] = p_Char[fillsrc];
p_len[filldst] = p_len[fillsrc];
fillsrc++; filldst++;
}
- while (fillsrc <= p_end && fillsrc != repl_beginning &&
- p_Char[fillsrc] != ' ')
+ while (fillsrc <= p_end && fillsrc != repl_beginning)
+ {
+ if (p_Char[fillsrc] == ' ')
+ fatal ("replacement text or line numbers mangled in hunk at line %ld",
+ p_hunk_beg);
fillsrc++;
-#ifdef DEBUGGING
+ }
if (debug & 64)
printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n",
fillsrc,filldst,repl_beginning,p_end+1);
-#endif
assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
assert(filldst==p_end+1 || filldst==repl_beginning);
}
}
- else if (diff_type == UNI_DIFF) {
+ else if (difftype == UNI_DIFF) {
long line_beginning = ftell(pfp);
/* file pos of the current line */
- Reg4 LINENUM fillsrc; /* index of old lines */
- Reg5 LINENUM filldst; /* index of new lines */
- char ch;
-
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch || strnNE(buf, "@@ -", 4)) {
+ register LINENUM fillsrc; /* index of old lines */
+ register LINENUM filldst; /* index of new lines */
+ char ch = '\0';
+
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1
+ || chars_read <= 4
+ || strncmp (buf, "@@ -", 4) != 0) {
next_intuit_at(line_beginning,p_input_line);
- return FALSE;
+ return chars_read == (size_t) -1 ? -1 : 0;
}
s = buf+4;
if (!*s)
malformed ();
p_first = (LINENUM) atol(s);
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
if (*s == ',') {
p_ptrn_lines = (LINENUM) atol(++s);
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
} else
p_ptrn_lines = 1;
if (*s == ' ') s++;
if (*s != '+' || !*++s)
malformed ();
p_newfirst = (LINENUM) atol(s);
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
if (*s == ',') {
p_repl_lines = (LINENUM) atol(++s);
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
} else
p_repl_lines = 1;
if (*s == ' ') s++;
@@ -803,53 +908,56 @@ another_hunk()
malformed ();
if (!p_ptrn_lines)
p_first++; /* do append rather than insert */
+ if (!p_repl_lines)
+ p_newfirst++;
p_max = p_ptrn_lines + p_repl_lines + 1;
while (p_max >= hunkmax)
- grow_hunkmax();
+ if (! grow_hunkmax ())
+ return -1;
fillsrc = 1;
filldst = fillsrc + p_ptrn_lines;
p_end = filldst + p_repl_lines;
- Sprintf(buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1);
- p_line[0] = savestr(buf);
- if (out_of_mem) {
+ sprintf (buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1);
+ p_len[0] = strlen (buf);
+ if (! (p_line[0] = savestr (buf))) {
p_end = -1;
- return FALSE;
+ return -1;
}
p_Char[0] = '*';
- Sprintf(buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1);
- p_line[filldst] = savestr(buf);
- if (out_of_mem) {
+ sprintf (buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1);
+ p_len[filldst] = strlen (buf);
+ if (! (p_line[filldst] = savestr (buf))) {
p_end = 0;
- return FALSE;
+ return -1;
}
p_Char[filldst++] = '=';
- p_context = 100;
- context = 0;
+ p_prefix_context = -1;
p_hunk_beg = p_input_line + 1;
while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
- line_beginning = ftell(pfp);
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch) {
- if (p_max - filldst < 3)
- Strcpy(buf, " \n"); /* assume blank lines got chopped */
- else {
- fatal1("unexpected end of file in patch\n");
+ chars_read = get_line ();
+ if (!chars_read) {
+ if (p_max - filldst < 3) {
+ strcpy (buf, " \n"); /* assume blank lines got chopped */
+ chars_read = 2;
+ } else {
+ fatal ("unexpected end of file in patch");
}
}
- if (*buf == '\t' || *buf == '\n') {
+ if (chars_read == (size_t) -1)
+ s = 0;
+ else if (*buf == '\t' || *buf == '\n') {
ch = ' '; /* assume the space got eaten */
- s = savestr(buf);
+ s = savebuf (buf, chars_read);
}
else {
ch = *buf;
- s = savestr(buf+1);
+ s = savebuf (buf+1, --chars_read);
}
- if (out_of_mem) {
+ if (!s) {
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
- return FALSE;
+ return -1;
}
switch (ch) {
case '-':
@@ -858,9 +966,10 @@ another_hunk()
p_end = filldst-1;
malformed ();
}
+ chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
- p_len[fillsrc++] = strlen(s);
+ p_len[fillsrc++] = chars_read;
break;
case '=':
ch = ' ';
@@ -874,15 +983,16 @@ another_hunk()
malformed ();
}
context++;
+ chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
- p_len[fillsrc++] = strlen(s);
- s = savestr(s);
- if (out_of_mem) {
+ p_len[fillsrc++] = chars_read;
+ s = savebuf (s, chars_read);
+ if (!s) {
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
- return FALSE;
+ return -1;
}
/* FALL THROUGH */
case '+':
@@ -893,39 +1003,42 @@ another_hunk()
p_end = fillsrc-1;
malformed ();
}
+ chars_read -= filldst == p_end && incomplete_line ();
p_Char[filldst] = ch;
p_line[filldst] = s;
- p_len[filldst++] = strlen(s);
+ p_len[filldst++] = chars_read;
break;
default:
p_end = filldst;
malformed ();
}
- if (ch != ' ' && context > 0) {
- if (context < p_context)
- p_context = context;
- context = -1000;
+ if (ch != ' ') {
+ if (p_prefix_context == -1)
+ p_prefix_context = context;
+ context = 0;
}
}/* while */
+ p_suffix_context = context;
}
else { /* normal diff--fake it up */
char hunk_type;
- Reg3 int i;
+ register int i;
LINENUM min, max;
long line_beginning = ftell(pfp);
- p_context = 0;
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch || !isdigit(*buf)) {
+ p_prefix_context = p_suffix_context = 0;
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1 || !chars_read || !ISDIGIT (*buf)) {
next_intuit_at(line_beginning,p_input_line);
- return FALSE;
+ return chars_read == (size_t) -1 ? -1 : 0;
}
p_first = (LINENUM)atol(buf);
- for (s=buf; isdigit(*s); s++) ;
+ for (s = buf; ISDIGIT (*s); s++)
+ continue;
if (*s == ',') {
p_ptrn_lines = (LINENUM)atol(++s) - p_first + 1;
- while (isdigit(*s)) s++;
+ while (ISDIGIT (*s))
+ s++;
}
else
p_ptrn_lines = (*s != 'a');
@@ -933,7 +1046,8 @@ another_hunk()
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
min = (LINENUM)atol(++s);
- for (; isdigit(*s); s++) ;
+ while (ISDIGIT (*s))
+ s++;
if (*s == ',')
max = (LINENUM)atol(++s);
else
@@ -941,75 +1055,87 @@ another_hunk()
if (hunk_type == 'd')
min++;
p_end = p_ptrn_lines + 1 + max - min + 1;
- if (p_end > MAXHUNKSIZE)
- fatal4("hunk too large (%ld lines) at line %ld: %s",
- p_end, p_input_line, buf);
while (p_end >= hunkmax)
- grow_hunkmax();
+ if (! grow_hunkmax ())
+ {
+ p_end = -1;
+ return -1;
+ }
p_newfirst = min;
p_repl_lines = max - min + 1;
- Sprintf(buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1);
- p_line[0] = savestr(buf);
- if (out_of_mem) {
+ sprintf (buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1);
+ p_len[0] = strlen (buf);
+ if (! (p_line[0] = savestr (buf))) {
p_end = -1;
- return FALSE;
+ return -1;
}
p_Char[0] = '*';
for (i=1; i<=p_ptrn_lines; i++) {
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch)
- fatal2("unexpected end of file in patch at line %ld\n",
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1)
+ {
+ p_end = i - 1;
+ return -1;
+ }
+ if (!chars_read)
+ fatal ("unexpected end of file in patch at line %ld",
p_input_line);
- if (*buf != '<')
- fatal2("< expected at line %ld of patch\n", p_input_line);
- p_line[i] = savestr(buf+2);
- if (out_of_mem) {
+ if (buf[0] != '<' || (buf[1] != ' ' && buf[1] != '\t'))
+ fatal ("`<' expected at line %ld of patch", p_input_line);
+ chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ());
+ p_len[i] = chars_read;
+ if (! (p_line[i] = savebuf (buf + 2, chars_read))) {
p_end = i-1;
- return FALSE;
+ return -1;
}
- p_len[i] = strlen(p_line[i]);
p_Char[i] = '-';
}
if (hunk_type == 'c') {
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch)
- fatal2("unexpected end of file in patch at line %ld\n",
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1)
+ {
+ p_end = i - 1;
+ return -1;
+ }
+ if (! chars_read)
+ fatal ("unexpected end of file in patch at line %ld",
p_input_line);
if (*buf != '-')
- fatal2("--- expected at line %ld of patch\n", p_input_line);
+ fatal ("`---' expected at line %ld of patch", p_input_line);
}
- Sprintf(buf, "--- %ld,%ld\n", min, max);
- p_line[i] = savestr(buf);
- if (out_of_mem) {
+ sprintf (buf, "--- %ld,%ld\n", min, max);
+ p_len[i] = strlen (buf);
+ if (! (p_line[i] = savestr (buf))) {
p_end = i-1;
- return FALSE;
+ return -1;
}
p_Char[i] = '=';
for (i++; i<=p_end; i++) {
- ret = pgets(buf, sizeof buf, pfp);
- p_input_line++;
- if (ret == Nullch)
- fatal2("unexpected end of file in patch at line %ld\n",
+ chars_read = get_line ();
+ if (chars_read == (size_t) -1)
+ {
+ p_end = i - 1;
+ return -1;
+ }
+ if (!chars_read)
+ fatal ("unexpected end of file in patch at line %ld",
p_input_line);
- if (*buf != '>')
- fatal2("> expected at line %ld of patch\n", p_input_line);
- p_line[i] = savestr(buf+2);
- if (out_of_mem) {
+ if (buf[0] != '>' || (buf[1] != ' ' && buf[1] != '\t'))
+ fatal ("`>' expected at line %ld of patch", p_input_line);
+ chars_read -= 2 + (i == p_end && incomplete_line ());
+ p_len[i] = chars_read;
+ if (! (p_line[i] = savebuf (buf + 2, chars_read))) {
p_end = i-1;
- return FALSE;
+ return -1;
}
- p_len[i] = strlen(p_line[i]);
p_Char[i] = '+';
}
}
if (reverse) /* backwards patch? */
if (!pch_swap())
- say1("Not enough memory to swap next hunk!\n");
-#ifdef DEBUGGING
+ say ("Not enough memory to swap next hunk!\n");
if (debug & 2) {
- int i;
+ LINENUM i;
char special;
for (i=0; i <= p_end; i++) {
@@ -1017,40 +1143,114 @@ another_hunk()
special = '^';
else
special = ' ';
- fprintf(stderr, "%3d %c %c %s", i, p_Char[i], special, p_line[i]);
- Fflush(stderr);
+ fprintf (stderr, "%3ld %c %c ", i, p_Char[i], special);
+ pch_write_line (i, stderr);
+ fflush (stderr);
}
}
-#endif
if (p_end+1 < hunkmax) /* paranoia reigns supreme... */
p_Char[p_end+1] = '^'; /* add a stopper for apply_hunk */
- return TRUE;
+ return 1;
+}
+
+static size_t
+get_line ()
+{
+ return pget_line (p_indent);
}
-/* Input a line from the patch file, worrying about indentation. */
+/* Input a line from the patch file, worrying about indentation.
+ Strip up to INDENT characters' worth of leading indentation.
+ Ignore any partial lines at end of input, but warn about them.
+ Succeed if a line was read; it is terminated by "\n\0" for convenience.
+ Return the number of characters read, including '\n' but not '\0'.
+ Return -1 if we ran out of memory. */
-char *
-pgets(bf,sz,fp)
-char *bf;
-int sz;
-FILE *fp;
+static size_t
+pget_line (indent)
+ int indent;
{
- char *ret = fgets(bf, sz, fp);
- Reg1 char *s;
- Reg2 int indent = 0;
+ register FILE *fp = pfp;
+ register int c;
+ register int i = 0;
+ register char *b;
+ register size_t s;
+
+ for (;;)
+ {
+ c = getc (fp);
+ if (c == EOF)
+ {
+ if (ferror (fp))
+ read_fatal ();
+ return 0;
+ }
+ if (indent <= i)
+ break;
+ if (c == ' ' || c == 'X')
+ i++;
+ else if (c == '\t')
+ i = (i + 8) & ~7;
+ else
+ break;
+ }
- if (p_indent && ret != Nullch) {
- for (s=buf;
- indent < p_indent && (*s == ' ' || *s == '\t' || *s == 'X'); s++) {
- if (*s == '\t')
- indent += 8 - (indent % 7);
- else
- indent++;
+ i = 0;
+ b = buf;
+ s = bufsize;
+
+ for (;;)
+ {
+ if (i == s - 1)
+ {
+ s *= 2;
+ b = realloc (b, s);
+ if (!b)
+ {
+ if (!using_plan_a)
+ memory_fatal ();
+ return (size_t) -1;
+ }
+ buf = b;
+ bufsize = s;
}
- if (buf != s)
- Strcpy(buf, s);
+ b[i++] = c;
+ if (c == '\n')
+ break;
+ c = getc (fp);
+ if (c == EOF)
+ {
+ if (ferror (fp))
+ read_fatal ();
+ say ("patch unexpectedly ends in middle of line\n");
+ return 0;
+ }
+ }
+
+ b[i] = '\0';
+ p_input_line++;
+ return i;
+}
+
+static bool
+incomplete_line ()
+{
+ register FILE *fp = pfp;
+ register int c;
+ register long line_beginning = ftell (fp);
+
+ if (getc (fp) == '\\')
+ {
+ while ((c = getc (fp)) != '\n' && c != EOF)
+ continue;
+ return TRUE;
+ }
+ else
+ {
+ /* We don't trust ungetc. */
+ Fseek (pfp, line_beginning, SEEK_SET);
+ return FALSE;
}
- return ret;
}
/* Reverse the old and new portions of the current hunk. */
@@ -1059,37 +1259,35 @@ bool
pch_swap()
{
char **tp_line; /* the text of the hunk */
- short *tp_len; /* length of each line */
+ size_t *tp_len; /* length of each line */
char *tp_char; /* +, -, and ! */
- Reg1 LINENUM i;
- Reg2 LINENUM n;
+ register LINENUM i;
+ register LINENUM n;
bool blankline = FALSE;
- Reg3 char *s;
+ register char *s;
i = p_first;
p_first = p_newfirst;
p_newfirst = i;
-
+
/* make a scratch copy */
tp_line = p_line;
tp_len = p_len;
tp_char = p_Char;
- p_line = Null(char**); /* force set_hunkmax to allocate again */
- p_len = Null(short*);
- p_Char = Nullch;
+ p_line = 0; /* force set_hunkmax to allocate again */
+ p_len = 0;
+ p_Char = 0;
set_hunkmax();
- if (p_line == Null(char**) || p_len == Null(short*) || p_Char == Nullch) {
-#ifndef lint
- if (p_line == Null(char**))
- free((char*)p_line);
+ if (!p_line || !p_len || !p_Char) {
+ if (p_line)
+ free (p_line);
p_line = tp_line;
- if (p_len == Null(short*))
- free((char*)p_len);
+ if (p_len)
+ free (p_len);
p_len = tp_len;
-#endif
- if (p_Char == Nullch)
- free((char*)p_Char);
+ if (p_Char)
+ free (p_Char);
p_Char = tp_char;
return FALSE; /* not enough memory to swap hunk! */
}
@@ -1147,14 +1345,12 @@ pch_swap()
i = p_ptrn_lines;
p_ptrn_lines = p_repl_lines;
p_repl_lines = i;
-#ifndef lint
- if (tp_line == Null(char**))
- free((char*)tp_line);
- if (tp_len == Null(short*))
- free((char*)tp_len);
-#endif
- if (tp_char == Nullch)
- free((char*)tp_char);
+ if (tp_line)
+ free (tp_line);
+ if (tp_len)
+ free (tp_len);
+ if (tp_char)
+ free (tp_char);
return TRUE;
}
@@ -1201,14 +1397,22 @@ pch_end()
/* Return the number of context lines before the first changed line. */
LINENUM
-pch_context()
+pch_prefix_context ()
{
- return p_context;
+ return p_prefix_context;
+}
+
+/* Return the number of context lines after the last changed line. */
+
+LINENUM
+pch_suffix_context ()
+{
+ return p_suffix_context;
}
/* Return the length of a particular patch line. */
-short
+size_t
pch_line_len(line)
LINENUM line;
{
@@ -1233,6 +1437,19 @@ LINENUM line;
return p_line[line];
}
+/* Output a patch line. */
+
+bool
+pch_write_line (line, file)
+ LINENUM line;
+ FILE *file;
+{
+ bool after_newline = p_line[line][p_len[line] - 1] == '\n';
+ if (! fwrite (p_line[line], sizeof (*p_line[line]), p_len[line], file))
+ write_fatal ();
+ return after_newline;
+}
+
/* Return where in the patch file this hunk began, for error messages. */
LINENUM
@@ -1244,41 +1461,46 @@ pch_hunk_beg()
/* Apply an ed script by feeding ed itself. */
void
-do_ed_script()
+do_ed_script (ofp)
+ FILE *ofp;
{
- Reg1 char *t;
- Reg2 long beginning_of_this_line;
- Reg3 bool this_line_is_command = FALSE;
- Reg4 FILE *pipefp;
+ static char const ed_program[] = ED_PROGRAM;
+
+ register char *t;
+ register long beginning_of_this_line;
+ register bool this_line_is_command = FALSE;
+ register FILE *pipefp = 0;
+ register size_t chars_read;
if (!skip_rest_of_patch) {
- Unlink(TMPOUTNAME);
- copy_file(filearg[0], TMPOUTNAME);
- if (verbose)
- Sprintf(buf, "/bin/ed %s", TMPOUTNAME);
- else
- Sprintf(buf, "/bin/ed - %s", TMPOUTNAME);
+ copy_file (inname, TMPOUTNAME);
+ sprintf (buf, "%s %s%s", ed_program, verbosity == VERBOSE ? "" : "- ",
+ TMPOUTNAME);
pipefp = popen(buf, "w");
+ if (!pipefp)
+ pfatal (buf);
}
for (;;) {
beginning_of_this_line = ftell(pfp);
- if (pgets(buf, sizeof buf, pfp) == Nullch) {
+ chars_read = get_line ();
+ if (! chars_read) {
next_intuit_at(beginning_of_this_line,p_input_line);
break;
}
- p_input_line++;
- for (t=buf; isdigit(*t) || *t == ','; t++) ;
- this_line_is_command = (isdigit(*buf) &&
- (*t == 'd' || *t == 'c' || *t == 'a') );
+ for (t = buf; ISDIGIT (*t) || *t == ','; t++)
+ continue;
+ this_line_is_command = (ISDIGIT (*buf) &&
+ (*t == 'd' || *t == 'c' || *t == 'a' || *t == 'i' || *t == 's') );
if (this_line_is_command) {
- if (!skip_rest_of_patch)
- fputs(buf, pipefp);
- if (*t != 'd') {
- while (pgets(buf, sizeof buf, pfp) != Nullch) {
- p_input_line++;
- if (!skip_rest_of_patch)
- fputs(buf, pipefp);
- if (strEQ(buf, ".\n"))
+ if (pipefp)
+ if (! fwrite (buf, sizeof *buf, chars_read, pipefp))
+ write_fatal ();
+ if (*t != 'd' && *t != 's') {
+ while ((chars_read = get_line ()) != 0) {
+ if (pipefp)
+ if (! fwrite (buf, sizeof *buf, chars_read, pipefp))
+ write_fatal ();
+ if (chars_read == 2 && strEQ (buf, ".\n"))
break;
}
}
@@ -1288,18 +1510,24 @@ do_ed_script()
break;
}
}
- if (skip_rest_of_patch)
- return;
- fprintf(pipefp, "w\n");
- fprintf(pipefp, "q\n");
- Fflush(pipefp);
- Pclose(pipefp);
- ignore_signals();
- if (move_file(TMPOUTNAME, outname) < 0) {
- toutkeep = TRUE;
- chmod(TMPOUTNAME, filemode);
- }
- else
- chmod(outname, filemode);
- set_signals(1);
+ if (!pipefp)
+ return;
+ if (fwrite ("w\nq\n", sizeof (char), (size_t) 4, pipefp) == 0
+ || fflush (pipefp) != 0)
+ write_fatal ();
+ if (pclose (pipefp) != 0)
+ fatal ("%s FAILED", ed_program);
+
+ if (ofp)
+ {
+ FILE *ifp = fopen (TMPOUTNAME, "r");
+ int c;
+ if (!ifp)
+ pfatal (TMPOUTNAME);
+ while ((c = getc (ifp)) != EOF)
+ if (putc (c, ofp) == EOF)
+ write_fatal ();
+ if (ferror (ifp) || fclose (ifp) != 0)
+ read_fatal ();
+ }
}
diff --git a/pch.h b/pch.h
index 97a5b28..d2c645b 100644
--- a/pch.h
+++ b/pch.h
@@ -1,36 +1,23 @@
-/* $Header: pch.h,v 2.0.1.1 87/01/30 22:47:16 lwall Exp $
- *
- * $Log: pch.h,v $
- * Revision 2.0.1.1 87/01/30 22:47:16 lwall
- * Added do_ed_script().
- *
- * Revision 2.0 86/09/17 15:39:57 lwall
- * Baseline for netwide release.
- *
- */
+/* reading patches */
-EXT FILE *pfp INIT(Nullfp); /* patch file pointer */
+/* $Id: pch.h,v 1.5 1997/04/07 01:07:00 eggert Exp $ */
-void re_patch();
-void open_patch_file();
-void set_hunkmax();
-void grow_hunkmax();
-bool there_is_another_patch();
-int intuit_diff_type();
-void next_intuit_at();
-void skip_to();
-bool another_hunk();
-bool pch_swap();
-char *pfetch();
-short pch_line_len();
-LINENUM pch_first();
-LINENUM pch_ptrn_lines();
-LINENUM pch_newfirst();
-LINENUM pch_repl_lines();
-LINENUM pch_end();
-LINENUM pch_context();
-LINENUM pch_hunk_beg();
-char pch_char();
-char *pfetch();
-char *pgets();
-void do_ed_script();
+LINENUM pch_end PARAMS ((void));
+LINENUM pch_first PARAMS ((void));
+LINENUM pch_hunk_beg PARAMS ((void));
+LINENUM pch_newfirst PARAMS ((void));
+LINENUM pch_prefix_context PARAMS ((void));
+LINENUM pch_ptrn_lines PARAMS ((void));
+LINENUM pch_repl_lines PARAMS ((void));
+LINENUM pch_suffix_context PARAMS ((void));
+bool pch_swap PARAMS ((void));
+bool pch_write_line PARAMS ((LINENUM, FILE *));
+bool there_is_another_patch PARAMS ((void));
+char *pfetch PARAMS ((LINENUM));
+char pch_char PARAMS ((LINENUM));
+int another_hunk PARAMS ((enum diff));
+size_t pch_line_len PARAMS ((LINENUM));
+void do_ed_script PARAMS ((FILE *));
+void open_patch_file PARAMS ((char const *));
+void re_patch PARAMS ((void));
+void set_hunkmax PARAMS ((void));
diff --git a/util.c b/util.c
index ecb85ff..fb8183c 100644
--- a/util.c
+++ b/util.c
@@ -1,296 +1,477 @@
-#include "EXTERN.h"
-#include "common.h"
-#include "INTERN.h"
-#include "util.h"
-#include "backupfile.h"
-
-void my_exit();
-
-#ifndef HAVE_STRERROR
-static char *
-private_strerror (errnum)
- int errnum;
-{
- extern char *sys_errlist[];
- extern int sys_nerr;
+/* utility functions for `patch' */
+
+/* $Id: util.c,v 1.9 1997/04/14 05:32:30 eggert Exp $ */
+
+/*
+Copyright 1986 Larry Wall
+Copyright 1992, 1993, 1997 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.
+If not, write to the Free Software Foundation,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#define XTERN extern
+#include <common.h>
+#include <backupfile.h>
+#include <version.h>
+#undef XTERN
+#define XTERN
+#include <util.h>
+
+#include <signal.h>
+#if !defined SIGCHLD && defined SIGCLD
+#define SIGCHLD SIGCLD
+#endif
- if (errnum > 0 && errnum <= sys_nerr)
- return sys_errlist[errnum];
- return "Unknown system error";
-}
-#define strerror private_strerror
-#endif /* !HAVE_STRERROR */
+#ifdef __STDC__
+# include <stdarg.h>
+# define vararg_start va_start
+#else
+# define vararg_start(ap,p) va_start (ap)
+# if HAVE_VARARGS_H
+# include <varargs.h>
+# else
+ typedef char *va_list;
+# define va_dcl int va_alist;
+# define va_start(ap) ((ap) = (va_list) &va_alist)
+# define va_arg(ap, t) (((t *) ((ap) += sizeof (t))) [-1])
+# define va_end(ap)
+# endif
+#endif
/* Rename a file, copying it if necessary. */
-int
-move_file(from,to)
-char *from, *to;
+void
+move_file (from, to, backup)
+ char const *from, *to;
+ int backup;
{
- char bakname[512];
- Reg1 char *s;
- Reg2 int i;
- Reg3 int fromfd;
-
- /* to stdout? */
-
- if (strEQ(to, "-")) {
-#ifdef DEBUGGING
- if (debug & 4)
- say2("Moving %s to stdout.\n", from);
-#endif
- fromfd = open(from, 0);
- if (fromfd < 0)
- pfatal2("internal error, can't reopen %s", from);
- while ((i=read(fromfd, buf, sizeof buf)) > 0)
- if (write(1, buf, i) != 1)
- pfatal1("write failed");
- Close(fromfd);
- return 0;
- }
-
- if (origprae) {
- Strcpy(bakname, origprae);
- Strcat(bakname, to);
- } else {
-#ifndef NODIR
- char *backupname = find_backup_file_name(to);
- if (backupname == (char *) 0)
- fatal1("out of memory\n");
- Strcpy(bakname, backupname);
- free(backupname);
-#else /* NODIR */
- Strcpy(bakname, to);
- Strcat(bakname, simple_backup_suffix);
-#endif /* NODIR */
- }
-
- if (stat(to, &filestat) == 0) { /* output file exists */
- dev_t to_device = filestat.st_dev;
- ino_t to_inode = filestat.st_ino;
- char *simplename = bakname;
-
- for (s=bakname; *s; s++) {
- if (*s == '/')
- simplename = s+1;
+ register char *s;
+ register char *bakname;
+ struct stat tost, bakst;
+
+ if (backup && stat (to, &tost) == 0)
+ {
+ char *simplename;
+
+ if (origprae || origbase)
+ {
+ char const *p = origprae ? origprae : "";
+ char const *b = origbase ? origbase : "";
+ char const *o = base_name (to);
+ size_t plen = strlen (p);
+ size_t tlen = o - to;
+ size_t blen = strlen (b);
+ size_t osize = strlen (o) + 1;
+ bakname = xmalloc (plen + tlen + blen + osize);
+ memcpy (bakname, p, plen);
+ memcpy (bakname + plen, to, tlen);
+ memcpy (bakname + plen + tlen, b, blen);
+ memcpy (bakname + plen + tlen + blen, o, osize);
}
- /* Find a backup name that is not the same file.
- Change the first lowercase char into uppercase;
- if that isn't sufficient, chop off the first char and try again. */
- while (stat(bakname, &filestat) == 0 &&
- to_device == filestat.st_dev && to_inode == filestat.st_ino) {
- /* Skip initial non-lowercase chars. */
- for (s=simplename; *s && !islower(*s); s++) ;
- if (*s)
- *s = toupper(*s);
- else
- Strcpy(simplename, simplename+1);
+ else
+ {
+ bakname = find_backup_file_name (to);
+ if (!bakname)
+ memory_fatal ();
}
- while (unlink(bakname) >= 0) ; /* while() is for benefit of Eunice */
-#ifdef DEBUGGING
- if (debug & 4)
- say3("Moving %s to %s.\n", to, bakname);
-#endif
- if (rename(to, bakname) < 0) {
- say4("Can't backup %s, output is in %s: %s\n", to, from,
- strerror(errno));
- return -1;
+
+ simplename = base_name (bakname);
+ /* Find a backup name that is not the same file.
+ Change the first lowercase char into uppercase;
+ if that doesn't suffice, chop off the first char and try again. */
+ while (stat (bakname, &bakst) == 0
+ && tost.st_dev == bakst.st_dev
+ && tost.st_ino == bakst.st_ino)
+ {
+ /* Skip initial non-lowercase chars. */
+ for (s=simplename; *s && !ISLOWER ((unsigned char) *s); s++)
+ continue;
+ if (*s)
+ *s = toupper ((unsigned char) *s);
+ else
+ remove_prefix (simplename, 1);
}
- while (unlink(to) >= 0) ;
+ if (debug & 4)
+ say ("Moving %s to %s.\n", to, bakname);
+ if (rename (to, bakname) != 0)
+ pfatal ("Can't rename `%s' to `%s'", to, bakname);
+ free (bakname);
}
-#ifdef DEBUGGING
- if (debug & 4)
- say3("Moving %s to %s.\n", from, to);
-#endif
- if (rename(from, to) < 0) { /* different file system? */
- Reg4 int tofd;
-
- tofd = creat(to, 0666);
- if (tofd < 0) {
- say4("Can't create %s, output is in %s: %s\n",
- to, from, strerror(errno));
- return -1;
+
+ if (debug & 4)
+ say ("Moving %s to %s.\n", from, to);
+
+ if (rename (from, to) != 0)
+ {
+#ifdef EXDEV
+ if (errno == EXDEV)
+ {
+ if (! backup && unlink (to) != 0
+ && errno != ENOENT && errno != ENOTDIR)
+ pfatal ("Can't remove `%s'", to);
+ copy_file (from, to);
+ if (unlink (from) != 0)
+ pfatal ("Can't remove `%s'", from);
+ return;
}
- fromfd = open(from, 0);
- if (fromfd < 0)
- pfatal2("internal error, can't reopen %s", from);
- while ((i=read(fromfd, buf, sizeof buf)) > 0)
- if (write(tofd, buf, i) != i)
- pfatal1("write failed");
- Close(fromfd);
- Close(tofd);
+#endif
+ pfatal ("Can't rename `%s' to `%s'", from, to);
}
- Unlink(from);
- return 0;
}
/* Copy a file. */
void
copy_file(from,to)
-char *from, *to;
+ char const *from;
+ char const *to;
{
- Reg3 int tofd;
- Reg2 int fromfd;
- Reg1 int i;
-
- tofd = creat(to, 0666);
- if (tofd < 0)
- pfatal2("can't create %s", to);
- fromfd = open(from, 0);
- if (fromfd < 0)
- pfatal2("internal error, can't reopen %s", from);
- while ((i=read(fromfd, buf, sizeof buf)) > 0)
- if (write(tofd, buf, i) != i)
- pfatal2("write to %s failed", to);
- Close(fromfd);
- Close(tofd);
+ int tofd;
+ int fromfd = open (from, O_RDONLY);
+ long i;
+
+ if (fromfd < 0)
+ pfatal ("can't reopen %s", from);
+ tofd = creat (to, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+ if (tofd < 0)
+ pfatal ("can't create %s", to);
+ while ((i = read (fromfd, buf, bufsize)) > 0)
+ if (write (tofd, buf, (size_t) i) != i)
+ write_fatal ();
+ if (i < 0 || close (fromfd) != 0)
+ read_fatal ();
+ if (close (tofd) != 0)
+ write_fatal ();
}
/* Allocate a unique area for a string. */
char *
-savestr(s)
-Reg1 char *s;
+savebuf (s, size)
+ register char const *s;
+ register size_t size;
{
- Reg3 char *rv;
- Reg2 char *t;
-
- if (!s)
- s = "Oops";
- t = s;
- while (*t++);
- rv = malloc((MEM) (t - s));
- if (rv == Nullch) {
- if (using_plan_a)
- out_of_mem = TRUE;
- else
- fatal1("out of memory\n");
- }
- else {
- t = rv;
- while (*t++ = *s++);
+ register char *rv;
+
+ assert (s && size);
+ rv = malloc (size);
+
+ if (! rv)
+ {
+ if (! using_plan_a)
+ memory_fatal ();
}
- return rv;
+ else
+ memcpy (rv, s, size);
+
+ return rv;
}
-#if defined(lint) && defined(CANVARARG)
+char *
+savestr(s)
+ char const *s;
+{
+ return savebuf (s, strlen (s) + 1);
+}
-/*VARARGS ARGSUSED*/
-say(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-fatal(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-pfatal(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-ask(pat) char *pat; { ; }
+void
+remove_prefix (p, prefixlen)
+ char *p;
+ size_t prefixlen;
+{
+ char const *s = p + prefixlen;
+ while ((*p++ = *s++))
+ continue;
+}
+#if !HAVE_VPRINTF
+#define vfprintf my_vfprintf
+static int vfprintf PARAMS ((FILE *, char const *, va_list));
+static int
+vfprintf (stream, format, args)
+ FILE *stream;
+ char const *format;
+ va_list args;
+{
+#if !HAVE_DOPRNT && HAVE__DOPRINTF
+# define _doprnt _doprintf
+#endif
+#if HAVE_DOPRNT || HAVE__DOPRINTF
+ _doprnt (format, args, stream);
+ return ferror (stream) ? -1 : 0;
#else
+ int *a = (int *) args;
+ return fprintf (stream, format,
+ a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
+#endif
+}
+#endif /* !HAVE_VPRINTF */
+
+/* Terminal output, pun intended. */
-/* Vanilla terminal output (buffered). */
+#ifdef __STDC__
+void
+fatal (char const *format, ...)
+#else
+/*VARARGS1*/ void
+fatal (format, va_alist)
+ char const *format;
+ va_dcl
+#endif
+{
+ va_list args;
+ fprintf (stderr, "%s: **** ", program_name);
+ vararg_start (args, format);
+ vfprintf (stderr, format, args);
+ va_end (args);
+ putc ('\n', stderr);
+ fflush (stderr);
+ fatal_exit (0);
+}
void
-say(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
+memory_fatal ()
{
- fprintf(stderr, pat, arg1, arg2, arg3);
- Fflush(stderr);
+ fatal ("out of memory");
}
-/* Terminal output, pun intended. */
+void
+read_fatal ()
+{
+ pfatal ("read error");
+}
-void /* very void */
-fatal(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
+void
+write_fatal ()
{
- fprintf(stderr, "patch: **** ");
- fprintf(stderr, pat, arg1, arg2, arg3);
- my_exit(1);
+ pfatal ("write error");
}
/* Say something from patch, something from the system, then silence . . . */
-void /* very void */
-pfatal(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
+#ifdef __STDC__
+void
+pfatal (char const *format, ...)
+#else
+/*VARARGS1*/ void
+pfatal (format, va_alist)
+ char const *format;
+ va_dcl
+#endif
{
- int errnum = errno;
+ int errnum = errno;
+ va_list args;
+ fprintf (stderr, "%s: **** ", program_name);
+ vararg_start (args, format);
+ vfprintf (stderr, format, args);
+ va_end (args);
+ fflush (stderr);
+ errno = errnum;
+ perror (" ");
+ fflush (stderr);
+ fatal_exit (0);
+}
+
+/* Tell the user something. */
- fprintf(stderr, "patch: **** ");
- fprintf(stderr, pat, arg1, arg2, arg3);
- fprintf(stderr, ": %s\n", strerror(errnum));
- my_exit(1);
+#ifdef __STDC__
+void
+say (char const *format, ...)
+#else
+/*VARARGS1*/ void
+say (format, va_alist)
+ char const *format;
+ va_dcl
+#endif
+{
+ va_list args;
+ vararg_start (args, format);
+ vfprintf (stdout, format, args);
+ va_end (args);
+ fflush (stdout);
}
/* Get a response from the user, somehow or other. */
+#ifdef __STDC__
void
-ask(pat,arg1,arg2,arg3)
-char *pat;
-long arg1,arg2,arg3;
+ask (char const *format, ...)
+#else
+/*VARARGS1*/ void
+ask (format, va_alist)
+ char const *format;
+ va_dcl
+#endif
{
- int ttyfd;
- int r;
- bool tty2 = isatty(2);
-
- Sprintf(buf, pat, arg1, arg2, arg3);
- Fflush(stderr);
- write(2, buf, strlen(buf));
- if (tty2) { /* might be redirected to a file */
- r = read(2, buf, sizeof buf);
- }
- else if (isatty(1)) { /* this may be new file output */
- Fflush(stdout);
- write(1, buf, strlen(buf));
- r = read(1, buf, sizeof buf);
- }
- else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
- /* might be deleted or unwriteable */
- write(ttyfd, buf, strlen(buf));
- r = read(ttyfd, buf, sizeof buf);
- Close(ttyfd);
+ static int ttyfd = -2;
+ int r;
+ va_list args;
+
+ vararg_start (args, format);
+ vfprintf (stdout, format, args);
+ va_end (args);
+ fflush (stdout);
+
+ if (ttyfd == -2)
+ {
+ ttyfd = open ("/dev/tty", O_RDONLY);
+ if (ttyfd < 0)
+ {
+ close (ttyfd);
+ for (ttyfd = STDERR_FILENO; 0 <= ttyfd; ttyfd--)
+ if (isatty (ttyfd))
+ break;
+ }
}
- else if (isatty(0)) { /* this is probably patch input */
- Fflush(stdin);
- write(0, buf, strlen(buf));
- r = read(0, buf, sizeof buf);
+
+ if (ttyfd < 0)
+ {
+ /* No terminal at all -- default it. */
+ buf[0] = '\n';
+ r = 1;
}
- else { /* no terminal at all--default it */
- buf[0] = '\n';
- r = 1;
+ else
+ {
+ r = read (ttyfd, buf, bufsize - 1);
+ if (r == 0)
+ printf ("EOF\n");
+ else if (r < 0)
+ {
+ close (ttyfd);
+ ttyfd = -1;
+ r = 0;
+ }
}
- if (r <= 0)
- buf[0] = 0;
- else
- buf[r] = '\0';
- if (!tty2)
- say1(buf);
+
+ buf[r] = '\0';
}
-#endif /* lint */
/* How to handle certain events when not in a critical region. */
+#define NUM_SIGS (sizeof (sigs) / sizeof (*sigs))
+static int const sigs[] = {
+#ifdef SIGHUP
+ SIGHUP,
+#endif
+#ifdef SIGTERM
+ SIGTERM,
+#endif
+#ifdef SIGXCPU
+ SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+ SIGXFSZ,
+#endif
+ SIGINT,
+ SIGPIPE
+};
+
+#if !HAVE_SIGPROCMASK
+#define sigset_t int
+#define sigemptyset(s) (*(s) = 0)
+#ifndef sigmask
+#define sigmask(sig) (1 << ((sig) - 1))
+#endif
+#define sigaddset(s, sig) (*(s) |= sigmask (sig))
+#define sigismember(s, sig) ((*(s) & sigmask (sig)) != 0)
+#ifndef SIG_BLOCK
+#define SIG_BLOCK 0
+#endif
+#ifndef SIG_UNBLOCK
+#define SIG_UNBLOCK (SIG_BLOCK + 1)
+#endif
+#ifndef SIG_SETMASK
+#define SIG_SETMASK (SIG_BLOCK + 2)
+#endif
+#define sigprocmask(how, n, o) \
+ ((how) == SIG_BLOCK \
+ ? ((o) ? *(o) = sigblock (*(n)) : sigblock (*(n))) \
+ : (how) == SIG_UNBLOCK \
+ ? sigsetmask (((o) ? *(o) = sigblock (0) : sigblock (0)) & ~*(n)) \
+ : (o ? *(o) = sigsetmask (*(n)) : sigsetmask (*(n))))
+#if !HAVE_SIGSETMASK
+#define sigblock(mask) 0
+#define sigsetmask(mask) 0
+#endif
+#endif
+
+static sigset_t initial_signal_mask;
+static sigset_t signals_to_block;
+
+#if ! HAVE_SIGACTION
+static RETSIGTYPE fatal_exit_handler PARAMS ((int)) __attribute__ ((noreturn));
+static RETSIGTYPE
+fatal_exit_handler (sig)
+ int sig;
+{
+ signal (sig, SIG_IGN);
+ fatal_exit (sig);
+}
+#endif
+
void
set_signals(reset)
int reset;
{
-#ifndef lint
- static RETSIGTYPE (*hupval)(),(*intval)();
-
- if (!reset) {
- hupval = signal(SIGHUP, SIG_IGN);
- if (hupval != SIG_IGN)
- hupval = (RETSIGTYPE(*)())my_exit;
- intval = signal(SIGINT, SIG_IGN);
- if (intval != SIG_IGN)
- intval = (RETSIGTYPE(*)())my_exit;
+ int i;
+#if HAVE_SIGACTION
+ struct sigaction initial_act, fatal_act;
+ fatal_act.sa_handler = fatal_exit;
+ sigemptyset (&fatal_act.sa_mask);
+ fatal_act.sa_flags = 0;
+#define setup_handler(sig) sigaction (sig, &fatal_act, (struct sigaction *) 0)
+#else
+#define setup_handler(sig) signal (sig, fatal_exit_handler)
+#endif
+
+ if (!reset)
+ {
+#ifdef SIGCHLD
+ /* System V fork+wait does not work if SIGCHLD is ignored. */
+ signal (SIGCHLD, SIG_DFL);
+#endif
+ sigemptyset (&signals_to_block);
+ for (i = 0; i < NUM_SIGS; i++)
+ {
+ int ignoring_signal;
+#if HAVE_SIGACTION
+ if (sigaction (sigs[i], (struct sigaction *) 0, &initial_act) != 0)
+ continue;
+ ignoring_signal = initial_act.sa_handler == SIG_IGN;
+#else
+ ignoring_signal = signal (sigs[i], SIG_IGN) == SIG_IGN;
+#endif
+ if (! ignoring_signal)
+ {
+ sigaddset (&signals_to_block, sigs[i]);
+ setup_handler (sigs[i]);
+ }
+ }
}
- Signal(SIGHUP, hupval);
- Signal(SIGINT, intval);
+ else
+ {
+ /* Undo the effect of ignore_signals. */
+#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
+ sigprocmask (SIG_SETMASK, &initial_signal_mask, (sigset_t *) 0);
+#else
+ for (i = 0; i < NUM_SIGS; i++)
+ if (sigismember (&signals_to_block, sigs[i]))
+ setup_handler (sigs[i]);
#endif
+ }
}
/* How to handle certain events when in a critical region. */
@@ -298,136 +479,203 @@ int reset;
void
ignore_signals()
{
-#ifndef lint
- Signal(SIGHUP, SIG_IGN);
- Signal(SIGINT, SIG_IGN);
+#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
+ sigprocmask (SIG_BLOCK, &signals_to_block, &initial_signal_mask);
+#else
+ int i;
+ for (i = 0; i < NUM_SIGS; i++)
+ if (sigismember (&signals_to_block, sigs[i]))
+ signal (sigs[i], SIG_IGN);
#endif
}
+void
+exit_with_signal (sig)
+ int sig;
+{
+ sigset_t s;
+ signal (sig, SIG_DFL);
+ sigemptyset (&s);
+ sigaddset (&s, sig);
+ sigprocmask (SIG_UNBLOCK, &s, (sigset_t *) 0);
+ kill (getpid (), sig);
+ exit (2);
+}
+
+#if !HAVE_MKDIR
+/* This is good enough for `patch'; it's not a general emulator. */
+static int mkdir PARAMS ((char const *, int));
+static int
+mkdir (path, mode)
+ char const *path;
+ int mode; /* ignored */
+{
+ char *cmd = xmalloc (strlen (path) + 9);
+ int r;
+ sprintf (cmd, "mkdir '%s'", path);
+ r = system (cmd);
+ free (cmd);
+ return r;
+}
+#endif
+
+/* Replace '/' with '\0' in FILENAME if it marks a place that
+ needs testing for the existence of directory. Return the address
+ of the last location replaced, or FILENAME if none were replaced. */
+static char *replace_slashes PARAMS ((char *));
+static char *
+replace_slashes (filename)
+ char *filename;
+{
+ char *f;
+ for (f = filename; *f == '/'; f++)
+ continue;
+ for (; *f; f++)
+ if (*f == '/')
+ {
+ *f = '\0';
+ while (f[1] == '/')
+ f++;
+ }
+ while (filename != f && *--f)
+ continue;
+ return f;
+}
+
+/* Count the number of path name components in the existing leading prefix
+ of `filename'. Do not count the last element, or the root dir. */
+int
+countdirs (filename)
+ char *filename;
+{
+ int count = 0;
+
+ if (*filename)
+ {
+ register char *f;
+ register char *flim = replace_slashes (filename);
+
+ /* Now turn the '\0's back to '/'s, calling stat as we go. */
+ for (f = filename; f <= flim; f++)
+ if (!*f)
+ {
+ struct stat sbuf;
+ if (stat (filename, &sbuf) != 0)
+ break;
+ count++;
+ *f = '/';
+ }
+
+ for (; f <= flim; f++)
+ if (!*f)
+ *f = '/';
+ }
+
+ return count;
+}
+
/* Make sure we'll have the directories to create a file.
- If `striplast' is TRUE, ignore the last element of `filename'. */
+ Ignore the last element of `filename'. */
void
-makedirs(filename,striplast)
-Reg1 char *filename;
-bool striplast;
+makedirs (filename)
+ register char *filename;
{
- char tmpbuf[256];
- Reg2 char *s = tmpbuf;
- char *dirv[20]; /* Point to the NULs between elements. */
- Reg3 int i;
- Reg4 int dirvp = 0; /* Number of finished entries in dirv. */
-
- /* Copy `filename' into `tmpbuf' with a NUL instead of a slash
- between the directories. */
- while (*filename) {
- if (*filename == '/') {
- filename++;
- dirv[dirvp++] = s;
- *s++ = '\0';
- }
- else {
- *s++ = *filename++;
- }
- }
- *s = '\0';
- dirv[dirvp] = s;
- if (striplast)
- dirvp--;
- if (dirvp < 0)
- return;
-
- strcpy(buf, "mkdir");
- s = buf;
- for (i=0; i<=dirvp; i++) {
- struct stat sbuf;
-
- if (stat(tmpbuf, &sbuf) && errno == ENOENT) {
- while (*s) s++;
- *s++ = ' ';
- strcpy(s, tmpbuf);
- }
- *dirv[i] = '/';
+ if (*filename)
+ {
+ register char *f;
+ register char *flim = replace_slashes (filename);
+
+ /* Now turn the NULs back to '/'s; stop when the path doesn't exist. */
+ errno = 0;
+ for (f = filename; f <= flim; f++)
+ if (!*f)
+ {
+ struct stat sbuf;
+ if (stat (filename, &sbuf) != 0)
+ break;
+ *f = '/';
+ }
+
+ /* Create the missing directories, replacing NULs by '/'s. */
+ if (errno == ENOENT)
+ for (; f <= flim; f++)
+ if (!*f)
+ {
+ if (mkdir (filename,
+ S_IRUSR|S_IWUSR|S_IXUSR
+ |S_IRGRP|S_IWGRP|S_IXGRP
+ |S_IROTH|S_IWOTH|S_IXOTH) != 0)
+ break;
+ *f = '/';
+ }
+
+ for (; f <= flim; f++)
+ if (!*f)
+ *f = '/';
}
- if (s != buf)
- system(buf);
}
/* Make filenames more reasonable. */
char *
-fetchname(at,strip_leading,assume_exists)
+fetchname (at, strip_leading)
char *at;
int strip_leading;
-int assume_exists;
{
- char *fullname;
char *name;
- Reg1 char *t;
- char tmpbuf[200];
+ register char *t;
int sleading = strip_leading;
if (!at)
- return Nullch;
- while (isspace(*at))
+ return 0;
+ while (ISSPACE (*at))
at++;
-#ifdef DEBUGGING
if (debug & 128)
- say4("fetchname %s %d %d\n",at,strip_leading,assume_exists);
-#endif
- if (strnEQ(at, "/dev/null", 9)) /* so files can be created by diffing */
- return Nullch; /* against /dev/null. */
- name = fullname = t = savestr(at);
+ say ("fetchname %s %d\n", at, strip_leading);
+ name = at;
/* Strip off up to `sleading' leading slashes and null terminate. */
- for (; *t && !isspace(*t); t++)
+ for (t = at; *t; t++)
if (*t == '/')
+ {
+ while (t[1] == '/')
+ t++;
if (--sleading >= 0)
name = t+1;
- *t = '\0';
-
- /* If no -p option was given (957 is the default value!),
- we were given a relative pathname,
- and the leading directories that we just stripped off all exist,
- put them back on. */
- if (strip_leading == 957 && name != fullname && *fullname != '/') {
- name[-1] = '\0';
- if (stat(fullname, &filestat) == 0 && S_ISDIR (filestat.st_mode)) {
- name[-1] = '/';
- name=fullname;
- }
- }
+ }
+ else if (ISSPACE (*t))
+ {
+ *t = '\0';
+ break;
+ }
- name = savestr(name);
- free(fullname);
-
- if (stat(name, &filestat) && !assume_exists) {
- char *filebase = basename(name);
- int pathlen = filebase - name;
-
- /* Put any leading path into `tmpbuf'. */
- strncpy(tmpbuf, name, pathlen);
-
-#define try(f, a1, a2) (Sprintf(tmpbuf + pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0)
- if ( try("RCS/%s%s", filebase, RCSSUFFIX)
- || try("RCS/%s" , filebase, 0)
- || try( "%s%s", filebase, RCSSUFFIX)
- || try("SCCS/%s%s", SCCSPREFIX, filebase)
- || try( "%s%s", SCCSPREFIX, filebase))
- return name;
- free(name);
- name = Nullch;
- }
+ if (!*name)
+ return 0;
+
+ /* Allow files to be created by diffing against /dev/null. */
+ if (strcmp (at, "/dev/null") == 0)
+ return 0;
- return name;
+ return savestr (name);
}
-char *
+VOID *
xmalloc (size)
- unsigned size;
+ size_t size;
{
- register char *p = (char *) malloc (size);
+ register VOID *p = malloc (size);
if (!p)
- fatal("out of memory");
+ memory_fatal ();
return p;
}
+
+void
+Fseek (stream, offset, ptrname)
+ FILE *stream;
+ long offset;
+ int ptrname;
+{
+ if (fseek (stream, offset, ptrname) != 0)
+ pfatal ("fseek");
+}
diff --git a/util.h b/util.h
index d8e46bb..0bc44ad 100644
--- a/util.h
+++ b/util.h
@@ -1,88 +1,27 @@
-/* $Header: util.h,v 2.0 86/09/17 15:40:06 lwall Exp $
- *
- * $Log: util.h,v $
- * Revision 2.0 86/09/17 15:40:06 lwall
- * Baseline for netwide release.
- *
- */
-
-/* and for those machine that can't handle a variable argument list */
-
-#ifdef CANVARARG
-
-#define say1 say
-#define say2 say
-#define say3 say
-#define say4 say
-#define ask1 ask
-#define ask2 ask
-#define ask3 ask
-#define ask4 ask
-#define fatal1 fatal
-#define fatal2 fatal
-#define fatal3 fatal
-#define fatal4 fatal
-#define pfatal1 pfatal
-#define pfatal2 pfatal
-#define pfatal3 pfatal
-#define pfatal4 pfatal
-
-#else /* hope they allow multi-line macro actual arguments */
-
-#ifdef lint
-
-#define say1(a) say(a, 0, 0, 0)
-#define say2(a,b) say(a, (b)==(b), 0, 0)
-#define say3(a,b,c) say(a, (b)==(b), (c)==(c), 0)
-#define say4(a,b,c,d) say(a, (b)==(b), (c)==(c), (d)==(d))
-#define ask1(a) ask(a, 0, 0, 0)
-#define ask2(a,b) ask(a, (b)==(b), 0, 0)
-#define ask3(a,b,c) ask(a, (b)==(b), (c)==(c), 0)
-#define ask4(a,b,c,d) ask(a, (b)==(b), (c)==(c), (d)==(d))
-#define fatal1(a) fatal(a, 0, 0, 0)
-#define fatal2(a,b) fatal(a, (b)==(b), 0, 0)
-#define fatal3(a,b,c) fatal(a, (b)==(b), (c)==(c), 0)
-#define fatal4(a,b,c,d) fatal(a, (b)==(b), (c)==(c), (d)==(d))
-#define pfatal1(a) pfatal(a, 0, 0, 0)
-#define pfatal2(a,b) pfatal(a, (b)==(b), 0, 0)
-#define pfatal3(a,b,c) pfatal(a, (b)==(b), (c)==(c), 0)
-#define pfatal4(a,b,c,d) pfatal(a, (b)==(b), (c)==(c), (d)==(d))
-
-#else /* lint */
- /* if this doesn't work, try defining CANVARARG above */
-#define say1(a) say(a, Nullch, Nullch, Nullch)
-#define say2(a,b) say(a, b, Nullch, Nullch)
-#define say3(a,b,c) say(a, b, c, Nullch)
-#define say4 say
-#define ask1(a) ask(a, Nullch, Nullch, Nullch)
-#define ask2(a,b) ask(a, b, Nullch, Nullch)
-#define ask3(a,b,c) ask(a, b, c, Nullch)
-#define ask4 ask
-#define fatal1(a) fatal(a, Nullch, Nullch, Nullch)
-#define fatal2(a,b) fatal(a, b, Nullch, Nullch)
-#define fatal3(a,b,c) fatal(a, b, c, Nullch)
-#define fatal4 fatal
-#define pfatal1(a) pfatal(a, Nullch, Nullch, Nullch)
-#define pfatal2(a,b) pfatal(a, b, Nullch, Nullch)
-#define pfatal3(a,b,c) pfatal(a, b, c, Nullch)
-#define pfatal4 pfatal
-
-#endif /* lint */
-
-/* if neither of the above work, join all multi-line macro calls. */
-#endif
-
-EXT char serrbuf[BUFSIZ]; /* buffer for stderr */
-
-char *fetchname();
-int move_file();
-void copy_file();
-void say();
-void fatal();
-void pfatal();
-void ask();
-char *savestr();
-void set_signals();
-void ignore_signals();
-void makedirs();
-char *basename();
+/* utility functions for `patch' */
+
+/* $Id: util.h,v 1.7 1997/04/14 05:32:30 eggert Exp $ */
+
+void ask PARAMS ((char const *, ...)) __attribute__ ((format (printf, 1, 2)));
+void say PARAMS ((char const *, ...)) __attribute__ ((format (printf, 1, 2)));
+
+void fatal PARAMS ((char const *, ...))
+ __attribute__ ((noreturn, format (printf, 1, 2)));
+void pfatal PARAMS ((char const *, ...))
+ __attribute__ ((noreturn, format (printf, 1, 2)));
+
+char *fetchname PARAMS ((char *, int));
+char *savebuf PARAMS ((char const *, size_t));
+char *savestr PARAMS ((char const *));
+int countdirs PARAMS ((char *));
+void Fseek PARAMS ((FILE *, long, int));
+void copy_file PARAMS ((char const *, char const *));
+void exit_with_signal PARAMS ((int)) __attribute__ ((noreturn));
+void ignore_signals PARAMS ((void));
+void makedirs PARAMS ((char *));
+void memory_fatal PARAMS ((void));
+void move_file PARAMS ((char const *, char const *, int));
+void read_fatal PARAMS ((void));
+void remove_prefix PARAMS ((char *, size_t));
+void set_signals PARAMS ((int));
+void write_fatal PARAMS ((void));
diff --git a/version.c b/version.c
index f0b5223..5e52939 100644
--- a/version.c
+++ b/version.c
@@ -1,25 +1,30 @@
-/* $Header: version.c,v 2.0 86/09/17 15:40:11 lwall Exp $
- *
- * $Log: version.c,v $
- * Revision 2.0 86/09/17 15:40:11 lwall
- * Baseline for netwide release.
- *
- */
+/* Print the version number. */
-#include "EXTERN.h"
-#include "common.h"
-#include "util.h"
-#include "INTERN.h"
-#include "patchlevel.h"
-#include "version.h"
+/* $Id: version.c,v 1.4 1997/04/07 01:07:00 eggert Exp $ */
-void my_exit();
+#define XTERN extern
+#include <common.h>
+#undef XTERN
+#define XTERN
+#include <patchlevel.h>
+#include <version.h>
-/* Print out the version number and die. */
+static char const copyright_string[] = "\
+Copyright 1984, 1985, 1986, 1987, 1988 Larry Wall\n\
+Copyright 1989, 1990, 1991, 1992, 1993, 1997 Free Software Foundation, Inc.";
+
+static char const free_software_msgid[] = "\
+This program comes with NO WARRANTY, to the extent permitted by law.\n\
+You may redistribute copies of this program\n\
+under the terms of the GNU General Public License.\n\
+For more information about these matters, see the file named COPYING.";
+
+static char const authorship_msgid[] = "\
+written by Larry Wall with lots o' patches by Paul Eggert";
void
version()
{
- fprintf(stderr, "Patch version %s\n", PATCH_VERSION);
- my_exit(0);
+ printf ("%s %s\n%s\n\n%s\n\n%s\n", program_name, PATCH_VERSION,
+ copyright_string, free_software_msgid, authorship_msgid);
}
diff --git a/version.h b/version.h
index 08fe68d..b061c94 100644
--- a/version.h
+++ b/version.h
@@ -1,9 +1,5 @@
-/* $Header: version.h,v 2.0 86/09/17 15:40:14 lwall Exp $
- *
- * $Log: version.h,v $
- * Revision 2.0 86/09/17 15:40:14 lwall
- * Baseline for netwide release.
- *
- */
+/* Print the version number. */
-void version();
+/* $Id: version.h,v 1.3 1997/04/07 01:07:00 eggert Exp $ */
+
+void version PARAMS ((void));