From a3209dfc203e1e9c5bb4efa7a4527a962a804ab1 Mon Sep 17 00:00:00 2001 From: "William F. Jolitz" Date: Wed, 8 Nov 1989 18:32:28 -0800 Subject: [PATCH] 386BSD 0.1 development Work on file usr/src/usr.bin/fgrep/std.c Work on file usr/src/usr.bin/fgrep/std.h Co-Authored-By: Lynne Greer Jolitz Synthesized-from: 386BSD-0.1 --- usr/src/usr.bin/fgrep/std.c | 55 ++++++++++++++ usr/src/usr.bin/fgrep/std.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 usr/src/usr.bin/fgrep/std.c create mode 100644 usr/src/usr.bin/fgrep/std.h diff --git a/usr/src/usr.bin/fgrep/std.c b/usr/src/usr.bin/fgrep/std.c new file mode 100644 index 0000000000..fb98fe6148 --- /dev/null +++ b/usr/src/usr.bin/fgrep/std.c @@ -0,0 +1,55 @@ +/* std.c - compensate for a few missing library functions. + In the Public Domain; written by Mike Haertel. */ + +#include "std.h" +#include "unix.h" + +#ifdef X_memmove +PTR +DEFUN(memmove, (d, s, n), PTR d AND PTRCONST s AND size_t n) +{ + char *dd; + const char *ss; + + dd = d; + ss = s; + if (dd > ss && dd < ss + n) + { + dd += n; + ss += n; + while (n--) + *--dd = *--ss; + } + else + while (n--) + *dd++ = *ss++; + return d; +} +#endif /* X_memmove */ + +#ifdef X_remove +#if defined(unix) || defined(__unix__) +int +DEFUN(remove, (filename), const char *filename) +{ + extern int EXFUN(unlink, (const char *)); + + return unlink(filename); +} +#endif /* unix */ +#endif /* X_strerror */ + +#ifdef X_strerror +#if defined(unix) || defined(__unix__) +char * +DEFUN(strerror, (errnum), int errnum) +{ + extern int sys_nerr; + extern char *sys_errlist[]; + + if (errnum > 0 && errnum < sys_nerr) + return sys_errlist[errnum]; + return ""; +} +#endif /* unix */ +#endif /* X_strerror */ diff --git a/usr/src/usr.bin/fgrep/std.h b/usr/src/usr.bin/fgrep/std.h new file mode 100644 index 0000000000..5185cac250 --- /dev/null +++ b/usr/src/usr.bin/fgrep/std.h @@ -0,0 +1,145 @@ +/* std.h - automagically adapt to old and new compilers. + In the Public Domain; written by Mike Haertel. */ + +#if __STDC__ + +#include +#include + +typedef void *PTR; +typedef const void *PTRCONST; + +#define AND , +#define DEFUN(F, L, P) F(P) +#define EXFUN(F, P) F P + +#else + +#define const +#define volatile + +/* The following approximations of and are appropriate + for most machines. */ +typedef int ptrdiff_t; +typedef unsigned int size_t; +#define NULL 0 +#define offsetof(T, M) ((size_t)&((T *) 0)->(M)) + +#define CHAR_BIT 8 +#define SCHAR_MIN -128 +#define SCHAR_MAX 127 +#define UCHAR_MAX 255 +#define CHAR_MIN ((char) UCHAR_MAX < 0 ? SCHAR_MIN : 0) +#define CHAR_MAX ((char) UCHAR_MAX < 0 ? SCHAR_MAX : UCHAR_MAX) +#define SHRT_MIN -32768 +#define SHRT_MAX 32767 +#define USHRT_MAX 65535 +#define INT_MIN (sizeof (int) == 2 ? -32768 : -2147483648) +#define INT_MAX (sizeof (int) == 2 ? 32767 : 2147483647) +#define UINT_MAX (sizeof (int) == 2 ? 65535 : 4294967295) +#define LONG_MIN -2147483648L +#define LONG_MAX 2147483647L +#define ULONG_MAX 4294967295 + +typedef char *PTR; +typedef const char *PTRCONST; + +#define AND ; +#define DEFUN(F, L, P) F L P ; +#define EXFUN(F, P) F() + +#endif + +/* Deal with lossage. */ +#include + +#ifndef isascii + +#define ISALNUM(C) isalnum(C) +#define ISALPHA(C) isalpha(C) +#define ISCNTRL(C) iscntrl(C) +#define ISDIGIT(C) isdigit(C) +#define ISGRAPH(C) isgraph(C) +#define ISLOWER(C) islower(C) +#define ISPRINT(C) isprint(C) +#define ISPUNCT(C) ispunct(C) +#define ISSPACE(C) isspace(C) +#define ISUPPER(C) isupper(C) +#define ISXDIGIT(C) isxdigit(C) +#define TOLOWER(C) tolower(C) +#define TOUPPER(C) toupper(C) + +#else + +#define ISALNUM(C) (isascii(C) && isalnum(C)) +#define ISALPHA(C) (isascii(C) && isalpha(C)) +#define ISCNTRL(C) (isascii(C) && iscntrl(C)) +#define ISDIGIT(C) (isascii(C) && isdigit(C)) +#define ISGRAPH(C) (isascii(C) && isgraph(C)) +#define ISLOWER(C) (isascii(C) && islower(C)) +#define ISPRINT(C) (isascii(C) && isprint(C)) +#define ISPUNCT(C) (isascii(C) && ispunct(C)) +#define ISSPACE(C) (isascii(C) && isspace(C)) +#define ISUPPER(C) (isascii(C) && isupper(C)) +#define ISXDIGIT(C) (isascii(C) && isxdigit(C)) +#define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C)) +#define TOUPPER(C) (ISLOWER(C) ? toupper(C) : (C)) + +#endif + +/* Declaring this here should be safe. Some losing 's don't. */ +extern int errno; + +/* Adapt variable arguments to new implementations (with ) + or old (which are assumed to have ). */ + +#if __STDC__ + +#include + +#define VA_ALIST ... +#define VA_DCL ... +#define VA_LIST va_list +#define VA_START(AP, LASTARG) va_start(AP, LASTARG) +#define VA_ARG(AP, TYPE) va_arg(AP, TYPE) +#define VA_END(AP) va_end(AP) + +#define VA_DEFUN(F, L, P) F(P) + +#else + +#include + +#define VA_ALIST va_alist +#define VA_DCL va_dcl +#define VA_LIST va_list +#define VA_START(AP, LASTARG) va_start(AP) +#define VA_ARG(AP, TYPE) va_arg(AP, TYPE) +#define VA_END(AP) va_end(AP) + +#define VA_DEFUN(F, L, P) F L P + +#endif + +/* Declarations of traditional library routines. */ +extern double EXFUN(atof, (const char *)); +extern int EXFUN(atoi, (const char *)); +extern long int EXFUN(atol, (const char *)); +extern int EXFUN(rand, (void)); +extern void EXFUN(srand, (int)); +extern PTR EXFUN(calloc, (size_t, size_t)); +extern void EXFUN(free, (PTR)); +extern PTR EXFUN(malloc, (size_t)); +extern PTR EXFUN(realloc, (PTR, size_t)); +extern void EXFUN(abort, (void)); +extern void EXFUN(exit, (int)); +extern char *EXFUN(getenv, (const char *)); +extern int EXFUN(system, (const char *)); +extern void EXFUN(qsort, (PTR, size_t, size_t, + int EXFUN((*), (PTRCONST, PTRCONST)))); +extern int EXFUN(abs, (int)); +extern long int EXFUN(labs, (long int)); + +#ifdef X_strerror +extern char *EXFUN(strerror, (int)); +#endif -- 2.20.1