Skip to content

Instantly share code, notes, and snippets.

@takumin
Created August 23, 2015 03:49
Show Gist options
  • Save takumin/fbfc981f96b01bac9014 to your computer and use it in GitHub Desktop.
Save takumin/fbfc981f96b01bac9014 to your computer and use it in GitHub Desktop.
GNU Patch 2.5.4 for W32 Dos Version.
diff --git backupfile.c backupfile.c
index 7f4da17..029bd7a 100644
--- backupfile.c
+++ backupfile.c
@@ -65,8 +65,10 @@ char *malloc ();
#endif
#ifndef HAVE_DECL_GETENV
+#ifndef WIN32
char *getenv ();
#endif
+#endif
char *base_name PARAMS ((char const *));
@@ -163,7 +165,7 @@ find_backup_file_name (const char *file, enum backup_type backup_type)
FILE in directory DIR. If there are no numbered backups
of FILE in DIR, or an error occurs reading DIR, return 0.
*/
-
+#include <dirent.h>
static int
max_backup_version (const char *file, const char *dir)
{
diff --git common.h common.h
index 0b040cf..7ab3ff3 100644
--- common.h
+++ common.h
@@ -315,14 +315,16 @@ GENERIC_OBJECT *realloc ();
#if HAVE_SETMODE
XTERN int binary_transput; /* O_BINARY if binary i/o is desired */
+ XTERN int dos_output;
#else
# define binary_transput 0
+# define dos_output 0
#endif
#ifndef NULL_DEVICE
-#define NULL_DEVICE "/dev/null"
+#define NULL_DEVICE "nul"
#endif
#ifndef TTY_DEVICE
-#define TTY_DEVICE "/dev/tty"
+#define TTY_DEVICE "con"
#endif
diff --git configure configure
old mode 100755
new mode 100644
diff --git error.c error.c
index 4eff5d0..900995b 100644
--- error.c
+++ error.c
@@ -87,7 +87,9 @@ extern char *program_name;
# else
# if HAVE_STRERROR
# ifndef strerror /* On some systems, strerror is a macro */
+/*
char *strerror ();
+*/
# endif
# else
static char *
diff --git getopt.c getopt.c
index 81cef23..964189d 100644
--- getopt.c
+++ getopt.c
@@ -1,42 +1,41 @@
/* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
- "Keep this file name-space clean" means, talk to drepper@gnu.org
+ "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
- Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94
Free Software Foundation, Inc.
- 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.
+ 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.
- The GNU C Library is distributed in the hope that it will be useful,
+ 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
- Library General Public License for more details.
+ 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 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. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Ditto for AIX 3.2 and <stdlib.h>. */
#ifndef _NO_PROTO
-# define _NO_PROTO
+#define _NO_PROTO
#endif
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
-#if !defined __STDC__ || !__STDC__
+#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
-# ifndef const
-# define const
-# endif
+#ifndef const
+#define const
+#endif
#endif
#include <stdio.h>
@@ -49,15 +48,7 @@
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
-#define GETOPT_INTERFACE_VERSION 2
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
-# include <gnu-versions.h>
-# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
-# define ELIDE_CODE
-# endif
-#endif
-
-#ifndef ELIDE_CODE
+#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
@@ -65,28 +56,9 @@
#ifdef __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
-# include <stdlib.h>
-# include <unistd.h>
+#include <stdlib.h>
#endif /* GNU C library. */
-#ifdef VMS
-# include <unixlib.h>
-# if HAVE_STRING_H - 0
-# include <string.h>
-# endif
-#endif
-
-#ifndef _
-/* This is for other GNU distributions with internationalized messages.
- When compiling libc, the _ macro is predefined. */
-# ifdef HAVE_LIBINTL_H
-# include <libintl.h>
-# define _(msgid) gettext (msgid)
-# else
-# define _(msgid) (msgid)
-# endif
-#endif
-
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
to intersperse the options with the other arguments.
@@ -117,20 +89,14 @@ char *optarg = NULL;
On entry to `getopt', zero means this is the first call; initialize.
- When `getopt' returns -1, this is the index of the first of the
+ When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
-/* 1003.2 says this must be 1 before any call. */
-int optind = 1;
-
-/* Formerly, initialization of getopt depended on optind==0, which
- causes problems with re-calling getopt as programs generally don't
- know that. */
-
-int __getopt_initialized = 0;
+/* XXX 1003.2 says this must be 1 before any call. */
+int optind = 0;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
@@ -179,7 +145,7 @@ int optopt = '?';
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
- `--' can cause `getopt' to return -1 with `optind' != ARGC. */
+ `--' can cause `getopt' to return EOF with `optind' != ARGC. */
static enum
{
@@ -194,22 +160,14 @@ static char *posixly_correct;
because there are many ways it can cause trouble.
On some systems, it contains special magic macros that don't work
in GCC. */
-# include <string.h>
-# define my_index strchr
+#include <string.h>
+#define my_index strchr
#else
-# if HAVE_STRING_H
-# include <string.h>
-# else
-# include <strings.h>
-# endif
-
/* Avoid depending on library functions or files
whose names are inconsistent. */
-#ifndef getenv
-extern char *getenv ();
-#endif
+char *getenv ();
static char *
my_index (str, chr)
@@ -230,11 +188,11 @@ my_index (str, chr)
#ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
That was relevant to code that was here before. */
-# if (!defined __STDC__ || !__STDC__) && !defined strlen
+#ifndef __STDC__
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen (const char *);
-# endif /* not __STDC__ */
+#endif /* not __STDC__ */
#endif /* __GNUC__ */
#endif /* not __GNU_LIBRARY__ */
@@ -248,46 +206,6 @@ extern int strlen (const char *);
static int first_nonopt;
static int last_nonopt;
-#ifdef _LIBC
-/* Bash 2.0 gives us an environment variable containing flags
- indicating ARGV elements that should not be considered arguments. */
-
-/* Defined in getopt_init.c */
-extern char *__getopt_nonoption_flags;
-
-static int nonoption_flags_max_len;
-static int nonoption_flags_len;
-
-static int original_argc;
-static char *const *original_argv;
-
-/* Make sure the environment variable bash 2.0 puts in the environment
- is valid for the getopt call we must make sure that the ARGV passed
- to getopt is that one passed to the process. */
-static void
-__attribute__ ((unused))
-store_args_and_env (int argc, char *const *argv)
-{
- /* XXX This is no good solution. We should rather copy the args so
- that we can compare them later. But we must not use malloc(3). */
- original_argc = argc;
- original_argv = argv;
-}
-# ifdef text_set_element
-text_set_element (__libc_subinit, store_args_and_env);
-# endif /* text_set_element */
-
-# define SWAP_FLAGS(ch1, ch2) \
- if (nonoption_flags_len > 0) \
- { \
- char __tmp = __getopt_nonoption_flags[ch1]; \
- __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
- __getopt_nonoption_flags[ch2] = __tmp; \
- }
-#else /* !_LIBC */
-# define SWAP_FLAGS(ch1, ch2)
-#endif /* _LIBC */
-
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
@@ -297,10 +215,6 @@ text_set_element (__libc_subinit, store_args_and_env);
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
-#if defined __STDC__ && __STDC__
-static void exchange (char **);
-#endif
-
static void
exchange (argv)
char **argv;
@@ -315,28 +229,6 @@ exchange (argv)
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
-#ifdef _LIBC
- /* First make sure the handling of the `__getopt_nonoption_flags'
- string can work normally. Our top argument must be in the range
- of the string. */
- if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
- {
- /* We must extend the array. The user plays games with us and
- presents new arguments. */
- char *new_str = malloc (top + 1);
- if (new_str == NULL)
- nonoption_flags_len = nonoption_flags_max_len = 0;
- else
- {
- memset (__mempcpy (new_str, __getopt_nonoption_flags,
- nonoption_flags_max_len),
- '\0', top + 1 - nonoption_flags_max_len);
- nonoption_flags_max_len = top + 1;
- __getopt_nonoption_flags = new_str;
- }
- }
-#endif
-
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
@@ -351,7 +243,6 @@ exchange (argv)
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
- SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
@@ -368,7 +259,6 @@ exchange (argv)
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
- SWAP_FLAGS (bottom + i, middle + i);
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
@@ -383,20 +273,15 @@ exchange (argv)
/* Initialize the internal data when the first call is made. */
-#if defined __STDC__ && __STDC__
-static const char *_getopt_initialize (int, char *const *, const char *);
-#endif
static const char *
-_getopt_initialize (argc, argv, optstring)
- int argc;
- char *const *argv;
+_getopt_initialize (optstring)
const char *optstring;
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
- first_nonopt = last_nonopt = optind;
+ first_nonopt = last_nonopt = optind = 1;
nextchar = NULL;
@@ -419,36 +304,6 @@ _getopt_initialize (argc, argv, optstring)
else
ordering = PERMUTE;
-#ifdef _LIBC
- if (posixly_correct == NULL
- && argc == original_argc && argv == original_argv)
- {
- if (nonoption_flags_max_len == 0)
- {
- if (__getopt_nonoption_flags == NULL
- || __getopt_nonoption_flags[0] == '\0')
- nonoption_flags_max_len = -1;
- else
- {
- const char *orig_str = __getopt_nonoption_flags;
- int len = nonoption_flags_max_len = strlen (orig_str);
- if (nonoption_flags_max_len < argc)
- nonoption_flags_max_len = argc;
- __getopt_nonoption_flags =
- (char *) malloc (nonoption_flags_max_len);
- if (__getopt_nonoption_flags == NULL)
- nonoption_flags_max_len = -1;
- else
- memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
- '\0', nonoption_flags_max_len - len);
- }
- }
- nonoption_flags_len = nonoption_flags_max_len;
- }
- else
- nonoption_flags_len = 0;
-#endif
-
return optstring;
}
@@ -465,7 +320,7 @@ _getopt_initialize (argc, argv, optstring)
updating `optind' and `nextchar' so that the next call to `getopt' can
resume the scan with the following option character or ARGV-element.
- If there are no more option characters, `getopt' returns -1.
+ If there are no more option characters, `getopt' returns `EOF'.
Then `optind' is the index in ARGV of the first ARGV-element
that is not an option. (The ARGV-elements have been permuted
so that those that are not options now come last.)
@@ -519,37 +374,13 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
optarg = NULL;
- if (optind == 0 || !__getopt_initialized)
- {
- if (optind == 0)
- optind = 1; /* Don't scan ARGV[0], the program name. */
- optstring = _getopt_initialize (argc, argv, optstring);
- __getopt_initialized = 1;
- }
-
- /* Test whether ARGV[optind] points to a non-option argument.
- Either it does not have option syntax, or there is an environment flag
- from the shell indicating it is not an option. The later information
- is only used when the used in the GNU libc. */
-#ifdef _LIBC
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
- || (optind < nonoption_flags_len \
- && __getopt_nonoption_flags[optind] == '1'))
-#else
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
-#endif
+ if (optind == 0)
+ optstring = _getopt_initialize (optstring);
if (nextchar == NULL || *nextchar == '\0')
{
/* Advance to the next ARGV-element. */
- /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
- moved back by the user (who may also have changed the arguments). */
- if (last_nonopt > optind)
- last_nonopt = optind;
- if (first_nonopt > optind)
- first_nonopt = optind;
-
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
@@ -563,7 +394,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
- while (optind < argc && NONOPTION_P)
+ while (optind < argc
+ && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
optind++;
last_nonopt = optind;
}
@@ -595,16 +427,16 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
- return -1;
+ return EOF;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
- if (NONOPTION_P)
+ if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
{
if (ordering == REQUIRE_ORDER)
- return -1;
+ return EOF;
optarg = argv[optind++];
return 1;
}
@@ -640,7 +472,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
- int indfound = -1;
+ int indfound;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
@@ -651,8 +483,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
- if ((unsigned int) (nameend - nextchar)
- == (unsigned int) strlen (p->name))
+ if (nameend - nextchar == strlen (p->name))
{
/* Exact match found. */
pfound = p;
@@ -674,11 +505,10 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (ambig && !exact)
{
if (opterr)
- fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
+ fprintf (stderr, "%s: option `%s' is ambiguous\n",
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
- optopt = 0;
return '?';
}
@@ -699,18 +529,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (argv[optind - 1][1] == '-')
/* --option */
fprintf (stderr,
- _("%s: option `--%s' doesn't allow an argument\n"),
+ "%s: option `--%s' doesn't allow an argument\n",
argv[0], pfound->name);
else
/* +option or -option */
fprintf (stderr,
- _("%s: option `%c%s' doesn't allow an argument\n"),
- argv[0], argv[optind - 1][0], pfound->name);
+ "%s: option `%c%s' doesn't allow an argument\n",
+ argv[0], argv[optind - 1][0], pfound->name);
}
-
nextchar += strlen (nextchar);
-
- optopt = pfound->val;
return '?';
}
}
@@ -721,11 +548,9 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else
{
if (opterr)
- fprintf (stderr,
- _("%s: option `%s' requires an argument\n"),
- argv[0], argv[optind - 1]);
+ fprintf (stderr, "%s: option `%s' requires an argument\n",
+ argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
- optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
@@ -751,16 +576,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (argv[optind][1] == '-')
/* --option */
- fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
+ fprintf (stderr, "%s: unrecognized option `--%s'\n",
argv[0], nextchar);
else
/* +option or -option */
- fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
+ fprintf (stderr, "%s: unrecognized option `%c%s'\n",
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *) "";
optind++;
- optopt = 0;
return '?';
}
}
@@ -781,139 +605,13 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
- fprintf (stderr, _("%s: illegal option -- %c\n"),
- argv[0], c);
+ fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
else
- fprintf (stderr, _("%s: invalid option -- %c\n"),
- argv[0], c);
+ fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c);
}
optopt = c;
return '?';
}
- /* Convenience. Treat POSIX -W foo same as long option --foo */
- if (temp[0] == 'W' && temp[1] == ';')
- {
- char *nameend;
- const struct option *p;
- const struct option *pfound = NULL;
- int exact = 0;
- int ambig = 0;
- int indfound = 0;
- int option_index;
-
- /* This is an option that requires an argument. */
- if (*nextchar != '\0')
- {
- optarg = nextchar;
- /* If we end this ARGV-element by taking the rest as an arg,
- we must advance to the next element now. */
- optind++;
- }
- else if (optind == argc)
- {
- if (opterr)
- {
- /* 1003.2 specifies the format of this message. */
- fprintf (stderr, _("%s: option requires an argument -- %c\n"),
- argv[0], c);
- }
- optopt = c;
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- return c;
- }
- else
- /* We already incremented `optind' once;
- increment it again when taking next ARGV-elt as argument. */
- optarg = argv[optind++];
-
- /* optarg is now the argument, see if it's in the
- table of longopts. */
-
- for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
- /* Do nothing. */ ;
-
- /* Test all long options for either exact match
- or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name; p++, option_index++)
- if (!strncmp (p->name, nextchar, nameend - nextchar))
- {
- if ((unsigned int) (nameend - nextchar) == strlen (p->name))
- {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- }
- else if (pfound == NULL)
- {
- /* First nonexact match found. */
- pfound = p;
- indfound = option_index;
- }
- else
- /* Second or later nonexact match found. */
- ambig = 1;
- }
- if (ambig && !exact)
- {
- if (opterr)
- fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
- argv[0], argv[optind]);
- nextchar += strlen (nextchar);
- optind++;
- return '?';
- }
- if (pfound != NULL)
- {
- option_index = indfound;
- if (*nameend)
- {
- /* Don't test has_arg with >, because some C compilers don't
- allow it to be used on enums. */
- if (pfound->has_arg)
- optarg = nameend + 1;
- else
- {
- if (opterr)
- fprintf (stderr, _("\
-%s: option `-W %s' doesn't allow an argument\n"),
- argv[0], pfound->name);
-
- nextchar += strlen (nextchar);
- return '?';
- }
- }
- else if (pfound->has_arg == 1)
- {
- if (optind < argc)
- optarg = argv[optind++];
- else
- {
- if (opterr)
- fprintf (stderr,
- _("%s: option `%s' requires an argument\n"),
- argv[0], argv[optind - 1]);
- nextchar += strlen (nextchar);
- return optstring[0] == ':' ? ':' : '?';
- }
- }
- nextchar += strlen (nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
- nextchar = NULL;
- return 'W'; /* Let the application handle it. */
- }
if (temp[1] == ':')
{
if (temp[2] == ':')
@@ -943,9 +641,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (opterr)
{
/* 1003.2 specifies the format of this message. */
- fprintf (stderr,
- _("%s: option requires an argument -- %c\n"),
- argv[0], c);
+ fprintf (stderr, "%s: option requires an argument -- %c\n",
+ argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
@@ -976,7 +673,7 @@ getopt (argc, argv, optstring)
0);
}
-#endif /* Not ELIDE_CODE. */
+#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST
@@ -996,7 +693,7 @@ main (argc, argv)
int this_option_optind = optind ? optind : 1;
c = getopt (argc, argv, "abc:d:0123456789");
- if (c == -1)
+ if (c == EOF)
break;
switch (c)
diff --git getopt.h getopt.h
index b0147e9..45541f5 100644
--- getopt.h
+++ getopt.h
@@ -1,27 +1,22 @@
/* Declarations for getopt.
- Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
+ Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
- 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.
+ 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.
- The GNU C Library is distributed in the hope that it will be useful,
+ 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
- Library General Public License for more details.
+ 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 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. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _GETOPT_H
-
-#ifndef __need_getopt
-# define _GETOPT_H 1
-#endif
+#define _GETOPT_H 1
#ifdef __cplusplus
extern "C" {
@@ -41,7 +36,7 @@ extern char *optarg;
On entry to `getopt', zero means this is the first call; initialize.
- When `getopt' returns -1, this is the index of the first of the
+ When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
@@ -58,7 +53,6 @@ extern int opterr;
extern int optopt;
-#ifndef __need_getopt
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
@@ -82,11 +76,11 @@ extern int optopt;
struct option
{
-# if defined __STDC__ && __STDC__
+#if __STDC__
const char *name;
-# else
+#else
char *name;
-# endif
+#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
@@ -96,74 +90,40 @@ struct option
/* Names for the values of the `has_arg' field of `struct option'. */
-# define no_argument 0
-# define required_argument 1
-# define optional_argument 2
-#endif /* need getopt */
-
-
-/* Get definitions and prototypes for functions to process the
- arguments in ARGV (ARGC of them, minus the program name) for
- options given in OPTS.
-
- Return the option character from OPTS just read. Return -1 when
- there are no more options. For unrecognized options, or options
- missing arguments, `optopt' is set to the option letter, and '?' is
- returned.
+#define no_argument 0
+#define required_argument 1
+#define optional_argument 2
- The OPTS string is a list of characters which are recognized option
- letters, optionally followed by colons, specifying that that letter
- takes an argument, to be placed in `optarg'.
-
- If a letter in OPTS is followed by two colons, its argument is
- optional. This behavior is specific to the GNU `getopt'.
-
- The argument `--' causes premature termination of argument
- scanning, explicitly telling `getopt' that there are no more
- options.
-
- If OPTS begins with `--', then non-option arguments are treated as
- arguments to the option '\0'. This behavior is specific to the GNU
- `getopt'. */
-
-#if defined __STDC__ && __STDC__
-# ifdef __GNU_LIBRARY__
+#if __STDC__
+#if defined(__GNU_LIBRARY__)
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
-extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
-# else /* not __GNU_LIBRARY__ */
+extern int getopt (int argc, char *const *argv, const char *shortopts);
+#else /* not __GNU_LIBRARY__ */
extern int getopt ();
-# endif /* __GNU_LIBRARY__ */
-
-# ifndef __need_getopt
-extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
- const struct option *__longopts, int *__longind);
-extern int getopt_long_only (int __argc, char *const *__argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind);
+#endif /* not __GNU_LIBRARY__ */
+extern int getopt_long (int argc, char *const *argv, const char *shortopts,
+ const struct option *longopts, int *longind);
+extern int getopt_long_only (int argc, char *const *argv,
+ const char *shortopts,
+ const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
-extern int _getopt_internal (int __argc, char *const *__argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- int __long_only);
-# endif
+extern int _getopt_internal (int argc, char *const *argv,
+ const char *shortopts,
+ const struct option *longopts, int *longind,
+ int long_only);
#else /* not __STDC__ */
extern int getopt ();
-# ifndef __need_getopt
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
-# endif
-#endif /* __STDC__ */
+#endif /* not __STDC__ */
#ifdef __cplusplus
}
#endif
-/* Make sure we later can get all the definitions and declarations. */
-#undef __need_getopt
-
-#endif /* getopt.h */
+#endif /* _GETOPT_H */
diff --git getopt1.c getopt1.c
index 3d264f2..725c653 100644
--- getopt1.c
+++ getopt1.c
@@ -1,22 +1,20 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
- Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
- Free Software Foundation, Inc.
- This file is part of the GNU C Library.
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
+ Free Software Foundation, Inc.
- 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.
+ 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.
- The GNU C Library is distributed in the hope that it will be useful,
+ 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
- Library General Public License for more details.
+ 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 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. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -24,7 +22,7 @@
#include "getopt.h"
-#if !defined __STDC__ || !__STDC__
+#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
@@ -42,21 +40,15 @@
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
-#define GETOPT_INTERFACE_VERSION 2
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
-#include <gnu-versions.h>
-#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
-#define ELIDE_CODE
-#endif
-#endif
-
-#ifndef ELIDE_CODE
+#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
+#else
+char *getenv ();
#endif
#ifndef NULL
@@ -91,7 +83,7 @@ getopt_long_only (argc, argv, options, long_options, opt_index)
}
-#endif /* Not ELIDE_CODE. */
+#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST
@@ -122,7 +114,7 @@ main (argc, argv)
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
- if (c == -1)
+ if (c == EOF)
break;
switch (c)
diff --git inp.c inp.c
index 3858a13..64948bd 100644
--- inp.c
+++ inp.c
@@ -157,7 +157,7 @@ get_input_file (char const *filename, char const *outname)
(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,
diff --git install-sh install-sh
old mode 100755
new mode 100644
diff --git mkinstalldirs mkinstalldirs
old mode 100755
new mode 100644
diff --git patch.c patch.c
index 798245a..d4d7efa 100644
--- patch.c
+++ patch.c
@@ -113,6 +113,10 @@ char const program_name[] = "patch";
int main PARAMS ((int, char **));
+#ifdef WIN32
+#include <fcntl.h>
+#endif
+
int
main (int argc, char **argv)
{
@@ -121,6 +125,12 @@ main (int argc, char **argv)
struct outstate outstate;
char numbuf[LINENUM_LENGTH_BOUND + 1];
+#ifdef WIN32
+ strcpy(argv[0], "patch");
+ binary_transput = 0;
+ dos_output = 0;
+#endif
+
init_time ();
setbuf(stderr, serrbuf);
@@ -340,7 +350,7 @@ main (int argc, char **argv)
}
/* Finish spewing out the new file. */
- assert (hunk);
+ /* assert (hunk); */ /* ---ak */
if (! spew_output (&outstate))
{
say ("Skipping patch.\n");
@@ -525,6 +535,7 @@ static struct option const longopts[] =
{"no-backup-if-mismatch", no_argument, NULL, CHAR_MAX + 6},
{"posix", no_argument, NULL, CHAR_MAX + 7},
{"quoting-style", required_argument, NULL, CHAR_MAX + 8},
+ {"dos", no_argument, NULL, CHAR_MAX + 9},
{NULL, no_argument, NULL, 0}
};
@@ -586,7 +597,13 @@ static char const *const option_help[] =
"",
" -d DIR --directory=DIR Change the working directory to DIR first.",
#if HAVE_SETMODE
-" --binary Read and write data in binary mode.",
+" --binary Read data in binary mode. Use for UNIX format files.",
+" Source and diff files must be UNIX format.",
+" If diff file is DOS format, do not use this option.",
+" In the case of DOS format diff file, source can be both",
+" DOS and UNIX format. Output is usually UNIX format.",
+" --dos Write file in DOS format. In the case of --binary option,",
+" --dos option has no effect.",
#else
" --binary Read and write data in binary mode (no effect on this platform).",
#endif
@@ -756,7 +773,7 @@ get_some_switches (void)
break;
case CHAR_MAX + 3:
#if HAVE_SETMODE
- binary_transput = O_BINARY;
+ binary_transput = _O_BINARY;
#endif
break;
case CHAR_MAX + 4:
@@ -782,6 +799,10 @@ get_some_switches (void)
(enum quoting_style) i);
}
break;
+ case CHAR_MAX + 9:
+ dos_output = 1;
+ break;
+
default:
usage (stderr, 2);
}
@@ -1154,9 +1175,18 @@ apply_hunk (struct outstate *outstate, LINENUM where)
static FILE *
create_output_file (char const *name, int open_flags)
{
- int fd = create_file (name, O_WRONLY | binary_transput | open_flags,
+ FILE *f;
+ int fd;
+ if(dos_output)
+ fd = create_file (name, O_WRONLY | binary_transput | open_flags,
+ instat.st_mode);
+ else
+ fd = create_file (name, O_WRONLY | _O_BINARY | open_flags,
instat.st_mode);
- FILE *f = fdopen (fd, binary_transput ? "wb" : "w");
+ if(dos_output)
+ f = fdopen (fd, binary_transput ? "wb" : "w");
+ else
+ f = fdopen (fd, binary_transput ? "wb" : "wb");
if (! f)
pfatal ("Can't create file %s", quotearg (name));
return f;
@@ -1308,7 +1338,7 @@ char *mktemp PARAMS ((char *));
#endif
#ifndef TMPDIR
-#define TMPDIR "/tmp"
+#define TMPDIR "c:/temp"
#endif
static char const *
diff --git pch.c pch.c
index 360fdf6..b82a720 100644
--- pch.c
+++ pch.c
@@ -1856,7 +1856,10 @@ do_ed_script (FILE *ofp)
sprintf (buf, "%s %s%s", ed_program, verbosity == VERBOSE ? "" : "- ",
TMPOUTNAME);
fflush (stdout);
- pipefp = popen(buf, binary_transput ? "wb" : "w");
+ if(dos_output)
+ pipefp = popen(buf, binary_transput ? "wb" : "w");
+ else
+ pipefp = popen(buf, binary_transput ? "wb" : "wb");
if (!pipefp)
pfatal ("Can't open pipe to %s", quotearg (buf));
}
diff --git util.c util.c
index 345210f..b913142 100644
--- util.c
+++ util.c
@@ -40,15 +40,15 @@
#define SIGCHLD SIGCLD
#endif
#if ! HAVE_RAISE && ! defined raise
-# define raise(sig) kill (getpid (), sig)
+# define raise(sig) exit(600)
#endif
-#ifdef __STDC__
+#ifdef BAKA
# include <stdarg.h>
# define vararg_start va_start
#else
# define vararg_start(ap,p) va_start (ap)
-# if HAVE_VARARGS_H
+# ifdef HAVE_VARARGS_H
# include <varargs.h>
# else
typedef char *va_list;
@@ -135,9 +135,10 @@ move_file (char const *from, int volatile *from_needs_removal,
quotearg_n (0, to), quotearg_n (1, bakname));
while (rename (to, bakname) != 0)
{
- if (errno != try_makedirs_errno)
+ 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;
}
@@ -157,7 +158,6 @@ move_file (char const *from, int volatile *from_needs_removal,
else
{
int to_dir_known_to_exist = 0;
-
if (errno == ENOENT
&& (to_errno == -1 || to_errno == ENOENT))
{
@@ -169,8 +169,11 @@ move_file (char const *from, int volatile *from_needs_removal,
return;
}
}
-
+#ifdef WIN32
+ else
+#else
if (errno == EXDEV)
+#endif
{
if (! backup)
{
@@ -554,7 +557,6 @@ ask (char const *format, ...)
static int ttyfd = -2;
int r;
va_list args;
-
vararg_start (args, format);
vfprintf (stdout, format, args);
va_end (args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment