summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2009-03-15 15:53:23 +0100
committerAndreas Gruenbacher <agruen@suse.de>2009-03-19 20:42:57 +0100
commit11374a026a0229a32d3d7d6e88aaa0f381a7a9c3 (patch)
tree5e4f824227608f2b848f0102f40a56b43953f199
parent65f7c26e8ae7016b967aad7cad42ec0e4e81d3e0 (diff)
downloadpatch-rcs-history.tar.gz
Previous work in progressrcs-history
-rw-r--r--COPYING340
-rw-r--r--ChangeLog2380
-rw-r--r--INSTALL228
-rw-r--r--Makefile.in14
-rw-r--r--NEWS11
-rw-r--r--README2
-rw-r--r--addext.c74
-rw-r--r--argmatch.c280
-rw-r--r--argmatch.h115
-rw-r--r--backupfile.c126
-rw-r--r--backupfile.h32
-rw-r--r--basename.c8
-rw-r--r--common.h43
-rw-r--r--configure.ac26
-rw-r--r--dirname.c119
-rw-r--r--dirname.h43
-rw-r--r--error.c298
-rw-r--r--error.h70
-rw-r--r--exitfail.c29
-rw-r--r--exitfail.h20
-rw-r--r--getopt.c1209
-rw-r--r--getopt.h169
-rw-r--r--getopt1.c185
-rw-r--r--gettext.h68
-rw-r--r--hash.c1035
-rw-r--r--hash.h87
-rw-r--r--inp.c14
-rw-r--r--inp.h4
-rwxr-xr-xinstall-sh286
-rw-r--r--m4/backupfile.m421
-rw-r--r--m4/d-ino.m442
-rw-r--r--m4/dirname.m415
-rw-r--r--m4/dos.m453
-rw-r--r--m4/error.m415
-rw-r--r--m4/exitfail.m413
-rw-r--r--m4/extensions.m415
-rw-r--r--m4/getopt.m413
-rw-r--r--m4/hash.m413
-rw-r--r--m4/malloc.m425
-rw-r--r--m4/mbrtowc.m427
-rw-r--r--m4/mbstate_t.m432
-rw-r--r--m4/memchr.m420
-rw-r--r--m4/mkdir.m48
-rw-r--r--m4/onceonly.m463
-rw-r--r--m4/quote.m413
-rw-r--r--m4/quotearg.m416
-rw-r--r--m4/realloc.m425
-rw-r--r--m4/setmode.m438
-rw-r--r--m4/st_mtim.m432
-rw-r--r--m4/stdbool.m489
-rw-r--r--m4/strcase.m439
-rw-r--r--m4/timespec.m452
-rw-r--r--m4/unlocked-io.m422
-rw-r--r--m4/utimbuf.m440
-rw-r--r--m4/xalloc.m425
-rw-r--r--maketime.c82
-rw-r--r--maketime.h22
-rw-r--r--malloc.c11
-rw-r--r--memchr.c200
-rwxr-xr-xmkinstalldirs124
-rw-r--r--partime.c95
-rw-r--r--partime.h18
-rw-r--r--patch.c89
-rw-r--r--patch.man14
-rw-r--r--pch.c48
-rw-r--r--pch.h4
-rw-r--r--quote.c41
-rw-r--r--quote.h22
-rw-r--r--quotearg.c589
-rw-r--r--quotearg.h75
-rw-r--r--quotesys.c125
-rw-r--r--quotesys.h9
-rw-r--r--realloc.c13
-rw-r--r--stdbool_.h92
-rw-r--r--strcasecmp.c66
-rw-r--r--strncasecmp.c2
-rw-r--r--timespec.h60
-rw-r--r--unlocked-io.h89
-rw-r--r--util.c37
-rw-r--r--util.h4
-rw-r--r--xalloc.h89
-rw-r--r--xmalloc.c83
82 files changed, 9495 insertions, 689 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..f90922e
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..5e91386
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,2380 @@
+ * Makefile.in (SRCS): Move hash.c here from LIBSRCS.
+ (exitfail.$(OBJEXT), patch.$(OBJEXT), xmalloc.$(OBJEXT)):
+ Depend on exitfail.h.
+ (util.$(OBJEXT)): Depend on hash.h, timespec.h.
+ * util.c: Whitespace cleanup in file_id.
+
+2004-07-19 Stepan Kasal <kasal@ucw.cz>
+
+ * pch.c (get_ed_command_letter): Allow commands without address.
+
+2003-11-10 Manu B <manubee@users.sourceforge.net>
+
+ Trivial change to port to mingw, which declares mkdir in unistd.h.
+ * m4/mkdir.m4 (PATCH_FUNC_MKDIR_TAKES_ONE_ARG): Include unistd.h.
+ * common.h (mkdir): Define after including unistd.h.
+
+2003-09-11 Paul Eggert <eggert@twinsun.com>
+
+ * Makefile.in (STDBOOL_H): New macro. All uses of @STDBOOL_H@ changed.
+ (SRCS): Add exitfail.c.
+ (OBJS): Add exitfail.$(OBJEXT).
+ (HDRS): Add exitfail.h.
+ (stdbool.h): Use $@, as gnulib now suggests.
+ (ACINCLUDE_INPUTS): Add exitfail.m4, extensions.m4.
+ * common.h: Include <string.h>, <stdlib.h> unconditionally.
+ * configure.ac (gl_USE_SYSTEM_EXTENSIONS): Use this instead
+ of AC_GNU_SOURCE.
+ (gl_EXITFAIL): Add.
+ * patch.c: Include exitfail.h.
+ (main): Set exit_failure, not xalloc_exit_failure.
+
+ * inp.c (get_input_file): Clear cs if dry run.
+
+ * util.c (fetchname): Handle missing timestamps better.
+
+ * Makefile.in (LIBSRCS): Add hash.c.
+ (OBJS): Add hash.$(OBJEXT).
+ (HDRS): Add hash.h.
+ (MISC): Add timespec.h.
+ (ACINCLUDE_INPUTS): Add hash.m4, st_mtim.m4, timespec.m4
+ (util.$(OBJEXT): Depend on timespec.h.
+ * configure.ac (gl_HASH, gl_TIMESPEC): Add.
+ * patch.c (spew_output): New output arg, to contain status of output
+ file.
+ (main): Use it to get status of output file, and pass this to
+ move_file as needed. Initialize hash table.
+ * util.c (file_id): New type.
+ (file_id_hasher, file_id_comparator, init_backup_hash_table,
+ insert_file, file_already_seen): New functions.
+ (file_id_table): New var.
+ (move_file): New arg FROMST; all uses changed.
+ Do not backup a file that's already been patched.
+ Keep track of files that have been patched.
+ (copy_file): New arg TOST; all uses changed.
+ * util.h (copy_file, move_file): Adjust decls as per above.
+ (init_backup_hash_table): New decl.
+
+2003-07-05 Paul Eggert <eggert@twinsun.com>
+
+ * Makefile.in (check): Add a trivial check that "patch --help" works.
+ From a suggestion by Ed Avis.
+
+2003-07-02 Paul Eggert <eggert@twinsun.com>
+
+ * pch.c (intuit_diff_type): If a unified-diff header line contains
+ trailing CR, strip CR from each body line. This corrects a bug
+ introduced in the 2003-05-18 patch. Bug reported by Andreas
+ Gruenbacher.
+
+ * mkdir.c, rmdir.c, m4/rmdir.m4: Remove; we no longer
+ need to worry about ancient hosts that lack these functions.
+
+ * addext.c, backupfile.c, backupfile.h, dirname.h, m4/backupfile.m4,
+ m4/onceonly.m4, m4/quote.m4, malloc.c, quote,c, quote.h, realloc.c,
+ strcasecmp.c, xalloc.h, xmalloc.c: Sync with gnulib.
+ * stdbool_.h: Renamed from stdbool.h.in; all uses changed.
+ This renaming is imported from gnulib.
+ * m4/strcase.m4: New file, imported from gnulib.
+
+ * Makefile.in (LIBSRCS): Remove mkdir.c and rmdir.c.
+ (stdbool.h): Put output into temporary file and then rename it;
+ this change is imported from gnulib.
+ (mostlyclean): Clean stdbool.h-t too.
+ (ACINCLUDE_INPUTS): Remove rmdir.m4. Add strcase.m4.
+ * configure.ac (gl_FUNC_RMDIR): Remove.
+ (jm_PREREQ_ADDEXT): Remove; now down by gl_BACKUPFILE.
+ (gl_STRCASE, gl_XALLOC): Add.
+ (AC_REPLACE_FUNCS): Remove mkdir, strcasecmp.
+
+2003-05-20 Paul Eggert <eggert@twinsun.com>
+
+ * NEWS, configure.ac (AC_INIT): Version 2.5.9 released.
+
+ * Makefile.in (HDRS): Add gettext.h.
+
+ Use bool, not int, for booleans.
+
+ * pch.c (pch_says_nonexistent): Returns int, not bool.
+
+ * configure.ac: Add AM_STDBOOL_H.
+
+ * Makefile.in (MISC): Add stdbool.h.in.
+ (stdbool.h): New rule.
+ (ACINCLUDE_INPUTS): Add stdbool.m4.
+ (mostlyclean): Remove stdbool.h.
+ (COMMON): New macro; use it instead of common.h for dependencies.
+
+ * common.h: Include <stdbool.h>.
+ Remove TRUE, FALSE, bool. All uses changed to standard names.
+
+ * common.h (reverse, set_time, set_utc):
+ Use bool, not int, for booleans.
+ * pch.c (p_strip_trailing_cr, p_pass_comments_through,
+ prefix_components, pget_line, re_patch,
+ there_is_another_patch, intuit_diff_type, scan_linenum,
+ another_hunk, pget_line, pch_timestamp): Likewise.
+ * inp.h (ifetch): Likewise.
+ * util.c (move_file, version_controller, version_get, ok_to_reverse,
+ set_signals): Likewise.
+ * inp.c (report_revision, get_input_file, plan_a, plan_b, ifetch):
+ Likewise.
+ * util.h (ok_to_reverse, version_controller, version_get,
+ move_file, set_signals): Likewise.
+ * pch.h (another_hunk, pch_says_nonexistent, pch_timestamp):
+ Likewise.
+ * patch.c (struct outstate, numeric_string, make_backups,
+ backup_if_mismatch, remove_empty_files,
+ reverse_flag_specified, main, reinitialize_almost_everything,
+ get_some_switches, apply_hunk, init_output, copy_till):
+ Likewise.
+
+2003-05-18 Paul Eggert <eggert@twinsun.com>
+
+ * pch.c (p_pass_comments_through): New var.
+ (pget_line): Accept new arg for pass_comments_through.
+ All callers changed.
+ (there_is_another_patch): Do not suggest -p for ed diffs.
+ (intuit_diff_type): Check ed command for correct syntax.
+ Do not set p_strip_trailing_cr merely because a -p line contains a CR.
+ (get_ed_command_letter): New function.
+ (do_ed_script): Use it. Do not treat '#' data lines as comments in ed
+ scripts.
+
+ * util.c (move_file):
+ Don't assume that when 'rename(A,B)' succeeds then A no
+ longer exists. This is not true of POSIX 1003.1-2001 rename when A
+ and B are links to the same file.
+ (fetchname): Fix test for file names with internal spaces.
+
+ * version.c: Don't include patchlevel.h.
+ (version): Use PACKAGE_NAME and PACKAGE_VERSION instead of obsolete
+ PROGRAM_NAME and PATCH_VERSION.
+ (copyright_string): Bump to 2003.
+
+ * common.h (FILESYSTEM_PREFIX_LEN, ISSLASH):
+ Remove; now done by 'configure'.
+ (PROGRAM_NAME): Remove; now done by 'configure' as PACKAGE_NAME.
+
+ * patch.c: Do not include <exitfail.h>.
+ (main): Set xalloc_exit_failure, not exit_failure.
+ Add "&& !skip_rest_of_patch" when deciding to continue ed scripts.
+ (option_help): Use PACKAGE_BUGREPORT rather than hardcoding.
+
+ * configure.ac (AC_PREREQ): Bump to 2.57.
+ (AC_GNU_SOURCE): Add, early on.
+ (gl_BACKUPFILE, gl_DIRNAME, gl_ERROR, gl_FUNC_MEMCHR, gl_FUNC_RMDIR,
+ gl_GETOPT, gl_PREREQ_XMALLOC, gl_QUOTE, gl_QUOTEARG): Add.
+ (jm_PREREQ_ADDEXT): Add, with definition.
+ (jm_PREREQ_DIRNAME, jm_PREREQ_ERROR, jm_PREREQ_MEMCHR,
+ jm_PREREQ_QUOTEARG): Remove.
+ (AC_REPLACE_FUNCS): Remove memchr, rename, rmdir).
+ (jm_FUNC_GLIBC_UNLOCKED_IO, jm_AC_DOS): Add.
+ (jm_CHECK_TYPE_STRUCT_DIRENT_D_INO): Do not call directly.
+ (AC_OUTPUT): Use new style, with AC_CONFIG_FILES.
+
+ Update to current CVS gnulib.
+
+ * exitfail.c, exitfail.h, patchlevel.h, rename.c, m4/c-bs-a.m4,
+ m4/jm-glibc-io.m4, m4/prereq.m4: Remove.
+ * m4/backupfile.m4, m4/dirname.m4, m4/dos.m4, m4/getopt.m4,
+ m4/memchr.m4, m4/onceonly.m4, m4/quote.m4, m4/quotearg.m4,
+ m4/rmdir.m4, m4/unlocked-io.m4, m4/xalloc.m4: New files.
+ * Makefile.in (LIBSRCS): Move error.c here from SRCS.
+ Remove rename.c.
+ (OBJS): Remove error.$(OBJEXT).
+ (HDRS): Remove exitfail.h, patchlevel.h.
+ (ACINCLUDE_INPUTS): Remove c-bs-a.m4, jm-glibc-io.m4, prereq.m4.
+ Add backupfile.m4, dirname.m4, dos.m4, getopt.m4, memchr.m4,
+ onceonly.m4, quote.m4, quotearg.m4, rmdir.m4, unlocked-io.m4,
+ xalloc.m4.
+ (patchlevel.h): Remove. All uses removed.
+ (argmatch.$(OBJEXT), error.$(OBJEXT), quotesys.$(OBJEXT)),
+ xmalloc.$(OBJEXT)): Depend on gettext.h.
+ (dirname.$(OBJEXT), quote.$(OBJEXT), strncasecmp.$(OBJEXT)): New rules.
+ (patch.$(OBJEXT), xmalloc.$(OBJEXT)): Remove exitfail.h.
+ (rename.$(OBJEXT)): Remove.
+ (version.$(OBJEXT)): Remove util.h.
+ (xmalloc.$(OBJEXT)): Add error.h.
+
+2002-11-23 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (main): Don't check for zero-sized file after 'ed'
+ when skipping patch. From Michael Fedrowitz.
+
+2002-06-03 Paul Eggert <eggert@twinsun.com>
+
+ * configure.ac (AC_OUTPUT): Use new form, with AC_CONFIG_FILES,
+ instead of obsolescent form. Patch from Art Haas.
+
+ * pch.c (intuit_diff_type): Do not warn about trailing white space
+ after Prereq: word. Bug reported by Mike Castle.
+
+2002-06-02 Paul Eggert <eggert@twinsun.com>
+
+ * NEWS, configure.ac (AC_INIT): Version 2.5.8 released.
+
+ * README: POSIX.2 -> POSIX.
+ * inp.c (report_revision): Don't modify 'revision', since
+ it gets freed later. Bug reported by Mike Castle.
+
+2002-05-30 Paul Eggert <eggert@twinsun.com>
+
+ * NEWS, configure.ac (AC_INIT): Version 2.5.7 released.
+
+ * Makefile.in (MISC): Remove README-alpha.
+ (patchlevel.h): Depend on configure, not configure.ac.
+
+ * INSTALL: Upgrade to Autoconf 2.53 version.
+
+2002-05-28 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (end_defined, apply_hunk): Output #endif without
+ the comment, as POSIX 1003.1-2001 requires.
+
+ * pch.c (there_is_another_patch): Flush stderr after perror.
+
+ * NEWS, configure.ac (AC_INIT): Version 2.5.6 released.
+
+ * strcasecmp.c, strncasecmp.c: New files, taken from fileutils.
+ * config.guess, config.sub: Remove.
+ * Makefile.in (LIBSRCS): Add strcasecmp.c, strncasecmp.c.
+ (MISC): Remove config.guess, config.sub.
+
+ The code already assumes C89 or better, so remove K&R stuff.
+ * common.h (volatile): Remove.
+ (GENERIC_OBJECT): Remove; all uses changed to 'void'.
+ (PARAMS): Remove; all uses changed to prototypes.
+ * configure.ac (AC_PROG_CC_STDC): Add.
+ * util.c (vararg_start): Remove. All uses changed to va_start.
+ Always include <stdarg.h>.
+
+ * configure.ac (AC_CANONICAL_HOST): Remove.
+ (AC_REPLACE_FUNCS): Add strncasecmp.
+ (AC_CHECK_DECLS): Add mktemp.
+
+ * patch.c (main): Remove useless prototype decl.
+ (mktemp): Don't declare if HAVE_DECL_MKTEMP || defined mktemp.
+ (make_temp): Now accepts char, not int.
+
+2002-05-26 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (not_defined): Prepend newline. All uses changed.
+ (apply_hunk): Fix bug: -D was outputting #ifdef when it should
+ have been outputting #ifndef. Bug report and partial fix by
+ Jason Short.
+
+ * pch.c (intuit_diff_type): When reading an ed diff, don't use
+ indent and trailing-CR-ness of "." line; instead, use that of the
+ command. Bug reported by Anthony Towns; partial fix by Michael
+ Fedrowitz.
+ (intuit_diff_type): If the index line exists, don't report a
+ missing header. Fix by Chip Salzenberg.
+
+2002-05-26 Alessandro Rubini <rubini@gnu.org>
+
+ * patch.c (locate_hunk): Fixed updating of last_offset.
+
+2002-05-25 Paul Eggert <eggert@twinsun.com>
+
+ * NEWS, README: Diffutils doc is up to date now.
+ Bug reporting address is now <bug-patch@gnu.org>.
+ * README: Describe '--disable-largefile'.
+
+ * NEWS-alpha, dirname.c, dirname.h, exitfail.c, exitfail.h,
+ quote.c, quote.h, unlocked-io.h: New files, taken from diffutils
+ and fileutils.
+
+ * argmatch.c: [STDC_HEADERS]: Include stdlib.h, for 'exit'.
+
+ * addext.c, argmatch.c, argmatch.h, backupfile.c, basename.c:
+ Update from diffutils and fileutils.
+
+ * ansi2knr.1, ansi2knr.c: Remove.
+
+ * common.h: HAVE_SETMODE && O_BINARY -> HAVE_SETMODE_DOS.
+ * patch.c (usage): Likewise.
+ * pch.c (open_patch_file): Likewise.
+
+ * configure.ac: Renamed from configure.in. Add copyright notice.
+ (AC_PREREQ): Bump to 2.53.
+ (AC_INIT): Use 2.5x style.
+ (AC_CONFIG_SRCDIR): Add.
+ (PACKAGE, VERSION): Remove.
+ (AC_C_PROTOTYPES): Use this instead of AM_C_PROTOTYPES.
+ (jm_CHECK_TYPE_STRUCT_UTIMBUF): Use this instead of jm_STRUCT_UTIMBUF.
+ (jm_PREREQ_ADDEXT, jm_PREREQ_DIRNAME, jm_PREREQ_ERROR,
+ jm_PREREQ_MEMCHR, jm_PREREQ_QUOTEARG): Add.
+ (AC_CHECK_DECLS): Add free, getenv, malloc.
+ (AC_CHECK_FUNCS): Remove setmode.
+ (AC_FUNC_SETMODE_DOS): Add.
+ (jm_CHECK_TYPE_STRUCT_DIRENT_D_INO): Use this instead of
+ jm_STRUCT_DIRENT_D_INO.
+
+ * Makefile.in (OBJEXT): New var.
+ (PACKAGE_NAME): Renamed from PACKAGE. All uses changed.
+ (PACKAGE_VERSION): Renamed from VERSION. All uses changed.
+ (U): Remove. All uses of "$U.o" changed to ".$(OBJEXT)".
+ (LIBSRCS): REmove getopt.c getopt1.c. Add mkdir.c, rmdir.c.
+ (SRCS): Add dirname.c, exitfail.c, getopt.c, getopt1.c, quote.c.
+ Remove mkdir.c.
+ (OBJS): Keep in sync with SRCS.
+ (HDRS): Remove basename.h.
+ Add dirname.h, exitfail.h, quote.h, unlocked-io.h.
+ (MISC, configure, config.hin, patchlevel.h):
+ configure.ac renamed from configure.in.
+ (MISC): Add README-alpha. Remove ansi2knr.1, ansi2knr.c.
+ (.c.$(OBJEXT)): Renamed from .c.o.
+ (ACINCLUDE_INPUTS): Add c-bs-a.m4, error.m4, jm-glibc-io.m4,
+ mbstate_t.m4, mkdir.m4, mbrtowc.m4, prereq.m4, setmode.m4.
+ Remove ccstdc.m4, inttypes_h.m4, largefile.m4, protos.m4.
+ (mostlyclean): Don't clean ansi2knr.
+ (ansi2knr.o, ansi2knr): Remove.
+ Redo dependencies.
+
+ * patch.c: Include <exitfail.h>.
+ (main): Initialize exit_failure.
+
+ * patch.man: Update copyright notice.
+
+ * pch.c, util.c: Include <dirname.h>, not <basename.h>.
+
+ * version.c (copyright_string): Update copyright notice.
+
+2002-02-17 Paul Eggert <eggert@twinsun.com>
+
+ * partime.c (parse_pattern_letter): Don't overrun buffer if it
+ contains only alphanumerics. Bug reported by Winni
+ <Winni470@gmx.net>.
+
+2001-07-28 Paul Eggert <eggert@sic.twinsun.com>
+
+ * util.c (fetchname), NEWS:
+ Allow file names with internal spaces, so long as they
+ don't contain tabs.
+
+ * pch.c (intuit_diff_type): Do not allow Prereq with multiple words.
+
+ * configure.in (AC_PREREQ): Bump to 2.50.
+ (AC_CHECK_FUNCS): Remove fseeko.
+ (AC_FUNC_FSEEKO): Add.
+ * Makefile.in (ACINCLUDE_INPUTS):
+ Remove largefile.m4; no longer needed with Autoconf 2.50.
+
+2001-02-07 "Tony E. Bennett" <tbennett@nvidia.com>
+
+ * util.c (PERFORCE_CO): New var.
+ (version_controller): Support Perforce.
+ * patch.man: Document this.
+
+2000-06-30 Paul Eggert <eggert@sic.twinsun.com>
+
+ * patch.man: Ignore comment lines.
+
+ * NEWS, pch.c: Ignore lines beginning with "#".
+
+1999-10-24 Paul Eggert <eggert@twinsun.com>
+
+ * pch.c (another_hunk): Report a fatal error if a regular
+ context hunk's pattern has a different number of unchanged
+ lines than the replacement.
+
+1999-10-18 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (main): If we skipped an ed patch, exit with nonzero status.
+
+1999-10-17 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (main): Apply do_ed_script even if dry_run, because
+ we need to make progress on the patch file.
+ * pch.c (do_ed_script): If skip_rest_of_patch is nonzero,
+ gobble up the patch without any other side effect.
+
+1999-10-12 Paul Eggert <eggert@twinsun.com>
+
+ * NEWS, README: New bug reporting address.
+ * NEWS: Report change in 2.5.4 that we forgot to document.
+ * README: Document `configure --disable-largefile'.
+
+ * basename.c, COPYING, getopt.c, getopt.h, getopt1.c, m4/largefile.m4:
+ Update to latest version.
+ * Makefile.in (basename$U.o): Depend on basename.h.
+ (config.hin): Depend on $(srcdir)/aclocal.m4.
+
+ * ansi2knr.c, maketime.c, mkinstalldirs, partime.c: Fix $Id.
+
+ FreeBSD has an unrelated setmode function; work around this.
+ * common.h (binary_transput): Don't declare unless O_BINARY.
+ * patch.c (option_help, get_some_switches):
+ Don't use setmode unless O_BINARY.
+ * pch.c (open_patch_file): Don't invoke setmode unless O_BINARY.
+
+ Fix incompatiblities with error.c.
+ * common.h (program_name): Now XTERN char *, for compatibility
+ with error.c. All uses changed.
+ (PROGRAM_NAME): New macro.
+ (PARAMS): Use ANSI C version only if defined PROTOTYPES
+ || (defined __STDC__ && __STDC__), for compatibilty with error.c.
+ * util.c (vararg_start): Likewise.
+ * patch.c (program_name): Remove.
+ (main): Initialize program_name.
+ * version.c (version): Print PROGRAM_NAME, not program_name.
+
+ Accommodate mingw32 port, which has one-argument mkdir (yuck!)
+ and no geteuid.
+ * m4/mkdir.m4: New file.
+ * Makefile.in (ACINCLUDE_INPUTS): Add $(M4DIR)/mkdir.m4.
+ * configure.in (AC_CHECK_FUNCS): Add geteuid, getuid.
+ (PATCH_FUNC_MKDIR_TAKES_ONE_ARG): Add.
+ * common.h (mkdir): Define if mkdir takes one arg.
+ (geteuid): New macro, if not already defined.
+
+1999-10-11 Christopher R. Gabriel <cgabriel@tin.it>
+
+ * patch.c (option_help): Updated bug report address
+ * configure.in (VERSION): Version 2.5.5 released.
+
+1999-09-01 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (main): Default simple_backup_suffix to ".orig".
+
+1999-10-08 Paul Eggert <eggert@twinsun.com>
+
+ * patch.man: Make it clear that `patch -o F' should not be
+ used if F is one of the files to be patched.
+
+1999-08-30 Paul Eggert <eggert@twinsun.com>
+
+ Version 2.5.4 fixes a few minor bugs, converts C sources to
+ ANSI prototypes, and modernizes auxiliary sources and autoconf
+ scripts.
+
+ * configure.in (VERSION): Version 2.5.4 released.
+ (AC_CANONICAL_HOST): Add.
+ (AC_SYS_LARGEFILE): Add, replacing inline code.
+ (AC_EXEEXT): Add.
+ (jm_AC_HEADER_INTTYPES_H): Add, replacing inline code.
+ (AC_TYPE_PID_T): Add.
+ (jm_STRUCT_UTIMBUF): Add, replacing inline code.
+ (HAVE_MEMCHR): Remove obsolescent test; nobody uses NetBSD 1.0 now.
+ (getopt_long): Append $U to object file basenames.
+ (AC_CHECK_FUNCS): Add fseeko, setmode. Remove mkdir.
+ (AC_REPLACE_FUNCS): Add mkdir, rmdir.
+ (jm_STRUCT_DIRENT_D_INO): Add, replacing inline code.
+
+ * Makefile.in (EXEEXT): New macro.
+ (mandir): New macro.
+ (man1dir): Define in terms of mandir.
+ (SRCS): Add mkdir.c, rmdir.c.
+ (OBJS): Change .o to $U.o for addext, argmatch, backupfile, basename,
+ error, inp, patch ,,pch, quotearg, util, version, xmalloc.
+ (HDRS): Add basename.h, patchlevel.h.
+ (MISC): Add ansi2knr.1, config.guess, config.sub.
+ (MISC, config.hin): Remove acconfig.h; no longer needed.
+ (DISTFILES_M4): New macro.
+ (all): patch -> patch$(EXEEXT).
+ (patch$(EXEEXT)): Renamed from patch. All uses changed.
+ (uninstall): Remove manual page.
+ (configure): Depend on aclocal.m4.
+ (M4DIR, ACINCLUDE_INPUTS): New macros.
+ ($(srcdir)/aclocal.m4): New rule.
+ (patchlevel.h): Depend on configure.in, not Makefile,
+ since we now distribute it.
+ (distclean): Don't remove patchlevel.h.
+ (dist): Distribute $(DISTFILES_M4).
+ (addext_.c argmatch_.c backupfile_.c basename_.c error_.c
+ getopt_.c getopt1_.c inp_.c malloc_.c mkdir_.c patch_.c pch_.c
+ rename_.c util_.c version_.c xmalloc_.c): Depend on ansi2knr.
+ Update dependencies to match sources.
+
+ * common.h (_LARGEFILE_SOURCE): Remove; now autoconfigured.
+ (file_offset): Depend on HAVE_FSEEKO, not _LFS_LARGEFILE.
+
+ * patch.c (version_control_context): New variable.
+ Convert to ANSI prototypes.
+ Adjust to new argmatch calling convention.
+ Similarly for get_version.
+ Complain about creating an existing file only if
+ pch_says_nonexistent returns 2 (not merely nonzero).
+ Similarly for time mismatch check.
+ (get_some_switches): Adjust to new get_version calling convention.
+ Similarly for argmatch.
+
+ * pch.c (<basename.h>): Include.
+ (intuit_diff_type): Improve quality of test for empty file.
+ (another_hunk): Don't assume off_t is no longer than long.
+
+ * util.h (backup_type): New decl.
+ * util.c (<basename.h>): Include.
+ (move_file): Adjust to new find_backup_file_name convention.
+ (doprogram, mkdir, rmdir): Remove; now in separate files.
+ (fetchame): Match "/dev/null", not NULL_DEVICE.
+ Ignore names that don't have enough slashes to strip off.
+
+ * version.c: Update copyright notice.
+
+1998-03-20 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.5.3.
+ * quotearg.h (quotearg_quoting_options):
+ Remove; it ran afoul of the Borland C compiler.
+ Its address is now represented by the null pointer.
+ * quotearg.c (default_quoting_options):
+ Renamed from quotearg_quoting_options,
+ and now static instead of extern.
+ (clone_quoting_options, get_quoting_style, set_quoting_style,
+ set_char_quoting, quotearg_buffer):
+ Use default_quoting_options when passed a null pointer.
+ * patch.c (main, get_some_switches):
+ Pass a null pointer instead of address of quotearg_quoting_options.
+
+1998-03-17 Paul Eggert <eggert@twinsun.com>
+
+ * patch.c (option_help): Update bug reporting address to gnu.org.
+ * patch.man: Fix copyright and bug reporting address.
+
+1998-03-16 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.5.2.
+ (AC_CHECK_FUNCS): Add strerror.
+ (jm_FUNC_MALLOC, jm_FUNC_REALLOC): Add.
+ (AM_C_PROTOTYPES): Add.
+
+ * NEWS, patch.c (longopts, get_some_switches), patch.man:
+ Add --quoting-style, --posix options.
+
+ * Makefile.in (LIBSRCS): Add malloc.c, realloc.c.
+ (SRCS): Add error.c, quotesys.c, xmalloc.c.
+ (OBJS): Likewise.
+ (HDRS): Add error.h, quotesys.h, xalloc.h.
+ (MISC): Add AUTHORS, aclocal.m4, ansi2knr.c.
+ (clean): Use mostlyclean rule.
+ (argmatch.o, inp.o, patch.o, pch.o): Now also depends on quotearg.h.
+ (inp.o, patch.o, util.o): Now also depends on xalloc.h.
+ (error.o, quotearg.o, quotesys.o, xmalloc.o,
+ ansi2knr.o, ansi2knr, quotearg_.c, .c_.c): New rules.
+ (U): New macro.
+ (OBJS, quotearg$U.o): Rename quotearg.o to quotearg$U.o.
+ (mostlyclean): Remove ansi2knr, *_.c.
+ (.SUFFIXES): Add _.c.
+
+ * acconfig.h (PROTOTYPES): New undef.
+
+ * acconfig.h, configure.in (HAVE_INTTYPES_H, malloc, realloc):
+ New macros.
+
+ * aclocal.m4, error.c, error.h, malloc.c,
+ quotearg.h, quotearg.c, realloc.c, xalloc.h, xmalloc.c: New files.
+
+ * argmatch.c: Include <sys/types.h> before <argmatch.h>.
+ Include <quotearg.h>.
+
+ * argmatch.c (invalid_arg),
+ inp.c (scan_input, report_revision, too_many_lines, get_input_file,
+ plan_a),
+ patch.c (main, get_some_switches, numeric_string),
+ pch.c (open_patch_file, intuit_diff_type, do_ed_script):
+ util.c (move_file, create_file, copy_file, version_get, removedirs):
+ Quote output operands properly.
+
+ * common.h: Include <inttypes.h> if available.
+ (CHAR_BIT, TYPE_SIGNED, TYPE_MINIMUM, TYPE_MAXIMUM,
+ CHAR_MAX, INT_MAX, LONG_MIN, SIZE_MAX, O_EXCL): New macros.
+ (TMPINNAME_needs_removal, TMPOUTNAME_needs_removal,
+ TMPPATNAME_needs_removal): New variables.
+ (xmalloc): Remove decl; now in xalloc.h.
+
+ * inp.c: Include <quotearg.h>, <xalloc.h>.
+
+ * inp.c (get_input_file),
+ pch.c (intuit_diff_type),
+ util.c (version_controller):
+ Don't do diff operation if diffbuf is null; used by ClearCase support.
+
+ * inp.c (plan_b),
+ patch.c (init_reject),
+ pch.c (open_patch_file, do_ed_script):
+ Create temporary file with O_EXCL to avoid races.
+
+ * patch.c: Include <quotearg.h>, <xalloc.h>.
+ (create_output_file, init_output): New open_flags arg.
+ All callers changed.
+ (init_reject): No longer takes filename arg. All callers changed.
+ (remove_if_needed): New function.
+ (cleanup): Use it to remove temporary files only if needed.
+ (TMPREJNAME_needs_removal): New var.
+ (main): Set xalloc_fail_func to memory_fatal; needed for xalloc.
+ Initialize quoting style from QUOTING_STYLE.
+ (longopts, get_some_switches): Offset longarg options by CHAR_MAX,
+ not 128; this is needed for EBCDIC ports.
+
+ * patch.c (main, locate_hunk, abort_hunk, spew_output),
+ pch.c (there_is_another_patch, intuit_diff_type, malformed,
+ another_hunk):
+ The LINENUM type now might be longer than long,
+ so print and read line numbers more carefully.
+
+ * patch.c (main),
+ pch.c (there_is_another_patch):
+ util.c (fetchname):
+ strippath now defaults to -1, so that we can distinguish unset
+ value from largest possible.
+
+ * patch.man: Clarify how file name is chosen from candidates.
+
+ * pch.c: Include <quotearg.h>.
+ (p_strip_trailing_cr): New variable.
+ (scan_linenum): New function.
+ (pget_line, re_patch, there_is_another_patch, intuit_diff_type,
+ get_line): Strip trailing CRs from context diffs that need this.
+ (best_name): Use SIZE_MAX instead of (size_t) -1 for max size_t.
+
+ * quotesys.c, quotearg.h: Renamed from quotearg.c and quotearg.h.
+ All uses changed.
+ * quotesys.h (__QUOTESYS_P): Renamed from __QUOTEARG_P.
+
+ * util.c: Include <quotearg.h>, <xalloc.h>.
+ (raise): Don't define if already defined.
+ (move_file): New arg from_needs_removal. All callers changed.
+ (copy_file): New arg to_flags. All callers changed.
+ (CLEARTOOL_CO): New constant.
+ (version_controller): Add ClearCase support.
+ (format_linenum): New function.
+ (fetchname): Allow any POSIX.1 time zone spec, which means
+ any local time offset in the range -25:00 < offset < +26:00.
+ Ignore the name if it doesn't have enough slashes to strip off.
+ (xmalloc): Remove; now in xmalloc.c.
+
+ * util.h (LINENUM_LENGTH_BOUND): New macro.
+ (format_linenum): New decl.
+
+ * version.c (copyright_string): Update years of copyrights.
+
+1997-09-03 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.5.1.
+ * inp.c (re_input): Don't free buffers twice when input is garbled.
+ * patch.c (main): If skipping patch and Plan A fails, don't
+ bother trying Plan B.
+
+1997-08-31 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Version 2.5 released.
+
+1997-07-21 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.4.4.
+ * pch.c (there_is_another_patch), NEWS: Report an error if the patch
+ input contains garbage but no patches.
+
+ * pch.c (open_patch_file):
+ Check for patch file too long (i.e., its size
+ doesn't fit in a `long', and LFS isn't available).
+
+ * inp.c (plan_a):
+ Cast malloc return value, in case malloc returns char *.
+
+1997-07-16 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.4.3.
+
+ * NEWS, patch.man, pch.c (intuit_diff_type, get_line, pget_line):
+ Now demangles RFC 934 encapsulation.
+ * pch.c (p_rfc934_nesting): New var.
+
+ * pch.c (intuit_diff_type): Don't bother to check file names carefully
+ if we're going to return NO_DIFF.
+
+ * inp.c (plan_a): Count the number of lines before allocating
+ pointer-to-line buffer; this reduces memory requirements
+ considerably (roughly by a factor of 5 on 32-bit hosts).
+ Decrease `size' only when read unexpectedly reports EOF.
+ (i_buffer): New var.
+ (too_many_lines): New fn.
+ (re_input): Free i_buffer if using plan A.
+ Free buffers unconditionally; they can't be zero.
+
+ * inp.c (plan_a, plan_b): Check for overflow of line counter.
+
+ * pch.c (malformed), util.h (memory_fatal, read_fatal, write_fatal):
+ Declare as noreturn.
+
+1997-07-10 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.4.2.
+
+ * util.c (ok_to_reverse), NEWS: The default answer is now `n';
+ this is better for Emacs.
+
+ * Makefile.in (dist): Use cp -p, not ln;
+ some hosts do the wrong thing with ln if the source is a symbolic link.
+
+ * patch.man: Fix typo: -y -> -Y.
+
+1997-07-05 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.4.1.
+
+ * patch.c: (main, get_some_switches), NEWS, patch.man:
+ Version control is now independent of whether backups are made.
+ * patch.c (option_help): Put version control options together.
+ (get_some_switches): With CVS 1.9 hack, treat -b foo like -b -z foo,
+ not just -z foo. This change is needed due to recent change in -z.
+ * backupfile.c (find_backup_file_name):
+ backup_type == none causes undefined behavior;
+ this undoes the previous change to this file.
+
+ * patch.c (locate_hunk): Fix bug when locating context diff hunks
+ near end of file with nonzero fuzz.
+
+ * util.c (move_file): Don't assume that ENOENT is reported when both
+ ENOENT and EXDEV apply; this isn't true with DJGPP, and
+ Posix doesn't require it.
+
+ * pch.c (there_is_another_patch):
+ Suggest -p when we can't intuit a file.
+
+1997-06-19 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Version 2.4 released.
+ * NEWS: Patch is now verbose when patches do not match exactly.
+
+1997-06-17 Paul Eggert <eggert@twinsun.com>
+
+ * pc/djgpp/configure.sed (config.h): Remove redundant $(srcdir).
+
+ * configure.in (VERSION): Bump to 2.3.9.
+ * patch.c (main): By default, warn about hunks that succeed
+ with nonzero offset.
+ * patch.man: Add LC_ALL=C advice for making patches.
+ * pc/djgpp/configure.sed (config.h): Fix paths to dependent files.
+
+1997-06-17 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.8.
+
+ * pch.c (open_patch_file): Test stdin for fseekability.
+ (intuit_diff_type): Missing context diff headers are now warnings,
+ not errors; some people use patches with them (e.g. when retrying
+ rejects).
+
+ * patch.c (struct outstate):
+ New type, collecting together some output state vars.
+ (apply_hunk, copy_till, spew_output, init_output): Use it.
+ Keep track of whether some output has been generated.
+ (backup_if_mismatch): New var.
+ (ofp): Remove, in favor of local struct outstate vars.
+ (main): Use struct outstate. Initialize backup_if_mismatch to
+ be the inverse of posixly_correct. Keep track of whether mismatches
+ occur, and use this to implement backup_if_mismatch.
+ Report files that are not empty after patching, but should be.
+ (longopts, option_help, get_some_switches): New options
+ --backup-if-mismatch, --no-backup-if-mismatch.
+ (get_some_switches): -B, -Y, -z no longer set backup_type.
+ * backupfile.c (find_backup_file_name):
+ Treat backup_type == none like simple.
+
+ * Makefile.in (CONFIG_HDRS):
+ Remove var; no longer needed by djgpp port.
+ (DISTFILES_PC_DJGPP): Rename pc/djgpp/config.sed to
+ pc/djgpp/configure.sed; remove pc/djgpp/config.h in favor of
+ new file that edits it, called pc/djgpp/config.sed.
+ * pc/djgpp/configure.bat: Rename config.sed to configure.sed.
+ * pc/djgpp/configure.sed (CONFIG_HDRS): Remove.
+ (config.h): Add rule to build this from config.hin and
+ pc/djgpp/config.sed.
+ * pc/djgpp/config.sed:
+ Convert from .h file to .sed script that generates .h file.
+
+ * NEWS: Describe --backup-if-mismatch, --no-backup-if-mismatch.
+ * patch.man:
+ Describe new options --backup-if-mismatch, --no-backup-if-mismatch
+ and their ramifications. Use unreadable backup to represent
+ nonexistent file.
+
+1997-06-12 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.7.
+ (AC_CHECK_FUNCS): Add `raise'.
+
+ * Makefile.in (inp.o): No longer depends on quotearg.h.
+
+ * common.h (outfile): New decl (was private var named `output').
+ (invc): New decl.
+ (GENERIC_OBJECT): Renamed from VOID.
+ (NULL_DEVICE, TTY_DEVICE): New macros.
+
+ * patch.c (output): Remove; renamed to `outfile' and moved to common.h.
+ (main): `failed' is count, not boolean.
+ Say "Skipping patch." when deciding to skip patch.
+ (get_some_switches): Set invc when setting inname.
+
+ * inp.c: Do not include <quotearg.h>.
+ (SCCSPREFIX, GET, GET_LOCKED, SCCSDIFF1, SCCSDIFF2, SCCSDIFF3,
+ RCSSUFFIX, CHECKOUT, CHECKOUT_LOCKED, RCSDIFF1, RCSDIFF2):
+ Move to util.c.
+ (get_input_file): Invoke new functions version_controller and
+ version_get to simplify this code.
+ (plan_b): "/dev/tty" -> NULL_DEVICE
+
+ * pch.h (pch_timestamp): New decl.
+ * pch.c (p_timestamp): New var; takes over from global timestamp array.
+ (pch_timestamp): New function to export p_timestamp.
+ (there_is_another_patch): Use blander wording when you can't intuit
+ the file name.
+ Say "Skipping patch." when deciding to skip patch.
+ (intuit_diff_type): Look for version-controlled but nonexistent files
+ when intuiting file names; set invc accordingly.
+ Ignore Index: line if either old or new line is present, and if
+ POSIXLY_CORRECT is not set.
+ (do_ed_script): Flush stdout before invoking popen, since it may
+ send output to stdout.
+
+ * util.h (version_controller, version_get): New decls.
+ * util.c: Include <quotearg.h> earlier.
+ (raise): New macro, if ! HAVE_RAISE.
+ (move_file): Create empty unreadable file when backing up a nonexistent
+ file.
+ (DEV_NULL): New constant.
+ (SCCSPREFIX, GET. GET_LOCKED, SCCSDIFF1, SCCSDIFF2,
+ RCSSUFFIX, CHECKOUT, CHECKOUT_LOCKED, RCSDIFF1): Moved here from inp.c.
+ (version_controller, version_get): New functions.
+ (ask): Look only at /dev/tty for answers; and when standard output is
+ not a terminal and ! posixly_correct, don't even look there.
+ Remove unnecessary fflushes of stdout.
+ (ok_to_reverse): Say "Skipping patch." when deciding to skip patch..
+ (sigs): SIGPIPE might not be defined.
+ (exit_with_signal): Use `raise' instead of `kill'.
+ (systemic): fflush stdout before invoking subsidiary command.
+
+ * patch.man: Document recent changes.
+ Add "COMPATIBILITY ISSUES" section.
+
+ * NEWS: New COMPATIBILITY ISSUES for man page.
+ Changed verbosity when fuzz is found.
+ File name intuition is changed, again.
+ Backups are made unreadable when the file did not exist.
+
+ * pc/djgpp/config.h (HAVE_STRUCT_UTIMBUF): Define.
+ (HAVE_RAISE): New macro.
+ (HAVE_UTIME_H): Define.
+ (TZ_is_unset): Do not define; it's not a serious problem with `patch'
+ to have TZ be unset in DOS.
+
+1997-06-08 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.6.
+ (AC_CHECK_HEADERS): Add utime.h.
+ * acconfig.h, configure.in, pc/djgpp/config.h (HAVE_STRUCT_UTIMBUF):
+ New macro.
+ * pc/djgpp/config.h (HAVE_UTIME_H, TZ_is_unset): New macros.
+
+ * NEWS, patch.man: Describe new -Z, -T options, new numeric
+ option for -G, retired -G, and more verbose default behavior
+ with fuzz.
+
+ * pch.c (intuit_diff_type): Record times reported for files in headers.
+ Remove head_says_nonexistent[x], since it's now equivalent to
+ !timestamp[x].
+ * util.h (fetchname): Change argument head_says_nonexistent to
+ timestamp.
+ * util.c: #include <partime.h> for TM_LOCAL_ZONE.
+ Don't include <time.h> since common.h now includes it.
+ (ok_to_reverse): noreverse and batch cases now output regardless of
+ verbosity.
+ (fetchname): Change argument head_says_nonexistent to pstamp, and
+ store header timestamp into *pstamp.
+ If -T or -Z option is given, match time stamps more precisely.
+ (ask): Remove unnecessary close of ttyfd.
+ When there is no terminal at all, output a newline to make the
+ output look nicer. After reporting EOF, flush stdout;
+ when an input error, report the error type.
+
+ * inp.c (get_input_file):
+ Ask user whether to get file if patch_get is negative.
+
+ * Makefile.in (clean): Don't clean */*.o; clean core* and *core.
+
+1997-06-04 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.5.
+
+ * util.c (ok_to_reverse):
+ Be less chatty if verbosity is SILENT and we don't
+ have to ask the user. If force is nonzero, apply the patch anyway.
+
+ * pch.c (there_is_another_patch):
+ Before skipping rest of patch, skip to
+ the patch start, so that another_hunk can skip it properly.
+ (intuit_diff_type): Slight wording change for missing headers, to
+ regularize with other diagnostics. Fix off-by-one error when setting
+ p_input_line when scanning the first hunk to check for deleted files.
+
+1997-06-03 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.4.
+
+ * NEWS: Now matches more generously against nonexistent or empty files.
+
+ * pch.c (there_is_another_patch): Move warning about not being
+ able to intuit file names here from skip_to.
+ (intuit_diff_type): Fatal error if we find a headless unified
+ or context diff.
+
+ * util.c (ask): Null-terminate buffer properly even if it grew.
+ (fetchname): No need to test for null first argument.
+
+1997-06-02 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.3.
+ * pch.c (p_says_nonexistent, pch_says_nonexistent): Is now 1 for empty,
+ 2 for nonexistent.
+ (intuit_diff_type): Set p_says_nonexistent according to new meaning.
+ Treat empty files like nonexistent files when reversing.
+ (skip_to): Output better diagnostic when we can't intuit a file name.
+ * patch.c (main):
+ Count bytes, not lines, when testing whether a file is empty,
+ since it may contain only non-newline chars.
+ pch_says_nonexistent now returns 2 for nonexistent files.
+
+1997-06-01 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.2.
+ * pch.c (open_patch_file):
+ Fix bug when computing size of patch read from a pipe.
+
+1997-05-30 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.3.1.
+
+ * Makefile.in (transform, patch_name): New vars,
+ for proper implementation of AC_ARG_PROGRAM.
+ (install, uninstall): Use them.
+ (install-strip): New rule.
+ * pc/djgpp/config.sed (program_transform_name): Set to empty.
+
+1997-05-30 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION), NEWS: Version 2.3 released.
+ * patch.man: Fix two font typos.
+ * util.c (doprogram): Fix misspelled decl.
+
+1997-05-26 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.2.93.
+
+ * pch.c (open_patch_file):
+ Fatal error if binary_transput and stdin is a tty.
+
+ * pc/djgpp/config.sed (chdirsaf.c):
+ Use sed instead of cp, since cp might not be installed.
+ * pc/djgpp/configure.bat:
+ Prepend %srcdir% to pathname of config.sed, for crosscompiles.
+
+1997-05-25 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.2.92.
+ (D_INO_IN_DIRENT): New macro.
+ * pc/djgpp/config.h, acconfig.h (D_INO_IN_DIRENT): New macro.
+ * backupfile.c (REAL_DIR_ENTRY):
+ Depend on D_INO_IN_DIRENT, not _POSIX_VERSION.
+
+ * addext.c (addext): Adjust slen when adjusting s for DOS 8.3 limit.
+ Do not use xxx.h -> xxxh~ hack.
+
+ * util.c: (move_file): Avoid makedirs test when possible even
+ if FILESYSTEM_PREFIX_LEN (p) is nonzero. Don't play
+ case-changing tricks to come up with backup file name; it's
+ not portable to case-insensitive file systems.
+ * common.h (ISLOWER): Remove.
+
+ * inp.c (scan_input): Don't use Plan A if (debug & 16).
+
+ * patch.c (shortopts): Add -g, -G.
+ (longopts): --help now maps to 132, not 'h', to avoid confusion.
+ (get_some_switches): Likewise.
+ Don't invoke setmode on input if --binary; wait until needed.
+ Don't ever invoke setmode on stdout.
+ * pch.c (open_patch_file): Setmode stdin to binary if binary_transput.
+
+ * patch.man: Fix documentation of backup file name to match behavior.
+ Add advice for ordering of patches of derived files.
+ Add /dev/tty to list of files used.
+ * README: Adjust instructions for building on DOS.
+ * pc/djgpp/README: Remove tentative wording.
+ * NEWS: The DOS port is now tested.
+ Backup file names are no longer computed by switching case.
+
+ * pc/chdirsaf.c (ERANGE): Include <errno.h> to define it.
+ (restore_wd): chdir unconditionally.
+ (chdir_safer): Invoke atexit successfully at most once.
+ * pc/djgpp/config.sed: Use chdirsaf.o, not pc/chdirsaf.o.
+ Replace CONFIG_HDRS, don't append.
+ Use $(srcdir) in CONFIG_STATUS.
+ Don't apply $(SHELL) to $(CONFIG_STATUS).
+ Append rules for chdirsaf.o, chdirsaf.c; clean chdirsaf.c at the end.
+ * pc/djgpp/configure.bat: Append CR to each line; DOS needs this.
+ Don't use | as sed s delimiter; DOS can't handle it.
+
+1997-05-21 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.2.91.
+
+ * pch.c (another_hunk):
+ Fix bug with computing size of prefix and suffix context
+ with ordinary context diffs. Report malformed patch if a unified diff
+ has nothing but context.
+
+ * inp.c (get_input_file):
+ Use patch_get, not backup_type, to decide whether to
+ get from RCS or SCCS. Use the word `get' in diagnostics.
+ * patch.c (main): Initialize patch_get from PATCH_GET.
+ Omit DEFAULT_VERSION_CONTROL hook; it just leads to nonstandarization.
+ (longopts, option_help, get_some_switches): Add support for -g, -G.
+ (option_help): Add bug report address.
+ * common.h (patch_get): New decl.
+ * patch.man: Add -g and -G options; use `get' instead of `check out'.
+ Add PATCH_GET. Recommend -Naur instead of -raNU2 for diff.
+ * NEWS: Describe -g, -G, PATCH_GET.
+
+ * version.c (copyright_string): Use only most recent copyright year,
+ as per GNU standards.
+
+ * Makefile.in (DISTFILES_PC): Remove pc/quotearg.c.
+ * pc/djgpp/config.sed: Remove unnecessary hooks for quotearg and SHELL.
+
+1997-05-18 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Increase to 2.2.9.
+ (AC_TYPE_MODE_T): Add.
+
+ * pch.h (another_hunk): New parameter REV.
+ * pch.c (hunkmax): Now of type LINENUM.
+ (malformed): Add decl.
+ (there_is_another_patch): Skip inname-detection if skip_rest_of_patch.
+ (intuit_diff_type): To determine whether file appears to have been
+ deleted, look at replacement, not pattern.
+ If there is a mismatch between existence of file and whether the
+ patch claims to change whether the file exists, ask whether to
+ reverse the patch.
+ (another_hunk): New parameter REV specifying whether to reverse the
+ hunk. All callers changed.
+ (do_ed_script): Add assertion to ensure input file exists.
+
+ * util.h (create_file): New function.
+ (copy_file): Now takes mode, not struct stat.
+ (makedirs): No longer exported.
+ (move_file): Now takes mode, not struct stat.
+ * util.c (makedirs): No longer exported.
+ (move_file): Accept mode of destination, not struct stat.
+ All callers changed.
+ Quote file names in diagnostics.
+ Create parent dir of destination if necessary.
+ Don't use ENOTDIR.
+ Don't unlink source; it will be unlinked later.
+ Unlink destination if FROM is zero.
+ (create_file): New function.
+ (copy_file): Accept mode of destination, not struct stat.
+ All callers changed.
+ Use create_file to create file.
+ (ok_to_reverse): Moved here from patch.c. Now accepts format and args;
+ all callers changed.
+ (mkdir): 2nd arg is now mode_t, for better compatibility.
+ (replace_slashes): Ignore slashes at the end of the filename.
+
+ * common.h (noreverse): New decl.
+ (ok_to_reverse): Remove decl.
+
+ * patch.c (noreverse): Now extern.
+ (main): New environment var PATCH_VERSION_CONTROL overrides VERSION_CONTROL.
+ Don't assert(hunk) if we're skipping the patch; we may not have any hunks.
+ When removing a file, back it up if backups are desired.
+ Don't chmod output file if input file did not exist.
+ chmod rej file to input file's mode minus executable bits.
+ (locate_hunk): Go back to old way of a single fuzz parameter, but
+ handle it more precisely: context diffs with partial contexts
+ can only match file ends, since the partial context can occur
+ only at the start or end of file.
+ All callers changed.
+ (create_output_file): Use create_file to create files.
+ (ok_to_reverse): Move to util.c.
+
+ * inp.c (scan_input, get_input_file): Quote file names in diagnostics.
+ (get_input_file): Set inerrno if it's not already set.
+ Don't create file; it's now the caller's responsibility.
+ (plan_b): Use /dev/null if input size is zero, since it might not exist.
+ Use create_file to create temporary file.
+
+ * NEWS: Add PATCH_VERSION_CONTROL; DOS port is untested.
+
+ * pc/djgpp/config.h: Add comment for mode_t.
+
+ * pc/djgpp/README: Note that it's not tested.
+
+ * patch.man: PATCH_VERSION_CONTROL overrides VERSION_CONTROL.
+
+1997-05-15 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in: Add AC_PREREQ(2.12).
+ (VERSION): Bump to 2.2.8.
+ (ed_PROGRAM): Rename from ED_PROGRAM.
+
+ * pch.c (prefix_components): Support DOS file names better.
+ Fix typo that caused fn to almost always yield 0.
+
+ * util.c (<time.h>, <maketime.h>): Include.
+ (move_file, copy_file): Add support for DOS filenames.
+ Preserve mode of input files when creating temp files.
+ Add binary file support.
+ (doprogram, rmdir): New functions.
+ (mkdir): Use doprogram.
+ (replace_slashes): Add support for DOS filenames.
+ (removedirs): New function.
+ (init_time)): New function.
+ (initial_time): New var.
+ (fetchname): Add support for deleted files, DOS filenames.
+
+ * basename.c (FILESYSTEM_PREFIX_LEN, ISSLASH):
+ New macros, for DOS port.
+ (base_name): Use them.
+
+ * addext.c (HAVE_DOS_FILE_NAMES): New macro.
+ <limits.h>: Include if HAVE_LIMITS_H.
+ (addext): Handle hosts with DOS file name limits.
+
+ * common.h (LONG_MIN): New macro.
+ (FILESYSTEM_PREFIX_LEN, ISSLASH): New macros, for DOS port.
+ (ok_to_create_file): Remove.
+ (reverse): Now int.
+ (ok_to_reverse): New function decl.
+ (O_WRONLY, _O_BINARY, O_BINARY, O_CREAT, O_TRUNC): New macros.
+ (binary_transput): New var decl.
+
+ * Makefile.in (ed_PROGRAM): Renamed from ED_PROGRAM.
+ (CONFIG_HDRS, CONFIG_STATUS): New vars.
+ (SRCS): Add maketime.c, partime.c.
+ (OBJS): Likewise.
+ (HDRS): Add maketime.h, partime.h.
+ (DISTFILES_PC, DISTFILES_PC_DJGPP): New vars.
+ (Makefile, config.status): Use CONFIG_STATUS, not config.status.
+ (clean): Remove */*.o.
+ (dist): Add pc and pc/djgpp subdirectories.
+ ($(OBJS)): Depend on $(CONFIG_HDRS) instead of config.h.
+ (maketime.o, partime.o): New rules.
+ (util.o): Depend on maketime.h.
+
+ * patch.c (main):
+ Call init_time. Add DEFAULT_VERSION_CONTROL hook for people who
+ prefer the old ways. Build temp file names before we might invoke cleanup.
+ Add support for deleted files and clean up the patch-swapping code a bit.
+ Delete empty ancestors of deleted files.
+ When creating temporaries, use file modes of original files.
+ (longopts, get_some_switches): New option --binary.
+ (get_some_switches): Report non-errno errors with `fatal', not `pfatal'.
+ (create_output_file): New function, which preserves modes of original files
+ and supports binary transput.
+ (init_output, init_reject): Use it.
+ (ok_to_reverse): New function.
+ (TMPDIR): New macro.
+ (make_temp): Use $TMPDIR, $TMP, $TEMP, or TMPDIR, whichever comes first.
+
+ * pch.c (p_says_nonexistent): New var.
+ (open_patch_file): Add binary transput support.
+ Apply stat to file names retrieved from user.
+ Reject them if they don't exist.
+ (intuit_diff_type): Add support for deleting files.
+ Don't treat trivial directories any differently.
+ Avoid stating the same file twice in common case of context diffs.
+ (prefix_components): Don't treat trivial directories any differently.
+ Add support for DOS filenames.
+ (pch_says_nonexistent): New function.
+ (do_ed_script): Preserve mode of input files when creating temp files.
+ Add support for binary transput.
+
+ * pch.h (pch_says_nonexistent): New decl.
+
+ * util.h (replace_slashes): No longer exported.
+ (fetchname): Add support for deleted files.
+ (copy_file, move_file): Add support for preserving file modes.
+ (init_time, removedirs): New functions.
+
+ * argmatch.c: Converge with fileutils.
+
+ * backupfile.c: Converge with fileutils.
+ (find_backup_file_name): Treat .~N~ suffix just like any other suffix
+ when handling file names that are too long.
+
+ * inp.c:
+ In messages, put quotes around file names and spaces around "--".
+ (get_input_file): Allow files to be deleted. Do the expense of
+ makedirs only if we can't create the file.
+ (plan_a, plan_b): Add support for binary transput.
+
+ * pc/chdirsaf.c, pc/djgpp/README, pc/djgpp/config.h, pc/djgpp/config.sed, pc/djgpp/configure.bat, pc/quotearg.c:
+ New file.
+
+ * NEWS:
+ New methods for removing files; adjust file name intuition again.
+ Add description of MS-DOS and MS-Windows ports.
+
+ * patch.man:
+ Simplify file name intuition slightly (no distinction for trivial dirs).
+ Add --binary. Describe how files and directories are deleted.
+ Suggest diff -a. Include caveats about what context diffs cannot represent.
+
+1997-05-06 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Now 2.2.7.
+ (CPPFLAGS, LDFLAGS, LIBS): If the user has not set any of these vars,
+ prefer support for large files if available.
+
+ * common.h (_LARGEFILE_SOURCE): Define.
+ (file_offset): New typedef.
+ (file_seek, file_tell): New macros.
+
+ * patch.c (main):
+ Remove empty files by default unless POSIXLY_CORRECT is set.
+
+ * util.c, util.h (Fseek):
+ Use file_offset instead of long, for portability to large-file hosts.
+
+ * pch.c: (p_base, p_start, next_intuit_at, skip_to, open_patch_file,
+ intuit_diff_type, another_hunk, incomplete_line, do_ed_script):
+ Use file_offset instead of long, for portability to large-file hosts.
+ (prefix_components): Renamed from path_name_components; count only
+ nontrivial prefix components, and take a 2nd EXISTING arg.
+ (existing_prefix_components): Remove; subsumed by prefix_components.
+ (intuit_diff_type): When creating files, try for the creation of the
+ fewest directories.
+
+ * configure.in (VERSION): Now 2.2.6.
+
+ * pch.c (existing_prefix_components): New function.
+ (intuit_diff_type): When creating a file, use a name whose existing
+ directory prefix contains the most nontrivial path name components.
+ (best_name): Don't check for null 2nd arg.
+
+ * util.h (replace_slashes): New decl.
+
+ * util.c (replace_slashes): Now external.
+ (fetchname): Don't assume chars are nonnegative.
+
+ * patch.man:
+ When creating a file, use a name whose existing directory prefix
+ contains the most nontrivial path name components.
+ Add advice for creating patches and applying them.
+
+1997-05-06 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Now 2.2.6.
+
+ * pch.c (existing_prefix_components): New function.
+ (intuit_diff_type): When creating a file, use a name whose existing
+ directory prefix contains the most nontrivial path name components.
+ (best_name): Don't check for null 2nd arg.
+
+ * util.h (replace_slashes): New decl.
+ * util.c (replace_slashes): Now external.
+ (fetchname): Don't assume chars are nonnegative.
+
+ * patch.man: Describe above change to pch.c.
+ Add advice for creating patches and applying them.
+
+1997-05-05 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Update to 2.2.5.
+
+ * quotearg.h, quotearg.c: New files.
+ * Makefile.in (SRCS, OBJS, HDRS): Mention new files.
+ (inp.o, util.o): Now depends on quotearg.h.
+ (quotearg.o): New makefile rule.
+
+ * common.h (posixly_correct): New var.
+ * patch.c (main): Initialize it.
+ If ! posixly_correct, default backup type is now `existing'.
+ SIMPLE_BACKUP_SUFFIX no longer affects backup type.
+ (backup): Remove var.
+
+ * util.h: (countdirs): Remove.
+ (systemic): New decl.
+ * util.c (move_file): Try making the parent directory of TO
+ if backup prefix or suffix contain a slash.
+ (ask): Remove arbitrary limit on size of result.
+ (systemic): New function.
+ (mkdir): Work even if arg contains shell metacharacters.
+ (replace_slashes): Return 0 if none were replaced.
+ Don't replace slash after . or .. since it's redundant.
+ (countdirs): Remove.
+ (makedirs): Ignore mkdir failures.
+
+ * NEWS, patch.man: More POSIXLY_CORRECT adjustments.
+ Describe new rules for how file names are intuited.
+
+1997-04-17 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Version 2.2 released.
+
+ * Makefile.in (config.hin):
+ Remove before building; we always want the timestamp updated.
+
+ * inp.c (get_input_file):
+ Look for RCS files only if backup_type == numbered_existing.
+
+ * NEWS, patch.man:
+ Remove mention of never-implemented -V rcs and -V sccs options.
+ * patch.man: `pathname' -> `file name'
+ Correct the description of how file names are found in diff headers.
+ Clarify the distinction between ordinary and unified context diffs.
+
+1997-04-13 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Update to 2.1.7.
+
+ * patch.c (numeric_optarg): New function.
+ (get_some_switches): Use it.
+
+ * pch.c (intuit_diff_type): When creating a file, prefer a name whose
+ existing dir prefix is the longest.
+
+ * util.h (countdirs): New function.
+ * util.c (replace_slashes, countdirs): New functions.
+ (makedirs): Use replace_slashes, to be more like countdirs.
+
+ * patch.man: Explain -pN vs -p N. Recommend --new-file.
+ Explain possible incompatibility with strip count.
+
+1997-04-10 Paul Eggert <eggert@twinsun.com>
+
+ * configure.in (VERSION): Bump to 2.1.6.
+ (AC_CHECK_HEADERS): Remove stdlib.h (i.e. remove HAVE_STDLIB_H).
+
+ * Makefile.in: (HDRS, patchlevel.h, TAGS, distclean, maintainer-clean):
+ Don't distribute patchlevel.h; let the user do it.
+ This works around some obscure (possibly nonexistent?) `make' bugs.
+
+ * common.h (program_name): extern, not XTERN.
+ (<stdlib.h>): Include if STDC_HEADERS, not if HAVE_STDLIB_H.
+ (atol, getenv, malloc, realloc): Don't worry whether they're #defined.
+
+ * patch.c (get_some_switches):
+ Add special hack for backwards compatibility with CVS 1.9.
+ (-B, -Y, -z): Now set backup_type = simple.
+
+ * NEWS: Fix misspellings; minor reformatting.
+ * README: Report POSIX.2 compliance.
+
+1997-04-06 Paul Eggert <eggert@twinsun.com>
+
+ Move all old RCS $Log entries into ChangeLog.
+ #include all files with < >, not " ".
+
+ * addext.c, argmatch.c, argmatch.h, memchr.c, install-sh:
+ New files.
+ * EXTERN.h, INTERN.h: Removed.
+ * config.hin: Renamed from config.h.in.
+
+ * acconfig.h (NODIR): Remove.
+ (HAVE_MEMCHR): Add.
+
+ * configure.in (AC_ARG_PROGRAM, AC_PROG_MAKE_SET, HAVE_MEMCHR): Add.
+ (AC_CHECK_HEADERS): Replaces obsolescent AC_HAVE_HEADERS.
+ Add stdlib.h, string.h, unistd.h, varargs.h.
+ Delete obsolete call to AC_UNISTD_H.
+ (AC_CONFIG_HEADER): Rename config.h.in to config.hin.
+ (AC_C_CONST): Replaces obsolescent AC_CONST.
+ (AC_CHECK_FUNC): Check for getopt_long; define LIBOBJS and substitute
+ for it accordingly.
+ (AC_CHECK_FUNCS): Replaces obsolescent AC_HAVE_FUNCS.
+ Add _doprintf, isascii, mktemp, sigaction, sigprocmask, sigsetmask.
+ Remove strerror.
+ (AC_FUNC_CLOSEDIR_VOID, AC_FUNC_VPRINTF): Add.
+ (AC_HEADER_DIRENT): Replaces obsolescent AC_DIR_HEADER.
+ (AC_HEADER_STDC): Replaces obsolescent AC_STDC_HEADERS.
+ (AC_SYS_LONG_FILE_NAMES): Replaces obsolescent AC_LONG_FILE_NAMES.
+ (AC_TYPE_OFF_T): Replaces obsolescent AC_OFF_T.
+ (AC_TYPE_SIGNAL): Replaces obsolescent AC_RETSIGTYPE.
+ (AC_TYPE_SIZE_T): Replaces obsolescent AC_SIZE_T.
+ (AC_XENIX_DIR): Remove.
+ (ED_PROGRAM): New var.
+ (NODIR): Remove.
+ (PACKAGE, VERSION): New vars; substitute them with AC_SUBST.
+
+ * Makefile.in: Conform to current GNU build standards.
+ Redo dependencies. Use library getopt_long if available.
+ Use `&&' instead of `;' inside shell commands where applicable;
+ GNU make requires this.
+ Use double-colon rules for actions that do not build files.
+ (@SET_MAKE@): Added.
+ (CFLAGS, LDFLAGS, prefix, exec_prefix): Base on @ versions of symbols.
+ (COMPILE, CPPFLAGS, DEFS, ED_PROGRAM, LIBOBJS, LIBSRCS, PACKAGE,
+ VERSION): New symbols.
+ (SRCS, OBJS, HDRS, MISC): Add new files.
+ (man1dir): Renamed from mandir.
+ (man1ext): Renamed from manext.
+ (patch): Put -o first.
+ (install): Use $(transform) to allow program to be renamed by configure.
+ (patchlevel.h): Build from $(VERSION).
+ (dist): Get version number from $(VERSION) and package name from
+ $(PACKAGE).
+ (TAGS): Scan $(HDRS).
+ (maintainer-clean): Renamed from realclean. Remove patchlevel.h.
+
+ * backupfile.h (simple_backup_suffix): Now const *.
+ (find_backup_file_name, base_name, get_version): Args are now const *.
+ (base_name): New decl.
+ * backupfile.c (<config.h>): Include only if HAVE_CONFIG_H.
+ (<argmatch.h>): Include.
+ (<string.h>): Include if HAVE_STRING_H, not if STDC_HEADERS.
+ (<strings.h>): Include if !HAVE_STRING_H.
+ (<unistd.h>): Do not include.
+ (<dirent.h>): Redo include as per current autoconf standards.
+ (<limits.h>): Include if HAVE_LIMITS_H. Define CHAR_BIT if not defined.
+ (NLENGTH): Now returns size_t.
+ (CLOSEDIR, INT_STRLEN_BOUND): New macros.
+ (ISDIGIT): Use faster method.
+ (find_backup_file_name): No longer depends on NODIR.
+ Remove redundant code.
+ (make_version_name): Remove; do it more portably.
+ (max_backup_version): Args are now const *.
+ (version_number): Simplify digit checking.
+ (basename, concat, dirname): Remove.
+ (argmatch, invalid_arg): Move to argmatch.c. Simplify test for
+ ambiguous args. When reporting an error, use program_name not "patch".
+ (addext): Move to addext.c. Treat all negative values from pathconf
+ like -1. Always use long extension if it fits, even if the filesystem
+ does not support long file names.
+ (backup_types): Now const.
+
+ * common.h, inp.h (XTERN): Renamed from EXT to avoid collision
+ with errno.h reserved name space.
+
+ * common.h (DEBUGGING): Now an integer; default is 1.
+ (enum diff): New type.
+ (diff_type): Use it instead of small integers.
+ (CONTEXT_DIFF, NORMAL_DIFF, ED_DIFF, NEW_CONTEXT_DIFF, UNI_DIFF):
+ Now enumerated values instead of macros.
+ (NO_DIFF): New enumerated value (used instead of 0).
+ (volatile): Default to the empty string if __STDC__ is not defined.
+ (<signal.h>): Do not include.
+ (Chmod, Close, Fclose, Fflush, Fputc, Signal, Sprintf, Strcat,
+ Strcpy, Unlink, Write): Remove these macros; casts to void are
+ not needed for GNU coding standards.
+ (INITHUNKMAX): Move to pch.c.
+ (malloc, realloc, INT_MIN, MAXLINELEN, strNE, strnNE,
+ Reg1, Reg2, Reg3, Reg4, Reg5, Reg6, Reg7, Reg8, Reg9, Reg10, Reg11,
+ Reg12, Reg13, Reg14, Reg15, Reg16): Remove these macros.
+ (S_IXOTH, S_IWOTH, S_IROTH, S_IXGRP, S_IWGRP,
+ S_IRGRP, S_IXUSR, S_IWUSR, S_IRUSR, O_RDONLY, O_RDWR):
+ Define these macros, if not defined.
+ (CTYPE_DOMAIN, ISLOWER, ISSPACE, ISDIGIT, PARAMS): New macros.
+ (instat): Renamed from filestat; used for input file now.
+ (bufsize, using_plan_a, debug, strippath): Not statically initialized.
+ (debug): #define to 0 if not DEBUGGING, so that users of `debug'
+ no longer need to be surrounded by `#if DEBUGGING'.
+ (out_of_mem, filec, filearg, outname, toutkeep, trejkeep): Remove.
+ (inname, inerrno, dry_run, origbase): New variables.
+ (origprae): Now const*.
+ (TMPOUTNAME, TMPINNAME, TMPPATNAME): Now const*volatile.
+ (verbosity): New variable; subsumes `verbose'.
+ (DEFAULT_VERBOSITY, SILENT, VERBOSE): Values in a new enum.
+ (verbose): Removed.
+ (VOID): Use `#ifdef __STDC__' instead of`#if __STDC__',
+ for consistency elsewhere.
+ (__attribute__): New macro (empty if not a recent GCC).
+ (fatal_exit): Renamed from my_exit.
+ (errno): Don't define if STDC_HEADERS.
+ (<string.h>): Include if either STDC_HEADERS or HAVE_STRING_H.
+ (memcmp, memcpy): Define if !STDC_HEADERS && !HAVE_STRING_H
+ && !HAVE_MEMCHR.
+ (<stdlib.h>): Include if HAVE_STDLIB_H, not if STDC_HEADERS.
+ (atol, getenv, malloc, realloc, lseek): Declare only if not defined
+ as a macro.
+ (popen, strcpy, strcat, mktemp): Do not declare.
+ (lseek): Declare to yield off_t, not long.
+ (<fcntl.h>): Include only if HAVE_FCNTL_H.
+
+ * inp.h (get_input_file): New decl.
+ * inp.c (SCCSPREFIX, GET, GET_LOCKED, SCCSDIFF, RCSSUFFIX, CHECKOUT,
+ CHECKOUT_LOCKED, RCSDIFF): Moved here from common.h.
+ (i_ptr): Now char const **.
+ (i_size): Remove.
+ (TIBUFSIZE_MINIMUM): Define only if not already defined.
+ (plan_a, plan_b): Arg is now const *.
+ (report_revision): Declare before use. It's now the caller's
+ responsibility to test whether revision is 0.
+ (scan_input, report_revision, get_input_file):
+ Be less chatty unless --verbose.
+ (get_input_file): New function, split off from plan_a.
+ Reuse file status gotten by pch if possible. Allow for dry run.
+ Use POSIX bits for creat, not number. Check for creation and
+ close failure, and use fstat not stat. Use memcpy not strncpy.
+ (plan_a): Rewrite for speed.
+ Caller now assigns result to using_plan_a.
+ Don't bother reading empty files; during dry runs they might not exist.
+ Use ISSPACE, not isspace.
+ (plan_b): Allow for dry runs. Use ISSPACE, and handle sign extension
+ correctly on arg. Use POSIX symbol for open arg.
+
+ * patch.c (backup, output, patchname, program_name): New vars.
+ (last_frozen_line): Moved here from inp.h.
+ (TMPREJNAME): Moved here from common.h.
+ (optind_last): Removed.
+ (do_defines, if_defined, not_defined, else_defined, end_defined):
+ Now char const. Prepend with \n (except for not_defined) to
+ allow for files ending in non-newline.
+ (Argv): Now char*const*.
+ (main, get_some_switches): Exit status 0 means success,
+ 1 means hunks were rejected, 2 means trouble.
+ (main, locate_hunk, patch_match): Keep track of patch prefix context
+ separately from suffix context; this fixes several bugs.
+ (main): Initialize bufsize, strippath.
+ Be less chatty unless --verbose.
+ No more NODIR; always have version control available.
+ Require environment variables to be nonempty to have effect.
+ Add support for --dry-run, --output, --verbose.
+ Invoke get_input_file first, before deciding among do_ed_script,
+ plan_a, or plan_b.
+ Clear ofp after closing it, to keep discipline that ofp is either
+ 0 or open, to avoid file descriptor leaks. Conversely, rejfp doesn't
+ need this trick since static analysis is enough to show when it
+ needs to be closed.
+ Don't allow file-creation patches to be applied to existing files.
+ Misordered hunks are now not fatal errors; just go on to the next file.
+ It's a fatal error to fall back on plan B when --output is given,
+ since the moving hand has writ.
+ Add support for binary files.
+ Check for I/O errors.
+ chmod output file ourselves, rather than letting move_file do it;
+ this saves global state.
+ Use better grammar when outputting hunks messages, e.g. avoid
+ `1 hunks'.
+ (main, reinitialize_almost_everything):
+ Remove support for multiple file arguments.
+ Move get_some_switches call from reinitialize_almost_everything
+ to main.
+ (reinitialize_almost_everything): No need to reinitialize things
+ that are no longer global variables, e.g. outname.
+ (shortopts): Remove leading "-"; it's no longer important to
+ return options and arguments in order. '-b' no longer takes operand.
+ -p's operand is no longer optional. Add -i, -Y, -z. Remove -S.
+ (longopts): --suffix is now pared with -z, not -b. --backup now
+ means -b. Add --input, --basename-prefix, --dry-run, --verbose.
+ Remove --skip. --strip's operand is now required.
+ (option_help): New variable. Use style of current coding standards.
+ Change to match current option set.
+ (usage): Use it.
+ (get_some_switches): Get all switches, since `+' is defunct.
+ New options -i, -Y, -z, --verbose, --dry-run.
+ Option -S removed.
+ -b now means backup (backup_type == simple), not simple_backup_suffix.
+ -B now implies backup, and requires nonempty operand.
+ -D no longer requires first char of argument to be an identifier.
+ `-o -' is now disallowed (formerly output to regular file named "-").
+ -p operand is now required.
+ -v no longer needs to cleanup (no temp files can exist at that point).
+ -V now implies backup.
+ Set inname, patchname from file name arguments, if any;
+ do not set filearg. It's now an error if extra operands are given.
+ (abort_junk): Check for write errors in reject file.
+ (apply_hunk, copy_till): Return error flag, so that failure to apply
+ out-of-order hunk is no longer fatal.
+ (apply_hunk): New arg after_newline,
+ for patching files not ending in newline.
+ Cache ofp for speed. Check for write errors.
+ (OUTSIDE, IN_IFNDEF, IN_IFDEF, IN_ELSE): Now part of an enumerated type
+ instead of being #defined to small integers.
+ Change while-do to do-while when copying !-part for R_do_defines,
+ since condition is always true the first time through the loop.
+ (init_output, init_reject): Arg is now const *.
+ (copy_till, spew_output): Do not insert ``missing'' newlines;
+ propagate them via new after_newline argument.
+ (spew_output): Nothing to copy if last_frozen_line == input lines.
+ Do not close (ofp) if it's null.
+ (dump_line): Remove.
+ (similar): Ignore presence or absence of trailing newlines.
+ Check for only ' ' or '\t', not isspace (as per POSIX.2).
+ (make_temp): Use tmpnam if mktemp is not available.
+ (cleanup): New function.
+ (fatal_exit): Use it. Renamed from my_exit.
+ Take signal to exit with, not exit status (which is now always 2).
+
+ * pch.h, pch.c (pch_prefix_context, pch_suffix_context):
+ New fns replacing pch_context.
+ (another_hunk): Now yields int, not bool; -1 means out of memory.
+ Now takes difftype as argument.
+ (pch_write_line): Now returns boolean indicating whether we're after
+ a newline just after the write, for supporting non-text files.
+ * pch.c (isdigit): Remove; use ISDIGIT instead.
+ (INITHUNKMAX): Moved here from common.h.
+ (p_context): Removed. We need to keep track of the pre- and post-
+ context separately, in:
+ (p_prefix_context, p_suffix_context): New variables.
+ (bestguess): Remove.
+ (open_patch_file): Arg is now char const *.
+ Copy file a buffer at a time, not a char at a time, for speed.
+ (grow_hunkmax): Now returns success indicator.
+ (there_is_another_patch, skip_to, another_hunk, do_ed_script):
+ Be less chatty unless --verbose.
+ (there_is_another_patch):
+ Avoid infinite loop if user input keeps yielding EOF.
+ (intuit_diff_type): New returns enum diff, not int.
+ Strip paths as they're being fetched.
+ Set ok_to_create_file correctly even if patch is reversed.
+ Set up file names correctly with unidiff output.
+ Use algorithm specified by POSIX 1003.2b/D11 to deduce
+ name of file to patch, with the exception of patches
+ that can create files.
+ (skip_to): Be verbose if !inname, since we're about to ask the
+ user for a file name and the context will help the user choose.
+ (another_hunk): Keep context as LINENUM, not int.
+ If the replacement is missing, calculate its context correctly.
+ Don't assume input ends in newline.
+ Keep track of patch prefix context separately from suffix context;
+ this fixes several bugs.
+ Don't assume blank lines got chopped if the replacement is missing.
+ Report poorly-formed hunks instead of aborting.
+ Do not use strcpy on overlapping strings; it's not portable.
+ Work even if lines are incomplete.
+ Fix bugs associated with context-less context hunks,
+ particularly when patching in reverse.
+ (pget_line): Now takes just 1 arg; instead of second arg,
+ just examine using_plan_a global. Return -1 if we ran out
+ of memory.
+ (do_ed_script): Now takes output FILE * argument.
+ Take name of editor from ED_PROGRAM instead of hardwiring /bin/ed.
+ Don't bother unlinking TMPOUTNAME.
+ Check for popen failure.
+ Flush pipe to check for output errors.
+ If ofp is nonzero, copy result to it, instead of trying to
+ move the result.
+
+ * util.h, util.c (say1, say2, say3, say4, fatal1, fatal2, fatal3,
+ fatal4, pfatal1, pfatal2, pfatal3, pfatal4, ask1, ask2, ask3, ask4):
+ Remove; replaced with following.
+ (ask, say, fatal, pfatal): New stdarg functions.
+ (fetchname): Remove last, `assume_exists' parameter.
+ (savebuf, savestr, move_file, copy_file): Args are now const *.
+ (exit_with_signal): New function, for proper process status if
+ a signal is received as per POSIX.2.
+ (basename): Rename to `base_name' and move to backupfile.
+ * util.c (<signal.h>): Include here, not in common.h.
+ (vararg_start): New macro.
+ (va_dcl, va_start, va_arg, va_end): Define if neither <stdarg.h>
+ nor <varargs.h> are available.
+ (SIGCHLD): Define to SIGCLD if SIGCLD is defined and
+ SIGCHLD isn't.
+ (private_strerror): Remove.
+ (move_file): Remove option of moving to stdout.
+ Add support for -Y, -z.
+ Don't assume chars in file name are nonnegative.
+ Use copy_file if rename fails due to EXDEV;
+ report failure if rename fails for any other reason.
+ (copy_file, makedirs): Use POSIX symbols for permissions.
+ (copy_file): Open source before destination.
+ (remove_prefix): New function.
+ (vfprintf): New function, if !HAVE_VPRINTF.
+ (afatal, apfatal, zfatal, zpfatal, errnum): Remove.
+ (fatal, pfatal, say): New functions that use stdarg.
+ All callers changed.
+ (zask): Renamed from `ask'. Now uses stdarg. Output to stdout,
+ and read from /dev/tty, or if that cannot be opened, from
+ stderr, stdout, stdin, whichever is first a tty.
+ Print "EOF" when an EOF is read. Do not echo input.
+ (sigs): New array.
+ (sigset_t, sigemptyset, sigmask, sigaddset, sigismember, SIG_BLOCK,
+ SIG_UNBLOCK, SIG_SETMASK, sigprocmask, sigblock, sigsetmask):
+ Define substitutes if not available.
+ (initial_signal_mask, signals_to_block): New vars.
+ (fatal_exit_handler): New function, if !HAVE_SIGACTION.
+ (set_signals, ignore_signals): Use sigaction and sigprocmask style
+ signal-handling if possible; it doesn't lose signals.
+ (set_signals): Default SIGCHLD to work around SysV fork+wait bug.
+ (mkdir): First arg is now const *.
+ (makedirs): Handle multiple adjacent slashes correctly.
+ (fetchname): Do not worry about whether the file exists
+ (that is now the caller's responsibility).
+ Treat a sequence of one or more slashes like one slash.
+ Do not unstrip leading directories if they all exist and if
+ no -p option was given; POSIX doesn't allow this.
+ (memcmp): Remove (now a macro in common.h).
+
+ * version.c (copyright_string, free_software_msgid, authorship_msgid):
+ New constants.
+ (version): Use them. Use program_name instead of hardwiring it.
+
+ * patch.man: Generate date from RCS Id.
+ Rewrite to match the above changes.
+
+Fri Jul 30 02:02:51 1993 Paul Eggert (eggert@twinsun.com)
+
+ * configure.in (AC_HAVE_FUNCS): Add mkdir.
+
+ * common.h (Chmod, Fputc, Write, VOID): New macros.
+ (malloc, realloc): Yield `VOID *', not `char *'.
+
+ * util.h (makedirs): Omit `striplast' argument. Remove `aask'.
+
+ * inp.c (plan_a): Remove fixed internal buffer. Remove lint.
+
+ * util.c (set_signals, ignore_signals): Trap SIGTERM, too.
+ (makedirs): Removed fixed internal buffer. Omit `striplast' argument.
+ (mkdir): New function, if !HAVE_MKDIR.
+ (fetchname): Remove fixed internal buffer.
+ Remove lint from various functions.
+
+ * patch.c, pch.c: Remove lint.
+
+Thu Jul 29 20:52:07 1993 David J. MacKenzie (djm@wookumz.gnu.ai.mit.edu)
+
+ * Makefile.in (config.status): Run config.status --recheck, not
+ configure, to get the right args passed.
+
+Thu Jul 29 07:46:16 1993 Paul Eggert (eggert@twinsun.com)
+
+ * The following changes remove all remaining fixed limits on memory,
+ and fix bugs in patch's handling of null bytes and files that do not
+ end in newline. `Patch' now works on binary files.
+
+ * backupfile.c (find_backup_file_name): Don't dump core if malloc fails.
+
+ * EXTERN.h, INTERN.h (EXITING): New macro.
+ * backupfile.[ch], patch.c, pch.c: Add PARAMS to function declarations.
+
+ * common.h (bool): Change to int, so ANSI C prototype promotion works.
+ (CANVARARG): Remove varargs hack; it wasn't portable.
+ (filearg): Now a pointer, not an array, so that it can be reallocated.
+ (GET*, SCCSDIFF, CHECKOUT*, RCSDIFF): Quote operands to commands.
+ (my_exit): Declare here.
+ (BUFFERSIZE, Ctl, filemode, Fseek, Fstat, Lseek, MAXFILEC, MAXHUNKSIZE,
+ Mktemp, myuid, Null, Nullch, Nullfp, Nulline, Pclose, VOIDUSED): Remove.
+ All invokers changed.
+ (Argc, Argv, *define[sd], last_offset, maxfuzz, noreverse, ofp,
+ optind_last, rejfp, rejname): No longer externally visible; all
+ definers changed.
+ (INT_MAX, INT_MIN, STD*_FILENO, SEEK_SET): Define if the underlying
+ system doesn't. Include <limits.h> for this.
+
+ * configure.in: Add limits.h, memcmp. Delete getline.
+
+ * inp.c (tibufsize): New variable; buffers grow as needed.
+ (TIBUFSIZE_MINIMUM): New macro.
+ (report_revision): New function.
+ (plan_a): Do not search patch as a big string, since that fails
+ if it contains null bytes.
+ Prepend `./' to filenames starting with `-', for RCS and SCCS.
+ If file does not match default RCS/SCCS version, go ahead and patch
+ it anyway; warn about the problem but do not report a fatal error.
+ (plan_b): Do not use a fixed buffer to read lines; read byte by byte
+ instead, so that the lines can be arbitrarily long. Do not search
+ lines as strings, since they may contain null bytes.
+ (plan_a, plan_b): Report I/O errors.
+
+ * inp.c, inp.h (rev_in_string): Remove.
+ (ifetch): Yield size of line too, since strlen no longer applies.
+ (plan_a, plan_b): No longer exported.
+
+ * patch.c (abort_hunk, apply_hunk, patch_match, similar):
+ Lines may contain NUL and need not end in newline.
+ (copy_till, dump_line): Insert newline if appending after partial line.
+ All invokers changed.
+ (main, get_some_switches, apply_hunk): Allocate *_define[ds], filearg,
+ rejname dynamically.
+ (make_temp): New function.
+ (main): Use it.
+ (main, spew_output, dump_line) Check for I/O errors.
+
+ * pch.c (open_patch_file): Don't copy stdin to a temporary file if
+ it's a regular file, since we can seek on it directly.
+ (open_patch_file, skip_to, another_hunk): The patch file may contain
+ NULs.
+ (another_hunk): The patch file may contain lines starting with '\',
+ which means the preceding line lacked a trailing newline.
+ (pgetline): Rename to pget_line.
+ (get_line, incomplete_line, pch_write_line): New functions.
+ (pch_line_len): Return size_t, not short; lines may be very long.
+ (do_ed_script): Check for I/O errors. Allow scripts to contain
+ 'i' and 's' commands, too.
+
+ * pch.h (pfp, grow_hunkmax, intuit_diff_type, next_intuit_at, skip_to,
+ pfetch, pgetline): No longer exported.
+ (pch_write_line): New declaration.
+ (getline): Removed.
+
+ * util.c (move_file, fetchname): Use private stat buffer, so that
+ filestat isn't lost. Check for I/O errors.
+ (savestr): Use savebuf.
+ (zask): Use STD*_FILENO instead of 0, 1, 2.
+ (fetchname): strip_leading defaults to INT_MAX instead of 957 (!).
+ (memcmp): Define if !HAVE_MEMCMP.
+
+ * util.c, util.h (say*, fatal*, pfatal*, ask*): Delete; these
+ pseudo-varargs functions weren't ANSI C. Replace by macros
+ that invoke [fs]printf directly, and invoke new functions
+ [az]{say,fatal,pfatal,ask} before and after.
+ (savebuf, read_fatal, write_fatal, memory_fatal, Fseek): New functions.
+ (fatal*): Output trailing newline after message. All invokers changed.
+
+ * version.c (version): Don't exit.
+
+ * Makefile.in (SRCS): Remove getline.c.
+
+Thu Jul 22 15:24:24 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * EXTERN.h, INTERN.h (PARAMS): Define.
+ * backupfile.h, common.h, inp.h, pch.h, util.h: Use.
+ * backupfile.c: Include EXTERN.h.
+
+Wed Jul 21 13:14:05 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * getline.c: New file.
+ * configure.in: Check for getline (GNU libc has it).
+ * pch.c: Use it instead of fgets.
+ (pgetline): Renamed from pgets. Change callers.
+ * pch.h: Change decl.
+
+ * pch.c (pgets): Tab adjusts by 8 - (indent % 8), not % 7.
+ Be consistent with similar code in pch.c::intuit_diff_type.
+
+ * common.h (MEM): Typedef removed.
+ inp.c, pch.c, util.c: Use size_t instead of MEM.
+ inp.c, pch.c: Use off_t.
+ configure.in: Add AC_SIZE_T and AC_OFF_T.
+
+ * common.h: Make buf a pointer and add a bufsize variable.
+ * util.c, pch.c, inp.c: Replace sizeof buf with bufsize.
+ * patch.c: malloc buf to bufsize bytes.
+
+Tue Jul 20 20:40:03 1993 Paul Eggert (eggert@twinsun.com)
+
+ * common.h (BUFFERSIZE): Grow it to 8k too, just in case.
+ (buf): Turn `buf' back into an array; making it a pointer broke
+ things seriously.
+ * patch.c (main): Likewise.
+
+Tue Jul 20 20:02:40 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * Move Reg[1-16] and CANVARARG decls from config.h.in to common.h.
+ * acconfig.h: New file.
+ * Makefile (HDRS): Add it.
+
+Tue Jul 20 16:35:27 1993 Paul Eggert (eggert@twinsun.com)
+
+ * Makefile.in: Remove alloca.[co]; getopt no longer needs it.
+ * configure.in (AC_ALLOCA): Remove.
+
+ * util.c (set_signals, ignore_signals): Do nothing if SIGHUP
+ and SIGINT aren't defined.
+
+Tue Jul 20 17:59:56 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * patch.c (main): Call xmalloc, not malloc. xmalloc buf.
+ * common.h: Declare xmalloc. Make buf a pointer, not an array.
+
+ * util.c (xmalloc): Call fatal1, not fatal.
+
+ * common.h [MAXLINELEN]: Bump from 1k to 8k.
+
+Thu Jul 8 19:56:16 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * Makefile.in (installdirs): New target.
+ (install): Use it.
+ (Makefile, config.status, configure): New targets.
+
+Wed Jul 7 13:25:40 1993 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * patch.c (get_some_switches, longopts): Recognize --help
+ option, and call usage.
+ (usage): New function.
+
+Fri Jun 25 07:49:45 1993 Paul Eggert (eggert@twinsun.com)
+
+ * backupfile.c (find_backup_file_name): Don't use .orig if
+ numbered_existing with no existing numbered backup.
+ (addext): Don't use ext if !HAVE_LONG_FILE_NAMES,
+ even if it would fit. This matches patch's historical behavior.
+ (simple_backup_suffix): Default to ".orig".
+ * patch.c (main): Just use that default.
+
+Tue Jun 15 22:32:14 1993 Paul Eggert (eggert@twinsun.com)
+
+ * config.h.in (HAVE_ALLOCA_H): This #undef was missing.
+ * Makefile.in (info, check, installcheck): New rules.
+
+Sun Jun 13 14:31:29 1993 Paul Eggert (eggert@twinsun.com)
+
+ * config.h.in (index, rindex): Remove unused macro
+ definitions; they get in the way when porting to AIX.
+ * config.h.in, configure.in (HAVE_STRING_H): Remove unused defn.
+
+Thu Jun 10 21:13:47 1993 Paul Eggert (eggert@twinsun.com)
+
+ * patchlevel.h: PATCH_VERSION 2.1.
+ (The name `patch-2.0.12g12' is too long for traditional Unix.)
+
+ * patchlevel.h (PATCH_VERSION): Renamed from PATCHLEVEL.
+ Now contains the entire patch version number.
+ * version.c (version): Use it.
+
+Wed Jun 9 21:43:23 1993 Paul Eggert (eggert@twinsun.com)
+
+ * common.h: Remove declarations of index and rindex.
+ * backupfile.c: Likewise.
+ (addext, basename, dirname): Avoid rindex.
+
+Tue Jun 8 15:24:14 1993 Paul Eggert (eggert@twinsun.com)
+
+ * inp.c (plan_a): Check that RCS and working files are not the
+ same. This check is needed on hosts that do not report file
+ name length limits and have short limits.
+
+Sat Jun 5 22:56:07 1993 Paul Eggert (eggert@twinsun.com)
+
+ * Makefile.in (.c.o): Put $(CFLAGS) after other options.
+ (dist): Switch from .z to .gz.
+
+Wed Jun 2 10:37:15 1993 Paul Eggert (eggert@twinsun.com)
+
+ * backupfile.c (find_backup_file_name): Initialize copy of
+ file name properly.
+
+Mon May 31 21:55:21 1993 Paul Eggert (eggert@twinsun.com)
+
+ * patchlevel.h: Patch level 12g11.
+
+ * pch.c (p_Char): Renamed from p_char, which is a system type
+ in Tex XD88's <sys/types.h>.
+
+ * backupfile.c: Include "config.h" first, so that `const' is
+ treated consistently in system headers.
+
+Mon May 31 16:06:23 1993 Paul Eggert (eggert@twinsun.com)
+
+ * patchlevel.h: Patch level 12g10.
+
+ * configure.in: Add AC_CONST.
+ * config.h.in: Add `const'.
+ * Makefile.in (.c.o): Add -DHAVE_CONFIG_H.
+ (getopt.o getopt1.o): Depend on config.h.
+
+ * util.c (xmalloc): New function; alloca.c needs this.
+
+Mon May 31 00:49:40 1993 Paul Eggert (eggert@twinsun.com)
+
+ * patchlevel.h: PATCHLEVEL 12g9.
+
+ * backupfile.c, backupfile.h (addext): New function.
+ It uses pathconf(), if available, to determine maximum file
+ name length.
+ * patch.c (main): Use it for reject file name.
+ * common.h (ORIGEXT): Moved to patch.c.
+ * config.h.in (HAVE_PATHCONF): New macro.
+ * configure.in: Define it.
+
+ * Makefile.in (dist): Use gzip, not compress.
+
+Sat May 29 09:42:18 1993 Paul Eggert (eggert@twinsun.com)
+
+ * patch.c (main): Use pathconf to decide reject file name.
+ * common.h (REJEXT): Remove.
+
+ * inp.c (plan_a): Don't lock the checked-out file if `patch -o'
+ redirected the output elsewhere.
+ * common.h (CHECKOUT_LOCKED, GET_LOCKED): New macros. GET and
+ CHECKOUT now just checkout unlocked copies.
+
+Fri May 28 08:44:50 1993 Paul Eggert (eggert@twinsun.com)
+
+ * backupfile.c (basename): Define even if NODIR isn't defined.
+ * patch.c (main): Ask just once to apply a reversed patch.
+
+Tue Nov 24 08:09:04 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu)
+
+ * config.h.in, common.h: Use HAVE_FCNTL_H and HAVE_STRING_H
+ instead of USG.
+
+ * backupfile.c: Use SYSDIR and NDIR instead of USG.
+ Define direct as dirent, not vice-versa.
+
+Wed Sep 16 17:11:48 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * patch.c (get_some_switches): optc should be int, not char.
+
+Tue Sep 15 00:36:46 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * patchlevel.h: PATCHLEVEL 12g8.
+
+Mon Sep 14 22:01:23 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * Makefile.in: Add uninstall target.
+
+ * util.c (fatal, pfatal): Add some asterisks to make fatal
+ messages stand out more.
+
+Tue Aug 25 22:13:36 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * patch.c (main, get_some_switches), common.h, inp.c (plan_a,
+ plan_b), pch.c (there_is_another_patch): Add -t --batch
+ option, similar to -f --force.
+
+Mon Jul 27 11:27:07 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * common.h: Define SCCSDIFF and RCSDIFF.
+ * inp.c (plan_a): Use them to make sure it's safe to check out
+ the default RCS or SCCS version.
+ From Paul Eggert.
+
+Mon Jul 20 14:10:32 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * util.h: Declare basename.
+ * inp.c (plan_a), util.c (fetchname): Use it to isolate the
+ leading path when testing for RCS and SCCS files.
+
+Fri Jul 10 16:03:23 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * util.c (makedirs): Only make the directories that don't exist.
+ From chip@tct.com (Chip Salzenberg).
+
+Wed Jul 8 01:20:56 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * patch.c (main): Open ofp after checking for ed script.
+ Close ofp and rejfp before trying plan B.
+ From epang@sfu.ca (Eugene Pang).
+
+ * util.c (fatal, pfatal): Print "patch: " before message.
+ * pch.c, inp.c, patch.c, util.c: Remove "patch: " from the
+ callers that had it.
+
+ * common.h (myuid): New variable.
+ * patch.c (main): Initialize it.
+ * inp.c (myuid): Function removed.
+ (plan_a): Use the variable, not the function.
+
+ * patch.c: Add back -E --remove-empty-files option.
+
+Tue Jul 7 23:19:28 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * inp.c (myuid): New function.
+ (plan_a): Call it. Optimize stat calls. Be smarter about
+ detecting checked out RCS and SCCS files.
+ From Paul Eggert (eggert@twinsun.com).
+
+ * inp.c, util.c, patch.c: Don't bother checking for stat() > 0.
+
+Mon Jul 6 13:01:52 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * util.c (move_file): Use rename instead of link and copying.
+
+ * util.c (pfatal): New function.
+ * util.h: Declare it and pfatal[1-4] macros.
+ * various files: Use it instead of fatal where appropriate.
+
+ * common.h, patch.c: Replace Arg[cv]_last with optind_last.
+
+ * patch.c (main, get_some_switches): Use getopt_long. Update
+ usage message.
+ (nextarg): Function removed.
+
+ * Rename FLEXFILENAMES to HAVE_LONG_FILE_NAMES,
+ VOIDSIG to RETSIGTYPE.
+
+ * backupfile.c, common.h: Use STDC header files if available.
+ backupfile.h: Declare get_version.
+
+ * COPYING, COPYING.LIB, INSTALL, Makefile.in, alloca.c,
+ config.h.in, configure, configure.in, getopt.[ch], getopt1.c,
+ rename.c: New files.
+ * Configure, MANIFEST, Makefile.SH, config.H, config.h.SH,
+ malloc.c: Files removed.
+
+ * version.c (version): Don't print the RCS stuff, since we're
+ not updating it regularly.
+
+ * patchlevel.h: PATCHLEVEL 12u7.
+
+ * Makefile.SH (dist): New target.
+ Makedist: File removed.
+
+ * inp.c (plan_a): Check whether the user can write to the
+ file, not whether anyone can write to the file.
+
+Sat Jul 4 00:06:58 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * inp.c (plan_a): Try to check out read-only files from RCS or SCCS.
+
+ * util.c (move_file): If backing up by linking fails, try copying.
+ From cek@sdc.boeing.com (Conrad Kimball).
+
+ * patch.c (get_some_switches): Eliminate -E option; always
+ remove empty output files.
+
+ * util.c (fetchname): Only undo slash removal for relative
+ paths if -p was not given.
+
+ * Makefile.sh: Add mostlyclean target.
+
+Fri Jul 3 23:48:14 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu)
+
+ * util.c (fetchname): Accept whitespace between `Index:' and filename.
+ Also plug a small memory leak for diffs against /dev/null.
+ From eggert@twinsun.com (Paul Eggert).
+
+ * common.h: Don't define TRUE and FALSE if already defined.
+ From phk@data.fls.dk (Poul-Henning Kamp).
+
+Wed Apr 29 10:19:33 1992 David J. MacKenzie (djm@churchy.gnu.ai.mit.edu)
+
+ * backupfile.c (get_version): Exit if given a bad backup type.
+
+Fri Mar 27 09:57:14 1992 Karl Berry (karl at hayley)
+
+ * common.h (S_ISDIR, S_ISREG): define these.
+ * inp.c (plan_a): use S_ISREG, not S_IFREG.
+ * util.c (fetchname): use S_ISDIR, not S_IFDIR.
+
+Mon Mar 16 14:10:42 1992 David J. MacKenzie (djm@wookumz.gnu.ai.mit.edu)
+
+ * patchlevel.h: PATCHLEVEL 12u6.
+
+Sat Mar 14 13:13:29 1992 David J. MacKenzie (djm at frob.eng.umd.edu)
+
+ * Configure, config.h.SH: Check for directory header and unistd.h.
+
+ * patch.c (main): If -E was given and output file is empty after
+ patching, remove it.
+ (get_some_switches): Recognize -E option.
+
+ * patch.c (copy_till): Make garbled output an error, not a warning
+ that doesn't change the exit status.
+
+ * common.h: Protect against system declarations of malloc and realloc.
+
+ * Makedist: Add backupfile.[ch].
+
+ * Configure: Look for C library where NeXT and SVR4 put it.
+ Look in /usr/ucb after /bin and /usr/bin for utilities,
+ and look in /usr/ccs/bin, to make SVR4 happier.
+ Recognize m68k predefine.
+
+ * util.c (fetchname): Test of stat return value was backward.
+ From csss@scheme.cs.ubc.ca.
+
+ * version.c (version): Exit with status 0, not 1.
+
+ * Makefile.SH: Add backupfile.[cho].
+ * patch.c (main): Initialize backup file generation.
+ (get_some_switches): Add -V option.
+ * common.h, util,c, patch.c: Replace origext with simple_backup_suffix.
+ * util.c (move_file): Use find_backup_file_name.
+
+Tue Dec 3 11:27:16 1991 David J. MacKenzie (djm at wookumz.gnu.ai.mit.edu)
+
+ * patchlevel.h: PATCHLEVEL 12u5.
+
+ * Makefile.SH: Change clean, distclean, and realclean targets a
+ little so they agree with the GNU coding standards.
+ Add Makefile to addedbyconf, so distclean removes it.
+
+ * Configure: Recognize Domain/OS C library in /lib/libc.
+ From mmuegel@mot.com (Michael S. Muegel).
+
+ * pch.c: Fixes from Wayne Davison:
+ Patch now accepts no-context context diffs that are
+ specified with an assumed one line hunk (e.g. "*** 10 ****").
+ Fixed a bug in both context and unified diff processing that would
+ put a zero-context hunk in the wrong place (one line too soon).
+ Fixed a minor problem with p_max in unified diffs where it would
+ set p_max to hunkmax unnecessarily (the only adverse effect was to
+ not supply empty lines at eof by assuming they were truncated).
+
+Tue Jul 2 03:25:51 1991 David J. MacKenzie (djm at geech.gnu.ai.mit.edu)
+
+ * Configure: Check for signal declaration in
+ /usr/include/sys/signal.h as well as /usr/include/signal.h.
+
+ * Configure, common.h, config.h.SH: Comment out the sprintf
+ declaration and tests to determine its return value type. It
+ conflicts with ANSI C systems' prototypes in stdio.h and the
+ return value of sprintf is never used anyway -- it's always cast
+ to void.
+
+Thu Jun 27 13:05:32 1991 David J. MacKenzie (djm at churchy.gnu.ai.mit.edu)
+
+ * patchlevel.h: PATCHLEVEL 12u4.
+
+Thu Feb 21 15:18:14 1991 David J. MacKenzie (djm at geech.ai.mit.edu)
+
+ * pch.c (another_hunk): Fix off by 1 error. From
+ iverson@xstor.com (Tim Iverson).
+
+Sun Jan 20 20:18:58 1991 David J. MacKenzie (djm at geech.ai.mit.edu)
+
+ * Makefile.SH (all): Don't make a dummy `all' file.
+
+ * patchlevel.h: PATCHLEVEL 12u3.
+
+ * patch.c (nextarg): New function.
+ (get_some_switches): Use it, to prevent dereferencing a null
+ pointer if an option that takes an arg is not given one (is last
+ on the command line). From Paul Eggert.
+
+ * pch.c (another_hunk): Fix from Wayne Davison to recognize
+ single-line hunks in unified diffs (with a single line number
+ instead of a range).
+
+ * inp.c (rev_in_string): Don't use `s' before defining it. From
+ Wayne Davison.
+
+Mon Jan 7 06:25:11 1991 David J. MacKenzie (djm at geech.ai.mit.edu)
+
+ * patchlevel.h: PATCHLEVEL 12u2.
+
+ * pch.c (intuit_diff_type): Recognize `+++' in diff headers, for
+ unified diff format. From unidiff patch 1.
+
+Mon Dec 3 00:14:25 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
+
+ * patch.c (get_some_switches): Make the usage message more
+ informative.
+
+Sun Dec 2 23:20:18 1990 David J. MacKenzie (djm at albert.ai.mit.edu)
+
+ * Configure: When checking for C preprocessor, look for 'abc.*xyz'
+ instead of 'abc.xyz', so ANSI C preprocessors work.
+
+ * Apply fix for -D from ksb@mentor.cc.purdue.edu (Kevin Braunsdorf).
+
+1990-05-01 Wayne Davison <davison@dri.com>
+ * patch.c, pch.c: unidiff support added
+
+Wed Mar 7 23:47:25 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
+
+ * pch.c: Call malformed instead of goto malformed
+ (just allows easier debugging).
+
+Tue Jan 23 21:27:00 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu)
+
+ * common.h (TMP*NAME): Make these char *, not char [].
+ patch.c (main): Use TMPDIR (if present) to set TMP*NAME.
+ common.h: Declare getenv.
+
+Sun Dec 17 17:29:48 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu)
+
+ * patch.c (reverse_flag_specified): New variable.
+ (get_some_switches, reinitialize_almost_everything): Use it.
+
+1988-06-22 Larry Wall <sdcrdcf!lwall>
+ patch12:
+ * common.h: sprintf was declared wrong
+ * patch.c: rindex() wasn't declared
+ * patch.man: now avoids Bell System Logo
+
+1988-06-03 Larry Wall <sdcrdcf!lwall>
+ patch10:
+ * common.h: support for shorter extensions.
+ * inp.c: made a little smarter about sccs files
+ * patch.c: exit code improved.
+ better support for non-flexfilenames.
+ * patch.man: -B switch was contributed.
+ * pch.c: Can now find patches in shar scripts.
+ Hunks that swapped and then swapped back could core dump.
+
+1987-06-04 Larry Wall <sdcrdcf!lwall>
+ * pch.c: pch_swap didn't swap p_bfake and p_efake.
+
+1987-02-16 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Short replacement caused spurious "Out of sync" message.
+
+1987-01-30 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Improved diagnostic on sync error.
+ Moved do_ed_script() to pch.c.
+ * pch.c: Improved responses to mangled patches.
+ * pch.h: Added do_ed_script().
+
+1987-01-05 Larry Wall <sdcrdcf!lwall>
+ * pch.c: New-style context diffs caused double call to free().
+
+1986-11-21 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Fuzz factor caused offset of installed lines.
+
+1986-11-14 Larry Wall <sdcrdcf!lwall>
+ * pch.c: Fixed problem where a long pattern wouldn't grow the hunk.
+ Also restored p_input_line when backtracking so error messages are
+ right.
+
+1986-11-03 Larry Wall <sdcrdcf!lwall>
+ * pch.c: New-style delete triggers spurious assertion error.
+
+1986-10-29 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Backwards search could terminate prematurely.
+ * pch.c: Could falsely report new-style context diff.
+
+1986-09-17 Larry Wall <sdcrdcf!lwall>
+ * common.h, inp.c, inp.h, patch.c, patch.man, pch.c, pch.h,
+ util.h, version.c, version.h: Baseline for netwide release.
+
+1986-08-01 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Fixes for machines that can't vararg.
+ Added fuzz factor. Generalized -p. General cleanup.
+ Changed some %d's to %ld's. Linted.
+ * patch.man: Documented -v, -p, -F.
+ Added notes to patch senders.
+
+1985-08-15 van%ucbmonet@berkeley
+ Changes for 4.3bsd diff -c.
+
+1985-03-26 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Frozen.
+ * patch.man: Frozen.
+
+1985-03-12 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Now checks for normalness of file to patch.
+ Check i_ptr and i_womp to make sure they aren't null before freeing.
+ Also allow ed output to be suppressed.
+ Changed pfp->_file to fileno(pfp).
+ Added -p option from jromine@uci-750a.
+ Added -D (#ifdef) option from joe@fluke.
+ * patch.man: Documented -p, -D.
+
+1984-12-06 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Made smarter about SCCS subdirectories.
+
+1984-12-05 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Added -l switch to do loose string comparison.
+ * patch.man: Added -l switch, and noted bistability bug.
+
+1984-12-04 Larry Wall <sdcrdcf!lwall>
+ Branch for sdcrdcf changes.
+ * patch.c: Failed hunk count not reset on multiple patch file.
+ * patch.man: Baseline version.
+
+1984-11-29 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Linted. Identifiers uniquified. Fixed i_ptr malloc() bug.
+ Fixed multiple calls to mktemp(). Will now work on machines that can
+ only read 32767 chars. Added -R option for diffs with new and old
+ swapped. Various cosmetic changes.
+
+1984-11-09 Larry Wall <sdcrdcf!lwall>
+ * patch.c: Initial revision
+
+
+Copyright (C) 1984, 1985, 1986, 1987, 1988 Larry Wall.
+
+Copyright (C) 1989, 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
+2002 Free Software Foundation, Inc.
+
+This file is part of GNU Patch.
+
+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.
+
+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.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..ce83b00
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,228 @@
+Copyright 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
+Foundation, Inc.
+
+ This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+ These are generic installation instructions.
+
+ The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+ It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring. (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+ The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'. You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
+
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
+
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+Compilers and Options
+=====================
+
+ Some systems require unusual options for compilation or linking that
+the `configure' script does not know about. Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+ You can give `configure' initial values for variables by setting
+them in the environment. You can do that on the command line like this:
+
+ ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+ *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+ You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script. `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory. After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+ By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc. You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+ You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files. If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+ Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+ There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on. Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+ CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+ OS KERNEL-OS
+
+ See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+ If you are _building_ compiler tools for cross-compiling, you should
+use the `--target=TYPE' option to select the type of system they will
+produce code for.
+
+ If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+ If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+ Variables not defined in a site shell script can be set in the
+environment passed to `configure'. However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost. In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'. For example:
+
+ ./configure CC=/usr/local2/bin/gcc
+
+will cause the specified gcc to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+`configure' Invocation
+======================
+
+ `configure' recognizes the following options to control how it
+operates.
+
+`--help'
+`-h'
+ Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
+`--cache-file=FILE'
+ Enable the cache: use and save the results of the tests in FILE,
+ traditionally `config.cache'. FILE defaults to `/dev/null' to
+ disable caching.
+
+`--config-cache'
+`-C'
+ Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
+
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options. Run
+`configure --help' for more details.
+
diff --git a/Makefile.in b/Makefile.in
index 9b19faa..4538bf2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,6 +1,6 @@
# Makefile for GNU patch.
-# Copyright (C) 1993, 1997, 1998, 1999, 2001, 2002, 2003 Free Software
+# Copyright (C) 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -16,7 +16,7 @@
# 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.
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#### Start of system configuration section. ####
@@ -62,12 +62,12 @@ CONFIG_STATUS = config.status
SHELL = /bin/sh
-LIBSRCS = error.c hash.c malloc.c memchr.c \
+LIBSRCS = error.c malloc.c memchr.c \
realloc.c strcasecmp.c strncasecmp.c
SRCS = $(LIBSRCS) \
addext.c argmatch.c backupfile.c \
basename.c dirname.c exitfail.c \
- getopt.c getopt1.c inp.c \
+ getopt.c getopt1.c hash.c inp.c \
maketime.c partime.c \
patch.c pch.c \
quote.c quotearg.c quotesys.c \
@@ -212,11 +212,13 @@ backupfile.$(OBJEXT): argmatch.h backupfile.h dirname.h
basename.$(OBJEXT): dirname.h
dirname.$(OBJEXT): dirname.h xalloc.h
error.$(OBJEXT): error.h gettext.h unlocked-io.h
+exitfail.$(OBJEXT): exitfail.h
getopt.$(OBJEXT) getopt1.$(OBJEXT): getopt.h
+hash.$(OBJEXT): hash.h
inp.$(OBJEXT): backupfile.h $(COMMON) inp.h pch.h quotearg.h util.h xalloc.h
maketime.$(OBJEXT): maketime.h partime.h
partime.$(OBJEXT): partime.h
-patch.$(OBJEXT): argmatch.h backupfile.h $(COMMON) getopt.h inp.h \
+patch.$(OBJEXT): argmatch.h backupfile.h $(COMMON) exitfail.h getopt.h inp.h \
pch.h quotearg.h util.h version.h xalloc.h
pch.$(OBJEXT): backupfile.h $(COMMON) dirname.h inp.h pch.h quotearg.h util.h
quote.$(OBJECT): quote.h quotearg.h
@@ -226,4 +228,4 @@ strncasecmp.$(OBJEXT): strcasecmp.c
util.$(OBJEXT): backupfile.h $(COMMON) dirname.h maketime.h \
partime.h quotearg.h quotesys.h timespec.h util.h version.h xalloc.h
version.$(OBJEXT): $(COMMON) version.h
-xmalloc.$(OBJEXT): error.h gettext.h xalloc.h
+xmalloc.$(OBJEXT): error.h exitfail.h gettext.h xalloc.h
diff --git a/NEWS b/NEWS
index ed05a32..9c8402b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+Changes in version 2.5.10:
+
+* If the input patch is in unified format, any .rej output is now
+ in unified format as well. Formerly it was in context format.
+
Changes in versions 2.5.8 and 2.5.9: bug fixes only.
Changes in version 2.5.7:
@@ -216,7 +221,7 @@ Changes in version 2.0.12g8:
-Copyright (C) 1992, 1993, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+Copyright (C) 1992, 1993, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006
Free Software Foundation, Inc.
This file is part of GNU Patch.
@@ -233,5 +238,5 @@ 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, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/README b/README
index db63301..dfe9e1d 100644
--- a/README
+++ b/README
@@ -51,4 +51,4 @@ See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this file; see the file COPYING.
If not, write to the Free Software Foundation,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
diff --git a/addext.c b/addext.c
index 56d0e4f..fff64f7 100644
--- a/addext.c
+++ b/addext.c
@@ -1,5 +1,7 @@
/* addext.c -- add an extension to a file name
- Copyright (C) 1990, 1997 Free Software Foundation, Inc.
+
+ Copyright (C) 1990, 1997, 1998, 1999, 2001, 2003 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
@@ -23,61 +25,67 @@
#endif
#ifndef HAVE_DOS_FILE_NAMES
-#define HAVE_DOS_FILE_NAMES 0
+# define HAVE_DOS_FILE_NAMES 0
#endif
#ifndef HAVE_LONG_FILE_NAMES
-#define HAVE_LONG_FILE_NAMES 0
+# define HAVE_LONG_FILE_NAMES 0
#endif
-#include <backupfile.h>
-
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <limits.h>
#ifndef _POSIX_NAME_MAX
-#define _POSIX_NAME_MAX 14
+# define _POSIX_NAME_MAX 14
#endif
-#include <sys/types.h>
-#if HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+#include <stddef.h>
+#include <string.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+#include "backupfile.h"
+#include "dirname.h"
+
/* Append to FILENAME the extension EXT, unless the result would be too long,
in which case just append the character E. */
void
-addext (filename, ext, e)
- char *filename;
- char const *ext;
- int e;
+addext (char *filename, char const *ext, int e)
{
char *s = base_name (filename);
- size_t slen = strlen (s), extlen = strlen (ext);
- long slen_max = -1;
+ size_t slen = base_len (s);
+ size_t extlen = strlen (ext);
+ size_t slen_max = HAVE_LONG_FILE_NAMES ? 255 : _POSIX_NAME_MAX;
#if HAVE_PATHCONF && defined _PC_NAME_MAX
- if (slen + extlen <= _POSIX_NAME_MAX && ! HAVE_DOS_FILE_NAMES)
- /* The file name is so short there's no need to call pathconf. */
- slen_max = _POSIX_NAME_MAX;
- else if (s == filename)
- slen_max = pathconf (".", _PC_NAME_MAX);
- else
+ if (_POSIX_NAME_MAX < slen + extlen || HAVE_DOS_FILE_NAMES)
{
- char c = *s;
- *s = 0;
- slen_max = pathconf (filename, _PC_NAME_MAX);
- *s = c;
+ /* The new base name is long enough to require a pathconf check. */
+ long name_max;
+ errno = 0;
+ if (s == filename)
+ name_max = pathconf (".", _PC_NAME_MAX);
+ else
+ {
+ char c = *s;
+ if (! ISSLASH (c))
+ *s = 0;
+ name_max = pathconf (filename, _PC_NAME_MAX);
+ *s = c;
+ }
+ if (0 <= name_max || errno == 0)
+ {
+ long size = slen_max = name_max;
+ if (name_max != size)
+ slen_max = -1;
+ }
}
#endif
- if (slen_max < 0)
- slen_max = HAVE_LONG_FILE_NAMES ? 255 : 14;
if (HAVE_DOS_FILE_NAMES && slen_max <= 12)
{
diff --git a/argmatch.c b/argmatch.c
new file mode 100644
index 0000000..3983632
--- /dev/null
+++ b/argmatch.c
@@ -0,0 +1,280 @@
+/* argmatch.c -- find a match for a string in an array
+
+ Copyright (C) 1990, 1998, 1999, 2001, 2002, 2003 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. */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>
+ Modified by Akim Demaille <demaille@inf.enst.fr> */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification. */
+#include "argmatch.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include "error.h"
+#include "quotearg.h"
+#include "quote.h"
+#include "unlocked-io.h"
+
+/* When reporting an invalid argument, show nonprinting characters
+ by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
+ literal_quoting_style. */
+#ifndef ARGMATCH_QUOTING_STYLE
+# define ARGMATCH_QUOTING_STYLE locale_quoting_style
+#endif
+
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+/* Non failing version of argmatch call this function after failing. */
+#ifndef ARGMATCH_DIE
+# define ARGMATCH_DIE exit (EXIT_FAILURE)
+#endif
+
+#ifdef ARGMATCH_DIE_DECL
+ARGMATCH_DIE_DECL;
+#endif
+
+static void
+__argmatch_die (void)
+{
+ ARGMATCH_DIE;
+}
+
+/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
+ Default to __argmatch_die, but allow caller to change this at run-time. */
+argmatch_exit_fn argmatch_die = __argmatch_die;
+
+
+/* If ARG is an unambiguous match for an element of the
+ null-terminated array ARGLIST, return the index in ARGLIST
+ of the matched element, else -1 if it does not match any element
+ or -2 if it is ambiguous (is a prefix of more than one element).
+
+ If VALLIST is none null, use it to resolve ambiguities limited to
+ synonyms, i.e., for
+ "yes", "yop" -> 0
+ "no", "nope" -> 1
+ "y" is a valid argument, for `0', and "n" for `1'. */
+
+int
+argmatch (const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ int i; /* Temporary index in ARGLIST. */
+ size_t arglen; /* Length of ARG. */
+ int matchind = -1; /* Index of first nonexact match. */
+ int ambiguous = 0; /* If nonzero, multiple nonexact match(es). */
+
+ arglen = strlen (arg);
+
+ /* Test all elements for either exact match or abbreviated matches. */
+ for (i = 0; arglist[i]; i++)
+ {
+ if (!strncmp (arglist[i], arg, arglen))
+ {
+ if (strlen (arglist[i]) == arglen)
+ /* Exact match found. */
+ return i;
+ else if (matchind == -1)
+ /* First nonexact match found. */
+ matchind = i;
+ else
+ {
+ /* Second nonexact match found. */
+ if (vallist == NULL
+ || memcmp (vallist + valsize * matchind,
+ vallist + valsize * i, valsize))
+ {
+ /* There is a real ambiguity, or we could not
+ disambiguate. */
+ ambiguous = 1;
+ }
+ }
+ }
+ }
+ if (ambiguous)
+ return -2;
+ else
+ return matchind;
+}
+
+/* Error reporting for argmatch.
+ CONTEXT is a description of the type of entity that was being matched.
+ VALUE is the invalid value that was given.
+ PROBLEM is the return value from argmatch. */
+
+void
+argmatch_invalid (const char *context, const char *value, int problem)
+{
+ char const *format = (problem == -1
+ ? _("invalid argument %s for %s")
+ : _("ambiguous argument %s for %s"));
+
+ error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value),
+ quote_n (1, context));
+}
+
+/* List the valid arguments for argmatch.
+ ARGLIST is the same as in argmatch.
+ VALLIST is a pointer to an array of values.
+ VALSIZE is the size of the elements of VALLIST */
+void
+argmatch_valid (const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ int i;
+ const char *last_val = NULL;
+
+ /* We try to put synonyms on the same line. The assumption is that
+ synonyms follow each other */
+ fprintf (stderr, _("Valid arguments are:"));
+ for (i = 0; arglist[i]; i++)
+ if ((i == 0)
+ || memcmp (last_val, vallist + valsize * i, valsize))
+ {
+ fprintf (stderr, "\n - `%s'", arglist[i]);
+ last_val = vallist + valsize * i;
+ }
+ else
+ {
+ fprintf (stderr, ", `%s'", arglist[i]);
+ }
+ putc ('\n', stderr);
+}
+
+/* Never failing versions of the previous functions.
+
+ CONTEXT is the context for which argmatch is called (e.g.,
+ "--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
+ calls the (supposed never to return) function EXIT_FN. */
+
+int
+__xargmatch_internal (const char *context,
+ const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn)
+{
+ int res = argmatch (arg, arglist, vallist, valsize);
+ if (res >= 0)
+ /* Success. */
+ return res;
+
+ /* We failed. Explain why. */
+ argmatch_invalid (context, arg, res);
+ argmatch_valid (arglist, vallist, valsize);
+ (*exit_fn) ();
+
+ return -1; /* To please the compilers. */
+}
+
+/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
+ return the first corresponding argument in ARGLIST */
+const char *
+argmatch_to_argument (const char *value,
+ const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ int i;
+
+ for (i = 0; arglist[i]; i++)
+ if (!memcmp (value, vallist + valsize * i, valsize))
+ return arglist[i];
+ return NULL;
+}
+
+#ifdef TEST
+/*
+ * Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
+ */
+char *program_name;
+extern const char *getenv ();
+
+/* When to make backup files. */
+enum backup_type
+{
+ /* Never make backups. */
+ none,
+
+ /* Make simple backups of every file. */
+ simple,
+
+ /* Make numbered backups of files that already have numbered backups,
+ and simple backups of the others. */
+ numbered_existing,
+
+ /* Make numbered backups of every file. */
+ numbered
+};
+
+/* Two tables describing arguments (keys) and their corresponding
+ values */
+static const char *const backup_args[] =
+{
+ "no", "none", "off",
+ "simple", "never",
+ "existing", "nil",
+ "numbered", "t",
+ 0
+};
+
+static const enum backup_type backup_vals[] =
+{
+ none, none, none,
+ simple, simple,
+ numbered_existing, numbered_existing,
+ numbered, numbered
+};
+
+int
+main (int argc, const char *const *argv)
+{
+ const char *cp;
+ enum backup_type backup_type = none;
+
+ program_name = (char *) argv[0];
+
+ if (argc > 2)
+ {
+ fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
+ exit (1);
+ }
+
+ if ((cp = getenv ("VERSION_CONTROL")))
+ backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
+ backup_args, backup_vals);
+
+ if (argc == 2)
+ backup_type = XARGMATCH (program_name, argv[1],
+ backup_args, backup_vals);
+
+ printf ("The version control is `%s'\n",
+ ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
+
+ return 0;
+}
+#endif
diff --git a/argmatch.h b/argmatch.h
index e95ff62..deb908f 100644
--- a/argmatch.h
+++ b/argmatch.h
@@ -1,12 +1,109 @@
-/* argmatch.h -- declarations for matching arguments against option lists */
+/* argmatch.h -- definitions and prototypes for argmatch.c
+ Copyright (C) 1990, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
-#if defined __STDC__ || __GNUC__
-# define __ARGMATCH_P(args) args
-#else
-# define __ARGMATCH_P(args) ()
-#endif
+ 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.
-int argmatch __ARGMATCH_P ((const char *, const char * const *));
-void invalid_arg __ARGMATCH_P ((const char *, const char *, int));
+ 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.
-extern char const program_name[];
+ 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. */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>
+ Modified by Akim Demaille <demaille@inf.enst.fr> */
+
+#ifndef ARGMATCH_H_
+# define ARGMATCH_H_ 1
+
+# include <stddef.h>
+
+# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
+
+# define ARGMATCH_CONSTRAINT(Arglist, Vallist) \
+ (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
+
+/* Assert there are as many real arguments as there are values
+ (argument list ends with a NULL guard). ARGMATCH_VERIFY is
+ preferred, since it is guaranteed to be checked at compile-time.
+ ARGMATCH_ASSERT is for backward compatibility only. */
+
+# define ARGMATCH_VERIFY(Arglist, Vallist) \
+ struct argmatch_verify \
+ { \
+ char argmatch_verify[ARGMATCH_CONSTRAINT(Arglist, Vallist) ? 1 : -1]; \
+ }
+
+# define ARGMATCH_ASSERT(Arglist, Vallist) \
+ assert (ARGMATCH_CONSTRAINT (Arglist, Vallist))
+
+/* Return the index of the element of ARGLIST (NULL terminated) that
+ matches with ARG. If VALLIST is not NULL, then use it to resolve
+ false ambiguities (i.e., different matches of ARG but corresponding
+ to the same values in VALLIST). */
+
+int argmatch (char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH(Arg, Arglist, Vallist) \
+ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+/* xargmatch calls this function when it fails. This function should not
+ return. By default, this is a function that calls ARGMATCH_DIE which
+ in turn defaults to `exit (EXIT_FAILURE)'. */
+typedef void (*argmatch_exit_fn) (void);
+extern argmatch_exit_fn argmatch_die;
+
+/* Report on stderr why argmatch failed. Report correct values. */
+
+void argmatch_invalid (char const *context, char const *value, int problem);
+
+/* Left for compatibility with the old name invalid_arg */
+
+# define invalid_arg(Context, Value, Problem) \
+ argmatch_invalid (Context, Value, Problem)
+
+
+
+/* Report on stderr the list of possible arguments. */
+
+void argmatch_valid (char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_VALID(Arglist, Vallist) \
+ argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+
+
+/* Same as argmatch, but upon failure, reports a explanation on the
+ failure, and exits using the function EXIT_FN. */
+
+int __xargmatch_internal (char const *context,
+ char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn);
+
+/* Programmer friendly interface to __xargmatch_internal. */
+
+# define XARGMATCH(Context, Arg, Arglist, Vallist) \
+ ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
+ (char const *) (Vallist), \
+ sizeof *(Vallist), \
+ argmatch_die)])
+
+/* Convert a value into a corresponding argument. */
+
+char const *argmatch_to_argument (char const *value,
+ char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
+ argmatch_to_argument (Value, Arglist, \
+ (char const *) (Vallist), sizeof *(Vallist))
+
+#endif /* ARGMATCH_H_ */
diff --git a/backupfile.c b/backupfile.c
index 4b0f2ec..7ea76b4 100644
--- a/backupfile.c
+++ b/backupfile.c
@@ -1,5 +1,7 @@
/* backupfile.c -- make Emacs style backup file names
- Copyright (C) 1990,1991,1992,1993,1995,1997 Free Software Foundation, Inc.
+
+ Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000, 2001, 2002, 2003 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
@@ -23,16 +25,9 @@
# include <config.h>
#endif
-#include <argmatch.h>
-#include <backupfile.h>
-
+#include <stddef.h>
#include <stdio.h>
-#include <sys/types.h>
-#if HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+#include <string.h>
#if HAVE_DIRENT_H
# include <dirent.h>
@@ -58,11 +53,7 @@
# define CLOSEDIR(d) closedir (d)
#endif
-#if STDC_HEADERS
-# include <stdlib.h>
-#else
-char *malloc ();
-#endif
+#include <stdlib.h>
#if HAVE_DIRENT_H || HAVE_NDIR_H || HAVE_SYS_DIR_H || HAVE_SYS_NDIR_H
# define HAVE_DIR 1
@@ -70,12 +61,8 @@ char *malloc ();
# define HAVE_DIR 0
#endif
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
-#ifndef CHAR_BIT
-#define CHAR_BIT 8
-#endif
+#include <limits.h>
+
/* Upper bound on the string length of an integer converted to string.
302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
add 1 for integer division truncation; add 1 more for a minus sign. */
@@ -85,10 +72,9 @@ char *malloc ();
- Its arg may be any int or unsigned int; it need not be an unsigned char.
- It's guaranteed to evaluate its argument exactly once.
- It's typically faster.
- Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
- only '0' through '9' are digits. Prefer ISDIGIT to isdigit unless
- it's important to use the locale's definition of `digit' even when the
- host does not conform to Posix. */
+ POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
+ ISDIGIT_LOCALE unless it's important to use the locale's definition
+ of `digit' even when the host does not conform to POSIX. */
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
#if D_INO_IN_DIRENT
@@ -97,15 +83,16 @@ char *malloc ();
# define REAL_DIR_ENTRY(dp) 1
#endif
-/* Which type of backup file names are generated. */
-enum backup_type backup_type = none;
+#include "argmatch.h"
+#include "backupfile.h"
+#include "dirname.h"
/* The extension added to file names to produce a simple (as opposed
to numbered) backup file name. */
-const char *simple_backup_suffix = ".orig";
+const char *simple_backup_suffix = "~";
-static int max_backup_version __BACKUPFILE_P ((const char *, const char *));
-static int version_number __BACKUPFILE_P ((const char *, const char *, size_t));
+static int max_backup_version (const char *, const char *);
+static int version_number (const char *, const char *, size_t);
/* Return the name of the new backup file for file FILE,
allocated with malloc. Return 0 if out of memory.
@@ -113,8 +100,7 @@ static int version_number __BACKUPFILE_P ((const char *, const char *, size_t));
Do not call this function if backup_type == none. */
char *
-find_backup_file_name (file)
- const char *file;
+find_backup_file_name (const char *file, enum backup_type backup_type)
{
size_t backup_suffix_size_max;
size_t file_len = strlen (file);
@@ -127,29 +113,31 @@ find_backup_file_name (file)
if (HAVE_DIR && backup_suffix_size_max < numbered_suffix_size_max)
backup_suffix_size_max = numbered_suffix_size_max;
- s = malloc (file_len + backup_suffix_size_max + numbered_suffix_size_max);
+ s = malloc (file_len + 1
+ + backup_suffix_size_max + numbered_suffix_size_max);
if (s)
{
- strcpy (s, file);
-
#if HAVE_DIR
if (backup_type != simple)
{
int highest_backup;
- size_t dir_len = base_name (s) - s;
+ size_t dirlen = dir_len (file);
- strcpy (s + dir_len, ".");
- highest_backup = max_backup_version (file + dir_len, s);
+ memcpy (s, file, dirlen);
+ if (dirlen == FILESYSTEM_PREFIX_LEN (file))
+ s[dirlen++] = '.';
+ s[dirlen] = '\0';
+ highest_backup = max_backup_version (base_name (file), s);
if (! (backup_type == numbered_existing && highest_backup == 0))
{
char *numbered_suffix = s + (file_len + backup_suffix_size_max);
sprintf (numbered_suffix, ".~%d~", highest_backup + 1);
suffix = numbered_suffix;
}
- strcpy (s, file);
}
#endif /* HAVE_DIR */
+ strcpy (s, file);
addext (s, suffix, '~');
}
return s;
@@ -163,9 +151,7 @@ find_backup_file_name (file)
*/
static int
-max_backup_version (file, dir)
- const char *file;
- const char *dir;
+max_backup_version (const char *file, const char *dir)
{
DIR *dirp;
struct dirent *dp;
@@ -178,7 +164,7 @@ max_backup_version (file, dir)
return 0;
highest_version = 0;
- file_name_length = strlen (file);
+ file_name_length = base_len (file);
while ((dp = readdir (dirp)) != 0)
{
@@ -199,10 +185,7 @@ max_backup_version (file, dir)
*/
static int
-version_number (base, backup, base_length)
- const char *base;
- const char *backup;
- size_t base_length;
+version_number (const char *base, const char *backup, size_t base_length)
{
int version;
const char *p;
@@ -223,30 +206,49 @@ version_number (base, backup, base_length)
static const char * const backup_args[] =
{
- "never", "simple", "nil", "existing", "t", "numbered", 0
+ /* In a series of synonyms, present the most meaning full first, so
+ that argmatch_valid be more readable. */
+ "none", "off",
+ "simple", "never",
+ "existing", "nil",
+ "numbered", "t",
+ 0
};
static const enum backup_type backup_types[] =
{
- simple, simple, numbered_existing, numbered_existing, numbered, numbered
+ none, none,
+ simple, simple,
+ numbered_existing, numbered_existing,
+ numbered, numbered
};
-/* Return the type of backup indicated by VERSION.
- Unique abbreviations are accepted. */
+/* Return the type of backup specified by VERSION.
+ If VERSION is NULL or the empty string, return numbered_existing.
+ If VERSION is invalid or ambiguous, fail with a diagnostic appropriate
+ for the specified CONTEXT. Unambiguous abbreviations are accepted. */
enum backup_type
-get_version (version)
- const char *version;
+get_version (const char *context, const char *version)
{
- int i;
-
if (version == 0 || *version == 0)
return numbered_existing;
- i = argmatch (version, backup_args);
- if (i < 0)
- {
- invalid_arg ("version control type", version, i);
- exit (2);
- }
- return backup_types[i];
+ else
+ return XARGMATCH (context, version, backup_args, backup_types);
+}
+
+
+/* Return the type of backup specified by VERSION.
+ If VERSION is NULL, use the value of the envvar VERSION_CONTROL.
+ If the specified string is invalid or ambiguous, fail with a diagnostic
+ appropriate for the specified CONTEXT.
+ Unambiguous abbreviations are accepted. */
+
+enum backup_type
+xget_version (const char *context, const char *version)
+{
+ if (version && *version)
+ return get_version (context, version);
+ else
+ return get_version ("$VERSION_CONTROL", getenv ("VERSION_CONTROL"));
}
diff --git a/backupfile.h b/backupfile.h
index dad1984..fe5e1de 100644
--- a/backupfile.h
+++ b/backupfile.h
@@ -1,5 +1,7 @@
/* backupfile.h -- declarations for making Emacs style backup file names
- Copyright (C) 1990, 1991, 1992, 1997 Free Software Foundation, Inc.
+
+ Copyright (C) 1990, 1991, 1992, 1997, 1998, 1999, 2003 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,6 +18,9 @@
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+#ifndef BACKUPFILE_H_
+# define BACKUPFILE_H_
+
/* When to make backup files. */
enum backup_type
{
@@ -33,18 +38,17 @@ enum backup_type
numbered
};
-extern enum backup_type backup_type;
+# define VALID_BACKUP_TYPE(Type) \
+ ((Type) == none \
+ || (Type) == simple \
+ || (Type) == numbered_existing \
+ || (Type) == numbered)
+
extern char const *simple_backup_suffix;
-#ifndef __BACKUPFILE_P
-# if defined __STDC__ || __GNUC__
-# define __BACKUPFILE_P(args) args
-# else
-# define __BACKUPFILE_P(args) ()
-# endif
-#endif
-
-char *base_name __BACKUPFILE_P ((char const *));
-char *find_backup_file_name __BACKUPFILE_P ((char const *));
-enum backup_type get_version __BACKUPFILE_P ((char const *));
-void addext __BACKUPFILE_P ((char *, char const *, int));
+char *find_backup_file_name (char const *, enum backup_type);
+enum backup_type get_version (char const *context, char const *arg);
+enum backup_type xget_version (char const *context, char const *arg);
+void addext (char *, char const *, int);
+
+#endif /* ! BACKUPFILE_H_ */
diff --git a/basename.c b/basename.c
index 54f037e..5ff2989 100644
--- a/basename.c
+++ b/basename.c
@@ -1,5 +1,7 @@
/* basename.c -- return the last element in a path
- Copyright (C) 1990, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003 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,10 +21,8 @@
# include <config.h>
#endif
-#if STDC_HEADERS || HAVE_STRING_H
-# include <string.h>
-#endif
#include "dirname.h"
+#include <string.h>
/* In general, we can't use the builtin `basename' function if available,
since it has different meanings in different environments.
diff --git a/common.h b/common.h
index da9c149..1f561de 100644
--- a/common.h
+++ b/common.h
@@ -1,10 +1,10 @@
/* common definitions for `patch' */
-/* $Id: common.h,v 1.35 2003/09/11 18:36:17 eggert Exp $ */
+/* $Id: common.h,v 1.35 2003/09/11 18:36:17 eggert Exp eggert $ */
/* Copyright (C) 1986, 1988 Larry Wall
- Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2002, 2003
+ Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2002, 2003, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef DEBUGGING
#define DEBUGGING 1
@@ -68,40 +68,16 @@
#ifndef S_IRUSR
#define S_IRUSR (S_IROTH << 6)
#endif
-#ifdef MKDIR_TAKES_ONE_ARG
-# define mkdir(name, mode) ((mkdir) (name))
-#endif
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
-#ifndef CHAR_BIT
-#define CHAR_BIT 8
-#endif
-/* The extra casts work around common compiler bugs,
- e.g. Cray C 5.0.3.0 time_t. */
-#define TYPE_SIGNED(t) ((t) -1 < (t) 0)
-#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
- ? (t) (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)) \
- : (t) 0))
-#define TYPE_MAXIMUM(t) ((t) ((t) ~ (t) 0 - TYPE_MINIMUM (t)))
-#ifndef CHAR_MAX
-#define CHAR_MAX TYPE_MAXIMUM (char)
-#endif
-#ifndef INT_MAX
-#define INT_MAX TYPE_MAXIMUM (int)
-#endif
-#ifndef LONG_MIN
-#define LONG_MIN TYPE_MINIMUM (long)
-#endif
+#include <limits.h>
#if HAVE_INTTYPES_H
# include <inttypes.h>
+#elif HAVE_STDINT_H
+# include <stdint.h>
#endif
#ifndef SIZE_MAX
-/* On some nonstandard hosts, size_t is signed,
- so SIZE_MAX != (size_t) -1. */
-#define SIZE_MAX TYPE_MAXIMUM (size_t)
+# define SIZE_MAX ((size_t) -1)
#endif
#include <ctype.h>
@@ -267,6 +243,11 @@ extern int errno;
#define O_TRUNC 0
#endif
+#if MKDIR_TAKES_ONE_ARG
+# undef mkdir
+# define mkdir(name, mode) ((mkdir) (name))
+#endif
+
#if HAVE_SETMODE_DOS
XTERN int binary_transput; /* O_BINARY if binary i/o is desired */
#else
diff --git a/configure.ac b/configure.ac
index 839099c..b821147 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
# Configure `patch'.
-# Copyright (C) 1993, 1997, 1998, 1999, 2002, 2003 Free Software
+# Copyright (C) 1993, 1997, 1998, 1999, 2002, 2003, 2006 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -15,8 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
AC_PREREQ(2.57)
AC_INIT(patch, 2.5.9, bug-patch@gnu.org)
@@ -33,25 +33,15 @@ AC_PROG_MAKE_SET
AC_PATH_PROG(ed_PROGRAM, ed, ed)
gl_USE_SYSTEM_EXTENSIONS
-AC_AIX
-AC_MINIX
AC_PROG_CC_STDC
-AC_ISC_POSIX
AC_SYS_LARGEFILE
AC_EXEEXT
-AC_C_PROTOTYPES
-AC_C_CONST
-
-AC_HEADER_DIRENT
AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h limits.h string.h unistd.h utime.h varargs.h)
+AC_CHECK_HEADERS(fcntl.h utime.h)
AC_TYPE_MODE_T
AC_TYPE_OFF_T
-AC_TYPE_PID_T
-AC_TYPE_SIGNAL
-AC_TYPE_SIZE_T
AM_STDBOOL_H
jm_CHECK_TYPE_STRUCT_UTIMBUF
@@ -69,20 +59,16 @@ gl_STRCASE
gl_TIMESPEC
gl_XALLOC
-AC_CHECK_DECLS([free, getenv, malloc, mktemp])
-AC_CHECK_FUNCS(_doprintf geteuid getuid isascii memcmp mktemp \
- pathconf raise sigaction sigprocmask sigsetmask strerror)
+AC_CHECK_DECLS([mktemp])
+AC_CHECK_FUNCS(geteuid getuid mktemp raise sigaction sigprocmask sigsetmask)
AC_FUNC_FSEEKO
-jm_FUNC_GLIBC_UNLOCKED_IO
jm_FUNC_MALLOC
jm_FUNC_REALLOC
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_SETMODE_DOS
-AC_FUNC_VPRINTF
PATCH_FUNC_MKDIR_TAKES_ONE_ARG
jm_AC_DOS
-AC_SYS_LONG_FILE_NAMES
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
diff --git a/dirname.c b/dirname.c
new file mode 100644
index 0000000..815192a
--- /dev/null
+++ b/dirname.c
@@ -0,0 +1,119 @@
+/* dirname.c -- return all but the last element in a path
+ Copyright (C) 1990, 1998, 2000, 2001, 2003 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "dirname.h"
+
+#include <string.h>
+#include "xalloc.h"
+
+/* Return the length of `dirname (PATH)', or zero if PATH is
+ in the working directory. Works properly even if
+ there are trailing slashes (by effectively ignoring them). */
+size_t
+dir_len (char const *path)
+{
+ size_t prefix_length = FILESYSTEM_PREFIX_LEN (path);
+ size_t length;
+
+ /* Strip the basename and any redundant slashes before it. */
+ for (length = base_name (path) - path; prefix_length < length; length--)
+ if (! ISSLASH (path[length - 1]))
+ return length;
+
+ /* But don't strip the only slash from "/". */
+ return prefix_length + ISSLASH (path[prefix_length]);
+}
+
+/* Return the leading directories part of PATH,
+ allocated with xmalloc.
+ Works properly even if there are trailing slashes
+ (by effectively ignoring them). */
+
+char *
+dir_name (char const *path)
+{
+ size_t length = dir_len (path);
+ int append_dot = (length == FILESYSTEM_PREFIX_LEN (path));
+ char *newpath = xmalloc (length + append_dot + 1);
+ memcpy (newpath, path, length);
+ if (append_dot)
+ newpath[length++] = '.';
+ newpath[length] = 0;
+ return newpath;
+}
+
+#ifdef TEST_DIRNAME
+/*
+
+Run the test like this (expect no output):
+ gcc -DHAVE_CONFIG_H -DTEST_DIRNAME -I.. -O -Wall \
+ basename.c dirname.c xmalloc.c error.c
+ sed -n '/^BEGIN-DATA$/,/^END-DATA$/p' dirname.c|grep -v DATA|./a.out
+
+If it's been built on a DOS or Windows platforms, run another test like
+this (again, expect no output):
+ sed -n '/^BEGIN-DOS-DATA$/,/^END-DOS-DATA$/p' dirname.c|grep -v DATA|./a.out
+
+BEGIN-DATA
+foo//// .
+bar/foo//// bar
+foo/ .
+/ /
+. .
+a .
+END-DATA
+
+BEGIN-DOS-DATA
+c:///// c:/
+c:/ c:/
+c:/. c:/
+c:foo c:.
+c:foo/bar c:foo
+END-DOS-DATA
+
+*/
+
+# define MAX_BUFF_LEN 1024
+# include <stdio.h>
+
+char *program_name;
+
+int
+main (int argc, char *argv[])
+{
+ char buff[MAX_BUFF_LEN + 1];
+
+ program_name = argv[0];
+
+ buff[MAX_BUFF_LEN] = 0;
+ while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
+ {
+ char path[MAX_BUFF_LEN];
+ char expected_result[MAX_BUFF_LEN];
+ char const *result;
+ sscanf (buff, "%s %s", path, expected_result);
+ result = dir_name (path);
+ if (strcmp (result, expected_result))
+ printf ("%s: got %s, expected %s\n", path, result, expected_result);
+ }
+ return 0;
+}
+#endif
diff --git a/dirname.h b/dirname.h
new file mode 100644
index 0000000..62da37d
--- /dev/null
+++ b/dirname.h
@@ -0,0 +1,43 @@
+/* Take file names apart into directory and base names.
+
+ Copyright (C) 1998, 2001, 2003 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 DIRNAME_H_
+# define DIRNAME_H_ 1
+
+# include <stddef.h>
+
+# ifndef DIRECTORY_SEPARATOR
+# define DIRECTORY_SEPARATOR '/'
+# endif
+
+# ifndef ISSLASH
+# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
+# endif
+
+# ifndef FILESYSTEM_PREFIX_LEN
+# define FILESYSTEM_PREFIX_LEN(Filename) 0
+# endif
+
+char *base_name (char const *path);
+char *dir_name (char const *path);
+size_t base_len (char const *path);
+size_t dir_len (char const *path);
+
+int strip_trailing_slashes (char *path);
+
+#endif /* not DIRNAME_H_ */
diff --git a/error.c b/error.c
new file mode 100644
index 0000000..5baec45
--- /dev/null
+++ b/error.c
@@ -0,0 +1,298 @@
+/* Error handler for noninteractive utilities
+ Copyright (C) 1990-1998, 2000, 2001, 2002, 2003 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. */
+
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "error.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "gettext.h"
+#endif
+
+#ifdef _LIBC
+# include <wchar.h>
+# define mbsrtowcs __mbsrtowcs
+#endif
+
+#if !_LIBC
+# include "unlocked-io.h"
+#endif
+
+#ifndef _
+# define _(String) String
+#endif
+
+/* If NULL, error will flush stdout, then print on stderr the program
+ name, a colon and a space. Otherwise, error will call this
+ function without parameters instead. */
+void (*error_print_progname) (void);
+
+/* This variable is incremented each time `error' is called. */
+unsigned int error_message_count;
+
+#ifdef _LIBC
+/* In the GNU C library, there is a predefined variable for this. */
+
+# define program_name program_invocation_name
+# include <libio/libioP.h>
+
+/* In GNU libc we want do not want to use the common name `error' directly.
+ Instead make it a weak alias. */
+extern void __error (int status, int errnum, const char *message, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+extern void __error_at_line (int status, int errnum, const char *file_name,
+ unsigned int line_number, const char *message,
+ ...)
+ __attribute__ ((__format__ (__printf__, 5, 6)));;
+# define error __error
+# define error_at_line __error_at_line
+
+# include <libio/iolibio.h>
+# define fflush(s) INTUSE(_IO_fflush) (s)
+# undef putc
+# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
+
+#else /* not _LIBC */
+
+# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
+# ifndef HAVE_DECL_STRERROR_R
+"this configure-time declaration test was not run"
+# endif
+char *strerror_r ();
+# endif
+
+/* The calling program should define program_name and set it to the
+ name of the executing program. */
+extern char *program_name;
+
+# if HAVE_STRERROR_R || defined strerror_r
+# define __strerror_r strerror_r
+# endif
+#endif /* not _LIBC */
+
+static void
+print_errno_message (int errnum)
+{
+ char const *s;
+
+#if defined HAVE_STRERROR_R || _LIBC
+ char errbuf[1024];
+# if STRERROR_R_CHAR_P || _LIBC
+ s = __strerror_r (errnum, errbuf, sizeof errbuf);
+# else
+ if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
+ s = errbuf;
+ else
+ s = 0;
+# endif
+#else
+ s = strerror (errnum);
+#endif
+
+#if !_LIBC
+ if (! s)
+ s = _("Unknown system error");
+#endif
+
+#if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ {
+ __fwprintf (stderr, L": %s", s);
+ return;
+ }
+#endif
+
+ fprintf (stderr, ": %s", s);
+}
+
+static void
+error_tail (int status, int errnum, const char *message, va_list args)
+{
+#if HAVE_VPRINTF || _LIBC
+# if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ {
+# define ALLOCA_LIMIT 2000
+ size_t len = strlen (message) + 1;
+ wchar_t *wmessage = NULL;
+ mbstate_t st;
+ size_t res;
+ const char *tmp;
+
+ do
+ {
+ if (len < ALLOCA_LIMIT)
+ wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
+ else
+ {
+ if (wmessage != NULL && len / 2 < ALLOCA_LIMIT)
+ wmessage = NULL;
+
+ wmessage = (wchar_t *) realloc (wmessage,
+ len * sizeof (wchar_t));
+
+ if (wmessage == NULL)
+ {
+ fputws_unlocked (L"out of memory\n", stderr);
+ return;
+ }
+ }
+
+ memset (&st, '\0', sizeof (st));
+ tmp =message;
+ }
+ while ((res = mbsrtowcs (wmessage, &tmp, len, &st)) == len);
+
+ if (res == (size_t) -1)
+ /* The string cannot be converted. */
+ wmessage = (wchar_t *) L"???";
+
+ __vfwprintf (stderr, wmessage, args);
+ }
+ else
+# endif
+ vfprintf (stderr, message, args);
+#else
+ _doprnt (message, args, stderr);
+#endif
+ va_end (args);
+
+ ++error_message_count;
+ if (errnum)
+ print_errno_message (errnum);
+#if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ putwc (L'\n', stderr);
+ else
+#endif
+ putc ('\n', stderr);
+ fflush (stderr);
+ if (status)
+ exit (status);
+}
+
+
+/* Print the program name and error message MESSAGE, which is a printf-style
+ format string with optional args.
+ If ERRNUM is nonzero, print its corresponding system error message.
+ Exit with status STATUS if it is nonzero. */
+/* VARARGS */
+void
+error (int status, int errnum, const char *message, ...)
+{
+ va_list args;
+
+ fflush (stdout);
+#ifdef _LIBC
+ _IO_flockfile (stderr);
+#endif
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ {
+#if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s: ", program_name);
+ else
+#endif
+ fprintf (stderr, "%s: ", program_name);
+ }
+
+ va_start (args, message);
+ error_tail (status, errnum, message, args);
+
+#ifdef _LIBC
+ _IO_funlockfile (stderr);
+#endif
+}
+
+/* Sometimes we want to have at most one error per line. This
+ variable controls whether this mode is selected or not. */
+int error_one_per_line;
+
+void
+error_at_line (int status, int errnum, const char *file_name,
+ unsigned int line_number, const char *message, ...)
+{
+ va_list args;
+
+ if (error_one_per_line)
+ {
+ static const char *old_file_name;
+ static unsigned int old_line_number;
+
+ if (old_line_number == line_number
+ && (file_name == old_file_name
+ || strcmp (old_file_name, file_name) == 0))
+ /* Simply return and print nothing. */
+ return;
+
+ old_file_name = file_name;
+ old_line_number = line_number;
+ }
+
+ fflush (stdout);
+#ifdef _LIBC
+ _IO_flockfile (stderr);
+#endif
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ {
+#if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s: ", program_name);
+ else
+#endif
+ fprintf (stderr, "%s:", program_name);
+ }
+
+ if (file_name != NULL)
+ {
+#if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s:%d: ", file_name, line_number);
+ else
+#endif
+ fprintf (stderr, "%s:%d: ", file_name, line_number);
+ }
+
+ va_start (args, message);
+ error_tail (status, errnum, message, args);
+
+#ifdef _LIBC
+ _IO_funlockfile (stderr);
+#endif
+}
+
+#ifdef _LIBC
+/* Make the weak alias. */
+# undef error
+# undef error_at_line
+weak_alias (__error, error)
+weak_alias (__error_at_line, error_at_line)
+#endif
diff --git a/error.h b/error.h
new file mode 100644
index 0000000..471a4d2
--- /dev/null
+++ b/error.h
@@ -0,0 +1,70 @@
+/* Declaration for error-reporting function
+ Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
+
+
+ NOTE: The canonical source of this file is maintained with the GNU C Library.
+ Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
+
+#ifndef _ERROR_H
+#define _ERROR_H 1
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+# define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __format__ format
+# define __printf__ printf
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Print a message with `fprintf (stderr, FORMAT, ...)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
+
+extern void error (int status, int errnum, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+
+extern void error_at_line (int status, int errnum, const char *fname,
+ unsigned int lineno, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 5, 6)));
+
+/* If NULL, error will flush stdout, then print on stderr the program
+ name, a colon and a space. Otherwise, error will call this
+ function without parameters instead. */
+extern void (*error_print_progname) (void);
+
+/* This variable is incremented each time `error' is called. */
+extern unsigned int error_message_count;
+
+/* Sometimes we want to have at most one error per line. This
+ variable controls whether this mode is selected or not. */
+extern int error_one_per_line;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* error.h */
diff --git a/exitfail.c b/exitfail.c
new file mode 100644
index 0000000..3668853
--- /dev/null
+++ b/exitfail.c
@@ -0,0 +1,29 @@
+/* Failure exit status
+
+ Copyright (C) 2002, 2003 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+int volatile exit_failure = EXIT_FAILURE;
diff --git a/exitfail.h b/exitfail.h
new file mode 100644
index 0000000..cf5ab71
--- /dev/null
+++ b/exitfail.h
@@ -0,0 +1,20 @@
+/* Failure exit status
+
+ Copyright (C) 2002 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. */
+
+extern int volatile exit_failure;
diff --git a/getopt.c b/getopt.c
new file mode 100644
index 0000000..6dcdbeb
--- /dev/null
+++ b/getopt.c
@@ -0,0 +1,1209 @@
+/* Getopt for GNU.
+ NOTE: getopt is now part of the C library, so if you don't know what
+ "Keep this file name-space clean" means, talk to drepper@gnu.org
+ before changing it!
+
+ Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+ 1996, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
+ Inc.
+
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
+ Ditto for AIX 3.2 and <stdlib.h>. */
+#ifndef _NO_PROTO
+# define _NO_PROTO
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+ actually compiling the library itself. This code is part of the GNU C
+ Library, but also included in many other GNU distributions. Compiling
+ and linking in this code is a waste when using the GNU C library
+ (especially if it is a shared library). Rather than having every GNU
+ program understand `configure --with-gnu-libc' and omit the object files,
+ it is simpler to just do this in the source for each such file. */
+
+#define GETOPT_INTERFACE_VERSION 2
+#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
+# include <gnu-versions.h>
+# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+# define ELIDE_CODE
+# endif
+#endif
+
+#ifndef ELIDE_CODE
+
+
+/* This needs to come after some library #include
+ to get __GNU_LIBRARY__ defined. */
+#ifdef __GNU_LIBRARY__
+/* Don't include stdlib.h for non-GNU C libraries because some of them
+ contain conflicting prototypes for getopt. */
+# include <stdlib.h>
+# include <unistd.h>
+#endif /* GNU C library. */
+
+#include <string.h>
+
+#ifdef VMS
+# include <unixlib.h>
+#endif
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+/* This is for other GNU distributions with internationalized messages. */
+# include "gettext.h"
+#endif
+#define _(msgid) gettext (msgid)
+
+#if defined _LIBC && defined USE_IN_LIBIO
+# include <wchar.h>
+#endif
+
+#ifndef attribute_hidden
+# define attribute_hidden
+#endif
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+ but it behaves differently for the user, since it allows the user
+ to intersperse the options with the other arguments.
+
+ As `getopt' works, it permutes the elements of ARGV so that,
+ when it is done, all the options precede everything else. Thus
+ all application programs are extended to handle flexible argument order.
+
+ Setting the environment variable POSIXLY_CORRECT disables permutation.
+ Then the behavior is completely standard.
+
+ GNU application programs can use a third alternative mode in which
+ they can distinguish the relative order of options and other arguments. */
+
+#include "getopt.h"
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns -1, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+/* 1003.2 says this must be 1 before any call. */
+int optind = 1;
+
+/* Formerly, initialization of getopt depended on optind==0, which
+ causes problems with re-calling getopt as programs generally don't
+ know that. */
+
+int __getopt_initialized attribute_hidden;
+
+/* The next char to be scanned in the option-element
+ in which the last option character we returned was found.
+ This allows us to pick up the scan where we left off.
+
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+
+static char *nextchar;
+
+/* Callers store zero here to inhibit the error message
+ for unrecognized options. */
+
+int opterr = 1;
+
+/* Set to an option character which was unrecognized.
+ This must be initialized on some systems to avoid linking in the
+ system's own getopt implementation. */
+
+int optopt = '?';
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+ If the caller did not specify anything,
+ the default is REQUIRE_ORDER if the environment variable
+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options;
+ stop option processing when the first non-option is seen.
+ This is what Unix does.
+ This mode of operation is selected by either setting the environment
+ variable POSIXLY_CORRECT, or using `+' as the first character
+ of the list of option characters.
+
+ PERMUTE is the default. We permute the contents of ARGV as we scan,
+ so that eventually all the non-options are at the end. This allows options
+ to be given in any order, even with programs that were not written to
+ expect this.
+
+ RETURN_IN_ORDER is an option available to programs that were written
+ to expect options and other ARGV-elements in any order and that care about
+ the ordering of the two. We describe each non-option ARGV-element
+ as if it were the argument of an option with character code 1.
+ Using `-' as the first character of the list of option characters
+ selects this mode of operation.
+
+ The special argument `--' forces an end of option-scanning regardless
+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
+ `--' can cause `getopt' to return -1 with `optind' != ARGC. */
+
+static enum
+{
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+} ordering;
+
+/* Value of POSIXLY_CORRECT environment variable. */
+static char *posixly_correct;
+
+#ifndef __GNU_LIBRARY__
+
+/* Avoid depending on library functions or files
+ whose names are inconsistent. */
+
+#ifndef getenv
+extern char *getenv ();
+#endif
+
+#endif /* not __GNU_LIBRARY__ */
+
+/* Handle permutation of arguments. */
+
+/* Describe the part of ARGV that contains non-options that have
+ been skipped. `first_nonopt' is the index in ARGV of the first of them;
+ `last_nonopt' is the index after the last of them. */
+
+static int first_nonopt;
+static int last_nonopt;
+
+#ifdef _LIBC
+/* Stored original parameters.
+ XXX This is no good solution. We should rather copy the args so
+ that we can compare them later. But we must not use malloc(3). */
+extern int __libc_argc;
+extern char **__libc_argv;
+
+/* Bash 2.0 gives us an environment variable containing flags
+ indicating ARGV elements that should not be considered arguments. */
+
+# ifdef USE_NONOPTION_FLAGS
+/* Defined in getopt_init.c */
+extern char *__getopt_nonoption_flags;
+
+static int nonoption_flags_max_len;
+static int nonoption_flags_len;
+# endif
+
+# ifdef USE_NONOPTION_FLAGS
+# define SWAP_FLAGS(ch1, ch2) \
+ if (nonoption_flags_len > 0) \
+ { \
+ char __tmp = __getopt_nonoption_flags[ch1]; \
+ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
+ __getopt_nonoption_flags[ch2] = __tmp; \
+ }
+# else
+# define SWAP_FLAGS(ch1, ch2)
+# endif
+#else /* !_LIBC */
+# define SWAP_FLAGS(ch1, ch2)
+#endif /* _LIBC */
+
+/* Exchange two adjacent subsequences of ARGV.
+ One subsequence is elements [first_nonopt,last_nonopt)
+ which contains all the non-options that have been skipped so far.
+ The other is elements [last_nonopt,optind), which contains all
+ the options processed since those non-options were skipped.
+
+ `first_nonopt' and `last_nonopt' are relocated so that they describe
+ the new indices of the non-options in ARGV after they are moved. */
+
+static void
+exchange (char **argv)
+{
+ int bottom = first_nonopt;
+ int middle = last_nonopt;
+ int top = optind;
+ char *tem;
+
+ /* Exchange the shorter segment with the far end of the longer segment.
+ That puts the shorter segment into the right place.
+ It leaves the longer segment in the right place overall,
+ but it consists of two parts that need to be swapped next. */
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+ /* First make sure the handling of the `__getopt_nonoption_flags'
+ string can work normally. Our top argument must be in the range
+ of the string. */
+ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
+ {
+ /* We must extend the array. The user plays games with us and
+ presents new arguments. */
+ char *new_str = malloc (top + 1);
+ if (new_str == NULL)
+ nonoption_flags_len = nonoption_flags_max_len = 0;
+ else
+ {
+ memset (__mempcpy (new_str, __getopt_nonoption_flags,
+ nonoption_flags_max_len),
+ '\0', top + 1 - nonoption_flags_max_len);
+ nonoption_flags_max_len = top + 1;
+ __getopt_nonoption_flags = new_str;
+ }
+ }
+#endif
+
+ while (top > middle && middle > bottom)
+ {
+ if (top - middle > middle - bottom)
+ {
+ /* Bottom segment is the short one. */
+ int len = middle - bottom;
+ register int i;
+
+ /* Swap it with the top part of the top segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[top - (middle - bottom) + i];
+ argv[top - (middle - bottom) + i] = tem;
+ SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
+ }
+ /* Exclude the moved bottom segment from further swapping. */
+ top -= len;
+ }
+ else
+ {
+ /* Top segment is the short one. */
+ int len = top - middle;
+ register int i;
+
+ /* Swap it with the bottom part of the bottom segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[middle + i];
+ argv[middle + i] = tem;
+ SWAP_FLAGS (bottom + i, middle + i);
+ }
+ /* Exclude the moved top segment from further swapping. */
+ bottom += len;
+ }
+ }
+
+ /* Update records for the slots the non-options now occupy. */
+
+ first_nonopt += (optind - last_nonopt);
+ last_nonopt = optind;
+}
+
+/* Initialize the internal data when the first call is made. */
+
+static const char *
+_getopt_initialize (int argc, char *const *argv, const char *optstring)
+{
+ /* Start processing options with ARGV-element 1 (since ARGV-element 0
+ is the program name); the sequence of previously skipped
+ non-option ARGV-elements is empty. */
+
+ first_nonopt = last_nonopt = optind;
+
+ nextchar = NULL;
+
+ posixly_correct = getenv ("POSIXLY_CORRECT");
+
+ /* Determine how to handle the ordering of options and nonoptions. */
+
+ if (optstring[0] == '-')
+ {
+ ordering = RETURN_IN_ORDER;
+ ++optstring;
+ }
+ else if (optstring[0] == '+')
+ {
+ ordering = REQUIRE_ORDER;
+ ++optstring;
+ }
+ else if (posixly_correct != NULL)
+ ordering = REQUIRE_ORDER;
+ else
+ ordering = PERMUTE;
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+ if (posixly_correct == NULL
+ && argc == __libc_argc && argv == __libc_argv)
+ {
+ if (nonoption_flags_max_len == 0)
+ {
+ if (__getopt_nonoption_flags == NULL
+ || __getopt_nonoption_flags[0] == '\0')
+ nonoption_flags_max_len = -1;
+ else
+ {
+ const char *orig_str = __getopt_nonoption_flags;
+ int len = nonoption_flags_max_len = strlen (orig_str);
+ if (nonoption_flags_max_len < argc)
+ nonoption_flags_max_len = argc;
+ __getopt_nonoption_flags =
+ (char *) malloc (nonoption_flags_max_len);
+ if (__getopt_nonoption_flags == NULL)
+ nonoption_flags_max_len = -1;
+ else
+ memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
+ '\0', nonoption_flags_max_len - len);
+ }
+ }
+ nonoption_flags_len = nonoption_flags_max_len;
+ }
+ else
+ nonoption_flags_len = 0;
+#endif
+
+ return optstring;
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+ given in OPTSTRING.
+
+ If an element of ARGV starts with '-', and is not exactly "-" or "--",
+ then it is an option element. The characters of this element
+ (aside from the initial '-') are option characters. If `getopt'
+ is called repeatedly, it returns successively each of the option characters
+ from each of the option elements.
+
+ If `getopt' finds another option character, it returns that character,
+ updating `optind' and `nextchar' so that the next call to `getopt' can
+ resume the scan with the following option character or ARGV-element.
+
+ If there are no more option characters, `getopt' returns -1.
+ Then `optind' is the index in ARGV of the first ARGV-element
+ that is not an option. (The ARGV-elements have been permuted
+ so that those that are not options now come last.)
+
+ OPTSTRING is a string containing the legitimate option characters.
+ If an option character is seen that is not listed in OPTSTRING,
+ return '?' after printing an error message. If you set `opterr' to
+ zero, the error message is suppressed but we still return '?'.
+
+ If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+ so the following text in the same ARGV-element, or the text of the following
+ ARGV-element, is returned in `optarg'. Two colons mean an option that
+ wants an optional arg; if there is text in the current ARGV-element,
+ it is returned in `optarg', otherwise `optarg' is set to zero.
+
+ If OPTSTRING starts with `-' or `+', it requests different methods of
+ handling the non-option ARGV-elements.
+ See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+
+ Long-named options begin with `--' instead of `-'.
+ Their names may be abbreviated as long as the abbreviation is unique
+ or is an exact match for some defined option. If they have an
+ argument, it follows the option name in the same ARGV-element, separated
+ from the option name by a `=', or else the in next ARGV-element.
+ When `getopt' finds a long-named option, it returns 0 if that option's
+ `flag' field is nonzero, the value of the option's `val' field
+ if the `flag' field is zero.
+
+ The elements of ARGV aren't really const, because we permute them.
+ But we pretend they're const in the prototype to be compatible
+ with other systems.
+
+ LONGOPTS is a vector of `struct option' terminated by an
+ element containing a name which is zero.
+
+ LONGIND returns the index in LONGOPT of the long-named option found.
+ It is only valid when a long-named option has been found by the most
+ recent call.
+
+ If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+ long-named options. */
+
+int
+_getopt_internal (int argc, char *const *argv,
+ const char *optstring, const struct option *longopts,
+ int *longind, int long_only)
+{
+ int print_errors = opterr;
+ if (optstring[0] == ':')
+ print_errors = 0;
+
+ if (argc < 1)
+ return -1;
+
+ optarg = NULL;
+
+ if (optind == 0 || !__getopt_initialized)
+ {
+ if (optind == 0)
+ optind = 1; /* Don't scan ARGV[0], the program name. */
+ optstring = _getopt_initialize (argc, argv, optstring);
+ __getopt_initialized = 1;
+ }
+
+ /* Test whether ARGV[optind] points to a non-option argument.
+ Either it does not have option syntax, or there is an environment flag
+ from the shell indicating it is not an option. The later information
+ is only used when the used in the GNU libc. */
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
+ || (optind < nonoption_flags_len \
+ && __getopt_nonoption_flags[optind] == '1'))
+#else
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
+#endif
+
+ if (nextchar == NULL || *nextchar == '\0')
+ {
+ /* Advance to the next ARGV-element. */
+
+ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
+ moved back by the user (who may also have changed the arguments). */
+ if (last_nonopt > optind)
+ last_nonopt = optind;
+ if (first_nonopt > optind)
+ first_nonopt = optind;
+
+ if (ordering == PERMUTE)
+ {
+ /* If we have just processed some options following some non-options,
+ exchange them so that the options come first. */
+
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
+ exchange ((char **) argv);
+ else if (last_nonopt != optind)
+ first_nonopt = optind;
+
+ /* Skip any additional non-options
+ and extend the range of non-options previously skipped. */
+
+ while (optind < argc && NONOPTION_P)
+ optind++;
+ last_nonopt = optind;
+ }
+
+ /* The special ARGV-element `--' means premature end of options.
+ Skip it like a null option,
+ then exchange with previous non-options as if it were an option,
+ then skip everything else like a non-option. */
+
+ if (optind != argc && !strcmp (argv[optind], "--"))
+ {
+ optind++;
+
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
+ exchange ((char **) argv);
+ else if (first_nonopt == last_nonopt)
+ first_nonopt = optind;
+ last_nonopt = argc;
+
+ optind = argc;
+ }
+
+ /* If we have done all the ARGV-elements, stop the scan
+ and back over any non-options that we skipped and permuted. */
+
+ if (optind == argc)
+ {
+ /* Set the next-arg-index to point at the non-options
+ that we previously skipped, so the caller will digest them. */
+ if (first_nonopt != last_nonopt)
+ optind = first_nonopt;
+ return -1;
+ }
+
+ /* If we have come to a non-option and did not permute it,
+ either stop the scan or describe it to the caller and pass it by. */
+
+ if (NONOPTION_P)
+ {
+ if (ordering == REQUIRE_ORDER)
+ return -1;
+ optarg = argv[optind++];
+ return 1;
+ }
+
+ /* We have found another option-ARGV-element.
+ Skip the initial punctuation. */
+
+ nextchar = (argv[optind] + 1
+ + (longopts != NULL && argv[optind][1] == '-'));
+ }
+
+ /* Decode the current option-ARGV-element. */
+
+ /* Check whether the ARGV-element is a long option.
+
+ If long_only and the ARGV-element has the form "-f", where f is
+ a valid short option, don't consider it an abbreviated form of
+ a long option that starts with f. Otherwise there would be no
+ way to give the -f short option.
+
+ On the other hand, if there's a long option "fubar" and
+ the ARGV-element is "-fu", do consider that an abbreviation of
+ the long option, just like "--fu", and not "-f" with arg "u".
+
+ This distinction seems to be the most useful approach. */
+
+ if (longopts != NULL
+ && (argv[optind][1] == '-'
+ || (long_only
+ && (argv[optind][2] || !strchr (optstring, argv[optind][1])))))
+ {
+ char *nameend;
+ const struct option *p;
+ const struct option *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = -1;
+ int option_index;
+
+ for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
+ {
+ if ((unsigned int) (nameend - nextchar)
+ == (unsigned int) strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }
+
+ if (ambig && !exact)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
+ argv[0], argv[optind]) >= 0)
+ {
+
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
+ argv[0], argv[optind]);
+#endif
+ }
+ nextchar += strlen (nextchar);
+ optind++;
+ optopt = 0;
+ return '?';
+ }
+
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ optind++;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg)
+ optarg = nameend + 1;
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+ int n;
+#endif
+
+ if (argv[optind - 1][1] == '-')
+ {
+ /* --option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("\
+%s: option `--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+#else
+ fprintf (stderr, _("\
+%s: option `--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+#endif
+ }
+ else
+ {
+ /* +option or -option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("\
+%s: option `%c%s' doesn't allow an argument\n"),
+ argv[0], argv[optind - 1][0],
+ pfound->name);
+#else
+ fprintf (stderr, _("\
+%s: option `%c%s' doesn't allow an argument\n"),
+ argv[0], argv[optind - 1][0], pfound->name);
+#endif
+ }
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ if (n >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#endif
+ }
+
+ nextchar += strlen (nextchar);
+
+ optopt = pfound->val;
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (optind < argc)
+ optarg = argv[optind++];
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr,
+ _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]);
+#endif
+ }
+ nextchar += strlen (nextchar);
+ optopt = pfound->val;
+ return optstring[0] == ':' ? ':' : '?';
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+
+ /* Can't find it as a long option. If this is not getopt_long_only,
+ or the option starts with '--' or is not a valid short
+ option, then it's an error.
+ Otherwise interpret it as a short option. */
+ if (!long_only || argv[optind][1] == '-'
+ || strchr (optstring, *nextchar) == NULL)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+ int n;
+#endif
+
+ if (argv[optind][1] == '-')
+ {
+ /* --option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
+ argv[0], nextchar);
+#else
+ fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
+ argv[0], nextchar);
+#endif
+ }
+ else
+ {
+ /* +option or -option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
+ argv[0], argv[optind][0], nextchar);
+#else
+ fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
+ argv[0], argv[optind][0], nextchar);
+#endif
+ }
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ if (n >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#endif
+ }
+ nextchar = (char *) "";
+ optind++;
+ optopt = 0;
+ return '?';
+ }
+ }
+
+ /* Look at and handle the next short option-character. */
+
+ {
+ char c = *nextchar++;
+ char *temp = strchr (optstring, c);
+
+ /* Increment `optind' when we start to process its last character. */
+ if (*nextchar == '\0')
+ ++optind;
+
+ if (temp == NULL || c == ':')
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+ int n;
+#endif
+
+ if (posixly_correct)
+ {
+ /* 1003.2 specifies the format of this message. */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
+ argv[0], c);
+#else
+ fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
+#endif
+ }
+ else
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: invalid option -- %c\n"),
+ argv[0], c);
+#else
+ fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
+#endif
+ }
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ if (n >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#endif
+ }
+ optopt = c;
+ return '?';
+ }
+ /* Convenience. Treat POSIX -W foo same as long option --foo */
+ if (temp[0] == 'W' && temp[1] == ';')
+ {
+ char *nameend;
+ const struct option *p;
+ const struct option *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = 0;
+ int option_index;
+
+ /* This is an option that requires an argument. */
+ if (*nextchar != '\0')
+ {
+ optarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ optind++;
+ }
+ else if (optind == argc)
+ {
+ if (print_errors)
+ {
+ /* 1003.2 specifies the format of this message. */
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf,
+ _("%s: option requires an argument -- %c\n"),
+ argv[0], c) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
+#endif
+ }
+ optopt = c;
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ return c;
+ }
+ else
+ /* We already incremented `optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ optarg = argv[optind++];
+
+ /* optarg is now the argument, see if it's in the
+ table of longopts. */
+
+ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
+ {
+ if ((unsigned int) (nameend - nextchar) == strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }
+ if (ambig && !exact)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
+ argv[0], argv[optind]) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
+ argv[0], argv[optind]);
+#endif
+ }
+ nextchar += strlen (nextchar);
+ optind++;
+ return '?';
+ }
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg)
+ optarg = nameend + 1;
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option `-W %s' doesn't allow an argument\n"),
+ argv[0], pfound->name) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("\
+%s: option `-W %s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+#endif
+ }
+
+ nextchar += strlen (nextchar);
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (optind < argc)
+ optarg = argv[optind++];
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr,
+ _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]);
+#endif
+ }
+ nextchar += strlen (nextchar);
+ return optstring[0] == ':' ? ':' : '?';
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+ nextchar = NULL;
+ return 'W'; /* Let the application handle it. */
+ }
+ if (temp[1] == ':')
+ {
+ if (temp[2] == ':')
+ {
+ /* This is an option that accepts an argument optionally. */
+ if (*nextchar != '\0')
+ {
+ optarg = nextchar;
+ optind++;
+ }
+ else
+ optarg = NULL;
+ nextchar = NULL;
+ }
+ else
+ {
+ /* This is an option that requires an argument. */
+ if (*nextchar != '\0')
+ {
+ optarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ optind++;
+ }
+ else if (optind == argc)
+ {
+ if (print_errors)
+ {
+ /* 1003.2 specifies the format of this message. */
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option requires an argument -- %c\n"),
+ argv[0], c) >= 0)
+ {
+ if (_IO_fwide (stderr, 0) > 0)
+ __fwprintf (stderr, L"%s", buf);
+ else
+ fputs (buf, stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr,
+ _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
+#endif
+ }
+ optopt = c;
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ }
+ else
+ /* We already incremented `optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ optarg = argv[optind++];
+ nextchar = NULL;
+ }
+ }
+ return c;
+ }
+}
+
+int
+getopt (int argc, char *const *argv, const char *optstring)
+{
+ return _getopt_internal (argc, argv, optstring,
+ (const struct option *) 0,
+ (int *) 0,
+ 0);
+}
+
+#endif /* Not ELIDE_CODE. */
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+ the above definition of `getopt'. */
+
+int
+main (int argc, char **argv)
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+
+ c = getopt (argc, argv, "abc:d:0123456789");
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/getopt.h b/getopt.h
new file mode 100644
index 0000000..1a55bab
--- /dev/null
+++ b/getopt.h
@@ -0,0 +1,169 @@
+/* Declarations for getopt.
+
+ Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+ 1999, 2001, 2003 Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ 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 _GETOPT_H
+
+#ifndef __need_getopt
+# define _GETOPT_H 1
+#endif
+
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
+ standalone, or this is the first header included in the source file.
+ If we are being used with glibc, we need to include <features.h>, but
+ that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
+ not defined, include <ctype.h>, which will pull in <features.h> for us
+ if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
+ doesn't flood the namespace with stuff the way some other headers do.) */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns -1, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+ for unrecognized options. */
+
+extern int opterr;
+
+/* Set to an option character which was unrecognized. */
+
+extern int optopt;
+
+#ifndef __need_getopt
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of `struct option' terminated by an element containing a name which is
+ zero.
+
+ The field `has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field `flag' is not NULL, it points to a variable that is set
+ to the value given in the field `val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an `int' to
+ a compiled-in constant, such as set a value from `optarg', set the
+ option's `flag' field to zero and its `val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero `flag' field, `getopt'
+ returns the contents of the `val' field. */
+
+struct option
+{
+ const char *name;
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'. */
+
+# define no_argument 0
+# define required_argument 1
+# define optional_argument 2
+#endif /* need getopt */
+
+
+/* Get definitions and prototypes for functions to process the
+ arguments in ARGV (ARGC of them, minus the program name) for
+ options given in OPTS.
+
+ Return the option character from OPTS just read. Return -1 when
+ there are no more options. For unrecognized options, or options
+ missing arguments, `optopt' is set to the option letter, and '?' is
+ returned.
+
+ The OPTS string is a list of characters which are recognized option
+ letters, optionally followed by colons, specifying that that letter
+ takes an argument, to be placed in `optarg'.
+
+ If a letter in OPTS is followed by two colons, its argument is
+ optional. This behavior is specific to the GNU `getopt'.
+
+ The argument `--' causes premature termination of argument
+ scanning, explicitly telling `getopt' that there are no more
+ options.
+
+ If OPTS begins with `--', then non-option arguments are treated as
+ arguments to the option '\0'. This behavior is specific to the GNU
+ `getopt'. */
+
+#ifdef __GNU_LIBRARY__
+/* Many other libraries have conflicting prototypes for getopt, with
+ differences in the consts, in stdlib.h. To avoid compilation
+ errors, only prototype getopt for the GNU C library. */
+extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
+#else /* not __GNU_LIBRARY__ */
+extern int getopt ();
+#endif /* __GNU_LIBRARY__ */
+
+#ifndef __need_getopt
+extern int getopt_long (int ___argc, char *const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int ___argc, char *const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind);
+
+/* Internal only. Users should not call this directly. */
+extern int _getopt_internal (int ___argc, char *const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ int __long_only);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/* Make sure we later can get all the definitions and declarations. */
+#undef __need_getopt
+
+#endif /* getopt.h */
diff --git a/getopt1.c b/getopt1.c
new file mode 100644
index 0000000..3288c72
--- /dev/null
+++ b/getopt1.c
@@ -0,0 +1,185 @@
+/* getopt_long and getopt_long_only entry points for GNU getopt.
+
+ Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996,
+ 1997, 1998, 2003 Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef _LIBC
+# include <getopt.h>
+#else
+# include "getopt.h"
+#endif
+
+#include <stdio.h>
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+ actually compiling the library itself. This code is part of the GNU C
+ Library, but also included in many other GNU distributions. Compiling
+ and linking in this code is a waste when using the GNU C library
+ (especially if it is a shared library). Rather than having every GNU
+ program understand `configure --with-gnu-libc' and omit the object files,
+ it is simpler to just do this in the source for each such file. */
+
+#define GETOPT_INTERFACE_VERSION 2
+#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
+#include <gnu-versions.h>
+#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+#define ELIDE_CODE
+#endif
+#endif
+
+#ifndef ELIDE_CODE
+
+
+/* This needs to come after some library #include
+ to get __GNU_LIBRARY__ defined. */
+#ifdef __GNU_LIBRARY__
+#include <stdlib.h>
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+int
+getopt_long (int argc,
+ char *const *argv,
+ const char *options,
+ const struct option *long_options,
+ int *opt_index)
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+}
+
+/* Like getopt_long, but '-' as well as '--' can indicate a long option.
+ If an option that starts with '-' (not '--') doesn't match a long option,
+ but does match a short option, it is parsed as a short option
+ instead. */
+
+int
+getopt_long_only (int argc,
+ char *const *argv,
+ const char *options,
+ const struct option *long_options,
+ int *opt_index)
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
+}
+
+# ifdef _LIBC
+libc_hidden_def (getopt_long)
+libc_hidden_def (getopt_long_only)
+# endif
+
+#endif /* Not ELIDE_CODE. */
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] =
+ {
+ {"add", 1, 0, 0},
+ {"append", 0, 0, 0},
+ {"delete", 1, 0, 0},
+ {"verbose", 0, 0, 0},
+ {"create", 0, 0, 0},
+ {"file", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "abc:d:0123456789",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 0:
+ printf ("option %s", long_options[option_index].name);
+ if (optarg)
+ printf (" with arg %s", optarg);
+ printf ("\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value `%s'\n", optarg);
+ break;
+
+ case 'd':
+ printf ("option d with value `%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/gettext.h b/gettext.h
new file mode 100644
index 0000000..835732e
--- /dev/null
+++ b/gettext.h
@@ -0,0 +1,68 @@
+/* Convenience header for conditional use of GNU <libintl.h>.
+ Copyright (C) 1995-1998, 2000-2002 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 _LIBGETTEXT_H
+#define _LIBGETTEXT_H 1
+
+/* NLS can be disabled through the configure --disable-nls option. */
+#if ENABLE_NLS
+
+/* Get declarations of GNU message catalog functions. */
+# include <libintl.h>
+
+#else
+
+/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
+ chokes if dcgettext is defined as a macro. So include it now, to make
+ later inclusions of <locale.h> a NOP. We don't include <libintl.h>
+ as well because people using "gettext.h" will not include <libintl.h>,
+ and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
+ is OK. */
+#if defined(__sun)
+# include <locale.h>
+#endif
+
+/* Disabled NLS.
+ The casts to 'const char *' serve the purpose of producing warnings
+ for invalid uses of the value returned from these functions.
+ On pre-ANSI systems without 'const', the config.h file is supposed to
+ contain "#define const". */
+# define gettext(Msgid) ((const char *) (Msgid))
+# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
+# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
+# define ngettext(Msgid1, Msgid2, N) \
+ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+# define dngettext(Domainname, Msgid1, Msgid2, N) \
+ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
+ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+# define textdomain(Domainname) ((const char *) (Domainname))
+# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
+# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
+
+#endif
+
+/* A pseudo function call that serves as a marker for the automated
+ extraction of messages, but does not call gettext(). The run-time
+ translation is done at a different place in the code.
+ The argument, String, should be a literal string. Concatenated strings
+ and other string expressions won't work.
+ The macro's expansion is not parenthesized, so that it is suitable as
+ initializer for static 'char[]' or 'const char[]' variables. */
+#define gettext_noop(String) String
+
+#endif /* _LIBGETTEXT_H */
diff --git a/hash.c b/hash.c
new file mode 100644
index 0000000..3948ce4
--- /dev/null
+++ b/hash.c
@@ -0,0 +1,1035 @@
+/* hash - hashing table processing.
+
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
+ Foundation, Inc.
+
+ Written by Jim Meyering, 1992.
+
+ 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. */
+
+/* A generic hash table package. */
+
+/* Define USE_OBSTACK to 1 if you want the allocator to use obstacks instead
+ of malloc. If you change USE_OBSTACK, you have to recompile! */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <limits.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if USE_OBSTACK
+# include "obstack.h"
+# ifndef obstack_chunk_alloc
+# define obstack_chunk_alloc malloc
+# endif
+# ifndef obstack_chunk_free
+# define obstack_chunk_free free
+# endif
+#endif
+
+#include "hash.h"
+
+struct hash_table
+ {
+ /* The array of buckets starts at BUCKET and extends to BUCKET_LIMIT-1,
+ for a possibility of N_BUCKETS. Among those, N_BUCKETS_USED buckets
+ are not empty, there are N_ENTRIES active entries in the table. */
+ struct hash_entry *bucket;
+ struct hash_entry *bucket_limit;
+ unsigned n_buckets;
+ unsigned n_buckets_used;
+ unsigned n_entries;
+
+ /* Tuning arguments, kept in a physicaly separate structure. */
+ const Hash_tuning *tuning;
+
+ /* Three functions are given to `hash_initialize', see the documentation
+ block for this function. In a word, HASHER randomizes a user entry
+ into a number up from 0 up to some maximum minus 1; COMPARATOR returns
+ true if two user entries compare equally; and DATA_FREER is the cleanup
+ function for a user entry. */
+ Hash_hasher hasher;
+ Hash_comparator comparator;
+ Hash_data_freer data_freer;
+
+ /* A linked list of freed struct hash_entry structs. */
+ struct hash_entry *free_entry_list;
+
+#if USE_OBSTACK
+ /* Whenever obstacks are used, it is possible to allocate all overflowed
+ entries into a single stack, so they all can be freed in a single
+ operation. It is not clear if the speedup is worth the trouble. */
+ struct obstack entry_stack;
+#endif
+ };
+
+/* A hash table contains many internal entries, each holding a pointer to
+ some user provided data (also called a user entry). An entry indistinctly
+ refers to both the internal entry and its associated user entry. A user
+ entry contents may be hashed by a randomization function (the hashing
+ function, or just `hasher' for short) into a number (or `slot') between 0
+ and the current table size. At each slot position in the hash table,
+ starts a linked chain of entries for which the user data all hash to this
+ slot. A bucket is the collection of all entries hashing to the same slot.
+
+ A good `hasher' function will distribute entries rather evenly in buckets.
+ In the ideal case, the length of each bucket is roughly the number of
+ entries divided by the table size. Finding the slot for a data is usually
+ done in constant time by the `hasher', and the later finding of a precise
+ entry is linear in time with the size of the bucket. Consequently, a
+ larger hash table size (that is, a larger number of buckets) is prone to
+ yielding shorter chains, *given* the `hasher' function behaves properly.
+
+ Long buckets slow down the lookup algorithm. One might use big hash table
+ sizes in hope to reduce the average length of buckets, but this might
+ become inordinate, as unused slots in the hash table take some space. The
+ best bet is to make sure you are using a good `hasher' function (beware
+ that those are not that easy to write! :-), and to use a table size
+ larger than the actual number of entries. */
+
+/* If an insertion makes the ratio of nonempty buckets to table size larger
+ than the growth threshold (a number between 0.0 and 1.0), then increase
+ the table size by multiplying by the growth factor (a number greater than
+ 1.0). The growth threshold defaults to 0.8, and the growth factor
+ defaults to 1.414, meaning that the table will have doubled its size
+ every second time 80% of the buckets get used. */
+#define DEFAULT_GROWTH_THRESHOLD 0.8
+#define DEFAULT_GROWTH_FACTOR 1.414
+
+/* If a deletion empties a bucket and causes the ratio of used buckets to
+ table size to become smaller than the shrink threshold (a number between
+ 0.0 and 1.0), then shrink the table by multiplying by the shrink factor (a
+ number greater than the shrink threshold but smaller than 1.0). The shrink
+ threshold and factor default to 0.0 and 1.0, meaning that the table never
+ shrinks. */
+#define DEFAULT_SHRINK_THRESHOLD 0.0
+#define DEFAULT_SHRINK_FACTOR 1.0
+
+/* Use this to initialize or reset a TUNING structure to
+ some sensible values. */
+static const Hash_tuning default_tuning =
+ {
+ DEFAULT_SHRINK_THRESHOLD,
+ DEFAULT_SHRINK_FACTOR,
+ DEFAULT_GROWTH_THRESHOLD,
+ DEFAULT_GROWTH_FACTOR,
+ false
+ };
+
+/* Information and lookup. */
+
+/* The following few functions provide information about the overall hash
+ table organization: the number of entries, number of buckets and maximum
+ length of buckets. */
+
+/* Return the number of buckets in the hash table. The table size, the total
+ number of buckets (used plus unused), or the maximum number of slots, are
+ the same quantity. */
+
+unsigned
+hash_get_n_buckets (const Hash_table *table)
+{
+ return table->n_buckets;
+}
+
+/* Return the number of slots in use (non-empty buckets). */
+
+unsigned
+hash_get_n_buckets_used (const Hash_table *table)
+{
+ return table->n_buckets_used;
+}
+
+/* Return the number of active entries. */
+
+unsigned
+hash_get_n_entries (const Hash_table *table)
+{
+ return table->n_entries;
+}
+
+/* Return the length of the longest chain (bucket). */
+
+unsigned
+hash_get_max_bucket_length (const Hash_table *table)
+{
+ struct hash_entry *bucket;
+ unsigned max_bucket_length = 0;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ struct hash_entry *cursor = bucket;
+ unsigned bucket_length = 1;
+
+ while (cursor = cursor->next, cursor)
+ bucket_length++;
+
+ if (bucket_length > max_bucket_length)
+ max_bucket_length = bucket_length;
+ }
+ }
+
+ return max_bucket_length;
+}
+
+/* Do a mild validation of a hash table, by traversing it and checking two
+ statistics. */
+
+bool
+hash_table_ok (const Hash_table *table)
+{
+ struct hash_entry *bucket;
+ unsigned n_buckets_used = 0;
+ unsigned n_entries = 0;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ struct hash_entry *cursor = bucket;
+
+ /* Count bucket head. */
+ n_buckets_used++;
+ n_entries++;
+
+ /* Count bucket overflow. */
+ while (cursor = cursor->next, cursor)
+ n_entries++;
+ }
+ }
+
+ if (n_buckets_used == table->n_buckets_used && n_entries == table->n_entries)
+ return true;
+
+ return false;
+}
+
+void
+hash_print_statistics (const Hash_table *table, FILE *stream)
+{
+ unsigned n_entries = hash_get_n_entries (table);
+ unsigned n_buckets = hash_get_n_buckets (table);
+ unsigned n_buckets_used = hash_get_n_buckets_used (table);
+ unsigned max_bucket_length = hash_get_max_bucket_length (table);
+
+ fprintf (stream, "# entries: %u\n", n_entries);
+ fprintf (stream, "# buckets: %u\n", n_buckets);
+ fprintf (stream, "# buckets used: %u (%.2f%%)\n", n_buckets_used,
+ (100.0 * n_buckets_used) / n_buckets);
+ fprintf (stream, "max bucket length: %u\n", max_bucket_length);
+}
+
+/* If ENTRY matches an entry already in the hash table, return the
+ entry from the table. Otherwise, return NULL. */
+
+void *
+hash_lookup (const Hash_table *table, const void *entry)
+{
+ struct hash_entry *bucket
+ = table->bucket + table->hasher (entry, table->n_buckets);
+ struct hash_entry *cursor;
+
+ if (! (bucket < table->bucket_limit))
+ abort ();
+
+ if (bucket->data == NULL)
+ return NULL;
+
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ if (table->comparator (entry, cursor->data))
+ return cursor->data;
+
+ return NULL;
+}
+
+/* Walking. */
+
+/* The functions in this page traverse the hash table and process the
+ contained entries. For the traversal to work properly, the hash table
+ should not be resized nor modified while any particular entry is being
+ processed. In particular, entries should not be added or removed. */
+
+/* Return the first data in the table, or NULL if the table is empty. */
+
+void *
+hash_get_first (const Hash_table *table)
+{
+ struct hash_entry *bucket;
+
+ if (table->n_entries == 0)
+ return NULL;
+
+ for (bucket = table->bucket; ; bucket++)
+ if (! (bucket < table->bucket_limit))
+ abort ();
+ else if (bucket->data)
+ return bucket->data;
+}
+
+/* Return the user data for the entry following ENTRY, where ENTRY has been
+ returned by a previous call to either `hash_get_first' or `hash_get_next'.
+ Return NULL if there are no more entries. */
+
+void *
+hash_get_next (const Hash_table *table, const void *entry)
+{
+ struct hash_entry *bucket
+ = table->bucket + table->hasher (entry, table->n_buckets);
+ struct hash_entry *cursor;
+
+ if (! (bucket < table->bucket_limit))
+ abort ();
+
+ /* Find next entry in the same bucket. */
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ if (cursor->data == entry && cursor->next)
+ return cursor->next->data;
+
+ /* Find first entry in any subsequent bucket. */
+ while (++bucket < table->bucket_limit)
+ if (bucket->data)
+ return bucket->data;
+
+ /* None found. */
+ return NULL;
+}
+
+/* Fill BUFFER with pointers to active user entries in the hash table, then
+ return the number of pointers copied. Do not copy more than BUFFER_SIZE
+ pointers. */
+
+unsigned
+hash_get_entries (const Hash_table *table, void **buffer,
+ unsigned buffer_size)
+{
+ unsigned counter = 0;
+ struct hash_entry *bucket;
+ struct hash_entry *cursor;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ if (counter >= buffer_size)
+ return counter;
+ buffer[counter++] = cursor->data;
+ }
+ }
+ }
+
+ return counter;
+}
+
+/* Call a PROCESSOR function for each entry of a hash table, and return the
+ number of entries for which the processor function returned success. A
+ pointer to some PROCESSOR_DATA which will be made available to each call to
+ the processor function. The PROCESSOR accepts two arguments: the first is
+ the user entry being walked into, the second is the value of PROCESSOR_DATA
+ as received. The walking continue for as long as the PROCESSOR function
+ returns nonzero. When it returns zero, the walking is interrupted. */
+
+unsigned
+hash_do_for_each (const Hash_table *table, Hash_processor processor,
+ void *processor_data)
+{
+ unsigned counter = 0;
+ struct hash_entry *bucket;
+ struct hash_entry *cursor;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ if (!(*processor) (cursor->data, processor_data))
+ return counter;
+ counter++;
+ }
+ }
+ }
+
+ return counter;
+}
+
+/* Allocation and clean-up. */
+
+/* Return a hash index for a NUL-terminated STRING between 0 and N_BUCKETS-1.
+ This is a convenience routine for constructing other hashing functions. */
+
+#if USE_DIFF_HASH
+
+/* About hashings, Paul Eggert writes to me (FP), on 1994-01-01: "Please see
+ B. J. McKenzie, R. Harries & T. Bell, Selecting a hashing algorithm,
+ Software--practice & experience 20, 2 (Feb 1990), 209-224. Good hash
+ algorithms tend to be domain-specific, so what's good for [diffutils'] io.c
+ may not be good for your application." */
+
+unsigned
+hash_string (const char *string, unsigned n_buckets)
+{
+# define ROTATE_LEFT(Value, Shift) \
+ ((Value) << (Shift) | (Value) >> ((sizeof (unsigned) * CHAR_BIT) - (Shift)))
+# define HASH_ONE_CHAR(Value, Byte) \
+ ((Byte) + ROTATE_LEFT (Value, 7))
+
+ unsigned value = 0;
+
+ for (; *string; string++)
+ value = HASH_ONE_CHAR (value, *(const unsigned char *) string);
+ return value % n_buckets;
+
+# undef ROTATE_LEFT
+# undef HASH_ONE_CHAR
+}
+
+#else /* not USE_DIFF_HASH */
+
+/* This one comes from `recode', and performs a bit better than the above as
+ per a few experiments. It is inspired from a hashing routine found in the
+ very old Cyber `snoop', itself written in typical Greg Mansfield style.
+ (By the way, what happened to this excellent man? Is he still alive?) */
+
+unsigned
+hash_string (const char *string, unsigned n_buckets)
+{
+ unsigned value = 0;
+
+ while (*string)
+ value = ((value * 31 + (int) *(const unsigned char *) string++)
+ % n_buckets);
+ return value;
+}
+
+#endif /* not USE_DIFF_HASH */
+
+/* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd
+ number at least equal to 11. */
+
+static bool
+is_prime (unsigned long candidate)
+{
+ unsigned long divisor = 3;
+ unsigned long square = divisor * divisor;
+
+ while (square < candidate && (candidate % divisor))
+ {
+ divisor++;
+ square += 4 * divisor;
+ divisor++;
+ }
+
+ return (candidate % divisor ? true : false);
+}
+
+/* Round a given CANDIDATE number up to the nearest prime, and return that
+ prime. Primes lower than 10 are merely skipped. */
+
+static unsigned long
+next_prime (unsigned long candidate)
+{
+ /* Skip small primes. */
+ if (candidate < 10)
+ candidate = 10;
+
+ /* Make it definitely odd. */
+ candidate |= 1;
+
+ while (!is_prime (candidate))
+ candidate += 2;
+
+ return candidate;
+}
+
+void
+hash_reset_tuning (Hash_tuning *tuning)
+{
+ *tuning = default_tuning;
+}
+
+/* For the given hash TABLE, check the user supplied tuning structure for
+ reasonable values, and return true if there is no gross error with it.
+ Otherwise, definitively reset the TUNING field to some acceptable default
+ in the hash table (that is, the user loses the right of further modifying
+ tuning arguments), and return false. */
+
+static bool
+check_tuning (Hash_table *table)
+{
+ const Hash_tuning *tuning = table->tuning;
+
+ if (tuning->growth_threshold > 0.0
+ && tuning->growth_threshold < 1.0
+ && tuning->growth_factor > 1.0
+ && tuning->shrink_threshold >= 0.0
+ && tuning->shrink_threshold < 1.0
+ && tuning->shrink_factor > tuning->shrink_threshold
+ && tuning->shrink_factor <= 1.0
+ && tuning->shrink_threshold < tuning->growth_threshold)
+ return true;
+
+ table->tuning = &default_tuning;
+ return false;
+}
+
+/* Allocate and return a new hash table, or NULL upon failure. The initial
+ number of buckets is automatically selected so as to _guarantee_ that you
+ may insert at least CANDIDATE different user entries before any growth of
+ the hash table size occurs. So, if have a reasonably tight a-priori upper
+ bound on the number of entries you intend to insert in the hash table, you
+ may save some table memory and insertion time, by specifying it here. If
+ the IS_N_BUCKETS field of the TUNING structure is true, the CANDIDATE
+ argument has its meaning changed to the wanted number of buckets.
+
+ TUNING points to a structure of user-supplied values, in case some fine
+ tuning is wanted over the default behavior of the hasher. If TUNING is
+ NULL, the default tuning parameters are used instead.
+
+ The user-supplied HASHER function should be provided. It accepts two
+ arguments ENTRY and TABLE_SIZE. It computes, by hashing ENTRY contents, a
+ slot number for that entry which should be in the range 0..TABLE_SIZE-1.
+ This slot number is then returned.
+
+ The user-supplied COMPARATOR function should be provided. It accepts two
+ arguments pointing to user data, it then returns true for a pair of entries
+ that compare equal, or false otherwise. This function is internally called
+ on entries which are already known to hash to the same bucket index.
+
+ The user-supplied DATA_FREER function, when not NULL, may be later called
+ with the user data as an argument, just before the entry containing the
+ data gets freed. This happens from within `hash_free' or `hash_clear'.
+ You should specify this function only if you want these functions to free
+ all of your `data' data. This is typically the case when your data is
+ simply an auxiliary struct that you have malloc'd to aggregate several
+ values. */
+
+Hash_table *
+hash_initialize (unsigned candidate, const Hash_tuning *tuning,
+ Hash_hasher hasher, Hash_comparator comparator,
+ Hash_data_freer data_freer)
+{
+ Hash_table *table;
+ struct hash_entry *bucket;
+
+ if (hasher == NULL || comparator == NULL)
+ return NULL;
+
+ table = (Hash_table *) malloc (sizeof (Hash_table));
+ if (table == NULL)
+ return NULL;
+
+ if (!tuning)
+ tuning = &default_tuning;
+ table->tuning = tuning;
+ if (!check_tuning (table))
+ {
+ /* Fail if the tuning options are invalid. This is the only occasion
+ when the user gets some feedback about it. Once the table is created,
+ if the user provides invalid tuning options, we silently revert to
+ using the defaults, and ignore further request to change the tuning
+ options. */
+ free (table);
+ return NULL;
+ }
+
+ table->n_buckets
+ = next_prime (tuning->is_n_buckets ? candidate
+ : (unsigned) (candidate / tuning->growth_threshold));
+
+ table->bucket = (struct hash_entry *)
+ malloc (table->n_buckets * sizeof (struct hash_entry));
+ if (table->bucket == NULL)
+ {
+ free (table);
+ return NULL;
+ }
+ table->bucket_limit = table->bucket + table->n_buckets;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ bucket->data = NULL;
+ bucket->next = NULL;
+ }
+ table->n_buckets_used = 0;
+ table->n_entries = 0;
+
+ table->hasher = hasher;
+ table->comparator = comparator;
+ table->data_freer = data_freer;
+
+ table->free_entry_list = NULL;
+#if USE_OBSTACK
+ obstack_init (&table->entry_stack);
+#endif
+ return table;
+}
+
+/* Make all buckets empty, placing any chained entries on the free list.
+ Apply the user-specified function data_freer (if any) to the datas of any
+ affected entries. */
+
+void
+hash_clear (Hash_table *table)
+{
+ struct hash_entry *bucket;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+
+ /* Free the bucket overflow. */
+ for (cursor = bucket->next; cursor; cursor = next)
+ {
+ if (table->data_freer)
+ (*table->data_freer) (cursor->data);
+ cursor->data = NULL;
+
+ next = cursor->next;
+ /* Relinking is done one entry at a time, as it is to be expected
+ that overflows are either rare or short. */
+ cursor->next = table->free_entry_list;
+ table->free_entry_list = cursor;
+ }
+
+ /* Free the bucket head. */
+ if (table->data_freer)
+ (*table->data_freer) (bucket->data);
+ bucket->data = NULL;
+ bucket->next = NULL;
+ }
+ }
+
+ table->n_buckets_used = 0;
+ table->n_entries = 0;
+}
+
+/* Reclaim all storage associated with a hash table. If a data_freer
+ function has been supplied by the user when the hash table was created,
+ this function applies it to the data of each entry before freeing that
+ entry. */
+
+void
+hash_free (Hash_table *table)
+{
+ struct hash_entry *bucket;
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+
+ /* Call the user data_freer function. */
+ if (table->data_freer && table->n_entries)
+ {
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ (*table->data_freer) (cursor->data);
+ }
+ }
+ }
+ }
+
+#if USE_OBSTACK
+
+ obstack_free (&table->entry_stack, NULL);
+
+#else
+
+ /* Free all bucket overflowed entries. */
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ for (cursor = bucket->next; cursor; cursor = next)
+ {
+ next = cursor->next;
+ free (cursor);
+ }
+ }
+
+ /* Also reclaim the internal list of previously freed entries. */
+ for (cursor = table->free_entry_list; cursor; cursor = next)
+ {
+ next = cursor->next;
+ free (cursor);
+ }
+
+#endif
+
+ /* Free the remainder of the hash table structure. */
+ free (table->bucket);
+ free (table);
+}
+
+/* Insertion and deletion. */
+
+/* Get a new hash entry for a bucket overflow, possibly by reclying a
+ previously freed one. If this is not possible, allocate a new one. */
+
+static struct hash_entry *
+allocate_entry (Hash_table *table)
+{
+ struct hash_entry *new;
+
+ if (table->free_entry_list)
+ {
+ new = table->free_entry_list;
+ table->free_entry_list = new->next;
+ }
+ else
+ {
+#if USE_OBSTACK
+ new = (struct hash_entry *)
+ obstack_alloc (&table->entry_stack, sizeof (struct hash_entry));
+#else
+ new = (struct hash_entry *) malloc (sizeof (struct hash_entry));
+#endif
+ }
+
+ return new;
+}
+
+/* Free a hash entry which was part of some bucket overflow,
+ saving it for later recycling. */
+
+static void
+free_entry (Hash_table *table, struct hash_entry *entry)
+{
+ entry->data = NULL;
+ entry->next = table->free_entry_list;
+ table->free_entry_list = entry;
+}
+
+/* This private function is used to help with insertion and deletion. When
+ ENTRY matches an entry in the table, return a pointer to the corresponding
+ user data and set *BUCKET_HEAD to the head of the selected bucket.
+ Otherwise, return NULL. When DELETE is true and ENTRY matches an entry in
+ the table, unlink the matching entry. */
+
+static void *
+hash_find_entry (Hash_table *table, const void *entry,
+ struct hash_entry **bucket_head, bool delete)
+{
+ struct hash_entry *bucket
+ = table->bucket + table->hasher (entry, table->n_buckets);
+ struct hash_entry *cursor;
+
+ if (! (bucket < table->bucket_limit))
+ abort ();
+
+ *bucket_head = bucket;
+
+ /* Test for empty bucket. */
+ if (bucket->data == NULL)
+ return NULL;
+
+ /* See if the entry is the first in the bucket. */
+ if ((*table->comparator) (entry, bucket->data))
+ {
+ void *data = bucket->data;
+
+ if (delete)
+ {
+ if (bucket->next)
+ {
+ struct hash_entry *next = bucket->next;
+
+ /* Bump the first overflow entry into the bucket head, then save
+ the previous first overflow entry for later recycling. */
+ *bucket = *next;
+ free_entry (table, next);
+ }
+ else
+ {
+ bucket->data = NULL;
+ }
+ }
+
+ return data;
+ }
+
+ /* Scan the bucket overflow. */
+ for (cursor = bucket; cursor->next; cursor = cursor->next)
+ {
+ if ((*table->comparator) (entry, cursor->next->data))
+ {
+ void *data = cursor->next->data;
+
+ if (delete)
+ {
+ struct hash_entry *next = cursor->next;
+
+ /* Unlink the entry to delete, then save the freed entry for later
+ recycling. */
+ cursor->next = next->next;
+ free_entry (table, next);
+ }
+
+ return data;
+ }
+ }
+
+ /* No entry found. */
+ return NULL;
+}
+
+/* For an already existing hash table, change the number of buckets through
+ specifying CANDIDATE. The contents of the hash table are preserved. The
+ new number of buckets is automatically selected so as to _guarantee_ that
+ the table may receive at least CANDIDATE different user entries, including
+ those already in the table, before any other growth of the hash table size
+ occurs. If TUNING->IS_N_BUCKETS is true, then CANDIDATE specifies the
+ exact number of buckets desired. */
+
+bool
+hash_rehash (Hash_table *table, unsigned candidate)
+{
+ Hash_table *new_table;
+ struct hash_entry *bucket;
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+
+ new_table = hash_initialize (candidate, table->tuning, table->hasher,
+ table->comparator, table->data_freer);
+ if (new_table == NULL)
+ return false;
+
+ /* Merely reuse the extra old space into the new table. */
+#if USE_OBSTACK
+ obstack_free (&new_table->entry_stack, NULL);
+ new_table->entry_stack = table->entry_stack;
+#endif
+ new_table->free_entry_list = table->free_entry_list;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ if (bucket->data)
+ for (cursor = bucket; cursor; cursor = next)
+ {
+ void *data = cursor->data;
+ struct hash_entry *new_bucket
+ = (new_table->bucket
+ + new_table->hasher (data, new_table->n_buckets));
+
+ if (! (new_bucket < new_table->bucket_limit))
+ abort ();
+
+ next = cursor->next;
+
+ if (new_bucket->data)
+ {
+ if (cursor == bucket)
+ {
+ /* Allocate or recycle an entry, when moving from a bucket
+ header into a bucket overflow. */
+ struct hash_entry *new_entry = allocate_entry (new_table);
+
+ if (new_entry == NULL)
+ return false;
+
+ new_entry->data = data;
+ new_entry->next = new_bucket->next;
+ new_bucket->next = new_entry;
+ }
+ else
+ {
+ /* Merely relink an existing entry, when moving from a
+ bucket overflow into a bucket overflow. */
+ cursor->next = new_bucket->next;
+ new_bucket->next = cursor;
+ }
+ }
+ else
+ {
+ /* Free an existing entry, when moving from a bucket
+ overflow into a bucket header. Also take care of the
+ simple case of moving from a bucket header into a bucket
+ header. */
+ new_bucket->data = data;
+ new_table->n_buckets_used++;
+ if (cursor != bucket)
+ free_entry (new_table, cursor);
+ }
+ }
+
+ free (table->bucket);
+ table->bucket = new_table->bucket;
+ table->bucket_limit = new_table->bucket_limit;
+ table->n_buckets = new_table->n_buckets;
+ table->n_buckets_used = new_table->n_buckets_used;
+ table->free_entry_list = new_table->free_entry_list;
+ /* table->n_entries already holds its value. */
+#if USE_OBSTACK
+ table->entry_stack = new_table->entry_stack;
+#endif
+ free (new_table);
+
+ return true;
+}
+
+/* If ENTRY matches an entry already in the hash table, return the pointer
+ to the entry from the table. Otherwise, insert ENTRY and return ENTRY.
+ Return NULL if the storage required for insertion cannot be allocated. */
+
+void *
+hash_insert (Hash_table *table, const void *entry)
+{
+ void *data;
+ struct hash_entry *bucket;
+
+ /* The caller cannot insert a NULL entry. */
+ if (! entry)
+ abort ();
+
+ /* If there's a matching entry already in the table, return that. */
+ if ((data = hash_find_entry (table, entry, &bucket, false)) != NULL)
+ return data;
+
+ /* ENTRY is not matched, it should be inserted. */
+
+ if (bucket->data)
+ {
+ struct hash_entry *new_entry = allocate_entry (table);
+
+ if (new_entry == NULL)
+ return NULL;
+
+ /* Add ENTRY in the overflow of the bucket. */
+
+ new_entry->data = (void *) entry;
+ new_entry->next = bucket->next;
+ bucket->next = new_entry;
+ table->n_entries++;
+ return (void *) entry;
+ }
+
+ /* Add ENTRY right in the bucket head. */
+
+ bucket->data = (void *) entry;
+ table->n_entries++;
+ table->n_buckets_used++;
+
+ /* If the growth threshold of the buckets in use has been reached, increase
+ the table size and rehash. There's no point in checking the number of
+ entries: if the hashing function is ill-conditioned, rehashing is not
+ likely to improve it. */
+
+ if (table->n_buckets_used
+ > table->tuning->growth_threshold * table->n_buckets)
+ {
+ /* Check more fully, before starting real work. If tuning arguments
+ became invalid, the second check will rely on proper defaults. */
+ check_tuning (table);
+ if (table->n_buckets_used
+ > table->tuning->growth_threshold * table->n_buckets)
+ {
+ const Hash_tuning *tuning = table->tuning;
+ unsigned candidate
+ = (unsigned) (tuning->is_n_buckets
+ ? (table->n_buckets * tuning->growth_factor)
+ : (table->n_buckets * tuning->growth_factor
+ * tuning->growth_threshold));
+
+ /* If the rehash fails, arrange to return NULL. */
+ if (!hash_rehash (table, candidate))
+ entry = NULL;
+ }
+ }
+
+ return (void *) entry;
+}
+
+/* If ENTRY is already in the table, remove it and return the just-deleted
+ data (the user may want to deallocate its storage). If ENTRY is not in the
+ table, don't modify the table and return NULL. */
+
+void *
+hash_delete (Hash_table *table, const void *entry)
+{
+ void *data;
+ struct hash_entry *bucket;
+
+ data = hash_find_entry (table, entry, &bucket, true);
+ if (!data)
+ return NULL;
+
+ table->n_entries--;
+ if (!bucket->data)
+ {
+ table->n_buckets_used--;
+
+ /* If the shrink threshold of the buckets in use has been reached,
+ rehash into a smaller table. */
+
+ if (table->n_buckets_used
+ < table->tuning->shrink_threshold * table->n_buckets)
+ {
+ /* Check more fully, before starting real work. If tuning arguments
+ became invalid, the second check will rely on proper defaults. */
+ check_tuning (table);
+ if (table->n_buckets_used
+ < table->tuning->shrink_threshold * table->n_buckets)
+ {
+ const Hash_tuning *tuning = table->tuning;
+ unsigned candidate
+ = (unsigned) (tuning->is_n_buckets
+ ? table->n_buckets * tuning->shrink_factor
+ : (table->n_buckets * tuning->shrink_factor
+ * tuning->growth_threshold));
+
+ hash_rehash (table, candidate);
+ }
+ }
+ }
+
+ return data;
+}
+
+/* Testing. */
+
+#if TESTING
+
+void
+hash_print (const Hash_table *table)
+{
+ struct hash_entry *bucket;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ struct hash_entry *cursor;
+
+ if (bucket)
+ printf ("%d:\n", bucket - table->bucket);
+
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ char *s = (char *) cursor->data;
+ /* FIXME */
+ if (s)
+ printf (" %s\n", s);
+ }
+ }
+}
+
+#endif /* TESTING */
diff --git a/hash.h b/hash.h
new file mode 100644
index 0000000..77e76d0
--- /dev/null
+++ b/hash.h
@@ -0,0 +1,87 @@
+/* hash - hashing table processing.
+ Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
+ Written by Jim Meyering <meyering@ascend.com>, 1998.
+
+ 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. */
+
+/* A generic hash table package. */
+
+/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
+ obstacks instead of malloc, and recompile `hash.c' with same setting. */
+
+#ifndef HASH_H_
+# define HASH_H_
+
+# include <stdio.h>
+
+typedef unsigned (*Hash_hasher) (const void *, unsigned);
+typedef bool (*Hash_comparator) (const void *, const void *);
+typedef void (*Hash_data_freer) (void *);
+typedef bool (*Hash_processor) (void *, void *);
+
+struct hash_entry
+ {
+ void *data;
+ struct hash_entry *next;
+ };
+
+struct hash_tuning
+ {
+ /* This structure is mainly used for `hash_initialize', see the block
+ documentation of `hash_reset_tuning' for more complete comments. */
+
+ float shrink_threshold; /* ratio of used buckets to trigger a shrink */
+ float shrink_factor; /* ratio of new smaller size to original size */
+ float growth_threshold; /* ratio of used buckets to trigger a growth */
+ float growth_factor; /* ratio of new bigger size to original size */
+ bool is_n_buckets; /* if CANDIDATE really means table size */
+ };
+
+typedef struct hash_tuning Hash_tuning;
+
+struct hash_table;
+
+typedef struct hash_table Hash_table;
+
+/* Information and lookup. */
+unsigned hash_get_n_buckets (const Hash_table *);
+unsigned hash_get_n_buckets_used (const Hash_table *);
+unsigned hash_get_n_entries (const Hash_table *);
+unsigned hash_get_max_bucket_length (const Hash_table *);
+bool hash_table_ok (const Hash_table *);
+void hash_print_statistics (const Hash_table *, FILE *);
+void *hash_lookup (const Hash_table *, const void *);
+
+/* Walking. */
+void *hash_get_first (const Hash_table *);
+void *hash_get_next (const Hash_table *, const void *);
+unsigned hash_get_entries (const Hash_table *, void **, unsigned);
+unsigned hash_do_for_each (const Hash_table *, Hash_processor, void *);
+
+/* Allocation and clean-up. */
+unsigned hash_string (const char *, unsigned);
+void hash_reset_tuning (Hash_tuning *);
+Hash_table *hash_initialize (unsigned, const Hash_tuning *,
+ Hash_hasher, Hash_comparator,
+ Hash_data_freer);
+void hash_clear (Hash_table *);
+void hash_free (Hash_table *);
+
+/* Insertion and deletion. */
+bool hash_rehash (Hash_table *, unsigned);
+void *hash_insert (Hash_table *, const void *);
+void *hash_delete (Hash_table *, const void *);
+
+#endif
diff --git a/inp.c b/inp.c
index bc899e9..15681b3 100644
--- a/inp.c
+++ b/inp.c
@@ -1,10 +1,10 @@
/* inputting files to be patched */
-/* $Id: inp.c,v 1.26 2003/09/11 18:36:17 eggert Exp $ */
+/* $Id: inp.c,v 1.26 2003/09/11 18:36:17 eggert Exp eggert $ */
/* Copyright (C) 1986, 1988 Larry Wall
- Copyright (C) 1991, 1992, 1993, 1997, 1998, 1999, 2002, 2003 Free
- Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1997, 1998, 1999, 2002, 2003, 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,7 +19,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#define XTERN extern
#include <common.h>
@@ -380,7 +380,7 @@ plan_b (char const *filename)
if (revision)
report_revision (found_revision);
- Fseek (ifp, (off_t) 0, SEEK_SET); /* rewind file */
+ Fseek (ifp, 0, SEEK_SET); /* rewind file */
for (tibufsize = TIBUFSIZE_MINIMUM; tibufsize < maxlen; tibufsize <<= 1)
continue;
lines_per_buf = tibufsize / maxlen;
@@ -452,8 +452,8 @@ ifetch (LINENUM line, bool whichbuf, size_t *psize)
whichbuf = true;
else {
tiline[whichbuf] = baseline;
- if (lseek (tifd, (off_t) (baseline/lines_per_buf * tibufsize),
- SEEK_SET) == -1
+ if ((lseek (tifd, baseline/lines_per_buf * tibufsize, SEEK_SET)
+ == -1)
|| read (tifd, tibuf[whichbuf], tibufsize) < 0)
read_fatal ();
}
diff --git a/inp.h b/inp.h
index 6f3e812..982837a 100644
--- a/inp.h
+++ b/inp.h
@@ -1,6 +1,6 @@
/* inputting files to be patched */
-/* $Id: inp.h,v 1.7 2003/05/20 14:05:22 eggert Exp $ */
+/* $Id: inp.h,v 1.7 2003/05/20 14:05:22 eggert Exp eggert $ */
/* Copyright (C) 1986, 1988 Larry Wall
Copyright (C) 1991, 1992, 1993, 1997, 1998, 1999, 2002, 2003
@@ -19,7 +19,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
XTERN LINENUM input_lines; /* how long is input file in lines */
diff --git a/install-sh b/install-sh
new file mode 100755
index 0000000..2c1f877
--- /dev/null
+++ b/install-sh
@@ -0,0 +1,286 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2003-06-13.21
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch. It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=
+transform_arg=
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=
+chgrpcmd=
+stripcmd=
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=
+dst=
+dir_arg=
+
+usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
+ or: $0 -d DIR1 DIR2...
+
+In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
+In the second, create the directory path DIR.
+
+Options:
+-b=TRANSFORMBASENAME
+-c copy source (using $cpprog) instead of moving (using $mvprog).
+-d create directories instead of installing files.
+-g GROUP $chgrp installed files to GROUP.
+-m MODE $chmod installed files to MODE.
+-o USER $chown installed files to USER.
+-s strip installed files (using $stripprog).
+-t=TRANSFORM
+--help display this help and exit.
+--version display version info and exit.
+
+Environment variables override the default commands:
+ CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
+"
+
+while test -n "$1"; do
+ case $1 in
+ -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+ shift
+ continue;;
+
+ -c) instcmd=$cpprog
+ shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ --help) echo "$usage"; exit 0;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd=$stripprog
+ shift
+ continue;;
+
+ -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+ shift
+ continue;;
+
+ --version) echo "$0 $scriptversion"; exit 0;;
+
+ *) if test -z "$src"; then
+ src=$1
+ else
+ # this colon is to work around a 386BSD /bin/sh bug
+ :
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if test -z "$src"; then
+ echo "$0: no input file specified." >&2
+ exit 1
+fi
+
+if test -n "$dir_arg"; then
+ dst=$src
+ src=
+
+ if test -d "$dst"; then
+ instcmd=:
+ chmodcmd=
+ else
+ instcmd=$mkdirprog
+ fi
+else
+ # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+ # might cause directories to be created, which would be especially bad
+ # if $src (and thus $dsttmp) contains '*'.
+ if test ! -f "$src" && test ! -d "$src"; then
+ echo "$0: $src does not exist." >&2
+ exit 1
+ fi
+
+ if test -z "$dst"; then
+ echo "$0: no destination specified." >&2
+ exit 1
+ fi
+
+ # If destination is a directory, append the input filename; won't work
+ # if double slashes aren't ignored.
+ if test -d "$dst"; then
+ dst=$dst/`basename "$src"`
+ fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+# (this part is taken from Noah Friedman's mkinstalldirs script.)
+
+# Skip lots of stat calls in the usual case.
+if test ! -d "$dstdir"; then
+ defaultIFS='
+ '
+ IFS="${IFS-$defaultIFS}"
+
+ oIFS=$IFS
+ # Some sh's can't handle IFS=/ for some reason.
+ IFS='%'
+ set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
+ IFS=$oIFS
+
+ pathcomp=
+
+ while test $# -ne 0 ; do
+ pathcomp=$pathcomp$1
+ shift
+ test -d "$pathcomp" || $mkdirprog "$pathcomp"
+ pathcomp=$pathcomp/
+ done
+fi
+
+if test -n "$dir_arg"; then
+ $doit $instcmd "$dst" \
+ && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
+ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
+ && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
+ && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
+
+else
+ # If we're going to rename the final executable, determine the name now.
+ if test -z "$transformarg"; then
+ dstfile=`basename "$dst"`
+ else
+ dstfile=`basename "$dst" $transformbasename \
+ | sed $transformarg`$transformbasename
+ fi
+
+ # don't allow the sed command to completely eliminate the filename.
+ test -z "$dstfile" && dstfile=`basename "$dst"`
+
+ # Make a couple of temp file names in the proper directory.
+ dsttmp=$dstdir/_inst.$$_
+ rmtmp=$dstdir/_rm.$$_
+
+ # Trap to clean up those temp files at exit.
+ trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
+ trap '(exit $?); exit' 1 2 13 15
+
+ # Move or copy the file name to the temp name
+ $doit $instcmd "$src" "$dsttmp" &&
+
+ # and set any options; do chmod last to preserve setuid bits.
+ #
+ # If any of these fail, we abort the whole thing. If we want to
+ # ignore errors from any of these, just make sure not to ignore
+ # errors from the above "$doit $instcmd $src $dsttmp" command.
+ #
+ { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
+ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
+ && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
+ && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
+
+ # Now remove or move aside any old file at destination location. We
+ # try this two ways since rm can't unlink itself on some systems and
+ # the destination file might be busy for other reasons. In this case,
+ # the final cleanup might fail but the new file should still install
+ # successfully.
+ {
+ if test -f "$dstdir/$dstfile"; then
+ $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
+ || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
+ || {
+ echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+ (exit 1); exit
+ }
+ else
+ :
+ fi
+ } &&
+
+ # Now rename the file to the real destination.
+ $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+fi &&
+
+# The final little trick to "correctly" pass the exit status to the exit trap.
+{
+ (exit 0); exit
+}
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
diff --git a/m4/backupfile.m4 b/m4/backupfile.m4
new file mode 100644
index 0000000..f3c2aa5
--- /dev/null
+++ b/m4/backupfile.m4
@@ -0,0 +1,21 @@
+# backupfile.m4 serial 3
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_BACKUPFILE],
+[
+ dnl Prerequisites of lib/backupfile.c.
+ AC_REQUIRE([AC_HEADER_DIRENT])
+ AC_REQUIRE([AC_FUNC_CLOSEDIR_VOID])
+ jm_CHECK_TYPE_STRUCT_DIRENT_D_INO
+
+ dnl Prerequisites of lib/addext.c.
+ AC_REQUIRE([jm_AC_DOS])
+ AC_REQUIRE([AC_SYS_LONG_FILE_NAMES])
+ AC_CHECK_HEADERS_ONCE(unistd.h)
+ AC_CHECK_FUNCS(pathconf)
+])
diff --git a/m4/d-ino.m4 b/m4/d-ino.m4
new file mode 100644
index 0000000..d2555e9
--- /dev/null
+++ b/m4/d-ino.m4
@@ -0,0 +1,42 @@
+#serial 5
+
+dnl From Jim Meyering.
+dnl
+dnl Check whether struct dirent has a member named d_ino.
+dnl
+
+AC_DEFUN([jm_CHECK_TYPE_STRUCT_DIRENT_D_INO],
+ [AC_REQUIRE([AC_HEADER_DIRENT])dnl
+ AC_CACHE_CHECK([for d_ino member in directory struct],
+ jm_cv_struct_dirent_d_ino,
+ [AC_TRY_LINK(dnl
+ [
+#include <sys/types.h>
+#ifdef HAVE_DIRENT_H
+# include <dirent.h>
+#else /* not HAVE_DIRENT_H */
+# define dirent direct
+# ifdef HAVE_SYS_NDIR_H
+# include <sys/ndir.h>
+# endif /* HAVE_SYS_NDIR_H */
+# ifdef HAVE_SYS_DIR_H
+# include <sys/dir.h>
+# endif /* HAVE_SYS_DIR_H */
+# ifdef HAVE_NDIR_H
+# include <ndir.h>
+# endif /* HAVE_NDIR_H */
+#endif /* HAVE_DIRENT_H */
+ ],
+ [struct dirent dp; dp.d_ino = 0;],
+
+ jm_cv_struct_dirent_d_ino=yes,
+ jm_cv_struct_dirent_d_ino=no)
+ ]
+ )
+ if test $jm_cv_struct_dirent_d_ino = yes; then
+ AC_DEFINE(D_INO_IN_DIRENT, 1,
+ [Define if there is a member named d_ino in the struct describing
+ directory headers.])
+ fi
+ ]
+)
diff --git a/m4/dirname.m4 b/m4/dirname.m4
new file mode 100644
index 0000000..9a5e6f5
--- /dev/null
+++ b/m4/dirname.m4
@@ -0,0 +1,15 @@
+# dirname.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_DIRNAME],
+[
+ dnl Prerequisites of lib/dirname.h.
+ AC_REQUIRE([jm_AC_DOS])
+
+ dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c.
+])
diff --git a/m4/dos.m4 b/m4/dos.m4
new file mode 100644
index 0000000..868626e
--- /dev/null
+++ b/m4/dos.m4
@@ -0,0 +1,53 @@
+#serial 5
+
+# Define some macros required for proper operation of code in lib/*.c
+# on MSDOS/Windows systems.
+
+# From Jim Meyering.
+
+AC_DEFUN([jm_AC_DOS],
+ [
+ AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos],
+ [
+ AC_TRY_COMPILE([],
+ [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__
+neither MSDOS nor Windows
+#endif],
+ [ac_cv_win_or_dos=yes],
+ [ac_cv_win_or_dos=no])
+ ])
+
+ if test x"$ac_cv_win_or_dos" = xyes; then
+ ac_fs_accepts_drive_letter_prefix=1
+ ac_fs_backslash_is_file_name_separator=1
+ else
+ ac_fs_accepts_drive_letter_prefix=0
+ ac_fs_backslash_is_file_name_separator=0
+ fi
+
+ AH_VERBATIM(FILESYSTEM_PREFIX_LEN,
+ [#if FILESYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
+# define FILESYSTEM_PREFIX_LEN(Filename) \
+ ((Filename)[0] && (Filename)[1] == ':' ? 2 : 0)
+#else
+# define FILESYSTEM_PREFIX_LEN(Filename) 0
+#endif])
+
+ AC_DEFINE_UNQUOTED([FILESYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX],
+ $ac_fs_accepts_drive_letter_prefix,
+ [Define on systems for which file names may have a so-called
+ `drive letter' prefix, define this to compute the length of that
+ prefix, including the colon.])
+
+ AH_VERBATIM(ISSLASH,
+ [#if FILESYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#else
+# define ISSLASH(C) ((C) == '/')
+#endif])
+
+ AC_DEFINE_UNQUOTED([FILESYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR],
+ $ac_fs_backslash_is_file_name_separator,
+ [Define if the backslash character may also serve as a file name
+ component separator.])
+ ])
diff --git a/m4/error.m4 b/m4/error.m4
new file mode 100644
index 0000000..05b28bf
--- /dev/null
+++ b/m4/error.m4
@@ -0,0 +1,15 @@
+#serial 8
+
+AC_DEFUN([gl_ERROR],
+[
+ AC_FUNC_ERROR_AT_LINE
+ dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]).
+ jm_PREREQ_ERROR
+])
+
+# Prerequisites of lib/error.c.
+AC_DEFUN([jm_PREREQ_ERROR],
+[
+ AC_REQUIRE([AC_FUNC_VPRINTF])
+ AC_FUNC_STRERROR_R
+])
diff --git a/m4/exitfail.m4 b/m4/exitfail.m4
new file mode 100644
index 0000000..fa5b149
--- /dev/null
+++ b/m4/exitfail.m4
@@ -0,0 +1,13 @@
+# exitfail.m4 serial 3
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_EXITFAIL],
+[
+ dnl No prerequisites of lib/exitfail.c.
+ :
+])
diff --git a/m4/extensions.m4 b/m4/extensions.m4
new file mode 100644
index 0000000..7faaa83
--- /dev/null
+++ b/m4/extensions.m4
@@ -0,0 +1,15 @@
+# gl_USE_SYSTEM_EXTENSIONS
+# ------------------------
+# Enable extensions on systems that normally disable them,
+# typically due to standards-conformance issues.
+AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [
+ AC_REQUIRE([AC_GNU_SOURCE])
+ AH_VERBATIM([__EXTENSIONS__],
+[/* Enable extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif])
+ AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
+ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
+ AC_DEFINE([__EXTENSIONS__])
+])
diff --git a/m4/getopt.m4 b/m4/getopt.m4
new file mode 100644
index 0000000..df602b9
--- /dev/null
+++ b/m4/getopt.m4
@@ -0,0 +1,13 @@
+# getopt.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_GETOPT],
+[
+ dnl Prerequisites of lib/getopt.c.
+ :
+])
diff --git a/m4/hash.m4 b/m4/hash.m4
new file mode 100644
index 0000000..9fe3211
--- /dev/null
+++ b/m4/hash.m4
@@ -0,0 +1,13 @@
+# hash.m4 serial 3
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_HASH],
+[
+ dnl Prerequisites of lib/hash.c.
+ AC_REQUIRE([AM_STDBOOL_H])
+])
diff --git a/m4/malloc.m4 b/m4/malloc.m4
new file mode 100644
index 0000000..2452acf
--- /dev/null
+++ b/m4/malloc.m4
@@ -0,0 +1,25 @@
+# malloc.m4 serial 7
+dnl Copyright (C) 2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+dnl From Jim Meyering.
+dnl Determine whether malloc accepts 0 as its argument.
+dnl If it doesn't, arrange to use the replacement function.
+
+AC_DEFUN([jm_FUNC_MALLOC],
+[
+ AC_REQUIRE([AC_FUNC_MALLOC])
+ dnl autoconf < 2.57 used the symbol ac_cv_func_malloc_works.
+ if test X"$ac_cv_func_malloc_0_nonnull" = Xno || test X"$ac_cv_func_malloc_works" = Xno; then
+ gl_PREREQ_MALLOC
+ fi
+])
+
+# Prerequisites of lib/malloc.c.
+AC_DEFUN([gl_PREREQ_MALLOC], [
+ :
+])
diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4
new file mode 100644
index 0000000..21e9daa
--- /dev/null
+++ b/m4/mbrtowc.m4
@@ -0,0 +1,27 @@
+# mbrtowc.m4 serial 5
+dnl Copyright (C) 2001-2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+dnl From Paul Eggert
+
+dnl This file can be removed, and jm_FUNC_MBRTOWC replaced with
+dnl AC_FUNC_MBRTOWC, when autoconf 2.57 can be assumed everywhere.
+
+AC_DEFUN([jm_FUNC_MBRTOWC],
+[
+ AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
+ jm_cv_func_mbrtowc,
+ [AC_TRY_LINK(
+ [#include <wchar.h>],
+ [mbstate_t state; return ! (sizeof state && mbrtowc);],
+ jm_cv_func_mbrtowc=yes,
+ jm_cv_func_mbrtowc=no)])
+ if test $jm_cv_func_mbrtowc = yes; then
+ AC_DEFINE(HAVE_MBRTOWC, 1,
+ [Define to 1 if mbrtowc and mbstate_t are properly declared.])
+ fi
+])
diff --git a/m4/mbstate_t.m4 b/m4/mbstate_t.m4
new file mode 100644
index 0000000..a07f51b
--- /dev/null
+++ b/m4/mbstate_t.m4
@@ -0,0 +1,32 @@
+# mbstate_t.m4 serial 9
+dnl Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+# From Paul Eggert.
+
+# BeOS 5 has <wchar.h> but does not define mbstate_t,
+# so you can't declare an object of that type.
+# Check for this incompatibility with Standard C.
+
+# AC_TYPE_MBSTATE_T
+# -----------------
+AC_DEFUN([AC_TYPE_MBSTATE_T],
+ [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [AC_INCLUDES_DEFAULT
+# include <wchar.h>],
+ [mbstate_t x; return sizeof x;])],
+ [ac_cv_type_mbstate_t=yes],
+ [ac_cv_type_mbstate_t=no])])
+ if test $ac_cv_type_mbstate_t = yes; then
+ AC_DEFINE([HAVE_MBSTATE_T], 1,
+ [Define to 1 if <wchar.h> declares mbstate_t.])
+ else
+ AC_DEFINE([mbstate_t], int,
+ [Define to a type if <wchar.h> does not define.])
+ fi])
diff --git a/m4/memchr.m4 b/m4/memchr.m4
new file mode 100644
index 0000000..60a06c2
--- /dev/null
+++ b/m4/memchr.m4
@@ -0,0 +1,20 @@
+# memchr.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_FUNC_MEMCHR],
+[
+ AC_REPLACE_FUNCS(memchr)
+ if test $ac_cv_func_memchr = no; then
+ jm_PREREQ_MEMCHR
+ fi
+])
+
+# Prerequisites of lib/memchr.c.
+AC_DEFUN([jm_PREREQ_MEMCHR], [
+ AC_CHECK_HEADERS(bp-sym.h)
+])
diff --git a/m4/mkdir.m4 b/m4/mkdir.m4
index 86315d0..3ae52ea 100644
--- a/m4/mkdir.m4
+++ b/m4/mkdir.m4
@@ -1,4 +1,4 @@
-#serial 1
+#serial 2
dnl From Mumit Khan and Paul Eggert
dnl Determine whether mkdir accepts only one argument instead of the usual two.
@@ -12,12 +12,18 @@ AC_DEFUN([PATCH_FUNC_MKDIR_TAKES_ONE_ARG],
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/stat.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
],
[mkdir (".", 0);],
,
[AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/stat.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
],
[mkdir (".");],
patch_cv_mkdir_takes_one_arg=yes
diff --git a/m4/onceonly.m4 b/m4/onceonly.m4
new file mode 100644
index 0000000..50b33f4
--- /dev/null
+++ b/m4/onceonly.m4
@@ -0,0 +1,63 @@
+# onceonly.m4 serial 3 (gettext-0.12)
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+dnl This file defines some "once only" variants of standard autoconf macros.
+dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
+dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
+dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
+dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC
+dnl The advantage is that the check for each of the headers/functions/decls
+dnl will be put only once into the 'configure' file. It keeps the size of
+dnl the 'configure' file down, and avoids redundant output when 'configure'
+dnl is run.
+dnl The drawback is that the checks cannot be conditionalized. If you write
+dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi
+dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to
+dnl empty, and the check will be inserted before the body of the AC_DEFUNed
+dnl function.
+
+dnl Autoconf version 2.57 or newer is recommended.
+AC_PREREQ(2.54)
+
+# AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of
+# AC_CHECK_HEADERS(HEADER1 HEADER2 ...).
+AC_DEFUN([AC_CHECK_HEADERS_ONCE], [
+ :
+ AC_FOREACH([gl_HEADER_NAME], [$1], [
+ AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(m4_defn([gl_HEADER_NAME]),
+ [-./], [___])), [
+ AC_CHECK_HEADERS(gl_HEADER_NAME)
+ ])
+ AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME,
+ [-./], [___])))
+ ])
+])
+
+# AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of
+# AC_CHECK_FUNCS(FUNC1 FUNC2 ...).
+AC_DEFUN([AC_CHECK_FUNCS_ONCE], [
+ :
+ AC_FOREACH([gl_FUNC_NAME], [$1], [
+ AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [
+ AC_CHECK_FUNCS(m4_defn([gl_FUNC_NAME]))
+ ])
+ AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]))
+ ])
+])
+
+# AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of
+# AC_CHECK_DECLS(DECL1, DECL2, ...).
+AC_DEFUN([AC_CHECK_DECLS_ONCE], [
+ :
+ AC_FOREACH([gl_DECL_NAME], [$1], [
+ AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [
+ AC_CHECK_DECLS(m4_defn([gl_DECL_NAME]))
+ ])
+ AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]))
+ ])
+])
diff --git a/m4/quote.m4 b/m4/quote.m4
new file mode 100644
index 0000000..14ce1b6
--- /dev/null
+++ b/m4/quote.m4
@@ -0,0 +1,13 @@
+# quote.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_QUOTE],
+[
+ dnl Prerequisites of lib/quote.c.
+ dnl (none)
+])
diff --git a/m4/quotearg.m4 b/m4/quotearg.m4
new file mode 100644
index 0000000..2fba109
--- /dev/null
+++ b/m4/quotearg.m4
@@ -0,0 +1,16 @@
+# quotearg.m4 serial 1
+dnl Copyright (C) 2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_QUOTEARG],
+[
+ dnl Prerequisites of lib/quotearg.c.
+ AC_CHECK_HEADERS_ONCE(wchar.h wctype.h)
+ AC_CHECK_FUNCS_ONCE(iswprint mbsinit)
+ AC_TYPE_MBSTATE_T
+ jm_FUNC_MBRTOWC
+])
diff --git a/m4/realloc.m4 b/m4/realloc.m4
new file mode 100644
index 0000000..9f746f1
--- /dev/null
+++ b/m4/realloc.m4
@@ -0,0 +1,25 @@
+# realloc.m4 serial 7
+dnl Copyright (C) 2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+dnl From Jim Meyering.
+dnl Determine whether realloc works when both arguments are 0.
+dnl If it doesn't, arrange to use the replacement function.
+
+AC_DEFUN([jm_FUNC_REALLOC],
+[
+ AC_REQUIRE([AC_FUNC_REALLOC])
+ dnl autoconf < 2.57 used the symbol ac_cv_func_realloc_works.
+ if test X"$ac_cv_func_realloc_0_nonnull" = Xno || test X"$ac_cv_func_realloc_works" = Xno; then
+ gl_PREREQ_REALLOC
+ fi
+])
+
+# Prerequisites of lib/realloc.c.
+AC_DEFUN([gl_PREREQ_REALLOC], [
+ :
+])
diff --git a/m4/setmode.m4 b/m4/setmode.m4
new file mode 100644
index 0000000..1af6bca
--- /dev/null
+++ b/m4/setmode.m4
@@ -0,0 +1,38 @@
+# Check for setmode, DOS style.
+
+# Copyright (C) 2001, 2002 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_DEFINE(HAVE_SETMODE_DOS, 1,
+ [Define to 1 if you have the DOS-style `setmode' function.])
+ fi])
diff --git a/m4/st_mtim.m4 b/m4/st_mtim.m4
new file mode 100644
index 0000000..4d03c8e
--- /dev/null
+++ b/m4/st_mtim.m4
@@ -0,0 +1,32 @@
+#serial 6
+
+dnl From Paul Eggert.
+
+# Define ST_MTIM_NSEC to be the nanoseconds member of struct stat's st_mtim,
+# if it exists.
+
+AC_DEFUN([AC_STRUCT_ST_MTIM_NSEC],
+ [AC_CACHE_CHECK([for nanoseconds member of struct stat.st_mtim],
+ ac_cv_struct_st_mtim_nsec,
+ [ac_save_CPPFLAGS="$CPPFLAGS"
+ ac_cv_struct_st_mtim_nsec=no
+ # tv_nsec -- the usual case
+ # _tv_nsec -- Solaris 2.6, if
+ # (defined _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED == 1
+ # && !defined __EXTENSIONS__)
+ # st__tim.tv_nsec -- UnixWare 2.1.2
+ for ac_val in tv_nsec _tv_nsec st__tim.tv_nsec; do
+ CPPFLAGS="$ac_save_CPPFLAGS -DST_MTIM_NSEC=$ac_val"
+ AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/stat.h>], [struct stat s; s.st_mtim.ST_MTIM_NSEC;],
+ [ac_cv_struct_st_mtim_nsec=$ac_val; break])
+ done
+ CPPFLAGS="$ac_save_CPPFLAGS"])
+
+ if test $ac_cv_struct_st_mtim_nsec != no; then
+ AC_DEFINE_UNQUOTED(ST_MTIM_NSEC, $ac_cv_struct_st_mtim_nsec,
+ [Define to be the nanoseconds member of struct stat's st_mtim,
+ if it exists.])
+ fi
+ ]
+)
diff --git a/m4/stdbool.m4 b/m4/stdbool.m4
new file mode 100644
index 0000000..ed000c8
--- /dev/null
+++ b/m4/stdbool.m4
@@ -0,0 +1,89 @@
+# Check for stdbool.h that conforms to C99.
+
+# Copyright (C) 2002-2003 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.
+
+# Prepare for substituting <stdbool.h> if it is not supported.
+
+AC_DEFUN([AM_STDBOOL_H],
+[
+ AC_REQUIRE([AC_HEADER_STDBOOL])
+
+ # Define two additional variables used in the Makefile substitution.
+
+ if test "$ac_cv_header_stdbool_h" = yes; then
+ STDBOOL_H=''
+ else
+ STDBOOL_H='stdbool.h'
+ fi
+ AC_SUBST([STDBOOL_H])
+
+ if test "$ac_cv_type__Bool" = yes; then
+ HAVE__BOOL=1
+ else
+ HAVE__BOOL=0
+ fi
+ AC_SUBST([HAVE__BOOL])
+])
+
+# This macro is only needed in autoconf <= 2.54. Newer versions of autoconf
+# have this macro built-in.
+
+AC_DEFUN([AC_HEADER_STDBOOL],
+ [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
+ [ac_cv_header_stdbool_h],
+ [AC_TRY_COMPILE(
+ [
+ #include <stdbool.h>
+ #ifndef bool
+ "error: bool is not defined"
+ #endif
+ #ifndef false
+ "error: false is not defined"
+ #endif
+ #if false
+ "error: false is not 0"
+ #endif
+ #ifndef true
+ "error: false is not defined"
+ #endif
+ #if true != 1
+ "error: true is not 1"
+ #endif
+ #ifndef __bool_true_false_are_defined
+ "error: __bool_true_false_are_defined is not defined"
+ #endif
+
+ struct s { _Bool s: 1; _Bool t; } s;
+
+ char a[true == 1 ? 1 : -1];
+ char b[false == 0 ? 1 : -1];
+ char c[__bool_true_false_are_defined == 1 ? 1 : -1];
+ char d[(bool) -0.5 == true ? 1 : -1];
+ bool e = &s;
+ char f[(_Bool) -0.0 == false ? 1 : -1];
+ char g[true];
+ char h[sizeof (_Bool)];
+ char i[sizeof s.t];
+ ],
+ [ return !a + !b + !c + !d + !e + !f + !g + !h + !i; ],
+ [ac_cv_header_stdbool_h=yes],
+ [ac_cv_header_stdbool_h=no])])
+ AC_CHECK_TYPES([_Bool])
+ if test $ac_cv_header_stdbool_h = yes; then
+ AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
+ fi])
diff --git a/m4/strcase.m4 b/m4/strcase.m4
new file mode 100644
index 0000000..3fd25d0
--- /dev/null
+++ b/m4/strcase.m4
@@ -0,0 +1,39 @@
+# strcase.m4 serial 1
+dnl Copyright (C) 2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_STRCASE],
+[
+ gl_FUNC_STRCASECMP
+ gl_FUNC_STRNCASECMP
+])
+
+AC_DEFUN([gl_FUNC_STRCASECMP],
+[
+ AC_REPLACE_FUNCS(strcasecmp)
+ if test $ac_cv_func_strcasecmp = no; then
+ gl_PREREQ_STRCASECMP
+ fi
+])
+
+AC_DEFUN([gl_FUNC_STRNCASECMP],
+[
+ AC_REPLACE_FUNCS(strncasecmp)
+ if test $ac_cv_func_strncasecmp = no; then
+ gl_PREREQ_STRNCASECMP
+ fi
+])
+
+# Prerequisites of lib/strcasecmp.c.
+AC_DEFUN([gl_PREREQ_STRCASECMP], [
+ :
+])
+
+# Prerequisites of lib/strncasecmp.c.
+AC_DEFUN([gl_PREREQ_STRNCASECMP], [
+ :
+])
diff --git a/m4/timespec.m4 b/m4/timespec.m4
new file mode 100644
index 0000000..5ca16d4
--- /dev/null
+++ b/m4/timespec.m4
@@ -0,0 +1,52 @@
+#serial 7
+
+dnl From Jim Meyering
+
+AC_DEFUN([gl_TIMESPEC],
+[
+ dnl Prerequisites of lib/timespec.h.
+ AC_REQUIRE([AC_HEADER_TIME])
+ AC_CHECK_HEADERS_ONCE(sys/time.h)
+ jm_CHECK_TYPE_STRUCT_TIMESPEC
+ AC_STRUCT_ST_MTIM_NSEC
+
+ dnl Persuade glibc <time.h> to declare nanosleep().
+ AC_REQUIRE([AC_GNU_SOURCE])
+
+ AC_CHECK_DECLS(nanosleep, , , [#include <time.h>])
+])
+
+dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
+dnl in time.h or sys/time.h.
+
+AC_DEFUN([jm_CHECK_TYPE_STRUCT_TIMESPEC],
+[
+ dnl Persuade pedantic Solaris to declare struct timespec.
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ AC_REQUIRE([AC_HEADER_TIME])
+ AC_CHECK_HEADERS_ONCE(sys/time.h)
+ AC_CACHE_CHECK([for struct timespec], fu_cv_sys_struct_timespec,
+ [AC_TRY_COMPILE(
+ [
+# if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+# else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+# endif
+ ],
+ [static struct timespec x; x.tv_sec = x.tv_nsec;],
+ fu_cv_sys_struct_timespec=yes,
+ fu_cv_sys_struct_timespec=no)
+ ])
+
+ if test $fu_cv_sys_struct_timespec = yes; then
+ AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1,
+ [Define if struct timespec is declared in <time.h>. ])
+ fi
+])
diff --git a/m4/unlocked-io.m4 b/m4/unlocked-io.m4
new file mode 100644
index 0000000..f8e98f1
--- /dev/null
+++ b/m4/unlocked-io.m4
@@ -0,0 +1,22 @@
+#serial 8 -*- autoconf -*-
+
+dnl From Jim Meyering.
+dnl
+dnl See if the glibc *_unlocked I/O macros or functions are available.
+dnl Use only those *_unlocked macros or functions that are declared
+dnl (because some of them were declared in Solaris 2.5.1 but were removed
+dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run
+dnl on Solaris 2.6).
+
+AC_DEFUN([jm_FUNC_GLIBC_UNLOCKED_IO],
+[
+ dnl Persuade glibc and Solaris <stdio.h> to declare
+ dnl fgets_unlocked(), fputs_unlocked() etc.
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_DECLS_ONCE(
+ [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/utimbuf.m4 b/m4/utimbuf.m4
new file mode 100644
index 0000000..21724aa
--- /dev/null
+++ b/m4/utimbuf.m4
@@ -0,0 +1,40 @@
+#serial 5
+
+dnl From Jim Meyering
+
+dnl Define HAVE_STRUCT_UTIMBUF if `struct utimbuf' is declared --
+dnl usually in <utime.h>.
+dnl Some systems have utime.h but don't declare the struct anywhere.
+
+AC_DEFUN([jm_CHECK_TYPE_STRUCT_UTIMBUF],
+[
+ AC_CHECK_HEADERS_ONCE(sys/time.h utime.h)
+ AC_REQUIRE([AC_HEADER_TIME])
+ AC_CACHE_CHECK([for struct utimbuf], fu_cv_sys_struct_utimbuf,
+ [AC_TRY_COMPILE(
+ [
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+#ifdef HAVE_UTIME_H
+# include <utime.h>
+#endif
+ ],
+ [static struct utimbuf x; x.actime = x.modtime;],
+ fu_cv_sys_struct_utimbuf=yes,
+ fu_cv_sys_struct_utimbuf=no)
+ ])
+
+ if test $fu_cv_sys_struct_utimbuf = yes; then
+ AC_DEFINE(HAVE_STRUCT_UTIMBUF, 1,
+ [Define if struct utimbuf is declared -- usually in <utime.h>.
+ Some systems have utime.h but don't declare the struct anywhere. ])
+ fi
+])
diff --git a/m4/xalloc.m4 b/m4/xalloc.m4
new file mode 100644
index 0000000..5dcb730
--- /dev/null
+++ b/m4/xalloc.m4
@@ -0,0 +1,25 @@
+# xalloc.m4 serial 2
+dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_XALLOC],
+[
+ gl_PREREQ_XMALLOC
+ gl_PREREQ_XSTRDUP
+])
+
+# Prerequisites of lib/xmalloc.c.
+AC_DEFUN([gl_PREREQ_XMALLOC], [
+ AC_REQUIRE([AC_HEADER_STDC])
+ AC_REQUIRE([jm_FUNC_MALLOC])
+ AC_REQUIRE([jm_FUNC_REALLOC])
+])
+
+# Prerequisites of lib/xstrdup.c.
+AC_DEFUN([gl_PREREQ_XSTRDUP], [
+ :
+])
diff --git a/maketime.c b/maketime.c
index ebb6bee..3978cce 100644
--- a/maketime.c
+++ b/maketime.c
@@ -1,6 +1,6 @@
/* Convert struct partime into time_t. */
-/* Copyright 1992, 1993, 1994, 1995, 1997 Paul Eggert
+/* Copyright (C) 1992, 1993, 1994, 1995, 1997, 2003, 2006 Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING.
If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Report problems and direct all questions to:
@@ -31,44 +31,19 @@
Avoid mktime because it's not universal and because there's no easy,
portable way for mktime to yield the inverse of gmtime. */
-#if has_conf_h
-# include <conf.h>
-#else
-# if HAVE_CONFIG_H
-# include <config.h>
-# else
-# ifndef __STDC__
-# define const
-# endif
-# endif
- /* MIPS RISCOS4.52 defines time_t in <sys/types.h> not <time.h>. */
-# include <sys/types.h>
-# if HAVE_LIMITS_H
-# include <limits.h>
-# endif
-# ifndef LONG_MIN
-# define LONG_MIN (-1-2147483647L)
-# endif
-# if STDC_HEADERS
-# include <stdlib.h>
-# endif
-# include <time.h>
-# ifdef __STDC__
-# define P(x) x
-# else
-# define P(x) ()
-# endif
+#if HAVE_CONFIG_H
+# include <config.h>
#endif
-#include <partime.h>
#include <maketime.h>
-char const maket_id[] =
- "$Id: maketime.c,v 1.1 1999/08/29 11:12:37 eggert Exp $";
+#include <limits.h>
+#include <partime.h>
+#include <stdlib.h>
+#include <time.h>
-static int isleap P ((int));
-static int month_days P ((struct tm const *));
-static time_t maketime P ((struct partime const *, time_t));
+char const maket_id[] =
+ "$Id: maketime.c,v 1.1 1999/08/29 11:12:37 eggert Exp eggert $";
/* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
@@ -89,8 +64,7 @@ static time_t maketime P ((struct partime const *, time_t));
#define TM_YEAR_ORIGIN 1900
static int
-isleap (y)
- int y;
+isleap (int y)
{
return (y & 3) == 0 && (y % 100 != 0 || y % 400 == 0);
}
@@ -103,8 +77,7 @@ static int const month_yday[] =
/* Yield the number of days in TM's month. */
static int
-month_days (tm)
- struct tm const *tm;
+month_days (struct tm const *tm)
{
int m = tm->tm_mon;
return (month_yday[m + 1] - month_yday[m]
@@ -114,9 +87,7 @@ month_days (tm)
/* Convert UNIXTIME to struct tm form.
Use gmtime if available and if !LOCALZONE, localtime otherwise. */
struct tm *
-time2tm (unixtime, localzone)
- time_t unixtime;
- int localzone;
+time2tm (time_t unixtime, int localzone)
{
struct tm *tm;
#ifdef TZ_is_unset
@@ -131,9 +102,7 @@ time2tm (unixtime, localzone)
/* Yield A - B, measured in seconds. */
time_t
-difftm (a, b)
- struct tm const *a;
- struct tm const *b;
+difftm (struct tm const *a, struct tm const *b)
{
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
@@ -162,9 +131,7 @@ difftm (a, b)
Adjust only T's year, mon, mday, hour, min and sec members;
plus adjust wday if it is defined. */
void
-adjzone (t, seconds)
- register struct tm *t;
- long seconds;
+adjzone (register struct tm *t, long seconds)
{
int days = 0;
@@ -223,9 +190,7 @@ adjzone (t, seconds)
POSIX 1003.1 doesn't allow leap seconds, but some implementations
have them anyway, so allow them if localtime/gmtime does. */
time_t
-tm2time (tm, localzone)
- struct tm *tm;
- int localzone;
+tm2time (struct tm *tm, int localzone)
{
/* Cache the most recent t,tm pairs; 1 for gmtime, 1 for localtime. */
static time_t t_cache[2];
@@ -294,9 +259,7 @@ tm2time (tm, localzone)
Yield -1 on failure.
ISO 8601 day-of-year and week numbers are not yet supported. */
static time_t
-maketime (pt, default_time)
- struct partime const *pt;
- time_t default_time;
+maketime (struct partime const *pt, time_t default_time)
{
int localzone, wday, year;
struct tm tm;
@@ -465,10 +428,7 @@ maketime (pt, default_time)
time and zone is used.
Return (time_t) -1 if the time is invalid or cannot be represented. */
time_t
-str2time (source, default_time, default_zone)
- char const **source;
- time_t default_time;
- long default_zone;
+str2time (char const **source, time_t default_time, long default_zone)
{
struct partime pt;
@@ -481,11 +441,9 @@ str2time (source, default_time, default_zone)
#ifdef TEST
#include <stdio.h>
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
- time_t default_time = time ((time_t *) 0);
+ time_t default_time = time (0);
long default_zone = argv[1] ? atol (argv[1]) : TM_LOCAL_ZONE;
char buf[1000];
while (fgets (buf, sizeof (buf), stdin))
diff --git a/maketime.h b/maketime.h
index 2f977c4..c24b751 100644
--- a/maketime.h
+++ b/maketime.h
@@ -1,6 +1,6 @@
/* Yield time_t from struct partime yielded by partime. */
-/* Copyright 1993, 1994, 1995 Paul Eggert
+/* Copyright (C) 1993, 1994, 1995, 2003, 2006 Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING.
If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Report problems and direct all questions to:
@@ -26,14 +26,10 @@
*/
-#if defined __STDC__ || has_prototypes
-# define __MAKETIME_P(x) x
-#else
-# define __MAKETIME_P(x) ()
-#endif
-
-struct tm *time2tm __MAKETIME_P ((time_t, int));
-time_t difftm __MAKETIME_P ((struct tm const *, struct tm const *));
-time_t str2time __MAKETIME_P ((char const **, time_t, long));
-time_t tm2time __MAKETIME_P ((struct tm *, int));
-void adjzone __MAKETIME_P ((struct tm *, long));
+#include <time.h>
+
+struct tm *time2tm (time_t, int);
+time_t difftm (struct tm const *, struct tm const *);
+time_t str2time (char const **, time_t, long);
+time_t tm2time (struct tm *, int);
+void adjzone (struct tm *, long);
diff --git a/malloc.c b/malloc.c
index b859e58..a43d169 100644
--- a/malloc.c
+++ b/malloc.c
@@ -1,5 +1,5 @@
/* Work around bug on some systems where malloc (0) fails.
- Copyright (C) 1997 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998 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
@@ -22,16 +22,13 @@
#endif
#undef malloc
-#include <sys/types.h>
-
-char *malloc ();
+#include <stdlib.h>
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
-char *
-rpl_malloc (n)
- size_t n;
+void *
+rpl_malloc (size_t n)
{
if (n == 0)
n = 1;
diff --git a/memchr.c b/memchr.c
new file mode 100644
index 0000000..ae232ae
--- /dev/null
+++ b/memchr.c
@@ -0,0 +1,200 @@
+/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free
+ Software Foundation, Inc.
+
+ Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
+ with help from Dan Sahlin (dan@sics.se) and
+ commentary by Jim Blandy (jimb@ai.mit.edu);
+ adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
+ and implemented by Roland McGrath (roland@ai.mit.edu).
+
+NOTE: The canonical source of this file is maintained with the GNU C Library.
+Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#if defined _LIBC
+# include <memcopy.h>
+#else
+# define reg_char char
+#endif
+
+#include <limits.h>
+#include <stdlib.h>
+
+#define LONG_MAX_32_BITS 2147483647
+
+#include <sys/types.h>
+#if HAVE_BP_SYM_H || defined _LIBC
+# include <bp-sym.h>
+#else
+# define BP_SYM(sym) sym
+#endif
+
+#undef memchr
+#undef __memchr
+
+/* Search no more than N bytes of S for C. */
+void *
+__memchr (void const *s, int c_in, size_t n)
+{
+ const unsigned char *char_ptr;
+ const unsigned long int *longword_ptr;
+ unsigned long int longword, magic_bits, charmask;
+ unsigned reg_char c;
+
+ c = (unsigned char) c_in;
+
+ /* Handle the first few characters by reading one character at a time.
+ Do this until CHAR_PTR is aligned on a longword boundary. */
+ for (char_ptr = (const unsigned char *) s;
+ n > 0 && ((unsigned long int) char_ptr
+ & (sizeof (longword) - 1)) != 0;
+ --n, ++char_ptr)
+ if (*char_ptr == c)
+ return (void *) char_ptr;
+
+ /* All these elucidatory comments refer to 4-byte longwords,
+ but the theory applies equally well to 8-byte longwords. */
+
+ longword_ptr = (unsigned long int *) char_ptr;
+
+ /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
+ the "holes." Note that there is a hole just to the left of
+ each byte, with an extra at the end:
+
+ bits: 01111110 11111110 11111110 11111111
+ bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
+
+ The 1-bits make sure that carries propagate to the next 0-bit.
+ The 0-bits provide holes for carries to fall into. */
+
+ if (sizeof (longword) != 4 && sizeof (longword) != 8)
+ abort ();
+
+#if LONG_MAX <= LONG_MAX_32_BITS
+ magic_bits = 0x7efefeff;
+#else
+ magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
+#endif
+
+ /* Set up a longword, each of whose bytes is C. */
+ charmask = c | (c << 8);
+ charmask |= charmask << 16;
+#if LONG_MAX > LONG_MAX_32_BITS
+ charmask |= charmask << 32;
+#endif
+
+ /* Instead of the traditional loop which tests each character,
+ we will test a longword at a time. The tricky part is testing
+ if *any of the four* bytes in the longword in question are zero. */
+ while (n >= sizeof (longword))
+ {
+ /* We tentatively exit the loop if adding MAGIC_BITS to
+ LONGWORD fails to change any of the hole bits of LONGWORD.
+
+ 1) Is this safe? Will it catch all the zero bytes?
+ Suppose there is a byte with all zeros. Any carry bits
+ propagating from its left will fall into the hole at its
+ least significant bit and stop. Since there will be no
+ carry from its most significant bit, the LSB of the
+ byte to the left will be unchanged, and the zero will be
+ detected.
+
+ 2) Is this worthwhile? Will it ignore everything except
+ zero bytes? Suppose every byte of LONGWORD has a bit set
+ somewhere. There will be a carry into bit 8. If bit 8
+ is set, this will carry into bit 16. If bit 8 is clear,
+ one of bits 9-15 must be set, so there will be a carry
+ into bit 16. Similarly, there will be a carry into bit
+ 24. If one of bits 24-30 is set, there will be a carry
+ into bit 31, so all of the hole bits will be changed.
+
+ The one misfire occurs when bits 24-30 are clear and bit
+ 31 is set; in this case, the hole at bit 31 is not
+ changed. If we had access to the processor carry flag,
+ we could close this loophole by putting the fourth hole
+ at bit 32!
+
+ So it ignores everything except 128's, when they're aligned
+ properly.
+
+ 3) But wait! Aren't we looking for C, not zero?
+ Good point. So what we do is XOR LONGWORD with a longword,
+ each of whose bytes is C. This turns each byte that is C
+ into a zero. */
+
+ longword = *longword_ptr++ ^ charmask;
+
+ /* Add MAGIC_BITS to LONGWORD. */
+ if ((((longword + magic_bits)
+
+ /* Set those bits that were unchanged by the addition. */
+ ^ ~longword)
+
+ /* Look at only the hole bits. If any of the hole bits
+ are unchanged, most likely one of the bytes was a
+ zero. */
+ & ~magic_bits) != 0)
+ {
+ /* Which of the bytes was C? If none of them were, it was
+ a misfire; continue the search. */
+
+ const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);
+
+ if (cp[0] == c)
+ return (void *) cp;
+ if (cp[1] == c)
+ return (void *) &cp[1];
+ if (cp[2] == c)
+ return (void *) &cp[2];
+ if (cp[3] == c)
+ return (void *) &cp[3];
+#if LONG_MAX > 2147483647
+ if (cp[4] == c)
+ return (void *) &cp[4];
+ if (cp[5] == c)
+ return (void *) &cp[5];
+ if (cp[6] == c)
+ return (void *) &cp[6];
+ if (cp[7] == c)
+ return (void *) &cp[7];
+#endif
+ }
+
+ n -= sizeof (longword);
+ }
+
+ char_ptr = (const unsigned char *) longword_ptr;
+
+ while (n-- > 0)
+ {
+ if (*char_ptr == c)
+ return (void *) char_ptr;
+ else
+ ++char_ptr;
+ }
+
+ return 0;
+}
+#ifdef weak_alias
+weak_alias (__memchr, BP_SYM (memchr))
+#endif
diff --git a/mkinstalldirs b/mkinstalldirs
new file mode 100755
index 0000000..8065dad
--- /dev/null
+++ b/mkinstalldirs
@@ -0,0 +1,124 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain.
+
+scriptversion=2003-06-14.23
+
+errstatus=0
+dirmode=""
+
+usage="\
+Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
+
+Create each directory DIR (with mode MODE, if specified), including all
+leading file name components.
+"
+
+# process command line arguments
+while test $# -gt 0 ; do
+ case $1 in
+ -h | --help | --h*) # -h for help
+ echo "$usage"
+ exit 0
+ ;;
+ -m) # -m PERM arg
+ shift
+ test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+ dirmode=$1
+ shift
+ ;;
+ --version)
+ echo "$0 $scriptversion"
+ exit 0
+ ;;
+ --) # stop option processing
+ shift
+ break
+ ;;
+ -*) # unknown option
+ echo "$usage" 1>&2
+ exit 1
+ ;;
+ *) # first non-opt arg
+ break
+ ;;
+ esac
+done
+
+for file
+do
+ if test -d "$file"; then
+ shift
+ else
+ break
+ fi
+done
+
+case $# in
+ 0) exit 0 ;;
+esac
+
+case $dirmode in
+ '')
+ if mkdir -p -- . 2>/dev/null; then
+ echo "mkdir -p -- $*"
+ exec mkdir -p -- "$@"
+ fi
+ ;;
+ *)
+ if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
+ echo "mkdir -m $dirmode -p -- $*"
+ exec mkdir -m "$dirmode" -p -- "$@"
+ fi
+ ;;
+esac
+
+for file
+do
+ set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+ shift
+
+ pathcomp=
+ for d
+ do
+ pathcomp="$pathcomp$d"
+ case $pathcomp in
+ -*) pathcomp=./$pathcomp ;;
+ esac
+
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp"
+
+ mkdir "$pathcomp" || lasterr=$?
+
+ if test ! -d "$pathcomp"; then
+ errstatus=$lasterr
+ else
+ if test ! -z "$dirmode"; then
+ echo "chmod $dirmode $pathcomp"
+ lasterr=""
+ chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+ if test ! -z "$lasterr"; then
+ errstatus=$lasterr
+ fi
+ fi
+ fi
+ fi
+
+ pathcomp="$pathcomp/"
+ done
+done
+
+exit $errstatus
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
diff --git a/partime.c b/partime.c
index 1732843..816ae69 100644
--- a/partime.c
+++ b/partime.c
@@ -1,6 +1,6 @@
/* Parse a string, yielding a struct partime that describes it. */
-/* Copyright (C) 1993, 1994, 1995, 1997, 2002 Paul Eggert
+/* Copyright (C) 1993, 1994, 1995, 1997, 2002, 2003, 2006 Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING.
If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Report problems and direct all questions to:
@@ -26,39 +26,16 @@
*/
-#if has_conf_h
-# include <conf.h>
-#else
-# if HAVE_CONFIG_H
-# include <config.h>
-# else
-# ifndef __STDC__
-# define const
-# endif
-# endif
-# if HAVE_LIMITS_H
-# include <limits.h>
-# endif
-# ifndef LONG_MIN
-# define LONG_MIN (-1-2147483647L)
-# endif
-# if HAVE_STDDEF_H
-# include <stddef.h>
-# endif
-# if STDC_HEADERS
-# include <stdlib.h>
-# endif
-# include <time.h>
-# ifdef __STDC__
-# define P(x) x
-# else
-# define P(x) ()
-# endif
+#if HAVE_CONFIG_H
+# include <config.h>
#endif
-#ifndef offsetof
-#define offsetof(aggregate, member) ((size_t) &((aggregate *) 0)->member)
-#endif
+#include <partime.h>
+
+#include <limits.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <time.h>
#include <ctype.h>
#if STDC_HEADERS
@@ -72,10 +49,8 @@
#define ISUPPER(c) (CTYPE_DOMAIN (c) && isupper (c))
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
-#include <partime.h>
-
char const partime_id[] =
- "$Id: partime.c,v 1.2 2002/02/18 07:42:58 eggert Exp $";
+ "$Id: partime.c,v 1.2 2002/02/18 07:42:58 eggert Exp eggert $";
/* Lookup tables for names of months, weekdays, time zones. */
@@ -89,15 +64,7 @@ struct name_val
};
-static char const *parse_decimal P ((char const *, int, int, int, int, int *, int *));
-static char const *parse_fixed P ((char const *, int, int *));
-static char const *parse_pattern_letter P ((char const *, int, struct partime *));
-static char const *parse_prefix P ((char const *, char const **, struct partime *));
-static char const *parse_ranged P ((char const *, int, int, int, int *));
-static char const *parse_varying P ((char const *, int *));
-static int lookup P ((char const *, struct name_val const[]));
-static int merge_partime P ((struct partime *, struct partime const *));
-static void undefine P ((struct partime *));
+static char const *parse_pattern_letter (char const *, int, struct partime *);
static struct name_val const month_names[] =
@@ -220,9 +187,7 @@ static struct name_val const zone_names[] =
/* Look for a prefix of S in TABLE, returning val for first matching entry. */
static int
-lookup (s, table)
- char const *s;
- struct name_val const table[];
+lookup (char const *s, struct name_val const table[])
{
int j;
char buf[NAME_LENGTH_MAXIMUM];
@@ -251,8 +216,7 @@ lookup (s, table)
/* Set *T to ``undefined'' values. */
static void
-undefine (t)
- struct partime *t;
+undefine (struct partime *t)
{
t->tm.tm_sec = t->tm.tm_min = t->tm.tm_hour = t->tm.tm_mday = t->tm.tm_mon
= t->tm.tm_year = t->tm.tm_wday = t->tm.tm_yday
@@ -350,10 +314,7 @@ static char const time_patterns[] =
Set *PATTERNS to 0 if we know there are no more patterns to try;
if *PATTERNS is initially 0, give up immediately. */
static char const *
-parse_prefix (str, patterns, t)
- char const *str;
- char const **patterns;
- struct partime *t;
+parse_prefix (char const *str, char const **patterns, struct partime *t)
{
char const *pat = *patterns;
unsigned char c;
@@ -401,9 +362,7 @@ parse_prefix (str, patterns, t)
Store the parsed number into *RES.
Return the first character after the prefix, or 0 if it wasn't parsed. */
static char const *
-parse_fixed (s, digits, res)
- char const *s;
- int digits, *res;
+parse_fixed (char const *s, int digits, int *res)
{
int n = 0;
char const *lim = s + digits;
@@ -422,9 +381,7 @@ parse_fixed (s, digits, res)
Store the parsed number into *RES.
Return the first character after the prefix. */
static char const *
-parse_varying (s, res)
- char const *s;
- int *res;
+parse_varying (char const *s, int *res)
{
int n = 0;
for (;;)
@@ -444,9 +401,7 @@ parse_varying (s, res)
Store the parsed number into *RES.
Return the first character after the prefix, or 0 if it wasn't parsed. */
static char const *
-parse_ranged (s, digits, lo, hi, res)
- char const *s;
- int digits, lo, hi, *res;
+parse_ranged (char const *s, int digits, int lo, int hi, int *res)
{
s = parse_fixed (s, digits, res);
return s && lo <= *res && *res <= hi ? s : 0;
@@ -459,9 +414,8 @@ parse_ranged (s, digits, lo, hi, res)
rounded to the nearest integer, into *FRES.
Return the first character after the prefix, or 0 if it wasn't parsed. */
static char const *
-parse_decimal (s, digits, lo, hi, resolution, res, fres)
- char const *s;
- int digits, lo, hi, resolution, *res, *fres;
+parse_decimal (char const *s, int digits, int lo, int hi, int resolution,
+ int *res, int *fres)
{
s = parse_fixed (s, digits, res);
if (s && lo <= *res && *res <= hi)
@@ -605,10 +559,7 @@ parzone (s, zone)
Set *T accordingly.
Return the first character after the prefix, or 0 if it wasn't parsed. */
static char const *
-parse_pattern_letter (s, c, t)
- char const *s;
- int c;
- struct partime *t;
+parse_pattern_letter (char const *s, int c, struct partime *t)
{
char const *s0 = s;
@@ -881,9 +832,7 @@ parse_pattern_letter (s, c, t)
/* If there is no conflict, merge into *T the additional information in *U
and return 0. Otherwise do nothing and return -1. */
static int
-merge_partime (t, u)
- struct partime *t;
- struct partime const *u;
+merge_partime (struct partime *t, struct partime const *u)
{
# define conflict(a,b) ((a) != (b) && TM_DEFINED (a) && TM_DEFINED (b))
if (conflict (t->tm.tm_sec, u->tm.tm_sec)
diff --git a/partime.h b/partime.h
index 1f4d31a..ea8f5fb 100644
--- a/partime.h
+++ b/partime.h
@@ -1,6 +1,6 @@
/* Parse a string, yielding a struct partime that describes it. */
-/* Copyright 1993, 1994, 1995, 1997 Paul Eggert
+/* Copyright (C) 1993, 1994, 1995, 1997, 2003, 2006 Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
@@ -18,7 +18,7 @@
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING.
If not, write to the Free Software Foundation,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Report problems and direct all questions to:
@@ -26,10 +26,12 @@
*/
+#include <limits.h>
+#include <time.h>
+
#define TM_UNDEFINED (-1)
#define TM_DEFINED(x) (0 <= (x))
-/* #include <limits.h> if you want to use these symbols. */
#define TM_LOCAL_ZONE LONG_MIN
#define TM_UNDEFINED_ZONE (LONG_MIN + 1)
@@ -67,11 +69,5 @@ struct partime
long zone;
};
-#if defined __STDC__ || has_prototypes
-# define __PARTIME_P(x) x
-#else
-# define __PARTIME_P(x) ()
-#endif
-
-char *partime __PARTIME_P ((char const *, struct partime *));
-char *parzone __PARTIME_P ((char const *, long *));
+char *partime (char const *, struct partime *);
+char *parzone (char const *, long *);
diff --git a/patch.c b/patch.c
index 740589d..ed391d3 100644
--- a/patch.c
+++ b/patch.c
@@ -1,11 +1,11 @@
/* patch - a program to apply diffs to original files */
-/* $Id: patch.c,v 1.45 2003/09/11 18:36:17 eggert Exp $ */
+/* $Id: patch.c,v 1.45 2003/09/11 18:36:17 eggert Exp eggert $ */
/* Copyright (C) 1984, 1985, 1986, 1987, 1988 Larry Wall
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2002,
- 2003 Free Software Foundation, Inc.
+ 2003, 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
@@ -20,7 +20,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#define XTERN
#include <common.h>
@@ -357,7 +357,7 @@ main (int argc, char **argv)
if (outstate.zero_output
&& (remove_empty_files
|| (pch_says_nonexistent (! reverse) == 2
- && ! posixly_correct)))
+ && (!posixly_correct || diff_type == UNI_DIFF))))
{
if (verbosity == VERBOSE)
say ("Removing file %s%s\n", quotearg (outname),
@@ -932,10 +932,76 @@ locate_hunk (LINENUM fuzz)
return 0;
}
-/* We did not find the pattern, dump out the hunk so they can handle it. */
+/* Output a line number range in unified format. */
static void
-abort_hunk (void)
+print_unidiff_range (FILE *fp, LINENUM start, LINENUM count)
+{
+ char numbuf0[LINENUM_LENGTH_BOUND + 1];
+ char numbuf1[LINENUM_LENGTH_BOUND + 1];
+
+ switch (count)
+ {
+ case 0:
+ fprintf (fp, "%s,0", format_linenum (numbuf0, start - 1));
+ break;
+
+ case 1:
+ fprintf (fp, "%s", format_linenum (numbuf0, start));
+ break;
+
+ default:
+ fprintf (fp, "%s,%s",
+ format_linenum (numbuf0, start),
+ format_linenum (numbuf1, count));
+ break;
+ }
+}
+
+/* Output the rejected patch in unified format. */
+
+static void
+abort_hunk_unified (void)
+{
+ FILE *fp = rejfp;
+ LINENUM old;
+ LINENUM new;
+ LINENUM lastline = pch_ptrn_lines ();
+ LINENUM pat_end = pch_end ();
+
+ /* Add last_offset to guess the same as the previous successful hunk. */
+ fprintf (fp, "@@ -");
+ print_unidiff_range (fp, pch_first () + last_offset, lastline);
+ fprintf (fp, " +");
+ print_unidiff_range (fp, pch_newfirst () + last_offset, pch_repl_lines ());
+ fprintf (fp, " @@\n");
+
+ for (old = 1, new = lastline + 2; ; old++, new++)
+ {
+ for (; old <= lastline && pch_char (old) == '-'; old++)
+ {
+ fputc ('-', fp);
+ pch_write_line (old, fp);
+ }
+
+ for (; new <= pat_end && pch_char (new) == '+'; new++)
+ {
+ fputc ('+', fp);
+ pch_write_line (new, fp);
+ }
+
+ if (! (old <= lastline))
+ break;
+
+ fputc (' ', fp);
+ pch_write_line (old, fp);
+ }
+}
+
+/* Output the rejected patch in context format. */
+
+static void
+abort_hunk_context (void)
{
register LINENUM i;
register LINENUM pat_end = pch_end ();
@@ -990,6 +1056,17 @@ abort_hunk (void)
}
}
+/* Output the rejected hunk. */
+
+static void
+abort_hunk (void)
+{
+ if (diff_type == UNI_DIFF)
+ abort_hunk_unified ();
+ else
+ abort_hunk_context ();
+}
+
/* We found where to apply it (we hope), so do it. */
static bool
diff --git a/patch.man b/patch.man
index 5b46a8a..d2ff984 100644
--- a/patch.man
+++ b/patch.man
@@ -2,7 +2,7 @@
.de Id
.ds Dt \\$4
..
-.Id $Id: patch.man,v 1.31 2002/05/25 10:36:44 eggert Exp $
+.Id $Id: patch.man,v 1.31 2002/05/25 10:36:44 eggert Exp eggert $
.ds = \-\^\-
.de Sp
.if t .sp .3
@@ -111,8 +111,8 @@ would generate a file name that is too long
makes the file name too long, then
.B #
replaces the file name's last character).
-(The rejected hunk comes out in ordinary context diff form regardless of
-the input patch's form.
+(The rejected hunk comes out in unified diff format if the input patch
+was of that format, otherwise in ordinary context diff form.
If the input was a normal diff, many of the contexts are simply null.)
The line numbers on the hunks in the reject file may be different than
in the patch file: they reflect the approximate location patch thinks the
@@ -459,10 +459,12 @@ Conform more strictly to the \s-1POSIX\s0 standard, as follows.
.TP 3
.B " \(bu"
Take the first existing file from the list (old, new, index)
-when intuiting file names from diff headers.
+when intuiting file names from diff headers that are not in
+unified format.
.TP
.B " \(bu"
-Do not remove files that are empty after patching.
+Do not remove files that are empty after patching from a diff
+that is not in unified format.
.TP
.B " \(bu"
Do not ask whether to get files from \s-1RCS\s0, ClearCase, Perforce,
@@ -1132,7 +1134,7 @@ Copyright
.ie t \(co
.el (C)
1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-2000, 2001, 2002 Free Software Foundation, Inc.
+2000, 2001, 2002, 2006 Free Software Foundation, Inc.
.PP
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
diff --git a/pch.c b/pch.c
index 3d456d1..ef64058 100644
--- a/pch.c
+++ b/pch.c
@@ -1,11 +1,11 @@
/* reading patches */
-/* $Id: pch.c,v 1.46 2003/09/11 18:36:17 eggert Exp $ */
+/* $Id: pch.c,v 1.46 2003/09/11 18:36:17 eggert Exp eggert $ */
/* Copyright (C) 1986, 1987, 1988 Larry Wall
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003 Free Software Foundation, Inc.
+ 2002, 2003, 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
@@ -20,7 +20,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#define XTERN extern
#include <common.h>
@@ -58,7 +58,7 @@ static char **p_line; /* the text of the hunk */
static size_t *p_len; /* line length including \n if any */
static char *p_Char; /* +, -, and ! */
static LINENUM hunkmax = INITHUNKMAX; /* size of above arrays */
-static int p_indent; /* indent to patch */
+static size_t p_indent; /* indent to patch */
static bool p_strip_trailing_cr; /* true if stripping trailing \r */
static bool p_pass_comments_through; /* true if not ignoring # lines */
static file_offset p_base; /* where to intuit this time */
@@ -235,7 +235,8 @@ there_is_another_patch (void)
if (verbosity != SILENT)
{
if (p_indent)
- say ("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
+ say ("(Patch is indented %lu space%s.)\n",
+ (unsigned long int) p_indent, p_indent==1?"":"s");
if (p_strip_trailing_cr)
say ("(Stripping trailing CRs from patch.)\n");
if (! inname)
@@ -320,7 +321,7 @@ intuit_diff_type (void)
register file_offset previous_line = this_line;
register bool last_line_was_command = this_is_a_command;
register bool stars_last_line = stars_this_line;
- register int indent = 0;
+ register size_t indent = 0;
char ed_command_letter;
bool strip_trailing_cr;
size_t chars_read;
@@ -522,15 +523,15 @@ intuit_diff_type (void)
- Take the old and new names from the context header if present,
and take the index name from the `Index:' line if present and
if either the old and new names are both absent
- or posixly_correct is nonzero.
+ or if conforming to POSIX.
Consider the file names to be in the order (old, new, index).
- - If some named files exist, use the first one if posixly_correct
- is nonzero, the best one otherwise.
+ - If some named files exist, use the first one if conforming
+ to POSIX, the best one otherwise.
- If patch_get is nonzero, and no named files exist,
but an RCS or SCCS master file exists,
use the first named file with an RCS or SCCS master.
- If no named files exist, no RCS or SCCS master was found,
- some names are given, posixly_correct is zero,
+ some names are given, we are conforming to POSIX,
and the patch appears to create a file, then use the best name
requiring the creation of the fewest directories.
- Otherwise, report failure by setting `inname' to 0;
@@ -563,13 +564,13 @@ intuit_diff_type (void)
else
{
stat_errno[i] = 0;
- if (posixly_correct)
+ if (posixly_correct && retval != UNI_DIFF)
break;
}
i0 = i;
}
- if (! posixly_correct)
+ if (!posixly_correct || retval == UNI_DIFF)
{
bool is_empty;
@@ -1554,12 +1555,12 @@ get_line (void)
Return -1 if we ran out of memory. */
static size_t
-pget_line (int indent, int rfc934_nesting, bool strip_trailing_cr,
+pget_line (size_t indent, int rfc934_nesting, bool strip_trailing_cr,
bool pass_comments_through)
{
register FILE *fp = pfp;
register int c;
- register int i;
+ register size_t i;
register char *b;
register size_t s;
@@ -1895,18 +1896,21 @@ get_ed_command_letter (char const *line)
char const *p = line;
char letter;
bool pair = false;
- if (! ISDIGIT (*p))
- return 0;
- while (ISDIGIT (*++p))
- continue;
- if (*p == ',')
+
+ if (ISDIGIT (*p))
{
- if (! ISDIGIT (*++p))
- return 0;
while (ISDIGIT (*++p))
continue;
- pair = true;
+ if (*p == ',')
+ {
+ if (! ISDIGIT (*++p))
+ return 0;
+ while (ISDIGIT (*++p))
+ continue;
+ pair = true;
+ }
}
+
letter = *p++;
switch (letter)
diff --git a/pch.h b/pch.h
index ba62d03..0964b22 100644
--- a/pch.h
+++ b/pch.h
@@ -1,6 +1,6 @@
/* reading patches */
-/* $Id: pch.h,v 1.11 2003/05/20 13:56:03 eggert Exp $ */
+/* $Id: pch.h,v 1.11 2003/05/20 13:56:03 eggert Exp eggert $ */
/* Copyright (C) 1986, 1987, 1988 Larry Wall
@@ -20,7 +20,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
LINENUM pch_end (void);
LINENUM pch_first (void);
diff --git a/quote.c b/quote.c
new file mode 100644
index 0000000..5f11d83
--- /dev/null
+++ b/quote.c
@@ -0,0 +1,41 @@
+/* quote.c - quote arguments for output
+ Copyright (C) 1998, 1999, 2000, 2001, 2003 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. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "quotearg.h"
+#include "quote.h"
+
+/* Return an unambiguous printable representation of NAME,
+ allocated in slot N, suitable for diagnostics. */
+char const *
+quote_n (int n, char const *name)
+{
+ return quotearg_n_style (n, locale_quoting_style, name);
+}
+
+/* Return an unambiguous printable representation of NAME,
+ suitable for diagnostics. */
+char const *
+quote (char const *name)
+{
+ return quote_n (0, name);
+}
diff --git a/quote.h b/quote.h
new file mode 100644
index 0000000..682f9d1
--- /dev/null
+++ b/quote.h
@@ -0,0 +1,22 @@
+/* quote.h - prototypes for quote.c
+
+ Copyright (C) 1998, 1999, 2000, 2001, 2003 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. */
+
+
+char const *quote_n (int n, char const *name);
+char const *quote (char const *name);
diff --git a/quotearg.c b/quotearg.c
index 494ac99..bffa14b 100644
--- a/quotearg.c
+++ b/quotearg.c
@@ -1,5 +1,5 @@
/* quotearg.c - quote arguments for output
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002 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
@@ -21,38 +21,55 @@
# include <config.h>
#endif
-#include <sys/types.h>
-#include <quotearg.h>
-#include <xalloc.h>
+#include "quotearg.h"
+
+#include "xalloc.h"
#include <ctype.h>
-#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
-# define ISASCII(c) 1
-#else
-# define ISASCII(c) isascii (c)
-#endif
-#ifdef isgraph
-# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
-#else
-# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
-#endif
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
-#if HAVE_LIMITS_H
-# include <limits.h>
+#if HAVE_WCHAR_H
+
+/* BSD/OS 4.1 wchar.h requires FILE and struct tm to be declared. */
+# include <stdio.h>
+# include <time.h>
+
+# include <wchar.h>
#endif
-#ifndef CHAR_BIT
-#define CHAR_BIT 8
+
+#if !HAVE_MBRTOWC
+/* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the
+ other macros are defined only for documentation and to satisfy C
+ syntax. */
+# undef MB_CUR_MAX
+# define MB_CUR_MAX 1
+# define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0)
+# define iswprint(wc) isprint ((unsigned char) (wc))
+# undef HAVE_MBSINIT
#endif
-#ifndef UCHAR_MAX
-#define UCHAR_MAX ((unsigned char) -1)
+
+#if !defined mbsinit && !HAVE_MBSINIT
+# define mbsinit(ps) 1
#endif
-#if HAVE_STDLIB_H
-# include <stdlib.h>
+#ifndef iswprint
+# if HAVE_WCTYPE_H
+# include <wctype.h>
+# endif
+# if !defined iswprint && !HAVE_ISWPRINT
+# define iswprint(wc) 1
+# endif
#endif
-#if HAVE_STRING_H
-# include <string.h>
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
#endif
#define INT_BITS (sizeof (int) * CHAR_BIT)
@@ -62,16 +79,34 @@ struct quoting_options
/* Basic quoting style. */
enum quoting_style style;
- /* Quote the chararacters indicated by this bit vector even if the
+ /* Quote the characters indicated by this bit vector even if the
quoting style would not normally require them to be quoted. */
- int quote_these_too[((UCHAR_MAX + 1) / INT_BITS
- + ((UCHAR_MAX + 1) % INT_BITS != 0))];
+ int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
};
/* Names of quoting styles. */
char const *const quoting_style_args[] =
{
- "literal", "shell", "shell-always", "c", "escape", 0
+ "literal",
+ "shell",
+ "shell-always",
+ "c",
+ "escape",
+ "locale",
+ "clocale",
+ 0
+};
+
+/* Correspondences to quoting style names. */
+enum quoting_style const quoting_style_vals[] =
+{
+ literal_quoting_style,
+ shell_quoting_style,
+ shell_always_quoting_style,
+ c_quoting_style,
+ escape_quoting_style,
+ locale_quoting_style,
+ clocale_quoting_style
};
/* The default quoting options. */
@@ -83,9 +118,10 @@ static struct quoting_options default_quoting_options;
struct quoting_options *
clone_quoting_options (struct quoting_options *o)
{
- struct quoting_options *p
- = (struct quoting_options *) xmalloc (sizeof (struct quoting_options));
+ int e = errno;
+ struct quoting_options *p = xmalloc (sizeof *p);
*p = *(o ? o : &default_quoting_options);
+ errno = e;
return p;
}
@@ -120,209 +156,417 @@ set_char_quoting (struct quoting_options *o, char c, int i)
return r;
}
+/* MSGID approximates a quotation mark. Return its translation if it
+ has one; otherwise, return either it or "\"", depending on S. */
+static char const *
+gettext_quote (char const *msgid, enum quoting_style s)
+{
+ char const *translation = _(msgid);
+ if (translation == msgid && s == clocale_quoting_style)
+ translation = "\"";
+ return translation;
+}
+
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
- argument ARG (of size ARGSIZE), using O to control quoting.
- If O is null, use the default.
+ argument ARG (of size ARGSIZE), using QUOTING_STYLE and the
+ non-quoting-style part of O to control quoting.
Terminate the output with a null character, and return the written
size of the output, not counting the terminating null.
If BUFFERSIZE is too small to store the output string, return the
value that would have been returned had BUFFERSIZE been large enough.
- If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
-size_t
-quotearg_buffer (char *buffer, size_t buffersize,
- char const *arg, size_t argsize,
- struct quoting_options const *o)
+ If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
+
+ This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
+ ARGSIZE, O), except it uses QUOTING_STYLE instead of the quoting
+ style specified by O, and O may not be null. */
+
+static size_t
+quotearg_buffer_restyled (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ enum quoting_style quoting_style,
+ struct quoting_options const *o)
{
- unsigned char c;
size_t i;
- size_t len;
- int quote_mark;
- struct quoting_options const *p = o ? o : &default_quoting_options;
- enum quoting_style quoting_style = p->style;
-# define STORE(c) \
+ size_t len = 0;
+ char const *quote_string = 0;
+ size_t quote_string_len = 0;
+ int backslash_escapes = 0;
+ int unibyte_locale = MB_CUR_MAX == 1;
+
+#define STORE(c) \
do \
{ \
if (len < buffersize) \
buffer[len] = (c); \
- len++; \
+ len++; \
} \
while (0)
switch (quoting_style)
{
- case shell_quoting_style:
- if (! (argsize == -1 ? arg[0] == '\0' : argsize == 0))
- {
- switch (arg[0])
- {
- case '#': case '~':
- break;
+ case c_quoting_style:
+ STORE ('"');
+ backslash_escapes = 1;
+ quote_string = "\"";
+ quote_string_len = 1;
+ break;
- default:
- len = 0;
- for (i = 0; ; i++)
- {
- if (argsize == -1 ? arg[i] == '\0' : i == argsize)
- goto done;
-
- c = arg[i];
-
- switch (c)
- {
- case '\t': case '\n': case ' ':
- case '!': /* special in csh */
- case '"': case '$': case '&': case '\'':
- case '(': case ')': case '*': case ';':
- case '<': case '>': case '?': case '[': case '\\':
- case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
- case '`': case '|':
- goto needs_quoting;
- }
-
- if (p->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS)))
- goto needs_quoting;
-
- STORE (c);
- }
-
- needs_quoting:;
- break;
- }
- }
- /* Fall through. */
+ case escape_quoting_style:
+ backslash_escapes = 1;
+ break;
- case shell_always_quoting_style:
- quote_mark = '\'';
+ case locale_quoting_style:
+ case clocale_quoting_style:
+ {
+ /* Get translations for open and closing quotation marks.
+
+ The message catalog should translate "`" to a left
+ quotation mark suitable for the locale, and similarly for
+ "'". If the catalog has no translation,
+ locale_quoting_style quotes `like this', and
+ clocale_quoting_style quotes "like this".
+
+ For example, an American English Unicode locale should
+ translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and
+ should translate "'" to U+201D (RIGHT DOUBLE QUOTATION
+ MARK). A British English Unicode locale should instead
+ translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and
+ U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. */
+
+ char const *left = gettext_quote (N_("`"), quoting_style);
+ char const *right = gettext_quote (N_("'"), quoting_style);
+ for (quote_string = left; *quote_string; quote_string++)
+ STORE (*quote_string);
+ backslash_escapes = 1;
+ quote_string = right;
+ quote_string_len = strlen (quote_string);
+ }
break;
- case c_quoting_style:
- quote_mark = '"';
+ case shell_always_quoting_style:
+ STORE ('\'');
+ quote_string = "'";
+ quote_string_len = 1;
break;
default:
- quote_mark = 0;
break;
}
- len = 0;
+ for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
+ {
+ unsigned char c;
+ unsigned char esc;
- if (quote_mark)
- STORE (quote_mark);
+ if (backslash_escapes
+ && quote_string_len
+ && i + quote_string_len <= argsize
+ && memcmp (arg + i, quote_string, quote_string_len) == 0)
+ STORE ('\\');
- for (i = 0; ! (argsize == -1 ? arg[i] == '\0' : i == argsize); i++)
- {
c = arg[i];
-
- switch (quoting_style)
+ switch (c)
{
- case literal_quoting_style:
- break;
-
- case shell_quoting_style:
- case shell_always_quoting_style:
- if (c == '\'')
+ case '\0':
+ if (backslash_escapes)
{
- STORE ('\'');
STORE ('\\');
- STORE ('\'');
+ STORE ('0');
+ STORE ('0');
+ c = '0';
}
break;
- case c_quoting_style:
- case escape_quoting_style:
- switch (c)
+ case '?':
+ switch (quoting_style)
{
- case '?': /* Do not generate trigraphs. */
- case '\\': goto store_escape;
- /* Not all C compilers know what \a means. */
- case 7 : c = 'a'; goto store_escape;
- case '\b': c = 'b'; goto store_escape;
- case '\f': c = 'f'; goto store_escape;
- case '\n': c = 'n'; goto store_escape;
- case '\r': c = 'r'; goto store_escape;
- case '\t': c = 't'; goto store_escape;
- case '\v': c = 'v'; goto store_escape;
-
- case ' ':
- if (quoting_style == escape_quoting_style)
- goto store_escape;
+ case shell_quoting_style:
+ goto use_shell_always_quoting_style;
+
+ case c_quoting_style:
+ if (i + 2 < argsize && arg[i + 1] == '?')
+ switch (arg[i + 2])
+ {
+ case '!': case '\'':
+ case '(': case ')': case '-': case '/':
+ case '<': case '=': case '>':
+ /* Escape the second '?' in what would otherwise be
+ a trigraph. */
+ c = arg[i + 2];
+ i += 2;
+ STORE ('?');
+ STORE ('\\');
+ STORE ('?');
+ break;
+ }
break;
- case '"':
- if (quoting_style == c_quoting_style)
- goto store_escape;
+ default:
+ break;
+ }
+ break;
+
+ case '\a': esc = 'a'; goto c_escape;
+ case '\b': esc = 'b'; goto c_escape;
+ case '\f': esc = 'f'; goto c_escape;
+ case '\n': esc = 'n'; goto c_and_shell_escape;
+ case '\r': esc = 'r'; goto c_and_shell_escape;
+ case '\t': esc = 't'; goto c_and_shell_escape;
+ case '\v': esc = 'v'; goto c_escape;
+ case '\\': esc = c; goto c_and_shell_escape;
+
+ c_and_shell_escape:
+ if (quoting_style == shell_quoting_style)
+ goto use_shell_always_quoting_style;
+ c_escape:
+ if (backslash_escapes)
+ {
+ c = esc;
+ goto store_escape;
+ }
+ break;
+
+ case '#': case '~':
+ if (i != 0)
+ break;
+ /* Fall through. */
+ case ' ':
+ case '!': /* special in bash */
+ case '"': case '$': case '&':
+ case '(': case ')': case '*': case ';':
+ case '<': case '>': case '[':
+ case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
+ case '`': case '|':
+ /* A shell special character. In theory, '$' and '`' could
+ be the first bytes of multibyte characters, which means
+ we should check them with mbrtowc, but in practice this
+ doesn't happen so it's not worth worrying about. */
+ if (quoting_style == shell_quoting_style)
+ goto use_shell_always_quoting_style;
+ break;
+
+ case '\'':
+ switch (quoting_style)
+ {
+ case shell_quoting_style:
+ goto use_shell_always_quoting_style;
+
+ case shell_always_quoting_style:
+ STORE ('\'');
+ STORE ('\\');
+ STORE ('\'');
break;
default:
- if (!ISGRAPH (c))
- {
- STORE ('\\');
- STORE ('0' + (c >> 6));
- STORE ('0' + ((c >> 3) & 3));
- c = '0' + (c & 3);
- goto store_c;
- }
break;
}
+ break;
- if (! (p->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
- goto store_c;
+ case '%': case '+': case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9': case ':': case '=':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
+ case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
+ case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
+ case 'o': case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
+ case '{': case '}':
+ /* These characters don't cause problems, no matter what the
+ quoting style is. They cannot start multibyte sequences. */
+ break;
- store_escape:
- STORE ('\\');
+ default:
+ /* If we have a multibyte sequence, copy it until we reach
+ its end, find an error, or come back to the initial shift
+ state. For C-like styles, if the sequence has
+ unprintable characters, escape the whole sequence, since
+ we can't easily escape single characters within it. */
+ {
+ /* Length of multibyte sequence found so far. */
+ size_t m;
+
+ int printable;
+
+ if (unibyte_locale)
+ {
+ m = 1;
+ printable = isprint (c);
+ }
+ else
+ {
+ mbstate_t mbstate;
+ memset (&mbstate, 0, sizeof mbstate);
+
+ m = 0;
+ printable = 1;
+ if (argsize == SIZE_MAX)
+ argsize = strlen (arg);
+
+ do
+ {
+ wchar_t w;
+ size_t bytes = mbrtowc (&w, &arg[i + m],
+ argsize - (i + m), &mbstate);
+ if (bytes == 0)
+ break;
+ else if (bytes == (size_t) -1)
+ {
+ printable = 0;
+ break;
+ }
+ else if (bytes == (size_t) -2)
+ {
+ printable = 0;
+ while (i + m < argsize && arg[i + m])
+ m++;
+ break;
+ }
+ else
+ {
+ if (! iswprint (w))
+ printable = 0;
+ m += bytes;
+ }
+ }
+ while (! mbsinit (&mbstate));
+ }
+
+ if (1 < m || (backslash_escapes && ! printable))
+ {
+ /* Output a multibyte sequence, or an escaped
+ unprintable unibyte character. */
+ size_t ilim = i + m;
+
+ for (;;)
+ {
+ if (backslash_escapes && ! printable)
+ {
+ STORE ('\\');
+ STORE ('0' + (c >> 6));
+ STORE ('0' + ((c >> 3) & 7));
+ c = '0' + (c & 7);
+ }
+ if (ilim <= i + 1)
+ break;
+ STORE (c);
+ c = arg[++i];
+ }
+
+ goto store_c;
+ }
+ }
}
+ if (! (backslash_escapes
+ && o->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
+ goto store_c;
+
+ store_escape:
+ STORE ('\\');
+
store_c:
STORE (c);
}
- if (quote_mark)
- STORE (quote_mark);
+ if (quote_string)
+ for (; *quote_string; quote_string++)
+ STORE (*quote_string);
- done:
if (len < buffersize)
buffer[len] = '\0';
return len;
+
+ use_shell_always_quoting_style:
+ return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
+ shell_always_quoting_style, o);
+}
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using O to control quoting.
+ If O is null, use the default.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
+size_t
+quotearg_buffer (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ struct quoting_options const *o)
+{
+ struct quoting_options const *p = o ? o : &default_quoting_options;
+ int e = errno;
+ size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
+ p->style, p);
+ errno = e;
+ return r;
}
-/* Use storage slot N to return a quoted version of the string ARG.
+/* Use storage slot N to return a quoted version of argument ARG.
+ ARG is of size ARGSIZE, but if that is -1, ARG is a null-terminated string.
OPTIONS specifies the quoting options.
The returned value points to static storage that can be
reused by the next call to this function with the same value of N.
- N must be nonnegative. */
+ N must be nonnegative. N is deliberately declared with type "int"
+ to allow for future extensions (using negative values). */
static char *
-quotearg_n_options (int n, char const *arg, struct quoting_options *options)
+quotearg_n_options (int n, char const *arg, size_t argsize,
+ struct quoting_options const *options)
{
- static unsigned nslots;
- static struct slotvec
+ int e = errno;
+
+ /* Preallocate a slot 0 buffer, so that the caller can always quote
+ one small component of a "memory exhausted" message in slot 0. */
+ static char slot0[256];
+ static unsigned int nslots = 1;
+ unsigned int n0 = n;
+ struct slotvec
{
size_t size;
char *val;
- } *slotvec;
+ };
+ static struct slotvec slotvec0 = {sizeof slot0, slot0};
+ static struct slotvec *slotvec = &slotvec0;
+
+ if (n < 0)
+ abort ();
- if (nslots <= n)
+ if (nslots <= n0)
{
- int n1 = n + 1;
- size_t s = n1 * sizeof (struct slotvec);
- if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
- abort ();
- slotvec = (struct slotvec *) xrealloc (slotvec, s);
- memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));
- nslots = n;
+ unsigned int n1 = n0 + 1;
+ size_t s = n1 * sizeof *slotvec;
+
+ if (SIZE_MAX / UINT_MAX <= sizeof *slotvec
+ && n1 != s / sizeof *slotvec)
+ xalloc_die ();
+
+ if (slotvec == &slotvec0)
+ {
+ slotvec = xmalloc (sizeof *slotvec);
+ *slotvec = slotvec0;
+ }
+ slotvec = xrealloc (slotvec, s);
+ memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec);
+ nslots = n1;
}
{
size_t size = slotvec[n].size;
char *val = slotvec[n].val;
- size_t qsize = quotearg_buffer (val, size, arg, (size_t) -1, options);
+ size_t qsize = quotearg_buffer (val, size, arg, argsize, options);
if (size <= qsize)
{
slotvec[n].size = size = qsize + 1;
- slotvec[n].val = val = xrealloc (val, size);
- quotearg_buffer (val, size, arg, (size_t) -1, options);
+ slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size);
+ quotearg_buffer (val, size, arg, argsize, options);
}
+ errno = e;
return val;
}
}
@@ -330,7 +574,7 @@ quotearg_n_options (int n, char const *arg, struct quoting_options *options)
char *
quotearg_n (int n, char const *arg)
{
- return quotearg_n_options (n, arg, &default_quoting_options);
+ return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
}
char *
@@ -339,13 +583,44 @@ quotearg (char const *arg)
return quotearg_n (0, arg);
}
+/* Return quoting options for STYLE, with no extra quoting. */
+static struct quoting_options
+quoting_options_from_style (enum quoting_style style)
+{
+ struct quoting_options o;
+ o.style = style;
+ memset (o.quote_these_too, 0, sizeof o.quote_these_too);
+ return o;
+}
+
+char *
+quotearg_n_style (int n, enum quoting_style s, char const *arg)
+{
+ struct quoting_options const o = quoting_options_from_style (s);
+ return quotearg_n_options (n, arg, SIZE_MAX, &o);
+}
+
+char *
+quotearg_n_style_mem (int n, enum quoting_style s,
+ char const *arg, size_t argsize)
+{
+ struct quoting_options const o = quoting_options_from_style (s);
+ return quotearg_n_options (n, arg, argsize, &o);
+}
+
+char *
+quotearg_style (enum quoting_style s, char const *arg)
+{
+ return quotearg_n_style (0, s, arg);
+}
+
char *
quotearg_char (char const *arg, char ch)
{
struct quoting_options options;
options = default_quoting_options;
set_char_quoting (&options, ch, 1);
- return quotearg_n_options (0, arg, &options);
+ return quotearg_n_options (0, arg, SIZE_MAX, &options);
}
char *
diff --git a/quotearg.h b/quotearg.h
index a4d1246..efc9331 100644
--- a/quotearg.h
+++ b/quotearg.h
@@ -1,5 +1,7 @@
/* quotearg.h - quote arguments for output
- Copyright (C) 1998 Free Software Foundation, Inc.
+
+ Copyright (C) 1998, 1999, 2000, 2001, 2002 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
@@ -17,6 +19,11 @@
/* Written by Paul Eggert <eggert@twinsun.com> */
+#ifndef QUOTEARG_H_
+# define QUOTEARG_H_ 1
+
+# include <stddef.h>
+
/* Basic quoting styles. */
enum quoting_style
{
@@ -24,51 +31,43 @@ enum quoting_style
shell_quoting_style, /* --quoting-style=shell */
shell_always_quoting_style, /* --quoting-style=shell-always */
c_quoting_style, /* --quoting-style=c */
- escape_quoting_style /* --quoting-style=escape */
+ escape_quoting_style, /* --quoting-style=escape */
+ locale_quoting_style, /* --quoting-style=locale */
+ clocale_quoting_style /* --quoting-style=clocale */
};
-/* For now, --quoting-style=literal is the default, but
- this is planned to change to --quoting-style=shell in the future. */
-#ifndef DEFAULT_QUOTING_STYLE
-#define DEFAULT_QUOTING_STYLE literal_quoting_style
-#endif
+/* For now, --quoting-style=literal is the default, but this may change. */
+# ifndef DEFAULT_QUOTING_STYLE
+# define DEFAULT_QUOTING_STYLE literal_quoting_style
+# endif
-/* Names of quoting styles. */
+/* Names of quoting styles and their corresponding values. */
extern char const *const quoting_style_args[];
+extern enum quoting_style const quoting_style_vals[];
struct quoting_options;
-#ifndef PARAMS
-# if defined PROTOTYPES || defined __STDC__
-# define PARAMS(Args) Args
-# else
-# define PARAMS(Args) ()
-# endif
-#endif
-
/* The functions listed below set and use a hidden variable
that contains the default quoting style options. */
/* Allocate a new set of quoting options, with contents initially identical
to O if O is not null, or to the default if O is null.
It is the caller's responsibility to free the result. */
-struct quoting_options *clone_quoting_options
- PARAMS ((struct quoting_options *o));
+struct quoting_options *clone_quoting_options (struct quoting_options *o);
/* Get the value of O's quoting style. If O is null, use the default. */
-enum quoting_style get_quoting_style PARAMS ((struct quoting_options *o));
+enum quoting_style get_quoting_style (struct quoting_options *o);
/* In O (or in the default if O is null),
set the value of the quoting style to S. */
-void set_quoting_style PARAMS ((struct quoting_options *o,
- enum quoting_style s));
+void set_quoting_style (struct quoting_options *o, enum quoting_style s);
/* In O (or in the default if O is null),
set the value of the quoting options for character C to I.
Return the old value. Currently, the only values defined for I are
0 (the default) and 1 (which means to quote the character even if
it would not otherwise be quoted). */
-int set_char_quoting PARAMS ((struct quoting_options *o, char c, int i));
+int set_char_quoting (struct quoting_options *o, char c, int i);
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
argument ARG (of size ARGSIZE), using O to control quoting.
@@ -78,22 +77,38 @@ int set_char_quoting PARAMS ((struct quoting_options *o, char c, int i));
If BUFFERSIZE is too small to store the output string, return the
value that would have been returned had BUFFERSIZE been large enough.
If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
-size_t quotearg_buffer PARAMS ((char *buffer, size_t buffersize,
- char const *arg, size_t argsize,
- struct quoting_options const *o));
+size_t quotearg_buffer (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ struct quoting_options const *o);
/* Use storage slot N to return a quoted version of the string ARG.
Use the default quoting options.
The returned value points to static storage that can be
reused by the next call to this function with the same value of N.
N must be nonnegative. */
-char *quotearg_n PARAMS ((int n, char const *arg));
+char *quotearg_n (int n, char const *arg);
+
+/* Equivalent to quotearg_n (0, ARG). */
+char *quotearg (char const *arg);
+
+/* Use style S and storage slot N to return a quoted version of the string ARG.
+ This is like quotearg_n (N, ARG), except that it uses S with no other
+ options to specify the quoting method. */
+char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
-/* Equivalent to quotearg_n (ARG, 0). */
-char *quotearg PARAMS ((char const *arg));
+/* Use style S and storage slot N to return a quoted version of the
+ argument ARG of size ARGSIZE. This is like quotearg_n_style
+ (N, S, ARG), except it can quote null bytes. */
+char *quotearg_n_style_mem (int n, enum quoting_style s,
+ char const *arg, size_t argsize);
+
+/* Equivalent to quotearg_n_style (0, S, ARG). */
+char *quotearg_style (enum quoting_style s, char const *arg);
/* Like quotearg (ARG), except also quote any instances of CH. */
-char *quotearg_char PARAMS ((char const *arg, char ch));
+char *quotearg_char (char const *arg, char ch);
/* Equivalent to quotearg_char (ARG, ':'). */
-char *quotearg_colon PARAMS ((char const *arg));
+char *quotearg_colon (char const *arg);
+
+#endif /* !QUOTEARG_H_ */
diff --git a/quotesys.c b/quotesys.c
new file mode 100644
index 0000000..528f382
--- /dev/null
+++ b/quotesys.c
@@ -0,0 +1,125 @@
+/* Shell command argument quoting.
+ Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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 <sys/types.h>
+#include <quotesys.h>
+
+/* Place into QUOTED a quoted version of ARG suitable for `system'.
+ Return the length of the resulting string (which is not null-terminated).
+ If QUOTED is null, return the length without any side effects. */
+
+size_t
+quote_system_arg (quoted, arg)
+ char *quoted;
+ char const *arg;
+{
+ char const *a;
+ size_t len = 0;
+
+ /* Scan ARG, copying it to QUOTED if QUOTED is not null,
+ looking for shell metacharacters. */
+
+ for (a = arg; ; a++)
+ {
+ char c = *a;
+ switch (c)
+ {
+ case 0:
+ /* ARG has no shell metacharacters. */
+ return len;
+
+ case '=':
+ if (*arg == '-')
+ break;
+ /* Fall through. */
+ case '\t': case '\n': case ' ':
+ case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
+ case '(': case ')': case '*': case ';':
+ case '<': case '>': case '?': case '[': case '\\':
+ case '^': case '`': case '|': case '~':
+ {
+ /* ARG has a shell metacharacter.
+ Start over, quoting it this time. */
+
+ len = 0;
+ c = *arg++;
+
+ /* If ARG is an option, quote just its argument.
+ This is not necessary, but it looks nicer. */
+ if (c == '-' && arg < a)
+ {
+ c = *arg++;
+
+ if (quoted)
+ {
+ quoted[len] = '-';
+ quoted[len + 1] = c;
+ }
+ len += 2;
+
+ if (c == '-')
+ while (arg < a)
+ {
+ c = *arg++;
+ if (quoted)
+ quoted[len] = c;
+ len++;
+ if (c == '=')
+ break;
+ }
+ c = *arg++;
+ }
+
+ if (quoted)
+ quoted[len] = '\'';
+ len++;
+
+ for (; c; c = *arg++)
+ {
+ if (c == '\'')
+ {
+ if (quoted)
+ {
+ quoted[len] = '\'';
+ quoted[len + 1] = '\\';
+ quoted[len + 2] = '\'';
+ }
+ len += 3;
+ }
+ if (quoted)
+ quoted[len] = c;
+ len++;
+ }
+
+ if (quoted)
+ quoted[len] = '\'';
+ return len + 1;
+ }
+ }
+
+ if (quoted)
+ quoted[len] = c;
+ len++;
+ }
+}
diff --git a/quotesys.h b/quotesys.h
new file mode 100644
index 0000000..0d0d825
--- /dev/null
+++ b/quotesys.h
@@ -0,0 +1,9 @@
+/* quotesys.h -- declarations for quoting system arguments */
+
+#if defined __STDC__ || __GNUC__
+# define __QUOTESYS_P(args) args
+#else
+# define __QUOTESYS_P(args) ()
+#endif
+
+size_t quote_system_arg __QUOTESYS_P ((char *, char const *));
diff --git a/realloc.c b/realloc.c
index d0d3e4a..ccbf991 100644
--- a/realloc.c
+++ b/realloc.c
@@ -1,5 +1,5 @@
/* Work around bug on some systems where realloc (NULL, 0) fails.
- Copyright (C) 1997 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2003 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
@@ -22,19 +22,14 @@
#endif
#undef realloc
-#include <sys/types.h>
-
-char *malloc ();
-char *realloc ();
+#include <stdlib.h>
/* Change the size of an allocated block of memory P to N bytes,
with error checking. If N is zero, change it to 1. If P is NULL,
use malloc. */
-char *
-rpl_realloc (p, n)
- char *p;
- size_t n;
+void *
+rpl_realloc (void *p, size_t n)
{
if (n == 0)
n = 1;
diff --git a/stdbool_.h b/stdbool_.h
new file mode 100644
index 0000000..3dbb51b
--- /dev/null
+++ b/stdbool_.h
@@ -0,0 +1,92 @@
+/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ 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 _STDBOOL_H
+#define _STDBOOL_H
+
+/* ISO C 99 <stdbool.h> for platforms that lack it. */
+
+/* Usage suggestions:
+
+ Programs that use <stdbool.h> should be aware of some limitations
+ and standards compliance issues.
+
+ Standards compliance:
+
+ - <stdbool.h> must be #included before 'bool', 'false', 'true'
+ can be used.
+
+ - You cannot assume that sizeof (bool) == 1.
+
+ - Programs should not undefine the macros bool, true, and false,
+ as C99 lists that as an "obsolescent feature".
+
+ Limitations of this substitute, when used in a C89 environment:
+
+ - <stdbool.h> must be #included before the '_Bool' type can be used.
+
+ - You cannot assume that _Bool is a typedef; it might be a macro.
+
+ - In C99, casts and automatic conversions to '_Bool' or 'bool' are
+ performed in such a way that every nonzero value gets converted
+ to 'true', and zero gets converted to 'false'. This doesn't work
+ with this substitute. With this substitute, only the values 0 and 1
+ give the expected result when converted to _Bool' or 'bool'.
+
+ Also, it is suggested that programs use 'bool' rather than '_Bool';
+ this isn't required, but 'bool' is more common. */
+
+
+/* 7.16. Boolean type and values */
+
+/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
+ definitions below, but temporarily we have to #undef them. */
+#ifdef __BEOS__
+# undef false
+# undef true
+#endif
+
+/* For the sake of symbolic names in gdb, we define true and false as
+ enum constants, not only as macros.
+ It is tempting to write
+ typedef enum { false = 0, true = 1 } _Bool;
+ so that gdb prints values of type 'bool' symbolically. But if we do
+ this, values of type '_Bool' may promote to 'int' or 'unsigned int'
+ (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
+ (see ISO C 99 6.3.1.1.(2)). So we add a negative value to the
+ enum; this ensures that '_Bool' promotes to 'int'. */
+#ifndef __cplusplus
+# if !@HAVE__BOOL@
+# if defined __SUNPRO_C && (__SUNPRO_C < 0x550 || __STDC__ == 1)
+ /* Avoid stupid "warning: _Bool is a keyword in ISO C99". */
+# define _Bool signed char
+enum { false = 0, true = 1 };
+# else
+typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
+# endif
+# endif
+#else
+typedef bool _Bool;
+#endif
+#define bool _Bool
+
+/* The other macros must be usable in preprocessor directives. */
+#define false 0
+#define true 1
+#define __bool_true_false_are_defined 1
+
+#endif /* _STDBOOL_H */
diff --git a/strcasecmp.c b/strcasecmp.c
new file mode 100644
index 0000000..cf4ab88
--- /dev/null
+++ b/strcasecmp.c
@@ -0,0 +1,66 @@
+/* strcasecmp.c -- case insensitive string comparator
+ Copyright (C) 1998, 1999 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. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef LENGTH_LIMIT
+# define STRXCASECMP_FUNCTION strncasecmp
+# define STRXCASECMP_DECLARE_N , size_t n
+# define LENGTH_LIMIT_EXPR(Expr) Expr
+#else
+# define STRXCASECMP_FUNCTION strcasecmp
+# define STRXCASECMP_DECLARE_N /* empty */
+# define LENGTH_LIMIT_EXPR(Expr) 0
+#endif
+
+#include <stddef.h>
+#include <ctype.h>
+
+#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
+
+/* Compare {{no more than N characters of }}strings S1 and S2,
+ ignoring case, returning less than, equal to or
+ greater than zero if S1 is lexicographically less
+ than, equal to or greater than S2. */
+
+int
+STRXCASECMP_FUNCTION (const char *s1, const char *s2 STRXCASECMP_DECLARE_N)
+{
+ register const unsigned char *p1 = (const unsigned char *) s1;
+ register const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+
+ if (p1 == p2 || LENGTH_LIMIT_EXPR (n == 0))
+ return 0;
+
+ do
+ {
+ c1 = TOLOWER (*p1);
+ c2 = TOLOWER (*p2);
+
+ if (LENGTH_LIMIT_EXPR (--n == 0) || c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ return c1 - c2;
+}
diff --git a/strncasecmp.c b/strncasecmp.c
new file mode 100644
index 0000000..68d95aa
--- /dev/null
+++ b/strncasecmp.c
@@ -0,0 +1,2 @@
+#define LENGTH_LIMIT
+#include "strcasecmp.c"
diff --git a/timespec.h b/timespec.h
new file mode 100644
index 0000000..8633461
--- /dev/null
+++ b/timespec.h
@@ -0,0 +1,60 @@
+/* timespec -- System time interface
+
+ Copyright (C) 2000, 2002 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. */
+
+#if ! defined TIMESPEC_H
+# define TIMESPEC_H
+
+/* You must include config.h before including this file. */
+
+# include <sys/types.h>
+# if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+# else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+# endif
+
+# if ! HAVE_STRUCT_TIMESPEC
+/* Some systems don't define this struct, e.g., AIX 4.1, Ultrix 4.3. */
+struct timespec
+{
+ time_t tv_sec;
+ long tv_nsec;
+};
+# endif
+
+# ifdef ST_MTIM_NSEC
+# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC)
+# else
+# define TIMESPEC_NS(timespec) 0
+# endif
+
+# if ! HAVE_DECL_NANOSLEEP
+/* Don't specify a prototype here. Some systems (e.g., OSF) declare
+ nanosleep with a conflicting one (const-less first parameter). */
+int nanosleep ();
+# endif
+
+int gettime (struct timespec *);
+int settime (struct timespec const *);
+
+#endif
diff --git a/unlocked-io.h b/unlocked-io.h
new file mode 100644
index 0000000..3fe5fe1
--- /dev/null
+++ b/unlocked-io.h
@@ -0,0 +1,89 @@
+/* Prefer faster, non-thread-safe stdio functions if available.
+
+ Copyright (C) 2001, 2002 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. */
+
+/* Written by Jim Meyering. */
+
+#ifndef UNLOCKED_IO_H
+# define UNLOCKED_IO_H 1
+
+# ifndef USE_UNLOCKED_IO
+# define USE_UNLOCKED_IO 1
+# endif
+
+# if USE_UNLOCKED_IO
+
+/* These are wrappers for functions/macros from GNU libc.
+ The standard I/O functions are thread-safe. These *_unlocked ones are
+ more efficient but not thread-safe. That they're not thread-safe is
+ fine since all of the applications in this package are single threaded. */
+
+# if HAVE_DECL_CLEARERR_UNLOCKED
+# undef clearerr
+# define clearerr(x) clearerr_unlocked (x)
+# endif
+# if HAVE_DECL_FEOF_UNLOCKED
+# undef feof
+# define feof(x) feof_unlocked (x)
+# endif
+# if HAVE_DECL_FERROR_UNLOCKED
+# undef ferror
+# define ferror(x) ferror_unlocked (x)
+# endif
+# if HAVE_DECL_FFLUSH_UNLOCKED
+# undef fflush
+# define fflush(x) fflush_unlocked (x)
+# endif
+# if HAVE_DECL_FGETS_UNLOCKED
+# undef fgets
+# define fgets(x,y,z) fgets_unlocked (x,y,z)
+# endif
+# if HAVE_DECL_FPUTC_UNLOCKED
+# undef fputc
+# define fputc(x,y) fputc_unlocked (x,y)
+# endif
+# if HAVE_DECL_FPUTS_UNLOCKED
+# undef fputs
+# define fputs(x,y) fputs_unlocked (x,y)
+# endif
+# if HAVE_DECL_FREAD_UNLOCKED
+# undef fread
+# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
+# endif
+# if HAVE_DECL_FWRITE_UNLOCKED
+# undef fwrite
+# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
+# endif
+# if HAVE_DECL_GETC_UNLOCKED
+# undef getc
+# define getc(x) getc_unlocked (x)
+# endif
+# if HAVE_DECL_GETCHAR_UNLOCKED
+# undef getchar
+# define getchar() getchar_unlocked ()
+# endif
+# if HAVE_DECL_PUTC_UNLOCKED
+# undef putc
+# define putc(x,y) putc_unlocked (x,y)
+# endif
+# if HAVE_DECL_PUTCHAR_UNLOCKED
+# undef putchar
+# define putchar(x) putchar_unlocked (x)
+# endif
+
+# endif /* USE_UNLOCKED_IO */
+#endif /* UNLOCKED_IO_H */
diff --git a/util.c b/util.c
index 936ea9a..30d09ac 100644
--- a/util.c
+++ b/util.c
@@ -1,11 +1,11 @@
/* utility functions for `patch' */
-/* $Id: util.c,v 1.37 2003/09/11 18:36:17 eggert Exp $ */
+/* $Id: util.c,v 1.37 2003/09/11 18:36:17 eggert Exp eggert $ */
/* Copyright (C) 1986 Larry Wall
- Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003 Free
- Software Foundation, Inc.
+ Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 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
@@ -20,7 +20,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#define XTERN extern
#include <common.h>
@@ -53,8 +53,8 @@ static void makedirs (char *);
typedef struct
{
- dev_t dev;
- ino_t ino;
+ dev_t dev;
+ ino_t ino;
struct timespec mtime;
} file_id;
@@ -566,25 +566,6 @@ format_linenum (char numbuf[LINENUM_LENGTH_BOUND + 1], LINENUM n)
return p;
}
-#if !HAVE_VPRINTF
-#define vfprintf my_vfprintf
-static int
-vfprintf (FILE *stream, char const *format, va_list args)
-{
-#if !HAVE_DOPRNT && HAVE__DOPRINTF
-# define _doprnt _doprintf
-#endif
-#if HAVE_DOPRNT || HAVE__DOPRINTF
- _doprnt (format, args, stream);
- return ferror (stream) ? -1 : 0;
-#else
- int *a = (int *) args;
- return fprintf (stream, format,
- a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
-#endif
-}
-#endif /* !HAVE_VPRINTF */
-
/* Terminal output, pun intended. */
void
@@ -759,7 +740,7 @@ ok_to_reverse (char const *format, ...)
/* How to handle certain events when not in a critical region. */
-#define NUM_SIGS (sizeof (sigs) / sizeof (*sigs))
+#define NUM_SIGS ((int) (sizeof (sigs) / sizeof (*sigs)))
static int const sigs[] = {
#ifdef SIGHUP
SIGHUP,
@@ -812,8 +793,8 @@ static sigset_t initial_signal_mask;
static sigset_t signals_to_block;
#if ! HAVE_SIGACTION
-static RETSIGTYPE fatal_exit_handler (int) __attribute__ ((noreturn));
-static RETSIGTYPE
+static void fatal_exit_handler (int) __attribute__ ((noreturn));
+static void
fatal_exit_handler (int sig)
{
signal (sig, SIG_IGN);
diff --git a/util.h b/util.h
index d10c14e..c62ed76 100644
--- a/util.h
+++ b/util.h
@@ -1,6 +1,6 @@
/* utility functions for `patch' */
-/* $Id: util.h,v 1.21 2003/09/11 18:36:17 eggert Exp $ */
+/* $Id: util.h,v 1.21 2003/09/11 18:36:17 eggert Exp eggert $ */
/* Copyright (C) 1986 Larry Wall
@@ -20,7 +20,7 @@
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. */
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* An upper bound on the print length of a signed decimal line number.
Add one for the sign. */
diff --git a/xalloc.h b/xalloc.h
index 3f8d779..c6ca117 100644
--- a/xalloc.h
+++ b/xalloc.h
@@ -1,21 +1,78 @@
-#ifndef PARAMS
-# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
-# define PARAMS(Args) Args
-# else
-# define PARAMS(Args) ()
+/* xalloc.h -- malloc with out-of-memory checking
+
+ Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000, 2003 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 XALLOC_H_
+# define XALLOC_H_
+
+# include <stddef.h>
+
+# ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+# define __attribute__(x)
+# endif
+# endif
+
+# ifndef ATTRIBUTE_NORETURN
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# endif
-#endif
-/* Exit value when the requested amount of memory is not available.
- The caller may set it to some other value. */
-extern int xalloc_exit_failure;
+/* If this pointer is non-zero, run the specified function upon each
+ allocation failure. It is initialized to zero. */
+extern void (*xalloc_fail_func) (void);
+
+/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this
+ message is output. It is translated via gettext.
+ Its value is "memory exhausted". */
+extern char const xalloc_msg_memory_exhausted[];
+
+/* This function is always triggered when memory is exhausted. It is
+ in charge of honoring the two previous items. It exits with status
+ exit_failure (defined in exitfail.h). This is the
+ function to call when one wants the program to die because of a
+ memory allocation failure. */
+extern void xalloc_die (void) ATTRIBUTE_NORETURN;
+
+void *xmalloc (size_t n);
+void *xcalloc (size_t n, size_t s);
+void *xrealloc (void *p, size_t n);
+char *xstrdup (const char *str);
+
+# define XMALLOC(Type, N_items) xmalloc (sizeof (Type) * (N_items))
+# define XCALLOC(Type, N_items) xcalloc (sizeof (Type), N_items)
+# define XREALLOC(Ptr, Type, N_items) xrealloc (Ptr, sizeof (Type) * (N_items))
+
+/* Declare and alloc memory for VAR of type TYPE. */
+# define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
+
+/* Free VAR only if non NULL. */
+# define XFREE(Var) \
+ do { \
+ if (Var) \
+ free (Var); \
+ } while (0)
+
+/* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
+# define CCLONE(Src, Num) \
+ (memcpy (xmalloc (sizeof *(Src) * (Num)), Src, sizeof *(Src) * (Num)))
-/* FIXME: describe */
-extern char *const xalloc_msg_memory_exhausted;
+/* Return a malloc'ed copy of SRC. */
+# define CLONE(Src) CCLONE (Src, 1)
-/* FIXME: describe */
-extern void (*xalloc_fail_func) ();
-void *xmalloc PARAMS ((size_t n));
-void *xcalloc PARAMS ((size_t n, size_t s));
-void *xrealloc PARAMS ((void *p, size_t n));
+#endif /* !XALLOC_H_ */
diff --git a/xmalloc.c b/xmalloc.c
index 204469f..ead5039 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,5 +1,7 @@
/* xmalloc.c -- malloc with out of memory checking
- Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+
+ Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000, 2002, 2003 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
@@ -30,104 +32,81 @@ void *realloc ();
void free ();
#endif
-#if ENABLE_NLS
-# include <libintl.h>
-# define _(Text) gettext (Text)
-#else
-# define textdomain(Domain)
-# define _(Text) Text
-#endif
-#define N_(Text) Text
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
#include "error.h"
+#include "exitfail.h"
#include "xalloc.h"
#ifndef EXIT_FAILURE
# define EXIT_FAILURE 1
#endif
-/* Prototypes for functions defined here. */
-#if defined (__STDC__) && __STDC__
-void *xmalloc (size_t n);
-void *xcalloc (size_t n, size_t s);
-void *xrealloc (void *p, size_t n);
-#endif
+/* The following tests require AC_PREREQ(2.54). */
-#ifndef HAVE_DONE_WORKING_MALLOC_CHECK
-you must run the autoconf test for a properly working malloc -- see malloc.m4
+#ifndef HAVE_MALLOC
+"you must run the autoconf test for a GNU libc compatible malloc"
#endif
-#ifndef HAVE_DONE_WORKING_REALLOC_CHECK
-you must run the autoconf test for a properly working realloc -- see realloc.m4
+#ifndef HAVE_REALLOC
+"you must run the autoconf test for a GNU libc compatible realloc"
#endif
-/* Exit value when the requested amount of memory is not available.
- The caller may set it to some other value. */
-int xalloc_exit_failure = EXIT_FAILURE;
-
-/* FIXME: describe */
-char *const xalloc_msg_memory_exhausted = N_("Memory exhausted");
+/* If non NULL, call this function when memory is exhausted. */
+void (*xalloc_fail_func) (void) = 0;
-/* FIXME: describe */
-void (*xalloc_fail_func) () = 0;
+/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
+ before exiting when memory is exhausted. Goes through gettext. */
+char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
-#if __STDC__ && (HAVE_VPRINTF || HAVE_DOPRNT)
-void error (int, int, const char *, ...);
-#else
-void error ();
-#endif
-
-static void
-xalloc_fail ()
+void
+xalloc_die (void)
{
if (xalloc_fail_func)
(*xalloc_fail_func) ();
- error (xalloc_exit_failure, 0, xalloc_msg_memory_exhausted);
+ error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
+ /* The `noreturn' cannot be given to error, since it may return if
+ its first argument is 0. To help compilers understand the
+ xalloc_die does terminate, call exit. */
+ exit (EXIT_FAILURE);
}
/* Allocate N bytes of memory dynamically, with error checking. */
void *
-xmalloc (n)
- size_t n;
+xmalloc (size_t n)
{
void *p;
p = malloc (n);
if (p == 0)
- xalloc_fail ();
+ xalloc_die ();
return p;
}
/* Change the size of an allocated block of memory P to N bytes,
- with error checking.
- If P is NULL, run xmalloc. */
+ with error checking. */
void *
-xrealloc (p, n)
- void *p;
- size_t n;
+xrealloc (void *p, size_t n)
{
p = realloc (p, n);
if (p == 0)
- xalloc_fail ();
+ xalloc_die ();
return p;
}
-#ifdef NOT_USED
-
/* Allocate memory for N elements of S bytes, with error checking. */
void *
-xcalloc (n, s)
- size_t n, s;
+xcalloc (size_t n, size_t s)
{
void *p;
p = calloc (n, s);
if (p == 0)
- xalloc_fail ();
+ xalloc_die ();
return p;
}
-
-#endif /* NOT_USED */