patch: use the outsourced packages.
* remove patch Jamfile from the build and patch sources from the tree. * added patch to DevelopmentBase. * should a bootstrap package be added?
This commit is contained in:
@@ -118,7 +118,7 @@ if [ IsOptionalHaikuImagePackageAdded DevelopmentBase ] {
|
||||
}
|
||||
|
||||
# other commonly used tools
|
||||
AddHaikuImagePackages bison cdrtools flex jam m4 make mkdepend nasm ;
|
||||
AddHaikuImagePackages bison cdrtools flex jam m4 make mkdepend nasm patch ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ SYSTEM_BIN = [ FFilterByBuildFeatures
|
||||
modifiers mount mountvolume
|
||||
netcat netstat notify
|
||||
open
|
||||
package package_repo passwd patch pc ping ping6 pkgman
|
||||
package package_repo passwd pc ping ping6 pkgman
|
||||
prio profile ps
|
||||
query quit
|
||||
rc reindex release renice rmattr rmindex roster
|
||||
|
||||
@@ -279,7 +279,6 @@ SubInclude HAIKU_TOP src bin mkfs ;
|
||||
SubInclude HAIKU_TOP src bin multiuser ;
|
||||
SubInclude HAIKU_TOP src bin package ;
|
||||
SubInclude HAIKU_TOP src bin package_repo ;
|
||||
SubInclude HAIKU_TOP src bin patch ;
|
||||
SubInclude HAIKU_TOP src bin pc ;
|
||||
SubInclude HAIKU_TOP src bin pcmcia-cs ;
|
||||
SubInclude HAIKU_TOP src bin pkgman ;
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
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) 19yy <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) 19yy 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.
|
||||
@@ -1,24 +0,0 @@
|
||||
SubDir HAIKU_TOP src bin patch ;
|
||||
|
||||
SubDirSysHdrs [ FDirName $(SUBDIR) ] ;
|
||||
|
||||
SubDirCcFlags -DHAVE_CONFIG_H -Ded_PROGRAM='\"ed\"' -w ;
|
||||
|
||||
BinCommand patch :
|
||||
addext.c
|
||||
argmatch.c
|
||||
backupfile.c
|
||||
basename.c
|
||||
error.c
|
||||
inp.c
|
||||
maketime.c
|
||||
partime.c
|
||||
patch.c
|
||||
pch.c
|
||||
quotearg.c
|
||||
quotesys.c
|
||||
util.c
|
||||
version.c
|
||||
xmalloc.c
|
||||
:
|
||||
: patch.rdef ;
|
||||
@@ -1,105 +0,0 @@
|
||||
/* addext.c -- add an extension to a file name
|
||||
Copyright (C) 1990, 1997, 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; 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 <[email protected]> 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
|
||||
|
||||
#include <backupfile.h>
|
||||
|
||||
#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
|
||||
|
||||
char *base_name PARAMS ((char const *));
|
||||
|
||||
/* 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 = strlen (s), extlen = strlen (ext);
|
||||
long slen_max = -1;
|
||||
|
||||
#if HAVE_PATHCONF && defined _PC_NAME_MAX
|
||||
if (slen + extlen <= _POSIX_NAME_MAX && ! HAVE_DOS_FILE_NAMES)
|
||||
/* The file name is so short there's no need to call pathconf. */
|
||||
slen_max = _POSIX_NAME_MAX;
|
||||
else if (s == filename)
|
||||
slen_max = pathconf (".", _PC_NAME_MAX);
|
||||
else
|
||||
{
|
||||
char c = *s;
|
||||
*s = 0;
|
||||
slen_max = pathconf (filename, _PC_NAME_MAX);
|
||||
*s = c;
|
||||
}
|
||||
#endif
|
||||
if (slen_max < 0)
|
||||
slen_max = HAVE_LONG_FILE_NAMES ? 255 : 14;
|
||||
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
@@ -1,306 +0,0 @@
|
||||
/* argmatch.c -- find a match for a string in an array
|
||||
Copyright (C) 1990, 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. */
|
||||
|
||||
/* Written by David MacKenzie <[email protected]>
|
||||
Modified by Akim Demaille <[email protected]> */
|
||||
|
||||
#include "argmatch.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef STDC_HEADERS
|
||||
# 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"
|
||||
|
||||
/* 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_style (ARGMATCH_QUOTING_STYLE, value), 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 <[email protected]>
|
||||
*/
|
||||
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
|
||||
@@ -1,129 +0,0 @@
|
||||
/* argmatch.h -- definitions and prototypes for argmatch.c
|
||||
Copyright (C) 1990, 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. */
|
||||
|
||||
/* Written by David MacKenzie <[email protected]>
|
||||
Modified by Akim Demaille <[email protected]> */
|
||||
|
||||
#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 ((char const *) &(Value), (Arglist), \
|
||||
(const char *) (Vallist), sizeof (*(Vallist)))
|
||||
|
||||
#endif /* ARGMATCH_H_ */
|
||||
@@ -1,268 +0,0 @@
|
||||
/* backupfile.c -- make Emacs style backup file names
|
||||
Copyright (C) 1990-1997, 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; 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 <[email protected]>.
|
||||
Some algorithms adapted from GNU Emacs. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <argmatch.h>
|
||||
#include <backupfile.h>
|
||||
|
||||
#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 STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
char *malloc ();
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DECL_GETENV
|
||||
char *getenv ();
|
||||
#endif
|
||||
|
||||
char *base_name PARAMS ((char const *));
|
||||
|
||||
#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 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
|
||||
only '0' through '9' are digits. Prefer ISDIGIT to isdigit unless
|
||||
it's important to use the locale's definition of `digit' even when the
|
||||
host does not conform to Posix. */
|
||||
#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
|
||||
|
||||
/* 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 + backup_suffix_size_max + numbered_suffix_size_max);
|
||||
if (s)
|
||||
{
|
||||
strcpy (s, file);
|
||||
|
||||
#if HAVE_DIR
|
||||
if (backup_type != simple)
|
||||
{
|
||||
int highest_backup;
|
||||
size_t dir_len = base_name (s) - s;
|
||||
|
||||
strcpy (s + dir_len, ".");
|
||||
highest_backup = max_backup_version (file + dir_len, s);
|
||||
if (! (backup_type == numbered_existing && highest_backup == 0))
|
||||
{
|
||||
char *numbered_suffix = s + (file_len + backup_suffix_size_max);
|
||||
sprintf (numbered_suffix, ".~%d~", highest_backup + 1);
|
||||
suffix = numbered_suffix;
|
||||
}
|
||||
strcpy (s, file);
|
||||
}
|
||||
#endif /* HAVE_DIR */
|
||||
|
||||
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 = strlen (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"));
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/* 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_ */
|
||||
@@ -1,55 +0,0 @@
|
||||
/* basename.c -- return the last element in a path
|
||||
Copyright (C) 1990, 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
|
||||
|
||||
#ifndef FILESYSTEM_PREFIX_LEN
|
||||
# define FILESYSTEM_PREFIX_LEN(Filename) 0
|
||||
#endif
|
||||
|
||||
#ifndef ISSLASH
|
||||
# define ISSLASH(C) ((C) == '/')
|
||||
#endif
|
||||
|
||||
/* 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.
|
||||
If NAME is all slashes, be sure to return `/'. */
|
||||
|
||||
char *
|
||||
base_name (char const *name)
|
||||
{
|
||||
char const *base = name += FILESYSTEM_PREFIX_LEN (name);
|
||||
int all_slashes = 1;
|
||||
char const *p;
|
||||
|
||||
for (p = name; *p; p++)
|
||||
{
|
||||
if (ISSLASH (*p))
|
||||
base = p + 1;
|
||||
else
|
||||
all_slashes = 0;
|
||||
}
|
||||
|
||||
/* If NAME is all slashes, arrange to return `/'. */
|
||||
if (*base == '\0' && ISSLASH (*name) && all_slashes)
|
||||
--base;
|
||||
|
||||
return (char *) base;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#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));
|
||||
@@ -1,328 +0,0 @@
|
||||
/* common definitions for `patch' */
|
||||
|
||||
/* $Id: common.h 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
/* Copyright 1986, 1988 Larry Wall
|
||||
Copyright 1990, 1991-1993, 1997-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; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef DEBUGGING
|
||||
#define DEBUGGING 1
|
||||
#endif
|
||||
|
||||
/* We must define `volatile' and `const' first (the latter inside config.h),
|
||||
so that they're used consistently in all system includes. */
|
||||
#ifndef __STDC__
|
||||
# ifndef volatile
|
||||
# define volatile
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <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
|
||||
|
||||
#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 */
|
||||
|
||||
extern char const program_name[];
|
||||
|
||||
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 */
|
||||
|
||||
#ifdef __STDC__
|
||||
# define GENERIC_OBJECT void
|
||||
#else
|
||||
# define GENERIC_OBJECT char
|
||||
#endif
|
||||
|
||||
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
#endif
|
||||
|
||||
#ifndef PARAMS
|
||||
# ifdef __STDC__
|
||||
# define PARAMS(args) args
|
||||
# else
|
||||
# define PARAMS(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void fatal_exit PARAMS ((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)
|
||||
GENERIC_OBJECT *memchr ();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
char *getenv ();
|
||||
GENERIC_OBJECT *malloc ();
|
||||
GENERIC_OBJECT *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_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
|
||||
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
|
||||
@@ -1,170 +0,0 @@
|
||||
/* config.h. Generated automatically by configure. */
|
||||
/* config.hin. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
/* #undef _ALL_SOURCE */
|
||||
#endif
|
||||
|
||||
/* Define if the closedir function returns void instead of int. */
|
||||
/* #undef CLOSEDIR_VOID */
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define if you don't have vprintf but do have _doprnt. */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define if you support file names longer than 14 characters. */
|
||||
#define HAVE_LONG_FILE_NAMES 1
|
||||
|
||||
/* Define if you have the vprintf function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define if on MINIX. */
|
||||
/* #undef _MINIX */
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef mode_t */
|
||||
|
||||
/* Define to `long' if <sys/types.h> doesn't define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef pid_t */
|
||||
|
||||
/* Define if the system does not provide POSIX.1 features except
|
||||
with this defined. */
|
||||
/* #undef _POSIX_1_SOURCE */
|
||||
|
||||
/* Define if you need to in order for stat and other things to work. */
|
||||
/* #undef _POSIX_SOURCE */
|
||||
|
||||
/* Define as the return type of signal handlers (int or void). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> doesn't define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define if you have the _doprintf function. */
|
||||
/* #undef HAVE__DOPRINTF */
|
||||
|
||||
/* Define if you have the fseeko function. */
|
||||
#define HAVE_FSEEKO 1
|
||||
|
||||
/* Define if you have the isascii function. */
|
||||
#define HAVE_ISASCII 1
|
||||
|
||||
/* Define if you have the memchr function. */
|
||||
#define HAVE_MEMCHR 1
|
||||
|
||||
/* Define if you have the memcmp function. */
|
||||
#define HAVE_MEMCMP 1
|
||||
|
||||
/* Define if you have the mkdir function. */
|
||||
#define HAVE_MKDIR 1
|
||||
|
||||
/* Define if you have the mktemp function. */
|
||||
#define HAVE_MKTEMP 1
|
||||
|
||||
/* Define if you have the pathconf function. */
|
||||
#define HAVE_PATHCONF 1
|
||||
|
||||
/* Define if you have the raise function. */
|
||||
#define HAVE_RAISE 1
|
||||
|
||||
/* Define if you have the rename function. */
|
||||
#define HAVE_RENAME 1
|
||||
|
||||
/* Define if you have the rmdir function. */
|
||||
#define HAVE_RMDIR 1
|
||||
|
||||
/* Define if you have the setmode function. */
|
||||
/* #undef HAVE_SETMODE */
|
||||
|
||||
/* Define if you have the sigaction function. */
|
||||
#define HAVE_SIGACTION 1
|
||||
|
||||
/* Define if you have the sigprocmask function. */
|
||||
#define HAVE_SIGPROCMASK 1
|
||||
|
||||
/* Define if you have the sigsetmask function. */
|
||||
/* #undef HAVE_SIGSETMASK */
|
||||
|
||||
/* Define if you have the strerror function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define if you have the <dirent.h> header file. */
|
||||
#define HAVE_DIRENT_H 1
|
||||
|
||||
/* Define if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define if you have the <ndir.h> header file. */
|
||||
/* #undef HAVE_NDIR_H */
|
||||
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define if you have the <sys/dir.h> header file. */
|
||||
/* #undef HAVE_SYS_DIR_H */
|
||||
|
||||
/* Define if you have the <sys/ndir.h> header file. */
|
||||
/* #undef HAVE_SYS_NDIR_H */
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define if you have the <utime.h> header file. */
|
||||
#define HAVE_UTIME_H 1
|
||||
|
||||
/* Define if you have the <varargs.h> header file. */
|
||||
#define HAVE_VARARGS_H 1
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
/* #undef _FILE_OFFSET_BITS */
|
||||
|
||||
/* Define to make fseeko etc. visible, on some hosts. */
|
||||
/* #undef _LARGEFILE_SOURCE */
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
/* #undef _LARGE_FILES */
|
||||
|
||||
/* Define if compiler has function prototypes */
|
||||
#define PROTOTYPES 1
|
||||
|
||||
/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,
|
||||
and declares uintmax_t. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define if struct utimbuf is declared -- usually in <utime.h>.
|
||||
Some systems have utime.h but don't declare the struct anywhere. */
|
||||
#define HAVE_STRUCT_UTIMBUF 1
|
||||
|
||||
/* Define if the malloc check has been performed. */
|
||||
#define HAVE_DONE_WORKING_MALLOC_CHECK 1
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define if the realloc check has been performed. */
|
||||
#define HAVE_DONE_WORKING_REALLOC_CHECK 1
|
||||
|
||||
/* Define to rpl_realloc if the replacement function should be used. */
|
||||
/* #undef realloc */
|
||||
|
||||
/* Define if there is a member named d_ino in the struct describing
|
||||
directory headers. */
|
||||
#define D_INO_IN_DIRENT 1
|
||||
|
||||
@@ -1,250 +0,0 @@
|
||||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990,91,92,93,94,95,96,97,98 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.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <[email protected]>. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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"
|
||||
|
||||
#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. */
|
||||
# define error __error
|
||||
# define error_at_line __error_at_line
|
||||
|
||||
#else /* not _LIBC */
|
||||
|
||||
/* The calling program should define program_name and set it to the
|
||||
name of the executing program. */
|
||||
extern char *program_name;
|
||||
|
||||
# ifdef HAVE_STRERROR_R
|
||||
# define __strerror_r strerror_r
|
||||
# else
|
||||
# if HAVE_STRERROR
|
||||
# ifndef strerror /* On some systems, strerror is a macro */
|
||||
char *strerror ();
|
||||
# endif
|
||||
# else
|
||||
static char *
|
||||
private_strerror (errnum)
|
||||
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 */
|
||||
#endif /* not _LIBC */
|
||||
|
||||
/* 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
|
||||
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
fflush (stdout);
|
||||
fprintf (stderr, "%s: ", program_name);
|
||||
}
|
||||
|
||||
#ifdef VA_START
|
||||
VA_START (args, message);
|
||||
# if HAVE_VPRINTF || _LIBC
|
||||
vfprintf (stderr, message, args);
|
||||
# else
|
||||
_doprnt (message, args, stderr);
|
||||
# endif
|
||||
va_end (args);
|
||||
#else
|
||||
fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
#endif
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
{
|
||||
#if defined HAVE_STRERROR_R || defined _LIBC
|
||||
char errbuf[1024];
|
||||
/* Don't use __strerror_r's return value because on some systems
|
||||
(at least DEC UNIX 4.0[A-D]) strerror_r returns `int'. */
|
||||
__strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
fprintf (stderr, ": %s", errbuf);
|
||||
#else
|
||||
fprintf (stderr, ": %s", strerror (errnum));
|
||||
#endif
|
||||
}
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
/* 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)))
|
||||
/* Simply return and print nothing. */
|
||||
return;
|
||||
|
||||
old_file_name = file_name;
|
||||
old_line_number = line_number;
|
||||
}
|
||||
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
fflush (stdout);
|
||||
fprintf (stderr, "%s:", program_name);
|
||||
}
|
||||
|
||||
if (file_name != NULL)
|
||||
fprintf (stderr, "%s:%d: ", file_name, line_number);
|
||||
|
||||
#ifdef VA_START
|
||||
VA_START (args, message);
|
||||
# if HAVE_VPRINTF || _LIBC
|
||||
vfprintf (stderr, message, args);
|
||||
# else
|
||||
_doprnt (message, args, stderr);
|
||||
# endif
|
||||
va_end (args);
|
||||
#else
|
||||
fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
#endif
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
{
|
||||
#if defined HAVE_STRERROR_R || defined _LIBC
|
||||
char errbuf[1024];
|
||||
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
|
||||
#else
|
||||
fprintf (stderr, ": %s", strerror (errnum));
|
||||
#endif
|
||||
}
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -1,78 +0,0 @@
|
||||
/* 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 [email protected].
|
||||
|
||||
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) || __STRICT_ANSI__
|
||||
# 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 */
|
||||
@@ -1,467 +0,0 @@
|
||||
/* inputting files to be patched */
|
||||
|
||||
/* $Id: inp.c 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
/* Copyright 1986, 1988 Larry Wall
|
||||
Copyright 1991, 1992-1993, 1997-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; 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 PARAMS ((char const *));/* yield FALSE if memory runs out */
|
||||
static void plan_b PARAMS ((char const *));
|
||||
static void report_revision PARAMS ((int));
|
||||
static void too_many_lines PARAMS ((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)
|
||||
{
|
||||
revision = quotearg (revision);
|
||||
|
||||
if (found_revision)
|
||||
{
|
||||
if (verbosity == VERBOSE)
|
||||
say ("Good. This file appears to be the %s version.\n", revision);
|
||||
}
|
||||
else if (force)
|
||||
{
|
||||
if (verbosity != SILENT)
|
||||
say ("Warning: this file doesn't appear to be the %s version -- patching anyway.\n",
|
||||
revision);
|
||||
}
|
||||
else if (batch)
|
||||
fatal ("This file doesn't appear to be the %s version -- aborting.",
|
||||
revision);
|
||||
else
|
||||
{
|
||||
ask ("This file doesn't appear to be the %s version -- patch anyway? [n] ",
|
||||
revision);
|
||||
if (*buf != 'y')
|
||||
fatal ("aborted");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/* inputting files to be patched */
|
||||
|
||||
/* $Id: inp.h 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
XTERN LINENUM input_lines; /* how long is input file in lines */
|
||||
|
||||
char const *ifetch PARAMS ((LINENUM, int, size_t *));
|
||||
void get_input_file PARAMS ((char const *, char const *));
|
||||
void re_input PARAMS ((void));
|
||||
void scan_input PARAMS ((char *));
|
||||
@@ -1,501 +0,0 @@
|
||||
/* 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:
|
||||
|
||||
[email protected]
|
||||
|
||||
*/
|
||||
|
||||
/* 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 8008 2004-06-16 21:22:10Z korli $";
|
||||
|
||||
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
|
||||
@@ -1,39 +0,0 @@
|
||||
/* 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));
|
||||
@@ -1,956 +0,0 @@
|
||||
/* 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
|
||||
|
||||
*/
|
||||
|
||||
#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 8008 2004-06-16 21:22:10Z korli $";
|
||||
|
||||
|
||||
/* 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++;
|
||||
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;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/* 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 *));
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
resource app_version
|
||||
{
|
||||
major = 2,
|
||||
middle = 5,
|
||||
minor = 4,
|
||||
variety = 5,
|
||||
internal = 0,
|
||||
short_info = "2.5.4",
|
||||
long_info = "2.5.4 ©1999 The Free Software Foundation"
|
||||
};
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#define PATCH_VERSION "2.5.4"
|
||||
-1913
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
||||
/* reading patches */
|
||||
|
||||
/* $Id: pch.h 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
LINENUM pch_end PARAMS ((void));
|
||||
LINENUM pch_first PARAMS ((void));
|
||||
LINENUM pch_hunk_beg PARAMS ((void));
|
||||
LINENUM pch_newfirst PARAMS ((void));
|
||||
LINENUM pch_prefix_context PARAMS ((void));
|
||||
LINENUM pch_ptrn_lines PARAMS ((void));
|
||||
LINENUM pch_repl_lines PARAMS ((void));
|
||||
LINENUM pch_suffix_context PARAMS ((void));
|
||||
bool pch_swap PARAMS ((void));
|
||||
bool pch_write_line PARAMS ((LINENUM, FILE *));
|
||||
bool there_is_another_patch PARAMS ((void));
|
||||
char *pfetch PARAMS ((LINENUM));
|
||||
char pch_char PARAMS ((LINENUM));
|
||||
int another_hunk PARAMS ((enum diff, int));
|
||||
int pch_says_nonexistent PARAMS ((int));
|
||||
size_t pch_line_len PARAMS ((LINENUM));
|
||||
time_t pch_timestamp PARAMS ((int));
|
||||
void do_ed_script PARAMS ((FILE *));
|
||||
void open_patch_file PARAMS ((char const *));
|
||||
void re_patch PARAMS ((void));
|
||||
void set_hunkmax PARAMS ((void));
|
||||
@@ -1,403 +0,0 @@
|
||||
/* quotearg.c - quote arguments for output
|
||||
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. */
|
||||
|
||||
/* Written by Paul Eggert <[email protected]> */
|
||||
|
||||
/* FIXME: Multibyte characters are not supported yet. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <quotearg.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define ISASCII(c) 1
|
||||
#else
|
||||
# define ISASCII(c) isascii (c)
|
||||
#endif
|
||||
#ifdef isgraph
|
||||
# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
|
||||
#else
|
||||
# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
|
||||
#endif
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(text) gettext (text)
|
||||
#else
|
||||
# define _(text) text
|
||||
#endif
|
||||
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
#ifndef UCHAR_MAX
|
||||
# define UCHAR_MAX ((unsigned char) -1)
|
||||
#endif
|
||||
|
||||
#if HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#define INT_BITS (sizeof (int) * CHAR_BIT)
|
||||
|
||||
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 + 1) / INT_BITS
|
||||
+ ((UCHAR_MAX + 1) % INT_BITS != 0))];
|
||||
};
|
||||
|
||||
/* Names of quoting styles. */
|
||||
char const *const quoting_style_args[] =
|
||||
{
|
||||
"literal",
|
||||
"shell",
|
||||
"shell-always",
|
||||
"c",
|
||||
"escape",
|
||||
"locale",
|
||||
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
|
||||
};
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
unsigned char c;
|
||||
size_t i;
|
||||
size_t len = 0;
|
||||
char const *quote_string;
|
||||
size_t quote_string_len;
|
||||
struct quoting_options const *p = o ? o : &default_quoting_options;
|
||||
enum quoting_style quoting_style = p->style;
|
||||
#define STORE(c) \
|
||||
do \
|
||||
{ \
|
||||
if (len < buffersize) \
|
||||
buffer[len] = (c); \
|
||||
len++; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
switch (quoting_style)
|
||||
{
|
||||
case shell_quoting_style:
|
||||
if (! (argsize == (size_t) -1 ? arg[0] == '\0' : argsize == 0))
|
||||
{
|
||||
switch (arg[0])
|
||||
{
|
||||
case '#': case '~':
|
||||
break;
|
||||
|
||||
default:
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
if (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize)
|
||||
goto done;
|
||||
|
||||
c = arg[i];
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\t': case '\n': case ' ':
|
||||
case '!': /* special in csh */
|
||||
case '"': case '$': case '&': case '\'':
|
||||
case '(': case ')': case '*': case ';':
|
||||
case '<': case '>': case '?': case '[': case '\\':
|
||||
case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
|
||||
case '`': case '|':
|
||||
goto needs_quoting;
|
||||
}
|
||||
|
||||
if (p->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS)))
|
||||
goto needs_quoting;
|
||||
|
||||
STORE (c);
|
||||
}
|
||||
needs_quoting:;
|
||||
|
||||
len = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Fall through. */
|
||||
|
||||
case shell_always_quoting_style:
|
||||
STORE ('\'');
|
||||
quote_string = "'";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
case c_quoting_style:
|
||||
STORE ('"');
|
||||
quote_string = "\"";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
case locale_quoting_style:
|
||||
for (quote_string = _("`"); *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
quote_string = _("'");
|
||||
quote_string_len = strlen (quote_string);
|
||||
break;
|
||||
|
||||
default:
|
||||
quote_string = 0;
|
||||
quote_string_len = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; ! (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize); i++)
|
||||
{
|
||||
c = arg[i];
|
||||
|
||||
switch (quoting_style)
|
||||
{
|
||||
case literal_quoting_style:
|
||||
break;
|
||||
|
||||
case shell_quoting_style:
|
||||
case shell_always_quoting_style:
|
||||
if (c == '\'')
|
||||
{
|
||||
STORE ('\'');
|
||||
STORE ('\\');
|
||||
STORE ('\'');
|
||||
}
|
||||
break;
|
||||
|
||||
case c_quoting_style:
|
||||
case escape_quoting_style:
|
||||
case locale_quoting_style:
|
||||
switch (c)
|
||||
{
|
||||
case '?': /* Do not generate trigraphs. */
|
||||
case '\\': goto store_escape;
|
||||
/* Not all C compilers know what \a means. */
|
||||
case 7 : c = 'a'; goto store_escape;
|
||||
case '\b': c = 'b'; goto store_escape;
|
||||
case '\f': c = 'f'; goto store_escape;
|
||||
case '\n': c = 'n'; goto store_escape;
|
||||
case '\r': c = 'r'; goto store_escape;
|
||||
case '\t': c = 't'; goto store_escape;
|
||||
case '\v': c = 'v'; goto store_escape;
|
||||
|
||||
case ' ': break;
|
||||
|
||||
default:
|
||||
if (quote_string_len
|
||||
&& strncmp (arg + i, quote_string, quote_string_len) == 0)
|
||||
goto store_escape;
|
||||
if (!ISGRAPH (c))
|
||||
{
|
||||
STORE ('\\');
|
||||
STORE ('0' + (c >> 6));
|
||||
STORE ('0' + ((c >> 3) & 7));
|
||||
c = '0' + (c & 7);
|
||||
goto store_c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (! (p->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);
|
||||
|
||||
done:
|
||||
if (len < buffersize)
|
||||
buffer[len] = '\0';
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Use storage slot N to return a quoted version of the string ARG.
|
||||
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,
|
||||
struct quoting_options const *options)
|
||||
{
|
||||
static unsigned int nslots;
|
||||
static struct slotvec
|
||||
{
|
||||
size_t size;
|
||||
char *val;
|
||||
} *slotvec;
|
||||
|
||||
if (nslots <= n)
|
||||
{
|
||||
int n1 = n + 1;
|
||||
size_t s = n1 * sizeof (struct slotvec);
|
||||
if (! (0 < n1 && n1 == s / sizeof (struct slotvec)))
|
||||
abort ();
|
||||
slotvec = (struct slotvec *) xrealloc (slotvec, s);
|
||||
memset (slotvec + nslots, 0, (n1 - nslots) * sizeof (struct slotvec));
|
||||
nslots = n;
|
||||
}
|
||||
|
||||
{
|
||||
size_t size = slotvec[n].size;
|
||||
char *val = slotvec[n].val;
|
||||
size_t qsize = quotearg_buffer (val, size, arg, (size_t) -1, options);
|
||||
|
||||
if (size <= qsize)
|
||||
{
|
||||
slotvec[n].size = size = qsize + 1;
|
||||
slotvec[n].val = val = xrealloc (val, size);
|
||||
quotearg_buffer (val, size, arg, (size_t) -1, options);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n (unsigned int n, char const *arg)
|
||||
{
|
||||
return quotearg_n_options (n, arg, &default_quoting_options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg (char const *arg)
|
||||
{
|
||||
return quotearg_n (0, arg);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n_style (unsigned int n, enum quoting_style s, char const *arg)
|
||||
{
|
||||
struct quoting_options o;
|
||||
o.style = s;
|
||||
memset (o.quote_these_too, 0, sizeof o.quote_these_too);
|
||||
return quotearg_n_options (n, arg, &o);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_style (enum quoting_style s, char const *arg)
|
||||
{
|
||||
return quotearg_n_style (0, s, arg);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_char (char const *arg, char ch)
|
||||
{
|
||||
struct quoting_options options;
|
||||
options = default_quoting_options;
|
||||
set_char_quoting (&options, ch, 1);
|
||||
return quotearg_n_options (0, arg, &options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_colon (char const *arg)
|
||||
{
|
||||
return quotearg_char (arg, ':');
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/* quotearg.h - quote arguments for output
|
||||
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. */
|
||||
|
||||
/* Written by Paul Eggert <[email protected]> */
|
||||
|
||||
/* 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 */
|
||||
};
|
||||
|
||||
/* 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 ((unsigned 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 ((unsigned int n, enum quoting_style s,
|
||||
char const *arg));
|
||||
|
||||
/* 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));
|
||||
@@ -1,125 +0,0 @@
|
||||
/* 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 <[email protected]> */
|
||||
|
||||
#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++;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/* 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 *));
|
||||
@@ -1,996 +0,0 @@
|
||||
/* utility functions for `patch' */
|
||||
|
||||
/* $Id: util.c 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
/* Copyright 1986 Larry Wall
|
||||
Copyright 1992, 1993, 1997-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; 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 <basename.h>
|
||||
#include <quotearg.h>
|
||||
#include <quotesys.h>
|
||||
#include <version.h>
|
||||
#undef XTERN
|
||||
#define XTERN
|
||||
#include <util.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include <maketime.h>
|
||||
#include <partime.h>
|
||||
|
||||
#include <signal.h>
|
||||
#if !defined SIGCHLD && defined SIGCLD
|
||||
#define SIGCHLD SIGCLD
|
||||
#endif
|
||||
#if ! HAVE_RAISE && ! defined raise
|
||||
# define raise(sig) kill (getpid (), sig)
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
# include <stdarg.h>
|
||||
# define vararg_start va_start
|
||||
#else
|
||||
# define vararg_start(ap,p) va_start (ap)
|
||||
# if HAVE_VARARGS_H
|
||||
# include <varargs.h>
|
||||
# else
|
||||
typedef char *va_list;
|
||||
# define va_dcl int va_alist;
|
||||
# define va_start(ap) ((ap) = (va_list) &va_alist)
|
||||
# define va_arg(ap, t) (((t *) ((ap) += sizeof (t))) [-1])
|
||||
# define va_end(ap)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static void makedirs PARAMS ((char *));
|
||||
|
||||
/* Move a file FROM (where *FROM_NEEDS_REMOVAL is nonzero if FROM
|
||||
needs removal when cleaning up at the end of execution)
|
||||
to TO, renaming it if possible and copying it if necessary.
|
||||
If we must create TO, use MODE to create it.
|
||||
If FROM is null, remove TO (ignoring FROMSTAT).
|
||||
FROM_NEEDS_REMOVAL must be nonnull if FROM is nonnull.
|
||||
Back up TO if BACKUP is nonzero. */
|
||||
|
||||
void
|
||||
move_file (char const *from, int volatile *from_needs_removal,
|
||||
char *to, mode_t mode, int backup)
|
||||
{
|
||||
struct stat to_st;
|
||||
int to_errno = ! backup ? -1 : stat (to, &to_st) == 0 ? 0 : errno;
|
||||
|
||||
if (backup)
|
||||
{
|
||||
int try_makedirs_errno = 0;
|
||||
char *bakname;
|
||||
|
||||
if (origprae || origbase)
|
||||
{
|
||||
char const *p = origprae ? origprae : "";
|
||||
char const *b = origbase ? origbase : "";
|
||||
char const *o = base_name (to);
|
||||
size_t plen = strlen (p);
|
||||
size_t tlen = o - to;
|
||||
size_t blen = strlen (b);
|
||||
size_t osize = strlen (o) + 1;
|
||||
bakname = xmalloc (plen + tlen + blen + osize);
|
||||
memcpy (bakname, p, plen);
|
||||
memcpy (bakname + plen, to, tlen);
|
||||
memcpy (bakname + plen + tlen, b, blen);
|
||||
memcpy (bakname + plen + tlen + blen, o, osize);
|
||||
for (p += FILESYSTEM_PREFIX_LEN (p); *p; p++)
|
||||
if (ISSLASH (*p))
|
||||
{
|
||||
try_makedirs_errno = ENOENT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bakname = find_backup_file_name (to, backup_type);
|
||||
if (!bakname)
|
||||
memory_fatal ();
|
||||
}
|
||||
|
||||
if (to_errno)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (debug & 4)
|
||||
say ("Creating empty unreadable file %s\n", quotearg (bakname));
|
||||
|
||||
try_makedirs_errno = ENOENT;
|
||||
unlink (bakname);
|
||||
while ((fd = creat (bakname, 0)) < 0)
|
||||
{
|
||||
if (errno != try_makedirs_errno)
|
||||
pfatal ("Can't create file %s", quotearg (bakname));
|
||||
makedirs (bakname);
|
||||
try_makedirs_errno = 0;
|
||||
}
|
||||
if (close (fd) != 0)
|
||||
pfatal ("Can't close file %s", quotearg (bakname));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (debug & 4)
|
||||
say ("Renaming file %s to %s\n",
|
||||
quotearg_n (0, to), quotearg_n (1, bakname));
|
||||
while (rename (to, bakname) != 0)
|
||||
{
|
||||
if (errno != try_makedirs_errno)
|
||||
pfatal ("Can't rename file %s to %s",
|
||||
quotearg_n (0, to), quotearg_n (1, bakname));
|
||||
makedirs (bakname);
|
||||
try_makedirs_errno = 0;
|
||||
}
|
||||
}
|
||||
|
||||
free (bakname);
|
||||
}
|
||||
|
||||
if (from)
|
||||
{
|
||||
if (debug & 4)
|
||||
say ("Renaming file %s to %s\n",
|
||||
quotearg_n (0, from), quotearg_n (1, to));
|
||||
|
||||
if (rename (from, to) == 0)
|
||||
*from_needs_removal = 0;
|
||||
else
|
||||
{
|
||||
int to_dir_known_to_exist = 0;
|
||||
|
||||
if (errno == ENOENT
|
||||
&& (to_errno == -1 || to_errno == ENOENT))
|
||||
{
|
||||
makedirs (to);
|
||||
to_dir_known_to_exist = 1;
|
||||
if (rename (from, to) == 0)
|
||||
{
|
||||
*from_needs_removal = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (errno == EXDEV)
|
||||
{
|
||||
if (! backup)
|
||||
{
|
||||
if (unlink (to) == 0)
|
||||
to_dir_known_to_exist = 1;
|
||||
else if (errno != ENOENT)
|
||||
pfatal ("Can't remove file %s", quotearg (to));
|
||||
}
|
||||
if (! to_dir_known_to_exist)
|
||||
makedirs (to);
|
||||
copy_file (from, to, 0, mode);
|
||||
return;
|
||||
}
|
||||
|
||||
pfatal ("Can't rename file %s to %s",
|
||||
quotearg_n (0, from), quotearg_n (1, to));
|
||||
}
|
||||
}
|
||||
else if (! backup)
|
||||
{
|
||||
if (debug & 4)
|
||||
say ("Removing file %s\n", quotearg (to));
|
||||
if (unlink (to) != 0)
|
||||
pfatal ("Can't remove file %s", quotearg (to));
|
||||
}
|
||||
}
|
||||
|
||||
/* Create FILE with OPEN_FLAGS, and with MODE adjusted so that
|
||||
we can read and write the file and that the file is not executable.
|
||||
Return the file descriptor. */
|
||||
int
|
||||
create_file (char const *file, int open_flags, mode_t mode)
|
||||
{
|
||||
int fd;
|
||||
mode |= S_IRUSR | S_IWUSR;
|
||||
mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH);
|
||||
if (! (O_CREAT && O_TRUNC))
|
||||
close (creat (file, mode));
|
||||
fd = open (file, O_CREAT | O_TRUNC | open_flags, mode);
|
||||
if (fd < 0)
|
||||
pfatal ("Can't create file %s", quotearg (file));
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Copy a file. */
|
||||
|
||||
void
|
||||
copy_file (char const *from, char const *to, int to_flags, mode_t mode)
|
||||
{
|
||||
int tofd;
|
||||
int fromfd;
|
||||
size_t i;
|
||||
|
||||
if ((fromfd = open (from, O_RDONLY | O_BINARY)) < 0)
|
||||
pfatal ("Can't reopen file %s", quotearg (from));
|
||||
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode);
|
||||
while ((i = read (fromfd, buf, bufsize)) != 0)
|
||||
{
|
||||
if (i == (size_t) -1)
|
||||
read_fatal ();
|
||||
if (write (tofd, buf, i) != i)
|
||||
write_fatal ();
|
||||
}
|
||||
if (close (fromfd) != 0)
|
||||
read_fatal ();
|
||||
if (close (tofd) != 0)
|
||||
write_fatal ();
|
||||
}
|
||||
|
||||
static char const DEV_NULL[] = NULL_DEVICE;
|
||||
|
||||
static char const RCSSUFFIX[] = ",v";
|
||||
static char const CHECKOUT[] = "co %s";
|
||||
static char const CHECKOUT_LOCKED[] = "co -l %s";
|
||||
static char const RCSDIFF1[] = "rcsdiff %s";
|
||||
|
||||
static char const SCCSPREFIX[] = "s.";
|
||||
static char const GET[] = "get ";
|
||||
static char const GET_LOCKED[] = "get -e ";
|
||||
static char const SCCSDIFF1[] = "get -p ";
|
||||
static char const SCCSDIFF2[] = "|diff - %s";
|
||||
|
||||
static char const CLEARTOOL_CO[] = "cleartool co -unr -nc ";
|
||||
|
||||
/* Return "RCS" if FILENAME is controlled by RCS,
|
||||
"SCCS" if it is controlled by SCCS,
|
||||
"ClearCase" if it is controlled by Clearcase, and 0 otherwise.
|
||||
READONLY is nonzero if we desire only readonly access to FILENAME.
|
||||
FILESTAT describes FILENAME's status or is 0 if FILENAME does not exist.
|
||||
If successful and if GETBUF is nonzero, set *GETBUF to a command
|
||||
that gets the file; similarly for DIFFBUF and a command to diff the file
|
||||
(but set *DIFFBUF to 0 if the diff operation is meaningless).
|
||||
*GETBUF and *DIFFBUF must be freed by the caller. */
|
||||
char const *
|
||||
version_controller (char const *filename, int readonly,
|
||||
struct stat const *filestat, char **getbuf, char **diffbuf)
|
||||
{
|
||||
struct stat cstat;
|
||||
char const *filebase = base_name (filename);
|
||||
char const *dotslash = *filename == '-' ? "./" : "";
|
||||
size_t dir_len = filebase - filename;
|
||||
size_t filenamelen = strlen (filename);
|
||||
size_t maxfixlen = sizeof "SCCS/" - 1 + sizeof SCCSPREFIX - 1;
|
||||
size_t maxtrysize = filenamelen + maxfixlen + 1;
|
||||
size_t quotelen = quote_system_arg (0, filename);
|
||||
size_t maxgetsize = sizeof CLEARTOOL_CO + quotelen + maxfixlen;
|
||||
size_t maxdiffsize =
|
||||
(sizeof SCCSDIFF1 + sizeof SCCSDIFF2 + sizeof DEV_NULL - 1
|
||||
+ 2 * quotelen + maxfixlen);
|
||||
char *trybuf = xmalloc (maxtrysize);
|
||||
char const *r = 0;
|
||||
|
||||
strcpy (trybuf, filename);
|
||||
|
||||
#define try1(f,a1) (sprintf (trybuf + dir_len, f, a1), stat (trybuf, &cstat) == 0)
|
||||
#define try2(f,a1,a2) (sprintf (trybuf + dir_len, f, a1,a2), stat (trybuf, &cstat) == 0)
|
||||
|
||||
/* Check that RCS file is not working file.
|
||||
Some hosts don't report file name length errors. */
|
||||
|
||||
if ((try2 ("RCS/%s%s", filebase, RCSSUFFIX)
|
||||
|| try1 ("RCS/%s", filebase)
|
||||
|| try2 ("%s%s", filebase, RCSSUFFIX))
|
||||
&& ! (filestat
|
||||
&& filestat->st_dev == cstat.st_dev
|
||||
&& filestat->st_ino == cstat.st_ino))
|
||||
{
|
||||
if (getbuf)
|
||||
{
|
||||
char *p = *getbuf = xmalloc (maxgetsize);
|
||||
sprintf (p, readonly ? CHECKOUT : CHECKOUT_LOCKED, dotslash);
|
||||
p += strlen (p);
|
||||
p += quote_system_arg (p, filename);
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
if (diffbuf)
|
||||
{
|
||||
char *p = *diffbuf = xmalloc (maxdiffsize);
|
||||
sprintf (p, RCSDIFF1, dotslash);
|
||||
p += strlen (p);
|
||||
p += quote_system_arg (p, filename);
|
||||
*p++ = '>';
|
||||
strcpy (p, DEV_NULL);
|
||||
}
|
||||
|
||||
r = "RCS";
|
||||
}
|
||||
else if (try2 ("SCCS/%s%s", SCCSPREFIX, filebase)
|
||||
|| try2 ("%s%s", SCCSPREFIX, filebase))
|
||||
{
|
||||
if (getbuf)
|
||||
{
|
||||
char *p = *getbuf = xmalloc (maxgetsize);
|
||||
sprintf (p, readonly ? GET : GET_LOCKED);
|
||||
p += strlen (p);
|
||||
p += quote_system_arg (p, trybuf);
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
if (diffbuf)
|
||||
{
|
||||
char *p = *diffbuf = xmalloc (maxdiffsize);
|
||||
strcpy (p, SCCSDIFF1);
|
||||
p += sizeof SCCSDIFF1 - 1;
|
||||
p += quote_system_arg (p, trybuf);
|
||||
sprintf (p, SCCSDIFF2, dotslash);
|
||||
p += strlen (p);
|
||||
p += quote_system_arg (p, filename);
|
||||
*p++ = '>';
|
||||
strcpy (p, DEV_NULL);
|
||||
}
|
||||
|
||||
r = "SCCS";
|
||||
}
|
||||
else if (!readonly && filestat
|
||||
&& try1 ("%s@@", filebase) && S_ISDIR (cstat.st_mode))
|
||||
{
|
||||
if (getbuf)
|
||||
{
|
||||
char *p = *getbuf = xmalloc (maxgetsize);
|
||||
strcpy (p, CLEARTOOL_CO);
|
||||
p += sizeof CLEARTOOL_CO - 1;
|
||||
p += quote_system_arg (p, filename);
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
if (diffbuf)
|
||||
*diffbuf = 0;
|
||||
|
||||
r = "ClearCase";
|
||||
}
|
||||
|
||||
free (trybuf);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Get FILENAME from version control system CS. The file already exists if
|
||||
EXISTS is nonzero. Only readonly access is needed if READONLY is nonzero.
|
||||
Use the command GETBUF to actually get the named file.
|
||||
Store the resulting file status into *FILESTAT.
|
||||
Return nonzero if successful. */
|
||||
int
|
||||
version_get (char const *filename, char const *cs, int exists, int readonly,
|
||||
char const *getbuf, struct stat *filestat)
|
||||
{
|
||||
if (patch_get < 0)
|
||||
{
|
||||
ask ("Get file %s from %s%s? [y] ",
|
||||
quotearg (filename), cs, readonly ? "" : " with lock");
|
||||
if (*buf == 'n')
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dry_run)
|
||||
{
|
||||
if (! exists)
|
||||
fatal ("can't do dry run on nonexistent version-controlled file %s; invoke `%s' and try again",
|
||||
quotearg (filename), getbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbosity == VERBOSE)
|
||||
say ("Getting file %s from %s%s...\n", quotearg (filename),
|
||||
cs, readonly ? "" : " with lock");
|
||||
if (systemic (getbuf) != 0)
|
||||
fatal ("Can't get file %s from %s", quotearg (filename), cs);
|
||||
if (stat (filename, filestat) != 0)
|
||||
pfatal ("%s", quotearg (filename));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Allocate a unique area for a string. */
|
||||
|
||||
char *
|
||||
savebuf (register char const *s, register size_t size)
|
||||
{
|
||||
register char *rv;
|
||||
|
||||
assert (s && size);
|
||||
rv = malloc (size);
|
||||
|
||||
if (! rv)
|
||||
{
|
||||
if (! using_plan_a)
|
||||
memory_fatal ();
|
||||
}
|
||||
else
|
||||
memcpy (rv, s, size);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *
|
||||
savestr (char const *s)
|
||||
{
|
||||
return savebuf (s, strlen (s) + 1);
|
||||
}
|
||||
|
||||
void
|
||||
remove_prefix (char *p, size_t prefixlen)
|
||||
{
|
||||
char const *s = p + prefixlen;
|
||||
while ((*p++ = *s++))
|
||||
continue;
|
||||
}
|
||||
|
||||
char *
|
||||
format_linenum (char numbuf[LINENUM_LENGTH_BOUND + 1], LINENUM n)
|
||||
{
|
||||
char *p = numbuf + LINENUM_LENGTH_BOUND;
|
||||
*p = '\0';
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
do
|
||||
*--p = '0' - (int) (n % 10);
|
||||
while ((n /= 10) != 0);
|
||||
|
||||
*--p = '-';
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
*--p = '0' + (int) (n % 10);
|
||||
while ((n /= 10) != 0);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#if !HAVE_VPRINTF
|
||||
#define vfprintf my_vfprintf
|
||||
static int
|
||||
vfprintf (FILE *stream, char const *format, va_list args)
|
||||
{
|
||||
#if !HAVE_DOPRNT && HAVE__DOPRINTF
|
||||
# define _doprnt _doprintf
|
||||
#endif
|
||||
#if HAVE_DOPRNT || HAVE__DOPRINTF
|
||||
_doprnt (format, args, stream);
|
||||
return ferror (stream) ? -1 : 0;
|
||||
#else
|
||||
int *a = (int *) args;
|
||||
return fprintf (stream, format,
|
||||
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
|
||||
#endif
|
||||
}
|
||||
#endif /* !HAVE_VPRINTF */
|
||||
|
||||
/* Terminal output, pun intended. */
|
||||
|
||||
void
|
||||
fatal (char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
fprintf (stderr, "%s: **** ", program_name);
|
||||
vararg_start (args, format);
|
||||
vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
fatal_exit (0);
|
||||
}
|
||||
|
||||
void
|
||||
memory_fatal (void)
|
||||
{
|
||||
fatal ("out of memory");
|
||||
}
|
||||
|
||||
void
|
||||
read_fatal (void)
|
||||
{
|
||||
pfatal ("read error");
|
||||
}
|
||||
|
||||
void
|
||||
write_fatal (void)
|
||||
{
|
||||
pfatal ("write error");
|
||||
}
|
||||
|
||||
/* Say something from patch, something from the system, then silence . . . */
|
||||
|
||||
void
|
||||
pfatal (char const *format, ...)
|
||||
{
|
||||
int errnum = errno;
|
||||
va_list args;
|
||||
fprintf (stderr, "%s: **** ", program_name);
|
||||
vararg_start (args, format);
|
||||
vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
fflush (stderr); /* perror bypasses stdio on some hosts. */
|
||||
errno = errnum;
|
||||
perror (" ");
|
||||
fflush (stderr);
|
||||
fatal_exit (0);
|
||||
}
|
||||
|
||||
/* Tell the user something. */
|
||||
|
||||
void
|
||||
say (char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
vararg_start (args, format);
|
||||
vfprintf (stdout, format, args);
|
||||
va_end (args);
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
/* Get a response from the user, somehow or other. */
|
||||
|
||||
void
|
||||
ask (char const *format, ...)
|
||||
{
|
||||
static int ttyfd = -2;
|
||||
int r;
|
||||
va_list args;
|
||||
|
||||
vararg_start (args, format);
|
||||
vfprintf (stdout, format, args);
|
||||
va_end (args);
|
||||
fflush (stdout);
|
||||
|
||||
if (ttyfd == -2)
|
||||
{
|
||||
/* If standard output is not a tty, don't bother opening /dev/tty,
|
||||
since it's unlikely that stdout will be seen by the tty user.
|
||||
The isatty test also works around a bug in GNU Emacs 19.34 under Linux
|
||||
which makes a call-process `patch' hang when it reads from /dev/tty.
|
||||
POSIX.2 requires that we read /dev/tty, though. */
|
||||
ttyfd = (posixly_correct || isatty (STDOUT_FILENO)
|
||||
? open (TTY_DEVICE, O_RDONLY)
|
||||
: -1);
|
||||
}
|
||||
|
||||
if (ttyfd < 0)
|
||||
{
|
||||
/* No terminal at all -- default it. */
|
||||
printf ("\n");
|
||||
buf[0] = '\n';
|
||||
buf[1] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t s = 0;
|
||||
while ((r = read (ttyfd, buf + s, bufsize - 1 - s)) == bufsize - 1 - s
|
||||
&& buf[bufsize - 2] != '\n')
|
||||
{
|
||||
s = bufsize - 1;
|
||||
bufsize *= 2;
|
||||
buf = realloc (buf, bufsize);
|
||||
if (!buf)
|
||||
memory_fatal ();
|
||||
}
|
||||
if (r == 0)
|
||||
printf ("EOF\n");
|
||||
else if (r < 0)
|
||||
{
|
||||
perror ("tty read");
|
||||
fflush (stderr);
|
||||
close (ttyfd);
|
||||
ttyfd = -1;
|
||||
r = 0;
|
||||
}
|
||||
buf[s + r] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* Return nonzero if it OK to reverse a patch. */
|
||||
|
||||
int
|
||||
ok_to_reverse (char const *format, ...)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
if (noreverse || ! (force && verbosity == SILENT))
|
||||
{
|
||||
va_list args;
|
||||
vararg_start (args, format);
|
||||
vfprintf (stdout, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
if (noreverse)
|
||||
{
|
||||
printf (" Skipping patch.\n");
|
||||
skip_rest_of_patch = TRUE;
|
||||
r = 0;
|
||||
}
|
||||
else if (force)
|
||||
{
|
||||
if (verbosity != SILENT)
|
||||
printf (" Applying it anyway.\n");
|
||||
r = 0;
|
||||
}
|
||||
else if (batch)
|
||||
{
|
||||
say (reverse ? " Ignoring -R.\n" : " Assuming -R.\n");
|
||||
r = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ask (reverse ? " Ignore -R? [n] " : " Assume -R? [n] ");
|
||||
r = *buf == 'y';
|
||||
if (! r)
|
||||
{
|
||||
ask ("Apply anyway? [n] ");
|
||||
if (*buf != 'y')
|
||||
{
|
||||
if (verbosity != SILENT)
|
||||
say ("Skipping patch.\n");
|
||||
skip_rest_of_patch = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* How to handle certain events when not in a critical region. */
|
||||
|
||||
#define NUM_SIGS (sizeof (sigs) / sizeof (*sigs))
|
||||
static int const sigs[] = {
|
||||
#ifdef SIGHUP
|
||||
SIGHUP,
|
||||
#endif
|
||||
#ifdef SIGPIPE
|
||||
SIGPIPE,
|
||||
#endif
|
||||
#ifdef SIGTERM
|
||||
SIGTERM,
|
||||
#endif
|
||||
#ifdef SIGXCPU
|
||||
SIGXCPU,
|
||||
#endif
|
||||
#ifdef SIGXFSZ
|
||||
SIGXFSZ,
|
||||
#endif
|
||||
SIGINT
|
||||
};
|
||||
|
||||
#if !HAVE_SIGPROCMASK
|
||||
#define sigset_t int
|
||||
#define sigemptyset(s) (*(s) = 0)
|
||||
#ifndef sigmask
|
||||
#define sigmask(sig) (1 << ((sig) - 1))
|
||||
#endif
|
||||
#define sigaddset(s, sig) (*(s) |= sigmask (sig))
|
||||
#define sigismember(s, sig) ((*(s) & sigmask (sig)) != 0)
|
||||
#ifndef SIG_BLOCK
|
||||
#define SIG_BLOCK 0
|
||||
#endif
|
||||
#ifndef SIG_UNBLOCK
|
||||
#define SIG_UNBLOCK (SIG_BLOCK + 1)
|
||||
#endif
|
||||
#ifndef SIG_SETMASK
|
||||
#define SIG_SETMASK (SIG_BLOCK + 2)
|
||||
#endif
|
||||
#define sigprocmask(how, n, o) \
|
||||
((how) == SIG_BLOCK \
|
||||
? ((o) ? *(o) = sigblock (*(n)) : sigblock (*(n))) \
|
||||
: (how) == SIG_UNBLOCK \
|
||||
? sigsetmask (((o) ? *(o) = sigblock (0) : sigblock (0)) & ~*(n)) \
|
||||
: (o ? *(o) = sigsetmask (*(n)) : sigsetmask (*(n))))
|
||||
#if !HAVE_SIGSETMASK
|
||||
#define sigblock(mask) 0
|
||||
#define sigsetmask(mask) 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static sigset_t initial_signal_mask;
|
||||
static sigset_t signals_to_block;
|
||||
|
||||
#if ! HAVE_SIGACTION
|
||||
static RETSIGTYPE fatal_exit_handler PARAMS ((int)) __attribute__ ((noreturn));
|
||||
static RETSIGTYPE
|
||||
fatal_exit_handler (int sig)
|
||||
{
|
||||
signal (sig, SIG_IGN);
|
||||
fatal_exit (sig);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
set_signals (int reset)
|
||||
{
|
||||
int i;
|
||||
#if HAVE_SIGACTION
|
||||
struct sigaction initial_act, fatal_act;
|
||||
fatal_act.sa_handler = fatal_exit;
|
||||
sigemptyset (&fatal_act.sa_mask);
|
||||
fatal_act.sa_flags = 0;
|
||||
#define setup_handler(sig) sigaction (sig, &fatal_act, (struct sigaction *) 0)
|
||||
#else
|
||||
#define setup_handler(sig) signal (sig, fatal_exit_handler)
|
||||
#endif
|
||||
|
||||
if (!reset)
|
||||
{
|
||||
#ifdef SIGCHLD
|
||||
/* System V fork+wait does not work if SIGCHLD is ignored. */
|
||||
signal (SIGCHLD, SIG_DFL);
|
||||
#endif
|
||||
sigemptyset (&signals_to_block);
|
||||
for (i = 0; i < NUM_SIGS; i++)
|
||||
{
|
||||
int ignoring_signal;
|
||||
#if HAVE_SIGACTION
|
||||
if (sigaction (sigs[i], (struct sigaction *) 0, &initial_act) != 0)
|
||||
continue;
|
||||
ignoring_signal = initial_act.sa_handler == SIG_IGN;
|
||||
#else
|
||||
ignoring_signal = signal (sigs[i], SIG_IGN) == SIG_IGN;
|
||||
#endif
|
||||
if (! ignoring_signal)
|
||||
{
|
||||
sigaddset (&signals_to_block, sigs[i]);
|
||||
setup_handler (sigs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Undo the effect of ignore_signals. */
|
||||
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
|
||||
sigprocmask (SIG_SETMASK, &initial_signal_mask, (sigset_t *) 0);
|
||||
#else
|
||||
for (i = 0; i < NUM_SIGS; i++)
|
||||
if (sigismember (&signals_to_block, sigs[i]))
|
||||
setup_handler (sigs[i]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* How to handle certain events when in a critical region. */
|
||||
|
||||
void
|
||||
ignore_signals (void)
|
||||
{
|
||||
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
|
||||
sigprocmask (SIG_BLOCK, &signals_to_block, &initial_signal_mask);
|
||||
#else
|
||||
int i;
|
||||
for (i = 0; i < NUM_SIGS; i++)
|
||||
if (sigismember (&signals_to_block, sigs[i]))
|
||||
signal (sigs[i], SIG_IGN);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
exit_with_signal (int sig)
|
||||
{
|
||||
sigset_t s;
|
||||
signal (sig, SIG_DFL);
|
||||
sigemptyset (&s);
|
||||
sigaddset (&s, sig);
|
||||
sigprocmask (SIG_UNBLOCK, &s, (sigset_t *) 0);
|
||||
raise (sig);
|
||||
exit (2);
|
||||
}
|
||||
|
||||
int
|
||||
systemic (char const *command)
|
||||
{
|
||||
if (debug & 8)
|
||||
say ("+ %s\n", command);
|
||||
fflush (stdout);
|
||||
return system (command);
|
||||
}
|
||||
|
||||
/* Replace '/' with '\0' in FILENAME if it marks a place that
|
||||
needs testing for the existence of directory. Return the address
|
||||
of the last location replaced, or 0 if none were replaced. */
|
||||
static char *
|
||||
replace_slashes (char *filename)
|
||||
{
|
||||
char *f;
|
||||
char *last_location_replaced = 0;
|
||||
char const *component_start;
|
||||
|
||||
for (f = filename + FILESYSTEM_PREFIX_LEN (filename); ISSLASH (*f); f++)
|
||||
continue;
|
||||
|
||||
component_start = f;
|
||||
|
||||
for (; *f; f++)
|
||||
if (ISSLASH (*f))
|
||||
{
|
||||
char *slash = f;
|
||||
|
||||
/* Treat multiple slashes as if they were one slash. */
|
||||
while (ISSLASH (f[1]))
|
||||
f++;
|
||||
|
||||
/* Ignore slashes at the end of the path. */
|
||||
if (! f[1])
|
||||
break;
|
||||
|
||||
/* "." and ".." need not be tested. */
|
||||
if (! (slash - component_start <= 2
|
||||
&& component_start[0] == '.' && slash[-1] == '.'))
|
||||
{
|
||||
*slash = '\0';
|
||||
last_location_replaced = slash;
|
||||
}
|
||||
|
||||
component_start = f + 1;
|
||||
}
|
||||
|
||||
return last_location_replaced;
|
||||
}
|
||||
|
||||
/* Make sure we'll have the directories to create a file.
|
||||
Ignore the last element of `filename'. */
|
||||
|
||||
static void
|
||||
makedirs (register char *filename)
|
||||
{
|
||||
register char *f;
|
||||
register char *flim = replace_slashes (filename);
|
||||
|
||||
if (flim)
|
||||
{
|
||||
/* Create any missing directories, replacing NULs by '/'s.
|
||||
Ignore errors. We may have to keep going even after an EEXIST,
|
||||
since the path may contain ".."s; and when there is an EEXIST
|
||||
failure the system may return some other error number.
|
||||
Any problems will eventually be reported when we create the file. */
|
||||
for (f = filename; f <= flim; f++)
|
||||
if (!*f)
|
||||
{
|
||||
mkdir (filename,
|
||||
S_IRUSR|S_IWUSR|S_IXUSR
|
||||
|S_IRGRP|S_IWGRP|S_IXGRP
|
||||
|S_IROTH|S_IWOTH|S_IXOTH);
|
||||
*f = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove empty ancestor directories of FILENAME.
|
||||
Ignore errors, since the path may contain ".."s, and when there
|
||||
is an EEXIST failure the system may return some other error number. */
|
||||
void
|
||||
removedirs (char *filename)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = strlen (filename); i != 0; i--)
|
||||
if (ISSLASH (filename[i])
|
||||
&& ! (ISSLASH (filename[i - 1])
|
||||
|| (filename[i - 1] == '.'
|
||||
&& (i == 1
|
||||
|| ISSLASH (filename[i - 2])
|
||||
|| (filename[i - 2] == '.'
|
||||
&& (i == 2
|
||||
|| ISSLASH (filename[i - 3])))))))
|
||||
{
|
||||
filename[i] = '\0';
|
||||
if (rmdir (filename) == 0 && verbosity == VERBOSE)
|
||||
say ("Removed empty directory %s\n", quotearg (filename));
|
||||
filename[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
static time_t initial_time;
|
||||
|
||||
void
|
||||
init_time (void)
|
||||
{
|
||||
time (&initial_time);
|
||||
}
|
||||
|
||||
/* Make filenames more reasonable. */
|
||||
|
||||
char *
|
||||
fetchname (char *at, int strip_leading, time_t *pstamp)
|
||||
{
|
||||
char *name;
|
||||
register char *t;
|
||||
int sleading = strip_leading;
|
||||
time_t stamp = (time_t) -1;
|
||||
|
||||
while (ISSPACE ((unsigned char) *at))
|
||||
at++;
|
||||
if (debug & 128)
|
||||
say ("fetchname %s %d\n", at, strip_leading);
|
||||
|
||||
name = at;
|
||||
/* Strip up to `strip_leading' leading slashes and null terminate.
|
||||
If `strip_leading' is negative, strip all leading slashes. */
|
||||
for (t = at; *t; t++)
|
||||
{
|
||||
if (ISSLASH (*t))
|
||||
{
|
||||
while (ISSLASH (t[1]))
|
||||
t++;
|
||||
if (strip_leading < 0 || --sleading >= 0)
|
||||
name = t+1;
|
||||
}
|
||||
else if (ISSPACE ((unsigned char) *t))
|
||||
{
|
||||
char const *u = t;
|
||||
|
||||
if (set_time | set_utc)
|
||||
stamp = str2time (&u, initial_time,
|
||||
set_utc ? 0L : TM_LOCAL_ZONE);
|
||||
else
|
||||
{
|
||||
/* The head says the file is nonexistent if the timestamp
|
||||
is the epoch; but the listed time is local time, not UTC,
|
||||
and POSIX.1 allows local time offset anywhere in the range
|
||||
-25:00 < offset < +26:00. Match any time in that
|
||||
range by assuming local time is -25:00 and then matching
|
||||
any ``local'' time T in the range 0 < T < 25+26 hours. */
|
||||
stamp = str2time (&u, initial_time, -25L * 60 * 60);
|
||||
if (0 < stamp && stamp < (25 + 26) * 60L * 60)
|
||||
stamp = 0;
|
||||
}
|
||||
|
||||
if (*u && ! ISSPACE ((unsigned char) *u))
|
||||
stamp = (time_t) -1;
|
||||
|
||||
*t = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*name)
|
||||
return 0;
|
||||
|
||||
/* If the name is "/dev/null", ignore the name and mark the file
|
||||
as being nonexistent. The name "/dev/null" appears in patches
|
||||
regardless of how NULL_DEVICE is spelled. */
|
||||
if (strcmp (at, "/dev/null") == 0)
|
||||
{
|
||||
if (pstamp)
|
||||
*pstamp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Ignore the name if it doesn't have enough slashes to strip off. */
|
||||
if (0 < sleading)
|
||||
return 0;
|
||||
|
||||
if (pstamp)
|
||||
*pstamp = stamp;
|
||||
|
||||
return savestr (name);
|
||||
}
|
||||
|
||||
void
|
||||
Fseek (FILE *stream, file_offset offset, int ptrname)
|
||||
{
|
||||
if (file_seek (stream, offset, ptrname) != 0)
|
||||
pfatal ("fseek");
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/* utility functions for `patch' */
|
||||
|
||||
/* $Id: util.h 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
/* 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 PARAMS ((char const *, ...)) __attribute__ ((format (printf, 1, 2)));
|
||||
void ask PARAMS ((char const *, ...)) __attribute__ ((format (printf, 1, 2)));
|
||||
void say PARAMS ((char const *, ...)) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
void fatal PARAMS ((char const *, ...))
|
||||
__attribute__ ((noreturn, format (printf, 1, 2)));
|
||||
void pfatal PARAMS ((char const *, ...))
|
||||
__attribute__ ((noreturn, format (printf, 1, 2)));
|
||||
|
||||
char *fetchname PARAMS ((char *, int, time_t *));
|
||||
char *savebuf PARAMS ((char const *, size_t));
|
||||
char *savestr PARAMS ((char const *));
|
||||
char const *version_controller PARAMS ((char const *, int, struct stat const *, char **, char **));
|
||||
int version_get PARAMS ((char const *, char const *, int, int, char const *, struct stat *));
|
||||
int create_file PARAMS ((char const *, int, mode_t));
|
||||
int systemic PARAMS ((char const *));
|
||||
char *format_linenum PARAMS ((char[LINENUM_LENGTH_BOUND + 1], LINENUM));
|
||||
void Fseek PARAMS ((FILE *, file_offset, int));
|
||||
void copy_file PARAMS ((char const *, char const *, int, mode_t));
|
||||
void exit_with_signal PARAMS ((int)) __attribute__ ((noreturn));
|
||||
void ignore_signals PARAMS ((void));
|
||||
void init_time PARAMS ((void));
|
||||
void memory_fatal PARAMS ((void)) __attribute__ ((noreturn));
|
||||
void move_file PARAMS ((char const *, int volatile *, char *, mode_t, int));
|
||||
void read_fatal PARAMS ((void)) __attribute__ ((noreturn));
|
||||
void remove_prefix PARAMS ((char *, size_t));
|
||||
void removedirs PARAMS ((char *));
|
||||
void set_signals PARAMS ((int));
|
||||
void write_fatal PARAMS ((void)) __attribute__ ((noreturn));
|
||||
@@ -1,30 +0,0 @@
|
||||
/* Print the version number. */
|
||||
|
||||
/* $Id: version.c 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
#define XTERN extern
|
||||
#include <common.h>
|
||||
#undef XTERN
|
||||
#define XTERN
|
||||
#include <patchlevel.h>
|
||||
#include <version.h>
|
||||
|
||||
static char const copyright_string[] = "\
|
||||
Copyright 1984-1988 Larry Wall\n\
|
||||
Copyright 1989-1999 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);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
/* Print the version number. */
|
||||
|
||||
/* $Id: version.h 8008 2004-06-16 21:22:10Z korli $ */
|
||||
|
||||
void version PARAMS ((void));
|
||||
@@ -1,52 +0,0 @@
|
||||
/* xalloc.h -- malloc with out-of-memory checking
|
||||
Copyright (C) 1990-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. */
|
||||
|
||||
#ifndef XALLOC_H_
|
||||
# define XALLOC_H_
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Exit value when the requested amount of memory is not available.
|
||||
It is initialized to EXIT_FAILURE, but the caller may set it to
|
||||
some other value. */
|
||||
extern int xalloc_exit_failure;
|
||||
|
||||
/* If this pointer is non-zero, run the specified function upon each
|
||||
allocation failure. It is initialized to zero. */
|
||||
extern void (*xalloc_fail_func) ();
|
||||
|
||||
/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this
|
||||
message must be non-NULL. It is translated via gettext.
|
||||
The default value is "Memory exhausted". */
|
||||
extern char *const xalloc_msg_memory_exhausted;
|
||||
|
||||
void *xmalloc PARAMS ((size_t n));
|
||||
void *xcalloc PARAMS ((size_t n, size_t s));
|
||||
void *xrealloc PARAMS ((void *p, size_t n));
|
||||
|
||||
# define XMALLOC(Type, N_bytes) ((Type *) xmalloc (sizeof (Type) * (N_bytes)))
|
||||
# define XCALLOC(Type, N_bytes) ((Type *) xcalloc (sizeof (Type), (N_bytes)))
|
||||
# define XREALLOC(Ptr, Type, N_bytes) \
|
||||
((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_bytes)))
|
||||
|
||||
#endif /* !XALLOC_H_ */
|
||||
@@ -1,113 +0,0 @@
|
||||
/* xmalloc.c -- malloc with out of memory checking
|
||||
Copyright (C) 1990-1997, 98, 99 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 "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
|
||||
|
||||
/* Exit value when the requested amount of memory is not available.
|
||||
The caller may set it to some other value. */
|
||||
int xalloc_exit_failure = EXIT_FAILURE;
|
||||
|
||||
/* If non NULL, call this function when memory is exhausted. */
|
||||
void (*xalloc_fail_func) () = 0;
|
||||
|
||||
/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
|
||||
before exiting when memory is exhausted. Goes through gettext. */
|
||||
char *const xalloc_msg_memory_exhausted = N_("Memory exhausted");
|
||||
|
||||
static void
|
||||
xalloc_fail (void)
|
||||
{
|
||||
if (xalloc_fail_func)
|
||||
(*xalloc_fail_func) ();
|
||||
error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
|
||||
}
|
||||
|
||||
/* Allocate N bytes of memory dynamically, with error checking. */
|
||||
|
||||
void *
|
||||
xmalloc (size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc (n);
|
||||
if (p == 0)
|
||||
xalloc_fail ();
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Change the size of an allocated block of memory P to N bytes,
|
||||
with error checking.
|
||||
If P is NULL, run xmalloc. */
|
||||
|
||||
void *
|
||||
xrealloc (void *p, size_t n)
|
||||
{
|
||||
p = realloc (p, n);
|
||||
if (p == 0)
|
||||
xalloc_fail ();
|
||||
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_fail ();
|
||||
return p;
|
||||
}
|
||||
@@ -41,7 +41,6 @@ provides {
|
||||
cmd:more
|
||||
cmd:netcat
|
||||
cmd:passwd
|
||||
cmd:patch
|
||||
cmd:ping
|
||||
cmd:ping6
|
||||
cmd:prio
|
||||
|
||||
@@ -41,7 +41,6 @@ provides {
|
||||
cmd:more
|
||||
cmd:netcat
|
||||
cmd:passwd
|
||||
cmd:patch
|
||||
cmd:ping
|
||||
cmd:ping6
|
||||
cmd:prio
|
||||
|
||||
@@ -41,7 +41,6 @@ provides {
|
||||
cmd:more
|
||||
cmd:netcat
|
||||
cmd:passwd
|
||||
cmd:patch
|
||||
cmd:ping
|
||||
cmd:ping6
|
||||
cmd:prio
|
||||
|
||||
@@ -41,7 +41,6 @@ provides {
|
||||
cmd:more
|
||||
cmd:netcat
|
||||
cmd:passwd
|
||||
cmd:patch
|
||||
cmd:ping
|
||||
cmd:ping6
|
||||
cmd:prio
|
||||
|
||||
@@ -40,7 +40,6 @@ provides {
|
||||
cmd:more
|
||||
cmd:netcat
|
||||
cmd:passwd
|
||||
cmd:patch
|
||||
cmd:ping
|
||||
cmd:ping6
|
||||
cmd:prio
|
||||
|
||||
@@ -41,7 +41,6 @@ provides {
|
||||
cmd:more
|
||||
cmd:netcat
|
||||
cmd:passwd
|
||||
cmd:patch
|
||||
cmd:ping
|
||||
cmd:ping6
|
||||
cmd:prio
|
||||
|
||||
Reference in New Issue
Block a user