mirror of
https://github.com/darlinghq/darling-gpatch.git
synced 2024-11-23 03:59:40 +00:00
gpatch-3
This commit is contained in:
commit
f6bfe1451a
22
Makefile
Normal file
22
Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
##
|
||||
# Makefile for Patch
|
||||
##
|
||||
|
||||
# Project info
|
||||
Project = patch
|
||||
UserType = Developer
|
||||
ToolType = Commands
|
||||
Extra_CC_Flags = -mdynamic-no-pic
|
||||
GnuAfterInstall = install-plist
|
||||
|
||||
# It's a GNU Source project
|
||||
include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make
|
||||
|
||||
OSV = $(DSTROOT)/usr/local/OpenSourceVersions
|
||||
OSL = $(DSTROOT)/usr/local/OpenSourceLicenses
|
||||
|
||||
install-plist:
|
||||
$(MKDIR) $(OSV)
|
||||
$(INSTALL_FILE) $(SRCROOT)/patch_cmds.plist $(OSV)/gpatch.plist
|
||||
$(MKDIR) $(OSL)
|
||||
$(INSTALL_FILE) $(Sources)/COPYING $(OSL)/gpatch.txt
|
10
dpkg/control
Normal file
10
dpkg/control
Normal file
@ -0,0 +1,10 @@
|
||||
Package: patch-cmds
|
||||
Maintainer: Darwin Developers <darwin-development@public.lists.apple.com>
|
||||
Vendor: GNU Project
|
||||
Version: 2.5.4
|
||||
URL: ftp://prep.ai.mit.edu/pub/gnu/patch/
|
||||
Build-Depends: build-base, autoconf, gm4
|
||||
Description: Patch file applicator
|
||||
Patch takes a patch file patchfile containing a difference listing
|
||||
produced by the diff program and applies those differences to one or
|
||||
more original files, producing patched versions.
|
9
patch/AUTHORS
Normal file
9
patch/AUTHORS
Normal file
@ -0,0 +1,9 @@
|
||||
Larry Wall wrote the original version of `patch'.
|
||||
|
||||
Paul Eggert removed arbitrary limits; added support for binary
|
||||
files, setting file times, and deleting files; and made it conform
|
||||
better to POSIX.
|
||||
|
||||
Wayne Davison added unidiff support.
|
||||
|
||||
David MacKenzie added configuration and backup support.
|
340
patch/COPYING
Normal file
340
patch/COPYING
Normal file
@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
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 Library 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library General
|
||||
Public License instead of this License.
|
2168
patch/ChangeLog
Normal file
2168
patch/ChangeLog
Normal file
File diff suppressed because it is too large
Load Diff
228
patch/INSTALL
Normal file
228
patch/INSTALL
Normal file
@ -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.
|
||||
|
200
patch/Makefile.in
Normal file
200
patch/Makefile.in
Normal file
@ -0,0 +1,200 @@
|
||||
# Makefile for GNU patch.
|
||||
|
||||
# Copyright (C) 1993, 1997, 1998, 1999, 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; see the file COPYING.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#### Start of system configuration section. ####
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
CC = @CC@
|
||||
ed_PROGRAM = @ed_PROGRAM@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
transform = @program_transform_name@
|
||||
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
DEFS = @DEFS@
|
||||
EXEEXT = @EXEEXT@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = $(exec_prefix)/bin
|
||||
|
||||
# Where to put the manual pages.
|
||||
mandir = @mandir@
|
||||
man1dir = $(mandir)/man1
|
||||
# Extension (including `.') for the manual page filenames.
|
||||
man1ext = .1
|
||||
|
||||
# Hook for nonstandard builds.
|
||||
CONFIG_STATUS = config.status
|
||||
|
||||
#### End of system configuration section. ####
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
LIBSRCS = malloc.c memchr.c mkdir.c \
|
||||
realloc.c rename.c rmdir.c strcasecmp.c strncasecmp.c
|
||||
SRCS = $(LIBSRCS) \
|
||||
addext.c argmatch.c backupfile.c \
|
||||
basename.c dirname.c \
|
||||
error.c exitfail.c \
|
||||
getopt.c getopt1.c inp.c \
|
||||
maketime.c partime.c \
|
||||
patch.c pch.c \
|
||||
quote.c quotearg.c quotesys.c \
|
||||
util.c version.c xmalloc.c
|
||||
OBJS = $(LIBOBJS) \
|
||||
addext.$(OBJEXT) argmatch.$(OBJEXT) backupfile.$(OBJEXT) \
|
||||
basename.$(OBJEXT) dirname.$(OBJEXT) \
|
||||
error.$(OBJEXT) exitfail.$(OBJEXT) \
|
||||
getopt.$(OBJEXT) getopt1.$(OBJEXT) inp.$(OBJEXT) \
|
||||
maketime.$(OBJEXT) partime.$(OBJEXT) \
|
||||
patch.$(OBJEXT) pch.$(OBJEXT) \
|
||||
quote.$(OBJEXT) quotearg.$(OBJEXT) quotesys.$(OBJEXT) \
|
||||
util.$(OBJEXT) version.$(OBJEXT) xmalloc.$(OBJEXT)
|
||||
HDRS = argmatch.h backupfile.h common.h dirname.h \
|
||||
error.h exitfail.h getopt.h \
|
||||
inp.h maketime.h partime.h patchlevel.h pch.h \
|
||||
quote.h quotearg.h quotesys.h \
|
||||
unlocked-io.h util.h version.h xalloc.h
|
||||
MISC = AUTHORS COPYING ChangeLog INSTALL Makefile.in NEWS README \
|
||||
aclocal.m4 \
|
||||
config.hin configure configure.ac \
|
||||
install-sh mkinstalldirs patch.man
|
||||
DISTFILES = $(MISC) $(SRCS) $(HDRS)
|
||||
DISTFILES_M4 = $(ACINCLUDE_INPUTS)
|
||||
DISTFILES_PC = pc/chdirsaf.c
|
||||
DISTFILES_PC_DJGPP = pc/djgpp/README pc/djgpp/config.sed \
|
||||
pc/djgpp/configure.bat pc/djgpp/configure.sed
|
||||
|
||||
patch_name = `echo patch | sed '$(transform)'`
|
||||
|
||||
all:: patch$(EXEEXT)
|
||||
|
||||
info::
|
||||
check::
|
||||
installcheck::
|
||||
|
||||
COMPILE = $(CC) -c $(CPPFLAGS) $(DEFS) -Ded_PROGRAM=\"$(ed_PROGRAM)\" \
|
||||
-I. -I$(srcdir) $(CFLAGS)
|
||||
|
||||
.c.$(OBJEXT):
|
||||
$(COMPILE) $<
|
||||
|
||||
patch$(EXEEXT): $(OBJS)
|
||||
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS)
|
||||
|
||||
install:: all installdirs
|
||||
$(INSTALL_PROGRAM) patch$(EXEEXT) $(bindir)/$(patch_name)$(EXEEXT)
|
||||
-$(INSTALL_DATA) $(srcdir)/patch.man $(man1dir)/$(patch_name)$(man1ext)
|
||||
|
||||
installdirs::
|
||||
$(SHELL) $(srcdir)/mkinstalldirs $(bindir) $(man1dir)
|
||||
|
||||
install-strip::
|
||||
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
|
||||
|
||||
uninstall::
|
||||
rm -f $(bindir)/$(patch_name)$(EXEEXT)
|
||||
rm -f $(man1dir)/$(patch_name)$(man1ext)
|
||||
|
||||
Makefile: Makefile.in $(CONFIG_STATUS)
|
||||
$(SHELL) $(CONFIG_STATUS)
|
||||
config.status: configure
|
||||
$(SHELL) $(CONFIG_STATUS) --recheck
|
||||
configure: configure.ac $(srcdir)/aclocal.m4
|
||||
config.hin: configure.ac $(srcdir)/aclocal.m4
|
||||
|
||||
M4DIR = $(srcdir)/m4
|
||||
ACINCLUDE_INPUTS = $(M4DIR)/c-bs-a.m4 $(M4DIR)/d-ino.m4 $(M4DIR)/error.m4 \
|
||||
$(M4DIR)/jm-glibc-io.m4 $(M4DIR)/malloc.m4 $(M4DIR)/mbstate_t.m4 \
|
||||
$(M4DIR)/mkdir.m4 $(M4DIR)/mbrtowc.m4 \
|
||||
$(M4DIR)/prereq.m4 $(M4DIR)/realloc.m4 \
|
||||
$(M4DIR)/setmode.m4 $(M4DIR)/utimbuf.m4
|
||||
|
||||
$(srcdir)/aclocal.m4: $(ACINCLUDE_INPUTS)
|
||||
cat $(ACINCLUDE_INPUTS) >$(srcdir)/aclocal.m4
|
||||
|
||||
patchlevel.h: configure
|
||||
echo '#define PATCH_VERSION "$(PACKAGE_VERSION)"' >patchlevel.h
|
||||
|
||||
TAGS: $(HDRS) patchlevel.h $(SRCS)
|
||||
etags $(HDRS) patchlevel.h $(SRCS)
|
||||
|
||||
mostlyclean::
|
||||
rm -f core* *core *.$(OBJEXT) *_.c
|
||||
|
||||
clean:: mostlyclean
|
||||
rm -f patch$(EXEEXT)
|
||||
|
||||
distclean:: clean
|
||||
rm -f Makefile config.cache config.log config.status config.h
|
||||
|
||||
maintainer-clean::
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "rebuilding the deleted files requires special tools."
|
||||
$(MAKE) distclean
|
||||
rm -f TAGS
|
||||
|
||||
PV = $(PACKAGE_NAME)-$(PACKAGE_VERSION)
|
||||
|
||||
dist:: $(DISTFILES) $(DISTFILES_M4) $(DISTFILES_PC) $(DISTFILES_PC_DJGPP)
|
||||
rm -rf $(PV)
|
||||
mkdir $(PV) $(PV)/m4 $(PV)/pc $(PV)/pc/djgpp
|
||||
cp -p $(DISTFILES) $(PV)
|
||||
cp -p $(DISTFILES_M4) $(PV)/m4
|
||||
cp -p $(DISTFILES_PC) $(PV)/pc
|
||||
cp -p $(DISTFILES_PC_DJGPP) $(PV)/pc/djgpp
|
||||
tar -chf - $(PV) | gzip -9 >$(PV).tar.gz
|
||||
rm -rf $(PV)
|
||||
|
||||
$(OBJS): config.h
|
||||
addext.$(OBJEXT): backupfile.h dirname.h
|
||||
argmatch.$(OBJEXT): argmatch.h error.h quote.h quotearg.h unlocked-io.h
|
||||
backupfile.$(OBJEXT): argmatch.h backupfile.h dirname.h
|
||||
basename.$(OBJEXT): dirname.h
|
||||
error.$(OBJEXT): error.h unlocked-io.h
|
||||
getopt.$(OBJEXT) getopt1.$(OBJEXT): getopt.h
|
||||
inp.$(OBJEXT): backupfile.h common.h inp.h pch.h quotearg.h util.h xalloc.h
|
||||
maketime.$(OBJEXT): maketime.h partime.h
|
||||
mkdir.$(OBJEXT): dirname.h xalloc.h
|
||||
partime.$(OBJEXT): partime.h
|
||||
patch.$(OBJEXT): argmatch.h backupfile.h common.h exitfail.h getopt.h inp.h \
|
||||
pch.h quotearg.h util.h version.h xalloc.h
|
||||
pch.$(OBJEXT): backupfile.h common.h dirname.h inp.h pch.h quotearg.h util.h
|
||||
quotearg.$(OBJEXT): quotearg.h xalloc.h
|
||||
quotesys.$(OBJEXT): quotesys.h
|
||||
rename.$(OBJEXT): dirname.h xalloc.h
|
||||
util.$(OBJEXT): backupfile.h common.h dirname.h maketime.h \
|
||||
partime.h quotearg.h quotesys.h util.h version.h xalloc.h
|
||||
version.$(OBJEXT): common.h patchlevel.h util.h version.h
|
||||
xmalloc.$(OBJEXT): exitfail.h xalloc.h
|
237
patch/NEWS
Normal file
237
patch/NEWS
Normal file
@ -0,0 +1,237 @@
|
||||
Changes in version 2.5.8: bug fixes only.
|
||||
|
||||
Changes in version 2.5.7:
|
||||
|
||||
* patch -D now outputs preprocessor lines without comments, as required
|
||||
by POSIX 1003.1-2001.
|
||||
|
||||
Changes in version 2.5.6:
|
||||
|
||||
* File names in context patches may now contain spaces, so long
|
||||
as the context patch headers use a tab to separate the file name
|
||||
from the time stamp.
|
||||
* Perforce is now supported.
|
||||
* Patch lines beginning with "#" are comments and are ignored.
|
||||
|
||||
Changes in version 2.5.5:
|
||||
|
||||
* The bug reporting address is now <bug-patch@gnu.org>.
|
||||
|
||||
Changes in version 2.5.4:
|
||||
|
||||
* A security hole has been closed.
|
||||
It involved race conditions with temporary files.
|
||||
|
||||
* The default quoting style is 'shell', which causes `patch' to quote
|
||||
file names with funny characters like `$'. This prevents their
|
||||
misinterpretation if you cut them from its output and paste them into
|
||||
the shell.
|
||||
|
||||
* `patch' now works correctly with large files on Large File Summit
|
||||
hosts like Solaris 2.6.
|
||||
|
||||
* `patch' now ignores trailing carriage returns in lines of context diffs
|
||||
if the context diff headers end in carriage return.
|
||||
|
||||
* `patch' now ignores context diff header file names that have fewer slashes
|
||||
than the count specified by the -p or --strip option.
|
||||
|
||||
* New options:
|
||||
--posix
|
||||
--quoting-style=WORD
|
||||
|
||||
* New environment variables:
|
||||
QUOTING_STYLE
|
||||
|
||||
* `patch' now supports ClearCase version management.
|
||||
|
||||
Changes in version 2.5:
|
||||
|
||||
* Version control is now independent of whether backups are made.
|
||||
The -V or --version-control option and the VERSION_CONTROL and
|
||||
PATCH_VERSION_CONTROL environment variables no longer affect whether
|
||||
backups are made; they affect only the names of the backup files.
|
||||
|
||||
* When asking the user whether to reverse a patch,
|
||||
the default answer is now `no' instead of `yes'.
|
||||
|
||||
* `patch' can now recognize context diffs that have been encapsulated
|
||||
by prepending "- " to lines beginning with "-" (as per Internet RFC 934).
|
||||
|
||||
* `patch' now reports an error if the input contains garbage and no patches.
|
||||
|
||||
Changes in version 2.4:
|
||||
|
||||
* New options:
|
||||
-Z or --set-utc sets times of patched files, assuming diff uses UTC (GMT).
|
||||
-T or --set-time is similar, assuming local time (not recommended).
|
||||
--backup-if-mismatch makes a backup if the patch does not match exactly
|
||||
--no-backup-if-mismatch makes a backup only if otherwise requested
|
||||
|
||||
* The default is now --backup-if-mismatch unless POSIXLY_CORRECT is set.
|
||||
|
||||
* The -B or --prefix, -Y or --basename-prefix, and -z or --suffix options
|
||||
no longer affect whether backups are made (as they did in patch 2.2 and 2.3);
|
||||
they now merely specify the file names used when simple backups are made.
|
||||
|
||||
* When patching a nonexistent file and making backups, an empty backup file
|
||||
is now made (just as with traditional patch); but the backup file is
|
||||
unreadable, as a way of indicating that it represents a nonexistent file.
|
||||
|
||||
* `patch' now matches against empty and nonexistent files more generously.
|
||||
A patch against an empty file applies to a nonexistent file, and vice versa.
|
||||
|
||||
* -g or --get and PATCH_GET now have a numeric value that specifies
|
||||
whether `patch' is getting files.
|
||||
If the value is positive, working files are gotten from RCS or SCCS files;
|
||||
if zero, `patch' ignores RCS and SCCS and working files are not gotten;
|
||||
and if negative, `patch' asks the user whether to get each file.
|
||||
The default is normally negative, but it is zero if POSIXLY_CORRECT is set.
|
||||
|
||||
* The -G or --no-get option introduced in GNU patch 2.3 has been removed;
|
||||
use -g0 instead.
|
||||
|
||||
* The method used to intuit names of files to be patched is changed again:
|
||||
`Index:' lines are normally ignored for context diffs,
|
||||
and RCS and SCCS files are normally looked for when files do not exist.
|
||||
The complete new method is described in the man page.
|
||||
|
||||
* By default, `patch' is now more verbose when patches do not match exactly.
|
||||
|
||||
* The manual page has a new COMPATIBILITY ISSUES section.
|
||||
|
||||
Changes in version 2.3:
|
||||
|
||||
* Unless the POSIXLY_CORRECT environment variable is set:
|
||||
|
||||
- `patch' now distinguishes more accurately between empty and
|
||||
nonexistent files if the input is a context diff.
|
||||
A file is assumed to not exist if its context diff header
|
||||
suggests that it is empty, and if the header timestamp
|
||||
looks like it might be equivalent to 1970-01-01 00:00:00 UTC.
|
||||
- Files that ``become nonexistent'' after patching are now removed.
|
||||
When a file is removed, any empty ancestor directories are also removed.
|
||||
|
||||
* Files are now automatically gotten from RCS and SCCS
|
||||
if the -g or --get option is specified.
|
||||
(The -G or --no-get option, also introduced in 2.3, was withdrawn in 2.4.)
|
||||
|
||||
* If the PATCH_VERSION_CONTROL environment variable is set,
|
||||
it overrides the VERSION_CONTROL environment variable.
|
||||
|
||||
* The method used to intuit names of files to be patched is changed.
|
||||
(It was further revised in 2.4; see above.)
|
||||
|
||||
* The new --binary option makes `patch' read and write files in binary mode.
|
||||
This option has no effect on POSIX-compliant hosts;
|
||||
it is useful only in on operating systems like DOS
|
||||
that distinguish between text and binary I/O.
|
||||
|
||||
* The environment variables TMP and TEMP are consulted for the name of
|
||||
the temporary directory if TMPDIR is not set.
|
||||
|
||||
* A port to MS-DOS and MS-Windows is available; see the `pc' directory.
|
||||
|
||||
* Backup file names are no longer ever computed by uppercasing characters,
|
||||
since this isn't portable to systems with case-insensitive file names.
|
||||
|
||||
Changes in version 2.2:
|
||||
|
||||
* Arbitrary limits removed (e.g. line length, file name length).
|
||||
|
||||
* On POSIX.1-compliant hosts, you can now patch binary files using the output
|
||||
of GNU `diff -a'.
|
||||
|
||||
* New options:
|
||||
--dry-run
|
||||
--help
|
||||
--verbose
|
||||
-i FILE or --input=FILE
|
||||
-Y PREF or --basename-prefix=PREF
|
||||
|
||||
* patch is now quieter by default; use --verbose for the old chatty behavior.
|
||||
|
||||
* Patch now complies better with POSIX.2 if your host complies with POSIX.1.
|
||||
|
||||
Therefore:
|
||||
- By default, no backups are made.
|
||||
(But this was changed again in patch 2.4; see above.)
|
||||
- The simple backup file name for F defaults to F.orig
|
||||
regardless of whether the file system supports long file names,
|
||||
and F~ is used only if F.orig is too long for that particular file.
|
||||
- Similarly for the reject file names F.rej and F#.
|
||||
|
||||
Also:
|
||||
- The pseudo-option `+' has been withdrawn.
|
||||
- -b is equivalent to --version-control=simple;
|
||||
`-z SUFF' has the meaning that `-b SUFF' used to.
|
||||
- Names of files to be patched are taken first from *** line and then from
|
||||
--- line of context diffs; then from Index: line; /dev/tty is
|
||||
consulted if none of the above files exist. However, if the patch
|
||||
appears to create a file, the file does not have to exist: instead,
|
||||
the first name with the longest existing directory prefix is taken.
|
||||
(These rules were changed again in patch 2.3 and 2.4; see above.)
|
||||
- Exit status 0 means success, 1 means hunks were rejected, 2 means trouble.
|
||||
- `-l' ignores changes only in spaces and tabs, not in other white space.
|
||||
- If no `-p' option is given, `-pINFINITY' is assumed, instead of trying
|
||||
to guess the proper value.
|
||||
- `-p' now requires an operand; use `-p 0' to get the effect of the old plain
|
||||
`-p' option.
|
||||
- `-p' treats two or more adjacent slashes as if it were one slash.
|
||||
- The TERM signal is caught.
|
||||
- New option `-i F' reads patch from F instead of stdin.
|
||||
|
||||
* The `patch' options and build procedure conform to current GNU standards.
|
||||
For example, the `--version' option now outputs copyright information.
|
||||
|
||||
* When the patch is creating a file, but a nonempty file of that name already
|
||||
exists, `patch' now asks for confirmation before patching.
|
||||
|
||||
* RCS is used only if the version control method is `existing'
|
||||
and there is already an RCS file. Similarly for SCCS.
|
||||
(But this was changed again in patch 2.3 and 2.4; see above.)
|
||||
|
||||
* Copyright notices have been clarified. Every file in this version of `patch'
|
||||
can be distributed under the GNU General Public License. See README for
|
||||
details.
|
||||
|
||||
Changes in version 2.1:
|
||||
|
||||
* A few more portability bugs have been fixed. The version number has
|
||||
been changed from 2.0.12g11 to 2.1, because the name
|
||||
`patch-2.0.12g10' was too long for traditional Unix file systems.
|
||||
|
||||
Versions 2.0.12g9 through 2.0.12g11 fix various portability bugs.
|
||||
|
||||
Changes in version 2.0.12g8:
|
||||
|
||||
* Start of the 12g series, with a GNU-style configure script and
|
||||
long-named options.
|
||||
* Added the -t --batch option, similar to -f.
|
||||
* Improved detection of files that are locked under RCS or SCCS.
|
||||
* Reinstate the -E option to remove output files that are empty after
|
||||
being patched.
|
||||
* Print the system error message when system calls fail.
|
||||
* Fixed various bugs and portability problems.
|
||||
|
||||
|
||||
|
||||
Copyright (C) 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.
|
54
patch/README
Normal file
54
patch/README
Normal file
@ -0,0 +1,54 @@
|
||||
This version of `patch' has many changes made by the Free Software Foundation.
|
||||
They add support for:
|
||||
* handling arbitrary binary data and large files
|
||||
* the unified context diff format that GNU diff can produce
|
||||
* making GNU Emacs-style backup files
|
||||
* improved interaction with RCS and SCCS
|
||||
* the GNU conventions for option parsing and configuring and compilation.
|
||||
* better POSIX compliance
|
||||
They also fix some bugs. See the NEWS and ChangeLog files for details.
|
||||
|
||||
Tutorial-style documentation for patch is included in the GNU
|
||||
Diffutils package; get GNU Diffutils 2.8 or later for up-to-date
|
||||
documentation for patch.
|
||||
|
||||
For GNU and Unix build and installation instructions, see the file INSTALL.
|
||||
Use `configure --disable-largefile' to disable large file support;
|
||||
this is reportedly necessary on Red Hat GNU/Linux 6.0 to avoid a C library bug.
|
||||
For MS-DOS using DJGPP tools, see the file pc/djgpp/README.
|
||||
For other systems, copy config.hin to config.h and change
|
||||
#undef statements in it to #define as appropriate for your system,
|
||||
and copy Makefile.in to Makefile and set the variables that are
|
||||
enclosed in @ signs as appropriate for your system.
|
||||
|
||||
Please send bug reports for this version of patch to
|
||||
<bug-patch@gnu.org>.
|
||||
|
||||
The Free Software Foundation is distributing this version of patch
|
||||
independently because as of this writing, Larry Wall has not released a
|
||||
new version of patch since mid-1988. We have heard that he has been
|
||||
too busy working on other things, like Perl. He has graciously agreed
|
||||
to let GNU `patch' be distributed under the terms of the GNU General
|
||||
Public License.
|
||||
|
||||
------
|
||||
|
||||
Copyright (C) 1984, 1985, 1986, 1987, 1988 Larry Wall
|
||||
|
||||
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1997, 1999, 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 file; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
495
patch/aclocal.m4
vendored
Normal file
495
patch/aclocal.m4
vendored
Normal file
@ -0,0 +1,495 @@
|
||||
# c-bs-a.m4 serial 4 (fileutils-4.1.3)
|
||||
dnl Copyright (C) 2000-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.
|
||||
|
||||
AC_DEFUN([AC_C_BACKSLASH_A],
|
||||
[
|
||||
AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
|
||||
[AC_TRY_COMPILE([],
|
||||
[
|
||||
#if '\a' == 'a'
|
||||
syntax error;
|
||||
#endif
|
||||
char buf['\a' == 'a' ? -1 : 1];
|
||||
buf[0] = '\a';
|
||||
return buf[0] != "\a"[0];
|
||||
],
|
||||
ac_cv_c_backslash_a=yes,
|
||||
ac_cv_c_backslash_a=no)])
|
||||
if test $ac_cv_c_backslash_a = yes; then
|
||||
AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
|
||||
[Define if backslash-a works in C strings.])
|
||||
fi
|
||||
])
|
||||
#serial 4
|
||||
|
||||
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
|
||||
]
|
||||
)
|
||||
#serial 4
|
||||
|
||||
dnl FIXME: put these prerequisite-only *.m4 files in a separate
|
||||
dnl directory -- otherwise, they'll conflict with existing files.
|
||||
|
||||
dnl These are the prerequisite macros for GNU's error.c file.
|
||||
AC_DEFUN([jm_PREREQ_ERROR],
|
||||
[
|
||||
AC_CHECK_FUNCS(strerror vprintf doprnt)
|
||||
AC_CHECK_DECLS([strerror])
|
||||
AC_FUNC_STRERROR_R
|
||||
AC_HEADER_STDC
|
||||
])
|
||||
#serial 7 -*- autoconf -*-
|
||||
|
||||
dnl From Jim Meyering.
|
||||
dnl
|
||||
dnl See if the glibc *_unlocked I/O macros are available.
|
||||
dnl Use only those *_unlocked macros that are declared.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([jm_FUNC_GLIBC_UNLOCKED_IO],
|
||||
[AC_CHECK_DECLS(
|
||||
[clearerr_unlocked, feof_unlocked, ferror_unlocked,
|
||||
fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked,
|
||||
fread_unlocked, fwrite_unlocked, getc_unlocked,
|
||||
getchar_unlocked, putc_unlocked, putchar_unlocked])])
|
||||
#serial 6
|
||||
|
||||
dnl From Jim Meyering.
|
||||
dnl Determine whether malloc accepts 0 as its argument.
|
||||
dnl If it doesn't, arrange to use the replacement function.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([jm_FUNC_MALLOC],
|
||||
[
|
||||
dnl xmalloc.c requires that this symbol be defined so it doesn't
|
||||
dnl mistakenly use a broken malloc -- as it might if this test were omitted.
|
||||
AC_DEFINE(HAVE_DONE_WORKING_MALLOC_CHECK, 1,
|
||||
[Define if the malloc check has been performed. ])
|
||||
|
||||
AC_CACHE_CHECK([whether malloc(0) returns a non-NULL pointer],
|
||||
jm_cv_func_working_malloc,
|
||||
[AC_TRY_RUN([
|
||||
char *malloc ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
exit (malloc (0) ? 0 : 1);
|
||||
}
|
||||
],
|
||||
jm_cv_func_working_malloc=yes,
|
||||
jm_cv_func_working_malloc=no,
|
||||
dnl When crosscompiling, assume malloc(0) returns NULL.
|
||||
jm_cv_func_working_malloc=no)
|
||||
])
|
||||
if test $jm_cv_func_working_malloc = no; then
|
||||
AC_LIBOBJ(malloc)
|
||||
AC_DEFINE(malloc, rpl_malloc,
|
||||
[Define to rpl_malloc if the replacement function should be used.])
|
||||
fi
|
||||
])
|
||||
# mbstate_t.m4 serial 9 (fileutils-4.1.3)
|
||||
dnl Copyright (C) 2000-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.
|
||||
|
||||
# Include stdlib.h first, because otherwise this test would fail on Linux
|
||||
# (at least glibc-2.1.3) because the "_XOPEN_SOURCE 500" definition elicits
|
||||
# a syntax error in wchar.h due to the use of undefined __int32_t.
|
||||
|
||||
AC_DEFUN([AC_MBSTATE_T],
|
||||
[
|
||||
AC_CHECK_HEADERS(stdlib.h)
|
||||
|
||||
AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
|
||||
[AC_TRY_COMPILE([
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#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,ma
|
||||
[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])
|
||||
#serial 1
|
||||
|
||||
dnl From Mumit Khan and Paul Eggert
|
||||
dnl Determine whether mkdir accepts only one argument instead of the usual two.
|
||||
|
||||
AC_DEFUN([PATCH_FUNC_MKDIR_TAKES_ONE_ARG],
|
||||
[AC_CHECK_FUNCS(mkdir)
|
||||
AC_CACHE_CHECK([whether mkdir takes only one argument],
|
||||
patch_cv_mkdir_takes_one_arg,
|
||||
[patch_cv_mkdir_takes_one_arg=no
|
||||
if test $ac_cv_func_mkdir = yes; then
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
],
|
||||
[mkdir (".", 0);],
|
||||
,
|
||||
[AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
],
|
||||
[mkdir (".");],
|
||||
patch_cv_mkdir_takes_one_arg=yes
|
||||
)]
|
||||
)
|
||||
fi
|
||||
]
|
||||
)
|
||||
if test $patch_cv_mkdir_takes_one_arg = yes; then
|
||||
AC_DEFINE([MKDIR_TAKES_ONE_ARG], 1,
|
||||
[Define if mkdir takes only one argument.])
|
||||
fi
|
||||
]
|
||||
)
|
||||
# mbrtowc.m4 serial 4 (fileutils-4.1.3)
|
||||
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
|
||||
|
||||
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
|
||||
])
|
||||
#serial 22
|
||||
|
||||
dnl These are the prerequisite macros for files in the lib/
|
||||
dnl directories of the fileutils, sh-utils, and textutils packages.
|
||||
|
||||
AC_DEFUN([jm_PREREQ],
|
||||
[
|
||||
jm_PREREQ_ADDEXT
|
||||
jm_PREREQ_CANON_HOST
|
||||
jm_PREREQ_DIRNAME
|
||||
jm_PREREQ_ERROR
|
||||
jm_PREREQ_EXCLUDE
|
||||
jm_PREREQ_GETPAGESIZE
|
||||
jm_PREREQ_HARD_LOCALE
|
||||
jm_PREREQ_HASH
|
||||
jm_PREREQ_HUMAN
|
||||
jm_PREREQ_MBSWIDTH
|
||||
jm_PREREQ_MEMCHR
|
||||
jm_PREREQ_PHYSMEM
|
||||
jm_PREREQ_POSIXVER
|
||||
jm_PREREQ_QUOTEARG
|
||||
jm_PREREQ_READUTMP
|
||||
jm_PREREQ_REGEX
|
||||
jm_PREREQ_TEMPNAME # called by mkstemp
|
||||
jm_PREREQ_XGETCWD
|
||||
jm_PREREQ_XREADLINK
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_ADDEXT],
|
||||
[
|
||||
dnl For addext.c.
|
||||
AC_SYS_LONG_FILE_NAMES
|
||||
AC_CHECK_FUNCS(pathconf)
|
||||
AC_CHECK_HEADERS(limits.h string.h unistd.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_CANON_HOST],
|
||||
[
|
||||
dnl Add any libraries as early as possible.
|
||||
dnl In particular, inet_ntoa needs -lnsl at least on Solaris5.5.1,
|
||||
dnl so we have to add -lnsl to LIBS before checking for that function.
|
||||
AC_SEARCH_LIBS(gethostbyname, [inet nsl])
|
||||
|
||||
dnl These come from -lnsl on Solaris5.5.1.
|
||||
AC_CHECK_FUNCS(gethostbyname gethostbyaddr inet_ntoa)
|
||||
|
||||
AC_CHECK_FUNCS(gethostbyname gethostbyaddr inet_ntoa)
|
||||
AC_CHECK_HEADERS(unistd.h string.h netdb.h sys/socket.h \
|
||||
netinet/in.h arpa/inet.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_DIRNAME],
|
||||
[
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(string.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_EXCLUDE],
|
||||
[
|
||||
AC_FUNC_FNMATCH_GNU([lib])
|
||||
AC_HEADER_STDBOOL
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_GETPAGESIZE],
|
||||
[
|
||||
AC_CHECK_FUNCS(getpagesize)
|
||||
AC_CHECK_HEADERS(OS.h unistd.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_HARD_LOCALE],
|
||||
[
|
||||
AC_C_PROTOTYPES
|
||||
AC_CHECK_FUNCS(setlocale)
|
||||
AC_CHECK_HEADERS(locale.h stdlib.h string.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_HASH],
|
||||
[
|
||||
AC_CHECK_HEADERS(stdlib.h)
|
||||
AC_HEADER_STDBOOL
|
||||
AC_REQUIRE([jm_CHECK_DECLS])
|
||||
])
|
||||
|
||||
# If you use human.c, you need the following files:
|
||||
# inttypes.m4 ulonglong.m4
|
||||
AC_DEFUN([jm_PREREQ_HUMAN],
|
||||
[
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h string.h)
|
||||
AC_CHECK_DECLS([getenv])
|
||||
AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_MEMCHR],
|
||||
[
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h bp-sym.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_PHYSMEM],
|
||||
[
|
||||
AC_CHECK_HEADERS(sys/pstat.h unistd.h)
|
||||
AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_POSIXVER],
|
||||
[
|
||||
AC_CHECK_HEADERS(unistd.h)
|
||||
AC_CHECK_DECLS([getenv])
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_QUOTEARG],
|
||||
[
|
||||
AC_CHECK_FUNCS(isascii iswprint)
|
||||
jm_FUNC_MBRTOWC
|
||||
AC_CHECK_HEADERS(limits.h stddef.h stdlib.h string.h wchar.h wctype.h)
|
||||
AC_HEADER_STDC
|
||||
AC_C_BACKSLASH_A
|
||||
AC_MBSTATE_T
|
||||
AC_C_PROTOTYPES
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_REGEX],
|
||||
[
|
||||
dnl FIXME: Maybe provide a btowc replacement someday: solaris-2.5.1 lacks it.
|
||||
dnl FIXME: Check for wctype and iswctype, and and add -lw if necessary
|
||||
dnl to get them.
|
||||
AC_CHECK_FUNCS(bzero bcopy isascii btowc)
|
||||
AC_CHECK_HEADERS(alloca.h libintl.h wctype.h wchar.h)
|
||||
AC_HEADER_STDC
|
||||
AC_FUNC_ALLOCA
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_TEMPNAME],
|
||||
[
|
||||
AC_HEADER_STDC
|
||||
AC_HEADER_STAT
|
||||
AC_CHECK_HEADERS(fcntl.h sys/time.h stdint.h unistd.h)
|
||||
AC_CHECK_FUNCS(__secure_getenv gettimeofday)
|
||||
AC_CHECK_DECLS([getenv])
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_XGETCWD],
|
||||
[
|
||||
AC_C_PROTOTYPES
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h sys/param.h unistd.h)
|
||||
AC_CHECK_FUNCS(getcwd)
|
||||
AC_FUNC_GETCWD_NULL
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_XREADLINK],
|
||||
[
|
||||
AC_C_PROTOTYPES
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h sys/types.h unistd.h)
|
||||
])
|
||||
#serial 6
|
||||
|
||||
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.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([jm_FUNC_REALLOC],
|
||||
[
|
||||
dnl xmalloc.c requires that this symbol be defined so it doesn't
|
||||
dnl mistakenly use a broken realloc -- as it might if this test were omitted.
|
||||
AC_DEFINE(HAVE_DONE_WORKING_REALLOC_CHECK, 1,
|
||||
[Define if the realloc check has been performed. ])
|
||||
|
||||
AC_CACHE_CHECK([whether realloc(0,0) returns a non-NULL pointer],
|
||||
jm_cv_func_working_realloc,
|
||||
[AC_TRY_RUN([
|
||||
char *realloc ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
exit (realloc (0, 0) ? 0 : 1);
|
||||
}
|
||||
],
|
||||
jm_cv_func_working_realloc=yes,
|
||||
jm_cv_func_working_realloc=no,
|
||||
dnl When crosscompiling, assume realloc(0,0) returns NULL.
|
||||
jm_cv_func_working_realloc=no)
|
||||
])
|
||||
if test $jm_cv_func_working_realloc = no; then
|
||||
AC_LIBOBJ(realloc)
|
||||
AC_DEFINE(realloc, rpl_realloc,
|
||||
[Define to rpl_realloc if the replacement function should be used.])
|
||||
fi
|
||||
])
|
||||
# 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])
|
||||
#serial 4
|
||||
|
||||
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(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
|
||||
])
|
114
patch/addext.c
Normal file
114
patch/addext.c
Normal file
@ -0,0 +1,114 @@
|
||||
/* addext.c -- add an extension to a file name
|
||||
Copyright 1990, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and Paul Eggert */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DOS_FILE_NAMES
|
||||
# define HAVE_DOS_FILE_NAMES 0
|
||||
#endif
|
||||
#ifndef HAVE_LONG_FILE_NAMES
|
||||
# define HAVE_LONG_FILE_NAMES 0
|
||||
#endif
|
||||
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef _POSIX_NAME_MAX
|
||||
# define _POSIX_NAME_MAX 14
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#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 (char *filename, char const *ext, int e)
|
||||
{
|
||||
char *s = base_name (filename);
|
||||
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 (_POSIX_NAME_MAX < slen + extlen || HAVE_DOS_FILE_NAMES)
|
||||
{
|
||||
/* 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)
|
||||
slen_max = name_max == (size_t) name_max ? name_max : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (HAVE_DOS_FILE_NAMES && slen_max <= 12)
|
||||
{
|
||||
/* Live within DOS's 8.3 limit. */
|
||||
char *dot = strchr (s, '.');
|
||||
if (dot)
|
||||
{
|
||||
slen -= dot + 1 - s;
|
||||
s = dot + 1;
|
||||
slen_max = 3;
|
||||
}
|
||||
else
|
||||
slen_max = 8;
|
||||
extlen = 9; /* Don't use EXT. */
|
||||
}
|
||||
|
||||
if (slen + extlen <= slen_max)
|
||||
strcpy (s + slen, ext);
|
||||
else
|
||||
{
|
||||
if (slen_max <= slen)
|
||||
slen = slen_max - 1;
|
||||
s[slen] = e;
|
||||
s[slen + 1] = 0;
|
||||
}
|
||||
}
|
36
patch/ansi2knr.1
Normal file
36
patch/ansi2knr.1
Normal file
@ -0,0 +1,36 @@
|
||||
.TH ANSI2KNR 1 "19 Jan 1996"
|
||||
.SH NAME
|
||||
ansi2knr \- convert ANSI C to Kernighan & Ritchie C
|
||||
.SH SYNOPSIS
|
||||
.I ansi2knr
|
||||
[--varargs] input_file [output_file]
|
||||
.SH DESCRIPTION
|
||||
If no output_file is supplied, output goes to stdout.
|
||||
.br
|
||||
There are no error messages.
|
||||
.sp
|
||||
.I ansi2knr
|
||||
recognizes function definitions by seeing a non-keyword identifier at the left
|
||||
margin, followed by a left parenthesis, with a right parenthesis as the last
|
||||
character on the line, and with a left brace as the first token on the
|
||||
following line (ignoring possible intervening comments). It will recognize a
|
||||
multi-line header provided that no intervening line ends with a left or right
|
||||
brace or a semicolon. These algorithms ignore whitespace and comments, except
|
||||
that the function name must be the first thing on the line.
|
||||
.sp
|
||||
The following constructs will confuse it:
|
||||
.br
|
||||
- Any other construct that starts at the left margin and follows the
|
||||
above syntax (such as a macro or function call).
|
||||
.br
|
||||
- Some macros that tinker with the syntax of the function header.
|
||||
.sp
|
||||
The --varargs switch is obsolete, and is recognized only for
|
||||
backwards compatibility. The present version of
|
||||
.I ansi2knr
|
||||
will always attempt to convert a ... argument to va_alist and va_dcl.
|
||||
.SH AUTHOR
|
||||
L. Peter Deutsch <ghost@aladdin.com> wrote the original ansi2knr and
|
||||
continues to maintain the current version; most of the code in the current
|
||||
version is his work. ansi2knr also includes contributions by Francois
|
||||
Pinard <pinard@iro.umontreal.ca> and Jim Avera <jima@netcom.com>.
|
678
patch/ansi2knr.c
Normal file
678
patch/ansi2knr.c
Normal file
@ -0,0 +1,678 @@
|
||||
/* Copyright (C) 1989, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. */
|
||||
|
||||
/*$Id: ansi2knr.c,v 1.1 2000/05/06 22:44:51 wsanchez Exp $*/
|
||||
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
|
||||
|
||||
/*
|
||||
ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY. No author or distributor accepts responsibility to anyone for the
|
||||
consequences of using it or for whether it serves any particular purpose or
|
||||
works at all, unless he says so in writing. Refer to the GNU General Public
|
||||
License (the "GPL") for full details.
|
||||
|
||||
Everyone is granted permission to copy, modify and redistribute ansi2knr,
|
||||
but only under the conditions described in the GPL. A copy of this license
|
||||
is supposed to have been given to you along with ansi2knr so you can know
|
||||
your rights and responsibilities. It should be in a file named COPYLEFT,
|
||||
or, if there is no file named COPYLEFT, a file named COPYING. Among other
|
||||
things, the copyright notice and this notice must be preserved on all
|
||||
copies.
|
||||
|
||||
We explicitly state here what we believe is already implied by the GPL: if
|
||||
the ansi2knr program is distributed as a separate set of sources and a
|
||||
separate executable file which are aggregated on a storage medium together
|
||||
with another program, this in itself does not bring the other program under
|
||||
the GPL, nor does the mere fact that such a program or the procedures for
|
||||
constructing it invoke the ansi2knr executable bring any other part of the
|
||||
program under the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]
|
||||
* --filename provides the file name for the #line directive in the output,
|
||||
* overriding input_file (if present).
|
||||
* If no input_file is supplied, input is read from stdin.
|
||||
* If no output_file is supplied, output goes to stdout.
|
||||
* There are no error messages.
|
||||
*
|
||||
* ansi2knr recognizes function definitions by seeing a non-keyword
|
||||
* identifier at the left margin, followed by a left parenthesis,
|
||||
* with a right parenthesis as the last character on the line,
|
||||
* and with a left brace as the first token on the following line
|
||||
* (ignoring possible intervening comments), except that a line
|
||||
* consisting of only
|
||||
* identifier1(identifier2)
|
||||
* will not be considered a function definition unless identifier2 is
|
||||
* the word "void", and a line consisting of
|
||||
* identifier1(identifier2, <<arbitrary>>)
|
||||
* will not be considered a function definition.
|
||||
* ansi2knr will recognize a multi-line header provided
|
||||
* that no intervening line ends with a left or right brace or a semicolon.
|
||||
* These algorithms ignore whitespace and comments, except that
|
||||
* the function name must be the first thing on the line.
|
||||
* The following constructs will confuse it:
|
||||
* - Any other construct that starts at the left margin and
|
||||
* follows the above syntax (such as a macro or function call).
|
||||
* - Some macros that tinker with the syntax of function headers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The original and principal author of ansi2knr is L. Peter Deutsch
|
||||
* <ghost@aladdin.com>. Other authors are noted in the change history
|
||||
* that follows (in reverse chronological order):
|
||||
lpd 1999-04-12 added minor fixes from Pavel Roskin
|
||||
<pavel_roskin@geocities.com> for clean compilation with
|
||||
gcc -W -Wall
|
||||
lpd 1999-03-22 added hack to recognize lines consisting of
|
||||
identifier1(identifier2, xxx) as *not* being procedures
|
||||
lpd 1999-02-03 made indentation of preprocessor commands consistent
|
||||
lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an
|
||||
endless loop; quoted strings within an argument list
|
||||
confused the parser
|
||||
lpd 1999-01-24 added a check for write errors on the output,
|
||||
suggested by Jim Meyering <meyering@ascend.com>
|
||||
lpd 1998-11-09 added further hack to recognize identifier(void)
|
||||
as being a procedure
|
||||
lpd 1998-10-23 added hack to recognize lines consisting of
|
||||
identifier1(identifier2) as *not* being procedures
|
||||
lpd 1997-12-08 made input_file optional; only closes input and/or
|
||||
output file if not stdin or stdout respectively; prints
|
||||
usage message on stderr rather than stdout; adds
|
||||
--filename switch (changes suggested by
|
||||
<ceder@lysator.liu.se>)
|
||||
lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with
|
||||
compilers that don't understand void, as suggested by
|
||||
Tom Lane
|
||||
lpd 1996-01-15 changed to require that the first non-comment token
|
||||
on the line following a function header be a left brace,
|
||||
to reduce sensitivity to macros, as suggested by Tom Lane
|
||||
<tgl@sss.pgh.pa.us>
|
||||
lpd 1995-06-22 removed #ifndefs whose sole purpose was to define
|
||||
undefined preprocessor symbols as 0; changed all #ifdefs
|
||||
for configuration symbols to #ifs
|
||||
lpd 1995-04-05 changed copyright notice to make it clear that
|
||||
including ansi2knr in a program does not bring the entire
|
||||
program under the GPL
|
||||
lpd 1994-12-18 added conditionals for systems where ctype macros
|
||||
don't handle 8-bit characters properly, suggested by
|
||||
Francois Pinard <pinard@iro.umontreal.ca>;
|
||||
removed --varargs switch (this is now the default)
|
||||
lpd 1994-10-10 removed CONFIG_BROKETS conditional
|
||||
lpd 1994-07-16 added some conditionals to help GNU `configure',
|
||||
suggested by Francois Pinard <pinard@iro.umontreal.ca>;
|
||||
properly erase prototype args in function parameters,
|
||||
contributed by Jim Avera <jima@netcom.com>;
|
||||
correct error in writeblanks (it shouldn't erase EOLs)
|
||||
lpd 1989-xx-xx original version
|
||||
*/
|
||||
|
||||
/* Most of the conditionals here are to make ansi2knr work with */
|
||||
/* or without the GNU configure machinery. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
|
||||
/*
|
||||
For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
|
||||
This will define HAVE_CONFIG_H and so, activate the following lines.
|
||||
*/
|
||||
|
||||
# if STDC_HEADERS || HAVE_STRING_H
|
||||
# include <string.h>
|
||||
# else
|
||||
# include <strings.h>
|
||||
# endif
|
||||
|
||||
#else /* not HAVE_CONFIG_H */
|
||||
|
||||
/* Otherwise do it the hard way */
|
||||
|
||||
# ifdef BSD
|
||||
# include <strings.h>
|
||||
# else
|
||||
# ifdef VMS
|
||||
extern int strlen(), strncmp();
|
||||
# else
|
||||
# include <string.h>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif /* not HAVE_CONFIG_H */
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
/*
|
||||
malloc and free should be declared in stdlib.h,
|
||||
but if you've got a K&R compiler, they probably aren't.
|
||||
*/
|
||||
# ifdef MSDOS
|
||||
# include <malloc.h>
|
||||
# else
|
||||
# ifdef VMS
|
||||
extern char *malloc();
|
||||
extern void free();
|
||||
# else
|
||||
extern char *malloc();
|
||||
extern int free();
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Define NULL (for *very* old compilers). */
|
||||
#ifndef NULL
|
||||
# define NULL (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The ctype macros don't always handle 8-bit characters correctly.
|
||||
* Compensate for this here.
|
||||
*/
|
||||
#ifdef isascii
|
||||
# undef HAVE_ISASCII /* just in case */
|
||||
# define HAVE_ISASCII 1
|
||||
#else
|
||||
#endif
|
||||
#if STDC_HEADERS || !HAVE_ISASCII
|
||||
# define is_ascii(c) 1
|
||||
#else
|
||||
# define is_ascii(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#define is_space(c) (is_ascii(c) && isspace(c))
|
||||
#define is_alpha(c) (is_ascii(c) && isalpha(c))
|
||||
#define is_alnum(c) (is_ascii(c) && isalnum(c))
|
||||
|
||||
/* Scanning macros */
|
||||
#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
|
||||
#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
|
||||
|
||||
/* Forward references */
|
||||
char *skipspace();
|
||||
char *scanstring();
|
||||
int writeblanks();
|
||||
int test1();
|
||||
int convert1();
|
||||
|
||||
/* The main program */
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{ FILE *in = stdin;
|
||||
FILE *out = stdout;
|
||||
char *filename = 0;
|
||||
char *program_name = argv[0];
|
||||
char *output_name = 0;
|
||||
#define bufsize 5000 /* arbitrary size */
|
||||
char *buf;
|
||||
char *line;
|
||||
char *more;
|
||||
char *usage =
|
||||
"Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
|
||||
/*
|
||||
* In previous versions, ansi2knr recognized a --varargs switch.
|
||||
* If this switch was supplied, ansi2knr would attempt to convert
|
||||
* a ... argument to va_alist and va_dcl; if this switch was not
|
||||
* supplied, ansi2knr would simply drop any such arguments.
|
||||
* Now, ansi2knr always does this conversion, and we only
|
||||
* check for this switch for backward compatibility.
|
||||
*/
|
||||
int convert_varargs = 1;
|
||||
int output_error;
|
||||
|
||||
while ( argc > 1 && argv[1][0] == '-' ) {
|
||||
if ( !strcmp(argv[1], "--varargs") ) {
|
||||
convert_varargs = 1;
|
||||
argc--;
|
||||
argv++;
|
||||
continue;
|
||||
}
|
||||
if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
|
||||
filename = argv[2];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name,
|
||||
argv[1]);
|
||||
fprintf(stderr, usage);
|
||||
exit(1);
|
||||
}
|
||||
switch ( argc )
|
||||
{
|
||||
default:
|
||||
fprintf(stderr, usage);
|
||||
exit(0);
|
||||
case 3:
|
||||
output_name = argv[2];
|
||||
out = fopen(output_name, "w");
|
||||
if ( out == NULL ) {
|
||||
fprintf(stderr, "%s: Cannot open output file %s\n",
|
||||
program_name, output_name);
|
||||
exit(1);
|
||||
}
|
||||
/* falls through */
|
||||
case 2:
|
||||
in = fopen(argv[1], "r");
|
||||
if ( in == NULL ) {
|
||||
fprintf(stderr, "%s: Cannot open input file %s\n",
|
||||
program_name, argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
if ( filename == 0 )
|
||||
filename = argv[1];
|
||||
/* falls through */
|
||||
case 1:
|
||||
break;
|
||||
}
|
||||
if ( filename )
|
||||
fprintf(out, "#line 1 \"%s\"\n", filename);
|
||||
buf = malloc(bufsize);
|
||||
if ( buf == NULL )
|
||||
{
|
||||
fprintf(stderr, "Unable to allocate read buffer!\n");
|
||||
exit(1);
|
||||
}
|
||||
line = buf;
|
||||
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
|
||||
{
|
||||
test: line += strlen(line);
|
||||
switch ( test1(buf) )
|
||||
{
|
||||
case 2: /* a function header */
|
||||
convert1(buf, out, 1, convert_varargs);
|
||||
break;
|
||||
case 1: /* a function */
|
||||
/* Check for a { at the start of the next line. */
|
||||
more = ++line;
|
||||
f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
|
||||
goto wl;
|
||||
if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
|
||||
goto wl;
|
||||
switch ( *skipspace(more, 1) )
|
||||
{
|
||||
case '{':
|
||||
/* Definitely a function header. */
|
||||
convert1(buf, out, 0, convert_varargs);
|
||||
fputs(more, out);
|
||||
break;
|
||||
case 0:
|
||||
/* The next line was blank or a comment: */
|
||||
/* keep scanning for a non-comment. */
|
||||
line += strlen(line);
|
||||
goto f;
|
||||
default:
|
||||
/* buf isn't a function header, but */
|
||||
/* more might be. */
|
||||
fputs(buf, out);
|
||||
strcpy(buf, more);
|
||||
line = buf;
|
||||
goto test;
|
||||
}
|
||||
break;
|
||||
case -1: /* maybe the start of a function */
|
||||
if ( line != buf + (bufsize - 1) ) /* overflow check */
|
||||
continue;
|
||||
/* falls through */
|
||||
default: /* not a function */
|
||||
wl: fputs(buf, out);
|
||||
break;
|
||||
}
|
||||
line = buf;
|
||||
}
|
||||
if ( line != buf )
|
||||
fputs(buf, out);
|
||||
free(buf);
|
||||
if ( output_name ) {
|
||||
output_error = ferror(out);
|
||||
output_error |= fclose(out);
|
||||
} else { /* out == stdout */
|
||||
fflush(out);
|
||||
output_error = ferror(out);
|
||||
}
|
||||
if ( output_error ) {
|
||||
fprintf(stderr, "%s: error writing to %s\n", program_name,
|
||||
(output_name ? output_name : "stdout"));
|
||||
exit(1);
|
||||
}
|
||||
if ( in != stdin )
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip over whitespace and comments, in either direction. */
|
||||
char *
|
||||
skipspace(p, dir)
|
||||
register char *p;
|
||||
register int dir; /* 1 for forward, -1 for backward */
|
||||
{ for ( ; ; )
|
||||
{ while ( is_space(*p) )
|
||||
p += dir;
|
||||
if ( !(*p == '/' && p[dir] == '*') )
|
||||
break;
|
||||
p += dir; p += dir;
|
||||
while ( !(*p == '*' && p[dir] == '/') )
|
||||
{ if ( *p == 0 )
|
||||
return p; /* multi-line comment?? */
|
||||
p += dir;
|
||||
}
|
||||
p += dir; p += dir;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Scan over a quoted string, in either direction. */
|
||||
char *
|
||||
scanstring(p, dir)
|
||||
register char *p;
|
||||
register int dir;
|
||||
{
|
||||
for (p += dir; ; p += dir)
|
||||
if (*p == '"' && p[-dir] != '\\')
|
||||
return p + dir;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write blanks over part of a string.
|
||||
* Don't overwrite end-of-line characters.
|
||||
*/
|
||||
int
|
||||
writeblanks(start, end)
|
||||
char *start;
|
||||
char *end;
|
||||
{ char *p;
|
||||
for ( p = start; p < end; p++ )
|
||||
if ( *p != '\r' && *p != '\n' )
|
||||
*p = ' ';
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test whether the string in buf is a function definition.
|
||||
* The string may contain and/or end with a newline.
|
||||
* Return as follows:
|
||||
* 0 - definitely not a function definition;
|
||||
* 1 - definitely a function definition;
|
||||
* 2 - definitely a function prototype (NOT USED);
|
||||
* -1 - may be the beginning of a function definition,
|
||||
* append another line and look again.
|
||||
* The reason we don't attempt to convert function prototypes is that
|
||||
* Ghostscript's declaration-generating macros look too much like
|
||||
* prototypes, and confuse the algorithms.
|
||||
*/
|
||||
int
|
||||
test1(buf)
|
||||
char *buf;
|
||||
{ register char *p = buf;
|
||||
char *bend;
|
||||
char *endfn;
|
||||
int contin;
|
||||
|
||||
if ( !isidfirstchar(*p) )
|
||||
return 0; /* no name at left margin */
|
||||
bend = skipspace(buf + strlen(buf) - 1, -1);
|
||||
switch ( *bend )
|
||||
{
|
||||
case ';': contin = 0 /*2*/; break;
|
||||
case ')': contin = 1; break;
|
||||
case '{': return 0; /* not a function */
|
||||
case '}': return 0; /* not a function */
|
||||
default: contin = -1;
|
||||
}
|
||||
while ( isidchar(*p) )
|
||||
p++;
|
||||
endfn = p;
|
||||
p = skipspace(p, 1);
|
||||
if ( *p++ != '(' )
|
||||
return 0; /* not a function */
|
||||
p = skipspace(p, 1);
|
||||
if ( *p == ')' )
|
||||
return 0; /* no parameters */
|
||||
/* Check that the apparent function name isn't a keyword. */
|
||||
/* We only need to check for keywords that could be followed */
|
||||
/* by a left parenthesis (which, unfortunately, is most of them). */
|
||||
{ static char *words[] =
|
||||
{ "asm", "auto", "case", "char", "const", "double",
|
||||
"extern", "float", "for", "if", "int", "long",
|
||||
"register", "return", "short", "signed", "sizeof",
|
||||
"static", "switch", "typedef", "unsigned",
|
||||
"void", "volatile", "while", 0
|
||||
};
|
||||
char **key = words;
|
||||
char *kp;
|
||||
unsigned len = endfn - buf;
|
||||
|
||||
while ( (kp = *key) != 0 )
|
||||
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
|
||||
return 0; /* name is a keyword */
|
||||
key++;
|
||||
}
|
||||
}
|
||||
{
|
||||
char *id = p;
|
||||
int len;
|
||||
/*
|
||||
* Check for identifier1(identifier2) and not
|
||||
* identifier1(void), or identifier1(identifier2, xxxx).
|
||||
*/
|
||||
|
||||
while ( isidchar(*p) )
|
||||
p++;
|
||||
len = p - id;
|
||||
p = skipspace(p, 1);
|
||||
if (*p == ',' ||
|
||||
(*p == ')' && (len != 4 || strncmp(id, "void", 4)))
|
||||
)
|
||||
return 0; /* not a function */
|
||||
}
|
||||
/*
|
||||
* If the last significant character was a ), we need to count
|
||||
* parentheses, because it might be part of a formal parameter
|
||||
* that is a procedure.
|
||||
*/
|
||||
if (contin > 0) {
|
||||
int level = 0;
|
||||
|
||||
for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1))
|
||||
level += (*p == '(' ? 1 : *p == ')' ? -1 : 0);
|
||||
if (level > 0)
|
||||
contin = -1;
|
||||
}
|
||||
return contin;
|
||||
}
|
||||
|
||||
/* Convert a recognized function definition or header to K&R syntax. */
|
||||
int
|
||||
convert1(buf, out, header, convert_varargs)
|
||||
char *buf;
|
||||
FILE *out;
|
||||
int header; /* Boolean */
|
||||
int convert_varargs; /* Boolean */
|
||||
{ char *endfn;
|
||||
register char *p;
|
||||
/*
|
||||
* The breaks table contains pointers to the beginning and end
|
||||
* of each argument.
|
||||
*/
|
||||
char **breaks;
|
||||
unsigned num_breaks = 2; /* for testing */
|
||||
char **btop;
|
||||
char **bp;
|
||||
char **ap;
|
||||
char *vararg = 0;
|
||||
|
||||
/* Pre-ANSI implementations don't agree on whether strchr */
|
||||
/* is called strchr or index, so we open-code it here. */
|
||||
for ( endfn = buf; *(endfn++) != '('; )
|
||||
;
|
||||
top: p = endfn;
|
||||
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
|
||||
if ( breaks == NULL )
|
||||
{ /* Couldn't allocate break table, give up */
|
||||
fprintf(stderr, "Unable to allocate break table!\n");
|
||||
fputs(buf, out);
|
||||
return -1;
|
||||
}
|
||||
btop = breaks + num_breaks * 2 - 2;
|
||||
bp = breaks;
|
||||
/* Parse the argument list */
|
||||
do
|
||||
{ int level = 0;
|
||||
char *lp = NULL;
|
||||
char *rp = NULL;
|
||||
char *end = NULL;
|
||||
|
||||
if ( bp >= btop )
|
||||
{ /* Filled up break table. */
|
||||
/* Allocate a bigger one and start over. */
|
||||
free((char *)breaks);
|
||||
num_breaks <<= 1;
|
||||
goto top;
|
||||
}
|
||||
*bp++ = p;
|
||||
/* Find the end of the argument */
|
||||
for ( ; end == NULL; p++ )
|
||||
{ switch(*p)
|
||||
{
|
||||
case ',':
|
||||
if ( !level ) end = p;
|
||||
break;
|
||||
case '(':
|
||||
if ( !level ) lp = p;
|
||||
level++;
|
||||
break;
|
||||
case ')':
|
||||
if ( --level < 0 ) end = p;
|
||||
else rp = p;
|
||||
break;
|
||||
case '/':
|
||||
if (p[1] == '*')
|
||||
p = skipspace(p, 1) - 1;
|
||||
break;
|
||||
case '"':
|
||||
p = scanstring(p, 1) - 1;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
/* Erase any embedded prototype parameters. */
|
||||
if ( lp && rp )
|
||||
writeblanks(lp + 1, rp);
|
||||
p--; /* back up over terminator */
|
||||
/* Find the name being declared. */
|
||||
/* This is complicated because of procedure and */
|
||||
/* array modifiers. */
|
||||
for ( ; ; )
|
||||
{ p = skipspace(p - 1, -1);
|
||||
switch ( *p )
|
||||
{
|
||||
case ']': /* skip array dimension(s) */
|
||||
case ')': /* skip procedure args OR name */
|
||||
{ int level = 1;
|
||||
while ( level )
|
||||
switch ( *--p )
|
||||
{
|
||||
case ']': case ')':
|
||||
level++;
|
||||
break;
|
||||
case '[': case '(':
|
||||
level--;
|
||||
break;
|
||||
case '/':
|
||||
if (p > buf && p[-1] == '*')
|
||||
p = skipspace(p, -1) + 1;
|
||||
break;
|
||||
case '"':
|
||||
p = scanstring(p, -1) + 1;
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
|
||||
{ /* We found the name being declared */
|
||||
while ( !isidfirstchar(*p) )
|
||||
p = skipspace(p, 1) + 1;
|
||||
goto found;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
||||
{ if ( convert_varargs )
|
||||
{ *bp++ = "va_alist";
|
||||
vararg = p-2;
|
||||
}
|
||||
else
|
||||
{ p++;
|
||||
if ( bp == breaks + 1 ) /* sole argument */
|
||||
writeblanks(breaks[0], p);
|
||||
else
|
||||
writeblanks(bp[-1] - 1, p);
|
||||
bp--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ while ( isidchar(*p) ) p--;
|
||||
*bp++ = p+1;
|
||||
}
|
||||
p = end;
|
||||
}
|
||||
while ( *p++ == ',' );
|
||||
*bp = p;
|
||||
/* Make a special check for 'void' arglist */
|
||||
if ( bp == breaks+2 )
|
||||
{ p = skipspace(breaks[0], 1);
|
||||
if ( !strncmp(p, "void", 4) )
|
||||
{ p = skipspace(p+4, 1);
|
||||
if ( p == breaks[2] - 1 )
|
||||
{ bp = breaks; /* yup, pretend arglist is empty */
|
||||
writeblanks(breaks[0], p + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Put out the function name and left parenthesis. */
|
||||
p = buf;
|
||||
while ( p != endfn ) putc(*p, out), p++;
|
||||
/* Put out the declaration. */
|
||||
if ( header )
|
||||
{ fputs(");", out);
|
||||
for ( p = breaks[0]; *p; p++ )
|
||||
if ( *p == '\r' || *p == '\n' )
|
||||
putc(*p, out);
|
||||
}
|
||||
else
|
||||
{ for ( ap = breaks+1; ap < bp; ap += 2 )
|
||||
{ p = *ap;
|
||||
while ( isidchar(*p) )
|
||||
putc(*p, out), p++;
|
||||
if ( ap < bp - 1 )
|
||||
fputs(", ", out);
|
||||
}
|
||||
fputs(") ", out);
|
||||
/* Put out the argument declarations */
|
||||
for ( ap = breaks+2; ap <= bp; ap += 2 )
|
||||
(*ap)[-1] = ';';
|
||||
if ( vararg != 0 )
|
||||
{ *vararg = 0;
|
||||
fputs(breaks[0], out); /* any prior args */
|
||||
fputs("va_dcl", out); /* the final arg */
|
||||
fputs(bp[0], out);
|
||||
}
|
||||
else
|
||||
fputs(breaks[0], out);
|
||||
}
|
||||
free((char *)breaks);
|
||||
return 0;
|
||||
}
|
310
patch/argmatch.c
Normal file
310
patch/argmatch.c
Normal file
@ -0,0 +1,310 @@
|
||||
/* argmatch.c -- find a match for a string in an array
|
||||
Copyright (C) 1990, 1998, 1999, 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 David MacKenzie <djm@ai.mit.edu>
|
||||
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
||||
|
||||
#include "argmatch.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(Text) gettext (Text)
|
||||
#else
|
||||
# define _(Text) Text
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
/* The following test is to work around the gross typo in
|
||||
systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
|
||||
is defined to 0, not 1. */
|
||||
#if !EXIT_FAILURE
|
||||
# undef 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 SENSITIVE, comparison is case sensitive.
|
||||
|
||||
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'. */
|
||||
|
||||
static int
|
||||
__argmatch_internal (const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize,
|
||||
int case_sensitive)
|
||||
{
|
||||
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 (case_sensitive
|
||||
? !strncmp (arglist[i], arg, arglen)
|
||||
: !strncasecmp (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;
|
||||
}
|
||||
|
||||
/* argmatch - case sensitive version */
|
||||
int
|
||||
argmatch (const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize)
|
||||
{
|
||||
return __argmatch_internal (arg, arglist, vallist, valsize, 1);
|
||||
}
|
||||
|
||||
/* argcasematch - case insensitive version */
|
||||
int
|
||||
argcasematch (const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize)
|
||||
{
|
||||
return __argmatch_internal (arg, arglist, vallist, valsize, 0);
|
||||
}
|
||||
|
||||
/* 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,
|
||||
int case_sensitive,
|
||||
argmatch_exit_fn exit_fn)
|
||||
{
|
||||
int res = __argmatch_internal (arg, arglist,
|
||||
vallist, valsize,
|
||||
case_sensitive);
|
||||
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 = XARGCASEMATCH ("$VERSION_CONTROL", cp,
|
||||
backup_args, backup_vals);
|
||||
|
||||
if (argc == 2)
|
||||
backup_type = XARGCASEMATCH (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
|
129
patch/argmatch.h
Normal file
129
patch/argmatch.h
Normal file
@ -0,0 +1,129 @@
|
||||
/* argmatch.h -- definitions and prototypes for argmatch.c
|
||||
Copyright (C) 1990, 1998, 1999, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@ai.mit.edu>
|
||||
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
||||
|
||||
#ifndef ARGMATCH_H_
|
||||
# define ARGMATCH_H_ 1
|
||||
|
||||
# if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
# endif
|
||||
|
||||
# include <sys/types.h>
|
||||
|
||||
# ifndef PARAMS
|
||||
# if PROTOTYPES || (defined (__STDC__) && __STDC__)
|
||||
# define PARAMS(args) args
|
||||
# else
|
||||
# define PARAMS(args) ()
|
||||
# endif /* GCC. */
|
||||
# endif /* Not PARAMS. */
|
||||
|
||||
/* Assert there are as many real arguments as there are values
|
||||
(argument list ends with a NULL guard). There is no execution
|
||||
cost, since it will be statically evalauted to `assert (0)' or
|
||||
`assert (1)'. Unfortunately there is no -Wassert-0. */
|
||||
|
||||
# undef ARRAY_CARDINALITY
|
||||
# define ARRAY_CARDINALITY(Array) (sizeof ((Array)) / sizeof (*(Array)))
|
||||
|
||||
# define ARGMATCH_ASSERT(Arglist, Vallist) \
|
||||
assert (ARRAY_CARDINALITY ((Arglist)) == ARRAY_CARDINALITY ((Vallist)) + 1)
|
||||
|
||||
/* 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
|
||||
PARAMS ((const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize));
|
||||
int argcasematch
|
||||
PARAMS ((const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize));
|
||||
|
||||
# define ARGMATCH(Arg, Arglist, Vallist) \
|
||||
argmatch ((Arg), (Arglist), (const char *) (Vallist), sizeof (*(Vallist)))
|
||||
|
||||
# define ARGCASEMATCH(Arg, Arglist, Vallist) \
|
||||
argcasematch ((Arg), (Arglist), (const char *) (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) PARAMS ((void));
|
||||
extern argmatch_exit_fn argmatch_die;
|
||||
|
||||
/* Report on stderr why argmatch failed. Report correct values. */
|
||||
|
||||
void argmatch_invalid
|
||||
PARAMS ((const char *context, const char *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
|
||||
PARAMS ((const char *const *arglist,
|
||||
const char *vallist, size_t valsize));
|
||||
|
||||
# define ARGMATCH_VALID(Arglist, Vallist) \
|
||||
argmatch_valid (Arglist, (const char *) 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
|
||||
PARAMS ((const char *context,
|
||||
const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize,
|
||||
int case_sensitive, argmatch_exit_fn exit_fn));
|
||||
|
||||
/* Programmer friendly interface to __xargmatch_internal. */
|
||||
|
||||
# define XARGMATCH(Context, Arg, Arglist, Vallist) \
|
||||
(Vallist [__xargmatch_internal ((Context), (Arg), (Arglist), \
|
||||
(const char *) (Vallist), \
|
||||
sizeof (*(Vallist)), \
|
||||
1, argmatch_die)])
|
||||
|
||||
# define XARGCASEMATCH(Context, Arg, Arglist, Vallist) \
|
||||
(Vallist [__xargmatch_internal ((Context), (Arg), (Arglist), \
|
||||
(const char *) (Vallist), \
|
||||
sizeof (*(Vallist)), \
|
||||
0, argmatch_die)])
|
||||
|
||||
/* Convert a value into a corresponding argument. */
|
||||
|
||||
const char *argmatch_to_argument
|
||||
PARAMS ((char const *value, const char *const *arglist,
|
||||
const char *vallist, size_t valsize));
|
||||
|
||||
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
|
||||
argmatch_to_argument ((Value), (Arglist), \
|
||||
(const char *) (Vallist), sizeof (*(Vallist)))
|
||||
|
||||
#endif /* ARGMATCH_H_ */
|
277
patch/backupfile.c
Normal file
277
patch/backupfile.c
Normal file
@ -0,0 +1,277 @@
|
||||
/* backupfile.c -- make Emacs style backup file names
|
||||
Copyright (C) 1990,91,92,93,94,95,96,97,98,99,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
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>.
|
||||
Some algorithms adapted from GNU Emacs. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NLENGTH(direct) strlen ((direct)->d_name)
|
||||
#else
|
||||
# define dirent direct
|
||||
# define NLENGTH(direct) ((size_t) (direct)->d_namlen)
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if CLOSEDIR_VOID
|
||||
/* Fake a return value. */
|
||||
# define CLOSEDIR(d) (closedir (d), 0)
|
||||
#else
|
||||
# define CLOSEDIR(d) closedir (d)
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DECL_GETENV
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
#if !HAVE_DECL_GETENV
|
||||
char *getenv ();
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DECL_MALLOC
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
#if !HAVE_DECL_MALLOC
|
||||
char *malloc ();
|
||||
#endif
|
||||
|
||||
#if HAVE_DIRENT_H || HAVE_NDIR_H || HAVE_SYS_DIR_H || HAVE_SYS_NDIR_H
|
||||
# define HAVE_DIR 1
|
||||
#else
|
||||
# define HAVE_DIR 0
|
||||
#endif
|
||||
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
/* Upper bound on the string length of an integer converted to string.
|
||||
302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
|
||||
add 1 for integer division truncation; add 1 more for a minus sign. */
|
||||
#define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
|
||||
|
||||
/* ISDIGIT differs from isdigit, as follows:
|
||||
- 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 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
|
||||
# define REAL_DIR_ENTRY(dp) ((dp)->d_ino != 0)
|
||||
#else
|
||||
# define REAL_DIR_ENTRY(dp) 1
|
||||
#endif
|
||||
|
||||
#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 = "~";
|
||||
|
||||
static int max_backup_version PARAMS ((const char *, const char *));
|
||||
static int version_number PARAMS ((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.
|
||||
FILE must not end with a '/' unless it is the root directory.
|
||||
Do not call this function if backup_type == none. */
|
||||
|
||||
char *
|
||||
find_backup_file_name (const char *file, enum backup_type backup_type)
|
||||
{
|
||||
size_t backup_suffix_size_max;
|
||||
size_t file_len = strlen (file);
|
||||
size_t numbered_suffix_size_max = INT_STRLEN_BOUND (int) + 4;
|
||||
char *s;
|
||||
const char *suffix = simple_backup_suffix;
|
||||
|
||||
/* Allow room for simple or `.~N~' backups. */
|
||||
backup_suffix_size_max = strlen (simple_backup_suffix) + 1;
|
||||
if (HAVE_DIR && backup_suffix_size_max < numbered_suffix_size_max)
|
||||
backup_suffix_size_max = numbered_suffix_size_max;
|
||||
|
||||
s = malloc (file_len + 1
|
||||
+ backup_suffix_size_max + numbered_suffix_size_max);
|
||||
if (s)
|
||||
{
|
||||
#if HAVE_DIR
|
||||
if (backup_type != simple)
|
||||
{
|
||||
int highest_backup;
|
||||
size_t dirlen = dir_len (file);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_DIR */
|
||||
|
||||
strcpy (s, file);
|
||||
addext (s, suffix, '~');
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#if HAVE_DIR
|
||||
|
||||
/* Return the number of the highest-numbered backup file for file
|
||||
FILE in directory DIR. If there are no numbered backups
|
||||
of FILE in DIR, or an error occurs reading DIR, return 0.
|
||||
*/
|
||||
|
||||
static int
|
||||
max_backup_version (const char *file, const char *dir)
|
||||
{
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
int highest_version;
|
||||
int this_version;
|
||||
size_t file_name_length;
|
||||
|
||||
dirp = opendir (dir);
|
||||
if (!dirp)
|
||||
return 0;
|
||||
|
||||
highest_version = 0;
|
||||
file_name_length = base_len (file);
|
||||
|
||||
while ((dp = readdir (dirp)) != 0)
|
||||
{
|
||||
if (!REAL_DIR_ENTRY (dp) || NLENGTH (dp) < file_name_length + 4)
|
||||
continue;
|
||||
|
||||
this_version = version_number (file, dp->d_name, file_name_length);
|
||||
if (this_version > highest_version)
|
||||
highest_version = this_version;
|
||||
}
|
||||
if (CLOSEDIR (dirp))
|
||||
return 0;
|
||||
return highest_version;
|
||||
}
|
||||
|
||||
/* If BACKUP is a numbered backup of BASE, return its version number;
|
||||
otherwise return 0. BASE_LENGTH is the length of BASE.
|
||||
*/
|
||||
|
||||
static int
|
||||
version_number (const char *base, const char *backup, size_t base_length)
|
||||
{
|
||||
int version;
|
||||
const char *p;
|
||||
|
||||
version = 0;
|
||||
if (strncmp (base, backup, base_length) == 0
|
||||
&& backup[base_length] == '.'
|
||||
&& backup[base_length + 1] == '~')
|
||||
{
|
||||
for (p = &backup[base_length + 2]; ISDIGIT (*p); ++p)
|
||||
version = version * 10 + *p - '0';
|
||||
if (p[0] != '~' || p[1])
|
||||
version = 0;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
#endif /* HAVE_DIR */
|
||||
|
||||
static const char * const backup_args[] =
|
||||
{
|
||||
/* 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[] =
|
||||
{
|
||||
none, none,
|
||||
simple, simple,
|
||||
numbered_existing, numbered_existing,
|
||||
numbered, numbered
|
||||
};
|
||||
|
||||
/* 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 (const char *context, const char *version)
|
||||
{
|
||||
if (version == 0 || *version == 0)
|
||||
return numbered_existing;
|
||||
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"));
|
||||
}
|
60
patch/backupfile.h
Normal file
60
patch/backupfile.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* backupfile.h -- declarations for making Emacs style backup file names
|
||||
Copyright (C) 1990-1992, 1997-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; see the file COPYING.
|
||||
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
|
||||
{
|
||||
/* 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
|
||||
};
|
||||
|
||||
# define VALID_BACKUP_TYPE(Type) \
|
||||
((Type) == none \
|
||||
|| (Type) == simple \
|
||||
|| (Type) == numbered_existing \
|
||||
|| (Type) == numbered)
|
||||
|
||||
extern char const *simple_backup_suffix;
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
char *find_backup_file_name PARAMS ((char const *, enum backup_type));
|
||||
enum backup_type get_version PARAMS ((char const *context, char const *arg));
|
||||
enum backup_type xget_version PARAMS ((char const *context, char const *arg));
|
||||
void addext PARAMS ((char *, char const *, int));
|
||||
|
||||
#endif /* ! BACKUPFILE_H_ */
|
79
patch/basename.c
Normal file
79
patch/basename.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* basename.c -- return the last element in a path
|
||||
Copyright (C) 1990, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS || HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#include "dirname.h"
|
||||
|
||||
/* In general, we can't use the builtin `basename' function if available,
|
||||
since it has different meanings in different environments.
|
||||
In some environments the builtin `basename' modifies its argument.
|
||||
|
||||
Return the address of the last file name component of NAME. If
|
||||
NAME has no file name components because it is all slashes, return
|
||||
NAME if it is empty, the address of its last slash otherwise. */
|
||||
|
||||
char *
|
||||
base_name (char const *name)
|
||||
{
|
||||
char const *base = name + FILESYSTEM_PREFIX_LEN (name);
|
||||
char const *p;
|
||||
|
||||
for (p = base; *p; p++)
|
||||
{
|
||||
if (ISSLASH (*p))
|
||||
{
|
||||
/* Treat multiple adjacent slashes like a single slash. */
|
||||
do p++;
|
||||
while (ISSLASH (*p));
|
||||
|
||||
/* If the file name ends in slash, use the trailing slash as
|
||||
the basename if no non-slashes have been found. */
|
||||
if (! *p)
|
||||
{
|
||||
if (ISSLASH (*base))
|
||||
base = p - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* *P is a non-slash preceded by a slash. */
|
||||
base = p;
|
||||
}
|
||||
}
|
||||
|
||||
return (char *) base;
|
||||
}
|
||||
|
||||
/* Return the length of of the basename NAME. Typically NAME is the
|
||||
value returned by base_name. Act like strlen (NAME), except omit
|
||||
redundant trailing slashes. */
|
||||
|
||||
size_t
|
||||
base_len (char const *name)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
|
||||
continue;
|
||||
|
||||
return len;
|
||||
}
|
9
patch/basename.h
Normal file
9
patch/basename.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
char *base_name PARAMS ((char const *name));
|
321
patch/common.h
Normal file
321
patch/common.h
Normal file
@ -0,0 +1,321 @@
|
||||
/* common definitions for `patch' */
|
||||
|
||||
/* $Id: common.h,v 1.1.1.3 2003/05/08 18:38:01 rbraun Exp $ */
|
||||
|
||||
/* Copyright (C) 1986, 1988 Larry Wall
|
||||
|
||||
Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 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. */
|
||||
|
||||
#ifndef DEBUGGING
|
||||
#define DEBUGGING 1
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#if ! defined S_ISDIR && defined S_IFDIR
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#if ! defined S_ISREG && defined S_IFREG
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
#ifndef S_IXOTH
|
||||
#define S_IXOTH 1
|
||||
#endif
|
||||
#ifndef S_IWOTH
|
||||
#define S_IWOTH 2
|
||||
#endif
|
||||
#ifndef S_IROTH
|
||||
#define S_IROTH 4
|
||||
#endif
|
||||
#ifndef S_IXGRP
|
||||
#define S_IXGRP (S_IXOTH << 3)
|
||||
#endif
|
||||
#ifndef S_IWGRP
|
||||
#define S_IWGRP (S_IWOTH << 3)
|
||||
#endif
|
||||
#ifndef S_IRGRP
|
||||
#define S_IRGRP (S_IROTH << 3)
|
||||
#endif
|
||||
#ifndef S_IXUSR
|
||||
#define S_IXUSR (S_IXOTH << 6)
|
||||
#endif
|
||||
#ifndef S_IWUSR
|
||||
#define S_IWUSR (S_IWOTH << 6)
|
||||
#endif
|
||||
#ifndef S_IRUSR
|
||||
#define S_IRUSR (S_IROTH << 6)
|
||||
#endif
|
||||
#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
|
||||
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.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)
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
/* CTYPE_DOMAIN (C) is nonzero if the unsigned char C can safely be given
|
||||
as an argument to <ctype.h> macros like `isspace'. */
|
||||
#if STDC_HEADERS
|
||||
#define CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
#define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
|
||||
#endif
|
||||
#ifndef ISSPACE
|
||||
#define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
|
||||
#endif
|
||||
|
||||
#ifndef ISDIGIT
|
||||
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FILESYSTEM_PREFIX_LEN
|
||||
#define FILESYSTEM_PREFIX_LEN(f) 0
|
||||
#endif
|
||||
|
||||
#ifndef ISSLASH
|
||||
#define ISSLASH(c) ((c) == '/')
|
||||
#endif
|
||||
|
||||
|
||||
/* constants */
|
||||
|
||||
/* AIX predefines these. */
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#endif
|
||||
#ifdef FALSE
|
||||
#undef FALSE
|
||||
#endif
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* handy definitions */
|
||||
|
||||
#define strEQ(s1,s2) (!strcmp(s1, s2))
|
||||
#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l))
|
||||
|
||||
/* typedefs */
|
||||
|
||||
typedef int bool; /* must promote to itself */
|
||||
typedef off_t LINENUM; /* must be signed */
|
||||
|
||||
/* globals */
|
||||
|
||||
XTERN char *program_name; /* The name this program was run with. */
|
||||
|
||||
XTERN char *buf; /* general purpose buffer */
|
||||
XTERN size_t bufsize; /* allocated size of buf */
|
||||
|
||||
XTERN bool using_plan_a; /* try to keep everything in memory */
|
||||
|
||||
XTERN char *inname;
|
||||
XTERN char *outfile;
|
||||
XTERN int inerrno;
|
||||
XTERN int invc;
|
||||
XTERN struct stat instat;
|
||||
XTERN bool dry_run;
|
||||
XTERN bool posixly_correct;
|
||||
|
||||
XTERN char const *origprae;
|
||||
XTERN char const *origbase;
|
||||
|
||||
XTERN char const * volatile TMPINNAME;
|
||||
XTERN char const * volatile TMPOUTNAME;
|
||||
XTERN char const * volatile TMPPATNAME;
|
||||
|
||||
XTERN int volatile TMPINNAME_needs_removal;
|
||||
XTERN int volatile TMPOUTNAME_needs_removal;
|
||||
XTERN int volatile TMPPATNAME_needs_removal;
|
||||
|
||||
#ifdef DEBUGGING
|
||||
XTERN int debug;
|
||||
#else
|
||||
# define debug 0
|
||||
#endif
|
||||
XTERN bool force;
|
||||
XTERN bool batch;
|
||||
XTERN bool noreverse;
|
||||
XTERN int reverse;
|
||||
XTERN enum { DEFAULT_VERBOSITY, SILENT, VERBOSE } verbosity;
|
||||
XTERN bool skip_rest_of_patch;
|
||||
XTERN int strippath;
|
||||
XTERN bool canonicalize;
|
||||
XTERN int patch_get;
|
||||
XTERN int set_time;
|
||||
XTERN int set_utc;
|
||||
|
||||
enum diff
|
||||
{
|
||||
NO_DIFF,
|
||||
CONTEXT_DIFF,
|
||||
NORMAL_DIFF,
|
||||
ED_DIFF,
|
||||
NEW_CONTEXT_DIFF,
|
||||
UNI_DIFF
|
||||
};
|
||||
|
||||
XTERN enum diff diff_type;
|
||||
|
||||
XTERN char *revision; /* prerequisite revision, if any */
|
||||
|
||||
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
#endif
|
||||
|
||||
void fatal_exit (int) __attribute__ ((noreturn));
|
||||
|
||||
#include <errno.h>
|
||||
#if !STDC_HEADERS && !defined errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS || HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# if !HAVE_MEMCHR
|
||||
# define memcmp(s1, s2, n) bcmp (s1, s2, n)
|
||||
# define memcpy(d, s, n) bcopy (s, d, n)
|
||||
void *memchr ();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
char *getenv ();
|
||||
void *malloc ();
|
||||
void *realloc ();
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# ifndef lseek
|
||||
off_t lseek ();
|
||||
# endif
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
#if HAVE_FSEEKO
|
||||
typedef off_t file_offset;
|
||||
# define file_seek fseeko
|
||||
# define file_tell ftello
|
||||
#else
|
||||
typedef long file_offset;
|
||||
# define file_seek fseek
|
||||
# define file_tell ftell
|
||||
#endif
|
||||
#if ! (HAVE_GETEUID || defined geteuid)
|
||||
# if ! (HAVE_GETUID || defined getuid)
|
||||
# define geteuid() (-1)
|
||||
# else
|
||||
# define geteuid() getuid ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
#ifndef O_RDONLY
|
||||
#define O_RDONLY 0
|
||||
#endif
|
||||
#ifndef O_WRONLY
|
||||
#define O_WRONLY 1
|
||||
#endif
|
||||
#ifndef O_RDWR
|
||||
#define O_RDWR 2
|
||||
#endif
|
||||
#ifndef _O_BINARY
|
||||
#define _O_BINARY 0
|
||||
#endif
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY _O_BINARY
|
||||
#endif
|
||||
#ifndef O_CREAT
|
||||
#define O_CREAT 0
|
||||
#endif
|
||||
#ifndef O_EXCL
|
||||
#define O_EXCL 0
|
||||
#endif
|
||||
#ifndef O_TRUNC
|
||||
#define O_TRUNC 0
|
||||
#endif
|
||||
|
||||
#if HAVE_SETMODE_DOS
|
||||
XTERN int binary_transput; /* O_BINARY if binary i/o is desired */
|
||||
#else
|
||||
# define binary_transput 0
|
||||
#endif
|
||||
|
||||
#ifndef NULL_DEVICE
|
||||
#define NULL_DEVICE "/dev/null"
|
||||
#endif
|
||||
|
||||
#ifndef TTY_DEVICE
|
||||
#define TTY_DEVICE "/dev/tty"
|
||||
#endif
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#define PROGRAM_NAME "patch"
|
1091
patch/config.guess
vendored
Normal file
1091
patch/config.guess
vendored
Normal file
File diff suppressed because it is too large
Load Diff
275
patch/config.hin
Normal file
275
patch/config.hin
Normal file
@ -0,0 +1,275 @@
|
||||
/* config.hin. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if the `closedir' function returns void instead of `int'. */
|
||||
#undef CLOSEDIR_VOID
|
||||
|
||||
/* Define if there is a member named d_ino in the struct describing directory
|
||||
headers. */
|
||||
#undef D_INO_IN_DIRENT
|
||||
|
||||
/* Define to 1 if you have the <bp-sym.h> header file. */
|
||||
#undef HAVE_BP_SYM_H
|
||||
|
||||
/* Define if backslash-a works in C strings. */
|
||||
#undef HAVE_C_BACKSLASH_A
|
||||
|
||||
/* Define to 1 if you have the declaration of `free', and to 0 if you don't.
|
||||
*/
|
||||
#undef HAVE_DECL_FREE
|
||||
|
||||
/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
|
||||
*/
|
||||
#undef HAVE_DECL_GETENV
|
||||
|
||||
/* Define to 1 if you have the declaration of `malloc', and to 0 if you don't.
|
||||
*/
|
||||
#undef HAVE_DECL_MALLOC
|
||||
|
||||
/* Define to 1 if you have the declaration of `mktemp', and to 0 if you don't.
|
||||
*/
|
||||
#undef HAVE_DECL_MKTEMP
|
||||
|
||||
/* Define to 1 if you have the declaration of `strerror', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_STRERROR
|
||||
|
||||
/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_STRERROR_R
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_DIRENT_H
|
||||
|
||||
/* Define if the malloc check has been performed. */
|
||||
#undef HAVE_DONE_WORKING_MALLOC_CHECK
|
||||
|
||||
/* Define if the realloc check has been performed. */
|
||||
#undef HAVE_DONE_WORKING_REALLOC_CHECK
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
|
||||
#undef HAVE_FSEEKO
|
||||
|
||||
/* Define to 1 if you have the `geteuid' function. */
|
||||
#undef HAVE_GETEUID
|
||||
|
||||
/* Define to 1 if you have the `getuid' function. */
|
||||
#undef HAVE_GETUID
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `isascii' function. */
|
||||
#undef HAVE_ISASCII
|
||||
|
||||
/* Define to 1 if you have the `iswprint' function. */
|
||||
#undef HAVE_ISWPRINT
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you support file names longer than 14 characters. */
|
||||
#undef HAVE_LONG_FILE_NAMES
|
||||
|
||||
/* Define to 1 if mbrtowc and mbstate_t are properly declared. */
|
||||
#undef HAVE_MBRTOWC
|
||||
|
||||
/* ma Define to 1 if <wchar.h> declares mbstate_t. */
|
||||
#undef HAVE_MBSTATE_T
|
||||
|
||||
/* Define to 1 if you have the `memchr' function. */
|
||||
#undef HAVE_MEMCHR
|
||||
|
||||
/* Define to 1 if you have the `memcmp' function. */
|
||||
#undef HAVE_MEMCMP
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `mkdir' function. */
|
||||
#undef HAVE_MKDIR
|
||||
|
||||
/* Define to 1 if you have the `mktemp' function. */
|
||||
#undef HAVE_MKTEMP
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the `pathconf' function. */
|
||||
#undef HAVE_PATHCONF
|
||||
|
||||
/* Define to 1 if you have the `raise' function. */
|
||||
#undef HAVE_RAISE
|
||||
|
||||
/* Define to 1 if you have the `rename' function. */
|
||||
#undef HAVE_RENAME
|
||||
|
||||
/* Define to 1 if you have the `rmdir' function. */
|
||||
#undef HAVE_RMDIR
|
||||
|
||||
/* Define to 1 if you have the DOS-style `setmode' function. */
|
||||
#undef HAVE_SETMODE_DOS
|
||||
|
||||
/* Define to 1 if you have the `sigaction' function. */
|
||||
#undef HAVE_SIGACTION
|
||||
|
||||
/* Define to 1 if you have the `sigprocmask' function. */
|
||||
#undef HAVE_SIGPROCMASK
|
||||
|
||||
/* Define to 1 if you have the `sigsetmask' function. */
|
||||
#undef HAVE_SIGSETMASK
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#undef HAVE_STDDEF_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the `strerror_r' function. */
|
||||
#undef HAVE_STRERROR_R
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strncasecmp' function. */
|
||||
#undef HAVE_STRNCASECMP
|
||||
|
||||
/* Define if struct utimbuf is declared -- usually in <utime.h>. Some systems
|
||||
have utime.h but don't declare the struct anywhere. */
|
||||
#undef HAVE_STRUCT_UTIMBUF
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_DIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
||||
|
||||
/* Define to 1 if you have the <varargs.h> header file. */
|
||||
#undef HAVE_VARARGS_H
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#undef HAVE_VPRINTF
|
||||
|
||||
/* Define to 1 if you have the <wchar.h> header file. */
|
||||
#undef HAVE_WCHAR_H
|
||||
|
||||
/* Define to 1 if you have the <wctype.h> header file. */
|
||||
#undef HAVE_WCTYPE_H
|
||||
|
||||
/* Define to 1 if you have the `_doprintf' function. */
|
||||
#undef HAVE__DOPRINTF
|
||||
|
||||
/* Define if mkdir takes only one argument. */
|
||||
#undef MKDIR_TAKES_ONE_ARG
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if the C compiler supports function prototypes. */
|
||||
#undef PROTOTYPES
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to 1 if strerror_r returns char *. */
|
||||
#undef STRERROR_R_CHAR_P
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
|
||||
#undef _LARGEFILE_SOURCE
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
#undef _LARGE_FILES
|
||||
|
||||
/* Define to 1 if on MINIX. */
|
||||
#undef _MINIX
|
||||
|
||||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
||||
this defined. */
|
||||
#undef _POSIX_1_SOURCE
|
||||
|
||||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
/* Define like PROTOTYPES; this can be used by system headers. */
|
||||
#undef __PROTOTYPES
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
#undef malloc
|
||||
|
||||
/* Define to a type if <wchar.h> does not define. */
|
||||
#undef mbstate_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef mode_t
|
||||
|
||||
/* Define to `long' if <sys/types.h> does not define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
#undef realloc
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
1220
patch/config.sub
vendored
Normal file
1220
patch/config.sub
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8633
patch/configure
vendored
Executable file
8633
patch/configure
vendored
Executable file
File diff suppressed because it is too large
Load Diff
75
patch/configure.ac
Normal file
75
patch/configure.ac
Normal file
@ -0,0 +1,75 @@
|
||||
# Configure `patch'.
|
||||
# Copyright (C) 1993, 1997, 1998, 1999, 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_PREREQ(2.53)
|
||||
AC_INIT(patch, 2.5.8, bug-patch@gnu.org)
|
||||
AC_CONFIG_SRCDIR(patch.c)
|
||||
AC_CONFIG_HEADER(config.h:config.hin)
|
||||
AC_ARG_PROGRAM
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
# Use ed_PROGRAM, not ED_PROGRAM,
|
||||
# because <errno.h> reserves symbols starting with `E'.
|
||||
AC_PATH_PROG(ed_PROGRAM, ed, ed)
|
||||
|
||||
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_TYPE_MODE_T
|
||||
AC_TYPE_OFF_T
|
||||
AC_TYPE_PID_T
|
||||
AC_TYPE_SIGNAL
|
||||
AC_TYPE_SIZE_T
|
||||
jm_CHECK_TYPE_STRUCT_UTIMBUF
|
||||
|
||||
jm_PREREQ_ADDEXT
|
||||
jm_PREREQ_DIRNAME
|
||||
jm_PREREQ_ERROR
|
||||
jm_PREREQ_MEMCHR
|
||||
jm_PREREQ_QUOTEARG
|
||||
|
||||
AC_CHECK_DECLS([free, getenv, malloc, mktemp])
|
||||
AC_CHECK_FUNCS(_doprintf geteuid getuid isascii memcmp mktemp \
|
||||
pathconf raise sigaction sigprocmask sigsetmask strerror)
|
||||
AC_REPLACE_FUNCS(memchr mkdir rename rmdir strncasecmp)
|
||||
AC_FUNC_FSEEKO
|
||||
jm_FUNC_MALLOC
|
||||
jm_FUNC_REALLOC
|
||||
AC_FUNC_CLOSEDIR_VOID
|
||||
AC_FUNC_SETMODE_DOS
|
||||
AC_FUNC_VPRINTF
|
||||
PATCH_FUNC_MKDIR_TAKES_ONE_ARG
|
||||
|
||||
AC_SYS_LONG_FILE_NAMES
|
||||
jm_CHECK_TYPE_STRUCT_DIRENT_D_INO
|
||||
|
||||
AC_OUTPUT(Makefile)
|
59
patch/configure.in
Normal file
59
patch/configure.in
Normal file
@ -0,0 +1,59 @@
|
||||
# Configure `patch'.
|
||||
# Copyright 1993, 1997-1998, 1999 Free Software Foundation, Inc.
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.12)
|
||||
AC_INIT(patch.c)
|
||||
AC_CONFIG_HEADER(config.h:config.hin)
|
||||
AC_ARG_PROGRAM
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
PACKAGE=patch
|
||||
VERSION=2.5.4
|
||||
AC_SUBST(PACKAGE)
|
||||
AC_SUBST(VERSION)
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
# Use ed_PROGRAM, not ED_PROGRAM,
|
||||
# because <errno.h> reserves symbols starting with `E'.
|
||||
AC_PATH_PROG(ed_PROGRAM, ed, ed)
|
||||
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
AC_AIX
|
||||
AC_MINIX
|
||||
AC_ISC_POSIX
|
||||
AC_EXEEXT
|
||||
|
||||
AM_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)
|
||||
jm_AC_HEADER_INTTYPES_H
|
||||
|
||||
AC_TYPE_MODE_T
|
||||
AC_TYPE_OFF_T
|
||||
AC_TYPE_PID_T
|
||||
AC_TYPE_SIGNAL
|
||||
AC_TYPE_SIZE_T
|
||||
jm_STRUCT_UTIMBUF
|
||||
|
||||
AC_CHECK_FUNC(getopt_long, , [LIBOBJS="$LIBOBJS getopt1\$U.o getopt\$U.o"])
|
||||
AC_SUBST(LIBOBJS)
|
||||
AC_CHECK_FUNCS(_doprintf isascii fseeko memcmp mktemp \
|
||||
pathconf raise setmode sigaction sigprocmask sigsetmask strerror)
|
||||
AC_REPLACE_FUNCS(memchr mkdir rename rmdir)
|
||||
jm_FUNC_MALLOC
|
||||
jm_FUNC_REALLOC
|
||||
AC_FUNC_CLOSEDIR_VOID
|
||||
AC_FUNC_VPRINTF
|
||||
|
||||
AC_SYS_LONG_FILE_NAMES
|
||||
jm_STRUCT_DIRENT_D_INO
|
||||
|
||||
AC_OUTPUT(Makefile)
|
105
patch/dirname.c
Normal file
105
patch/dirname.c
Normal file
@ -0,0 +1,105 @@
|
||||
/* dirname.c -- return all but the last element in a path
|
||||
Copyright 1990, 1998, 2000, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS || HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include "dirname.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
|
||||
sed -n '/^BEGIN-DATA$/,/^END-DATA$/p' dirname.c|grep -v DATA|./a.out
|
||||
|
||||
BEGIN-DATA
|
||||
foo//// .
|
||||
bar/foo//// bar
|
||||
foo/ .
|
||||
/ /
|
||||
. .
|
||||
a .
|
||||
END-DATA
|
||||
|
||||
*/
|
||||
|
||||
# define MAX_BUFF_LEN 1024
|
||||
# include <stdio.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
char buff[MAX_BUFF_LEN + 1];
|
||||
|
||||
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
|
47
patch/dirname.h
Normal file
47
patch/dirname.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* Copyright (C) 1998, 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef DIRNAME_H_
|
||||
# define DIRNAME_H_ 1
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# 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 PARAMS ((char const *path));
|
||||
char *dir_name PARAMS ((char const *path));
|
||||
size_t base_len PARAMS ((char const *path));
|
||||
size_t dir_len PARAMS ((char const *path));
|
||||
|
||||
int strip_trailing_slashes PARAMS ((char *path));
|
||||
|
||||
#endif /* not DIRNAME_H_ */
|
400
patch/error.c
Normal file
400
patch/error.c
Normal file
@ -0,0 +1,400 @@
|
||||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990-1998, 2000, 2001 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library. Its master source is NOT part of
|
||||
the C library, however. The master source lives in /gd/gnu/lib.
|
||||
|
||||
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 <stdio.h>
|
||||
#if HAVE_LIBINTL_H
|
||||
# include <libintl.h>
|
||||
#endif
|
||||
#ifdef _LIBC
|
||||
# include <wchar.h>
|
||||
# define mbsrtowcs __mbsrtowcs
|
||||
#endif
|
||||
|
||||
#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
|
||||
# if __STDC__
|
||||
# include <stdarg.h>
|
||||
# define VA_START(args, lastarg) va_start(args, lastarg)
|
||||
# else
|
||||
# include <varargs.h>
|
||||
# define VA_START(args, lastarg) va_start(args)
|
||||
# endif
|
||||
#else
|
||||
# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
|
||||
# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS || _LIBC
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
void exit ();
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
#include "unlocked-io.h"
|
||||
|
||||
#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) (
|
||||
#if __STDC__ - 0
|
||||
void
|
||||
#endif
|
||||
);
|
||||
|
||||
/* 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 <errno.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
|
||||
|
||||
# ifdef USE_IN_LIBIO
|
||||
# include <libio/iolibio.h>
|
||||
# define fflush(s) _IO_fflush (s)
|
||||
# endif
|
||||
|
||||
#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
|
||||
# else
|
||||
# if HAVE_STRERROR
|
||||
# ifndef HAVE_DECL_STRERROR
|
||||
"this configure-time declaration test was not run"
|
||||
# endif
|
||||
# if !HAVE_DECL_STRERROR
|
||||
char *strerror ();
|
||||
# endif
|
||||
# else
|
||||
static char *
|
||||
private_strerror (int errnum)
|
||||
{
|
||||
extern char *sys_errlist[];
|
||||
extern int sys_nerr;
|
||||
|
||||
if (errnum > 0 && errnum <= sys_nerr)
|
||||
return _(sys_errlist[errnum]);
|
||||
return _("Unknown system error");
|
||||
}
|
||||
# define strerror private_strerror
|
||||
# endif /* HAVE_STRERROR */
|
||||
# endif /* HAVE_STRERROR_R || defined strerror_r */
|
||||
#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 && USE_IN_LIBIO
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
{
|
||||
__fwprintf (stderr, L": %s", s);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
fprintf (stderr, ": %s", s);
|
||||
}
|
||||
|
||||
#ifdef VA_START
|
||||
static void
|
||||
error_tail (int status, int errnum, const char *message, va_list args)
|
||||
{
|
||||
# if HAVE_VPRINTF || _LIBC
|
||||
# if _LIBC && USE_IN_LIBIO
|
||||
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 && USE_IN_LIBIO
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
putwc (L'\n', stderr);
|
||||
else
|
||||
# endif
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* 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
|
||||
#if defined VA_START && __STDC__
|
||||
error (int status, int errnum, const char *message, ...)
|
||||
#else
|
||||
error (status, errnum, message, va_alist)
|
||||
int status;
|
||||
int errnum;
|
||||
char *message;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
#ifdef VA_START
|
||||
va_list args;
|
||||
#endif
|
||||
|
||||
fflush (stdout);
|
||||
#ifdef _LIBC
|
||||
# ifdef USE_IN_LIBIO
|
||||
_IO_flockfile (stderr);
|
||||
# else
|
||||
__flockfile (stderr);
|
||||
# endif
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC && USE_IN_LIBIO
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
__fwprintf (stderr, L"%s: ", program_name);
|
||||
else
|
||||
#endif
|
||||
fprintf (stderr, "%s: ", program_name);
|
||||
}
|
||||
|
||||
#ifdef VA_START
|
||||
VA_START (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
#else
|
||||
fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
print_errno_message (errnum);
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
# ifdef USE_IN_LIBIO
|
||||
_IO_funlockfile (stderr);
|
||||
# else
|
||||
__funlockfile (stderr);
|
||||
# endif
|
||||
#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
|
||||
#if defined VA_START && __STDC__
|
||||
error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message, ...)
|
||||
#else
|
||||
error_at_line (status, errnum, file_name, line_number, message, va_alist)
|
||||
int status;
|
||||
int errnum;
|
||||
const char *file_name;
|
||||
unsigned int line_number;
|
||||
char *message;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
#ifdef VA_START
|
||||
va_list args;
|
||||
#endif
|
||||
|
||||
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
|
||||
# ifdef USE_IN_LIBIO
|
||||
_IO_flockfile (stderr);
|
||||
# else
|
||||
__flockfile (stderr);
|
||||
# endif
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC && USE_IN_LIBIO
|
||||
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 && USE_IN_LIBIO
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef VA_START
|
||||
VA_START (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
#else
|
||||
fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
print_errno_message (errnum);
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
# ifdef USE_IN_LIBIO
|
||||
_IO_funlockfile (stderr);
|
||||
# else
|
||||
__funlockfile (stderr);
|
||||
# endif
|
||||
#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
|
78
patch/error.h
Normal file
78
patch/error.h
Normal file
@ -0,0 +1,78 @@
|
||||
/* Declaration for error-reporting function
|
||||
Copyright (C) 1995, 1996, 1997 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
|
||||
|
||||
#if defined (__STDC__) && __STDC__
|
||||
|
||||
/* 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);
|
||||
|
||||
#else
|
||||
void error ();
|
||||
void error_at_line ();
|
||||
extern void (*error_print_progname) ();
|
||||
#endif
|
||||
|
||||
/* 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 */
|
31
patch/exitfail.c
Normal file
31
patch/exitfail.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* 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. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#ifndef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
int volatile exit_failure = EXIT_FAILURE;
|
20
patch/exitfail.h
Normal file
20
patch/exitfail.h
Normal file
@ -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;
|
1067
patch/getopt.c
Normal file
1067
patch/getopt.c
Normal file
File diff suppressed because it is too large
Load Diff
179
patch/getopt.h
Normal file
179
patch/getopt.h
Normal file
@ -0,0 +1,179 @@
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001 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
|
||||
{
|
||||
# if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
const char *name;
|
||||
# else
|
||||
char *name;
|
||||
# endif
|
||||
/* 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'. */
|
||||
|
||||
#if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
# 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
|
||||
#else /* not __STDC__ */
|
||||
extern int getopt ();
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long ();
|
||||
extern int getopt_long_only ();
|
||||
|
||||
extern int _getopt_internal ();
|
||||
# endif
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
|
||||
#endif /* getopt.h */
|
187
patch/getopt1.c
Normal file
187
patch/getopt1.c
Normal file
@ -0,0 +1,187 @@
|
||||
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
|
||||
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
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#if !defined __STDC__ || !__STDC__
|
||||
/* This is a separate conditional since some stdc systems
|
||||
reject `defined (const)'. */
|
||||
#ifndef const
|
||||
#define const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* 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 (argc, argv, options, long_options, opt_index)
|
||||
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 (argc, argv, options, long_options, opt_index)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
#endif /* Not ELIDE_CODE. */
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
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 */
|
468
patch/inp.c
Normal file
468
patch/inp.c
Normal file
@ -0,0 +1,468 @@
|
||||
/* inputting files to be patched */
|
||||
|
||||
/* $Id: inp.c,v 1.1.1.3 2003/05/08 18:38:02 rbraun Exp $ */
|
||||
|
||||
/* Copyright (C) 1986, 1988 Larry Wall
|
||||
Copyright (C) 1991, 1992, 1993, 1997, 1998, 1999, 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. */
|
||||
|
||||
#define XTERN extern
|
||||
#include <common.h>
|
||||
#include <backupfile.h>
|
||||
#include <pch.h>
|
||||
#include <quotearg.h>
|
||||
#include <util.h>
|
||||
#include <xalloc.h>
|
||||
#undef XTERN
|
||||
#define XTERN
|
||||
#include <inp.h>
|
||||
|
||||
/* Input-file-with-indexable-lines abstract type */
|
||||
|
||||
static char *i_buffer; /* plan A buffer */
|
||||
static char const **i_ptr; /* pointers to lines in plan A buffer */
|
||||
|
||||
static size_t tibufsize; /* size of plan b buffers */
|
||||
#ifndef TIBUFSIZE_MINIMUM
|
||||
#define TIBUFSIZE_MINIMUM (8 * 1024) /* minimum value for tibufsize */
|
||||
#endif
|
||||
static int tifd = -1; /* plan b virtual string array */
|
||||
static char *tibuf[2]; /* plan b buffers */
|
||||
static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */
|
||||
static LINENUM lines_per_buf; /* how many lines per buffer */
|
||||
static size_t tireclen; /* length of records in tmp file */
|
||||
static size_t last_line_size; /* size of last input line */
|
||||
|
||||
static bool plan_a (char const *); /* yield FALSE if memory runs out */
|
||||
static void plan_b (char const *);
|
||||
static void report_revision (int);
|
||||
static void too_many_lines (char const *) __attribute__((noreturn));
|
||||
|
||||
/* New patch--prepare to edit another file. */
|
||||
|
||||
void
|
||||
re_input (void)
|
||||
{
|
||||
if (using_plan_a) {
|
||||
if (i_buffer)
|
||||
{
|
||||
free (i_buffer);
|
||||
i_buffer = 0;
|
||||
free (i_ptr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
close (tifd);
|
||||
tifd = -1;
|
||||
if (tibuf[0])
|
||||
{
|
||||
free (tibuf[0]);
|
||||
tibuf[0] = 0;
|
||||
}
|
||||
tiline[0] = tiline[1] = -1;
|
||||
tireclen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Construct the line index, somehow or other. */
|
||||
|
||||
void
|
||||
scan_input (char *filename)
|
||||
{
|
||||
using_plan_a = ! (debug & 16) && plan_a (filename);
|
||||
if (!using_plan_a)
|
||||
plan_b(filename);
|
||||
|
||||
if (verbosity != SILENT)
|
||||
{
|
||||
filename = quotearg (filename);
|
||||
|
||||
if (verbosity == VERBOSE)
|
||||
say ("Patching file %s using Plan %s...\n",
|
||||
filename, using_plan_a ? "A" : "B");
|
||||
else
|
||||
say ("patching file %s\n", filename);
|
||||
}
|
||||
}
|
||||
|
||||
/* Report whether a desired revision was found. */
|
||||
|
||||
static void
|
||||
report_revision (int found_revision)
|
||||
{
|
||||
char const *rev = quotearg (revision);
|
||||
|
||||
if (found_revision)
|
||||
{
|
||||
if (verbosity == VERBOSE)
|
||||
say ("Good. This file appears to be the %s version.\n", rev);
|
||||
}
|
||||
else if (force)
|
||||
{
|
||||
if (verbosity != SILENT)
|
||||
say ("Warning: this file doesn't appear to be the %s version -- patching anyway.\n",
|
||||
rev);
|
||||
}
|
||||
else if (batch)
|
||||
fatal ("This file doesn't appear to be the %s version -- aborting.",
|
||||
rev);
|
||||
else
|
||||
{
|
||||
ask ("This file doesn't appear to be the %s version -- patch anyway? [n] ",
|
||||
rev);
|
||||
if (*buf != 'y')
|
||||
fatal ("aborted");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
too_many_lines (char const *filename)
|
||||
{
|
||||
fatal ("File %s has too many lines", quotearg (filename));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
get_input_file (char const *filename, char const *outname)
|
||||
{
|
||||
int elsewhere = strcmp (filename, outname);
|
||||
char const *cs;
|
||||
char *diffbuf;
|
||||
char *getbuf;
|
||||
|
||||
if (inerrno == -1)
|
||||
inerrno = stat (inname, &instat) == 0 ? 0 : errno;
|
||||
|
||||
/* Perhaps look for RCS or SCCS versions. */
|
||||
if (patch_get
|
||||
&& invc != 0
|
||||
&& (inerrno
|
||||
|| (! elsewhere
|
||||
&& (/* No one can write to it. */
|
||||
(instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0
|
||||
/* Only the owner (who's not me) can write to it. */
|
||||
|| ((instat.st_mode & (S_IWGRP|S_IWOTH)) == 0
|
||||
&& instat.st_uid != geteuid ()))))
|
||||
&& (invc = !! (cs = (version_controller
|
||||
(filename, elsewhere,
|
||||
inerrno ? (struct stat *) 0 : &instat,
|
||||
&getbuf, &diffbuf))))) {
|
||||
|
||||
if (!inerrno) {
|
||||
if (!elsewhere
|
||||
&& (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0)
|
||||
/* Somebody can write to it. */
|
||||
fatal ("File %s seems to be locked by somebody else under %s",
|
||||
quotearg (filename), cs);
|
||||
if (diffbuf)
|
||||
{
|
||||
/* It might be checked out unlocked. See if it's safe to
|
||||
check out the default version locked. */
|
||||
|
||||
if (verbosity == VERBOSE)
|
||||
say ("Comparing file %s to default %s version...\n",
|
||||
quotearg (filename), cs);
|
||||
|
||||
if (systemic (diffbuf) != 0)
|
||||
{
|
||||
say ("warning: Patching file %s, which does not match default %s version\n",
|
||||
quotearg (filename), cs);
|
||||
cs = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cs && version_get (filename, cs, ! inerrno, elsewhere, getbuf,
|
||||
&instat))
|
||||
inerrno = 0;
|
||||
|
||||
free (getbuf);
|
||||
if (diffbuf)
|
||||
free (diffbuf);
|
||||
|
||||
} else if (inerrno && !pch_says_nonexistent (reverse))
|
||||
{
|
||||
errno = inerrno;
|
||||
pfatal ("Can't find file %s", quotearg (filename));
|
||||
}
|
||||
|
||||
if (inerrno)
|
||||
{
|
||||
instat.st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
|
||||
instat.st_size = 0;
|
||||
}
|
||||
else if (! S_ISREG (instat.st_mode))
|
||||
fatal ("File %s is not a regular file -- can't patch",
|
||||
quotearg (filename));
|
||||
}
|
||||
|
||||
|
||||
/* Try keeping everything in memory. */
|
||||
|
||||
static bool
|
||||
plan_a (char const *filename)
|
||||
{
|
||||
register char const *s;
|
||||
register char const *lim;
|
||||
register char const **ptr;
|
||||
register char *buffer;
|
||||
register LINENUM iline;
|
||||
size_t size = instat.st_size;
|
||||
|
||||
/* Fail if the file size doesn't fit in a size_t,
|
||||
or if storage isn't available. */
|
||||
if (! (size == instat.st_size
|
||||
&& (buffer = malloc (size ? size : (size_t) 1))))
|
||||
return FALSE;
|
||||
|
||||
/* Read the input file, but don't bother reading it if it's empty.
|
||||
When creating files, the files do not actually exist. */
|
||||
if (size)
|
||||
{
|
||||
int ifd = open (filename, O_RDONLY|binary_transput);
|
||||
size_t buffered = 0, n;
|
||||
if (ifd < 0)
|
||||
pfatal ("can't open file %s", quotearg (filename));
|
||||
|
||||
while (size - buffered != 0)
|
||||
{
|
||||
n = read (ifd, buffer + buffered, size - buffered);
|
||||
if (n == 0)
|
||||
{
|
||||
/* Some non-POSIX hosts exaggerate st_size in text mode;
|
||||
or the file may have shrunk! */
|
||||
size = buffered;
|
||||
break;
|
||||
}
|
||||
if (n == (size_t) -1)
|
||||
{
|
||||
/* Perhaps size is too large for this host. */
|
||||
close (ifd);
|
||||
free (buffer);
|
||||
return FALSE;
|
||||
}
|
||||
buffered += n;
|
||||
}
|
||||
|
||||
if (close (ifd) != 0)
|
||||
read_fatal ();
|
||||
}
|
||||
|
||||
/* Scan the buffer and build array of pointers to lines. */
|
||||
lim = buffer + size;
|
||||
iline = 3; /* 1 unused, 1 for SOF, 1 for EOF if last line is incomplete */
|
||||
for (s = buffer; (s = (char *) memchr (s, '\n', lim - s)); s++)
|
||||
if (++iline < 0)
|
||||
too_many_lines (filename);
|
||||
if (! (iline == (size_t) iline
|
||||
&& (size_t) iline * sizeof *ptr / sizeof *ptr == (size_t) iline
|
||||
&& (ptr = (char const **) malloc ((size_t) iline * sizeof *ptr))))
|
||||
{
|
||||
free (buffer);
|
||||
return FALSE;
|
||||
}
|
||||
iline = 0;
|
||||
for (s = buffer; ; s++)
|
||||
{
|
||||
ptr[++iline] = s;
|
||||
if (! (s = (char *) memchr (s, '\n', lim - s)))
|
||||
break;
|
||||
}
|
||||
if (size && lim[-1] != '\n')
|
||||
ptr[++iline] = lim;
|
||||
input_lines = iline - 1;
|
||||
|
||||
if (revision)
|
||||
{
|
||||
char const *rev = revision;
|
||||
int rev0 = rev[0];
|
||||
int found_revision = 0;
|
||||
size_t revlen = strlen (rev);
|
||||
|
||||
if (revlen <= size)
|
||||
{
|
||||
char const *limrev = lim - revlen;
|
||||
|
||||
for (s = buffer; (s = (char *) memchr (s, rev0, limrev - s)); s++)
|
||||
if (memcmp (s, rev, revlen) == 0
|
||||
&& (s == buffer || ISSPACE ((unsigned char) s[-1]))
|
||||
&& (s + 1 == limrev || ISSPACE ((unsigned char) s[revlen])))
|
||||
{
|
||||
found_revision = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
report_revision (found_revision);
|
||||
}
|
||||
|
||||
/* Plan A will work. */
|
||||
i_buffer = buffer;
|
||||
i_ptr = ptr;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Keep (virtually) nothing in memory. */
|
||||
|
||||
static void
|
||||
plan_b (char const *filename)
|
||||
{
|
||||
register FILE *ifp;
|
||||
register int c;
|
||||
register size_t len;
|
||||
register size_t maxlen;
|
||||
register int found_revision;
|
||||
register size_t i;
|
||||
register char const *rev;
|
||||
register size_t revlen;
|
||||
register LINENUM line = 1;
|
||||
int exclusive;
|
||||
|
||||
if (instat.st_size == 0)
|
||||
filename = NULL_DEVICE;
|
||||
if (! (ifp = fopen (filename, binary_transput ? "rb" : "r")))
|
||||
pfatal ("Can't open file %s", quotearg (filename));
|
||||
exclusive = TMPINNAME_needs_removal ? 0 : O_EXCL;
|
||||
TMPINNAME_needs_removal = 1;
|
||||
tifd = create_file (TMPINNAME, O_RDWR | O_BINARY | exclusive, (mode_t) 0);
|
||||
i = 0;
|
||||
len = 0;
|
||||
maxlen = 1;
|
||||
rev = revision;
|
||||
found_revision = !rev;
|
||||
revlen = rev ? strlen (rev) : 0;
|
||||
|
||||
while ((c = getc (ifp)) != EOF)
|
||||
{
|
||||
len++;
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
if (++line < 0)
|
||||
too_many_lines (filename);
|
||||
if (maxlen < len)
|
||||
maxlen = len;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
if (!found_revision)
|
||||
{
|
||||
if (i == revlen)
|
||||
{
|
||||
found_revision = ISSPACE ((unsigned char) c);
|
||||
i = (size_t) -1;
|
||||
}
|
||||
else if (i != (size_t) -1)
|
||||
i = rev[i]==c ? i + 1 : (size_t) -1;
|
||||
|
||||
if (i == (size_t) -1 && ISSPACE ((unsigned char) c))
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (revision)
|
||||
report_revision (found_revision);
|
||||
Fseek (ifp, (off_t) 0, SEEK_SET); /* rewind file */
|
||||
for (tibufsize = TIBUFSIZE_MINIMUM; tibufsize < maxlen; tibufsize <<= 1)
|
||||
continue;
|
||||
lines_per_buf = tibufsize / maxlen;
|
||||
tireclen = maxlen;
|
||||
tibuf[0] = xmalloc (2 * tibufsize);
|
||||
tibuf[1] = tibuf[0] + tibufsize;
|
||||
|
||||
for (line = 1; ; line++)
|
||||
{
|
||||
char *p = tibuf[0] + maxlen * (line % lines_per_buf);
|
||||
char const *p0 = p;
|
||||
if (! (line % lines_per_buf)) /* new block */
|
||||
if (write (tifd, tibuf[0], tibufsize) != tibufsize)
|
||||
write_fatal ();
|
||||
if ((c = getc (ifp)) == EOF)
|
||||
break;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
*p++ = c;
|
||||
if (c == '\n')
|
||||
{
|
||||
last_line_size = p - p0;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((c = getc (ifp)) == EOF)
|
||||
{
|
||||
last_line_size = p - p0;
|
||||
line++;
|
||||
goto EOF_reached;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF_reached:
|
||||
if (ferror (ifp) || fclose (ifp) != 0)
|
||||
read_fatal ();
|
||||
|
||||
if (line % lines_per_buf != 0)
|
||||
if (write (tifd, tibuf[0], tibufsize) != tibufsize)
|
||||
write_fatal ();
|
||||
input_lines = line - 1;
|
||||
}
|
||||
|
||||
/* Fetch a line from the input file.
|
||||
WHICHBUF is ignored when the file is in memory. */
|
||||
|
||||
char const *
|
||||
ifetch (LINENUM line, int whichbuf, size_t *psize)
|
||||
{
|
||||
register char const *q;
|
||||
register char const *p;
|
||||
|
||||
if (line < 1 || line > input_lines) {
|
||||
*psize = 0;
|
||||
return "";
|
||||
}
|
||||
if (using_plan_a) {
|
||||
p = i_ptr[line];
|
||||
*psize = i_ptr[line + 1] - p;
|
||||
return p;
|
||||
} else {
|
||||
LINENUM offline = line % lines_per_buf;
|
||||
LINENUM baseline = line - offline;
|
||||
|
||||
if (tiline[0] == baseline)
|
||||
whichbuf = 0;
|
||||
else if (tiline[1] == baseline)
|
||||
whichbuf = 1;
|
||||
else {
|
||||
tiline[whichbuf] = baseline;
|
||||
if (lseek (tifd, (off_t) (baseline/lines_per_buf * tibufsize),
|
||||
SEEK_SET) == -1
|
||||
|| read (tifd, tibuf[whichbuf], tibufsize) < 0)
|
||||
read_fatal ();
|
||||
}
|
||||
p = tibuf[whichbuf] + (tireclen*offline);
|
||||
if (line == input_lines)
|
||||
*psize = last_line_size;
|
||||
else {
|
||||
for (q = p; *q++ != '\n'; )
|
||||
continue;
|
||||
*psize = q - p;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
29
patch/inp.h
Normal file
29
patch/inp.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* inputting files to be patched */
|
||||
|
||||
/* $Id: inp.h,v 1.1.1.3 2003/05/08 18:38:02 rbraun Exp $ */
|
||||
|
||||
/* Copyright (C) 1986, 1988 Larry Wall
|
||||
Copyright (C) 1991, 1992, 1993, 1997, 1998, 1999, 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. */
|
||||
|
||||
XTERN LINENUM input_lines; /* how long is input file in lines */
|
||||
|
||||
char const *ifetch (LINENUM, int, size_t *);
|
||||
void get_input_file (char const *, char const *);
|
||||
void re_input (void);
|
||||
void scan_input (char *);
|
251
patch/install-sh
Executable file
251
patch/install-sh
Executable file
@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5 (mit/util/scripts/install.sh).
|
||||
#
|
||||
# Copyright 1991 by the Massachusetts Institute of Technology
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of M.I.T. not be used in advertising or
|
||||
# publicity pertaining to distribution of the software without specific,
|
||||
# written prior permission. M.I.T. makes no representations about the
|
||||
# suitability of this software for any purpose. It is provided "as is"
|
||||
# without express or implied warranty.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. 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=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -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 [ -f $src -o -d $src ]
|
||||
then
|
||||
:
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
:
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
29
patch/m4/c-bs-a.m4
Normal file
29
patch/m4/c-bs-a.m4
Normal file
@ -0,0 +1,29 @@
|
||||
# c-bs-a.m4 serial 4 (fileutils-4.1.3)
|
||||
dnl Copyright (C) 2000-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.
|
||||
|
||||
AC_DEFUN([AC_C_BACKSLASH_A],
|
||||
[
|
||||
AC_CACHE_CHECK([whether backslash-a works in strings], ac_cv_c_backslash_a,
|
||||
[AC_TRY_COMPILE([],
|
||||
[
|
||||
#if '\a' == 'a'
|
||||
syntax error;
|
||||
#endif
|
||||
char buf['\a' == 'a' ? -1 : 1];
|
||||
buf[0] = '\a';
|
||||
return buf[0] != "\a"[0];
|
||||
],
|
||||
ac_cv_c_backslash_a=yes,
|
||||
ac_cv_c_backslash_a=no)])
|
||||
if test $ac_cv_c_backslash_a = yes; then
|
||||
AC_DEFINE(HAVE_C_BACKSLASH_A, 1,
|
||||
[Define if backslash-a works in C strings.])
|
||||
fi
|
||||
])
|
95
patch/m4/ccstdc.m4
Normal file
95
patch/m4/ccstdc.m4
Normal file
@ -0,0 +1,95 @@
|
||||
# The following is taken from automake 1.4,
|
||||
# except that it prefers the compiler option -Ae to "-Aa -D_HPUX_SOURCE"
|
||||
# because only the former supports 64-bit integral types on HP-UX 10.20.
|
||||
|
||||
## ----------------------------------------- ##
|
||||
## ANSIfy the C compiler whenever possible. ##
|
||||
## From Franc,ois Pinard ##
|
||||
## ----------------------------------------- ##
|
||||
|
||||
# serial 2
|
||||
|
||||
# @defmac AC_PROG_CC_STDC
|
||||
# @maindex PROG_CC_STDC
|
||||
# @ovindex CC
|
||||
# If the C compiler in not in ANSI C mode by default, try to add an option
|
||||
# to output variable @code{CC} to make it so. This macro tries various
|
||||
# options that select ANSI C on some system or another. It considers the
|
||||
# compiler to be in ANSI C mode if it handles function prototypes correctly.
|
||||
#
|
||||
# If you use this macro, you should check after calling it whether the C
|
||||
# compiler has been set to accept ANSI C; if not, the shell variable
|
||||
# @code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source
|
||||
# code in ANSI C, you can make an un-ANSIfied copy of it by using the
|
||||
# program @code{ansi2knr}, which comes with Ghostscript.
|
||||
# @end defmac
|
||||
|
||||
AC_DEFUN(AM_PROG_CC_STDC,
|
||||
[AC_REQUIRE([AC_PROG_CC])
|
||||
AC_BEFORE([$0], [AC_C_INLINE])
|
||||
AC_BEFORE([$0], [AC_C_CONST])
|
||||
dnl Force this before AC_PROG_CPP. Some cpp's, eg on HPUX, require
|
||||
dnl a magic option to avoid problems with ANSI preprocessor commands
|
||||
dnl like #elif.
|
||||
dnl FIXME: can't do this because then AC_AIX won't work due to a
|
||||
dnl circular dependency.
|
||||
dnl AC_BEFORE([$0], [AC_PROG_CPP])
|
||||
AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
|
||||
AC_CACHE_VAL(am_cv_prog_cc_stdc,
|
||||
[am_cv_prog_cc_stdc=no
|
||||
ac_save_CC="$CC"
|
||||
# Don't try gcc -ansi; that turns off useful extensions and
|
||||
# breaks some systems' header files.
|
||||
# AIX -qlanglvl=ansi
|
||||
# Ultrix and OSF/1 -std1
|
||||
# HP-UX -Aa -D_HPUX_SOURCE
|
||||
# SVR4 -Xc -D__EXTENSIONS__
|
||||
for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
|
||||
do
|
||||
CC="$ac_save_CC $ac_arg"
|
||||
AC_TRY_COMPILE(
|
||||
[#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
|
||||
struct buf { int x; };
|
||||
FILE * (*rcsopen) (struct buf *, struct stat *, int);
|
||||
static char *e (p, i)
|
||||
char **p;
|
||||
int i;
|
||||
{
|
||||
return p[i];
|
||||
}
|
||||
static char *f (char * (*g) (char **, int), char **p, ...)
|
||||
{
|
||||
char *s;
|
||||
va_list v;
|
||||
va_start (v,p);
|
||||
s = g (p, va_arg (v,int));
|
||||
va_end (v);
|
||||
return s;
|
||||
}
|
||||
int test (int i, double x);
|
||||
struct s1 {int (*f) (int a);};
|
||||
struct s2 {int (*f) (double a);};
|
||||
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
|
||||
int argc;
|
||||
char **argv;
|
||||
], [
|
||||
return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
|
||||
],
|
||||
[am_cv_prog_cc_stdc="$ac_arg"; break])
|
||||
done
|
||||
CC="$ac_save_CC"
|
||||
])
|
||||
if test -z "$am_cv_prog_cc_stdc"; then
|
||||
AC_MSG_RESULT([none needed])
|
||||
else
|
||||
AC_MSG_RESULT($am_cv_prog_cc_stdc)
|
||||
fi
|
||||
case "x$am_cv_prog_cc_stdc" in
|
||||
x|xno) ;;
|
||||
*) CC="$CC $am_cv_prog_cc_stdc" ;;
|
||||
esac
|
||||
])
|
42
patch/m4/d-ino.m4
Normal file
42
patch/m4/d-ino.m4
Normal file
@ -0,0 +1,42 @@
|
||||
#serial 4
|
||||
|
||||
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
|
||||
]
|
||||
)
|
13
patch/m4/error.m4
Normal file
13
patch/m4/error.m4
Normal file
@ -0,0 +1,13 @@
|
||||
#serial 4
|
||||
|
||||
dnl FIXME: put these prerequisite-only *.m4 files in a separate
|
||||
dnl directory -- otherwise, they'll conflict with existing files.
|
||||
|
||||
dnl These are the prerequisite macros for GNU's error.c file.
|
||||
AC_DEFUN([jm_PREREQ_ERROR],
|
||||
[
|
||||
AC_CHECK_FUNCS(strerror vprintf doprnt)
|
||||
AC_CHECK_DECLS([strerror])
|
||||
AC_FUNC_STRERROR_R
|
||||
AC_HEADER_STDC
|
||||
])
|
22
patch/m4/inttypes_h.m4
Normal file
22
patch/m4/inttypes_h.m4
Normal file
@ -0,0 +1,22 @@
|
||||
#serial 3
|
||||
|
||||
dnl From Paul Eggert.
|
||||
|
||||
# Define HAVE_INTTYPES_H if <inttypes.h> exists,
|
||||
# doesn't clash with <sys/types.h>, and declares uintmax_t.
|
||||
|
||||
AC_DEFUN(jm_AC_HEADER_INTTYPES_H,
|
||||
[
|
||||
AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h,
|
||||
[AC_TRY_COMPILE(
|
||||
[#include <sys/types.h>
|
||||
#include <inttypes.h>],
|
||||
[uintmax_t i = (uintmax_t) -1;],
|
||||
jm_ac_cv_header_inttypes_h=yes,
|
||||
jm_ac_cv_header_inttypes_h=no)])
|
||||
if test $jm_ac_cv_header_inttypes_h = yes; then
|
||||
AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H, 1,
|
||||
[Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
|
||||
and declares uintmax_t. ])
|
||||
fi
|
||||
])
|
14
patch/m4/jm-glibc-io.m4
Normal file
14
patch/m4/jm-glibc-io.m4
Normal file
@ -0,0 +1,14 @@
|
||||
#serial 7 -*- autoconf -*-
|
||||
|
||||
dnl From Jim Meyering.
|
||||
dnl
|
||||
dnl See if the glibc *_unlocked I/O macros are available.
|
||||
dnl Use only those *_unlocked macros that are declared.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([jm_FUNC_GLIBC_UNLOCKED_IO],
|
||||
[AC_CHECK_DECLS(
|
||||
[clearerr_unlocked, feof_unlocked, ferror_unlocked,
|
||||
fflush_unlocked, fgets_unlocked, fputc_unlocked, fputs_unlocked,
|
||||
fread_unlocked, fwrite_unlocked, getc_unlocked,
|
||||
getchar_unlocked, putc_unlocked, putchar_unlocked])])
|
115
patch/m4/largefile.m4
Normal file
115
patch/m4/largefile.m4
Normal file
@ -0,0 +1,115 @@
|
||||
#serial 5
|
||||
|
||||
dnl By default, many hosts won't let programs access large files;
|
||||
dnl one must use special compiler options to get large-file access to work.
|
||||
dnl For more details about this brain damage please see:
|
||||
dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
|
||||
|
||||
dnl Written by Paul Eggert <eggert@twinsun.com>.
|
||||
|
||||
dnl Internal subroutine of AC_SYS_LARGEFILE.
|
||||
dnl AC_SYS_LARGEFILE_FLAGS(FLAGSNAME)
|
||||
AC_DEFUN(AC_SYS_LARGEFILE_FLAGS,
|
||||
[AC_CACHE_CHECK([for $1 value to request large file support],
|
||||
ac_cv_sys_largefile_$1,
|
||||
[ac_cv_sys_largefile_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
|
||||
ac_cv_sys_largefile_$1=no
|
||||
ifelse($1, CFLAGS,
|
||||
[case "$host_os" in
|
||||
# IRIX 6.2 and later require cc -n32.
|
||||
changequote(, )dnl
|
||||
irix6.[2-9]* | irix6.1[0-9]* | irix[7-9].* | irix[1-9][0-9]*)
|
||||
changequote([, ])dnl
|
||||
if test "$GCC" != yes; then
|
||||
ac_cv_sys_largefile_CFLAGS=-n32
|
||||
fi
|
||||
ac_save_CC="$CC"
|
||||
CC="$CC $ac_cv_sys_largefile_CFLAGS"
|
||||
AC_TRY_LINK(, , , ac_cv_sys_largefile_CFLAGS=no)
|
||||
CC="$ac_save_CC"
|
||||
esac])
|
||||
}])])
|
||||
|
||||
dnl Internal subroutine of AC_SYS_LARGEFILE.
|
||||
dnl AC_SYS_LARGEFILE_SPACE_APPEND(VAR, VAL)
|
||||
AC_DEFUN(AC_SYS_LARGEFILE_SPACE_APPEND,
|
||||
[case $2 in
|
||||
no) ;;
|
||||
?*)
|
||||
case "[$]$1" in
|
||||
'') $1=$2 ;;
|
||||
*) $1=[$]$1' '$2 ;;
|
||||
esac ;;
|
||||
esac])
|
||||
|
||||
dnl Internal subroutine of AC_SYS_LARGEFILE.
|
||||
dnl AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, CACHE-VAR, COMMENT, CODE-TO-SET-DEFAULT)
|
||||
AC_DEFUN(AC_SYS_LARGEFILE_MACRO_VALUE,
|
||||
[AC_CACHE_CHECK([for $1], $2,
|
||||
[$2=no
|
||||
changequote(, )dnl
|
||||
$4
|
||||
for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
|
||||
case "$ac_flag" in
|
||||
-D$1)
|
||||
$2=1 ;;
|
||||
-D$1=*)
|
||||
$2=`expr " $ac_flag" : '[^=]*=\(.*\)'` ;;
|
||||
esac
|
||||
done
|
||||
changequote([, ])dnl
|
||||
])
|
||||
if test "[$]$2" != no; then
|
||||
AC_DEFINE_UNQUOTED([$1], [$]$2, [$3])
|
||||
fi])
|
||||
|
||||
AC_DEFUN(AC_SYS_LARGEFILE,
|
||||
[AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_ARG_ENABLE(largefile,
|
||||
[ --disable-largefile omit support for large files])
|
||||
if test "$enable_largefile" != no; then
|
||||
AC_CHECK_TOOL(GETCONF, getconf)
|
||||
AC_SYS_LARGEFILE_FLAGS(CFLAGS)
|
||||
AC_SYS_LARGEFILE_FLAGS(LDFLAGS)
|
||||
AC_SYS_LARGEFILE_FLAGS(LIBS)
|
||||
|
||||
for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
|
||||
case "$ac_flag" in
|
||||
no) ;;
|
||||
-D_FILE_OFFSET_BITS=*) ;;
|
||||
-D_LARGEFILE_SOURCE | -D_LARGEFILE_SOURCE=*) ;;
|
||||
-D_LARGE_FILES | -D_LARGE_FILES=*) ;;
|
||||
-D?* | -I?*)
|
||||
AC_SYS_LARGEFILE_SPACE_APPEND(CPPFLAGS, "$ac_flag") ;;
|
||||
*)
|
||||
AC_SYS_LARGEFILE_SPACE_APPEND(CFLAGS, "$ac_flag") ;;
|
||||
esac
|
||||
done
|
||||
AC_SYS_LARGEFILE_SPACE_APPEND(LDFLAGS, "$ac_cv_sys_largefile_LDFLAGS")
|
||||
AC_SYS_LARGEFILE_SPACE_APPEND(LIBS, "$ac_cv_sys_largefile_LIBS")
|
||||
AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS,
|
||||
ac_cv_sys_file_offset_bits,
|
||||
[Number of bits in a file offset, on hosts where this is settable.],
|
||||
[case "$host_os" in
|
||||
# HP-UX 10.20 and later
|
||||
hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
|
||||
ac_cv_sys_file_offset_bits=64 ;;
|
||||
esac])
|
||||
AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE,
|
||||
ac_cv_sys_largefile_source,
|
||||
[Define to make fseeko etc. visible, on some hosts.],
|
||||
[case "$host_os" in
|
||||
# HP-UX 10.20 and later
|
||||
hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
|
||||
ac_cv_sys_largefile_source=1 ;;
|
||||
esac])
|
||||
AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES,
|
||||
ac_cv_sys_large_files,
|
||||
[Define for large files, on AIX-style hosts.],
|
||||
[case "$host_os" in
|
||||
# AIX 4.2 and later
|
||||
aix4.[2-9]* | aix4.1[0-9]* | aix[5-9].* | aix[1-9][0-9]*)
|
||||
ac_cv_sys_large_files=1 ;;
|
||||
esac])
|
||||
fi
|
||||
])
|
35
patch/m4/malloc.m4
Normal file
35
patch/m4/malloc.m4
Normal file
@ -0,0 +1,35 @@
|
||||
#serial 6
|
||||
|
||||
dnl From Jim Meyering.
|
||||
dnl Determine whether malloc accepts 0 as its argument.
|
||||
dnl If it doesn't, arrange to use the replacement function.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([jm_FUNC_MALLOC],
|
||||
[
|
||||
dnl xmalloc.c requires that this symbol be defined so it doesn't
|
||||
dnl mistakenly use a broken malloc -- as it might if this test were omitted.
|
||||
AC_DEFINE(HAVE_DONE_WORKING_MALLOC_CHECK, 1,
|
||||
[Define if the malloc check has been performed. ])
|
||||
|
||||
AC_CACHE_CHECK([whether malloc(0) returns a non-NULL pointer],
|
||||
jm_cv_func_working_malloc,
|
||||
[AC_TRY_RUN([
|
||||
char *malloc ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
exit (malloc (0) ? 0 : 1);
|
||||
}
|
||||
],
|
||||
jm_cv_func_working_malloc=yes,
|
||||
jm_cv_func_working_malloc=no,
|
||||
dnl When crosscompiling, assume malloc(0) returns NULL.
|
||||
jm_cv_func_working_malloc=no)
|
||||
])
|
||||
if test $jm_cv_func_working_malloc = no; then
|
||||
AC_LIBOBJ(malloc)
|
||||
AC_DEFINE(malloc, rpl_malloc,
|
||||
[Define to rpl_malloc if the replacement function should be used.])
|
||||
fi
|
||||
])
|
24
patch/m4/mbrtowc.m4
Normal file
24
patch/m4/mbrtowc.m4
Normal file
@ -0,0 +1,24 @@
|
||||
# mbrtowc.m4 serial 4 (fileutils-4.1.3)
|
||||
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
|
||||
|
||||
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
|
||||
])
|
38
patch/m4/mbstate_t.m4
Normal file
38
patch/m4/mbstate_t.m4
Normal file
@ -0,0 +1,38 @@
|
||||
# mbstate_t.m4 serial 9 (fileutils-4.1.3)
|
||||
dnl Copyright (C) 2000-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.
|
||||
|
||||
# Include stdlib.h first, because otherwise this test would fail on Linux
|
||||
# (at least glibc-2.1.3) because the "_XOPEN_SOURCE 500" definition elicits
|
||||
# a syntax error in wchar.h due to the use of undefined __int32_t.
|
||||
|
||||
AC_DEFUN([AC_MBSTATE_T],
|
||||
[
|
||||
AC_CHECK_HEADERS(stdlib.h)
|
||||
|
||||
AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
|
||||
[AC_TRY_COMPILE([
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#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,ma
|
||||
[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])
|
34
patch/m4/mkdir.m4
Normal file
34
patch/m4/mkdir.m4
Normal file
@ -0,0 +1,34 @@
|
||||
#serial 1
|
||||
|
||||
dnl From Mumit Khan and Paul Eggert
|
||||
dnl Determine whether mkdir accepts only one argument instead of the usual two.
|
||||
|
||||
AC_DEFUN([PATCH_FUNC_MKDIR_TAKES_ONE_ARG],
|
||||
[AC_CHECK_FUNCS(mkdir)
|
||||
AC_CACHE_CHECK([whether mkdir takes only one argument],
|
||||
patch_cv_mkdir_takes_one_arg,
|
||||
[patch_cv_mkdir_takes_one_arg=no
|
||||
if test $ac_cv_func_mkdir = yes; then
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
],
|
||||
[mkdir (".", 0);],
|
||||
,
|
||||
[AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
],
|
||||
[mkdir (".");],
|
||||
patch_cv_mkdir_takes_one_arg=yes
|
||||
)]
|
||||
)
|
||||
fi
|
||||
]
|
||||
)
|
||||
if test $patch_cv_mkdir_takes_one_arg = yes; then
|
||||
AC_DEFINE([MKDIR_TAKES_ONE_ARG], 1,
|
||||
[Define if mkdir takes only one argument.])
|
||||
fi
|
||||
]
|
||||
)
|
153
patch/m4/prereq.m4
Normal file
153
patch/m4/prereq.m4
Normal file
@ -0,0 +1,153 @@
|
||||
#serial 22
|
||||
|
||||
dnl These are the prerequisite macros for files in the lib/
|
||||
dnl directories of the fileutils, sh-utils, and textutils packages.
|
||||
|
||||
AC_DEFUN([jm_PREREQ],
|
||||
[
|
||||
jm_PREREQ_ADDEXT
|
||||
jm_PREREQ_CANON_HOST
|
||||
jm_PREREQ_DIRNAME
|
||||
jm_PREREQ_ERROR
|
||||
jm_PREREQ_EXCLUDE
|
||||
jm_PREREQ_GETPAGESIZE
|
||||
jm_PREREQ_HARD_LOCALE
|
||||
jm_PREREQ_HASH
|
||||
jm_PREREQ_HUMAN
|
||||
jm_PREREQ_MBSWIDTH
|
||||
jm_PREREQ_MEMCHR
|
||||
jm_PREREQ_PHYSMEM
|
||||
jm_PREREQ_POSIXVER
|
||||
jm_PREREQ_QUOTEARG
|
||||
jm_PREREQ_READUTMP
|
||||
jm_PREREQ_REGEX
|
||||
jm_PREREQ_TEMPNAME # called by mkstemp
|
||||
jm_PREREQ_XGETCWD
|
||||
jm_PREREQ_XREADLINK
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_ADDEXT],
|
||||
[
|
||||
dnl For addext.c.
|
||||
AC_SYS_LONG_FILE_NAMES
|
||||
AC_CHECK_FUNCS(pathconf)
|
||||
AC_CHECK_HEADERS(limits.h string.h unistd.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_CANON_HOST],
|
||||
[
|
||||
dnl Add any libraries as early as possible.
|
||||
dnl In particular, inet_ntoa needs -lnsl at least on Solaris5.5.1,
|
||||
dnl so we have to add -lnsl to LIBS before checking for that function.
|
||||
AC_SEARCH_LIBS(gethostbyname, [inet nsl])
|
||||
|
||||
dnl These come from -lnsl on Solaris5.5.1.
|
||||
AC_CHECK_FUNCS(gethostbyname gethostbyaddr inet_ntoa)
|
||||
|
||||
AC_CHECK_FUNCS(gethostbyname gethostbyaddr inet_ntoa)
|
||||
AC_CHECK_HEADERS(unistd.h string.h netdb.h sys/socket.h \
|
||||
netinet/in.h arpa/inet.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_DIRNAME],
|
||||
[
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(string.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_EXCLUDE],
|
||||
[
|
||||
AC_FUNC_FNMATCH_GNU([lib])
|
||||
AC_HEADER_STDBOOL
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_GETPAGESIZE],
|
||||
[
|
||||
AC_CHECK_FUNCS(getpagesize)
|
||||
AC_CHECK_HEADERS(OS.h unistd.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_HARD_LOCALE],
|
||||
[
|
||||
AC_C_PROTOTYPES
|
||||
AC_CHECK_FUNCS(setlocale)
|
||||
AC_CHECK_HEADERS(locale.h stdlib.h string.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_HASH],
|
||||
[
|
||||
AC_CHECK_HEADERS(stdlib.h)
|
||||
AC_HEADER_STDBOOL
|
||||
AC_REQUIRE([jm_CHECK_DECLS])
|
||||
])
|
||||
|
||||
# If you use human.c, you need the following files:
|
||||
# inttypes.m4 ulonglong.m4
|
||||
AC_DEFUN([jm_PREREQ_HUMAN],
|
||||
[
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h string.h)
|
||||
AC_CHECK_DECLS([getenv])
|
||||
AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_MEMCHR],
|
||||
[
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h bp-sym.h)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_PHYSMEM],
|
||||
[
|
||||
AC_CHECK_HEADERS(sys/pstat.h unistd.h)
|
||||
AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic)
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_POSIXVER],
|
||||
[
|
||||
AC_CHECK_HEADERS(unistd.h)
|
||||
AC_CHECK_DECLS([getenv])
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_QUOTEARG],
|
||||
[
|
||||
AC_CHECK_FUNCS(isascii iswprint)
|
||||
jm_FUNC_MBRTOWC
|
||||
AC_CHECK_HEADERS(limits.h stddef.h stdlib.h string.h wchar.h wctype.h)
|
||||
AC_HEADER_STDC
|
||||
AC_C_BACKSLASH_A
|
||||
AC_MBSTATE_T
|
||||
AC_C_PROTOTYPES
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_REGEX],
|
||||
[
|
||||
dnl FIXME: Maybe provide a btowc replacement someday: solaris-2.5.1 lacks it.
|
||||
dnl FIXME: Check for wctype and iswctype, and and add -lw if necessary
|
||||
dnl to get them.
|
||||
AC_CHECK_FUNCS(bzero bcopy isascii btowc)
|
||||
AC_CHECK_HEADERS(alloca.h libintl.h wctype.h wchar.h)
|
||||
AC_HEADER_STDC
|
||||
AC_FUNC_ALLOCA
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_TEMPNAME],
|
||||
[
|
||||
AC_HEADER_STDC
|
||||
AC_HEADER_STAT
|
||||
AC_CHECK_HEADERS(fcntl.h sys/time.h stdint.h unistd.h)
|
||||
AC_CHECK_FUNCS(__secure_getenv gettimeofday)
|
||||
AC_CHECK_DECLS([getenv])
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_XGETCWD],
|
||||
[
|
||||
AC_C_PROTOTYPES
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h sys/param.h unistd.h)
|
||||
AC_CHECK_FUNCS(getcwd)
|
||||
AC_FUNC_GETCWD_NULL
|
||||
])
|
||||
|
||||
AC_DEFUN([jm_PREREQ_XREADLINK],
|
||||
[
|
||||
AC_C_PROTOTYPES
|
||||
AC_CHECK_HEADERS(limits.h stdlib.h sys/types.h unistd.h)
|
||||
])
|
25
patch/m4/protos.m4
Normal file
25
patch/m4/protos.m4
Normal file
@ -0,0 +1,25 @@
|
||||
## ------------------------------- ##
|
||||
## Check for function prototypes. ##
|
||||
## From Franc,ois Pinard ##
|
||||
## ------------------------------- ##
|
||||
|
||||
# serial 1
|
||||
|
||||
AC_DEFUN(AM_C_PROTOTYPES,
|
||||
[AC_REQUIRE([AM_PROG_CC_STDC])
|
||||
AC_REQUIRE([AC_PROG_CPP])
|
||||
AC_MSG_CHECKING([for function prototypes])
|
||||
if test "$am_cv_prog_cc_stdc" != no; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(PROTOTYPES,1,[Define if compiler has function prototypes])
|
||||
U= ANSI2KNR=
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
U=_ ANSI2KNR=./ansi2knr
|
||||
# Ensure some checks needed by ansi2knr itself.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(string.h)
|
||||
fi
|
||||
AC_SUBST(U)dnl
|
||||
AC_SUBST(ANSI2KNR)dnl
|
||||
])
|
35
patch/m4/realloc.m4
Normal file
35
patch/m4/realloc.m4
Normal file
@ -0,0 +1,35 @@
|
||||
#serial 6
|
||||
|
||||
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.
|
||||
dnl
|
||||
|
||||
AC_DEFUN([jm_FUNC_REALLOC],
|
||||
[
|
||||
dnl xmalloc.c requires that this symbol be defined so it doesn't
|
||||
dnl mistakenly use a broken realloc -- as it might if this test were omitted.
|
||||
AC_DEFINE(HAVE_DONE_WORKING_REALLOC_CHECK, 1,
|
||||
[Define if the realloc check has been performed. ])
|
||||
|
||||
AC_CACHE_CHECK([whether realloc(0,0) returns a non-NULL pointer],
|
||||
jm_cv_func_working_realloc,
|
||||
[AC_TRY_RUN([
|
||||
char *realloc ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
exit (realloc (0, 0) ? 0 : 1);
|
||||
}
|
||||
],
|
||||
jm_cv_func_working_realloc=yes,
|
||||
jm_cv_func_working_realloc=no,
|
||||
dnl When crosscompiling, assume realloc(0,0) returns NULL.
|
||||
jm_cv_func_working_realloc=no)
|
||||
])
|
||||
if test $jm_cv_func_working_realloc = no; then
|
||||
AC_LIBOBJ(realloc)
|
||||
AC_DEFINE(realloc, rpl_realloc,
|
||||
[Define to rpl_realloc if the replacement function should be used.])
|
||||
fi
|
||||
])
|
38
patch/m4/setmode.m4
Normal file
38
patch/m4/setmode.m4
Normal file
@ -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])
|
40
patch/m4/utimbuf.m4
Normal file
40
patch/m4/utimbuf.m4
Normal file
@ -0,0 +1,40 @@
|
||||
#serial 4
|
||||
|
||||
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(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
|
||||
])
|
501
patch/maketime.c
Normal file
501
patch/maketime.c
Normal file
@ -0,0 +1,501 @@
|
||||
/* Convert struct partime into time_t. */
|
||||
|
||||
/* Copyright 1992, 1993, 1994, 1995, 1997 Paul Eggert
|
||||
Distributed under license by the Free Software Foundation, Inc.
|
||||
|
||||
This file is part of RCS.
|
||||
|
||||
RCS 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.
|
||||
|
||||
RCS 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 RCS; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Report problems and direct all questions to:
|
||||
|
||||
rcs-bugs@cs.purdue.edu
|
||||
|
||||
*/
|
||||
|
||||
/* For maximum portability, use only localtime and gmtime.
|
||||
Make no assumptions about the time_t epoch or the range of time_t values.
|
||||
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
|
||||
#endif
|
||||
|
||||
#include <partime.h>
|
||||
#include <maketime.h>
|
||||
|
||||
char const maket_id[] =
|
||||
"$Id: maketime.c,v 1.1.1.2 2000/05/06 22:44:53 wsanchez Exp $";
|
||||
|
||||
static int isleap P ((int));
|
||||
static int month_days P ((struct tm const *));
|
||||
static time_t maketime P ((struct partime const *, time_t));
|
||||
|
||||
/* 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.
|
||||
Then this yields nonzero if overflow occurred during the addition.
|
||||
Overflow occurs if A and B have the same sign, but A and SUM differ in sign.
|
||||
Use `^' to test whether signs differ, and `< 0' to isolate the sign. */
|
||||
#define overflow_sum_sign(a, b, sum) ((~((a) ^ (b)) & ((a) ^ (sum))) < 0)
|
||||
|
||||
/* Quotient and remainder when dividing A by B,
|
||||
truncating towards minus infinity, where B is positive. */
|
||||
#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
|
||||
#define MOD(a, b) ((a) % (b) + (b) * ((a) % (b) < 0))
|
||||
|
||||
/* Number of days in 400 consecutive Gregorian years. */
|
||||
#define Y400_DAYS (365 * 400L + 100 - 4 + 1)
|
||||
|
||||
/* Number of years to add to tm_year to get Gregorian year. */
|
||||
#define TM_YEAR_ORIGIN 1900
|
||||
|
||||
static int
|
||||
isleap (y)
|
||||
int y;
|
||||
{
|
||||
return (y & 3) == 0 && (y % 100 != 0 || y % 400 == 0);
|
||||
}
|
||||
|
||||
/* days in year before start of months 0-12 */
|
||||
static int const month_yday[] =
|
||||
{
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
|
||||
};
|
||||
|
||||
/* Yield the number of days in TM's month. */
|
||||
static int
|
||||
month_days (tm)
|
||||
struct tm const *tm;
|
||||
{
|
||||
int m = tm->tm_mon;
|
||||
return (month_yday[m + 1] - month_yday[m]
|
||||
+ (m == 1 && isleap (tm->tm_year + TM_YEAR_ORIGIN)));
|
||||
}
|
||||
|
||||
/* 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;
|
||||
{
|
||||
struct tm *tm;
|
||||
#ifdef TZ_is_unset
|
||||
static char const *TZ;
|
||||
if (!TZ && !(TZ = getenv ("TZ")))
|
||||
TZ_is_unset ("The TZ environment variable is not set; please set it to your timezone");
|
||||
#endif
|
||||
if (localzone || !(tm = gmtime (&unixtime)))
|
||||
tm = localtime (&unixtime);
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* Yield A - B, measured in seconds. */
|
||||
time_t
|
||||
difftm (a, b)
|
||||
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);
|
||||
int ac = DIV (ay, 100);
|
||||
int bc = DIV (by, 100);
|
||||
int difference_in_day_of_year = a->tm_yday - b->tm_yday;
|
||||
int intervening_leap_days = (((ay >> 2) - (by >> 2))
|
||||
- (ac - bc)
|
||||
+ ((ac >> 2) - (bc >> 2)));
|
||||
time_t difference_in_years = ay - by;
|
||||
time_t difference_in_days
|
||||
= (difference_in_years * 365
|
||||
+ (intervening_leap_days + difference_in_day_of_year));
|
||||
return (((((difference_in_days * 24
|
||||
+ (a->tm_hour - b->tm_hour))
|
||||
* 60)
|
||||
+ (a->tm_min - b->tm_min))
|
||||
* 60)
|
||||
+ (a->tm_sec - b->tm_sec));
|
||||
}
|
||||
|
||||
/* Adjust time T by adding SECONDS.
|
||||
The absolute value of SECONDS cannot exceed 59 * INT_MAX,
|
||||
and also cannot exceed one month's worth of seconds;
|
||||
this is enough to handle any POSIX or real-life daylight-saving offset.
|
||||
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;
|
||||
{
|
||||
int days = 0;
|
||||
|
||||
/* This code can be off by a second if SECONDS is not a multiple of 60,
|
||||
if T is local time, and if a leap second happens during this minute.
|
||||
But this bug has never occurred, and most likely will not ever occur.
|
||||
Liberia, the last country for which SECONDS % 60 was nonzero,
|
||||
switched to UTC in May 1972; the first leap second was in June 1972. */
|
||||
int leap_second = t->tm_sec == 60;
|
||||
long sec = seconds + (t->tm_sec - leap_second);
|
||||
if (sec < 0)
|
||||
{
|
||||
if ((t->tm_min -= (59 - sec) / 60) < 0
|
||||
&& (t->tm_hour -= (59 - t->tm_min) / 60) < 0)
|
||||
{
|
||||
days = - ((23 - t->tm_hour) / 24);
|
||||
if ((t->tm_mday += days) <= 0)
|
||||
{
|
||||
if (--t->tm_mon < 0)
|
||||
{
|
||||
--t->tm_year;
|
||||
t->tm_mon = 11;
|
||||
}
|
||||
t->tm_mday += month_days (t);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (60 <= (t->tm_min += sec / 60)
|
||||
&& (24 <= (t->tm_hour += t->tm_min / 60)))
|
||||
{
|
||||
days = t->tm_hour / 24;
|
||||
if (month_days (t) < (t->tm_mday += days))
|
||||
{
|
||||
if (11 < ++t->tm_mon)
|
||||
{
|
||||
++t->tm_year;
|
||||
t->tm_mon = 0;
|
||||
}
|
||||
t->tm_mday = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (TM_DEFINED (t->tm_wday))
|
||||
t->tm_wday = MOD (t->tm_wday + days, 7);
|
||||
t->tm_hour = MOD (t->tm_hour, 24);
|
||||
t->tm_min = MOD (t->tm_min, 60);
|
||||
t->tm_sec = (int) MOD (sec, 60) + leap_second;
|
||||
}
|
||||
|
||||
/* Convert TM to time_t, using localtime if LOCALZONE and gmtime otherwise.
|
||||
Use only TM's year, mon, mday, hour, min, and sec members.
|
||||
Ignore TM's old tm_yday and tm_wday, but fill in their correct values.
|
||||
Yield -1 on failure (e.g. a member out of range).
|
||||
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;
|
||||
{
|
||||
/* Cache the most recent t,tm pairs; 1 for gmtime, 1 for localtime. */
|
||||
static time_t t_cache[2];
|
||||
static struct tm tm_cache[2];
|
||||
|
||||
time_t d, gt;
|
||||
struct tm const *gtm;
|
||||
/* The maximum number of iterations should be enough to handle any
|
||||
combinations of leap seconds, time zone rule changes, and solar time.
|
||||
4 is probably enough; we use a bigger number just to be safe. */
|
||||
int remaining_tries = 8;
|
||||
|
||||
/* Avoid subscript errors. */
|
||||
if (12 <= (unsigned) tm->tm_mon)
|
||||
return -1;
|
||||
|
||||
tm->tm_yday = month_yday[tm->tm_mon] + tm->tm_mday
|
||||
- (tm->tm_mon < 2 || !isleap (tm->tm_year + TM_YEAR_ORIGIN));
|
||||
|
||||
/* Make a first guess. */
|
||||
gt = t_cache[localzone];
|
||||
gtm = gt ? &tm_cache[localzone] : time2tm (gt, localzone);
|
||||
|
||||
/* Repeatedly use the error from the guess to improve the guess. */
|
||||
while ((d = difftm (tm, gtm)) != 0)
|
||||
{
|
||||
if (--remaining_tries == 0)
|
||||
return -1;
|
||||
gt += d;
|
||||
gtm = time2tm (gt, localzone);
|
||||
}
|
||||
|
||||
/* Check that the guess actually matches;
|
||||
overflow can cause difftm to yield 0 even on differing times,
|
||||
or tm may have members out of range (e.g. bad leap seconds). */
|
||||
#define TM_DIFFER(a,b) \
|
||||
( \
|
||||
((a)->tm_year ^ (b)->tm_year) | \
|
||||
((a)->tm_mon ^ (b)->tm_mon) | \
|
||||
((a)->tm_mday ^ (b)->tm_mday) | \
|
||||
((a)->tm_hour ^ (b)->tm_hour) | \
|
||||
((a)->tm_min ^ (b)->tm_min) | \
|
||||
((a)->tm_sec ^ (b)->tm_sec) \
|
||||
)
|
||||
if (TM_DIFFER (tm, gtm))
|
||||
{
|
||||
/* If gt is a leap second, try gt+1; if it is one greater than
|
||||
a leap second, try gt-1; otherwise, it doesn't matter.
|
||||
Leap seconds always fall at month end. */
|
||||
int yd = tm->tm_year - gtm->tm_year;
|
||||
gt += yd + (yd ? 0 : tm->tm_mon - gtm->tm_mon);
|
||||
gtm = time2tm (gt, localzone);
|
||||
if (TM_DIFFER (tm, gtm))
|
||||
return -1;
|
||||
}
|
||||
t_cache[localzone] = gt;
|
||||
tm_cache[localzone] = *gtm;
|
||||
|
||||
tm->tm_wday = gtm->tm_wday;
|
||||
return gt;
|
||||
}
|
||||
|
||||
/* Check *PT and convert it to time_t.
|
||||
If it is incompletely specified, use DEFAULT_TIME to fill it out.
|
||||
Use localtime if PT->zone is the special value TM_LOCAL_ZONE.
|
||||
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;
|
||||
{
|
||||
int localzone, wday, year;
|
||||
struct tm tm;
|
||||
struct tm *tm0 = 0;
|
||||
time_t r;
|
||||
int use_ordinal_day;
|
||||
|
||||
tm0 = 0; /* Keep gcc -Wall happy. */
|
||||
localzone = pt->zone == TM_LOCAL_ZONE;
|
||||
|
||||
tm = pt->tm;
|
||||
year = tm.tm_year;
|
||||
wday = tm.tm_wday;
|
||||
use_ordinal_day = (!TM_DEFINED (tm.tm_mday)
|
||||
&& TM_DEFINED (wday) && TM_DEFINED (pt->wday_ordinal));
|
||||
|
||||
if (use_ordinal_day || TM_DEFINED (pt->ymodulus) || !TM_DEFINED (year))
|
||||
{
|
||||
/* Get tm corresponding to default time. */
|
||||
tm0 = time2tm (default_time, localzone);
|
||||
if (!localzone)
|
||||
adjzone (tm0, pt->zone);
|
||||
}
|
||||
|
||||
if (use_ordinal_day)
|
||||
tm.tm_mday = (tm0->tm_mday
|
||||
+ ((wday - tm0->tm_wday + 7) % 7
|
||||
+ 7 * (pt->wday_ordinal - (pt->wday_ordinal != 0))));
|
||||
|
||||
if (TM_DEFINED (pt->ymodulus))
|
||||
{
|
||||
/* Yield a year closest to the default that has the given modulus. */
|
||||
int year0 = tm0->tm_year + TM_YEAR_ORIGIN;
|
||||
int y0 = MOD (year0, pt->ymodulus);
|
||||
int d = 2 * (year - y0);
|
||||
year += (((year0 - y0) / pt->ymodulus
|
||||
+ (pt->ymodulus < d ? -1 : d < -pt->ymodulus))
|
||||
* pt->ymodulus);
|
||||
}
|
||||
else if (!TM_DEFINED (year))
|
||||
{
|
||||
/* Set default year, month, day from current time. */
|
||||
year = tm0->tm_year + TM_YEAR_ORIGIN;
|
||||
if (!TM_DEFINED (tm.tm_mon))
|
||||
{
|
||||
tm.tm_mon = tm0->tm_mon;
|
||||
if (!TM_DEFINED (tm.tm_mday))
|
||||
tm.tm_mday = tm0->tm_mday;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set remaining default fields to be their minimum values. */
|
||||
if (!TM_DEFINED (tm.tm_mon))
|
||||
tm.tm_mon = 0;
|
||||
if (!TM_DEFINED (tm.tm_mday))
|
||||
tm.tm_mday = 1;
|
||||
if (!TM_DEFINED (tm.tm_hour))
|
||||
tm.tm_hour = 0;
|
||||
if (!TM_DEFINED (tm.tm_min))
|
||||
tm.tm_min = 0;
|
||||
if (!TM_DEFINED (tm.tm_sec))
|
||||
tm.tm_sec = 0;
|
||||
|
||||
tm.tm_year = year - TM_YEAR_ORIGIN;
|
||||
if ((year < tm.tm_year) != (TM_YEAR_ORIGIN < 0))
|
||||
return -1;
|
||||
|
||||
if (!localzone)
|
||||
{
|
||||
adjzone (&tm, -pt->zone);
|
||||
wday = tm.tm_wday;
|
||||
}
|
||||
|
||||
/* Convert and fill in the rest of the tm. */
|
||||
r = tm2time (&tm, localzone);
|
||||
if (r == -1)
|
||||
return r;
|
||||
|
||||
/* Check weekday. */
|
||||
if (TM_DEFINED (wday) && wday != tm.tm_wday)
|
||||
return -1;
|
||||
|
||||
/* Add relative time, except for seconds.
|
||||
We handle seconds separately, at the end,
|
||||
so that leap seconds are handled properly. */
|
||||
if (pt->tmr.tm_year | pt->tmr.tm_mon | pt->tmr.tm_mday
|
||||
| pt->tmr.tm_hour | pt->tmr.tm_min)
|
||||
{
|
||||
int years = tm.tm_year + pt->tmr.tm_year;
|
||||
int mons = tm.tm_mon + pt->tmr.tm_mon;
|
||||
int mdays = tm.tm_mday + pt->tmr.tm_mday;
|
||||
int hours = tm.tm_hour + pt->tmr.tm_hour;
|
||||
int mins = tm.tm_min + pt->tmr.tm_min;
|
||||
|
||||
int carried_hours = DIV (mins, 60);
|
||||
int hours1 = hours + carried_hours;
|
||||
int carried_days = DIV (hours1, 24);
|
||||
int mdays1 = mdays + carried_days;
|
||||
|
||||
int mon0 = MOD (mons, 12);
|
||||
int carried_years0 = DIV (mons, 12);
|
||||
int year0 = years + carried_years0;
|
||||
int yday0 = (month_yday[mon0]
|
||||
- (mon0 < 2 || !isleap (year0 + TM_YEAR_ORIGIN)));
|
||||
|
||||
int yday1 = yday0 + mdays1;
|
||||
int carried_years1 = DIV (yday1, Y400_DAYS) * 400;
|
||||
int year1 = year0 + carried_years1;
|
||||
int yday2 = MOD (yday1, Y400_DAYS);
|
||||
int leap;
|
||||
|
||||
if (overflow_sum_sign (tm.tm_year, pt->tmr.tm_year, years)
|
||||
| overflow_sum_sign (tm.tm_mon, pt->tmr.tm_mon, mons)
|
||||
| overflow_sum_sign (tm.tm_mday, pt->tmr.tm_mday, mdays)
|
||||
| overflow_sum_sign (tm.tm_hour, pt->tmr.tm_hour, hours)
|
||||
| overflow_sum_sign (tm.tm_min, pt->tmr.tm_min, mins)
|
||||
| overflow_sum_sign (hours, carried_hours, hours1)
|
||||
| overflow_sum_sign (mdays, carried_days, mdays1)
|
||||
| overflow_sum_sign (years, carried_years0, year0)
|
||||
| overflow_sum_sign (yday0, mdays1, yday1)
|
||||
| overflow_sum_sign (year0, carried_years1, year1))
|
||||
return -1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int days_per_year = 365 + (leap = isleap (year1 + TM_YEAR_ORIGIN));
|
||||
if (yday2 < days_per_year)
|
||||
break;
|
||||
yday2 -= days_per_year;
|
||||
year1++;
|
||||
}
|
||||
|
||||
tm.tm_year = year1;
|
||||
|
||||
{
|
||||
int mon;
|
||||
for (mon = 11;
|
||||
(tm.tm_mday = (yday2 - month_yday[mon] + (mon < 2 || !leap))) <= 0;
|
||||
mon--)
|
||||
continue;
|
||||
tm.tm_mon = mon;
|
||||
}
|
||||
|
||||
tm.tm_hour = MOD (hours1, 24);
|
||||
tm.tm_min = MOD (mins, 60);
|
||||
|
||||
r = tm2time (&tm, localzone);
|
||||
if (r == -1)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Add the seconds' part of relative time. */
|
||||
{
|
||||
time_t rs = r + pt->tmr.tm_sec;
|
||||
if ((pt->tmr.tm_sec < 0) != (rs < r))
|
||||
return -1;
|
||||
return rs;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse a free-format date in *SOURCE, yielding a Unix format time.
|
||||
Update *SOURCE to point to the first character after the date.
|
||||
If *SOURCE is missing some information, take defaults from
|
||||
DEFAULT_TIME and DEFAULT_ZONE. *SOURCE may even be the empty
|
||||
string or an immediately invalid string, in which case the default
|
||||
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;
|
||||
{
|
||||
struct partime pt;
|
||||
|
||||
*source = partime (*source, &pt);
|
||||
if (pt.zone == TM_UNDEFINED_ZONE)
|
||||
pt.zone = default_zone;
|
||||
return maketime (&pt, default_time);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
time_t default_time = time ((time_t *) 0);
|
||||
long default_zone = argv[1] ? atol (argv[1]) : TM_LOCAL_ZONE;
|
||||
char buf[1000];
|
||||
while (fgets (buf, sizeof (buf), stdin))
|
||||
{
|
||||
char const *p = buf;
|
||||
time_t t = str2time (&p, default_time, default_zone);
|
||||
printf ("`%.*s' -> %s",
|
||||
(int) (p - buf - (p[0] == '\0' && p[-1] == '\n')), buf,
|
||||
asctime ((argv[1] ? gmtime : localtime) (&t)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
39
patch/maketime.h
Normal file
39
patch/maketime.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* Yield time_t from struct partime yielded by partime. */
|
||||
|
||||
/* Copyright 1993, 1994, 1995 Paul Eggert
|
||||
Distributed under license by the Free Software Foundation, Inc.
|
||||
|
||||
This file is part of RCS.
|
||||
|
||||
RCS 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.
|
||||
|
||||
RCS 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 RCS; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Report problems and direct all questions to:
|
||||
|
||||
rcs-bugs@cs.purdue.edu
|
||||
|
||||
*/
|
||||
|
||||
#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));
|
38
patch/malloc.c
Normal file
38
patch/malloc.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* Work around bug on some systems where malloc (0) fails.
|
||||
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
|
||||
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 */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#undef malloc
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
char *malloc ();
|
||||
|
||||
/* Allocate an N-byte block of memory from the heap.
|
||||
If N is zero, allocate a 1-byte block. */
|
||||
|
||||
char *
|
||||
rpl_malloc (size_t n)
|
||||
{
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
return malloc (n);
|
||||
}
|
216
patch/memchr.c
Normal file
216
patch/memchr.c
Normal file
@ -0,0 +1,216 @@
|
||||
/* Copyright (C) 1991,93,96,97,99,2000 Free Software Foundation, Inc.
|
||||
Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
|
||||
with help from Dan Sahlin (dan@sics.se) and
|
||||
commentary by Jim Blandy (jimb@ai.mit.edu);
|
||||
adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
|
||||
and implemented by Roland McGrath (roland@ai.mit.edu).
|
||||
|
||||
NOTE: The canonical source of this file is maintained with the GNU C Library.
|
||||
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#undef __ptr_t
|
||||
#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
|
||||
# define __ptr_t void *
|
||||
#else /* Not C++ or ANSI C. */
|
||||
# define __ptr_t char *
|
||||
#endif /* C++ or ANSI C. */
|
||||
|
||||
#if defined _LIBC
|
||||
# include <string.h>
|
||||
# include <memcopy.h>
|
||||
#else
|
||||
# define reg_char char
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H || defined _LIBC
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_LIMITS_H || defined _LIBC
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#define LONG_MAX_32_BITS 2147483647
|
||||
|
||||
#ifndef LONG_MAX
|
||||
# define LONG_MAX LONG_MAX_32_BITS
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#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. */
|
||||
__ptr_t
|
||||
__memchr (s, c_in, n)
|
||||
const __ptr_t 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 (__ptr_t) char_ptr;
|
||||
|
||||
/* All these elucidatory comments refer to 4-byte longwords,
|
||||
but the theory applies equally well to 8-byte longwords. */
|
||||
|
||||
longword_ptr = (unsigned long int *) char_ptr;
|
||||
|
||||
/* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
|
||||
the "holes." Note that there is a hole just to the left of
|
||||
each byte, with an extra at the end:
|
||||
|
||||
bits: 01111110 11111110 11111110 11111111
|
||||
bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
|
||||
|
||||
The 1-bits make sure that carries propagate to the next 0-bit.
|
||||
The 0-bits provide holes for carries to fall into. */
|
||||
|
||||
if (sizeof (longword) != 4 && sizeof (longword) != 8)
|
||||
abort ();
|
||||
|
||||
#if LONG_MAX <= LONG_MAX_32_BITS
|
||||
magic_bits = 0x7efefeff;
|
||||
#else
|
||||
magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff;
|
||||
#endif
|
||||
|
||||
/* Set up a longword, each of whose bytes is C. */
|
||||
charmask = c | (c << 8);
|
||||
charmask |= charmask << 16;
|
||||
#if LONG_MAX > LONG_MAX_32_BITS
|
||||
charmask |= charmask << 32;
|
||||
#endif
|
||||
|
||||
/* Instead of the traditional loop which tests each character,
|
||||
we will test a longword at a time. The tricky part is testing
|
||||
if *any of the four* bytes in the longword in question are zero. */
|
||||
while (n >= sizeof (longword))
|
||||
{
|
||||
/* We tentatively exit the loop if adding MAGIC_BITS to
|
||||
LONGWORD fails to change any of the hole bits of LONGWORD.
|
||||
|
||||
1) Is this safe? Will it catch all the zero bytes?
|
||||
Suppose there is a byte with all zeros. Any carry bits
|
||||
propagating from its left will fall into the hole at its
|
||||
least significant bit and stop. Since there will be no
|
||||
carry from its most significant bit, the LSB of the
|
||||
byte to the left will be unchanged, and the zero will be
|
||||
detected.
|
||||
|
||||
2) Is this worthwhile? Will it ignore everything except
|
||||
zero bytes? Suppose every byte of LONGWORD has a bit set
|
||||
somewhere. There will be a carry into bit 8. If bit 8
|
||||
is set, this will carry into bit 16. If bit 8 is clear,
|
||||
one of bits 9-15 must be set, so there will be a carry
|
||||
into bit 16. Similarly, there will be a carry into bit
|
||||
24. If one of bits 24-30 is set, there will be a carry
|
||||
into bit 31, so all of the hole bits will be changed.
|
||||
|
||||
The one misfire occurs when bits 24-30 are clear and bit
|
||||
31 is set; in this case, the hole at bit 31 is not
|
||||
changed. If we had access to the processor carry flag,
|
||||
we could close this loophole by putting the fourth hole
|
||||
at bit 32!
|
||||
|
||||
So it ignores everything except 128's, when they're aligned
|
||||
properly.
|
||||
|
||||
3) But wait! Aren't we looking for C, not zero?
|
||||
Good point. So what we do is XOR LONGWORD with a longword,
|
||||
each of whose bytes is C. This turns each byte that is C
|
||||
into a zero. */
|
||||
|
||||
longword = *longword_ptr++ ^ charmask;
|
||||
|
||||
/* Add MAGIC_BITS to LONGWORD. */
|
||||
if ((((longword + magic_bits)
|
||||
|
||||
/* Set those bits that were unchanged by the addition. */
|
||||
^ ~longword)
|
||||
|
||||
/* Look at only the hole bits. If any of the hole bits
|
||||
are unchanged, most likely one of the bytes was a
|
||||
zero. */
|
||||
& ~magic_bits) != 0)
|
||||
{
|
||||
/* Which of the bytes was C? If none of them were, it was
|
||||
a misfire; continue the search. */
|
||||
|
||||
const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);
|
||||
|
||||
if (cp[0] == c)
|
||||
return (__ptr_t) cp;
|
||||
if (cp[1] == c)
|
||||
return (__ptr_t) &cp[1];
|
||||
if (cp[2] == c)
|
||||
return (__ptr_t) &cp[2];
|
||||
if (cp[3] == c)
|
||||
return (__ptr_t) &cp[3];
|
||||
#if LONG_MAX > 2147483647
|
||||
if (cp[4] == c)
|
||||
return (__ptr_t) &cp[4];
|
||||
if (cp[5] == c)
|
||||
return (__ptr_t) &cp[5];
|
||||
if (cp[6] == c)
|
||||
return (__ptr_t) &cp[6];
|
||||
if (cp[7] == c)
|
||||
return (__ptr_t) &cp[7];
|
||||
#endif
|
||||
}
|
||||
|
||||
n -= sizeof (longword);
|
||||
}
|
||||
|
||||
char_ptr = (const unsigned char *) longword_ptr;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*char_ptr == c)
|
||||
return (__ptr_t) char_ptr;
|
||||
else
|
||||
++char_ptr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#ifdef weak_alias
|
||||
weak_alias (__memchr, BP_SYM (memchr))
|
||||
#endif
|
76
patch/mkdir.c
Normal file
76
patch/mkdir.c
Normal file
@ -0,0 +1,76 @@
|
||||
/* On some systems, mkdir ("foo/", 0700) fails because of the trailing
|
||||
slash. On those systems, this wrapper removes the trailing slash.
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* written by Jim Meyering */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Disable the definition of mkdir to rpl_mkdir (from config.h) in this
|
||||
file. Otherwise, we'd get conflicting prototypes for rpl_mkdir on
|
||||
most systems. */
|
||||
#undef mkdir
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "dirname.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef HAVE_DECL_FREE
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
#if !HAVE_DECL_FREE
|
||||
void free ();
|
||||
#endif
|
||||
|
||||
/* This function is required at least for NetBSD 1.5.2. */
|
||||
|
||||
int
|
||||
rpl_mkdir (char const *dir, mode_t mode)
|
||||
{
|
||||
int ret_val;
|
||||
char *tmp_dir;
|
||||
size_t len = strlen (dir);
|
||||
|
||||
if (len && dir[len - 1] == '/')
|
||||
{
|
||||
tmp_dir = xstrdup (dir);
|
||||
strip_trailing_slashes (tmp_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_dir = (char *) dir;
|
||||
}
|
||||
|
||||
ret_val = mkdir (tmp_dir, mode);
|
||||
|
||||
if (tmp_dir != dir)
|
||||
free (tmp_dir);
|
||||
|
||||
return ret_val;
|
||||
}
|
101
patch/mkinstalldirs
Executable file
101
patch/mkinstalldirs
Executable file
@ -0,0 +1,101 @@
|
||||
#! /bin/sh
|
||||
# mkinstalldirs --- make directory hierarchy
|
||||
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
|
||||
# Created: 1993-05-16
|
||||
# Public domain
|
||||
|
||||
# $Id: mkinstalldirs,v 1.1.1.3 2003/05/08 18:38:03 rbraun Exp $
|
||||
|
||||
errstatus=0
|
||||
dirmode=""
|
||||
|
||||
usage="\
|
||||
Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
|
||||
|
||||
# process command line arguments
|
||||
while test $# -gt 0 ; do
|
||||
case "${1}" in
|
||||
-h | --help | --h* ) # -h for help
|
||||
echo "${usage}" 1>&2; exit 0 ;;
|
||||
-m ) # -m PERM arg
|
||||
shift
|
||||
test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
|
||||
dirmode="${1}"
|
||||
shift ;;
|
||||
-- ) shift; break ;; # stop option processing
|
||||
-* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option
|
||||
* ) break ;; # first non-opt arg
|
||||
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: 3
|
||||
# End:
|
||||
# mkinstalldirs ends here
|
956
patch/partime.c
Normal file
956
patch/partime.c
Normal file
@ -0,0 +1,956 @@
|
||||
/* Parse a string, yielding a struct partime that describes it. */
|
||||
|
||||
/* Copyright (C) 1993, 1994, 1995, 1997, 2002 Paul Eggert
|
||||
Distributed under license by the Free Software Foundation, Inc.
|
||||
|
||||
This file is part of RCS.
|
||||
|
||||
RCS 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.
|
||||
|
||||
RCS 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 RCS; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Report problems and direct all questions to:
|
||||
|
||||
rcs-bugs@cs.purdue.edu
|
||||
|
||||
*/
|
||||
|
||||
#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
|
||||
#endif
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(aggregate, member) ((size_t) &((aggregate *) 0)->member)
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#if STDC_HEADERS
|
||||
# define CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define CTYPE_DOMAIN(c) ((unsigned) (c) <= 0177)
|
||||
#endif
|
||||
#define ISALNUM(c) (CTYPE_DOMAIN (c) && isalnum (c))
|
||||
#define ISALPHA(c) (CTYPE_DOMAIN (c) && isalpha (c))
|
||||
#define ISSPACE(c) (CTYPE_DOMAIN (c) && isspace (c))
|
||||
#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.1.1.3 2003/05/08 18:38:03 rbraun Exp $";
|
||||
|
||||
|
||||
/* Lookup tables for names of months, weekdays, time zones. */
|
||||
|
||||
#define NAME_LENGTH_MAXIMUM 4
|
||||
|
||||
struct name_val
|
||||
{
|
||||
char name[NAME_LENGTH_MAXIMUM];
|
||||
int 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 struct name_val const month_names[] =
|
||||
{
|
||||
{"jan", 0},
|
||||
{"feb", 1},
|
||||
{"mar", 2},
|
||||
{"apr", 3},
|
||||
{"may", 4},
|
||||
{"jun", 5},
|
||||
{"jul", 6},
|
||||
{"aug", 7},
|
||||
{"sep", 8},
|
||||
{"oct", 9},
|
||||
{"nov", 10},
|
||||
{"dec", 11},
|
||||
{"", TM_UNDEFINED}
|
||||
};
|
||||
|
||||
static struct name_val const weekday_names[] =
|
||||
{
|
||||
{"sun", 0},
|
||||
{"mon", 1},
|
||||
{"tue", 2},
|
||||
{"wed", 3},
|
||||
{"thu", 4},
|
||||
{"fri", 5},
|
||||
{"sat", 6},
|
||||
{"", TM_UNDEFINED}
|
||||
};
|
||||
|
||||
#define RELATIVE_CONS(member, multiplier) \
|
||||
(offsetof (struct tm, member) + (multiplier) * sizeof (struct tm))
|
||||
#define RELATIVE_OFFSET(c) ((c) % sizeof (struct tm))
|
||||
#define RELATIVE_MULTIPLIER(c) ((c) / sizeof (struct tm))
|
||||
static struct name_val const relative_units[] =
|
||||
{
|
||||
{"year", RELATIVE_CONS (tm_year, 1) },
|
||||
{"mont", RELATIVE_CONS (tm_mon , 1) },
|
||||
{"fort", RELATIVE_CONS (tm_mday, 14) },
|
||||
{"week", RELATIVE_CONS (tm_mday, 7) },
|
||||
{"day" , RELATIVE_CONS (tm_mday, 1) },
|
||||
{"hour", RELATIVE_CONS (tm_hour, 1) },
|
||||
{"min" , RELATIVE_CONS (tm_min , 1) },
|
||||
{"sec" , RELATIVE_CONS (tm_sec , 1) },
|
||||
{"", TM_UNDEFINED}
|
||||
};
|
||||
|
||||
static struct name_val const ago[] =
|
||||
{
|
||||
{"ago", 0},
|
||||
{"", TM_UNDEFINED}
|
||||
};
|
||||
|
||||
static struct name_val const dst_names[] =
|
||||
{
|
||||
{"dst", 1},
|
||||
{"", 0}
|
||||
};
|
||||
|
||||
#define hr60nonnegative(t) ((t)/100 * 60 + (t)%100)
|
||||
#define hr60(t) ((t) < 0 ? - hr60nonnegative (-(t)) : hr60nonnegative (t))
|
||||
#define zs(t, s) {s, hr60 (t)}
|
||||
#define zd(t, s, d) zs (t, s), zs ((t) + 100, d)
|
||||
|
||||
static struct name_val const zone_names[] =
|
||||
{
|
||||
zs (-1000, "hst"), /* Hawaii */
|
||||
zd (-1000, "hast", "hadt"), /* Hawaii-Aleutian */
|
||||
zd (- 900, "akst", "akdt"), /* Alaska */
|
||||
zd (- 800, "pst" , "pdt" ), /* Pacific */
|
||||
zd (- 700, "mst" , "mdt" ), /* Mountain */
|
||||
zd (- 600, "cst" , "cdt" ), /* Central */
|
||||
zd (- 500, "est" , "edt" ), /* Eastern */
|
||||
zd (- 400, "ast" , "adt" ), /* Atlantic */
|
||||
zd (- 330, "nst" , "ndt" ), /* Newfoundland */
|
||||
zs ( 000, "utc" ), /* Coordinated Universal */
|
||||
zs ( 000, "uct" ), /* " */
|
||||
zs ( 000, "cut" ), /* " */
|
||||
zs ( 000, "ut"), /* Universal */
|
||||
zs ( 000, "z"), /* Zulu (required by ISO 8601) */
|
||||
zd ( 000, "gmt" , "bst" ), /* Greenwich Mean, British Summer */
|
||||
zd ( 000, "wet" , "west"), /* Western European */
|
||||
zd ( 100, "cet" , "cest"), /* Central European */
|
||||
zd ( 100, "met" , "mest"), /* Middle European (bug in old tz versions) */
|
||||
zd ( 100, "mez" , "mesz"), /* Mittel-Europaeische Zeit */
|
||||
zd ( 200, "eet" , "eest"), /* Eastern European */
|
||||
zs ( 530, "ist" ), /* India */
|
||||
zd ( 900, "jst" , "jdt" ), /* Japan */
|
||||
zd ( 900, "kst" , "kdt" ), /* Korea */
|
||||
zd ( 1200, "nzst", "nzdt"), /* New Zealand */
|
||||
{"lt", 1},
|
||||
#if 0
|
||||
/* The following names are duplicates or are not well attested.
|
||||
It's not worth keeping a complete list, since alphabetic time zone names
|
||||
are deprecated and there are lots more where these came from. */
|
||||
zs (-1100, "sst" ), /* Samoan */
|
||||
zd (- 900, "yst" , "ydt" ), /* Yukon - name is no longer used */
|
||||
zd (- 500, "ast" , "adt" ), /* Acre */
|
||||
zd (- 400, "wst" , "wdt" ), /* Western Brazil */
|
||||
zd (- 400, "cst" , "cdt" ), /* Chile */
|
||||
zd (- 200, "fst" , "fdt" ), /* Fernando de Noronha */
|
||||
zs ( 000, "wat" ), /* West African */
|
||||
zs ( 100, "cat" ), /* Central African */
|
||||
zs ( 200, "sat" ), /* South African */
|
||||
zd ( 200, "ist" , "idt" ), /* Israel */
|
||||
zs ( 300, "eat" ), /* East African */
|
||||
zd ( 300, "msk" , "msd" ), /* Moscow */
|
||||
zd ( 330, "ist" , "idt" ), /* Iran */
|
||||
zs ( 800, "hkt" ), /* Hong Kong */
|
||||
zs ( 800, "sgt" ), /* Singapore */
|
||||
zd ( 800, "cst" , "cdt" ), /* China */
|
||||
zd ( 800, "wst" , "wst" ), /* Western Australia */
|
||||
zd ( 930, "cst" , "cst" ), /* Central Australia */
|
||||
zs ( 1000, "gst" ), /* Guam */
|
||||
zd ( 1000, "est" , "est" ), /* Eastern Australia */
|
||||
#endif
|
||||
{"", -1}
|
||||
};
|
||||
|
||||
/* 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[];
|
||||
{
|
||||
int j;
|
||||
char buf[NAME_LENGTH_MAXIMUM];
|
||||
|
||||
for (j = 0; j < NAME_LENGTH_MAXIMUM; j++)
|
||||
{
|
||||
unsigned char c = *s;
|
||||
if (! ISALPHA (c))
|
||||
{
|
||||
buf[j] = '\0';
|
||||
break;
|
||||
}
|
||||
buf[j] = ISUPPER (c) ? tolower (c) : c;
|
||||
s++;
|
||||
s += *s == '.';
|
||||
}
|
||||
|
||||
for (;; table++)
|
||||
for (j = 0; ; j++)
|
||||
if (j == NAME_LENGTH_MAXIMUM || ! table[0].name[j])
|
||||
return table[0].val;
|
||||
else if (buf[j] != table[0].name[j])
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Set *T to ``undefined'' values. */
|
||||
static void
|
||||
undefine (t)
|
||||
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
|
||||
= t->wday_ordinal = t->ymodulus = t->yweek
|
||||
= TM_UNDEFINED;
|
||||
t->tmr.tm_sec = t->tmr.tm_min = t->tmr.tm_hour =
|
||||
t->tmr.tm_mday = t->tmr.tm_mon = t->tmr.tm_year = 0;
|
||||
t->zone = TM_UNDEFINED_ZONE;
|
||||
}
|
||||
|
||||
/* Patterns to look for in a time string.
|
||||
Order is important: we look for the first matching pattern
|
||||
whose values do not contradict values that we already know about.
|
||||
See `parse_pattern_letter' below for the meaning of the pattern codes. */
|
||||
static char const time_patterns[] =
|
||||
{
|
||||
/* Traditional patterns come first,
|
||||
to prevent an ISO 8601 format from misinterpreting their prefixes. */
|
||||
|
||||
/* RFC 822, extended */
|
||||
'E', '_', 'N', '_', 'y', '$', 0,
|
||||
'x', 0,
|
||||
|
||||
/* traditional */
|
||||
'4', '_', 'M', '_', 'D', '_', 'h', '_', 'm', '_', 's', '$', 0,
|
||||
'R', '_', 'M', '_', 'D', '_', 'h', '_', 'm', '_', 's', '$', 0,
|
||||
'E', '_', 'N', 0,
|
||||
'N', '_', 'E', '_', 'y', ';', 0,
|
||||
'N', '_', 'E', ';', 0,
|
||||
'N', 0,
|
||||
't', ':', 'm', ':', 's', '_', 'A', 0,
|
||||
't', ':', 'm', '_', 'A', 0,
|
||||
't', '_', 'A', 0,
|
||||
|
||||
/* traditional get_date */
|
||||
'i', '_', 'x', 0,
|
||||
'Y', '/', 'n', '/', 'E', ';', 0,
|
||||
'n', '/', 'E', '/', 'y', ';', 0,
|
||||
'n', '/', 'E', ';', 0,
|
||||
'u', 0,
|
||||
|
||||
/* ISO 8601:1988 formats, generalized a bit. */
|
||||
'y', '-', 'M', '-', 'D', '$', 0,
|
||||
'4', 'M', 'D', '$', 0,
|
||||
'Y', '-', 'M', '$', 0,
|
||||
'R', 'M', 'D', '$', 0,
|
||||
'-', 'R', '=', 'M', '$', 0,
|
||||
'-', 'R', '$', 0,
|
||||
'-', '-', 'M', '=', 'D', '$', 0,
|
||||
'M', '=', 'D', 'T', 0,
|
||||
'-', '-', 'M', '$', 0,
|
||||
'-', '-', '-', 'D', '$', 0,
|
||||
'D', 'T', 0,
|
||||
'Y', '-', 'd', '$', 0,
|
||||
'4', 'd', '$', 0,
|
||||
'R', '=', 'd', '$', 0,
|
||||
'-', 'd', '$', 0,
|
||||
'd', 'T', 0,
|
||||
'y', '-', 'W', '-', 'X', 0,
|
||||
'y', 'W', 'X', 0,
|
||||
'y', '=', 'W', 0,
|
||||
'-', 'r', '-', 'W', '-', 'X', 0,
|
||||
'r', '-', 'W', '-', 'X', 'T', 0,
|
||||
'-', 'r', 'W', 'X', 0,
|
||||
'r', 'W', 'X', 'T', 0,
|
||||
'-', 'W', '=', 'X', 0,
|
||||
'W', '=', 'X', 'T', 0,
|
||||
'-', 'W', 0,
|
||||
'-', 'w', '-', 'X', 0,
|
||||
'w', '-', 'X', 'T', 0,
|
||||
'-', '-', '-', 'X', '$', 0,
|
||||
'X', 'T', 0,
|
||||
'4', '$', 0,
|
||||
'T', 0,
|
||||
'h', ':', 'm', ':', 's', '$', 0,
|
||||
'h', 'm', 's', '$', 0,
|
||||
'h', ':', 'L', '$', 0,
|
||||
'h', 'L', '$', 0,
|
||||
'H', '$', 0,
|
||||
'-', 'm', ':', 's', '$', 0,
|
||||
'-', 'm', 's', '$', 0,
|
||||
'-', 'L', '$', 0,
|
||||
'-', '-', 's', '$', 0,
|
||||
'Y', 0,
|
||||
'Z', 0,
|
||||
|
||||
0
|
||||
};
|
||||
|
||||
/* Parse an initial prefix of STR according to *PATTERNS, setting *T.
|
||||
Return the first character after the prefix, or 0 if it couldn't be parsed.
|
||||
*PATTERNS is a character array containing one pattern string after another;
|
||||
it is terminated by an empty string.
|
||||
If success, set *PATTERNS to the next pattern to try.
|
||||
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;
|
||||
{
|
||||
char const *pat = *patterns;
|
||||
unsigned char c;
|
||||
|
||||
if (! pat)
|
||||
return 0;
|
||||
|
||||
/* Remove initial noise. */
|
||||
while (! ISALNUM (c = *str) && c != '-' && c != '+')
|
||||
{
|
||||
if (! c)
|
||||
{
|
||||
undefine (t);
|
||||
*patterns = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
str++;
|
||||
}
|
||||
|
||||
/* Try a pattern until one succeeds. */
|
||||
while (*pat)
|
||||
{
|
||||
char const *s = str;
|
||||
undefine (t);
|
||||
|
||||
do
|
||||
{
|
||||
if (! (c = *pat++))
|
||||
{
|
||||
*patterns = pat;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
while ((s = parse_pattern_letter (s, c, t)) != 0);
|
||||
|
||||
while (*pat++)
|
||||
continue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse an initial prefix of S of length DIGITS; it must be a number.
|
||||
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;
|
||||
{
|
||||
int n = 0;
|
||||
char const *lim = s + digits;
|
||||
while (s < lim)
|
||||
{
|
||||
unsigned d = *s++ - '0';
|
||||
if (9 < d)
|
||||
return 0;
|
||||
n = 10 * n + d;
|
||||
}
|
||||
*res = n;
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Parse a possibly empty initial prefix of S.
|
||||
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;
|
||||
{
|
||||
int n = 0;
|
||||
for (;;)
|
||||
{
|
||||
unsigned d = *s - '0';
|
||||
if (9 < d)
|
||||
break;
|
||||
s++;
|
||||
n = 10 * n + d;
|
||||
}
|
||||
*res = n;
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Parse an initial prefix of S of length DIGITS;
|
||||
it must be a number in the range LO through HI.
|
||||
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;
|
||||
{
|
||||
s = parse_fixed (s, digits, res);
|
||||
return s && lo <= *res && *res <= hi ? s : 0;
|
||||
}
|
||||
|
||||
/* Parse an initial prefix of S of length DIGITS;
|
||||
it must be a number in the range LO through HI
|
||||
and it may be followed by a fraction to be computed using RESOLUTION.
|
||||
Store the parsed number into *RES; store the fraction times RESOLUTION,
|
||||
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;
|
||||
{
|
||||
s = parse_fixed (s, digits, res);
|
||||
if (s && lo <= *res && *res <= hi)
|
||||
{
|
||||
int f = 0;
|
||||
if ((s[0] == ',' || s[0] == '.') && ISDIGIT (s[1]))
|
||||
{
|
||||
char const *s1 = ++s;
|
||||
int num10 = 0, denom10 = 10, product;
|
||||
while (ISDIGIT (*++s))
|
||||
{
|
||||
int d = denom10 * 10;
|
||||
if (d / 10 != denom10)
|
||||
return 0; /* overflow */
|
||||
denom10 = d;
|
||||
}
|
||||
s = parse_fixed (s1, (int) (s - s1), &num10);
|
||||
product = num10 * resolution;
|
||||
f = (product + (denom10 >> 1)) / denom10;
|
||||
f -= f & (product % denom10 == denom10 >> 1); /* round to even */
|
||||
if (f < 0 || product/resolution != num10)
|
||||
return 0; /* overflow */
|
||||
}
|
||||
*fres = f;
|
||||
return s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse an initial prefix of S; it must denote a time zone.
|
||||
Set *ZONE to the number of seconds east of GMT,
|
||||
or to TM_LOCAL_ZONE if it is the local time zone.
|
||||
Return the first character after the prefix, or 0 if it wasn't parsed. */
|
||||
char *
|
||||
parzone (s, zone)
|
||||
char const *s;
|
||||
long *zone;
|
||||
{
|
||||
char const *s1;
|
||||
char sign;
|
||||
int hh, mm, ss;
|
||||
int minutes_east_of_UTC;
|
||||
int trailing_DST;
|
||||
long offset, z;
|
||||
|
||||
/* The formats are LT, n, n DST, nDST, no, o
|
||||
where n is a time zone name
|
||||
and o is a time zone offset of the form [-+]hh[:mm[:ss]]. */
|
||||
switch (*s)
|
||||
{
|
||||
case '-':
|
||||
case '+':
|
||||
z = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
minutes_east_of_UTC = lookup (s, zone_names);
|
||||
if (minutes_east_of_UTC == -1)
|
||||
return 0;
|
||||
|
||||
/* Don't bother to check rest of spelling,
|
||||
but look for an embedded "DST". */
|
||||
trailing_DST = 0;
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
{
|
||||
if ((*s == 'D' || *s == 'd') && lookup (s, dst_names))
|
||||
trailing_DST = 1;
|
||||
s++;
|
||||
s += *s == '.';
|
||||
}
|
||||
|
||||
/* Don't modify LT. */
|
||||
if (minutes_east_of_UTC == 1)
|
||||
{
|
||||
*zone = TM_LOCAL_ZONE;
|
||||
return (char *) s;
|
||||
}
|
||||
|
||||
z = minutes_east_of_UTC * 60L;
|
||||
s1 = s;
|
||||
|
||||
/* Look for trailing "DST" or " DST". */
|
||||
while (ISSPACE ((unsigned char) *s))
|
||||
s++;
|
||||
if (lookup (s, dst_names))
|
||||
{
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
{
|
||||
s++;
|
||||
s += *s == '.';
|
||||
}
|
||||
trailing_DST = 1;
|
||||
}
|
||||
|
||||
if (trailing_DST)
|
||||
{
|
||||
*zone = z + 60*60;
|
||||
return (char *) s;
|
||||
}
|
||||
|
||||
s = s1;
|
||||
|
||||
switch (*s)
|
||||
{
|
||||
case '-':
|
||||
case '+':
|
||||
break;
|
||||
|
||||
default:
|
||||
*zone = z;
|
||||
return (char *) s;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
sign = *s++;
|
||||
|
||||
if (! (s = parse_ranged (s, 2, 0, 23, &hh)))
|
||||
return 0;
|
||||
mm = ss = 0;
|
||||
if (*s == ':')
|
||||
s++;
|
||||
if (ISDIGIT (*s))
|
||||
{
|
||||
if (! (s = parse_ranged (s, 2, 0, 59, &mm)))
|
||||
return 0;
|
||||
if (*s == ':' && s[-3] == ':' && ISDIGIT (s[1])
|
||||
&& ! (s = parse_ranged (s + 1, 2, 0, 59, &ss)))
|
||||
return 0;
|
||||
}
|
||||
if (ISDIGIT (*s))
|
||||
return 0;
|
||||
offset = (hh * 60 + mm) * 60L + ss;
|
||||
*zone = z + (sign == '-' ? -offset : offset);
|
||||
/* ?? Are fractions allowed here? If so, they're not implemented. */
|
||||
return (char *) s;
|
||||
}
|
||||
|
||||
/* Parse an initial prefix of S, matching the pattern whose code is C.
|
||||
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;
|
||||
{
|
||||
char const *s0 = s;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '$': /* The next character must be a non-digit. */
|
||||
if (ISDIGIT (*s))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case '-':
|
||||
case '/':
|
||||
case ':':
|
||||
/* These characters stand for themselves. */
|
||||
if (*s++ != c)
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case '4': /* 4-digit year */
|
||||
s = parse_fixed (s, 4, &t->tm.tm_year);
|
||||
break;
|
||||
|
||||
case ';': /* The next character must be a non-digit, and cannot be ':'. */
|
||||
if (ISDIGIT (*s) || *s == ':')
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case '=': /* optional '-' */
|
||||
s += *s == '-';
|
||||
break;
|
||||
|
||||
case 'A': /* AM or PM */
|
||||
/* This matches the regular expression [AaPp]\.?([Mm]\.?)?.
|
||||
It must not be followed by a letter or digit;
|
||||
otherwise it would match prefixes of strings like "PST". */
|
||||
switch (*s)
|
||||
{
|
||||
case 'A':
|
||||
case 'a':
|
||||
if (t->tm.tm_hour == 12)
|
||||
t->tm.tm_hour = 0;
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
case 'p':
|
||||
if (t->tm.tm_hour != 12)
|
||||
t->tm.tm_hour += 12;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
s++;
|
||||
s += *s == '.';
|
||||
switch (*s)
|
||||
{
|
||||
case 'M':
|
||||
case 'm':
|
||||
s++;
|
||||
s += *s == '.';
|
||||
break;
|
||||
}
|
||||
if (ISALNUM ((unsigned char) *s))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 'D': /* day of month [01-31] */
|
||||
s = parse_ranged (s, 2, 1, 31, &t->tm.tm_mday);
|
||||
break;
|
||||
|
||||
case 'd': /* day of year [001-366] */
|
||||
s = parse_ranged (s, 3, 1, 366, &t->tm.tm_yday);
|
||||
t->tm.tm_yday--;
|
||||
break;
|
||||
|
||||
case 'E': /* traditional day of month [1-9, 01-31] */
|
||||
s = parse_ranged (s, (ISDIGIT (s[0]) && ISDIGIT (s[1])) + 1, 1, 31,
|
||||
&t->tm.tm_mday);
|
||||
break;
|
||||
|
||||
case 'h': /* hour [00-23] */
|
||||
s = parse_ranged (s, 2, 0, 23, &t->tm.tm_hour);
|
||||
break;
|
||||
|
||||
case 'H': /* hour [00-23 followed by optional fraction] */
|
||||
{
|
||||
int frac;
|
||||
s = parse_decimal (s, 2, 0, 23, 60 * 60, &t->tm.tm_hour, &frac);
|
||||
t->tm.tm_min = frac / 60;
|
||||
t->tm.tm_sec = frac % 60;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'i': /* ordinal day number, e.g. "3rd" */
|
||||
s = parse_varying (s, &t->wday_ordinal);
|
||||
if (s == s0)
|
||||
return 0;
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
s++;
|
||||
break;
|
||||
|
||||
case 'L': /* minute [00-59 followed by optional fraction] */
|
||||
s = parse_decimal (s, 2, 0, 59, 60, &t->tm.tm_min, &t->tm.tm_sec);
|
||||
break;
|
||||
|
||||
case 'm': /* minute [00-59] */
|
||||
s = parse_ranged (s, 2, 0, 59, &t->tm.tm_min);
|
||||
break;
|
||||
|
||||
case 'M': /* month [01-12] */
|
||||
s = parse_ranged (s, 2, 1, 12, &t->tm.tm_mon);
|
||||
t->tm.tm_mon--;
|
||||
break;
|
||||
|
||||
case 'n': /* traditional month [1-9, 01-12] */
|
||||
s = parse_ranged (s, (ISDIGIT (s[0]) && ISDIGIT (s[1])) + 1, 1, 12,
|
||||
&t->tm.tm_mon);
|
||||
t->tm.tm_mon--;
|
||||
break;
|
||||
|
||||
case 'N': /* month name [e.g. "Jan"] */
|
||||
if (! TM_DEFINED (t->tm.tm_mon = lookup (s, month_names)))
|
||||
return 0;
|
||||
/* Don't bother to check rest of spelling. */
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
s++;
|
||||
break;
|
||||
|
||||
case 'r': /* year % 10 (remainder in origin-0 decade) [0-9] */
|
||||
s = parse_fixed (s, 1, &t->tm.tm_year);
|
||||
t->ymodulus = 10;
|
||||
break;
|
||||
|
||||
case_R:
|
||||
case 'R': /* year % 100 (remainder in origin-0 century) [00-99] */
|
||||
s = parse_fixed (s, 2, &t->tm.tm_year);
|
||||
t->ymodulus = 100;
|
||||
break;
|
||||
|
||||
case 's': /* second [00-60 followed by optional fraction] */
|
||||
{
|
||||
int frac;
|
||||
s = parse_decimal (s, 2, 0, 60, 1, &t->tm.tm_sec, &frac);
|
||||
t->tm.tm_sec += frac;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'T': /* 'T' or 't' */
|
||||
switch (*s++)
|
||||
{
|
||||
case 'T':
|
||||
case 't':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 't': /* traditional hour [1-9 or 01-12] */
|
||||
s = parse_ranged (s, (ISDIGIT (s[0]) && ISDIGIT (s[1])) + 1, 1, 12,
|
||||
&t->tm.tm_hour);
|
||||
break;
|
||||
|
||||
case 'u': /* relative unit */
|
||||
{
|
||||
int i;
|
||||
int n;
|
||||
int negative = 0;
|
||||
switch (*s)
|
||||
{
|
||||
case '-': negative = 1;
|
||||
/* Fall through. */
|
||||
case '+': s++;
|
||||
}
|
||||
if (ISDIGIT (*s))
|
||||
s = parse_varying (s, &n);
|
||||
else if (s == s0)
|
||||
n = 1;
|
||||
else
|
||||
return 0;
|
||||
if (negative)
|
||||
n = -n;
|
||||
while (! ISALNUM ((unsigned char) *s) && *s)
|
||||
s++;
|
||||
i = lookup (s, relative_units);
|
||||
if (!TM_DEFINED (i))
|
||||
return 0;
|
||||
* (int *) ((char *) &t->tmr + RELATIVE_OFFSET (i))
|
||||
+= n * RELATIVE_MULTIPLIER (i);
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
s++;
|
||||
while (! ISALNUM ((unsigned char) *s) && *s)
|
||||
s++;
|
||||
if (TM_DEFINED (lookup (s, ago)))
|
||||
{
|
||||
t->tmr.tm_sec = - t->tmr.tm_sec;
|
||||
t->tmr.tm_min = - t->tmr.tm_min;
|
||||
t->tmr.tm_hour = - t->tmr.tm_hour;
|
||||
t->tmr.tm_mday = - t->tmr.tm_mday;
|
||||
t->tmr.tm_mon = - t->tmr.tm_mon;
|
||||
t->tmr.tm_year = - t->tmr.tm_year;
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
s++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'w': /* 'W' or 'w' only (stands for current week) */
|
||||
switch (*s++)
|
||||
{
|
||||
case 'W':
|
||||
case 'w':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'W': /* 'W' or 'w', followed by a week of year [00-53] */
|
||||
switch (*s++)
|
||||
{
|
||||
case 'W':
|
||||
case 'w':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
s = parse_ranged (s, 2, 0, 53, &t->yweek);
|
||||
break;
|
||||
|
||||
case 'X': /* weekday (1=Mon ... 7=Sun) [1-7] */
|
||||
s = parse_ranged (s, 1, 1, 7, &t->tm.tm_wday);
|
||||
t->tm.tm_wday--;
|
||||
break;
|
||||
|
||||
case 'x': /* weekday name [e.g. "Sun"] */
|
||||
if (! TM_DEFINED (t->tm.tm_wday = lookup (s, weekday_names)))
|
||||
return 0;
|
||||
/* Don't bother to check rest of spelling. */
|
||||
while (ISALPHA ((unsigned char) *s))
|
||||
s++;
|
||||
break;
|
||||
|
||||
case 'y': /* either R or Y */
|
||||
if (ISDIGIT (s[0]) && ISDIGIT (s[1]) && ! ISDIGIT (s[2]))
|
||||
goto case_R;
|
||||
/* fall into */
|
||||
case 'Y': /* year in full [4 or more digits] */
|
||||
s = parse_varying (s, &t->tm.tm_year);
|
||||
if (s - s0 < 4)
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case 'Z': /* time zone */
|
||||
s = parzone (s, &t->zone);
|
||||
break;
|
||||
|
||||
case '_': /* possibly empty sequence of non-alphanumerics */
|
||||
while (! ISALNUM ((unsigned char) *s) && *s)
|
||||
s++;
|
||||
break;
|
||||
|
||||
default: /* bad pattern */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
{
|
||||
# define conflict(a,b) ((a) != (b) && TM_DEFINED (a) && TM_DEFINED (b))
|
||||
if (conflict (t->tm.tm_sec, u->tm.tm_sec)
|
||||
|| conflict (t->tm.tm_min, u->tm.tm_min)
|
||||
|| conflict (t->tm.tm_hour, u->tm.tm_hour)
|
||||
|| conflict (t->tm.tm_mday, u->tm.tm_mday)
|
||||
|| conflict (t->tm.tm_mon, u->tm.tm_mon)
|
||||
|| conflict (t->tm.tm_year, u->tm.tm_year)
|
||||
|| conflict (t->tm.tm_wday, u->tm.tm_wday)
|
||||
|| conflict (t->tm.tm_yday, u->tm.tm_yday)
|
||||
|| conflict (t->ymodulus, u->ymodulus)
|
||||
|| conflict (t->yweek, u->yweek)
|
||||
|| (t->zone != u->zone
|
||||
&& t->zone != TM_UNDEFINED_ZONE
|
||||
&& u->zone != TM_UNDEFINED_ZONE))
|
||||
return -1;
|
||||
# undef conflict
|
||||
# define merge_(a,b) if (TM_DEFINED (b)) (a) = (b);
|
||||
merge_ (t->tm.tm_sec, u->tm.tm_sec)
|
||||
merge_ (t->tm.tm_min, u->tm.tm_min)
|
||||
merge_ (t->tm.tm_hour, u->tm.tm_hour)
|
||||
merge_ (t->tm.tm_mday, u->tm.tm_mday)
|
||||
merge_ (t->tm.tm_mon, u->tm.tm_mon)
|
||||
merge_ (t->tm.tm_year, u->tm.tm_year)
|
||||
merge_ (t->tm.tm_wday, u->tm.tm_wday)
|
||||
merge_ (t->tm.tm_yday, u->tm.tm_yday)
|
||||
merge_ (t->ymodulus, u->ymodulus)
|
||||
merge_ (t->yweek, u->yweek)
|
||||
# undef merge_
|
||||
t->tmr.tm_sec += u->tmr.tm_sec;
|
||||
t->tmr.tm_min += u->tmr.tm_min;
|
||||
t->tmr.tm_hour += u->tmr.tm_hour;
|
||||
t->tmr.tm_mday += u->tmr.tm_mday;
|
||||
t->tmr.tm_mon += u->tmr.tm_mon;
|
||||
t->tmr.tm_year += u->tmr.tm_year;
|
||||
if (u->zone != TM_UNDEFINED_ZONE)
|
||||
t->zone = u->zone;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse a date/time prefix of S, putting the parsed result into *T.
|
||||
Return the first character after the prefix.
|
||||
The prefix may contain no useful information;
|
||||
in that case, *T will contain only undefined values. */
|
||||
char *
|
||||
partime (s, t)
|
||||
char const *s;
|
||||
struct partime *t;
|
||||
{
|
||||
struct partime p;
|
||||
|
||||
undefine (t);
|
||||
|
||||
while (*s)
|
||||
{
|
||||
char const *patterns = time_patterns;
|
||||
char const *s1;
|
||||
|
||||
do
|
||||
{
|
||||
if (! (s1 = parse_prefix (s, &patterns, &p)))
|
||||
return (char *) s;
|
||||
}
|
||||
while (merge_partime (t, &p) != 0);
|
||||
|
||||
s = s1;
|
||||
}
|
||||
|
||||
return (char *) s;
|
||||
}
|
77
patch/partime.h
Normal file
77
patch/partime.h
Normal file
@ -0,0 +1,77 @@
|
||||
/* Parse a string, yielding a struct partime that describes it. */
|
||||
|
||||
/* Copyright 1993, 1994, 1995, 1997 Paul Eggert
|
||||
Distributed under license by the Free Software Foundation, Inc.
|
||||
|
||||
This file is part of RCS.
|
||||
|
||||
RCS 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.
|
||||
|
||||
RCS 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 RCS; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Report problems and direct all questions to:
|
||||
|
||||
rcs-bugs@cs.purdue.edu
|
||||
|
||||
*/
|
||||
|
||||
#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)
|
||||
|
||||
struct partime
|
||||
{
|
||||
/* This structure describes the parsed time.
|
||||
Only the following tm_* members are used:
|
||||
sec, min, hour, mday, mon, year, wday, yday.
|
||||
If ! TM_DEFINED (value), the parser never found the value.
|
||||
The tm_year field is the actual year, not the year - 1900;
|
||||
but see ymodulus below. */
|
||||
struct tm tm;
|
||||
|
||||
/* Like tm, but values are relative to the value in tm,
|
||||
and values are initialized to 0 rather than to TM_UNDEFINED.
|
||||
Only the following tm_* members are used:
|
||||
sec, min, hour, mday, mon, year. */
|
||||
struct tm tmr;
|
||||
|
||||
/* If TM_DEFINED (wday_ordinal),
|
||||
then day number (e.g. 3 in "3rd Sunday"). */
|
||||
int wday_ordinal;
|
||||
|
||||
/* If TM_DEFINED (ymodulus),
|
||||
then tm.tm_year is actually modulo ymodulus. */
|
||||
int ymodulus;
|
||||
|
||||
/* Week of year, ISO 8601 style.
|
||||
If ! TM_DEFINED (yweek), the parser never found yweek.
|
||||
Weeks start on Mondays.
|
||||
Week 1 includes Jan 4. */
|
||||
int yweek;
|
||||
|
||||
/* Seconds east of UTC; or TM_LOCAL_ZONE or TM_UNDEFINED_ZONE. */
|
||||
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 *));
|
1370
patch/patch.c
Normal file
1370
patch/patch.c
Normal file
File diff suppressed because it is too large
Load Diff
1160
patch/patch.man
Normal file
1160
patch/patch.man
Normal file
File diff suppressed because it is too large
Load Diff
1
patch/patchlevel.h
Normal file
1
patch/patchlevel.h
Normal file
@ -0,0 +1 @@
|
||||
#define PATCH_VERSION "2.5.8"
|
34
patch/pc/chdirsaf.c
Normal file
34
patch/pc/chdirsaf.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* A safer version of chdir, which returns back to the
|
||||
initial working directory when the program exits. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char *initial_wd;
|
||||
|
||||
static void
|
||||
restore_wd (void)
|
||||
{
|
||||
chdir (initial_wd);
|
||||
}
|
||||
|
||||
int
|
||||
chdir_safer (char const *dir)
|
||||
{
|
||||
if (! initial_wd)
|
||||
{
|
||||
size_t s;
|
||||
for (s = 256; ! (initial_wd = getcwd (0, s)); s *= 2)
|
||||
if (errno != ERANGE)
|
||||
return -1;
|
||||
if (atexit (restore_wd) != 0)
|
||||
{
|
||||
free (initial_wd);
|
||||
initial_wd = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return chdir (dir);
|
||||
}
|
19
patch/pc/djgpp/README
Normal file
19
patch/pc/djgpp/README
Normal file
@ -0,0 +1,19 @@
|
||||
To configure `patch' for DJGPP, issue these commands from the
|
||||
`patch' source directory:
|
||||
|
||||
pc\djgpp\configure
|
||||
make
|
||||
|
||||
To build `patch' in a directory other than where the sources are,
|
||||
add a parameter that specifies the source directory, e.g.:
|
||||
|
||||
e:\src\patch\pc\djgpp\configure e:/src/patch
|
||||
|
||||
You MUST use forward slashes to specify the source directory.
|
||||
|
||||
Running configure.bat requires a port of `sed'.
|
||||
You can find one on the usual DJGPP archive sites.
|
||||
|
||||
|
||||
Thanks to Eli Zaretskii <eliz@is.elta.co.il> for
|
||||
suggestions and ideas for this DJGPP port.
|
41
patch/pc/djgpp/config.sed
Normal file
41
patch/pc/djgpp/config.sed
Normal file
@ -0,0 +1,41 @@
|
||||
1c\
|
||||
/* config.h for compiling `patch' with DJGPP for MS-DOS and MS-Windows.\
|
||||
Please keep this file as similar as possible to ../../config.h\
|
||||
to simplify maintenance later. */\
|
||||
\
|
||||
/* This does most of the work; the rest of this file defines only those\
|
||||
symbols that <sys/config.h> doesn't define correctly. */\
|
||||
#include <sys/config.h>
|
||||
|
||||
s/#undef HAVE_DONE_WORKING_MALLOC_CHECK/#define HAVE_DONE_WORKING_MALLOC_CHECK 1/
|
||||
s/#undef HAVE_DONE_WORKING_REALLOC_CHECK/#define HAVE_DONE_WORKING_REALLOC_CHECK 1/
|
||||
s/#undef HAVE_LONG_FILE_NAMES/#define HAVE_LONG_FILE_NAMES 1/
|
||||
s/#undef HAVE_MEMCMP/#define HAVE_MEMCMP 1/
|
||||
s/#undef HAVE_MKTEMP/#define HAVE_MKTEMP 1/
|
||||
s/#undef HAVE_PATHCONF/#define HAVE_PATHCONF 1/
|
||||
s/#undef HAVE_RAISE/#define HAVE_RAISE 1/
|
||||
s/#undef HAVE_SIGPROCMASK/#define HAVE_SIGPROCMASK 1/
|
||||
s/#undef HAVE_STRUCT_UTIMBUF/#define HAVE_STRUCT_UTIMBUF 1/
|
||||
s/#undef HAVE_UTIME_H/#define HAVE_UTIME_H 1/
|
||||
s/#undef HAVE_VPRINTF/#define HAVE_VPRINTF 1/
|
||||
s/#undef PROTOTYPES/#define PROTOTYPES 1/
|
||||
|
||||
s,#undef.*,/* & */,
|
||||
|
||||
$a\
|
||||
/* DGJPP-specific definitions */\
|
||||
\
|
||||
#define chdir chdir_safer\
|
||||
int chdir_safer (char const *);\
|
||||
\
|
||||
#define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)\
|
||||
#define ISSLASH(c) ((c) == '/' || (c) == '\\\\')\
|
||||
\
|
||||
#define HAVE_DOS_FILE_NAMES 1\
|
||||
\
|
||||
#define HAVE_SETMODE 1\
|
||||
#ifdef WIN32\
|
||||
# define setmode _setmode\
|
||||
#endif\
|
||||
\
|
||||
#define TMPDIR "c:"
|
27
patch/pc/djgpp/configure.bat
Normal file
27
patch/pc/djgpp/configure.bat
Normal file
@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
Rem Configure patch for DJGPP v2.
|
||||
Rem $Id: configure.bat,v 1.4 1997/06/17 06:52:12 eggert Exp $
|
||||
|
||||
Rem The DOS shell has fixed-size environment storage.
|
||||
Rem When the environment is full, the shell prints
|
||||
Rem "Out of environment space" and truncates the string at will.
|
||||
Rem Since people often ignore these messages,
|
||||
Rem test whether the environment variable got the correct value.
|
||||
|
||||
Rem Where is our source directory?
|
||||
set srcdir=.
|
||||
if not "%srcdir%" == "." goto SmallEnv
|
||||
if not "%1" == "" set srcdir=%1
|
||||
if not "%1" == "" if not "%srcdir%" == "%1" goto SmallEnv
|
||||
|
||||
Rem Create Makefile
|
||||
sed -f %srcdir%/pc/djgpp/configure.sed -e "s,@srcdir@,%srcdir%,g" %srcdir%/Makefile.in >Makefile
|
||||
sed -n -e "/^VERSION/p" %srcdir%/configure.in >>Makefile
|
||||
|
||||
goto Exit
|
||||
|
||||
:SmallEnv
|
||||
echo Your environment size is too small. Please enlarge it and run me again.
|
||||
|
||||
:Exit
|
||||
set srcdir=
|
37
patch/pc/djgpp/configure.sed
Normal file
37
patch/pc/djgpp/configure.sed
Normal file
@ -0,0 +1,37 @@
|
||||
# Edit Makefile.in to produce Makefile for DJGPP v2
|
||||
# $Id: configure.sed,v 1.1.1.2 2000/05/06 22:44:56 wsanchez Exp $
|
||||
|
||||
1i\
|
||||
# Makefile generated by "configure.bat" for DJGPP v2\
|
||||
|
||||
/@SET_MAKE@/d
|
||||
|
||||
s|@CC@|gcc|g
|
||||
s|@ed_PROGRAM@|ed|g
|
||||
s|@INSTALL@|${DJDIR}/bin/ginstall -c|g
|
||||
s|@INSTALL_PROGRAM@|${INSTALL}|g
|
||||
s|@INSTALL_DATA@|${INSTALL} -m 644|g
|
||||
s|@program_transform_name@||g
|
||||
|
||||
s|@CFLAGS@|-g -O2|g
|
||||
s|@CPPFLAGS@|-I$(srcdir)/pc/djgpp|g
|
||||
s|@DEFS@|-DHAVE_CONFIG_H|g
|
||||
s|@LDFLAGS@||g
|
||||
s|@LIBOBJS@|getopt1.o getopt.o chdirsaf.o|g
|
||||
s|@LIBS@||g
|
||||
s|@PACKAGE@|patch|g
|
||||
s|@U@||g
|
||||
/@VERSION@/d
|
||||
|
||||
s|@prefix@|${DJDIR}|g
|
||||
s|@exec_prefix@|${prefix}|g
|
||||
|
||||
/^CONFIG_STATUS *=/s|=.*|= $(srcdir)/pc/djgpp/configure.bat|
|
||||
/^ \$(SHELL) \$(CONFIG_STATUS) *$/s// $(CONFIG_STATUS) $(srcdir)/
|
||||
|
||||
$a\
|
||||
config.h: config.hin pc/djgpp/config.sed; sed -f $(srcdir)/pc/djgpp/config.sed $(srcdir)/config.hin >$@\
|
||||
chdirsaf.o: chdirsaf.c\
|
||||
# Use sed instead of cp, since cp might not be installed.\
|
||||
chdirsaf.c: pc/chdirsaf.c; sed -e '' $? > $@\
|
||||
distclean::; rm -f chdirsaf.c
|
1951
patch/pch.c
Normal file
1951
patch/pch.c
Normal file
File diff suppressed because it is too large
Load Diff
45
patch/pch.h
Normal file
45
patch/pch.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* reading patches */
|
||||
|
||||
/* $Id: pch.h,v 1.1.1.3 2003/05/08 18:38:03 rbraun Exp $ */
|
||||
|
||||
/* Copyright (C) 1986, 1987, 1988 Larry Wall
|
||||
|
||||
Copyright (C) 1990, 1991, 1992, 1993, 1997, 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
|
||||
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. */
|
||||
|
||||
LINENUM pch_end (void);
|
||||
LINENUM pch_first (void);
|
||||
LINENUM pch_hunk_beg (void);
|
||||
LINENUM pch_newfirst (void);
|
||||
LINENUM pch_prefix_context (void);
|
||||
LINENUM pch_ptrn_lines (void);
|
||||
LINENUM pch_repl_lines (void);
|
||||
LINENUM pch_suffix_context (void);
|
||||
bool pch_swap (void);
|
||||
bool pch_write_line (LINENUM, FILE *);
|
||||
bool there_is_another_patch (void);
|
||||
char *pfetch (LINENUM);
|
||||
char pch_char (LINENUM);
|
||||
int another_hunk (enum diff, int);
|
||||
int pch_says_nonexistent (int);
|
||||
size_t pch_line_len (LINENUM);
|
||||
time_t pch_timestamp (int);
|
||||
void do_ed_script (FILE *);
|
||||
void open_patch_file (char const *);
|
||||
void re_patch (void);
|
||||
void set_hunkmax (void);
|
28
patch/quote.c
Normal file
28
patch/quote.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STDDEF_H
|
||||
# include <stddef.h> /* For the definition of size_t on windows w/MSVC. */
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <quotearg.h>
|
||||
#include <quote.h>
|
||||
|
||||
/* Return an unambiguous printable representated, allocated in slot N,
|
||||
for NAME, 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);
|
||||
}
|
12
patch/quote.h
Normal file
12
patch/quote.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* prototypes for quote.c */
|
||||
|
||||
#ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
char const *quote_n PARAMS ((int n, char const *name));
|
||||
char const *quote PARAMS ((char const *name));
|
658
patch/quotearg.c
Normal file
658
patch/quotearg.c
Normal file
@ -0,0 +1,658 @@
|
||||
/* quotearg.c - quote arguments for output
|
||||
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
|
||||
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
|
||||
|
||||
#if HAVE_STDDEF_H
|
||||
# include <stddef.h> /* For the definition of size_t on windows w/MSVC. */
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <quotearg.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(text) gettext (text)
|
||||
#else
|
||||
# define _(text) text
|
||||
#endif
|
||||
#define N_(text) text
|
||||
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
#ifndef UCHAR_MAX
|
||||
# define UCHAR_MAX ((unsigned char) -1)
|
||||
#endif
|
||||
#ifndef UINT_MAX
|
||||
# define UINT_MAX ((unsigned int) -1)
|
||||
#endif
|
||||
|
||||
#if HAVE_C_BACKSLASH_A
|
||||
# define ALERT_CHAR '\a'
|
||||
#else
|
||||
# define ALERT_CHAR '\7'
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#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 mbsinit(ps) 1
|
||||
# define iswprint(wc) ISPRINT ((unsigned char) (wc))
|
||||
#endif
|
||||
|
||||
#ifndef iswprint
|
||||
# if HAVE_WCTYPE_H
|
||||
# include <wctype.h>
|
||||
# endif
|
||||
# if !defined iswprint && !HAVE_ISWPRINT
|
||||
# define iswprint(wc) 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define INT_BITS (sizeof (int) * CHAR_BIT)
|
||||
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
/* Undefine to protect against the definition in wctype.h of solaris2.6. */
|
||||
#undef ISPRINT
|
||||
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
|
||||
|
||||
struct quoting_options
|
||||
{
|
||||
/* Basic quoting style. */
|
||||
enum quoting_style style;
|
||||
|
||||
/* 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 / INT_BITS) + 1];
|
||||
};
|
||||
|
||||
/* Names of quoting styles. */
|
||||
char const *const quoting_style_args[] =
|
||||
{
|
||||
"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. */
|
||||
static struct quoting_options default_quoting_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 (struct quoting_options *o)
|
||||
{
|
||||
struct quoting_options *p
|
||||
= (struct quoting_options *) xmalloc (sizeof (struct quoting_options));
|
||||
*p = *(o ? o : &default_quoting_options);
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Get the value of O's quoting style. If O is null, use the default. */
|
||||
enum quoting_style
|
||||
get_quoting_style (struct quoting_options *o)
|
||||
{
|
||||
return (o ? o : &default_quoting_options)->style;
|
||||
}
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting style to S. */
|
||||
void
|
||||
set_quoting_style (struct quoting_options *o, enum quoting_style s)
|
||||
{
|
||||
(o ? o : &default_quoting_options)->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 (struct quoting_options *o, char c, int i)
|
||||
{
|
||||
unsigned char uc = c;
|
||||
int *p = (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
|
||||
int shift = uc % INT_BITS;
|
||||
int r = (*p >> shift) & 1;
|
||||
*p ^= ((i & 1) ^ r) << shift;
|
||||
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 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.
|
||||
|
||||
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)
|
||||
{
|
||||
size_t i;
|
||||
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++; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
switch (quoting_style)
|
||||
{
|
||||
case c_quoting_style:
|
||||
STORE ('"');
|
||||
backslash_escapes = 1;
|
||||
quote_string = "\"";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
case escape_quoting_style:
|
||||
backslash_escapes = 1;
|
||||
break;
|
||||
|
||||
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 shell_always_quoting_style:
|
||||
STORE ('\'');
|
||||
quote_string = "'";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; ! (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize); i++)
|
||||
{
|
||||
unsigned char c;
|
||||
unsigned char esc;
|
||||
|
||||
if (backslash_escapes
|
||||
&& quote_string_len
|
||||
&& i + quote_string_len <= argsize
|
||||
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
|
||||
STORE ('\\');
|
||||
|
||||
c = arg[i];
|
||||
switch (c)
|
||||
{
|
||||
case '\0':
|
||||
if (backslash_escapes)
|
||||
{
|
||||
STORE ('\\');
|
||||
STORE ('0');
|
||||
STORE ('0');
|
||||
c = '0';
|
||||
}
|
||||
break;
|
||||
|
||||
case '?':
|
||||
switch (quoting_style)
|
||||
{
|
||||
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. */
|
||||
i += 2;
|
||||
c = arg[i + 2];
|
||||
STORE ('?');
|
||||
STORE ('\\');
|
||||
STORE ('?');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ALERT_CHAR: 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:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
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_t) -1)
|
||||
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_string)
|
||||
for (; *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
|
||||
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;
|
||||
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
|
||||
p->style, p);
|
||||
}
|
||||
|
||||
/* 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 is deliberately declared with type "int"
|
||||
to allow for future extensions (using negative values). */
|
||||
static char *
|
||||
quotearg_n_options (int n, char const *arg, size_t argsize,
|
||||
struct quoting_options const *options)
|
||||
{
|
||||
/* 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;
|
||||
};
|
||||
static struct slotvec slotvec0 = {sizeof slot0, slot0};
|
||||
static struct slotvec *slotvec = &slotvec0;
|
||||
|
||||
if (n < 0)
|
||||
abort ();
|
||||
|
||||
if (nslots <= n0)
|
||||
{
|
||||
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 = (struct slotvec *) xmalloc (sizeof *slotvec);
|
||||
*slotvec = slotvec0;
|
||||
}
|
||||
slotvec = (struct 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, argsize, options);
|
||||
|
||||
if (size <= qsize)
|
||||
{
|
||||
slotvec[n].size = size = qsize + 1;
|
||||
slotvec[n].val = val = xrealloc (val == slot0 ? 0 : val, size);
|
||||
quotearg_buffer (val, size, arg, argsize, options);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n (int n, char const *arg)
|
||||
{
|
||||
return quotearg_n_options (n, arg, (size_t) -1, &default_quoting_options);
|
||||
}
|
||||
|
||||
char *
|
||||
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_t) -1, &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, (size_t) -1, &options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_colon (char const *arg)
|
||||
{
|
||||
return quotearg_char (arg, ':');
|
||||
}
|
114
patch/quotearg.h
Normal file
114
patch/quotearg.h
Normal file
@ -0,0 +1,114 @@
|
||||
/* quotearg.h - quote arguments for output
|
||||
Copyright (C) 1998, 1999, 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. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
/* Basic quoting styles. */
|
||||
enum quoting_style
|
||||
{
|
||||
literal_quoting_style, /* --quoting-style=literal */
|
||||
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 */
|
||||
locale_quoting_style, /* --quoting-style=locale */
|
||||
clocale_quoting_style /* --quoting-style=clocale */
|
||||
};
|
||||
|
||||
/* 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 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));
|
||||
|
||||
/* 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));
|
||||
|
||||
/* 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));
|
||||
|
||||
/* 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));
|
||||
|
||||
/* 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 PARAMS ((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));
|
||||
|
||||
/* Equivalent to quotearg_n (0, ARG). */
|
||||
char *quotearg PARAMS ((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 PARAMS ((int n, enum quoting_style s, 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 PARAMS ((int n, enum quoting_style s,
|
||||
char const *arg, size_t argsize));
|
||||
|
||||
/* Equivalent to quotearg_n_style (0, S, ARG). */
|
||||
char *quotearg_style PARAMS ((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));
|
||||
|
||||
/* Equivalent to quotearg_char (ARG, ':'). */
|
||||
char *quotearg_colon PARAMS ((char const *arg));
|
125
patch/quotesys.c
Normal file
125
patch/quotesys.c
Normal file
@ -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++;
|
||||
}
|
||||
}
|
9
patch/quotesys.h
Normal file
9
patch/quotesys.h
Normal file
@ -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 *));
|
44
patch/realloc.c
Normal file
44
patch/realloc.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* Work around bug on some systems where realloc (NULL, 0) fails.
|
||||
Copyright (C) 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; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* written by Jim Meyering */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#undef realloc
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
char *malloc ();
|
||||
char *realloc ();
|
||||
|
||||
/* 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;
|
||||
{
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
if (p == 0)
|
||||
return malloc (n);
|
||||
return realloc (p, n);
|
||||
}
|
68
patch/rename.c
Normal file
68
patch/rename.c
Normal file
@ -0,0 +1,68 @@
|
||||
/* Work around the bug in some systems whereby rename fails when the source
|
||||
path has a trailing slash. The rename functions of SunOS 4.1.1_U1 and
|
||||
mips-dec-ultrix4.4 have this bug.
|
||||
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 Volker Borchert */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "dirname.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef HAVE_DECL_FREE
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
#if !HAVE_DECL_FREE
|
||||
void free ();
|
||||
#endif
|
||||
|
||||
/* Rename the file SRC_PATH to DST_PATH, removing any trailing
|
||||
slashes from SRC_PATH. Needed for SunOS 4.1.1_U1. */
|
||||
|
||||
int
|
||||
rpl_rename (const char *src_path, const char *dst_path)
|
||||
{
|
||||
char *src_temp;
|
||||
int ret_val;
|
||||
size_t s_len = strlen (src_path);
|
||||
|
||||
if (s_len && src_path[s_len - 1] == '/')
|
||||
{
|
||||
src_temp = xstrdup (src_path);
|
||||
strip_trailing_slashes (src_temp);
|
||||
}
|
||||
else
|
||||
src_temp = (char *) src_path;
|
||||
|
||||
ret_val = rename (src_temp, dst_path);
|
||||
|
||||
if (src_temp != src_path)
|
||||
free (src_temp);
|
||||
|
||||
return ret_val;
|
||||
}
|
87
patch/rmdir.c
Normal file
87
patch/rmdir.c
Normal file
@ -0,0 +1,87 @@
|
||||
/* BSD compatible remove directory function for System V
|
||||
Copyright (C) 1988, 1990 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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if STAT_MACROS_BROKEN
|
||||
# undef S_ISDIR
|
||||
#endif
|
||||
|
||||
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
/* rmdir adapted from GNU tar. */
|
||||
|
||||
/* Remove directory DPATH.
|
||||
Return 0 if successful, -1 if not. */
|
||||
|
||||
int
|
||||
rmdir (dpath)
|
||||
char *dpath;
|
||||
{
|
||||
pid_t cpid;
|
||||
int status;
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat (dpath, &statbuf) != 0)
|
||||
return -1; /* errno already set */
|
||||
|
||||
if (!S_ISDIR (statbuf.st_mode))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cpid = fork ();
|
||||
switch (cpid)
|
||||
{
|
||||
case -1: /* cannot fork */
|
||||
return -1; /* errno already set */
|
||||
|
||||
case 0: /* child process */
|
||||
execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
|
||||
_exit (1);
|
||||
|
||||
default: /* parent process */
|
||||
|
||||
/* Wait for kid to finish. */
|
||||
|
||||
while (wait (&status) != cpid)
|
||||
/* Do nothing. */ ;
|
||||
|
||||
if (status)
|
||||
{
|
||||
|
||||
/* /bin/rmdir failed. */
|
||||
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
66
patch/strcasecmp.c
Normal file
66
patch/strcasecmp.c
Normal file
@ -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 <sys/types.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;
|
||||
}
|
2
patch/strncasecmp.c
Normal file
2
patch/strncasecmp.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define LENGTH_LIMIT
|
||||
#include "strcasecmp.c"
|
69
patch/unlocked-io.h
Normal file
69
patch/unlocked-io.h
Normal file
@ -0,0 +1,69 @@
|
||||
#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 */
|
1009
patch/util.c
Normal file
1009
patch/util.c
Normal file
File diff suppressed because it is too large
Load Diff
59
patch/util.h
Normal file
59
patch/util.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* utility functions for `patch' */
|
||||
|
||||
/* $Id: util.h,v 1.1.1.3 2003/05/08 18:38:04 rbraun Exp $ */
|
||||
|
||||
/* Copyright (C) 1986 Larry Wall
|
||||
|
||||
Copyright (C) 1992, 1993, 1997, 1998, 1999, 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; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* An upper bound on the print length of a signed decimal line number.
|
||||
Add one for the sign. */
|
||||
#define LINENUM_LENGTH_BOUND (sizeof (LINENUM) * CHAR_BIT / 3 + 1)
|
||||
|
||||
XTERN enum backup_type backup_type;
|
||||
|
||||
int ok_to_reverse (char const *, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
void ask (char const *, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
void say (char const *, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
void fatal (char const *, ...)
|
||||
__attribute__ ((noreturn, format (printf, 1, 2)));
|
||||
void pfatal (char const *, ...)
|
||||
__attribute__ ((noreturn, format (printf, 1, 2)));
|
||||
|
||||
char *fetchname (char *, int, time_t *);
|
||||
char *savebuf (char const *, size_t);
|
||||
char *savestr (char const *);
|
||||
char const *version_controller (char const *, int, struct stat const *, char **, char **);
|
||||
int version_get (char const *, char const *, int, int, char const *, struct stat *);
|
||||
int create_file (char const *, int, mode_t);
|
||||
int systemic (char const *);
|
||||
char *format_linenum (char[LINENUM_LENGTH_BOUND + 1], LINENUM);
|
||||
void Fseek (FILE *, file_offset, int);
|
||||
void copy_file (char const *, char const *, int, mode_t);
|
||||
void exit_with_signal (int) __attribute__ ((noreturn));
|
||||
void ignore_signals (void);
|
||||
void init_time (void);
|
||||
void memory_fatal (void) __attribute__ ((noreturn));
|
||||
void move_file (char const *, int volatile *, char *, mode_t, int);
|
||||
void read_fatal (void) __attribute__ ((noreturn));
|
||||
void remove_prefix (char *, size_t);
|
||||
void removedirs (char *);
|
||||
void set_signals (int);
|
||||
void write_fatal (void) __attribute__ ((noreturn));
|
30
patch/version.c
Normal file
30
patch/version.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* Print the version number. */
|
||||
|
||||
/* $Id: version.c,v 1.1.1.3 2003/05/08 18:38:04 rbraun Exp $ */
|
||||
|
||||
#define XTERN extern
|
||||
#include <common.h>
|
||||
#undef XTERN
|
||||
#define XTERN
|
||||
#include <patchlevel.h>
|
||||
#include <version.h>
|
||||
|
||||
static char const copyright_string[] = "\
|
||||
Copyright (C) 1988 Larry Wall\n\
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.";
|
||||
|
||||
static char const free_software_msgid[] = "\
|
||||
This program comes with NO WARRANTY, to the extent permitted by law.\n\
|
||||
You may redistribute copies of this program\n\
|
||||
under the terms of the GNU General Public License.\n\
|
||||
For more information about these matters, see the file named COPYING.";
|
||||
|
||||
static char const authorship_msgid[] = "\
|
||||
written by Larry Wall and Paul Eggert";
|
||||
|
||||
void
|
||||
version (void)
|
||||
{
|
||||
printf ("%s %s\n%s\n\n%s\n\n%s\n", PROGRAM_NAME, PATCH_VERSION,
|
||||
copyright_string, free_software_msgid, authorship_msgid);
|
||||
}
|
5
patch/version.h
Normal file
5
patch/version.h
Normal file
@ -0,0 +1,5 @@
|
||||
/* Print the version number. */
|
||||
|
||||
/* $Id: version.h,v 1.1.1.3 2003/05/08 18:38:04 rbraun Exp $ */
|
||||
|
||||
void version (void);
|
82
patch/xalloc.h
Normal file
82
patch/xalloc.h
Normal file
@ -0,0 +1,82 @@
|
||||
/* xalloc.h -- malloc with out-of-memory checking
|
||||
Copyright (C) 1990-1998, 1999, 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 XALLOC_H_
|
||||
# define XALLOC_H_
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# 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
|
||||
|
||||
/* If this pointer is non-zero, run the specified function upon each
|
||||
allocation failure. It is initialized to zero. */
|
||||
extern void (*xalloc_fail_func) PARAMS ((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 three previous items. This is the
|
||||
function to call when one wants the program to die because of a
|
||||
memory allocation failure. */
|
||||
extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN;
|
||||
|
||||
void *xmalloc PARAMS ((size_t n));
|
||||
void *xcalloc PARAMS ((size_t n, size_t s));
|
||||
void *xrealloc PARAMS ((void *p, size_t n));
|
||||
char *xstrdup PARAMS ((const char *str));
|
||||
|
||||
# define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
|
||||
# define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
|
||||
# define XREALLOC(Ptr, Type, N_items) \
|
||||
((Type *) xrealloc ((void *) (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)))
|
||||
|
||||
/* Return a malloc'ed copy of SRC. */
|
||||
# define CLONE(Src) CCLONE (Src, 1)
|
||||
|
||||
|
||||
#endif /* !XALLOC_H_ */
|
113
patch/xmalloc.c
Normal file
113
patch/xmalloc.c
Normal file
@ -0,0 +1,113 @@
|
||||
/* xmalloc.c -- malloc with out of memory checking
|
||||
Copyright (C) 1990-1999, 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 HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
void *calloc ();
|
||||
void *malloc ();
|
||||
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 "error.h"
|
||||
#include "exitfail.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DONE_WORKING_MALLOC_CHECK
|
||||
"you must run the autoconf test for a properly working malloc -- see malloc.m4"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DONE_WORKING_REALLOC_CHECK
|
||||
"you must run the autoconf test for a properly working realloc --see realloc.m4"
|
||||
#endif
|
||||
|
||||
/* If non NULL, call this function when memory is exhausted. */
|
||||
void (*xalloc_fail_func) PARAMS ((void)) = 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");
|
||||
|
||||
void
|
||||
xalloc_die (void)
|
||||
{
|
||||
if (xalloc_fail_func)
|
||||
(*xalloc_fail_func) ();
|
||||
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 (size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc (n);
|
||||
if (p == 0)
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Change the size of an allocated block of memory P to N bytes,
|
||||
with error checking. */
|
||||
|
||||
void *
|
||||
xrealloc (void *p, size_t n)
|
||||
{
|
||||
p = realloc (p, n);
|
||||
if (p == 0)
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Allocate memory for N elements of S bytes, with error checking. */
|
||||
|
||||
void *
|
||||
xcalloc (size_t n, size_t s)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc (n, s);
|
||||
if (p == 0)
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
22
patch_cmds.plist
Normal file
22
patch_cmds.plist
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>OpenSourceImportDate</key>
|
||||
<string>2003-05-08</string>
|
||||
<key>OpenSourceLicense</key>
|
||||
<string>GPL</string>
|
||||
<key>OpenSourceLicenseFile</key>
|
||||
<string>gpatch.txt</string>
|
||||
<key>OpenSourceProject</key>
|
||||
<string>patch</string>
|
||||
<key>OpenSourceVersion</key>
|
||||
<string>2.5.8</string>
|
||||
<key>OpenSourceSHA1</key>
|
||||
<string>ae3fe3837818041162039e41a7da8eb7ede14292</string>
|
||||
<key>OpenSourceURL</key>
|
||||
<string>http://ftp.gnu.org/gnu/patch/patch-2.5.8.tar.gz</string>
|
||||
<key>OpenSourceWebsiteURL</key>
|
||||
<string>http://www.gnu.org/software/patch/</string>
|
||||
</dict>
|
||||
</plist>
|
Loading…
Reference in New Issue
Block a user