mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-23 18:25:19 +00:00
This commit was generated by cvs2svn to compensate for changes in r53469,
which included commits to RCS files with non-trunk default branches.
This commit is contained in:
commit
2186a02c95
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53470
189
gnu/usr.bin/grep/getopt1.c
Normal file
189
gnu/usr.bin/grep/getopt1.c
Normal file
|
@ -0,0 +1,189 @@
|
|||
/* 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. 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. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#if !defined (__STDC__) || !__STDC__
|
||||
/* This is a separate conditional since some stdc systems
|
||||
reject `defined (const)'. */
|
||||
#ifndef const
|
||||
#define const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Comment out all this code if we are using the GNU C Library, and are not
|
||||
actually compiling the library itself. This code is part of the GNU C
|
||||
Library, but also included in many other GNU distributions. Compiling
|
||||
and linking in this code is a waste when using the GNU C library
|
||||
(especially if it is a shared library). Rather than having every GNU
|
||||
program understand `configure --with-gnu-libc' and omit the object files,
|
||||
it is simpler to just do this in the source for each such file. */
|
||||
|
||||
#define GETOPT_INTERFACE_VERSION 2
|
||||
#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
|
||||
#include <gnu-versions.h>
|
||||
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
|
||||
#define ELIDE_CODE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ELIDE_CODE
|
||||
|
||||
|
||||
/* This needs to come after some library #include
|
||||
to get __GNU_LIBRARY__ defined. */
|
||||
#ifdef __GNU_LIBRARY__
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
int
|
||||
getopt_long (argc, argv, options, long_options, opt_index)
|
||||
int argc;
|
||||
char *const *argv;
|
||||
const char *options;
|
||||
const struct option *long_options;
|
||||
int *opt_index;
|
||||
{
|
||||
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
|
||||
}
|
||||
|
||||
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
||||
If an option that starts with '-' (not '--') doesn't match a long option,
|
||||
but does match a short option, it is parsed as a short option
|
||||
instead. */
|
||||
|
||||
int
|
||||
getopt_long_only (argc, argv, options, long_options, opt_index)
|
||||
int argc;
|
||||
char *const *argv;
|
||||
const char *options;
|
||||
const struct option *long_options;
|
||||
int *opt_index;
|
||||
{
|
||||
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
|
||||
}
|
||||
|
||||
|
||||
#endif /* Not ELIDE_CODE. */
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
int option_index = 0;
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"add", 1, 0, 0},
|
||||
{"append", 0, 0, 0},
|
||||
{"delete", 1, 0, 0},
|
||||
{"verbose", 0, 0, 0},
|
||||
{"create", 0, 0, 0},
|
||||
{"file", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long (argc, argv, "abc:d:0123456789",
|
||||
long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
printf (_("option %s"), long_options[option_index].name);
|
||||
if (optarg)
|
||||
printf (_(" with arg %s"), optarg);
|
||||
printf ("\n");
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf (_("digits occur in two different argv-elements.\n"));
|
||||
digit_optind = this_option_optind;
|
||||
printf (_("option %c\n"), c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf (_("option a\n"));
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf (_("option b\n"));
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf (_("option c with value `%s'\n"), optarg);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
printf (_("option d with value `%s'\n"), optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
break;
|
||||
|
||||
default:
|
||||
printf (_("?? getopt returned character code 0%o ??\n"), c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf (_("non-option ARGV-elements: "));
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
135
gnu/usr.bin/grep/savedir.c
Normal file
135
gnu/usr.bin/grep/savedir.c
Normal file
|
@ -0,0 +1,135 @@
|
|||
/* savedir.c -- save the list of files in a directory in a string
|
||||
Copyright (C) 1990, 1997, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
# define dirent direct
|
||||
# define NAMLEN(dirent) (dirent)->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
|
||||
|
||||
#ifdef CLOSEDIR_VOID
|
||||
/* Fake a return value. */
|
||||
# define CLOSEDIR(d) (closedir (d), 0)
|
||||
#else
|
||||
# define CLOSEDIR(d) closedir (d)
|
||||
#endif
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
char *malloc ();
|
||||
char *realloc ();
|
||||
#endif
|
||||
#ifndef NULL
|
||||
# define NULL 0
|
||||
#endif
|
||||
|
||||
#ifndef stpcpy
|
||||
char *stpcpy ();
|
||||
#endif
|
||||
|
||||
#include "savedir.h"
|
||||
|
||||
/* Return a freshly allocated string containing the filenames
|
||||
in directory DIR, separated by '\0' characters;
|
||||
the end is marked by two '\0' characters in a row.
|
||||
NAME_SIZE is the number of bytes to initially allocate
|
||||
for the string; it will be enlarged as needed.
|
||||
Return NULL if DIR cannot be opened or if out of memory. */
|
||||
|
||||
char *
|
||||
savedir (dir, name_size)
|
||||
const char *dir;
|
||||
unsigned int name_size;
|
||||
{
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char *name_space;
|
||||
char *namep;
|
||||
|
||||
dirp = opendir (dir);
|
||||
if (dirp == NULL)
|
||||
return NULL;
|
||||
|
||||
name_space = (char *) malloc (name_size);
|
||||
if (name_space == NULL)
|
||||
{
|
||||
closedir (dirp);
|
||||
return NULL;
|
||||
}
|
||||
namep = name_space;
|
||||
|
||||
while ((dp = readdir (dirp)) != NULL)
|
||||
{
|
||||
/* Skip "." and ".." (some NFS filesystems' directories lack them). */
|
||||
if (dp->d_name[0] != '.'
|
||||
|| (dp->d_name[1] != '\0'
|
||||
&& (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
|
||||
{
|
||||
unsigned size_needed = (namep - name_space) + NAMLEN (dp) + 2;
|
||||
|
||||
if (size_needed > name_size)
|
||||
{
|
||||
char *new_name_space;
|
||||
|
||||
while (size_needed > name_size)
|
||||
name_size += 1024;
|
||||
|
||||
new_name_space = realloc (name_space, name_size);
|
||||
if (new_name_space == NULL)
|
||||
{
|
||||
closedir (dirp);
|
||||
return NULL;
|
||||
}
|
||||
namep += new_name_space - name_space;
|
||||
name_space = new_name_space;
|
||||
}
|
||||
namep = stpcpy (namep, dp->d_name) + 1;
|
||||
}
|
||||
}
|
||||
*namep = '\0';
|
||||
if (CLOSEDIR (dirp))
|
||||
{
|
||||
free (name_space);
|
||||
return NULL;
|
||||
}
|
||||
return name_space;
|
||||
}
|
15
gnu/usr.bin/grep/savedir.h
Normal file
15
gnu/usr.bin/grep/savedir.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#if !defined SAVEDIR_H_
|
||||
# define SAVEDIR_H_
|
||||
|
||||
# ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
# endif
|
||||
|
||||
char *
|
||||
savedir PARAMS ((const char *dir, unsigned int name_size));
|
||||
|
||||
#endif
|
52
gnu/usr.bin/grep/stpcpy.c
Normal file
52
gnu/usr.bin/grep/stpcpy.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* stpcpy.c -- copy a string and return pointer to end of new string
|
||||
Copyright (C) 1992, 1995, 1997, 1998 Free Software Foundation, Inc.
|
||||
|
||||
NOTE: The canonical source of this file is maintained with the GNU C Library.
|
||||
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#undef __stpcpy
|
||||
#undef stpcpy
|
||||
|
||||
#ifndef weak_alias
|
||||
# define __stpcpy stpcpy
|
||||
#endif
|
||||
|
||||
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
|
||||
char *
|
||||
__stpcpy (dest, src)
|
||||
char *dest;
|
||||
const char *src;
|
||||
{
|
||||
register char *d = dest;
|
||||
register const char *s = src;
|
||||
|
||||
do
|
||||
*d++ = *s;
|
||||
while (*s++ != '\0');
|
||||
|
||||
return d - 1;
|
||||
}
|
||||
#ifdef weak_alias
|
||||
weak_alias (__stpcpy, stpcpy)
|
||||
#endif
|
188
gnu/usr.bin/grep/system.h
Normal file
188
gnu/usr.bin/grep/system.h
Normal file
|
@ -0,0 +1,188 @@
|
|||
/* Portability cruft. Include after config.h and sys/types.h.
|
||||
Copyright (C) 1996, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
02111-1307, USA. */
|
||||
|
||||
#undef PARAMS
|
||||
#if defined (__STDC__) && __STDC__
|
||||
# ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
typedef void * ptr_t;
|
||||
# endif
|
||||
# define PARAMS(x) x
|
||||
#else
|
||||
# ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
typedef char * ptr_t;
|
||||
# endif
|
||||
# define PARAMS(x) ()
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# define O_RDONLY 0
|
||||
int open(), read(), close();
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
# define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error"))
|
||||
#endif
|
||||
|
||||
/* Some operating systems treat text and binary files differently. */
|
||||
#if O_BINARY
|
||||
# include <io.h>
|
||||
# ifdef HAVE_SETMODE
|
||||
# define SET_BINARY(fd) setmode (fd, O_BINARY)
|
||||
# else
|
||||
# define SET_BINARY(fd) _setmode (fd, O_BINARY)
|
||||
# endif
|
||||
#else
|
||||
# ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
# define SET_BINARY(fd) (void)0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DOS_FILE_NAMES
|
||||
# define IS_SLASH(c) ((c) == '/' || (c) == '\\')
|
||||
# define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
|
||||
#endif
|
||||
|
||||
#ifndef IS_SLASH
|
||||
# define IS_SLASH(c) ((c) == '/')
|
||||
#endif
|
||||
|
||||
#ifndef FILESYSTEM_PREFIX_LEN
|
||||
# define FILESYSTEM_PREFIX_LEN(f) 0
|
||||
#endif
|
||||
|
||||
/* This assumes _WIN32, like DJGPP, has D_OK. Does it? In what header? */
|
||||
#ifdef D_OK
|
||||
# ifdef EISDIR
|
||||
# define is_EISDIR(e, f) \
|
||||
((e) == EISDIR \
|
||||
|| ((e) == EACCES && access (f, D_OK) == 0 && ((e) = EISDIR, 1)))
|
||||
# else
|
||||
# define is_EISDIR(e, f) ((e) == EACCES && access (f, D_OK) == 0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef is_EISDIR
|
||||
# ifdef EISDIR
|
||||
# define is_EISDIR(e, f) ((e) == EISDIR)
|
||||
# else
|
||||
# define is_EISDIR(e, f) 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if STAT_MACROS_BROKEN
|
||||
# undef S_ISDIR
|
||||
#endif
|
||||
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
||||
# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
ptr_t malloc(), realloc(), calloc();
|
||||
void free();
|
||||
#endif
|
||||
|
||||
#if __STDC__
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
#ifdef STDC_HEADERS
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#ifndef CHAR_BIT
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
#ifndef INT_MAX
|
||||
# define INT_MAX 2147483647
|
||||
#endif
|
||||
#ifndef UCHAR_MAX
|
||||
# define UCHAR_MAX 255
|
||||
#endif
|
||||
|
||||
#if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
|
||||
# include <memory.h>
|
||||
#endif
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
# undef strchr
|
||||
# define strchr index
|
||||
# undef strrchr
|
||||
# define strrchr rindex
|
||||
# undef memcpy
|
||||
# define memcpy(d, s, n) bcopy((s), (d), (n))
|
||||
#endif
|
||||
#ifndef HAVE_MEMCHR
|
||||
ptr_t memchr();
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef isgraph
|
||||
# define isgraph(C) (isprint(C) && !isspace(C))
|
||||
#endif
|
||||
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#define ISALPHA(C) (IN_CTYPE_DOMAIN (C) && isalpha (C))
|
||||
#define ISUPPER(C) (IN_CTYPE_DOMAIN (C) && isupper (C))
|
||||
#define ISLOWER(C) (IN_CTYPE_DOMAIN (C) && islower (C))
|
||||
#define ISDIGIT(C) (IN_CTYPE_DOMAIN (C) && isdigit (C))
|
||||
#define ISXDIGIT(C) (IN_CTYPE_DOMAIN (C) && isxdigit (C))
|
||||
#define ISSPACE(C) (IN_CTYPE_DOMAIN (C) && isspace (C))
|
||||
#define ISPUNCT(C) (IN_CTYPE_DOMAIN (C) && ispunct (C))
|
||||
#define ISALNUM(C) (IN_CTYPE_DOMAIN (C) && isalnum (C))
|
||||
#define ISPRINT(C) (IN_CTYPE_DOMAIN (C) && isprint (C))
|
||||
#define ISGRAPH(C) (IN_CTYPE_DOMAIN (C) && isgraph (C))
|
||||
#define ISCNTRL(C) (IN_CTYPE_DOMAIN (C) && iscntrl (C))
|
||||
|
||||
#define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
|
||||
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(String) gettext (String)
|
||||
#else
|
||||
# define _(String) String
|
||||
#endif
|
||||
#define N_(String) String
|
||||
|
||||
#if HAVE_SETLOCALE
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#ifndef initialize_main
|
||||
#define initialize_main(argcp, argvp)
|
||||
#endif
|
Loading…
Reference in a new issue