diff options
-rw-r--r-- | AUTHORS | 151 | ||||
-rw-r--r-- | ChangeLog | 136 | ||||
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | NEWS | 13 | ||||
-rw-r--r-- | THANKS | 23 | ||||
-rwxr-xr-x | bootstrap | 150 | ||||
-rw-r--r-- | configure.ac | 55 | ||||
-rw-r--r-- | doc/diff.texi | 23 | ||||
-rw-r--r-- | lib/Makefile.am | 9 | ||||
-rw-r--r-- | lib/cmpbuf.c | 8 | ||||
-rw-r--r-- | lib/posix/regex.h | 566 | ||||
-rw-r--r-- | lib/setmode.c | 53 | ||||
-rw-r--r-- | lib/setmode.h | 29 | ||||
-rw-r--r-- | m4/Makefile.am.in | 12 | ||||
-rw-r--r-- | m4/gnu-source.m4 | 12 | ||||
-rw-r--r-- | m4/jm-glibc-io.m4 | 14 | ||||
-rw-r--r-- | m4/setmode.m4 | 39 | ||||
-rw-r--r-- | src/cmp.c | 24 | ||||
-rw-r--r-- | src/context.c | 207 | ||||
-rw-r--r-- | src/diff.c | 516 | ||||
-rw-r--r-- | src/diff3.c | 16 | ||||
-rw-r--r-- | src/dir.c | 4 | ||||
-rw-r--r-- | src/io.c | 34 | ||||
-rw-r--r-- | src/sdiff.c | 14 | ||||
-rw-r--r-- | src/system.h | 47 | ||||
-rw-r--r-- | src/util.c | 8 |
26 files changed, 741 insertions, 1426 deletions
@@ -1,112 +1,53 @@ -Authors of GNU diffutils. +GNU diff was written by Paul Eggert, Mike Haertel, David Hayes, +Richard Stallman, and Len Tower. - Copyright 2001 Free Software Foundation, Inc. +GNU diff3 was written by Randy Smith. - This file is part of GNU diffutils. +GNU sdiff was written by Thomas Lord. - GNU diffutils 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. +GNU cmp was written by Torbjorn Granlund and David MacKenzie. - GNU diffutils 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. +The diffutils manual was written by David MacKenzie, Paul Eggert, and +Richard Stallman. Parts are adapted by from a manual page written by +Larry Wall, with his permission. - You should have received a copy of the GNU General Public License - along with GNU diffutils; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. +Many other people have contributed to GNU diffutils, including Wayne +Davison, Patrick D'Cruze, F. Thomas May, Greg McGary, Chip Rosenthal, +and Eli Zaretskii. The following contributions warranted legal paper exchanges with the -Free Software Foundation. Also see files ChangeLog and THANKS. - -DIFFUTILS Leonard H. Tower Jr. US 1949 1987-03-09 -Assigns diff (diff.c, initial version). - -DIFFUTILS Torbjorn Granlund Sweden 1961 1988-01-11 -Assigns cmp. -tege@matematik.su.se - -DIFFUTILS Mike Haertel US 1967 1988-09-16 -Assigns changes to diff. - -DIFFUTILS David S. Hayes US ? 1988-01-12 -Assigns changes to diff. - -DIFFUTILS Randall Smith US 1964 1988-09-21 -Assigns diff3. - -DIFFUTILS Richard Stallman US 1953 1988-01-15 -Assigns changes to GNU Diff. - -DIFFUTILS F. Thomas May US 1965 1989-08-22 -Assigns changes to diff (for -D). - -DIFFUTILS Optimal Solutions, Inc. 1989-08-14 -Disclaims changes by Thomas May to diff. - -DIFFUTILS Wayne Davison 1990-09-10 -Disclaims changes to diff. - -DIFFUTILS Digital Research Inc. 1990-09-13 -Disclaims changes by Wayne Davison to diff. - -DIFFUTILS Paul Eggert 1990-03-16 -Disclaims changes to diff. -eggert@twinsun.com - -DIFFUTILS Paul Eggert 1990-08-14 -Disclaims changes to GNU Diff. -eggert@twinsun.com - -DIFFUTILS Twin Sun Inc. 1990-03-16 -Disclaims changes to GNU Diff by Paul Eggert. - -DIFFUTILS Twin Sun Inc. 1990-08-14 -Disclaims changes to GNU Diff by Paul Eggert. - -DIFFUTILS Chip Rosenthal US 1959 1990-03-06 -Assigns changes to diff. -chip@chinacat.Unicom.COM - -DIFFUTILS Unicom Systems Development 1990-03-06 -Disclaims changes by Chip Rosenthal to diff. - -GCC DIFFUTILS Paul Eggert and Twin Sun Inc. 1992-03-11 -Disclaims changes by Paul Eggert to gcc and diff. -eggert@twinsun.com - -DIFF Wayne Davison 1993-06-20 -Disclaims diffcvt.c. - -DIFFUTILS Francois Pinard Canada 1949 1993-01-15 -Assigns wdiff and future changes submitted to the FSF. -pinard@iro.umontreal.ca - -DIFFUTILS Patrick D'Cruze Australia 1971 1994-11-10 -Assigns changes (makefile.in, analyze.c, cmp.c, error.c, diff.c, -diff3.c, getopt.c, getopt1.c, regex.c, sdiff.c, util.c, xmalloc.c; -new file: language.++) - -DIFFUTILS Paul R. Eggert US 1954 1997-04-07 -Assigns past and future changes. -eggert@twinsun.com - -DIFFUTILS Paul R. Eggert US 1954 1997-04-07 -Assigns past and future changes to manual. -eggert@twinsun.com - -ANY DIFFUTILS GNATS Cyclic Software 1997-11-11 -Assigns past and future works (work for hire by Tim Pierce (diffutils) and -Abe Feldman (GNATS)). -kingdon@cyclic.com - -WEBPAGES Gregory B. Harvey Canada 1976 1998-02-14 -Assigns web pages describing GNU Diffutils and future changes. - -DIFFUTILS Olga Nikulin Russia 1965 2001-01-11 -Assigns changes to diff. (diffutils-2.7.2/analyze.c, context.c, diff.[ch], -ed.c, ifdef.c, io.c, normal.c, side.c, util.c) -onikulin@yahoo.com +Free Software Foundation. Also see the files ChangeLog and THANKS. + +Leonard H. Tower Jr. +Torbjorn Granlund +Mike Haertel +David S. Hayes +Randall Smith +Richard Stallman +F. Thomas May +Wayne Davison +Paul R. Eggert +Chip Rosenthal +Wayne Davison +Patrick D'Cruze +Eli Zaretskii + + +Copyright (C) 2001, 2006 Free Software Foundation, Inc. + +This file is part of GNU diffutils. + +GNU diffutils 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. + +GNU diffutils 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 GNU diffutils; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. @@ -1,8 +1,118 @@ +2006-01-04 Paul Eggert <eggert@cs.ucla.edu> + + * AUTHORS: Simplify list by removing legalisms. + * THANKS: Add Larry Wall, who contributed to manual. Update email + addresses. + * Makefile.am (SUBDIRS): Remove m4. Put lib first, then other + source files, so documentation can rely on programs being built. + * bootstrap: Import changes from Bison bootstrap. Add gettext, + gettime, sh-quote, stat-time, verify, version-etc-fsf modules. + Remove posixver module. Retrieve doc/fdl.texi from gnulib. + * configure.ac (AC_PREREQ): Bump to 2.59. + (AC_INIT): Bump version to 2.8.7-cvs. + (AC_CONFIG_AUX_DIR): Change from config to build-aux. + Prefer AC_CHECK_HEADERS_ONCE to AC_CHECK_HEADERS + and AC_CHECK_FUNCS_ONCE to AC_CHECK_FUNCS. + Remove jm_AC_TYPE_INTMAX_T, jm_AC_TYPE_UINTMAX_T, + AC_STRUCT_ST_MTIM_NSEC. + (DIFFUTILS_PREREQUISITES): New macro. Call it. + (REGEX_MALLOC): Remove; no longer needed. + (AM_GNU_GETTEXT_VERSION): Now 0.14.15. + (AM_GNU_GETTEXT): Call. + (LIB_CLOCK_GETTIME): Remove; bootstrap now does that. + (AC_FUNC_SETMODE_DOS): Remove. + (AC_CONFIG_FILES): Remove m4/Makefile. + * doc/diff.texi: Use @- at end of lines that should end in white space, + so that Emacs doesn't remove the white space. + (diff Options): "diff -NUM" is a pure extension to POSIX, so support + it unconditionally. + * lib/Makefile.am (noinst_HEADERS): Remove quotesys.h. + (lib_SOURCES): Remove quotesys.c. + (DISTCLEANFILES): Remove. + (EXTRA_DIST): Remove setmode.h, waitpid.c. + * lib/cmpbuf.c (block_read): Reword to avoid gcc -W warning. + * lib/setmode.c, lib/setmode.h: Remove. + * m4/setmode.m4, m4/gnu-source.m4, m4/Makefile.am.in: Remove. + * m4/jm-glibc-io.m4: Remove. + * src/cmp.c: Don't include <setmode.h>. + (specify_ignore_initial): Reword to avoid gcc -W warnings. + (main): Use freopen instead of setmode, since freopen is in POSIX. + * src/context.c: Revert most 2004-09-01 changes. Then: + (TIMESPEC_NS): Remove. All uses replaced by + get_stat_mtime_ns. + Include stat-time.h, strftime.h. + (nstrtime): Remove decl. + * src/diff.c: Revert most 2004-09-01 changes. Then: + Don't include <posixver.h>, <quotesys.h>, <setmode.h>. + Include <sh-quote.h>, <stat-time.h>, <timespec.h>. + All uses of quotesys replaced by sh-quote. + (main, compare_files): + Use freopen instead of setmode, since freopen is in POSIX. + (main): Don't complain about "diff -NUM'. + (main, set_mtime_to_now): + Adjust to stat-time.h macros when accessing nanoseconds. + * src/diff3.c: Include sh-quote.h rather than quotesys. All uses + changed. + * src/dir.c (dir_read): excluded_filename renamed to + excluded_file_name. + * src/io.c: Don't include <setmode.h>. + (sip, read_files): Remove binary file stuff, leaving a FIXME behind. + A DOS expert needs to look at this. + * src/diff.c: Include sh-quote.h rather than quotesys.h. + All uses changed. + * src/system.h: Include verify.h. + (verify): Remove. All uses changed to verify.h version. + Include <intprops.h>. + (TYPE_SIGNED, TYPE_MINIMUM, TYPE_MAXIMUM): Remove. Now uses + intprops.h versions. + (O_BINARY): New defns, taken from coreutils. + * src/util.c: Include sh-quote.h rather than quotesys.h. + All uses changed. + +2004-09-01 Paul Eggert <eggert@cs.ucla.edu> + + * src/diff.c (recursive, new_file, unidirectional_new_file): + (report_identical_files): + Move into struct diffopt. All uses changed. + (exclude_options, compare_files, specify_style, check_stdout): + New arg OPT. All uses changed. + (GDIFF_MAIN): Remove. All uses removed. + (function_regexp_list, ignore_regexp_list): No longer static; now + locals in 'main'. + (main): Set opt.function_regexp, opt.ignore_regexp if using regexps; + all other code now tests these pointers rather than inspecting fastmap + internals. + New local OPT to hold former statics; initialize it. + (init_regexp_list): New function, used by main. + (summarize_regexp_list): Now returns struct re_pattern_buffer *, and + assumes reglist->regexps is not NULL. All uses changed. + + * src/context.c (find_function_last_search): Move into struct diffopt. + All uses changed. + (pr_context_label, pr_context_header, + print_context_script, find_function, find_hunk, mark_ignorable, + pr_context_hunk, pr_unidiff_hunk): New arg OPT. All uses changed. + (print_context_number_range, + print_unidiff_number_range): New arg OUT. All uses changed. + 2004-07-19 Stepan Kasal <kasal@ucw.cz> * src/ed.c (print_ed_hunk): Optimize the case where an insert's last line is a single-dot line. +2004-06-30 Paul Eggert <eggert@cs.ucla.edu> + + * lib/setmode.c: + Don't include <stdbool.h>, since setmode.h now does this. + Include setmode.h first, to catch interface errors. + Assume HAVE_SETMODE_DOS is defined. + + * lib/setmode.h: Include stdbool.h. + +2004-04-26 Paul Eggert <eggert@cs.ucla.edu> + + * bootstrap: Don't remove po/en.po. + 2004-04-13 Paul Eggert <eggert@twinsun.com> * NEWS, configure.ac (AC_INIT): Version 2.8.7. @@ -48,7 +158,7 @@ the above. (AC_CONFIG_FILES): Remove lib/posix/Makefile. (AC_CONFIG_COMMANDS): Remove. - + * doc/diff.texi (dircategory): Change to "Text creation and manipulation" from "GNU packages". (Translations): New node. @@ -3862,22 +3972,12 @@ Thu Nov 3 16:30:24 1988 Randall Smith (randy at gluteus.ai.mit.edu) the sake of System V (too simple not to do). -Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1997, 1998, 1999, -2000, 2001, 2002 Free Software Foundation, Inc. - -This file is part of GNU Diffutils. - -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 they 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. + Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1997, + 1998, 1999, 2000, 2001, 2002, 2004, 2006 Free Software Foundation, + Inc. -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, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. + Copying and distribution of this file, with or without + modification, are permitted provided the copyright notice and this + notice are preserved. diff --git a/Makefile.am b/Makefile.am index 87f7c3d..a0cda37 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ # Main Automakefile for GNU diffutils. -# Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2004, 2006 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 @@ -18,6 +18,6 @@ ## 02111-1307, USA. EXTRA_DIST = bootstrap exgettext -SUBDIRS = doc lib m4 ms src man po +SUBDIRS = lib ms src doc man po ACLOCAL_AMFLAGS = -I m4 @@ -1,3 +1,16 @@ +User-visible changes since 2.8.7 (in "version" 2.8.7-cvs): + +* Bring back support for `diff -NUM', where NUM is a number, + even when conforming to POSIX 1003.1-2001. This change reverts to + the behavior of GNU diff 2.7 and earlier. This is a change only + when conforming to POSIX 1003.1-2001; there is no effect when + conforming to older POSIX versions. + + This change is in response to decisions taken in the January 2005 + Austin Group standardization meeting. For more details, please see + "Utility Syntax Guidelines" in the Minutes of the January 2005 + Meeting <http://www.opengroup.org/austin/docs/austin_239.html>. + Version 2.8.7 contains no user-visible changes. User-visible changes in version 2.8.6: @@ -1,22 +1,23 @@ Thanks to all the following for their contributions to GNU diffutils: -Thomas Bushnell <tb@becket.net> -Wayne Davison <wayned@users.sourceforge.net> +Thomas Bushnell, BSG <tb@becket.net> +Wayne Davison <wayne@opencoder.net> Ulrich Drepper <drepper@redhat.com> -Paul Eggert <eggert@twinsun.com> -Jay Fenlason <hack@gnu.org> -John Gilmore <gnu@cygnus.com> +Paul Eggert <eggert@cs.ucla.edu> +Jay Fenlason <fenlason@redhat.com> +John Gilmore <gnu@toad.com> Torbjorn Granlund <tege@swox.com> Mike Haertel <mike@ichips.intel.com> -Bruno Haible <haible@ilog.fr> +Bruno Haible <haible@clisp.org> Chris Hanson <cph@gnu.org> Jim Kingdon <kingdon@panix.com> Tom Lord <lord@gnu.org> David J. MacKenzie <djm@gnu.org> -Roland McGrath <roland@gnu.org> -Jim Meyering <meyering@lucent.com> -Eugene W. Myers <gene@cs.arizona.edu> +Roland McGrath <roland@redhat.com> +Jim Meyering <jim@meyering.net> +Gene Myers <gene@eecs.berkeley.edu> Randy Smith <randy@gnu.org> Richard Stallman <rms@gnu.org> -Leonard H. Tower Jr. <tower@ai.mit.edu> -Eli Zaretskii <eliz@is.elta.co.il> +Leonard H. Tower Jr. <tower@art.net> +Larry Wall <larry@wall.org> +Eli Zaretskii <eliz@gnu.org> @@ -2,7 +2,7 @@ # Bootstrap this package from CVS. -# Copyright (C) 2003, 2004 Free Software Foundation, Inc. +# Copyright (C) 2003, 2004, 2005, 2006 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 @@ -16,27 +16,31 @@ # 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. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. # Written by Paul Eggert. package=diffutils +# Ensure file names are sorted consistently across platforms; +# e.g., m4/ulonglong_gl.m4 should follow m4/ulonglong.m4. +# Also, ensure diagnostics are in English, e.g., "wget --help" below. +LC_ALL=C +export LC_ALL + # Parse options. for option do case $option in --help) - echo "$0: usage: $0 [--gnulib-srcdir=DIR] [--cvs-auth=AUTH-METHOD] [--cvs-user=USERNAME] [--skip-po]" + echo "$0: usage: $0 [--gnulib-srcdir=DIR] [--cvs-user=USERNAME] [--skip-po]" exit;; --gnulib-srcdir=*) - GNULIB_SRCDIR=`expr "$1" : '--gnulib-srcdir=\(.*\)'`;; - --cvs-auth=*) - CVS_AUTH=`expr "$1" : '--cvs-auth=\(.*\)'`;; + GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;; --cvs-user=*) - CVS_USER=`expr "$1" : '--cvs-user=\(.*\)'`;; + CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;; --skip-po) SKIP_PO=t;; *) @@ -47,11 +51,10 @@ done echo "$0: Bootstrapping CVS $package..." -build_cvs_prefix() { - CVS_PREFIX=:${1}: - if [ "${2}" != - ]; then - CVS_PREFIX=${CVS_PREFIX}${2}@ - fi +cleanup_gnulib() { + status=$? + rm -fr gnulib + exit $status } # Get gnulib files. @@ -61,26 +64,26 @@ case ${GNULIB_SRCDIR--} in if [ ! -d gnulib ]; then echo "$0: getting gnulib files..." - trap exit 1 2 13 15 - trap 'rm -fr gnulib; exit 1' 0 - - case "${CVS_AUTH--}" in - -) : ${CVS_RSH:?} - CVS_PREFIX="";; - pserver) build_cvs_prefix $CVS_AUTH ${CVS_USER:-anoncvs};; - gserver|server) - build_cvs_prefix $CVS_AUTH ${CVS_USER--};; - ext) : ${CVS_RSH:?} - build_cvs_prefix $CVS_AUTH ${CVS_USER--};; - *) echo "$0: Unknown CVS access method" >&2 - exit 1;; + case ${CVS_AUTH-pserver} in + pserver) + CVS_PREFIX=':pserver:anonymous@';; + ssh) + CVS_PREFIX="$CVS_USER${CVS_USER+@}";; + *) + echo "$0: $CVS_AUTH: Unknown CVS access method" >&2 + exit 1;; + esac + + case $CVS_RSH in + '') export CVS_RSH=ssh;; esac - if [ "${CVS_AUTH--}" = "pserver" ]; then - cvs -d ${CVS_PREFIX}subversions.gnu.org:/cvsroot/gnulib login || exit - fi - cvs -q -d ${CVS_PREFIX}subversions.gnu.org:/cvsroot/gnulib co gnulib || exit - trap 0 + trap cleanup_gnulib 1 2 13 15 + + cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/gnulib co gnulib || + cleanup_gnulib + + trap - 1 2 13 15 fi GNULIB_SRCDIR=gnulib esac @@ -97,16 +100,21 @@ exitfail file-type fnmatch-gnu getopt +gettext +gettime hard-locale inttostr mkstemp -posixver regex +sh-quote +stat-time strcase strftime strtoumax unlocked-io +verify version-etc +version-etc-fsf xalloc xstrtoumax ' @@ -126,7 +134,9 @@ gnulib_files=` (for gnulib_module in $gnulib_modules; do $GNULIB_SRCDIR/gnulib-tool --extract-filelist $gnulib_module done) | sort -u -` +`' + doc/fdl.texi +' gnulib_dirs=`echo "$gnulib_files" | sed 's,/[^/]*$,,' | sort -u` mkdir -p $gnulib_dirs || exit @@ -136,6 +146,14 @@ for gnulib_file in $gnulib_files; do case $gnulib_file in m4/onceonly_2_57.m4) dest=m4/onceonly.m4;; + # These will be overwritten by autopoint, which still uses + # old jm_.* macro names, so we have to keep both copies. + # m4/gettext.m4 isn't mentioned here, since it's patched below. + m4/glibc21.m4 | m4/inttypes_h.m4 | m4/lib-ld.m4 | \ + m4/lib-prefix.m4 | m4/longlong.m4 | \ + m4/po.m4 | m4/stdint_h.m4 | m4/uintmax_t.m4 | \ + m4/ulonglong.m4) + dest=`expr $gnulib_file : '\(.*\).m4'`_gl.m4;; esac rm -f $dest && @@ -148,22 +166,25 @@ done case $SKIP_PO in '') - echo "$0: getting translations into po..." + case `wget --help` in + *'--no-cache'*) + no_cache='--no-cache';; + *'--cache=on/off'*) + no_cache='--cache=off';; + *) + no_cache='';; + esac + + echo "$0: getting translations into po (please ignore the robots.txt ERROR 404)..." (cd po && - rm -f dummy `ls | sed -n '/\.gmo$/p; /^en\.po$d/; /\.po/p'` && - wget -nv -nd -r -l 1 -A .po -C off \ - http://www2.iro.umontreal.ca/~gnutra/po/maint/$package/ && + rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'` && + wget -nv -nd -r -l 1 -A .po $no_cache \ + http://www.iro.umontreal.ca/translation/maint/$package/ && ls *.po | sed 's/\.po$//' >LINGUAS ) || exit;; esac -# Reconfigure, getting other files. - -echo "$0: autoreconf --verbose --install --force ..." -autoreconf --verbose --install --force || exit - - # Generate autoconf and automake snippets. (echo '# This file is generated automatically by "bootstrap".' && @@ -177,4 +198,47 @@ autoreconf --verbose --install --force || exit ) >lib/gnulib.mk || exit +# Reconfigure, getting other files. + +echo "$0: autoreconf --verbose --install --force ..." +autoreconf --verbose --install --force || exit + + +# We don't need intl, so remove it. +# Remove aclocal.m4 too, so that it gets rebuilt. +intl_files_to_remove=' + aclocal.m4 + intl + m4/gettext.m4 + m4/glibc2.m4 + m4/glibc21.m4 + m4/intdiv0.m4 + m4/intmax.m4 + m4/inttypes_h.m4 + m4/inttypes.m4 + m4/inttypes-pri.m4 + m4/isc-posix.m4 + m4/lcmessage.m4 + m4/lib-ld.m4 + m4/lib-prefix.m4 + m4/longdouble.m4 + m4/longlong.m4 + m4/po.m4 + m4/printf-posix.m4 + m4/signed.m4 + m4/size_max.m4 + m4/stdint_h.m4 + m4/uintmax_t.m4 + m4/ulonglong.m4 + m4/wchar_t.m4 + m4/wint_t.m4 + m4/xsize.m4 +' +echo $0: rm -fr $intl_files_to_remove ... +rm -fr $intl_files_to_remove || exit + +# Put bug-reporting address into po/Makevars. +echo "$0: sed '/^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-bison@gnu.org/' po/Makevars.template >po/Makevars ..." +sed '/^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-bison@gnu.org/' po/Makevars.template >po/Makevars + echo "$0: done. Now you can run './configure'." diff --git a/configure.ac b/configure.ac index a85a2c9..8f44313 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Configure template for GNU Diffutils. -# Copyright (C) 1994, 1995, 1998, 2001, 2002, 2004 Free Software +# Copyright (C) 1994, 1995, 1998, 2001, 2002, 2004, 2006 Free Software # Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -18,11 +18,11 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. -AC_PREREQ(2.53) +AC_PREREQ(2.59) -AC_INIT([GNU diffutils], [2.8.7], [bug-gnu-utils@gnu.org]) +AC_INIT([GNU diffutils], [2.8.7-cvs], [bug-gnu-utils@gnu.org]) AC_CONFIG_SRCDIR([src/diff.c]) -AC_CONFIG_AUX_DIR([config]) +AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([gnits]) @@ -32,7 +32,7 @@ gl_USE_SYSTEM_EXTENSIONS AC_PROG_AWK AC_PROG_CC AM_PROG_CC_STDC -AM_MISSING_PROG(HELP2MAN, help2man) +AM_MISSING_PROG([HELP2MAN], [help2man]) AC_PROG_RANLIB AC_SYS_LARGEFILE @@ -40,52 +40,35 @@ AC_SYS_LARGEFILE AC_C_INLINE AC_C_VARARRAYS -AC_DEFINE(DEFAULT_EDITOR_PROGRAM, "ed", +AC_DEFINE([DEFAULT_EDITOR_PROGRAM], ["ed"], [Name of editor program, unless overridden.]) -AC_PATH_PROG(PR_PROGRAM, pr, "") -AC_DEFINE_UNQUOTED(PR_PROGRAM, "$PR_PROGRAM", [Name of "pr" program.]) +AC_PATH_PROG([PR_PROGRAM], [pr], [""]) +AC_DEFINE_UNQUOTED([PR_PROGRAM], ["$PR_PROGRAM"], [Name of "pr" program.]) -AC_CHECK_HEADERS(fcntl.h locale.h sys/file.h unistd.h) +AC_CHECK_HEADERS_ONCE([fcntl.h locale.h sys/file.h unistd.h]) AC_CHECK_MEMBERS([struct stat.st_blksize]) AC_CHECK_MEMBERS([struct stat.st_rdev]) -jm_AC_TYPE_INTMAX_T -jm_AC_TYPE_UINTMAX_T AC_HEADER_DIRENT AC_HEADER_SYS_WAIT -AC_STRUCT_ST_MTIM_NSEC AC_TYPE_PID_T -AC_CHECK_FUNCS(dup2 gettimeofday sigaction sigprocmask strcasecoll stricoll) -AC_REPLACE_FUNCS(waitpid) +AC_DEFUN([DIFFUTILS_PREREQUISITES], [ + AC_REQUIRE([gl_AC_TYPE_INTMAX_T]) + AC_REQUIRE([gl_AC_TYPE_UINTMAX_T]) +]) +DIFFUTILS_PREREQUISITES + +AC_CHECK_FUNCS_ONCE([dup2 sigaction sigprocmask strcasecoll stricoll]) AC_FUNC_CLOSEDIR_VOID AC_FUNC_FORK -AC_DEFINE([REGEX_MALLOC], 1, - [Define to 1 to avoid alloca in the regular-expression implementation.]) - GNULIB_AUTOCONF_SNIPPET -AM_GNU_GETTEXT_VERSION([0.14.1]) +AM_GNU_GETTEXT([external], [need-ngettext]) +AM_GNU_GETTEXT_VERSION([0.14.5]) XGETTEXT="AWK='$AWK' \$(SHELL) \$(top_srcdir)/exgettext $XGETTEXT" - -# Check for clock_gettime and its library. Solaris puts it in -lrt or -# -lposix4, but we don't want to link that library unless we have to. -diff_saved_libs=$LIBS -AC_SEARCH_LIBS(clock_gettime, [rt posix4]) -case $ac_cv_search_clock_gettime in -no | 'none required') - LIB_CLOCK_GETTIME=;; -*) - LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime;; -esac -AC_SUBST([LIB_CLOCK_GETTIME]) -AC_CHECK_FUNCS(clock_gettime) -LIBS=$diff_saved_libs - -AC_FUNC_SETMODE_DOS - AC_CONFIG_FILES([Makefile doc/Makefile \ lib/Makefile man/Makefile \ - m4/Makefile ms/Makefile po/Makefile.in src/Makefile]) + ms/Makefile po/Makefile.in src/Makefile]) AC_OUTPUT diff --git a/doc/diff.texi b/doc/diff.texi index 79d0a7e..c891c71 100644 --- a/doc/diff.texi +++ b/doc/diff.texi @@ -15,8 +15,8 @@ and documents the @acronym{GNU} @command{diff}, @command{diff3}, differences between files and the @acronym{GNU} @command{patch} command for using their output to update files. -Copyright @copyright{} 1992, 1993, 1994, 1998, 2001, 2002, 2004 Free -Software Foundation, Inc. +Copyright @copyright{} 1992, 1993, 1994, 1998, 2001, 2002, 2004, 2006 +Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document @@ -635,7 +635,7 @@ hunks have run together, because their contents overlap. --- 1,6 ---- The Nameless is the origin of Heaven and Earth; ! The named is the mother of all things. -! +! @- Therefore let there always be non-being, so we may see their subtlety, And let there always be being, @@ -670,7 +670,7 @@ most one context line is reported here. --- 1,4 ---- The Nameless is the origin of Heaven and Earth; ! The named is the mother of all things. -! +! @- Therefore let there always be non-being, *************** *** 11 **** @@ -1087,7 +1087,7 @@ files. < The Named is the mother of all things. --- > The named is the mother of all things. -> +> @- 11a11,13 > They both may be called deep and profound. > Deeper and more profound, @@ -2026,7 +2026,7 @@ files. 2:2,3c 3:4,5c The named is the mother of all things. - + @- ====3 1:8c 2:7c @@ -2040,7 +2040,7 @@ files. Deeper and more profound, The door of all subtleties! 3:13,14c - + @- -- The Way of Lao-Tzu, tr. Wing-tsit Chan @end example @@ -3708,11 +3708,10 @@ context, or three if @var{lines} is not given. @xref{Context Format}. For proper operation, @command{patch} typically needs at least two lines of context. -On older systems, @command{diff} supports an obsolete option -@option{-@var{lines}} that has effect when combined with @option{-c} -or @option{-p}. @acronym{POSIX} 1003.1-2001 (@pxref{Standards -conformance}) does not allow this; use @option{-C @var{lines}} -instead. +For compatibility @command{diff} also supports an obsolete option +syntax @option{-@var{lines}} that has effect when combined with +@option{-c}, @option{-p}, or @option{-u}. New scripts should use +@option{-C @var{lines}} or @option{-U @var{lines}} instead. @item --changed-group-format=@var{format} Use @var{format} to output a line group containing differing lines from diff --git a/lib/Makefile.am b/lib/Makefile.am index dbf8b0f..fb14eb3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,6 @@ # Automakefile for GNU Diffutils library. -# Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2004, 2006 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 @@ -19,17 +19,16 @@ noinst_LIBRARIES = libdiffutils.a -noinst_HEADERS = cmpbuf.h prepargs.h quotesys.h +noinst_HEADERS = cmpbuf.h prepargs.h libdiffutils_a_SOURCES = $(lib_SOURCES) -lib_SOURCES = cmpbuf.c prepargs.c quotesys.c +lib_SOURCES = cmpbuf.c prepargs.c libdiffutils_a_LIBADD = @ALLOCA@ @LIBOBJS@ libdiffutils_a_DEPENDENCIES = $(libdiffutils_a_LIBADD) BUILT_SOURCES = -DISTCLEANFILES = -EXTRA_DIST = setmode.h waitpid.c +EXTRA_DIST = MOSTLYCLEANFILES = include gnulib.mk diff --git a/lib/cmpbuf.c b/lib/cmpbuf.c index 858aa39..971d4ac 100644 --- a/lib/cmpbuf.c +++ b/lib/cmpbuf.c @@ -1,6 +1,7 @@ /* Buffer primitives for comparison operations. - Copyright (C) 1993, 1995, 1998, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 1998, 2001, 2002, 2006 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 @@ -85,11 +86,12 @@ block_read (int fd, char *buf, size_t nbytes) { char *bp = buf; char const *buflim = buf + nbytes; - size_t readlim = SSIZE_MAX; + size_t readlim = MIN (SSIZE_MAX, SIZE_MAX); do { - size_t bytes_to_read = MIN (buflim - bp, readlim); + size_t bytes_remaining = buflim - bp; + size_t bytes_to_read = MIN (bytes_remaining, readlim); ssize_t nread = read (fd, bp, bytes_to_read); if (nread <= 0) { diff --git a/lib/posix/regex.h b/lib/posix/regex.h deleted file mode 100644 index 4230aff..0000000 --- a/lib/posix/regex.h +++ /dev/null @@ -1,566 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library, version 0.12. - Copyright (C) 1985,1989-93,1995-98,2000,2001 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; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifndef _REGEX_H -#define _REGEX_H 1 - -/* Allow the use in C++ code. */ -#ifdef __cplusplus -extern "C" { -#endif - -/* POSIX says that <sys/types.h> must be included (by the caller) before - <regex.h>. */ - -#if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS -/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it - should be there. */ -# include <stddef.h> -#endif - -/* The following two types have to be signed and unsigned integer type - wide enough to hold a value of a pointer. For most ANSI compilers - ptrdiff_t and size_t should be likely OK. Still size of these two - types is 2 for Microsoft C. Ugh... */ -typedef long int s_reg_t; -typedef unsigned long int active_reg_t; - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned long int reg_syntax_t; - -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions, of course). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX draft 11.2 says that * etc. in leading positions is undefined. - We already implemented a previous draft which made those constructs - invalid, though, so we haven't changed the code back. */ -#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. */ -#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches newline. - If not set, then it doesn't. */ -#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then . doesn't match NUL. - If not set, then it does. */ -#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -#define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, then `{...}' defines an interval, and \{ and \} - are literals. - If not set, then `\{...\}' defines an interval. */ -#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then \<digit> matches <digit>. - If not set, then \<digit> is a back-reference. */ -#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then an ending range point collating higher - than the starting range point, as in [z-a], is invalid. - If not set, then when ending range point collates higher than the - starting range point, the range is ignored. */ -#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then an unmatched ) is ordinary. - If not set, then an unmatched ) is invalid. */ -#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) - -/* If this bit is set, succeed as soon as we match the whole pattern, - without further backtracking. */ -#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) - -/* If this bit is set, do not process the GNU regex operators. - If not set, then the GNU regex operators are recognized. */ -#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) - -/* If this bit is set, turn on internal regex debugging. - If not set, and debugging was on, turn it off. - This only works if regex.c is compiled -DDEBUG. - We define this bit always, so that all that's needed to turn on - debugging is to recompile regex.c; the calling code can always have - this bit set, and it won't affect anything in the normal case. */ -#define RE_DEBUG (RE_NO_GNU_OPS << 1) - -/* If this bit is set, a syntactically invalid interval is treated as - a string of ordinary characters. For example, the ERE 'a{1' is - treated as 'a\{1'. */ -#define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; - -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ -/* [[[begin syntaxes]]] */ -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ - | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) - -#define RE_SYNTAX_GNU_AWK \ - ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ - & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS)) - -#define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ - | RE_INTERVALS | RE_NO_GNU_OPS) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ - | RE_INVALID_INTERVAL_ORD) - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -#define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is - removed and RE_NO_BK_REFS is added. */ -#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - -/* Maximum number of duplicates an interval can allow. Some systems - (erroneously) define this in other header files, but we want our - value, so remove any previous define. */ -#ifdef RE_DUP_MAX -# undef RE_DUP_MAX -#endif -/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */ -#define RE_DUP_MAX (0x7fff) - - -/* POSIX `cflags' bits (i.e., information for `regcomp'). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (REG_EXTENDED << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (REG_ICASE << 1) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (REG_NEWLINE << 1) - - -/* POSIX `eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - - -/* If any error codes are removed, changed, or added, update the - `re_error_msg' table in regex.c. */ -typedef enum -{ -#ifdef _XOPEN_SOURCE - REG_ENOSYS = -1, /* This will never happen for this implementation. */ -#endif - - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been - compiled, the `re_nsub' field is available. All other fields are - private to the regex routines. */ - -#ifndef RE_TRANSLATE_TYPE -# define RE_TRANSLATE_TYPE char * -#endif - -struct re_pattern_buffer -{ -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long int allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long int used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - RE_TRANSLATE_TYPE translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#define REGS_UNALLOCATED 0 -#define REGS_REALLOCATE 1 -#define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - -/* [[[end pattern_buffer]]] */ -}; - -typedef struct re_pattern_buffer regex_t; - -/* Type for byte offsets within the string. POSIX mandates this. */ -typedef int regoff_t; - - -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, - `re_match_2' returns information about at least this many registers - the first time a `regs' structure is passed. */ -#ifndef RE_NREGS -# define RE_NREGS 30 -#endif - - -/* POSIX specification for registers. Aside from the different names than - `re_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - -/* Declarations for routines. */ - -/* To avoid duplicating every routine declaration -- once with a - prototype (if we are ANSI), and once without (if we aren't) -- we - use the following macro to declare argument types. This - unfortunately clutters up the declarations a bit, but I think it's - worth it. */ - -#if __STDC__ - -# define _RE_ARGS(args) args - -#else /* not __STDC__ */ - -# define _RE_ARGS(args) () - -#endif /* not __STDC__ */ - -/* Sets the current default syntax to SYNTAX, and return the old syntax. - You can also simply assign to the `re_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global `re_syntax_options', into the buffer - BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern - _RE_ARGS ((const char *pattern, size_t length, - struct re_pattern_buffer *buffer)); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, int range, struct re_registers *regs)); - - -/* Like `re_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, int range, struct re_registers *regs, int stop)); - - -/* Like `re_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern int re_match - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, struct re_registers *regs)); - - -/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, struct re_registers *regs, int stop)); - - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using BUFFER and REGS will use this memory - for recording register information. STARTS and ENDS must be - allocated with malloc, and must each be at least `NUM_REGS * sizeof - (regoff_t)' bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ -extern void re_set_registers - _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, - unsigned num_regs, regoff_t *starts, regoff_t *ends)); - -#if defined _REGEX_RE_COMP || defined _LIBC -# ifndef _CRAY -/* 4.2 bsd compatibility. */ -extern char *re_comp _RE_ARGS ((const char *)); -extern int re_exec _RE_ARGS ((const char *)); -# endif -#endif - -/* GCC 2.95 and later have "__restrict"; C99 compilers have - "restrict", and "configure" may have defined "restrict". */ -#ifndef __restrict -# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) -# if defined restrict || 199901L <= __STDC_VERSION__ -# define __restrict restrict -# else -# define __restrict -# endif -# endif -#endif -/* gcc 3.1 and up support the [restrict] syntax. */ -#ifndef __restrict_arr -# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) -# define __restrict_arr __restrict -# else -# define __restrict_arr -# endif -#endif - -/* POSIX compatibility. */ -extern int regcomp _RE_ARGS ((regex_t *__restrict __preg, - const char *__restrict __pattern, - int __cflags)); - -extern int regexec _RE_ARGS ((const regex_t *__restrict __preg, - const char *__restrict __string, size_t __nmatch, - regmatch_t __pmatch[__restrict_arr], - int __eflags)); - -extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg, - char *__errbuf, size_t __errbuf_size)); - -extern void regfree _RE_ARGS ((regex_t *__preg)); - - -#ifdef __cplusplus -} -#endif /* C++ */ - -#endif /* regex.h */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/lib/setmode.c b/lib/setmode.c deleted file mode 100644 index 4f49be6..0000000 --- a/lib/setmode.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Set a file descriptor's mode to binary or to text. - - Copyright (C) 2001, 2004 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 Paul Eggert <eggert@twinsun.com> */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include "setmode.h" -#undef set_binary_mode - -#include <io.h> -#if HAVE_FCNTL_H -# include <fcntl.h> -#endif -#if HAVE_UNISTD_H -# include <unistd.h> -#endif - -#ifndef __attribute__ -# if __GNUC__ < 3 || __STRICT_ANSI__ -# define __attribute__(x) -# endif -#endif - -/* Set the binary mode of FD to MODE, returning its previous mode. - MODE is true for binary and false for text. If setting the mode might - cause problems, ignore the request and return MODE. */ - -bool -set_binary_mode (int fd, bool mode) -{ - if (isatty (fd)) - return mode; - return setmode (fd, mode ? O_BINARY : O_TEXT) != O_TEXT; -} diff --git a/lib/setmode.h b/lib/setmode.h deleted file mode 100644 index e562aeb..0000000 --- a/lib/setmode.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Set a file descriptor's mode to binary or to text. - - Copyright (C) 2001, 2004 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 Paul Eggert <eggert@twinsun.com> */ - -#include <stdbool.h> - -#ifndef set_binary_mode -bool set_binary_mode (int, bool); -# if ! HAVE_SETMODE_DOS -# define set_binary_mode(fd, mode) true -# endif -#endif diff --git a/m4/Makefile.am.in b/m4/Makefile.am.in deleted file mode 100644 index f5e1931..0000000 --- a/m4/Makefile.am.in +++ /dev/null @@ -1,12 +0,0 @@ -## This is a template from which Makefile.am is generated. -*-Makefile-*- - -Makefile.am: Makefile.am.in - rm -f $@ $@t - (echo "## Process this file with automake to produce Makefile.in."; \ - echo EXTRA_DIST =; \ - echo "EXTRA_DIST += Makefile.am.in"; \ - ls -1 *.m4 | sed 's/^/EXTRA_DIST += /'; echo ) \ - >> $@t - sed -n '/^Makefile\.am:/,$$p' $@.in >> $@t - chmod a-w $@t - mv $@t $@ diff --git a/m4/gnu-source.m4 b/m4/gnu-source.m4 deleted file mode 100644 index edecf5d..0000000 --- a/m4/gnu-source.m4 +++ /dev/null @@ -1,12 +0,0 @@ -# AC_GNU_SOURCE -# -------------- -AC_DEFUN([AC_GNU_SOURCE], -[AH_VERBATIM([_GNU_SOURCE], -[/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif])dnl -AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl -AC_BEFORE([$0], [AC_RUN_IFELSE])dnl -AC_DEFINE([_GNU_SOURCE]) -]) diff --git a/m4/jm-glibc-io.m4 b/m4/jm-glibc-io.m4 deleted file mode 100644 index e8054f0..0000000 --- a/m4/jm-glibc-io.m4 +++ /dev/null @@ -1,14 +0,0 @@ -#serial 7 -*- autoconf -*- - -dnl From Jim Meyering. -dnl -dnl See if the glibc *_unlocked I/O macros are available. -dnl Use only those *_unlocked macros that are declared. -dnl - -AC_DEFUN([jm_FUNC_GLIBC_UNLOCKED_IO], - [AC_CHECK_DECLS( - [clearerr_unlocked, feof_unlocked, ferror_unlocked, - fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked, - fread_unlocked, fwrite_unlocked, getc_unlocked, - getchar_unlocked, putc_unlocked, putchar_unlocked])]) diff --git a/m4/setmode.m4 b/m4/setmode.m4 deleted file mode 100644 index 827d303..0000000 --- a/m4/setmode.m4 +++ /dev/null @@ -1,39 +0,0 @@ -# Check for setmode, DOS style. - -# Copyright (C) 2001, 2002, 2004 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; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -AC_DEFUN([AC_FUNC_SETMODE_DOS], - [AC_CHECK_HEADERS(fcntl.h unistd.h) - AC_CACHE_CHECK([for DOS-style setmode], - [ac_cv_func_setmode_dos], - [AC_TRY_LINK( - [#include <io.h> - #if HAVE_FCNTL_H - # include <fcntl.h> - #endif - #if HAVE_UNISTD_H - # include <unistd.h> - #endif], - [int ret = setmode && setmode (1, O_BINARY);], - [ac_cv_func_setmode_dos=yes], - [ac_cv_func_setmode_dos=no])]) - if test $ac_cv_func_setmode_dos = yes; then - AC_LIBOBJ(setmode) - AC_DEFINE(HAVE_SETMODE_DOS, 1, - [Define to 1 if you have the DOS-style `setmode' function.]) - fi]) @@ -1,7 +1,7 @@ /* cmp - compare two files byte by byte Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2001, - 2002, 2004 Free Software Foundation, Inc. + 2002, 2004, 2006 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 @@ -32,7 +32,6 @@ #include <getopt.h> #include <hard-locale.h> #include <inttostr.h> -#include <setmode.h> #include <unlocked-io.h> #include <version-etc.h> #include <xalloc.h> @@ -126,15 +125,14 @@ static void specify_ignore_initial (int f, char **argptr, char delimiter) { uintmax_t val; - off_t o; char const *arg = *argptr; strtol_error e = xstrtoumax (arg, argptr, 0, &val, valid_suffixes); if (! (e == LONGINT_OK || (e == LONGINT_INVALID_SUFFIX_CHAR && **argptr == delimiter)) - || (o = val) < 0 || o != val || val == UINTMAX_MAX) + || TYPE_MAXIMUM (off_t) < val) try_help ("invalid --ignore-initial value `%s'", arg); - if (ignore_initial[f] < o) - ignore_initial[f] = o; + if (ignore_initial[f] < val) + ignore_initial[f] = val; } /* Specify the output format. */ @@ -284,9 +282,15 @@ main (int argc, char **argv) && file_name_cmp (file[0], file[1]) == 0) return EXIT_SUCCESS; - file_desc[f1] = (strcmp (file[f1], "-") == 0 - ? STDIN_FILENO - : open (file[f1], O_RDONLY, 0)); + if (strcmp (file[f1], "-") == 0) + { + file_desc[f1] = STDIN_FILENO; + if (O_BINARY && ! isatty (STDIN_FILENO)) + freopen (NULL, "rb", stdin); + } + else + file_desc[f1] = open (file[f1], O_RDONLY | O_BINARY, 0); + if (file_desc[f1] < 0 || fstat (file_desc[f1], stat_buf + f1) != 0) { if (file_desc[f1] < 0 && comparison_type == type_status) @@ -294,8 +298,6 @@ main (int argc, char **argv) else error (EXIT_TROUBLE, errno, "%s", file[f1]); } - - set_binary_mode (file_desc[f1], true); } /* If the files are links to the same inode and have the same file position, diff --git a/src/context.c b/src/context.c index 17164b3..7c127dd 100644 --- a/src/context.c +++ b/src/context.c @@ -1,7 +1,7 @@ /* Context-format output routines for GNU DIFF. Copyright (C) 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1998, 2001, - 2002, 2004 Free Software Foundation, Inc. + 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -22,73 +22,70 @@ #include "diff.h" #include <inttostr.h> +#include <stat-time.h> +#include <strftime.h> -#ifdef ST_MTIM_NSEC -# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC) -#else -# define TIMESPEC_NS(timespec) 0 -#endif +static char const *find_function (char const * const *, lin); +static struct change *find_hunk (struct change *); +static void mark_ignorable (struct change *); +static void pr_context_hunk (struct change *); +static void pr_unidiff_hunk (struct change *); -size_t nstrftime (char *, size_t, char const *, struct tm const *, int, int); +/* Last place find_function started searching from. */ +static lin find_function_last_search; -static char const *find_function (char const * const *, lin, struct diffopt *); -static struct change *find_hunk (struct change *, struct diffopt const *opt); -static void mark_ignorable (struct change *, struct diffopt *); -static void pr_context_hunk (struct change *, struct diffopt *); -static void pr_unidiff_hunk (struct change *, struct diffopt *); +/* The value find_function returned when it started searching there. */ +static lin find_function_last_match; /* Print a label for a context diff, with a file name and date or a label. */ static void print_context_label (char const *mark, struct file_data *inf, - char const *label, - struct diffopt const *opt) + char const *label) { if (label) - fprintf (opt->out, "%s %s\n", mark, label); + fprintf (outfile, "%s %s\n", mark, label); else { char buf[MAX (INT_STRLEN_BOUND (int) + 32, INT_STRLEN_BOUND (time_t) + 11)]; struct tm const *tm = localtime (&inf->stat.st_mtime); - int nsec = TIMESPEC_NS (inf->stat.st_mtim); - if (! (tm && nstrftime (buf, sizeof buf, opt->time_format, tm, 0, nsec))) + int nsec = get_stat_mtime_ns (&inf->stat); + if (! (tm && nstrftime (buf, sizeof buf, time_format, tm, 0, nsec))) { long int sec = inf->stat.st_mtime; - verify (info_preserved, sizeof inf->stat.st_mtime <= sizeof sec); + verify (sizeof inf->stat.st_mtime <= sizeof sec); sprintf (buf, "%ld.%.9d", sec, nsec); } - fprintf (opt->out, "%s %s\t%s\n", mark, inf->name, buf); + fprintf (outfile, "%s %s\t%s\n", mark, inf->name, buf); } } /* Print a header for a context diff, with the file names and dates. */ void -print_context_header (struct file_data inf[], bool unidiff, - struct diffopt const *opt) +print_context_header (struct file_data inf[], bool unidiff) { if (unidiff) { - print_context_label ("---", &inf[0], opt->file_label[0], opt); - print_context_label ("+++", &inf[1], opt->file_label[1], opt); + print_context_label ("---", &inf[0], file_label[0]); + print_context_label ("+++", &inf[1], file_label[1]); } else { - print_context_label ("***", &inf[0], opt->file_label[0], opt); - print_context_label ("---", &inf[1], opt->file_label[1], opt); + print_context_label ("***", &inf[0], file_label[0]); + print_context_label ("---", &inf[1], file_label[1]); } } /* Print an edit script in context format. */ void -print_context_script (struct change *script, bool unidiff, - struct diffopt *opt) +print_context_script (struct change *script, bool unidiff) { - if (opt->ignore_blank_lines || opt->ignore_regexp) - mark_ignorable (script, opt); + if (ignore_blank_lines || ignore_regexp.fastmap) + mark_ignorable (script); else { struct change *e; @@ -96,13 +93,13 @@ print_context_script (struct change *script, bool unidiff, e->ignore = false; } - opt->find_function.last_search = - opt->file[0].prefix_lines; - opt->find_function.last_match = LIN_MAX; + find_function_last_search = - files[0].prefix_lines; + find_function_last_match = LIN_MAX; if (unidiff) - print_script (script, find_hunk, pr_unidiff_hunk, opt); + print_script (script, find_hunk, pr_unidiff_hunk); else - print_script (script, find_hunk, pr_context_hunk, opt); + print_script (script, find_hunk, pr_context_hunk); } /* Print a pair of line numbers with a comma, translated for file FILE. @@ -112,8 +109,7 @@ print_context_script (struct change *script, bool unidiff, We print the translated (real) line numbers. */ static void -print_context_number_range (FILE *out, struct file_data const *file, - lin a, lin b) +print_context_number_range (struct file_data const *file, lin a, lin b) { long int trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); @@ -128,9 +124,9 @@ print_context_number_range (FILE *out, struct file_data const *file, specification. */ if (trans_b <= trans_a) - fprintf (out, "%ld", trans_b); + fprintf (outfile, "%ld", trans_b); else - fprintf (out, "%ld,%ld", trans_a, trans_b); + fprintf (outfile, "%ld,%ld", trans_a, trans_b); } /* Print FUNCTION in a context header. */ @@ -147,13 +143,12 @@ print_context_function (FILE *out, char const *function) /* Print a portion of an edit script in context format. HUNK is the beginning of the portion to be printed. The end is marked by a `link' that has been nulled out. - OPT is the diff options. Prints out lines from both files, and precedes each line with the appropriate flag-character. */ static void -pr_context_hunk (struct change *hunk, struct diffopt *opt) +pr_context_hunk (struct change *hunk) { lin first0, last0, first1, last1, i; char const *prefix; @@ -162,32 +157,31 @@ pr_context_hunk (struct change *hunk, struct diffopt *opt) /* Determine range of line numbers involved in each file. */ - enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1, - opt); + enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1); if (! changes) return; /* Include a context's width before and after. */ - i = - opt->file[0].prefix_lines; - first0 = MAX (first0 - opt->context, i); - first1 = MAX (first1 - opt->context, i); - if (last0 < opt->file[0].valid_lines - opt->context) - last0 += opt->context; + i = - files[0].prefix_lines; + first0 = MAX (first0 - context, i); + first1 = MAX (first1 - context, i); + if (last0 < files[0].valid_lines - context) + last0 += context; else - last0 = opt->file[0].valid_lines - 1; - if (last1 < opt->file[1].valid_lines - opt->context) - last1 += opt->context; + last0 = files[0].valid_lines - 1; + if (last1 < files[1].valid_lines - context) + last1 += context; else - last1 = opt->file[1].valid_lines - 1; + last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ - function = 0; - if (opt->function_regexp) - function = find_function (opt->file[0].linbuf, first0, opt); + function = NULL; + if (function_regexp.fastmap) + function = find_function (files[0].linbuf, first0); - begin_output (opt); - out = opt->out; + begin_output (); + out = outfile; fprintf (out, "***************"); @@ -195,7 +189,7 @@ pr_context_hunk (struct change *hunk, struct diffopt *opt) print_context_function (out, function); fprintf (out, "\n*** "); - print_context_number_range (opt->out, &opt->file[0], first0, last0); + print_context_number_range (&files[0], first0, last0); fprintf (out, " ****\n"); if (changes & OLD) @@ -219,12 +213,12 @@ pr_context_hunk (struct change *hunk, struct diffopt *opt) Otherwise it is "deleted". */ prefix = (next->inserted > 0 ? "!" : "-"); - print_1_line (prefix, &opt->file[0].linbuf[i], opt); + print_1_line (prefix, &files[0].linbuf[i]); } } fprintf (out, "--- "); - print_context_number_range (opt->out, &opt->file[1], first1, last1); + print_context_number_range (&files[1], first1, last1); fprintf (out, " ----\n"); if (changes & NEW) @@ -248,7 +242,7 @@ pr_context_hunk (struct change *hunk, struct diffopt *opt) Otherwise it is "inserted". */ prefix = (next->deleted > 0 ? "!" : "+"); - print_1_line (prefix, &opt->file[1].linbuf[i], opt); + print_1_line (prefix, &files[1].linbuf[i]); } } } @@ -258,13 +252,10 @@ pr_context_hunk (struct change *hunk, struct diffopt *opt) If the numbers are equal, print just one number. Args A and B are internal line numbers. - We print the translated (real) line numbers. - - OPT is the diff options. */ + We print the translated (real) line numbers. */ static void -print_unidiff_number_range (FILE *out, struct file_data const *file, - lin a, lin b) +print_unidiff_number_range (struct file_data const *file, lin a, lin b) { long int trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); @@ -274,9 +265,9 @@ print_unidiff_number_range (FILE *out, struct file_data const *file, which is B. It would be more logical to print A, but 'patch' expects B in order to detect diffs against empty files. */ if (trans_b <= trans_a) - fprintf (out, trans_b < trans_a ? "%ld,0" : "%ld", trans_b); + fprintf (outfile, trans_b < trans_a ? "%ld,0" : "%ld", trans_b); else - fprintf (out, "%ld,%ld", trans_a, trans_b - trans_a + 1); + fprintf (outfile, "%ld,%ld", trans_a, trans_b - trans_a + 1); } /* Print a portion of an edit script in unidiff format. @@ -284,12 +275,10 @@ print_unidiff_number_range (FILE *out, struct file_data const *file, The end is marked by a `link' that has been nulled out. Prints out lines from both files, and precedes each - line with the appropriate flag-character. - - OPT is the diff options. */ + line with the appropriate flag-character. */ static void -pr_unidiff_hunk (struct change *hunk, struct diffopt *opt) +pr_unidiff_hunk (struct change *hunk) { lin first0, last0, first1, last1; lin i, j, k; @@ -299,35 +288,35 @@ pr_unidiff_hunk (struct change *hunk, struct diffopt *opt) /* Determine range of line numbers involved in each file. */ - if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1, opt)) + if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1)) return; /* Include a context's width before and after. */ - i = - opt->file[0].prefix_lines; - first0 = MAX (first0 - opt->context, i); - first1 = MAX (first1 - opt->context, i); - if (last0 < opt->file[0].valid_lines - opt->context) - last0 += opt->context; + i = - files[0].prefix_lines; + first0 = MAX (first0 - context, i); + first1 = MAX (first1 - context, i); + if (last0 < files[0].valid_lines - context) + last0 += context; else - last0 = opt->file[0].valid_lines - 1; - if (last1 < opt->file[1].valid_lines - opt->context) - last1 += opt->context; + last0 = files[0].valid_lines - 1; + if (last1 < files[1].valid_lines - context) + last1 += context; else - last1 = opt->file[1].valid_lines - 1; + last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ - function = 0; - if (opt->function_regexp) - function = find_function (opt->file[0].linbuf, first0, opt); + function = NULL; + if (function_regexp.fastmap) + function = find_function (files[0].linbuf, first0); - begin_output (opt); - out = opt->out; + begin_output (); + out = outfile; fprintf (out, "@@ -"); - print_unidiff_number_range (opt->out, &opt->file[0], first0, last0); + print_unidiff_number_range (&files[0], first0, last0); fprintf (out, " +"); - print_unidiff_number_range (opt->out, &opt->file[1], first1, last1); + print_unidiff_number_range (&files[1], first1, last1); fprintf (out, " @@"); if (function) @@ -346,8 +335,8 @@ pr_unidiff_hunk (struct change *hunk, struct diffopt *opt) if (!next || i < next->line0) { - putc (opt->initial_tab ? '\t' : ' ', out); - print_1_line (0, &opt->file[0].linbuf[i++], opt); + putc (initial_tab ? '\t' : ' ', out); + print_1_line (NULL, &files[0].linbuf[i++]); j++; } else @@ -358,9 +347,9 @@ pr_unidiff_hunk (struct change *hunk, struct diffopt *opt) while (k--) { putc ('-', out); - if (opt->initial_tab) + if (initial_tab) putc ('\t', out); - print_1_line (0, &opt->file[0].linbuf[i++], opt); + print_1_line (NULL, &files[0].linbuf[i++]); } /* Then output the inserted part. */ @@ -369,9 +358,9 @@ pr_unidiff_hunk (struct change *hunk, struct diffopt *opt) while (k--) { putc ('+', out); - if (opt->initial_tab) + if (initial_tab) putc ('\t', out); - print_1_line (0, &opt->file[1].linbuf[j++], opt); + print_1_line (NULL, &files[1].linbuf[j++]); } /* We're done with this hunk, so on to the next! */ @@ -386,7 +375,7 @@ pr_unidiff_hunk (struct change *hunk, struct diffopt *opt) to the `struct change' for the last change before those lines. */ static struct change * -find_hunk (struct change *start, struct diffopt const *opt) +find_hunk (struct change *start) { struct change *prev; lin top0, top1; @@ -396,8 +385,8 @@ find_hunk (struct change *start, struct diffopt const *opt) changes, but only CONTEXT if one is ignorable. Watch out for integer overflow, though. */ lin non_ignorable_threshold = - (LIN_MAX - 1) / 2 < opt->context ? LIN_MAX : 2 * opt->context + 1; - lin ignorable_threshold = opt->context; + (LIN_MAX - 1) / 2 < context ? LIN_MAX : 2 * context + 1; + lin ignorable_threshold = context; do { @@ -426,7 +415,7 @@ find_hunk (struct change *start, struct diffopt const *opt) are ignorable lines. */ static void -mark_ignorable (struct change *script, struct diffopt *opt) +mark_ignorable (struct change *script) { while (script) { @@ -438,7 +427,7 @@ mark_ignorable (struct change *script, struct diffopt *opt) /* Determine whether this change is ignorable. */ script->ignore = ! analyze_hunk (script, - &first0, &last0, &first1, &last1, opt); + &first0, &last0, &first1, &last1); /* Reconnect the chain as before. */ script->link = next; @@ -449,17 +438,15 @@ mark_ignorable (struct change *script, struct diffopt *opt) } /* Find the last function-header line in LINBUF prior to line number LINENUM. - This is a line containing a match for the regexp in `opt->function_regexp'. - OPT is the diff options. - Return the address of the text, or 0 if no function-header is found. */ + This is a line containing a match for the regexp in `function_regexp'. + Return the address of the text, or NULL if no function-header is found. */ static char const * -find_function (char const * const *linbuf, lin linenum, - struct diffopt *opt) +find_function (char const * const *linbuf, lin linenum) { lin i = linenum; - lin last = opt->find_function.last_search; - opt->find_function.last_search = i; + lin last = find_function_last_search; + find_function_last_search = i; while (last <= --i) { @@ -470,16 +457,16 @@ find_function (char const * const *linbuf, lin linenum, /* FIXME: re_search's size args should be size_t, not int. */ int len = MIN (linelen, INT_MAX); - if (0 <= re_search (opt->function_regexp, line, len, 0, len, 0)) + if (0 <= re_search (&function_regexp, line, len, 0, len, NULL)) { - opt->find_function.last_match = i; + find_function_last_match = i; return line; } } /* If we search back to where we started searching the previous time, find the line we found last time. */ - if (opt->find_function.last_match != LIN_MAX) - return linbuf[opt->find_function.last_match]; + if (find_function_last_match != LIN_MAX) + return linbuf[find_function_last_match]; - return 0; + return NULL; } @@ -1,7 +1,7 @@ /* diff - compare files line by line Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 2001, 2002, - 2004 Free Software Foundation, Inc. + 2004, 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -20,6 +20,7 @@ If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define GDIFF_MAIN #include "diff.h" #include "paths.h" #include <c-stack.h> @@ -32,10 +33,10 @@ #include <fnmatch.h> #include <getopt.h> #include <hard-locale.h> -#include <posixver.h> #include <prepargs.h> -#include <quotesys.h> -#include <setmode.h> +#include <sh-quote.h> +#include <stat-time.h> +#include <timespec.h> #include <version-etc.h> #include <xalloc.h> @@ -52,23 +53,47 @@ struct regexp_list struct re_pattern_buffer *buf; }; -static int compare_files (struct comparison const *, char const *, char const *, struct diffopt *); -static void init_regexp_list (struct regexp_list *, struct re_pattern_buffer *); +static int compare_files (struct comparison const *, char const *, char const *); static void add_regexp (struct regexp_list *, char const *); -static struct re_pattern_buffer *summarize_regexp_list (struct regexp_list *); -static void specify_style (enum output_style, struct diffopt *); +static void summarize_regexp_list (struct regexp_list *); +static void specify_style (enum output_style); static void specify_value (char const **, char const *, char const *); static void try_help (char const *, char const *) __attribute__((noreturn)); -static void check_stdout (struct diffopt const *); +static void check_stdout (void); static void usage (void); -#if HAVE_SETMODE_DOS +/* If comparing directories, compare their common subdirectories + recursively. */ +static bool recursive; + +/* In context diffs, show previous lines that match these regexps. */ +static struct regexp_list function_regexp_list; + +/* Ignore changes affecting only lines that match these regexps. */ +static struct regexp_list ignore_regexp_list; + +#if O_BINARY /* Use binary I/O when reading and writing data (--binary). On POSIX hosts, this has no effect. */ static bool binary; #else enum { binary = true }; #endif + +/* When comparing directories, if a file appears only in one + directory, treat it as present but empty in the other (-N). + Then `patch' would create the file with appropriate contents. */ +static bool new_file; + +/* When comparing directories, if a file appears only in the second + directory of the two, treat it as present but empty in the other + (--unidirectional-new-file). + Then `patch' would create the file with appropriate contents. */ +static bool unidirectional_new_file; + +/* Report files compared that are the same (-s). + Normally nothing is output when that happens. */ +static bool report_identical_files; static char const shortopts[] = "0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:y"; @@ -181,6 +206,8 @@ static struct option const longopts[] = /* Program name. */ char *program_name; + + /* Return a string containing the command options with which diff was invoked. Spaces appear between what were separate ARGV-elements. There is a space at the beginning but none at the end. @@ -198,14 +225,14 @@ option_list (char **optionvec, int count) char *p; for (i = 0; i < count; i++) - size += 1 + quote_system_arg (NULL, optionvec[i]); + size += 1 + shell_quote_length (optionvec[i]); p = result = xmalloc (size); for (i = 0; i < count; i++) { *p++ = ' '; - p += quote_system_arg (p, optionvec[i]); + p = shell_quote_copy (p, optionvec[i]); } *p = '\0'; @@ -216,9 +243,9 @@ option_list (char **optionvec, int count) /* Return an option value suitable for add_exclude. */ static int -exclude_options (struct diffopt const *opt) +exclude_options (void) { - return EXCLUDE_WILDCARDS | (opt->ignore_file_name_case ? FNM_CASEFOLD : 0); + return EXCLUDE_WILDCARDS | (ignore_file_name_case ? FNM_CASEFOLD : 0); } int @@ -236,11 +263,6 @@ main (int argc, char **argv) char const *to_file = NULL; uintmax_t numval; char *numend; - struct regexp_list function_regexp_list; - struct regexp_list ignore_regexp_list; - struct re_pattern_buffer function_regexp; - struct re_pattern_buffer ignore_regexp; - struct diffopt opt; /* Do our initializations. */ exit_failure = 2; @@ -250,12 +272,10 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (0); + function_regexp_list.buf = &function_regexp; + ignore_regexp_list.buf = &ignore_regexp; re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING); - - memset (&opt, 0, sizeof opt); - init_regexp_list (&function_regexp_list, &function_regexp); - init_regexp_list (&ignore_regexp_list, &ignore_regexp); - opt.excluded = new_exclude (); + excluded = new_exclude (); /* Decode the options. */ @@ -284,16 +304,16 @@ main (int argc, char **argv) break; case 'a': - opt.text = true; + text = true; break; case 'b': - if (opt.ignore_white_space < IGNORE_SPACE_CHANGE) - opt.ignore_white_space = IGNORE_SPACE_CHANGE; + if (ignore_white_space < IGNORE_SPACE_CHANGE) + ignore_white_space = IGNORE_SPACE_CHANGE; break; case 'B': - opt.ignore_blank_lines = true; + ignore_blank_lines = true; break; case 'C': @@ -310,25 +330,25 @@ main (int argc, char **argv) else numval = 3; - specify_style (c == 'U' ? OUTPUT_UNIFIED : OUTPUT_CONTEXT, &opt); - if (opt.context < numval) - opt.context = numval; + specify_style (c == 'U' ? OUTPUT_UNIFIED : OUTPUT_CONTEXT); + if (context < numval) + context = numval; explicit_context = true; } break; case 'c': - specify_style (OUTPUT_CONTEXT, &opt); - if (opt.context < 3) - opt.context = 3; + specify_style (OUTPUT_CONTEXT); + if (context < 3) + context = 3; break; case 'd': - opt.minimal = true; + minimal = true; break; case 'D': - specify_style (OUTPUT_IFDEF, &opt); + specify_style (OUTPUT_IFDEF); { static char const C_ifdef_group_formats[] = "%%=%c#ifndef %s\n%%<#endif /* ! %s */\n%c#ifdef %s\n%%>#endif /* %s */\n%c#ifndef %s\n%%<#else /* %s */\n%%>#endif /* %s */\n"; @@ -340,27 +360,25 @@ main (int argc, char **argv) optarg, optarg, 0, optarg, optarg, 0, optarg, optarg, optarg); - for (i = 0; - i < sizeof opt.group_format / sizeof opt.group_format[0]; - i++) + for (i = 0; i < sizeof group_format / sizeof group_format[0]; i++) { - specify_value (&opt.group_format[i], b, "-D"); + specify_value (&group_format[i], b, "-D"); b += strlen (b) + 1; } } break; case 'e': - specify_style (OUTPUT_ED, &opt); + specify_style (OUTPUT_ED); break; case 'E': - if (opt.ignore_white_space < IGNORE_TAB_EXPANSION) - opt.ignore_white_space = IGNORE_TAB_EXPANSION; + if (ignore_white_space < IGNORE_TAB_EXPANSION) + ignore_white_space = IGNORE_TAB_EXPANSION; break; case 'f': - specify_style (OUTPUT_FORWARD_ED, &opt); + specify_style (OUTPUT_FORWARD_ED); break; case 'F': @@ -375,11 +393,11 @@ main (int argc, char **argv) break; case 'H': - opt.speed_large_files = true; + speed_large_files = true; break; case 'i': - opt.ignore_case = true; + ignore_case = true; break; case 'I': @@ -389,7 +407,7 @@ main (int argc, char **argv) case 'l': if (!pr_program[0]) try_help ("pagination not supported on this host", NULL); - opt.paginate = true; + paginate = true; #ifdef SIGCHLD /* Pagination requires forking and waiting, and System V fork+wait does not work if SIGCHLD is ignored. */ @@ -398,20 +416,20 @@ main (int argc, char **argv) break; case 'L': - if (!opt.file_label[0]) - opt.file_label[0] = optarg; - else if (!opt.file_label[1]) - opt.file_label[1] = optarg; + if (!file_label[0]) + file_label[0] = optarg; + else if (!file_label[1]) + file_label[1] = optarg; else - fatal ("too many file label options", &opt); + fatal ("too many file label options"); break; case 'n': - specify_style (OUTPUT_RCS, &opt); + specify_style (OUTPUT_RCS); break; case 'N': - opt.new_file = true; + new_file = true; break; case 'p': @@ -420,62 +438,62 @@ main (int argc, char **argv) break; case 'P': - opt.unidirectional_new_file = true; + unidirectional_new_file = true; break; case 'q': - opt.brief = true; + brief = true; break; case 'r': - opt.recursive = true; + recursive = true; break; case 's': - opt.report_identical_files = true; + report_identical_files = true; break; case 'S': - specify_value (&opt.starting_file, optarg, "-S"); + specify_value (&starting_file, optarg, "-S"); break; case 't': - opt.expand_tabs = true; + expand_tabs = true; break; case 'T': - opt.initial_tab = true; + initial_tab = true; break; case 'u': - specify_style (OUTPUT_UNIFIED, &opt); - if (opt.context < 3) - opt.context = 3; + specify_style (OUTPUT_UNIFIED); + if (context < 3) + context = 3; break; case 'v': version_etc (stdout, "diff", PACKAGE_NAME, PACKAGE_VERSION, "Paul Eggert", "Mike Haertel", "David Hayes", "Richard Stallman", "Len Tower", (char *) NULL); - check_stdout (&opt); + check_stdout (); return EXIT_SUCCESS; case 'w': - opt.ignore_white_space = IGNORE_ALL_SPACE; + ignore_white_space = IGNORE_ALL_SPACE; break; case 'x': - add_exclude (opt.excluded, optarg, exclude_options (&opt)); + add_exclude (excluded, optarg, exclude_options ()); break; case 'X': - if (add_exclude_file (add_exclude, opt.excluded, optarg, - exclude_options (&opt), '\n')) - pfatal_with_name (optarg, &opt); + if (add_exclude_file (add_exclude, excluded, optarg, + exclude_options (), '\n')) + pfatal_with_name (optarg); break; case 'y': - specify_style (OUTPUT_SDIFF, &opt); + specify_style (OUTPUT_SDIFF); break; case 'W': @@ -485,15 +503,16 @@ main (int argc, char **argv) if (width != numval) { if (width) - fatal ("conflicting width options", &opt); + fatal ("conflicting width options"); width = numval; } break; case BINARY_OPTION: -#if HAVE_SETMODE_DOS +#if O_BINARY binary = true; - set_binary_mode (STDOUT_FILENO, true); + if (! isatty (STDOUT_FILENO)) + freopen (NULL, "wb", stdout); #endif break; @@ -503,18 +522,18 @@ main (int argc, char **argv) case HELP_OPTION: usage (); - check_stdout (&opt); + check_stdout (); return EXIT_SUCCESS; case HORIZON_LINES_OPTION: numval = strtoumax (optarg, &numend, 10); if (*numend) try_help ("invalid horizon length `%s'", optarg); - opt.horizon_lines = MAX (opt.horizon_lines, MIN (numval, LIN_MAX)); + horizon_lines = MAX (horizon_lines, MIN (numval, LIN_MAX)); break; case IGNORE_FILE_NAME_CASE_OPTION: - opt.ignore_file_name_case = true; + ignore_file_name_case = true; break; case INHIBIT_HUNK_MERGE_OPTION: @@ -523,47 +542,45 @@ main (int argc, char **argv) break; case LEFT_COLUMN_OPTION: - opt.left_column = true; + left_column = true; break; case LINE_FORMAT_OPTION: - specify_style (OUTPUT_IFDEF, &opt); - for (i = 0; - i < sizeof opt.line_format / sizeof opt.line_format[0]; - i++) - specify_value (&opt.line_format[i], optarg, "--line-format"); + specify_style (OUTPUT_IFDEF); + for (i = 0; i < sizeof line_format / sizeof line_format[0]; i++) + specify_value (&line_format[i], optarg, "--line-format"); break; case NO_IGNORE_FILE_NAME_CASE_OPTION: - opt.ignore_file_name_case = false; + ignore_file_name_case = false; break; case NORMAL_OPTION: - specify_style (OUTPUT_NORMAL, &opt); + specify_style (OUTPUT_NORMAL); break; case SDIFF_MERGE_ASSIST_OPTION: - specify_style (OUTPUT_SDIFF, &opt); - opt.sdiff_merge_assist = true; + specify_style (OUTPUT_SDIFF); + sdiff_merge_assist = true; break; case STRIP_TRAILING_CR_OPTION: - opt.strip_trailing_cr = true; + strip_trailing_cr = true; break; case SUPPRESS_COMMON_LINES_OPTION: - opt.suppress_common_lines = true; + suppress_common_lines = true; break; case TABSIZE_OPTION: numval = strtoumax (optarg, &numend, 10); if (! (0 < numval && numval <= SIZE_MAX) || *numend) try_help ("invalid tabsize `%s'", optarg); - if (opt.tabsize != numval) + if (tabsize != numval) { - if (opt.tabsize) - fatal ("conflicting tabsize options", &opt); - opt.tabsize = numval; + if (tabsize) + fatal ("conflicting tabsize options"); + tabsize = numval; } break; @@ -574,18 +591,18 @@ main (int argc, char **argv) case UNCHANGED_LINE_FORMAT_OPTION: case OLD_LINE_FORMAT_OPTION: case NEW_LINE_FORMAT_OPTION: - specify_style (OUTPUT_IFDEF, &opt); + specify_style (OUTPUT_IFDEF); c -= UNCHANGED_LINE_FORMAT_OPTION; - specify_value (&opt.line_format[c], optarg, line_format_option[c]); + specify_value (&line_format[c], optarg, line_format_option[c]); break; case UNCHANGED_GROUP_FORMAT_OPTION: case OLD_GROUP_FORMAT_OPTION: case NEW_GROUP_FORMAT_OPTION: case CHANGED_GROUP_FORMAT_OPTION: - specify_style (OUTPUT_IFDEF, &opt); + specify_style (OUTPUT_IFDEF); c -= UNCHANGED_GROUP_FORMAT_OPTION; - specify_value (&opt.group_format[c], optarg, group_format_option[c]); + specify_value (&group_format[c], optarg, group_format_option[c]); break; default: @@ -594,65 +611,42 @@ main (int argc, char **argv) prev = c; } - if (opt.output_style == OUTPUT_UNSPECIFIED) + if (output_style == OUTPUT_UNSPECIFIED) { if (show_c_function) { - specify_style (OUTPUT_CONTEXT, &opt); + specify_style (OUTPUT_CONTEXT); if (ocontext < 0) - opt.context = 3; + context = 3; } else - specify_style (OUTPUT_NORMAL, &opt); + specify_style (OUTPUT_NORMAL); } - if (opt.output_style != OUTPUT_CONTEXT || hard_locale (LC_TIME)) + if (output_style != OUTPUT_CONTEXT || hard_locale (LC_TIME)) { -#ifdef ST_MTIM_NSEC - opt.time_format = "%Y-%m-%d %H:%M:%S.%N %z"; +#if (defined STAT_TIMESPEC || defined STAT_TIMESPEC_NS \ + || defined HAVE_STRUCT_STAT_ST_SPARE1) + time_format = "%Y-%m-%d %H:%M:%S.%N %z"; #else - opt.time_format = "%Y-%m-%d %H:%M:%S %z"; + time_format = "%Y-%m-%d %H:%M:%S %z"; #endif } else { /* See POSIX 1003.1-2001 for this format. */ - opt.time_format = "%a %b %e %T %Y"; + time_format = "%a %b %e %T %Y"; } - if (0 <= ocontext) - { - bool modern_usage = 200112 <= posix2_version (); - - if ((opt.output_style == OUTPUT_CONTEXT - || opt.output_style == OUTPUT_UNIFIED) - && (opt.context < ocontext - || (ocontext < opt.context && ! explicit_context))) - { - if (modern_usage) - { - error (0, 0, - _("`-%ld' option is obsolete; use `-%c %ld'"), - (long int) ocontext, - opt.output_style == OUTPUT_CONTEXT ? 'C' : 'U', - (long int) ocontext); - try_help (NULL, NULL); - } - opt.context = ocontext; - } - else - { - if (modern_usage) - { - error (0, 0, _("`-%ld' option is obsolete; omit it"), - (long int) ocontext); - try_help (NULL, NULL); - } - } - } + if (0 <= ocontext + && (output_style == OUTPUT_CONTEXT + || output_style == OUTPUT_UNIFIED) + && (context < ocontext + || (ocontext < context && ! explicit_context))) + context = ocontext; - if (! opt.tabsize) - opt.tabsize = 8; + if (! tabsize) + tabsize = 8; if (! width) width = 130; @@ -667,63 +661,61 @@ main (int argc, char **argv) a half line plus a gutter is an integral number of tabs, so that tabs in the right column line up. */ - intmax_t t = opt.expand_tabs ? 1 : opt.tabsize; + intmax_t t = expand_tabs ? 1 : tabsize; intmax_t w = width; intmax_t off = (w + t + GUTTER_WIDTH_MINIMUM) / (2 * t) * t; - opt.sdiff_half_width = MAX (0, MIN (off - GUTTER_WIDTH_MINIMUM, w - off)), - opt.sdiff_column2_offset = opt.sdiff_half_width ? off : w; + sdiff_half_width = MAX (0, MIN (off - GUTTER_WIDTH_MINIMUM, w - off)), + sdiff_column2_offset = sdiff_half_width ? off : w; } /* Make the horizon at least as large as the context, so that shift_boundaries has more freedom to shift the first and last hunks. */ - if (opt.horizon_lines < opt.context) - opt.horizon_lines = opt.context; + if (horizon_lines < context) + horizon_lines = context; - if (function_regexp_list.regexps) - opt.function_regexp = summarize_regexp_list (&function_regexp_list); - if (ignore_regexp_list.regexps) - opt.ignore_regexp = summarize_regexp_list (&ignore_regexp_list); + summarize_regexp_list (&function_regexp_list); + summarize_regexp_list (&ignore_regexp_list); - if (opt.output_style == OUTPUT_IFDEF) + if (output_style == OUTPUT_IFDEF) { - for (i = 0; i < sizeof opt.line_format / sizeof opt.line_format[0]; i++) - if (!opt.line_format[i]) - opt.line_format[i] = "%l\n"; - if (!opt.group_format[OLD]) - opt.group_format[OLD] - = opt.group_format[CHANGED] ? opt.group_format[CHANGED] : "%<"; - if (!opt.group_format[NEW]) - opt.group_format[NEW] - = opt.group_format[CHANGED] ? opt.group_format[CHANGED] : "%>"; - if (!opt.group_format[UNCHANGED]) - opt.group_format[UNCHANGED] = "%="; - if (!opt.group_format[CHANGED]) - opt.group_format[CHANGED] = concat (opt.group_format[OLD], - opt.group_format[NEW], ""); + for (i = 0; i < sizeof line_format / sizeof line_format[0]; i++) + if (!line_format[i]) + line_format[i] = "%l\n"; + if (!group_format[OLD]) + group_format[OLD] + = group_format[CHANGED] ? group_format[CHANGED] : "%<"; + if (!group_format[NEW]) + group_format[NEW] + = group_format[CHANGED] ? group_format[CHANGED] : "%>"; + if (!group_format[UNCHANGED]) + group_format[UNCHANGED] = "%="; + if (!group_format[CHANGED]) + group_format[CHANGED] = concat (group_format[OLD], + group_format[NEW], ""); } - opt.no_diff_means_no_output = - (opt.output_style == OUTPUT_IFDEF ? - (!*opt.group_format[UNCHANGED] - || (strcmp (opt.group_format[UNCHANGED], "%=") == 0 - && !*opt.line_format[UNCHANGED])) - : (opt.output_style != OUTPUT_SDIFF) | opt.suppress_common_lines); + no_diff_means_no_output = + (output_style == OUTPUT_IFDEF ? + (!*group_format[UNCHANGED] + || (strcmp (group_format[UNCHANGED], "%=") == 0 + && !*line_format[UNCHANGED])) + : (output_style != OUTPUT_SDIFF) | suppress_common_lines); - opt.files_can_be_treated_as_binary = - (opt.brief & binary - & ~ (opt.ignore_blank_lines | opt.ignore_case | opt.strip_trailing_cr - | (ignore_regexp_list.regexps || opt.ignore_white_space))); + files_can_be_treated_as_binary = + (brief & binary + & ~ (ignore_blank_lines | ignore_case | strip_trailing_cr + | (ignore_regexp_list.regexps || ignore_white_space))); - opt.switch_string = option_list (argv + 1, optind - 1); + switch_string = option_list (argv + 1, optind - 1); if (from_file) { if (to_file) - fatal ("--from-file and --to-file both specified", &opt); + fatal ("--from-file and --to-file both specified"); else for (; optind < argc; optind++) { - int status = compare_files (NULL, from_file, argv[optind], &opt); + int status = compare_files (NULL, from_file, argv[optind]); if (exit_status < status) exit_status = status; } @@ -733,7 +725,7 @@ main (int argc, char **argv) if (to_file) for (; optind < argc; optind++) { - int status = compare_files (NULL, argv[optind], to_file, &opt); + int status = compare_files (NULL, argv[optind], to_file); if (exit_status < status) exit_status = status; } @@ -747,31 +739,18 @@ main (int argc, char **argv) try_help ("extra operand `%s'", argv[optind + 2]); } - exit_status = compare_files (NULL, argv[optind], argv[optind + 1], - &opt); + exit_status = compare_files (NULL, argv[optind], argv[optind + 1]); } } /* Print any messages that were saved up for last. */ - print_message_queue (&opt); + print_message_queue (); - check_stdout (&opt); + check_stdout (); exit (exit_status); return exit_status; } -/* Initialize REGLIST for BUF. */ - -static void -init_regexp_list (struct regexp_list *reglist, struct re_pattern_buffer *buf) -{ - reglist->regexps = NULL; - reglist->len = 0; - reglist->size = 0; - reglist->multiple_regexps = false; - reglist->buf = buf; -} - /* Append to REGLIST the regexp PATTERN. */ static void @@ -811,23 +790,25 @@ add_regexp (struct regexp_list *reglist, char const *pattern) } /* Ensure that REGLIST represents the disjunction of its regexps. - This is done here, rather than earlier, to avoid O(N^2) behavior. - Return the compiled regular expression summarizing the disjunction. */ + This is done here, rather than earlier, to avoid O(N^2) behavior. */ -static struct re_pattern_buffer * +static void summarize_regexp_list (struct regexp_list *reglist) { - reglist->buf->fastmap = xmalloc (1 << CHAR_BIT); - if (reglist->multiple_regexps) + if (reglist->regexps) { - /* Compile the disjunction of the regexps. - (If just one regexp was specified, it is already compiled.) */ - char const *m = re_compile_pattern (reglist->regexps, reglist->len, - reglist->buf); - if (m) - error (EXIT_TROUBLE, 0, "%s: %s", reglist->regexps, m); + /* At least one regexp was specified. Allocate a fastmap for it. */ + reglist->buf->fastmap = xmalloc (1 << CHAR_BIT); + if (reglist->multiple_regexps) + { + /* Compile the disjunction of the regexps. + (If just one regexp was specified, it is already compiled.) */ + char const *m = re_compile_pattern (reglist->regexps, reglist->len, + reglist->buf); + if (m) + error (EXIT_TROUBLE, 0, "%s: %s", reglist->regexps, m); + } } - return reglist->buf; } static void @@ -841,12 +822,12 @@ try_help (char const *reason_msgid, char const *operand) } static void -check_stdout (struct diffopt const *opt) +check_stdout (void) { if (ferror (stdout)) - fatal ("write failed", opt); + fatal ("write failed"); else if (fclose (stdout) != 0) - pfatal_with_name (_("standard output"), opt); + pfatal_with_name (_("standard output")); } static char const * const option_help_msgid[] = { @@ -861,7 +842,7 @@ static char const * const option_help_msgid[] = { N_("-B --ignore-blank-lines Ignore changes whose lines are all blank."), N_("-I RE --ignore-matching-lines=RE Ignore changes whose lines all match RE."), N_("--strip-trailing-cr Strip trailing carriage return on input."), -#if HAVE_SETMODE_DOS +#if O_BINARY N_("--binary Read and write data in binary mode."), #endif N_("-a --text Treat all files as text."), @@ -977,13 +958,13 @@ specify_value (char const **var, char const *value, char const *option) /* Set the output style to STYLE, diagnosing conflicts. */ static void -specify_style (enum output_style style, struct diffopt *opt) +specify_style (enum output_style style) { - if (opt->output_style != style) + if (output_style != style) { - if (opt->output_style != OUTPUT_UNSPECIFIED) + if (output_style != OUTPUT_UNSPECIFIED) try_help ("conflicting output style options", NULL); - opt->output_style = style; + output_style = style; } } @@ -992,28 +973,18 @@ specify_style (enum output_style style, struct diffopt *opt) static void set_mtime_to_now (struct stat *st) { -#ifdef ST_MTIM_NSEC - -# if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME - if (clock_gettime (CLOCK_REALTIME, &st->st_mtim) == 0) - return; -# endif - -# if HAVE_GETTIMEOFDAY - { - struct timeval timeval; - if (gettimeofday (&timeval, 0) == 0) - { - st->st_mtime = timeval.tv_sec; - st->st_mtim.ST_MTIM_NSEC = timeval.tv_usec * 1000; - return; - } - } +#ifdef STAT_TIMESPEC + gettime (&STAT_TIMESPEC (st, st_mtim)); +#else + struct timespec t; + gettime (&t); + st->st_mtime = t.tv_sec; +# if defined STAT_TIMESPEC_NS + STAT_TIMESPEC_NS (st, st_mtim) = t.tv_nsec; +# elif defined HAVE_STRUCT_STAT_ST_SPARE1 + st->st_spare1 = t.tv_nsec / 1000; # endif - -#endif /* ST_MTIM_NSEC */ - - time (&st->st_mtime); +#endif } /* Compare two files (or dirs) with parent comparison PARENT @@ -1027,8 +998,7 @@ set_mtime_to_now (struct stat *st) static int compare_files (struct comparison const *parent, char const *name0, - char const *name1, - struct diffopt *opt) + char const *name1) { struct comparison cmp; #define DIR_P(f) (S_ISDIR (cmp.file[f].stat.st_mode) != 0) @@ -1043,14 +1013,14 @@ compare_files (struct comparison const *parent, If so, just print a message to that effect. */ if (! ((name0 && name1) - || (opt->unidirectional_new_file && name1) - || opt->new_file)) + || (unidirectional_new_file && name1) + || new_file)) { char const *name = name0 ? name0 : name1; char const *dir = parent->file[!name0].name; /* See POSIX 1003.1-2001 for this format. */ - message (opt, "Only in %s: %s\n", dir, name); + message ("Only in %s: %s\n", dir, name); /* Return EXIT_FAILURE so that diff_dirs will return EXIT_FAILURE ("some files differ"). */ @@ -1106,6 +1076,8 @@ compare_files (struct comparison const *parent, else if (strcmp (cmp.file[f].name, "-") == 0) { cmp.file[f].desc = STDIN_FILENO; + if (binary && ! isatty (STDIN_FILENO)) + freopen (NULL, "rb", stdin); if (fstat (STDIN_FILENO, &cmp.file[f].stat) != 0) cmp.file[f].desc = ERRNO_ENCODE (errno); else @@ -1136,7 +1108,7 @@ compare_files (struct comparison const *parent, top-level files that do not exist but their counterparts do exist. */ for (f = 0; f < 2; f++) - if ((opt->new_file || (f == 0 && opt->unidirectional_new_file)) + if ((new_file || (f == 0 && unidirectional_new_file)) && (cmp.file[f].desc == UNOPENED ? (S_ISREG (cmp.file[f].stat.st_mode) && ! (cmp.file[f].stat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) @@ -1177,7 +1149,7 @@ compare_files (struct comparison const *parent, = dir_file_pathname (dir, base_name (fnm)); if (strcmp (fnm, "-") == 0) - fatal ("cannot compare `-' to a directory", opt); + fatal ("cannot compare `-' to a directory"); if (stat (filename, &cmp.file[dir_arg].stat) != 0) { @@ -1201,28 +1173,28 @@ compare_files (struct comparison const *parent, && 0 < same_file (&cmp.file[0].stat, &cmp.file[1].stat) && same_file_attributes (&cmp.file[0].stat, &cmp.file[1].stat))) - && opt->no_diff_means_no_output) + && no_diff_means_no_output) { /* The two named files are actually the same physical file. We know they are identical without actually reading them. */ } else if (DIR_P (0) & DIR_P (1)) { - if (opt->output_style == OUTPUT_IFDEF) - fatal ("-D option not supported with directories", opt); + if (output_style == OUTPUT_IFDEF) + fatal ("-D option not supported with directories"); /* If both are directories, compare the files in them. */ - if (parent && !opt->recursive) + if (parent && !recursive) { /* But don't compare dir contents one level down unless -r was specified. See POSIX 1003.1-2001 for this format. */ - message (opt, "Common subdirectories: %s and %s\n", + message ("Common subdirectories: %s and %s\n", cmp.file[0].name, cmp.file[1].name); } else - status = diff_dirs (&cmp, compare_files, opt); + status = diff_dirs (&cmp, compare_files); } else if ((DIR_P (0) | DIR_P (1)) || (parent @@ -1234,18 +1206,18 @@ compare_files (struct comparison const *parent, /* We have a subdirectory that exists only in one directory. */ if ((DIR_P (0) | DIR_P (1)) - && opt->recursive - && (opt->new_file - || (opt->unidirectional_new_file + && recursive + && (new_file + || (unidirectional_new_file && cmp.file[0].desc == NONEXISTENT))) - status = diff_dirs (&cmp, compare_files, opt); + status = diff_dirs (&cmp, compare_files); else { char const *dir = parent->file[cmp.file[0].desc == NONEXISTENT].name; /* See POSIX 1003.1-2001 for this format. */ - message (opt, "Only in %s: %s\n", dir, name0); + message ("Only in %s: %s\n", dir, name0); status = EXIT_FAILURE; } @@ -1255,22 +1227,24 @@ compare_files (struct comparison const *parent, /* We have two files that are not to be compared. */ /* See POSIX 1003.1-2001 for this format. */ - message5 (opt, "File %s is a %s while file %s is a %s\n", - file_label (0, opt), file_type (&cmp.file[0].stat), - file_label (1, opt), file_type (&cmp.file[1].stat)); + message5 ("File %s is a %s while file %s is a %s\n", + file_label[0] ? file_label[0] : cmp.file[0].name, + file_type (&cmp.file[0].stat), + file_label[1] ? file_label[1] : cmp.file[1].name, + file_type (&cmp.file[1].stat)); /* This is a difference. */ status = EXIT_FAILURE; } } - else if (opt->files_can_be_treated_as_binary + else if (files_can_be_treated_as_binary && S_ISREG (cmp.file[0].stat.st_mode) && S_ISREG (cmp.file[1].stat.st_mode) && cmp.file[0].stat.st_size != cmp.file[1].stat.st_size) { - message (opt, "Files %s and %s differ\n", - file_label (0, opt), - file_label (1, opt)); + message ("Files %s and %s differ\n", + file_label[0] ? file_label[0] : cmp.file[0].name, + file_label[1] ? file_label[1] : cmp.file[1].name); status = EXIT_FAILURE; } else @@ -1279,8 +1253,10 @@ compare_files (struct comparison const *parent, /* Open the files and record their descriptors. */ + int oflags = O_RDONLY | (binary ? O_BINARY : 0); + if (cmp.file[0].desc == UNOPENED) - if ((cmp.file[0].desc = open (cmp.file[0].name, O_RDONLY, 0)) < 0) + if ((cmp.file[0].desc = open (cmp.file[0].name, oflags, 0)) < 0) { perror_with_name (cmp.file[0].name); status = EXIT_TROUBLE; @@ -1289,25 +1265,17 @@ compare_files (struct comparison const *parent, { if (same_files) cmp.file[1].desc = cmp.file[0].desc; - else if ((cmp.file[1].desc = open (cmp.file[1].name, O_RDONLY, 0)) - < 0) + else if ((cmp.file[1].desc = open (cmp.file[1].name, oflags, 0)) < 0) { perror_with_name (cmp.file[1].name); status = EXIT_TROUBLE; } } -#if HAVE_SETMODE_DOS - if (binary) - for (f = 0; f < 2; f++) - if (0 <= cmp.file[f].desc) - set_binary_mode (cmp.file[f].desc, true); -#endif - /* Compare the files, if no error was found. */ if (status == EXIT_SUCCESS) - status = diff_2_files (&cmp, opt); + status = diff_2_files (&cmp); /* Close the file descriptors. */ @@ -1329,17 +1297,17 @@ compare_files (struct comparison const *parent, if (status == EXIT_SUCCESS) { - if (opt->report_identical_files && !DIR_P (0)) - message (opt, "Files %s and %s are identical\n", - file_label (0, opt), - file_label (1, opt)); + if (report_identical_files && !DIR_P (0)) + message ("Files %s and %s are identical\n", + file_label[0] ? file_label[0] : cmp.file[0].name, + file_label[1] ? file_label[1] : cmp.file[1].name); } else { /* Flush stdout so that the user sees differences immediately. This can hurt performance, unfortunately. */ if (fflush (stdout) != 0) - pfatal_with_name (_("standard output"), opt); + pfatal_with_name (_("standard output")); } if (free0) diff --git a/src/diff3.c b/src/diff3.c index 261eeab..531c949 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -1,7 +1,7 @@ /* diff3 - compare three files line by line Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1998, 2001, - 2002, 2004 Free Software Foundation, Inc. + 2002, 2004, 2006 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 @@ -31,7 +31,7 @@ #include <file-type.h> #include <getopt.h> #include <inttostr.h> -#include <quotesys.h> +#include <sh-quote.h> #include <version-etc.h> #include <xalloc.h> @@ -1192,14 +1192,14 @@ read_diff (char const *filea, FILE *fpipe; char const args[] = " --horizon-lines=100 -- "; - char *command = xmalloc (quote_system_arg (0, diff_program) + char *command = xmalloc (shell_quote_length (diff_program) + sizeof "-a" + sizeof "--strip-trailing-cr" + sizeof args - 1 - + quote_system_arg (0, filea) + 1 - + quote_system_arg (0, fileb) + 1); + + shell_quote_length (filea) + 1 + + shell_quote_length (fileb) + 1); char *p = command; - p += quote_system_arg (p, diff_program); + p = shell_quote_copy (p, diff_program); if (text) { strcpy (p, " -a"); @@ -1212,9 +1212,9 @@ read_diff (char const *filea, } strcpy (p, args); p += sizeof args - 1; - p += quote_system_arg (p, filea); + p = shell_quote_copy (p, filea); *p++ = ' '; - p += quote_system_arg (p, fileb); + p = shell_quote_copy (p, fileb); *p = 0; errno = 0; fpipe = popen (command, "r"); @@ -1,7 +1,7 @@ /* Read, sort and compare two directories. Used for GNU DIFF. Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1998, 2001, 2002, - 2004 Free Software Foundation, Inc. + 2004, 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -99,7 +99,7 @@ dir_read (struct file_data const *dir, struct dirdata *dirdata) && (d_name[1] == 0 || (d_name[1] == '.' && d_name[2] == 0))) continue; - if (excluded_filename (excluded, d_name)) + if (excluded_file_name (excluded, d_name)) continue; while (data_alloc < data_used + d_size) @@ -1,7 +1,7 @@ /* File I/O for GNU DIFF. Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1998, 2001, 2002, - 2004 Free Software Foundation, Inc. + 2004, 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -23,7 +23,6 @@ #include "diff.h" #include <cmpbuf.h> #include <file-type.h> -#include <setmode.h> #include <xalloc.h> /* Rotate an unsigned value to the left. */ @@ -34,7 +33,7 @@ /* The type of a hash value. */ typedef size_t hash_value; -verify (hash_value_is_unsigned, ! TYPE_SIGNED (hash_value)); +verify (! TYPE_SIGNED (hash_value)); /* Lines are put into equivalence classes of lines that match in lines_differ. Each equivalence class is represented by one of these structures, @@ -114,26 +113,11 @@ sip (struct file_data *current, bool skip_test) { /* Check first part of file to see if it's a binary file. */ - bool was_binary = set_binary_mode (current->desc, true); - off_t buffered; - file_block_read (current, current->bufsize); - buffered = current->buffered; + /* FIXME: if O_BINARY, this should revert to text mode + if the file is not binary. */ - if (! was_binary) - { - /* Revert to text mode and seek back to the beginning to - reread the file. Use relative seek, since file - descriptors like stdin might not start at offset - zero. */ - - if (lseek (current->desc, - buffered, SEEK_CUR) == -1) - pfatal_with_name (current->name); - set_binary_mode (current->desc, false); - current->buffered = 0; - current->eof = false; - } - - return binary_file_p (current->buffer, buffered); + file_block_read (current, current->bufsize); + return binary_file_p (current->buffer, current->buffered); } } @@ -796,8 +780,7 @@ static unsigned char const prime_offset[] = /* Verify that this host's size_t is not too wide for the above table. */ -verify (enough_prime_offsets, - sizeof (size_t) * CHAR_BIT <= sizeof prime_offset); +verify (sizeof (size_t) * CHAR_BIT <= sizeof prime_offset); /* Given a vector of two file_data objects, read the file associated with each one, and build the table of equivalence classes. @@ -821,8 +804,7 @@ read_files (struct file_data filevec[], bool pretend_binary) } if (appears_binary) { - set_binary_mode (filevec[0].desc, true); - set_binary_mode (filevec[1].desc, true); + /* FIXME: If O_BINARY, this should set both files to binary mode. */ return true; } diff --git a/src/sdiff.c b/src/sdiff.c index 2b0a2ae..f0d39a2 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -1,7 +1,7 @@ /* sdiff - side-by-side merge of file differences - Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 2001, 2002, 2004 - Free Software Foundation, Inc. + Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 2001, 2002, 2004, + 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -33,7 +33,7 @@ #include <exitfail.h> #include <file-type.h> #include <getopt.h> -#include <quotesys.h> +#include <sh-quote.h> #include <version-etc.h> #include <xalloc.h> @@ -614,11 +614,11 @@ main (int argc, char *argv[]) int i; for (i = 0; diffargv[i]; i++) - cmdsize += quote_system_arg (0, diffargv[i]) + 1; + cmdsize += shell_quote_length (diffargv[i]) + 1; command = p = xmalloc (cmdsize); for (i = 0; diffargv[i]; i++) { - p += quote_system_arg (p, diffargv[i]); + p = shell_quote_copy (diffargv[i]); *p++ = ' '; } p[-1] = 0; @@ -1056,9 +1056,9 @@ edit (struct line_filter *left, char const *lname, lin lline, lin llen, { #if ! (HAVE_WORKING_FORK || HAVE_WORKING_VFORK) char *command = - xmalloc (quote_system_arg (0, editor_program) + xmalloc (shell_quote_length (editor_program) + 1 + strlen (tmpname) + 1); - sprintf (command + quote_system_arg (command, editor_program), + sprintf (shell_quote_copy (command, editor_program), " %s", tmpname); wstatus = system (command); if (wstatus == -1) diff --git a/src/system.h b/src/system.h index e480cc5..bf0da79 100644 --- a/src/system.h +++ b/src/system.h @@ -1,7 +1,7 @@ /* System dependent declarations. Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1998, 2001, 2002, - 2004 Free Software Foundation, Inc. + 2004, 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -37,26 +37,7 @@ # define volatile #endif -/* Verify a requirement at compile-time (unlike assert, which is runtime). */ -#define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; } - - -/* Determine whether an integer type is signed, and its bounds. - This code assumes two's (or one's!) complement with no holes. */ - -/* The extra casts work around common compiler bugs, - e.g. Cray C 5.0.3.0 when t == time_t. */ -#ifndef TYPE_SIGNED -# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) -#endif -#ifndef TYPE_MINIMUM -# define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \ - ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \ - : (t) 0)) -#endif -#ifndef TYPE_MAXIMUM -# define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t))) -#endif +#include <verify.h> #include <sys/types.h> #include <sys/stat.h> @@ -119,6 +100,22 @@ # define S_IWUSR 0200 #endif +/* For systems that distinguish between text and binary I/O. + O_BINARY is usually declared in fcntl.h */ +#if !defined O_BINARY && defined _O_BINARY + /* For MSC-compatible compilers. */ +# define O_BINARY _O_BINARY +#endif + +#ifdef __BEOS__ + /* BeOS 5 has O_BINARY, but it has no effect. */ +# undef O_BINARY +#endif + +#ifndef O_BINARY +# define O_BINARY 0 +#endif + #if HAVE_SYS_WAIT_H # include <sys/wait.h> #endif @@ -240,6 +237,8 @@ int strcasecmp (char const *, char const *); # define vfork fork #endif +#include <intprops.h> + /* Type used for fast comparison of several bytes at a time. */ #ifndef word @@ -251,9 +250,9 @@ int strcasecmp (char const *, char const *); typedef ptrdiff_t lin; #define LIN_MAX PTRDIFF_MAX -verify (lin_is_signed, TYPE_SIGNED (lin)); -verify (lin_is_wide_enough, sizeof (ptrdiff_t) <= sizeof (lin)); -verify (lin_is_printable_as_long_int, sizeof (lin) <= sizeof (long int)); +verify (TYPE_SIGNED (lin)); +verify (sizeof (ptrdiff_t) <= sizeof (lin)); +verify (sizeof (lin) <= sizeof (long int)); /* This section contains POSIX-compliant defaults for macros that are meant to be overridden by hand in config.h as needed. */ @@ -1,7 +1,7 @@ /* Support routines for GNU DIFF. Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1998, 2001, 2002, - 2004 Free Software Foundation, Inc. + 2004, 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -23,7 +23,7 @@ #include "diff.h" #include <dirname.h> #include <error.h> -#include <quotesys.h> +#include <sh-quote.h> #include <xalloc.h> char const pr_program[] = PR_PROGRAM; @@ -226,11 +226,11 @@ begin_output (void) } #else char *command = xmalloc (sizeof pr_program - 1 + 7 - + quote_system_arg ((char *) 0, name) + 1); + + shell_quote_length (name) + 1); char *p; sprintf (command, "%s -f -h ", pr_program); p = command + sizeof pr_program - 1 + 7; - p += quote_system_arg (p, name); + p = shell_quote_copy (name); *p = 0; errno = 0; outfile = popen (command, "w"); |