From 5fd83771641d15c418f747bd343ba6738d3875f7 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 9 May 2021 14:20:58 -0400 Subject: Import macOS userland adv_cmds-176 basic_cmds-55 bootstrap_cmds-116.100.1 developer_cmds-66 diskdev_cmds-667.40.1 doc_cmds-53.60.1 file_cmds-321.40.3 mail_cmds-35 misc_cmds-34 network_cmds-606.40.1 patch_cmds-17 remote_cmds-63 shell_cmds-216.60.1 system_cmds-880.60.2 text_cmds-106 --- patch_cmds/diffstat/porting/getopt.c | 79 ++++++++++++++++++++++++ patch_cmds/diffstat/porting/getopt.h | 4 ++ patch_cmds/diffstat/porting/system.h | 85 +++++++++++++++++++++++++ patch_cmds/diffstat/porting/wildcard.c | 109 +++++++++++++++++++++++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 patch_cmds/diffstat/porting/getopt.c create mode 100644 patch_cmds/diffstat/porting/getopt.h create mode 100644 patch_cmds/diffstat/porting/system.h create mode 100644 patch_cmds/diffstat/porting/wildcard.c (limited to 'patch_cmds/diffstat/porting') diff --git a/patch_cmds/diffstat/porting/getopt.c b/patch_cmds/diffstat/porting/getopt.c new file mode 100644 index 0000000..39ed078 --- /dev/null +++ b/patch_cmds/diffstat/porting/getopt.c @@ -0,0 +1,79 @@ +/* ::[[ @(#) getopt.c 1.5 89/03/11 05:40:23 ]]:: */ +#ifndef LINT +static const char Id[] = "$Id: getopt.c,v 1.2 2009/09/01 00:41:59 tom Exp $"; +#endif + +/* + * Here's something you've all been waiting for: the AT&T public domain + * source for getopt(3). It is the code which was given out at the 1985 + * UNIFORUM conference in Dallas. I obtained it by electronic mail + * directly from AT&T. The people there assure me that it is indeed + * in the public domain. + * + * There is no manual page. That is because the one they gave out at + * UNIFORUM was slightly different from the current System V Release 2 + * manual page. The difference apparently involved a note about the + * famous rules 5 and 6, recommending using white space between an option + * and its first argument, and not grouping options that have arguments. + * Getopt itself is currently lenient about both of these things White + * space is allowed, but not mandatory, and the last option in a group can + * have an argument. That particular version of the man page evidently + * has no official existence, and my source at AT&T did not send a copy. + * The current SVR2 man page reflects the actual behavor of this getopt. + * However, I am not about to post a copy of anything licensed by AT&T. + */ + +#include +#include + +#define ERR(szz,czz) if(opterr){fprintf(stderr,"%s%s%c\n",argv[0],szz,czz);} + +int opterr = 1; +int optind = 1; +int optopt; +char *optarg; + +int +getopt(int argc, char *const *argv, const char *opts) +{ + static int sp = 1; + register int c; + register char *cp; + + if (sp == 1) { + if (optind >= argc || + argv[optind][0] != '-' || argv[optind][1] == '\0') + return (EOF); + else if (strcmp(argv[optind], "--") == 0) { + optind++; + return (EOF); + } + } + optopt = c = argv[optind][sp]; + if (c == ':' || (cp = strchr(opts, c)) == NULL) { + ERR(": illegal option -- ", c); + if (argv[optind][++sp] == '\0') { + optind++; + sp = 1; + } + return ('?'); + } + if (*++cp == ':') { + if (argv[optind][sp + 1] != '\0') + optarg = &argv[optind++][sp + 1]; + else if (++optind >= argc) { + ERR(": option requires an argument -- ", c); + sp = 1; + return ('?'); + } else + optarg = argv[optind++]; + sp = 1; + } else { + if (argv[optind][++sp] == '\0') { + sp = 1; + optind++; + } + optarg = NULL; + } + return (c); +} diff --git a/patch_cmds/diffstat/porting/getopt.h b/patch_cmds/diffstat/porting/getopt.h new file mode 100644 index 0000000..e02470d --- /dev/null +++ b/patch_cmds/diffstat/porting/getopt.h @@ -0,0 +1,4 @@ +extern char *optarg; +extern int optind, opterr; + +int getopt (int argc, char *const*argv, const char *options); diff --git a/patch_cmds/diffstat/porting/system.h b/patch_cmds/diffstat/porting/system.h new file mode 100644 index 0000000..02dc60e --- /dev/null +++ b/patch_cmds/diffstat/porting/system.h @@ -0,0 +1,85 @@ +/* $Id: system.h,v 1.1 2002/11/22 22:36:56 tom Exp $ */ + +#ifdef HAVE_CONFIG_H + +# include "config.h" +# define SYS_UNIX 1 + +#else + /* provide values for non-UNIX systems */ +# if defined(vms) +# include +# define SYS_VMS 1 +# define EXIT_SUCCESS (STS$M_INHIB_MSG | STS$K_SUCCESS) +# define EXIT_FAILURE (STS$M_INHIB_MSG | STS$K_ERROR) +# endif + +# if defined(MSDOS) || defined(__MSDOS__) +# define SYS_MSDOS 1 +# endif + +# if !defined(SYS_VMS) || !defined(SYS_MSDOS) || defined(WIN32) +# define SYS_UNIX 1 /* assume we're autoconfiguring */ +# endif + +#define HAVE_STRCHR 1 + +#endif /* HAVE_CONFIG_H */ + +#ifndef HAVE_GETOPT_H +#define HAVE_GETOPT_H 0 +#endif + +#ifndef HAVE_MALLOC_H +#define HAVE_MALLOC_H 0 +#endif + +#ifndef HAVE_STDLIB_H +#define HAVE_STDLIB_H 1 +#endif + +#ifndef HAVE_STRING_H +#define HAVE_STRING_H 1 +#endif + +#ifndef SYS_MSDOS +#define SYS_MSDOS 0 +#endif + +#ifndef SYS_UNIX +#define SYS_UNIX 0 +#endif + +#ifndef SYS_VMS +#define SYS_VMS 0 +#endif + +#ifndef HAVE_GETOPT_HEADER +#define HAVE_GETOPT_HEADER 0 +#endif + +#ifndef PRINT_ROUNDS_DOWN +#define PRINT_ROUNDS_DOWN 0 +#endif + +#ifdef lint +#define typeCalloc(type,elts) (type *)(elts) +#else +#define typeCalloc(type,elts) (type *)calloc(elts,sizeof(type)) +#endif + +#ifndef TRUE +#define TRUE (1) +#define FALSE (0) +#endif + +#undef EOS +#define EOS '\0' + + /* On VMS and MSDOS we can fake wildcards by embedding a directory + * scanning loop... + */ +#if !SYS_UNIX +extern int has_wildcard(char *); +extern int expand_wildcard(char *, int); +#endif diff --git a/patch_cmds/diffstat/porting/wildcard.c b/patch_cmds/diffstat/porting/wildcard.c new file mode 100644 index 0000000..0b7c494 --- /dev/null +++ b/patch_cmds/diffstat/porting/wildcard.c @@ -0,0 +1,109 @@ +#ifndef NO_IDENT +static char *Id = "$Id: wildcard.c,v 1.1 2004/05/03 13:12:10 tom Exp $"; +#endif + +/* + * wildcard.c - perform wildcard expansion for non-UNIX configurations + */ + +#include "system.h" + +#if HAVE_STDLIB_H +# include +#endif + +#if HAVE_STRING_H +# include +#endif + +#if SYS_MSDOS || SYS_OS2 +# if SYS_MSDOS +# include +# include /* defines MAXPATH */ +# define FILENAME_MAX MAXPATH +# endif +# define DeclareFind(p) struct find_t p +# define DirEntryStr(p) p.name +# define DirFindFirst(path,p) (!_dos_findfirst(path, 0, &p)) +# define DirFindNext(p) (!_dos_findnext(&p)) +#endif + +#if SYS_VMS + +#include /* DEC-C (e.g., sys$parse) */ +#include /* perror */ + +#include +#include + +#endif /* SYS_VMS */ + +int +has_wildcard(char *path) +{ +#if SYS_VMS + return (strstr(path, "...") != 0 + || strchr(path, '*') != 0 + || strchr(path, '?') != 0); +#else /* SYS_MSDOS, SYS_OS2 */ + return (strchr(path, '*') != 0 + || strchr(path, '?') != 0); +#endif +} + +int +expand_wildcard(char *path, int initiate) +{ +#if SYS_MSDOS || SYS_OS2 + static DeclareFind(p); + static char temp[FILENAME_MAX + 1]; + register char *leaf; + + if ((leaf = strchr(path, '/')) == 0 + && (leaf = strchr(path, '\\')) == 0) + leaf = path; + else + leaf++; + + if ((initiate && DirFindFirst(strcpy(temp, path), p)) + || DirFindNext(p)) { + (void) strcpy(leaf, DirEntryStr(p)); + return TRUE; + } +#endif /* SYS_MSDOS || SYS_OS2 */ +#if SYS_VMS + static struct FAB zfab; + static struct NAM znam; + static char my_esa[NAM$C_MAXRSS]; /* expanded: SYS$PARSE */ + static char my_rsa[NAM$C_MAXRSS]; /* expanded: SYS$SEARCH */ + + if (initiate) { + zfab = cc$rms_fab; + zfab.fab$l_fop = FAB$M_NAM; + zfab.fab$l_nam = &znam; /* FAB => NAM block */ + zfab.fab$l_dna = "*.*;"; /* Default-selection */ + zfab.fab$b_dns = strlen(zfab.fab$l_dna); + + zfab.fab$l_fna = path; + zfab.fab$b_fns = strlen(path); + + znam = cc$rms_nam; + znam.nam$b_ess = sizeof(my_esa); + znam.nam$l_esa = my_esa; + znam.nam$b_rss = sizeof(my_rsa); + znam.nam$l_rsa = my_rsa; + + if (sys$parse(&zfab) != RMS$_NORMAL) { + perror(path); + exit(EXIT_FAILURE); + } + } + if (sys$search(&zfab) == RMS$_NORMAL) { + strncpy(path, my_rsa, znam.nam$b_rsl)[znam.nam$b_rsl] = '\0'; + return (TRUE); + } +#endif /* SYS_VMS */ +#if SYS_MSDOS +#endif + return FALSE; +} -- cgit v1.2.3-56-ge451