Public Domain Korn Shell - Part.07 of 7

USENET Administration netnews at netcom.UUCP
Wed Dec 12 22:39:36 AEST 1990


#!/bin/sh
# This is part 07 of ksh-pd
# ============= stdc/stdio.h ==============
if test ! -d 'stdc'; then
    echo 'x - creating directory stdc'
    mkdir 'stdc'
fi
if test -f 'stdc/stdio.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/stdio.h (File already exists)'
else
echo 'x - extracting stdc/stdio.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/stdio.h' &&
X/*
X * ANSI stream IO
X *
X * Heavily dependent on /usr/include/stdio.h being AT&T derived.
X * todo: needs L_* constants.
X */
X
X/* $Header: stdio.h,v 1.2 88/06/23 18:32:35 egisin Locked $ */
X
X#if ! _STDIO_H
X#define	_STDIO_H 1
X
X#include <stddef.h>
X
X/* system stdio.h goes here ... %%% */
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.  The Berkeley software License Agreement
X * specifies the terms and conditions for redistribution.
X *
X *	@(#)stdio.h	5.3 (Berkeley) 3/15/86
X */
X
X# ifndef FILE
X#define	BUFSIZ	1024
Xextern	struct	_iobuf {
X	int	_cnt;
X	char	*_ptr;		/* should be unsigned char */
X	char	*_base;		/* ditto */
X	int	_bufsiz;
X	short	_flag;
X	char	_file;		/* should be short */
X} _iob[];
X
X#define	_IOREAD	01
X#define	_IOWRT	02
X#define	_IONBF	04
X#define	_IOMYBUF	010
X#define	_IOEOF	020
X#define	_IOERR	040
X#define	_IOSTRG	0100
X#define	_IOLBF	0200
X#define	_IORW	0400
X#define	FILE	struct _iobuf
X#define	EOF	(-1)
X
X#define	stdin	(&_iob[0])
X#define	stdout	(&_iob[1])
X#define	stderr	(&_iob[2])
X#ifndef lint
X#define	getc(p)		(--(p)->_cnt>=0? (int)(*(unsigned char *)(p)->_ptr++):_filbuf(p))
X#endif /*not lint*/
X#define	getchar()	getc(stdin)
X#ifndef lint
X#define putc(x, p)	(--(p)->_cnt >= 0 ?\
X	(int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
X	(((p)->_flag & _IOLBF) && -(p)->_cnt < (p)->_bufsiz ?\
X		((*(p)->_ptr = (x)) != '\n' ?\
X			(int)(*(unsigned char *)(p)->_ptr++) :\
X			_flsbuf(*(unsigned char *)(p)->_ptr, p)) :\
X		_flsbuf((unsigned char)(x), p)))
X#endif /*not lint*/
X#define	putchar(x)	putc(x,stdout)
X#define	feof(p)		(((p)->_flag&_IOEOF)!=0)
X#define	ferror(p)	(((p)->_flag&_IOERR)!=0)
X#define	fileno(p)	((p)->_file)
X#define	clearerr(p)	((p)->_flag &= ~(_IOERR|_IOEOF))
X
X
X#ifdef lint
Xextern int printf(/*FORMAT1*/);
Xextern int fprintf(/*FORMAT2*/);
X#endif /*lint*/
X
XFILE	*fopen();
XFILE	*fdopen();
XFILE	*freopen();
XFILE	*popen();
Xlong	ftell();
Xchar	*fgets();
Xchar	*gets();
X#ifdef vax
X#endif
X# endif
X/* ... end system stdio.h */
X#line 15 "stdio.h"
X
X#ifndef _IOFBF
X#define	_IOFBF	00000
X#endif
X#ifndef _IOLBF
X#define	_IOLBF	00000		/* same as _IOFBF */
X#endif
X
X#define	SEEK_SET	0
X#define	SEEK_CUR	1
X#define	SEEK_END	2
X
X#if _SYSV
X#define	_EXTERN	extern
X#else
X#define	_EXTERN	
X#endif
X
X_EXTERN	int	remove ARGS((const char *name));
X_EXTERN	int	rename ARGS((const char *oname, const char *nname));
X_EXTERN	FILE   *tmpfile ARGS((void));
X_EXTERN	char   *tmpnam ARGS((char *s));
X
X_EXTERN	FILE   *fopen ARGS((const char *name, const char *mode));
X_EXTERN	FILE   *freopen ARGS((const char *name, const char *mode, FILE *f));
X_EXTERN	FILE   *fdopen ARGS((int fd, const char *mode));
X_EXTERN	int	fflush ARGS((FILE *f));
X_EXTERN	int	fclose ARGS((FILE *f));
X_EXTERN	void	setbuf ARGS((FILE *f, char *buf));
X_EXTERN	int	setvbuf ARGS((FILE *f, char *buf, int flags, size_t len));
X
X_EXTERN	int	fseek ARGS((FILE *f, long off, int how));
X_EXTERN	long	ftell ARGS((FILE *f));
X_EXTERN	void	rewind ARGS((FILE *f));
X
X_EXTERN	int	printf ARGS((const char *fmt, ...));
X_EXTERN	int	fprintf ARGS((FILE *f, const char *fmt, ...));
X_EXTERN	int	sprintf ARGS((char *s, const char *fmt, ...));
X/* we do not include <stdarg.h> to prevent <varargs.h> conflicts */
X_EXTERN	int	vprintf ARGS((const char *fmt, Void *va));
X_EXTERN	int	vfprintf ARGS((FILE *f, const char *fmt, Void *va));
X_EXTERN	int	vsprintf ARGS((char *s, const char *fmt, Void *va));
X_EXTERN	int	scanf ARGS((const char *fmt, ...));
X_EXTERN	int	fscanf ARGS((FILE *f, const char *fmt, ...));
X_EXTERN	int	sscanf ARGS((const char *s, const char *fmt, ...));
X
X_EXTERN	size_t	fread ARGS((void *ptr, size_t size, size_t n, FILE *f));
X_EXTERN	size_t	frwrite ARGS((const void *ptr, size_t size, size_t n, FILE *f));
X_EXTERN	int	fgetc ARGS((FILE *f));
X_EXTERN	int	fputc ARGS((int c, FILE *f));
X_EXTERN	char   *fgets ARGS((char *s, int len, FILE *f));
X_EXTERN	int	fputs ARGS((const char *s, FILE *f));
X_EXTERN	char   *gets ARGS((char *s));
X_EXTERN	int     puts ARGS((const char *s));
X
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/stdio.h failed'
fi
# ============= stdc/stdio.h_std ==============
if test -f 'stdc/stdio.h_std' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/stdio.h_std (File already exists)'
else
echo 'x - extracting stdc/stdio.h_std (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/stdio.h_std' &&
X/*
X * ANSI stream IO
X *
X * Heavily dependent on /usr/include/stdio.h being AT&T derived.
X * todo: needs L_* constants.
X */
X
X/* $Header: stdio.h,v 1.2 88/06/23 18:32:35 egisin Locked $ */
X
X#if ! _STDIO_H
X#define	_STDIO_H 1
X
X#include <stddef.h>
X
X/* system stdio.h goes here ... %%% */
X/* ... end system stdio.h */
X#line 15 "stdio.h"
X
X#ifndef _IOFBF
X#define	_IOFBF	00000
X#endif
X#ifndef _IOLBF
X#define	_IOLBF	00000		/* same as _IOFBF */
X#endif
X
X#define	SEEK_SET	0
X#define	SEEK_CUR	1
X#define	SEEK_END	2
X
X#if _SYSV
X#define	_EXTERN	extern
X#else
X#define	_EXTERN	
X#endif
X
X_EXTERN	int	remove ARGS((const char *name));
X_EXTERN	int	rename ARGS((const char *oname, const char *nname));
X_EXTERN	FILE   *tmpfile ARGS((void));
X_EXTERN	char   *tmpnam ARGS((char *s));
X
X_EXTERN	FILE   *fopen ARGS((const char *name, const char *mode));
X_EXTERN	FILE   *freopen ARGS((const char *name, const char *mode, FILE *f));
X_EXTERN	FILE   *fdopen ARGS((int fd, const char *mode));
X_EXTERN	int	fflush ARGS((FILE *f));
X_EXTERN	int	fclose ARGS((FILE *f));
X_EXTERN	void	setbuf ARGS((FILE *f, char *buf));
X_EXTERN	int	setvbuf ARGS((FILE *f, char *buf, int flags, size_t len));
X
X_EXTERN	int	fseek ARGS((FILE *f, long off, int how));
X_EXTERN	long	ftell ARGS((FILE *f));
X_EXTERN	void	rewind ARGS((FILE *f));
X
X_EXTERN	int	printf ARGS((const char *fmt, ...));
X_EXTERN	int	fprintf ARGS((FILE *f, const char *fmt, ...));
X_EXTERN	int	sprintf ARGS((char *s, const char *fmt, ...));
X/* we do not include <stdarg.h> to prevent <varargs.h> conflicts */
X_EXTERN	int	vprintf ARGS((const char *fmt, Void *va));
X_EXTERN	int	vfprintf ARGS((FILE *f, const char *fmt, Void *va));
X_EXTERN	int	vsprintf ARGS((char *s, const char *fmt, Void *va));
X_EXTERN	int	scanf ARGS((const char *fmt, ...));
X_EXTERN	int	fscanf ARGS((FILE *f, const char *fmt, ...));
X_EXTERN	int	sscanf ARGS((const char *s, const char *fmt, ...));
X
X_EXTERN	size_t	fread ARGS((void *ptr, size_t size, size_t n, FILE *f));
X_EXTERN	size_t	frwrite ARGS((const void *ptr, size_t size, size_t n, FILE *f));
X_EXTERN	int	fgetc ARGS((FILE *f));
X_EXTERN	int	fputc ARGS((int c, FILE *f));
X_EXTERN	char   *fgets ARGS((char *s, int len, FILE *f));
X_EXTERN	int	fputs ARGS((const char *s, FILE *f));
X_EXTERN	char   *gets ARGS((char *s));
X_EXTERN	int     puts ARGS((const char *s));
X
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/stdio.h_std failed'
fi
# ============= stdc/stdlib.h ==============
if test -f 'stdc/stdlib.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/stdlib.h (File already exists)'
else
echo 'x - extracting stdc/stdlib.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/stdlib.h' &&
X/* ANSI utility functions */
X
X/* $Header: stdlib.h,v 1.1 88/03/09 21:52:59 egisin Locked $ */
X
X#if ! _STDLIB_H
X#define	_STDLIB_H 1
X
X#include <stddef.h>
X
Xdouble	atof ARGS((const char *s));
Xint	atoi ARGS((const char *s));
Xlong	atol ARGS((const char *s));
Xdouble	strtod ARGS((const char *s, char **));
Xlong	strtol ARGS((const char *s, char **, int base));
Xunsigned long	strtoul ARGS((const char *s, char **, int base));
Xint	rand ARGS((void));
Xvoid	srand ARGS((unsigned int seed));
XVoid   *malloc ARGS((size_t size));
XVoid   *realloc ARGS((void *ptr, size_t size));
XVoid   *calloc ARGS((size_t n, size_t size));
Xvoid	free ARGS((void *ptr));
Xvoid	abort ARGS((void));
Xint	atexit ARGS((void (*func)(void)));
Xvoid	exit ARGS((int status));
Xchar   *getenv ARGS((const char *name));
Xint	system ARGS((const char *cmd));
Xvoid   *bsearch ARGS ((const void *key, const void *base, size_t n, size_t size,
X		       int (*compar)(const void *, const void *)));
Xvoid   *qsort ARGS ((const void *base, size_t n, size_t size,
X		     int (*compar)(const void *, const void *)));
X#define	abs(a)	((a) < 0 : -(a) : (a))
X
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/stdlib.h failed'
fi
# ============= stdc/string.h ==============
if test -f 'stdc/string.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/string.h (File already exists)'
else
echo 'x - extracting stdc/string.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/string.h' &&
X/* ANSI string handling (missing wide char stuff) */
X
X#if ! _STRING_H
X#define _STRING_H 1
X
X#include <stddef.h>		/* define NULL and size_t */
X
X#if __STDC__
X#define	ARGS(args)	args
X#define	Void	void
X#else
X#define	ARGS(args)	()
X#define	Void	char
X#endif
X
XVoid   *memcpy ARGS((Void *s1, const Void *s2, size_t));
XVoid   *memmove ARGS((Void *s1, const Void *s2, size_t));
Xint	memcmp ARGS((const Void *s1, const Void *s2, size_t));
XVoid   *memchr ARGS((const Void *s, int c, size_t));
XVoid   *memset ARGS((Void *s, int c, size_t));
Xsize_t	strlen ARGS((const char *s));
Xchar   *strcpy ARGS((char *s1, const char *s2));
Xchar   *strncpy ARGS((char *s1, const char *s2, size_t));
Xchar   *strcat ARGS((char *s1, const char *s2));
Xchar   *strncat ARGS((char *s1, const char *s2, size_t));
Xint	strcmp ARGS((const char *s1, const char *s2));
Xint	strncmp ARGS((const char *s1, const char *s2, size_t));
Xchar   *strchr ARGS((const char *s1, int c));
Xchar   *strrchr ARGS((const char *s1, int c));
Xsize_t	strspn ARGS((const char *s1, const char *s2));
Xsize_t	strcspn ARGS((const char *s1, const char *s2));
Xchar   *strpbrk ARGS((const char *s1, const char *s2));
Xchar   *strstr ARGS((const char *s1, const char *s2));
Xchar   *strtok ARGS((char *s1, const char *s2));
Xchar   *strerror ARGS((int errno));
X
X#endif /* _STRING_H */
X
SHAR_EOF
true || echo 'restore of stdc/string.h failed'
fi
# ============= stdc/strcat.c ==============
if test -f 'stdc/strcat.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strcat.c (File already exists)'
else
echo 'x - extracting stdc/strcat.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strcat.c' &&
X#include <string.h>
X
X/*
X * strcat - append string src to dst
X */
Xchar *				/* dst */
Xstrcat(dst, src)
Xchar *dst;
XConst char *src;
X{
X	register char *dscan;
X	register Const char *sscan;
X
X	for (dscan = dst; *dscan != '\0'; dscan++)
X		continue;
X	sscan = src;
X	while ((*dscan++ = *sscan++) != '\0')
X		continue;
X	return(dst);
X}
SHAR_EOF
true || echo 'restore of stdc/strcat.c failed'
fi
# ============= stdc/sprintf.c ==============
if test -f 'stdc/sprintf.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/sprintf.c (File already exists)'
else
echo 'x - extracting stdc/sprintf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/sprintf.c' &&
X/*
X * sprintf and vsprintf
X */
X
X/* $Header */
X
X#if __STDC__
X#include <stdarg.h>
X#else
X#include <varargs.h>
X#endif
X#include <stdio.h>
X
X#if _V7 || _BSD
X
Xint
X#if __STDC__
Xsprintf(char *s, Const char *fmt, ...) {
X#else
Xsprintf(va_alist) va_dcl
X{
X	char *s;
X	char *fmt;
X#endif
X	register va_list va;
X	int n;
X
X#if __STDC__
X	va_start(va, fmt);
X#else
X	va_start(va);
X	s = va_arg(va, char *);
X	fmt = va_arg(va, char *);
X#endif
X	n = vsprintf(s, fmt, va);
X	va_end(va);
X	return n;
X}
X
Xint
X#if __STDC__
Xvsprintf(char *s, const char *fmt, va_list va) {
X#else
Xvsprintf(s, fmt, va)
X	char *s;
X	char *fmt;
X	va_list va;
X{
X#endif
X	int n;
X	static FILE siob;
X
X	siob._flag = _IOWRT;
X	siob._base = siob._ptr = s;
X	siob._cnt = BUFSIZ;
X	siob._file = -1;
X
X	n = vfprintf(&siob, fmt, va);
X	*siob._ptr = 0;
X	return n;
X}
X
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/sprintf.c failed'
fi
# ============= stdc/time.h ==============
if test -f 'stdc/time.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/time.h (File already exists)'
else
echo 'x - extracting stdc/time.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/time.h' &&
X/* time, time/date conversion */
X
X#if ! _TIME_H
X#define	_TIME_H 1
X
X#include <stddef.h>		/* need size_t */
X
Xtypedef long time_t;
Xtypedef long clock_t;		/* seconds/CLK_TCK */
X
X#if _V7 || _SYSV
X#define	CLK_TCK	60		/* todo: get from <sys/param.h> */
X#endif
X
X#if _BSD
X#define	CLK_TCK	100
X#endif
X
X#if _ST
X#define	CLK_TCK	200		/* ST system clock */
X#endif
X
Xstruct tm {
X	int	tm_sec, tm_min, tm_hour;
X	int	tm_mday, tm_mon, tm_year, tm_wday, tm_yday;
X	int	tm_isdst;
X	long	tm_gmtoff;	/* BSD */
X	char   *tm_zone;	/* BSD */
X};
X
Xclock_t	clock ARGS((void));
Xtime_t	time ARGS((time_t *tp));
X#define	difftime(t1, t2)	(double)((t2)-(t1))
Xtime_t	mktime ARGS((struct tm *tmp));
Xchar   *asctime ARGS((const struct tm *tmp));
Xchar   *ctime ARGS((const time_t *tp));
Xstruct tm *gmtime ARGS((const time_t *tp));
Xstruct tm *localtime ARGS((const time_t *tp));
Xsize_t	strftime ARGS((char *buf, size_t len, const char *fmt, const struct tm *tmp));
X
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/time.h failed'
fi
# ============= stdc/memcpy.c ==============
if test -f 'stdc/memcpy.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/memcpy.c (File already exists)'
else
echo 'x - extracting stdc/memcpy.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/memcpy.c' &&
X/* $Header$ */
X
X#include <string.h>
X
XVoid *
Xmemcpy(dap, sap, n)
X	Void *dap;
X	Const Void *sap;
X	register size_t n;
X{
X	register char *dp = dap, *sp = (Void*) sap;
X
X	if (n++ > 0)
X		while (--n > 0)
X			*dp++ = *sp++;
X	return dap;
X}
X
SHAR_EOF
true || echo 'restore of stdc/memcpy.c failed'
fi
# ============= stdc/setvbuf.c ==============
if test -f 'stdc/setvbuf.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/setvbuf.c (File already exists)'
else
echo 'x - extracting stdc/setvbuf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/setvbuf.c' &&
X/*
X * PD ksh needs an ANSI-compatible setvbuf.
X * if (buf == NULL) it must also allocate a buffer
X * and arrange for fclose to deallocate it.
X * the reason for doing setvbuf(f, (char *)NULL, _IOFBF, BUFSIZ)
X * in the shell is to avoid 4/8K buffers on BSD like systems.
X */
X
X/* $Header */
X
X#include <stdlib.h>
X#include <stdio.h>
X
X#if _BSD || _SYSV
Xint
Xsetvbuf(f, buf, type, size)
X	register FILE *f;
X	char *buf;
X	int type;
X	size_t size;
X{
X	if ((f->_flag&_IOMYBUF) && f->_base != NULL)
X		free(f->_base);
X	f->_flag &= ~(_IOMYBUF|_IONBF|_IOFBF|_IOLBF);
X	switch (type) {
X	  case _IONBF:
X		size = 0;
X		buf = NULL;
X		break;
X	  case _IOLBF:
X	  case _IOFBF:
X		if (size == 0)
X			size = BUFSIZ;
X#if _V7
X		else if (size != BUFSIZ)
X			return -1;
X#endif
X		if (buf == NULL) {
X			buf = malloc(size);
X			if (buf == NULL)
X				return -1;
X			f->_flag |= _IOMYBUF;
X		}
X		break;
X	  default:
X		return -1;
X	}
X	f->_flag |= type;
X	f->_base = f->_ptr = buf;
X	f->_cnt = 0;
X#if _BSD
X	f->_bufsiz = size;
X#endif
X#if _SYSV
X	_bufend(f) = buf + size;
X#endif
X	return 0;
X}
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/setvbuf.c failed'
fi
# ============= stdc/clock.c ==============
if test -f 'stdc/clock.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/clock.c (File already exists)'
else
echo 'x - extracting stdc/clock.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/clock.c' &&
X/* clock() */
X
X#include <time.h>
X
X#if _BSD
X
X#include <sys/time.h>
X#include <sys/resource.h>
X
Xclock_t
Xclock()
X{
X	struct timeval tv;
X	struct rusage ru;
X
X	getrusage(RUSAGE_SELF, &ru);
X	tv.tv_sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
X	tv.tv_usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
X	return tv.tv_sec*CLK_TCK + (long)tv.tv_usec*CLK_TCK/1000000;
X}
X
X#endif
X
X#if _V7 || _SYSV
X
X#include <sys/times.h>
X
Xclock_t
Xclock()
X{
X	struct tms tms;
X
X	(void) times(&tms);
X	return tms.tms_utime + tms.tms_stime;
X}
X
X#endif
X
X#if _ST
X
X#include <osbind.h>
X
Xclock_t
Xclock()
X{
X	long save;
X	clock_t c;
X
X	/* access the ST's 200 HZ system clock in protected memory */
X	save = Super(0L);
X	c = *((long *)0x04BA);
X	(void)Super(save);
X	return c;
X}
X
X#endif
X
SHAR_EOF
true || echo 'restore of stdc/clock.c failed'
fi
# ============= stdc/types.h ==============
if test -f 'stdc/types.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/types.h (File already exists)'
else
echo 'x - extracting stdc/types.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/types.h' &&
X/* work around multiple typedefs in stddef.h and sys/types.h */
X
X#include <stddef.h>		/* defines size_t and ptrdiff_t */
X#include <time.h>		/* defines time_t and clock_t */
X
X/* "inhibit" the typedefs in sys/types.h */
X#define size_t _size_t
X#define	time_t _time_t
X#define	clock_t _clock_t
X#include "/usr/include/sys/types.h"
X#undef	size_t
X#undef	time_t
X#undef	clock_t
X
SHAR_EOF
true || echo 'restore of stdc/types.h failed'
fi
# ============= stdc/limits.h ==============
if test -f 'stdc/limits.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/limits.h (File already exists)'
else
echo 'x - extracting stdc/limits.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/limits.h' &&
X/* Implementation-defined limits */
X
X#if __STDC__
X#define	Signed	signed
X#else
X#define	Signed	
X#endif
X
X#define	CHAR_BIT	8
X
X#define	_S_MIN(type)	(-(Signed type)((unsigned type) ~0 >> 1) - 1)
X#define	_S_MAX(type)	((Signed type)((unsigned type) ~0 >> 1))
X
X#define	UCHAR_MIN	((unsigned char) 0)
X#define	UCHAR_MAX	((unsigned char) ~0)
X#define	SCHAR_MIN	_S_MIN(char)
X#define	SCHAR_MAX	_S_MAX(char)
X
X#define	_U_CHAR		((char) ~0 == (unsigned char) ~0)
X#define	CHAR_MIN	(_U_CHAR ? UCHAR_MIN : SCHAR_MIN)
X#define	CHAR_MAX	(_U_CHAR ? UCHAR_MAX : SCHAR_MAX)
X
X#define	USHRT_MAX	((unsigned short) ~0)
X#define	SHRT_MIN	_S_MIN(short)
X#define	SHRT_MAX	_S_MAX(short)
X
X#define	UINT_MAX	((unsigned int) ~0)
X#define	INT_MIN		_S_MIN(int)
X#define	INT_MAX		_S_MAX(int)
X
X#define	ULONG_MAX	((unsigned long) ~0)
X#define	LONG_MIN	_S_MIN(long)
X#define	LONG_MAX	_S_MAX(long)
X
SHAR_EOF
true || echo 'restore of stdc/limits.h failed'
fi
# ============= stdc/stdarg.h ==============
if test -f 'stdc/stdarg.h' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/stdarg.h (File already exists)'
else
echo 'x - extracting stdc/stdarg.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/stdarg.h' &&
X#ifndef _STDARG_H
X#define _STDARG_H
X
Xtypedef char *va_list;
X
X/* Amount of space required in an argument list for an arg of type TYPE.
X   TYPE may alternatively be an expression whose type is used.  */
X
X#define __va_rounded_size(TYPE)  \
X  (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
X
X#define va_start(AP, LASTARG) 						\
X (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
X
Xvoid va_end (va_list);		/* Defined in gnulib */
X#define va_end(AP)
X
X#define va_arg(AP, TYPE)						\
X (AP += __va_rounded_size (TYPE),					\
X  *((TYPE *) (AP - __va_rounded_size (TYPE))))
X
X#endif /* _STDARG_H */
SHAR_EOF
true || echo 'restore of stdc/stdarg.h failed'
fi
# ============= stdc/strcmp.s ==============
if test -f 'stdc/strcmp.s' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strcmp.s (File already exists)'
else
echo 'x - extracting stdc/strcmp.s (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strcmp.s' &&
X#NO_APP
X.text
X	.even
X.globl _strcmp
X_strcmp:
X	link a6,#0
X	movel a6@(8),a1
X	movel a6@(12),a0
XL2:
X	moveb a1 at +,d0
X	moveb a0 at +,d1
X	cmpb d0,d1
X	jne L3
X	tstb d0
X	jne L2
XL3:
X	tstb d0
X	jne L4
X	tstb d1
X	jne L4
X	clrl d0
X	jra L1
XL4:
X	tstb d0
X	jne L6
X	moveq #-1,d0
X	jra L1
XL6:
X	tstb d1
X	jne L8
X	moveq #1,d0
X	jra L1
XL8:
X	extbl d0
X	extbl d1
X	subl d1,d0
XL1:
X	unlk a6
X	rts
SHAR_EOF
true || echo 'restore of stdc/strcmp.s failed'
fi
# ============= stdc/strcpy.s ==============
if test -f 'stdc/strcpy.s' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strcpy.s (File already exists)'
else
echo 'x - extracting stdc/strcpy.s (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strcpy.s' &&
X#NO_APP
X.text
X	.align 1
X.globl _strcpy
X_strcpy:
X	.word 0x0
X	movl 4(ap),r3
X	movl r3,r2
X	movl 8(ap),r1
XL3:
X	movb (r1)+,r0
X	movb r0,(r2)+
X	jneq L3
X	movl r3,r0
X	ret
SHAR_EOF
true || echo 'restore of stdc/strcpy.s failed'
fi
# ============= stdc/memchr.c ==============
if test -f 'stdc/memchr.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/memchr.c (File already exists)'
else
echo 'x - extracting stdc/memchr.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/memchr.c' &&
X/* $Header$ */
X
X#include <string.h>
X
XVoid *
Xmemchr(ap, c, n)
X	Const Void *ap;
X	register int c;
X	register size_t n;
X{
X	register char *p = ap;
X
X	if (n++ > 0)
X		while (--n > 0)
X			if (*p++ == c)
X				return --p;
X	return NULL;
X}
X
SHAR_EOF
true || echo 'restore of stdc/memchr.c failed'
fi
# ============= stdc/memcmp.c ==============
if test -f 'stdc/memcmp.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/memcmp.c (File already exists)'
else
echo 'x - extracting stdc/memcmp.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/memcmp.c' &&
X/* $Header$ */
X
X#include <string.h>
X
Xint
Xmemcmp(dap, sap, n)
X	Const Void *dap;
X	Const Void *sap;
X	register size_t n;
X{
X	register Const unsigned char *dp = (unsigned char Const *) dap;
X	register Const unsigned char *sp = (unsigned char Const *) sap;
X
X	if (n++ > 0)
X		while (--n > 0)
X			if (*dp++ != *sp++)
X				return *--dp - *--sp; /* (int)? */
X	return 0;
X}
X
SHAR_EOF
true || echo 'restore of stdc/memcmp.c failed'
fi
# ============= stdc/memmove.c ==============
if test -f 'stdc/memmove.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/memmove.c (File already exists)'
else
echo 'x - extracting stdc/memmove.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/memmove.c' &&
X/* $Header$ */
X
X#include <string.h>
X
XVoid *
Xmemmove(dap, sap, n)
X	Void *dap;
X	Const Void *sap;
X	register size_t n;
X{
X	register char *dp = dap, *sp = (Void*) sap;
X
X	if (n <= 0)
X		;
X	else if (dp < sp)
X		do *dp++ = *sp++; while (--n > 0);
X	else if (dp > sp) {
X		dp += n;
X		sp += n;
X		do *--dp = *--sp; while (--n > 0);
X	}
X	return dap;
X}
X
X
SHAR_EOF
true || echo 'restore of stdc/memmove.c failed'
fi
# ============= stdc/memset.c ==============
if test -f 'stdc/memset.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/memset.c (File already exists)'
else
echo 'x - extracting stdc/memset.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/memset.c' &&
X/* $Header$ */
X
X#include <string.h>
X
XVoid *
Xmemset(ap, c, n)
X	Void *ap;
X	register int c;
X	register size_t n;
X{
X	register char *p = ap;
X
X	if (n++ > 0)
X		while (--n > 0)
X			*p++ = c;
X	return ap;
X}
X
SHAR_EOF
true || echo 'restore of stdc/memset.c failed'
fi
# ============= stdc/fprintf.c ==============
if test -f 'stdc/fprintf.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/fprintf.c (File already exists)'
else
echo 'x - extracting stdc/fprintf.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/fprintf.c' &&
X/*
X * printf and fprintf
X */
X
X/* $Header */
X
X#if __STDC__
X#include <stdarg.h>
X#else
X#include <varargs.h>
X#endif
X#include <stdio.h>
X
X#if _V7 || _BSD
X
X/* printf to stdout */
Xint
X#if __STDC__
Xprintf(Const char *fmt, ...) {
X#else
Xprintf(va_alist) va_dcl
X{
X	char *fmt;
X#endif
X	va_list va;
X
X#if __STDC__
X	va_start(va, fmt);
X#else
X	va_start(va);
X	fmt = va_arg(va, char *);
X#endif
X	vfprintf(stdout, fmt, va);
X	va_end(va);
X	return 0;
X}
X
Xint
X#if __STDC__
Xfprintf(FILE *f, Const char *fmt, ...) {
X#else
Xfprintf(va_alist) va_dcl
X{
X	FILE *f;
X	char *fmt;
X#endif
X	va_list va;
X
X#if __STDC__
X	va_start(va, fmt);
X#else
X	va_start(va);
X	f = va_arg(va, FILE *);
X	fmt = va_arg(va, char *);
X#endif
X	vfprintf(f, fmt, va);
X	va_end(va);
X	return 0;
X}
X
X#endif
SHAR_EOF
true || echo 'restore of stdc/fprintf.c failed'
fi
# ============= stdc/strtok.c ==============
if test -f 'stdc/strtok.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strtok.c (File already exists)'
else
echo 'x - extracting stdc/strtok.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strtok.c' &&
X#include <string.h>
X
X/*
X * Get next token from string s (NULL on 2nd, 3rd, etc. calls),
X * where tokens are nonempty strings separated by runs of
X * chars from delim.  Writes NULs into s to end tokens.  delim need not
X * remain constant from call to call.
X */
X
Xstatic char *scanpoint = NULL;
X
Xchar *				/* NULL if no token left */
Xstrtok(s, delim)
Xchar *s;
Xregister Const char *delim;
X{
X	register char *scan;
X	char *tok;
X	register Const char *dscan;
X
X	if (s == NULL && scanpoint == NULL)
X		return(NULL);
X	if (s != NULL)
X		scan = s;
X	else
X		scan = scanpoint;
X
X	/*
X	 * Scan leading delimiters.
X	 */
X	for (; *scan != '\0'; scan++) {
X		for (dscan = delim; *dscan != '\0'; dscan++)
X			if (*scan == *dscan)
X				break;
X		if (*dscan == '\0')
X			break;
X	}
X	if (*scan == '\0') {
X		scanpoint = NULL;
X		return(NULL);
X	}
X
X	tok = scan;
X
X	/*
X	 * Scan token.
X	 */
X	for (; *scan != '\0'; scan++) {
X		for (dscan = delim; *dscan != '\0';)	/* ++ moved down. */
X			if (*scan == *dscan++) {
X				scanpoint = scan+1;
X				*scan = '\0';
X				return(tok);
X			}
X	}
X
X	/*
X	 * Reached end of string.
X	 */
X	scanpoint = NULL;
X	return(tok);
X}
SHAR_EOF
true || echo 'restore of stdc/strtok.c failed'
fi
# ============= stdc/strchr.c ==============
if test -f 'stdc/strchr.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strchr.c (File already exists)'
else
echo 'x - extracting stdc/strchr.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strchr.c' &&
X#include <string.h>
X
X/*
X * strchr - find first occurrence of a character in a string
X */
X
Xchar *				/* found char, or NULL if none */
Xstrchr(s, charwanted)
XConst char *s;
Xregister char charwanted;
X{
X	register Const char *scan;
X
X	/*
X	 * The odd placement of the two tests is so NUL is findable.
X	 */
X	for (scan = s; *scan != charwanted;)	/* ++ moved down for opt. */
X		if (*scan++ == '\0')
X			return(NULL);
X	return(scan);
X}
SHAR_EOF
true || echo 'restore of stdc/strchr.c failed'
fi
# ============= stdc/strcmp.c ==============
if test -f 'stdc/strcmp.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strcmp.c (File already exists)'
else
echo 'x - extracting stdc/strcmp.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strcmp.c' &&
X#include <string.h>
X
X/* Modified by Eric Gisin */
X
X/*
X * strcmp - compare string s1 to s2
X */
X
Xint				/* <0 for <, 0 for ==, >0 for > */
Xstrcmp(s1, s2)
XConst char *s1;
XConst char *s2;
X{
X	register Const char *scan1;
X	register Const char *scan2;
X#if 0				/* some machines prefer int to char */
X	register int c1, c2;
X#else
X	register char c1, c2;
X#endif
X
X	scan1 = s1;
X	scan2 = s2;
X	while ((c1 = *scan1++) == (c2 = *scan2++) && c1 != 0)
X		;
X
X	/*
X	 * The following case analysis is necessary so that characters
X	 * which look negative collate low against normal characters but
X	 * high against the end-of-string NUL.
X	 */
X	if (c1 == '\0' && c2 == '\0')
X		return(0);
X	else if (c1 == '\0')
X		return(-1);
X	else if (c2 == '\0')
X		return(1);
X	else
X		return(c1 - c2);
X}
SHAR_EOF
true || echo 'restore of stdc/strcmp.c failed'
fi
# ============= stdc/strcpy.c ==============
if test -f 'stdc/strcpy.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strcpy.c (File already exists)'
else
echo 'x - extracting stdc/strcpy.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strcpy.c' &&
X#include <string.h>
X
X/*
X * strcpy - copy string src to dst
X */
Xchar *				/* dst */
Xstrcpy(dst, src)
Xchar *dst;
XConst char *src;
X{
X	register char *dscan;
X	register Const char *sscan;
X
X	dscan = dst;
X	sscan = src;
X	while ((*dscan++ = *sscan++) != '\0')
X		continue;
X	return(dst);
X}
SHAR_EOF
true || echo 'restore of stdc/strcpy.c failed'
fi
# ============= stdc/strcspn.c ==============
if test -f 'stdc/strcspn.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strcspn.c (File already exists)'
else
echo 'x - extracting stdc/strcspn.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strcspn.c' &&
X#include <string.h>
X
X/*
X * strcspn - find length of initial segment of s consisting entirely
X * of characters not from reject
X */
X
Xsize_t
Xstrcspn(s, reject)
XConst char *s;
XConst char *reject;
X{
X	register Const char *scan;
X	register Const char *rscan;
X	register size_t count;
X
X	count = 0;
X	for (scan = s; *scan != '\0'; scan++) {
X		for (rscan = reject; *rscan != '\0';)	/* ++ moved down. */
X			if (*scan == *rscan++)
X				return(count);
X		count++;
X	}
X	return(count);
X}
SHAR_EOF
true || echo 'restore of stdc/strcspn.c failed'
fi
# ============= stdc/strerror.c ==============
if test -f 'stdc/strerror.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strerror.c (File already exists)'
else
echo 'x - extracting stdc/strerror.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strerror.c' &&
X#include <string.h>
X
X/*
X * strerror - map error number to descriptive string
X *
X * This version is obviously somewhat Unix-specific.
X */
Xchar *
Xstrerror(errno)
Xint errno;
X{
X	extern int sys_nerr;
X	extern char *sys_errlist[];
X
X	if (errno > 0 && errno < sys_nerr)
X		return(sys_errlist[errno]);
X	else
X		return("unknown error");
X}
SHAR_EOF
true || echo 'restore of stdc/strerror.c failed'
fi
# ============= stdc/strlen.c ==============
if test -f 'stdc/strlen.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strlen.c (File already exists)'
else
echo 'x - extracting stdc/strlen.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strlen.c' &&
X#include <string.h>
X
X/*
X * strlen - length of string (not including NUL)
X */
Xsize_t
Xstrlen(s)
XConst char *s;
X{
X	register Const char *scan;
X	register size_t count;
X
X	count = 0;
X	scan = s;
X	while (*scan++ != '\0')
X		count++;
X	return(count);
X}
SHAR_EOF
true || echo 'restore of stdc/strlen.c failed'
fi
# ============= stdc/strncat.c ==============
if test -f 'stdc/strncat.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strncat.c (File already exists)'
else
echo 'x - extracting stdc/strncat.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strncat.c' &&
X#include <string.h>
X
X/*
X * strncat - append at most n characters of string src to dst
X */
Xchar *				/* dst */
Xstrncat(dst, src, n)
Xchar *dst;
XConst char *src;
Xsize_t n;
X{
X	register char *dscan;
X	register Const char *sscan;
X	register size_t count;
X
X	for (dscan = dst; *dscan != '\0'; dscan++)
X		continue;
X	sscan = src;
X	count = n;
X	while (*sscan != '\0' && --count >= 0)
X		*dscan++ = *sscan++;
X	*dscan++ = '\0';
X	return(dst);
X}
SHAR_EOF
true || echo 'restore of stdc/strncat.c failed'
fi
# ============= stdc/strncmp.c ==============
if test -f 'stdc/strncmp.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strncmp.c (File already exists)'
else
echo 'x - extracting stdc/strncmp.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strncmp.c' &&
X#include <string.h>
X
X/*
X * strncmp - compare at most n characters of string s1 to s2
X */
X
Xint				/* <0 for <, 0 for ==, >0 for > */
Xstrncmp(s1, s2, n)
XConst char *s1;
XConst char *s2;
Xsize_t n;
X{
X	register Const char *scan1;
X	register Const char *scan2;
X	register size_t count;
X
X	scan1 = s1;
X	scan2 = s2;
X	count = n;
X	while (--count >= 0 && *scan1 != '\0' && *scan1 == *scan2) {
X		scan1++;
X		scan2++;
X	}
X	if (count < 0)
X		return(0);
X
X	/*
X	 * The following case analysis is necessary so that characters
X	 * which look negative collate low against normal characters but
X	 * high against the end-of-string NUL.
X	 */
X	if (*scan1 == '\0' && *scan2 == '\0')
X		return(0);
X	else if (*scan1 == '\0')
X		return(-1);
X	else if (*scan2 == '\0')
X		return(1);
X	else
X		return(*scan1 - *scan2);
X}
SHAR_EOF
true || echo 'restore of stdc/strncmp.c failed'
fi
# ============= stdc/strncpy.c ==============
if test -f 'stdc/strncpy.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strncpy.c (File already exists)'
else
echo 'x - extracting stdc/strncpy.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strncpy.c' &&
X#include <string.h>
X
X/*
X * strncpy - copy at most n characters of string src to dst
X */
Xchar *				/* dst */
Xstrncpy(dst, src, n)
Xchar *dst;
XConst char *src;
Xsize_t n;
X{
X	register char *dscan;
X	register Const char *sscan;
X	register size_t count;
X
X	dscan = dst;
X	sscan = src;
X	count = n;
X	while (--count >= 0 && (*dscan++ = *sscan++) != '\0')
X		continue;
X	while (--count >= 0)
X		*dscan++ = '\0';
X	return(dst);
X}
SHAR_EOF
true || echo 'restore of stdc/strncpy.c failed'
fi
# ============= stdc/strpbrk.c ==============
if test -f 'stdc/strpbrk.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strpbrk.c (File already exists)'
else
echo 'x - extracting stdc/strpbrk.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strpbrk.c' &&
X#include <string.h>
X
X/*
X * strpbrk - find first occurrence of any char from breakat in s
X */
X
Xchar *				/* found char, or NULL if none */
Xstrpbrk(s, breakat)
XConst char *s;
XConst char *breakat;
X{
X	register Const char *sscan;
X	register Const char *bscan;
X
X	for (sscan = s; *sscan != '\0'; sscan++) {
X		for (bscan = breakat; *bscan != '\0';)	/* ++ moved down. */
X			if (*sscan == *bscan++)
X				return(sscan);
X	}
X	return(NULL);
X}
SHAR_EOF
true || echo 'restore of stdc/strpbrk.c failed'
fi
# ============= stdc/strrchr.c ==============
if test -f 'stdc/strrchr.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strrchr.c (File already exists)'
else
echo 'x - extracting stdc/strrchr.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strrchr.c' &&
X#include <string.h>
X
X/*
X * strrchr - find last occurrence of a character in a string
X */
X
Xchar *				/* found char, or NULL if none */
Xstrrchr(s, charwanted)
XConst char *s;
Xregister char charwanted;
X{
X	register Const char *scan;
X	register Const char *place;
X
X	place = NULL;
X	for (scan = s; *scan != '\0'; scan++)
X		if (*scan == charwanted)
X			place = scan;
X	if (charwanted == '\0')
X		return(scan);
X	return(place);
X}
SHAR_EOF
true || echo 'restore of stdc/strrchr.c failed'
fi
# ============= stdc/strspn.c ==============
if test -f 'stdc/strspn.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strspn.c (File already exists)'
else
echo 'x - extracting stdc/strspn.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strspn.c' &&
X#include <string.h>
X
X/*
X * strspn - find length of initial segment of s consisting entirely
X * of characters from accept
X */
X
Xsize_t
Xstrspn(s, accept)
XConst char *s;
XConst char *accept;
X{
X	register Const char *sscan;
X	register Const char *ascan;
X	register size_t count;
X
X	count = 0;
X	for (sscan = s; *sscan != '\0'; sscan++) {
X		for (ascan = accept; *ascan != '\0'; ascan++)
X			if (*sscan == *ascan)
X				break;
X		if (*ascan == '\0')
X			return(count);
X		count++;
X	}
X	return(count);
X}
SHAR_EOF
true || echo 'restore of stdc/strspn.c failed'
fi
# ============= stdc/strstr.c ==============
if test -f 'stdc/strstr.c' -a X"$1" != X"-c"; then
	echo 'x - skipping stdc/strstr.c (File already exists)'
else
echo 'x - extracting stdc/strstr.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'stdc/strstr.c' &&
X#include <string.h>
X
X/*
X * strstr - find first occurrence of wanted in s
X */
X
Xchar *				/* found string, or NULL if none */
Xstrstr(s, wanted)
XConst char *s;
XConst char *wanted;
X{
X	register Const char *scan;
X	register size_t len;
X	register char firstc;
X
X	/*
X	 * The odd placement of the two tests is so "" is findable.
X	 * Also, we inline the first char for speed.
X	 * The ++ on scan has been moved down for optimization.
X	 */
X	firstc = *wanted;
X	len = strlen(wanted);
X	for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
X		if (*scan++ == '\0')
X			return(NULL);
X	return(scan);
X}
SHAR_EOF
true || echo 'restore of stdc/strstr.c failed'
fi
exit 0



More information about the Alt.sources mailing list