0707070000000000011006440044230044230000010000000475416516000002400000006446Makefile Ugsf Ggsf /* * libx make */ VERSION = 3.0 .SOURCE : comp dir hash man misc port preroot re \ sfio stdio string tm vec .SOURCE.h : include DEBUG == LIBX == 1 HEADERSRC = error.h ftwalk.h hash.h hashpart.h ls.h namval.h \ option.h re.h sfio.h stack.h stak.h stdio.h swap.h tar.h tm.h HEADERGEN = align.h dirent.h fsinfo.h limits.h sigdata.h HEADERMK = lcldirent.h lcllimits.h lclparam.h lclstdio.h \ preroot.h sig.h ttyinfo.h x $(VERSION) :LIBRARY: README hash.3 ftwalk.3 re.3 sfio.3 stak.3 tm.3 \ $(HEADERSRC) \ dirlib.h opendir.c readdir.c rewinddir.c seekdir.c telldir.c \ getcwd.c setcwd.c getshell.c \ hashlib.h hashalloc.c hashdump.c hashfree.c hashlook.c \ hashscan.c hashsize.c hashwalk.c \ memhash.c memsum.c strhash.c strsum.c \ cvtatoe.c cvtetoa.c \ chresc.c ctoi.c streval.c strmatch.c strcopy.c \ modelib.h strmode.c \ stresc.c stropt.c strtape.c tok.c \ pathaccess.c pathcanon.c pathcheck.c pathpath.c \ pathkey.c pathprobe.c pathtemp.c \ cmdargs.c fs3d.c ftwalk.c perror.c putenv.c calloc.c malloc.c \ getnamval.c optget.c hsort.c query.c \ error.c liberror.c strerror.c strsignal.c \ fmtelapsed.c fmtls.c fmtmode.c fmtperm.c fmtuid.c fmtgid.c \ strelapsed.c strperm.c struid.c strgid.c stack.c stak.c \ memswap.c gethalf.c getlong.c puthalf.c putlong.c \ fgetline.c sigcrit.c sigunblock.c \ cmdlib.h cmdopen.c cmdclose.c cmdrun.c cmdwait.c cmdkill.c \ relib.h recomp.c reerror.c reexec.c resub.c \ tmdate.c tmfix.c tmform.c tmgoff.c \ tminit.c tmleap.c tmlex.c tmmake.c tmpoff.c \ tmtime.c tmtype.c tmword.c tmzone.c \ vecargs.c vecfile.c vecfree.c vecload.c vecstring.c \ getsymlink.c putsymlink.c univlib.h univdata.c getuniv.c setuniv.c \ winsize.c fclex.c sigdata.c touch.c lpstat.c \ memcmp.c memcpy.c memdup.c memset.c \ mkdir.c rmdir.c remove.c rename.c link.c unlink.c \ strtok.c strspn.c strpbrk.c strdup.c strchr.c strrchr.c \ strtod.c strtol.c strton.c sigsetmask.c mktemp.c tmpnam.c \ vfork.c killpg.c lstat.c readlink.c symlink.c setpgid.c \ atexit.c getdents.c getwd.c copy.c dup2.c errno.c sgetl.c sputl.c \ getpreroot.c ispreroot.c realopen.c setpreroot.c \ mount.c popen.c system.c iblocks.c \ modedata.c tmdata.c \ sfhdr.h sfclose.c sfclrlock.c sfcvt.c sfdlen.c sfdopen.c \ sfexcept.c sfextern.c sffilbuf.c sfflsbuf.c sfgetd.c sfgetl.c \ sfgets.c sfgetu.c sfllen.c sfmode.c sfmove.c sfnew.c sfnotify.c \ sfnputc.c sfopen.c sfpeek.c sfpool.c sfpopen.c sfprintf.c sfputd.c \ sfputl.c sfputs.c sfputu.c sfread.c sfscanf.c sfseek.c \ sfsetbuf.c sfsetdisc.c sfset.c sfstack.c sfstrtod.c \ sfsync.c sftable.c sftell.c sftmpfile.c sfungetc.c sfvprintf.c \ sfvscanf.c sfwrite.c \ _sfhdr.h _sfclearerr.c _sffileno.c _sforigin.c _sfputl.c _sftmp.c \ _sfecvt.c _sfgetc.c _sfpeek.c _sfputu.c _sfulen.c _sfeof.c _sfgetl.c \ _sfpushed.c _sfslen.c _sferror.c _sfgetu.c _sfputc.c _sffcvt.c \ _sfputd.c _sfsync.c \ stdgets.c stdprintf.c stdscanf.c stdsetvbuf.c stdsprintf.c \ stdvsprintf.c stdvsscanf.c sprintf.c vsprintf.c :READONLY: modedata.c sftable.c sigdata.c tmdata.c univdata.c $(INCLUDEDIR) :INSTALLDIR: $(HEADERSRC) $(HEADERGEN) $(HEADERMK) :INSTALLDIR: mkhdr genhdr mkhdr :: mkhdr.sh genhdr :: genhdr.c $(HEADERGEN) : mkhdr genhdr $(*:N=*mkhdr) $(<:B) "$(TARGET:/\\\\/\\/G) $(*:N=*genhdr)" "$(CC)" $(CCFLAGS) > $(<) $(HEADERMK) : mkhdr $(*) $(<:B) "" "$(CC)" $(CCFLAGS) > $(<) 0707070000000000021006440044230044230000010000000441571252600002200000006712README Ugsf Ggsf The advanced software department has been collecting useful C routines in a single library called libx. libx is used by nmake, the nmake cpp (which is mainly based on another library (libpp)), CIA (C information abstractor from Yih-Farn Chen), and a collection of other /bin and /usr/bin commands that benefit from concentrating functionality in libx. More detail is available in the man pages. libx contains: (1) routines to support a generic environment for a variety of UNIX operating system variants (2) routines that update standard libc routines (3) routines shared between several commands If you already have nmake 2.0 or newer installed then use `nmake install' from this directory, otherwise use ship/shipin from the root of the distribution directory tree. Some of the routines not found in section 3: hash: generic, scoped hash table support hashalloc create a hash table or push new scope hashdump debug dump of one or all hash tables hashfree free a hashalloc()'d table hashlook low level name lookup hashscan entry generator for scoped table scan hashsize explicitly change table size (usually automatic) hashwalk apply function to each table entry memhash return hash code for n-char chunk of memory strhash return hash code for null terminated string include: libx support headers align.h compile time type alignmnent support dirent.h POSIX directory(3) interface definitions error.h error() interface definitions ftw.h ftwalk() interface definitions hash.h hash*() interface definitions ls.h strls() interface definitions re.h re*() interface definitions tar.h POSIX ustar format interface definitions tm.h tm*() interface definitions misc: cmdargs apply a sequence of cmd line option parsers cmdopen like popen() but stdin and stdout are specified cvtatoe convert ASCII to EBCDIC cvtetoa convert EBCDIC to ASCII error output generic error and trace messages ftwalk an ftw(3) that works -- used in new tw(1) getcwd uses $PWD if ok, doesn't use /bin/pwd getshell return full path of shell for cmdopen() ooptget optget() for obsolete ar(1) and tar(1) options optget YA getopt(3) but no argc or error message output pathaccess find file with specific acces on list of dirs pathcanon canonicalize path name in place pathcmd return full path name of executable using $PATH pathroot determine `related root' directory for command perror uses strerror() readargs append each line of file to argv[0] re: egrep(1) and ed(1) style re's from V9 (not the good awk(1) algorithm) recomp compile re pattern reerror report re*() errors reexec match string using compiled re resub ed(1) style substitute using last reexec() string: chresc return next char in string converting \ sequences ctoi convert char constant string to int strcopy like strcpy(3) but returns end of destination strdup malloc(3) and strcpy(3) smashed together strerror return error message string given errno stresc convert \ sequences in string in place streval evaluate C expression in string strls ls -l format support strmatch Korn shell file pattern match strmode return ls -l style output given st.st_mode strsignal return signal id string given SIG* number strtape convert generic tape unit to /dev/* file token generate space separated tokens in string tm: time conversion support tmdate convert date string to time_t tmform format time_t to date string tmmake return current time_t tmtime convert struct tm to time_t 0707070000000000031006440044230044230000010000000471771066600003100000001610comp/atexit.c Ugsf Ggsf /* * ANSI C atexit() * arrange for func to be called LIFO on exit() */ #include "FEATURE/atexit" #ifdef _lib_atexit int _lib_dummy; #else typedef void (*PFV)(); #include "FEATURE/onexit" #ifdef _lib_onexit int atexit(func) PFV func; { return(onexit(func)); } #else #include "FEATURE/on_exit" #ifdef _lib_on_exit int atexit(func) PFV func; { return(on_exit(func)); } #else #include "FEATURE/_cleanup" struct list { struct list* next; PFV func; }; static struct list* funclist; extern char* malloc(); int atexit(func) PFV func; { register struct list* p; if (!(p = (struct list*)malloc(sizeof(struct list)))) return(-1); p->func = func; p->next = funclist; funclist = p; return(0); } int exit(code) int code; { register struct list* p; for (p = funclist; p; p = p->next) (*p->func)(); #ifdef _lib__cleanup _cleanup(); #endif _exit(code); } #endif #endif #endif 0707070000000000041006440044230044230000010000000441570075300002700000000512comp/dup2.c Ugsf Ggsf #include "FEATURE/dup2" #ifdef _lib_dup2 int _lib_dummy; #else #include <fcntl.h> extern int errno; extern int close(); extern int fcntl(); int dup2(d1, d2) int d1; int d2; { int save_errno; if (d1 == d2) return(d1); save_errno = errno; (void)close(d2); errno = save_errno; return(fcntl(d1, F_DUPFD, d2)); } #endif 0707070000000000051006440044230044230000010000000461342262600003000000000220comp/errno.c Ugsf Ggsf /* * this avoids multiple definitions with some libc's * that define both a libx supplied routine and errno * in the same .o */ int errno; 0707070000000000061006440044230044230000010000000474436324700003300000007014comp/getdents.c Ugsf Ggsf #include "FEATURE/getdents" #ifdef _lib_getdents int _lib_dummy; #else /* * getdents * * read directory entries into directory block * * NOTE: directory entries must fit within DIRBLKSIZ boundaries */ #include <fsinfo.h> #include <dirent.h> #include <errno.h> #define round(x,y) (((x)+((y)-1))&~((y)-1)) #ifndef DIRBLKSIZ #ifdef DIRBLK #define DIRBLKSIZ DIRBLK #else #ifdef DIRBUF #define DIRBLKSIZ DIRBUF #else #ifdef DEV_BSIZE #define DIRBLKSIZ DEV_BSIZE #else #define DIRBLKSIZ 4096 #endif #endif #endif #endif #ifndef MAXNAMLEN #define MAXNAMLEN 255 #endif int getdents(fd, buf, siz) int fd; char* buf; int siz; { struct stat st; extern int errno; extern int fstat(); if (siz < DIRBLKSIZ) { errno = EINVAL; return(-1); } if (fstat(fd, &st)) return(-1); if ((st.st_mode & S_IFMT) != S_IFDIR) { #ifdef ENOTDIR errno = ENOTDIR; #else errno = EBADF; #endif return(-1); } #include "FEATURE/getdirentries" #ifdef _lib_getdirentries { long off; extern int getdirentries(); return(getdirentries(fd, buf, siz, &off)); } #else #include "FEATURE/dirread" #ifdef _lib_dirread { register char* sp; /* system */ register struct dirent* up; /* user */ char* u; int n; int m; int i; extern int dirread(); m = (siz * 6) / 10; m = round(m, 8); sp = buf + siz - m - 1; if (!(n = dirread(fd, sp, m))) return(0); if (n > 0) { up = (struct dirent*)buf; sp[n] = 0; while (sp < buf + siz - m + n) { i = 0; while (*sp >= '0' && *sp <= '9') i = 10 * i + *sp++ - '0'; while (*sp && *sp != '\t') sp++; if (*sp++) { up->d_ino = i; u = up->d_name; while ((*u = *sp++) && u < up->d_name + MAXNAMLEN) u++; *u = 0; up->d_reclen = sizeof(struct dirent) - sizeof(up->d_name) + ( #if defined(d_fileno) || defined(d_ino) up->d_namlen = #endif u - up->d_name) + 1; up->d_reclen = round(up->d_reclen, 8); up = (struct dirent*)((char*)up + up->d_reclen); } } return((char*)up - buf); } } #endif { #ifndef _dir_fixed #include "FEATURE/readdir" #ifndef _lib_readdir #define _dir_fixed #endif #endif #ifdef _dir_fixed #ifndef DIRSIZ #include "FEATURE/dir" #ifdef _sys_dir #include <sys/dir.h> #endif #endif #define MAXREC round(sizeof(*up)-sizeof(up->d_name)+sizeof(sp->d_name)+1,8) register struct direct* sp; /* system */ register struct dirent* up; /* user */ register char* s; register char* u; int n; int m; char tmp[sizeof(sp->d_name) + 1]; extern int read(); extern int strcpy(); /* * we assume sizeof(struct dirent) > sizeof(struct direct) */ up = (struct dirent*)buf; n = (siz / MAXREC) * sizeof(struct direct); if ((!(m = n & ~511) || m < MAXREC) && (!(m = n & ~255) || m < MAXREC)) m = n; do { if ((n = read(fd, buf + siz - m, m)) <= 0) break; sp = (struct direct*)(buf + siz - m); while (sp < (struct direct*)(buf + siz - m + n)) { if (sp->d_ino) { up->d_ino = sp->d_ino; s = sp->d_name; u = tmp; while (s < sp->d_name + sizeof(sp->d_name) && *s) *u++ = *s++; *u = 0; (void)strcpy(up->d_name, tmp); up->d_reclen = sizeof(struct dirent) - sizeof(up->d_name) + ( #if defined(d_fileno) || defined(d_ino) up->d_namlen = #endif u - tmp) + 1; up->d_reclen = round(up->d_reclen, 8); up = (struct dirent*)((char*)up + up->d_reclen); } sp++; } } while (up == (struct dirent*)buf); return((char*)up - buf); #else extern int read(); return(read(fd, buf, siz)); #endif } #endif } #endif 0707070000000000071006440044230044230000010000000441570077400003100000000234comp/killpg.c Ugsf Ggsf #include "FEATURE/killpg" #ifdef _lib_killpg int _lib_dummy; #else extern int kill(); int killpg(g, s) int g; int s; { return(kill(-g, s)); } #endif 0707070000000000101006440044230044230000010000000472226401000002700000000275comp/link.c Ugsf Ggsf #include "FEATURE/link" #ifdef _lib_link int _lib_dummy; #else #include <errno.h> extern int errno; int link(from, to) char* from; char* to; { errno = EINVAL; return(-1); } #endif 0707070000000000111006440044230044230000010000000472226261100003000000000336comp/lstat.c Ugsf Ggsf #include "FEATURE/lstat" #ifdef _lib_lstat int _lib_dummy; #else #include <sys/types.h> #include <sys/stat.h> extern int stat(); int lstat(path, st) char* path; struct stat* st; { return(stat(path, st)); } #endif 0707070000000000121006440044230044230000010000000441570100700003100000000450comp/memcmp.c Ugsf Ggsf #include "FEATURE/memcmp" #ifdef _lib_memcmp int _lib_dummy; #else int memcmp(b1, b2, n) register unsigned char* b1; register unsigned char* b2; unsigned int n; { register unsigned char* e; e = b1 + n; while (b1 < e) if (*b1++ != *b2++) return(*--b1 - *--b2); return(0); } #endif 0707070000000000131006440044230044230000010000000455540707300003100000000627comp/memcpy.c Ugsf Ggsf #include "FEATURE/memcpy" #ifdef _lib_memcpy int _lib_dummy; #else #include "FEATURE/bcopy" #ifdef _lib_bcopy extern void bcopy(); char* memcpy(s1, s2, n) char* s1; char* s2; int n; { bcopy(s2, s1, n); return(s1); } #else char* memcpy(s1, s2, n) register char* s1; register char* s2; register int n; { register char* os1 = s1; while (--n >= 0) *s1++ = *s2++; return(os1); } #endif #endif 0707070000000000141006440044230044230000010000000472226263000003100000000331comp/memset.c Ugsf Ggsf #include "FEATURE/memset" #ifdef _lib_memset int _lib_dummy; #else char* memset(sp, c, n) register char *sp, c; register int n; { register char *sp0 = sp; while (--n >= 0) *sp++ = c; return (sp0); } #endif 0707070000000000151006440044230044230000010000000472226263600003000000001270comp/mkdir.c Ugsf Ggsf #include "FEATURE/mkdir" #ifdef _lib_mkdir int _lib_dummy; #else #include <errno.h> extern int errno; extern int _exit(); extern int access(); extern int chmod(); extern int execl(); extern int fork(); extern int wait(); int mkdir(path, mode) char* path; int mode; { register int n; register int pid; n = errno; if (!access(path, 0)) { errno = EEXIST; return(-1); } if (errno != ENOENT) return(-1); errno = n; switch (pid = fork()) { case -1: return(-1); case 0: execl("/bin/mkdir", "mkdir", path, 0); execl("/usr/5bin/mkdir", "mkdir", path, 0); _exit(1); default: while ((n = wait((int*)0)) >= 0 && n != pid); break; } return(chmod(path, mode)); } #endif 0707070000000000161006440044230044230000010000000441570103400003100000002030comp/mktemp.c Ugsf Ggsf #include "FEATURE/mktemp" #ifdef _lib_mktemp int _lib_dummy; #else /* @(#)mktemp.c 1.2 9/24/85 19:52:37 */ /*LINTLIBRARY*/ /**************************************************************** * Routine expects a string of length at least 6, with * six trailing 'X's. These will be overlaid with a * letter and the last (5) digigts of the proccess ID. * If every letter (a thru z) thus inserted leads to * an existing file name, your string is shortened to * length zero upon return (first character set to '\0'). ***************************************************************/ extern int strlen(), access(), getpid(); char * mktemp(as) char *as; { register char *s=as; register unsigned pid; pid = getpid(); s += strlen(as); /* point at the terminal null */ while(*--s == 'X') { *s = (pid%10) + '0'; pid /= 10; } if(*++s) { /* maybe there were no 'X's */ *s = 'a'; while(access(as, 0) == 0) { if(++*s > 'z') { *as = '\0'; break; } } } else if(access(as, 0) == 0) *as = '\0'; return(as); } #endif 0707070000000000171006440044230044230000010000000471605023500003000000000317comp/mount.c Ugsf Ggsf #include "FEATURE/mount" #ifdef _lib_mount int _lib_dummy; #else #include <errno.h> extern int errno; /*ARGSUSED*/ int mount(a, b, c) char* a; char* b; int c; { errno = EINVAL; return(-1); } #endif 0707070000000000201006440044230044230000010000000475446255100003000000001136comp/popen.c Ugsf Ggsf /* * libx popen(3) */ #include <stdio.h> #undef popen #undef pclose extern int cmdopen(); extern int cmdclose(); #if __STDC__ #ifndef fdopen extern FILE* fdopen(int, char*); #endif #endif FILE* popen(cmd, mode) char* cmd; char* mode; { int fd; FILE* fp; char* sh[4]; sh[0] = "sh"; sh[1] = "-c"; sh[2] = cmd; sh[3] = 0; if ((fd = cmdopen((char*)0, sh, (char**)0, (int**)0, mode)) < 0) return(0); if (!(fp = fdopen(fd, mode))) (void)cmdclose(fd); return(fp); } int pclose(fp) FILE* fp; { int fd; if (fp) { fd = fileno(fp); fclose(fp); return(cmdclose(fd)); } return(-1); } 0707070000000000211006440044230044230000010000000451516406000003300000000346comp/readlink.c Ugsf Ggsf #include "FEATURE/readlink" #ifdef _lib_readlink int _lib_dummy; #else #include <errno.h> extern int errno; /*ARGSUSED*/ int readlink(path, buf, siz) char* path; char* buf; int siz; { errno = EINVAL; return(-1); } #endif 0707070000000000221006440044230044230000010000000472227245200003100000000235comp/remove.c Ugsf Ggsf #include "FEATURE/remove" #ifdef _lib_remove int _lib_dummy; #else extern int unlink(); int remove(path) char* path; { return(unlink(path)); } #endif 0707070000000000231006440044230044230000010000000472226252400003100000000354comp/rename.c Ugsf Ggsf #include "FEATURE/rename" #ifdef _lib_rename int _lib_dummy; #else extern int link(); extern int unlink(); int rename(from, to) char* from; char* to; { int n; if (!(n = link(from, to))) (void)unlink(from); return(n); } #endif 0707070000000000241006440044230044230000010000000472226265000003000000001475comp/rmdir.c Ugsf Ggsf #include "FEATURE/rmdir" #ifdef _lib_rmdir int _lib_dummy; #else #include <sys/types.h> #include <sys/stat.h> #include <errno.h> extern int errno; extern int _exit(); extern int access(); extern int chmod(); extern int execl(); extern int fork(); extern int stat(); extern int wait(); int rmdir(path) char* path; { register int n; register int pid; struct stat st; if (stat(path, &st) < 0) return(-1); if ((st.st_mode & S_IFMT) != S_IFDIR) { errno = ENOTDIR; return(-1); } switch (pid = fork()) { case -1: return(-1); case 0: execl("/bin/rmdir", "rmdir", path, 0); execl("/usr/5bin/rmdir", "rmdir", path, 0); _exit(1); default: while ((n = wait((int*)0)) >= 0 && n != pid); break; } n = errno; if (access(path, 0) < 0) { errno = n; return(0); } errno = EPERM; return(-1); } #endif 0707070000000000251006440044230044230000010000000441570106000003200000000263comp/setpgid.c Ugsf Ggsf #include "FEATURE/setpgid" #ifdef _lib_setpgid int _lib_dummy; #else extern int setpgrp(); int setpgid(pid, pgid) int pid; int pgid; { return(setpgrp(pid, pgid)); } #endif 0707070000000000261006440044230044230000010000000441570106600003000000001045comp/sgetl.c Ugsf Ggsf #include "FEATURE/sgetl" #ifdef _lib_sgetl int _lib_dummy; #else /* * The intent here is to provide a means to make the value of * bytes in an io-buffer correspond to the value of a long * in the memory while doing the io a `long' at a time. * Files written and read in this way are machine-independent. */ #include <limits.h> long sgetl(buffer) register char *buffer; { register long w = 0; register int i = CHAR_BIT * sizeof(long); while ((i -= CHAR_BIT) >= 0) w |= (long) ((unsigned char) *buffer++) << i; return (w); } #endif 0707070000000000271006440044230044230000010000000441570107200003500000000206comp/sigsetmask.c Ugsf Ggsf #include "FEATURE/sigsetmask" #ifdef _lib_sigsetmask int _lib_dummy; #else int sigsetmask(mask) int mask; { return(0); } #endif 0707070000000000301006440044230044230000010000000471770567300003500000000270comp/sigunblock.c Ugsf Ggsf #include "FEATURE/sigunblock" #ifdef _lib_sigunblock int _lib_dummy; #else #include <sig.h> int sigunblock(s) int s; { return(sigsetmask(sigsetmask(0) & ~sigmask(s))); } #endif 0707070000000000311006440044230044230000010000000441570110500003000000001007comp/sputl.c Ugsf Ggsf #include "FEATURE/sputl" #ifdef _lib_sputl int _lib_dummy; #else /* * The intent here is to provide a means to make the value of * bytes in an io-stream correspond to the value of the long * in the memory while doing the io a `long' at a time. * Files written and read in this way are machine-independent. */ #include <limits.h> void sputl(w, buffer) register long w; register char *buffer; { register int i = CHAR_BIT * sizeof(long); while ((i -= CHAR_BIT) >= 0) *buffer++ = (char) (w >> i); } #endif 0707070000000000321006440044230044230000010000000472226266100003100000000516comp/strchr.c Ugsf Ggsf #include "FEATURE/strchr" #ifdef _lib_strchr int _lib_dummy; #else #include "FEATURE/index" #ifdef _lib_index extern char* index(); char* strchr(s, c) char* s; int c; { return(index(s, c)); } #else char* strchr(s, c) register char* s; register int c; { do if (*s == c) return(s); while(*s++); return(0); } #endif #endif 0707070000000000331006440044230044230000010000000441570112000003200000000645comp/strpbrk.c Ugsf Ggsf #include "FEATURE/strpbrk" #ifdef _lib_strpbrk int _lib_dummy; #else /* * Return ptr to first occurance of any character from `brkset' * in the character string `string'; 0 if none exists. */ char* strpbrk(string, brkset) register char* string; register char* brkset; { register char* p; do { for (p = brkset; *p && *p != *string; p++); if (*p) return(string); } while (*string++); return(0); } #endif 0707070000000000341006440044230044230000010000000441570112600003200000000556comp/strrchr.c Ugsf Ggsf #include "FEATURE/strrchr" #ifdef _lib_strrchr int _lib_dummy; #else #include "FEATURE/rindex" #ifdef _lib_rindex extern char* rindex(); char* strrchr(s, c) char* s; int c; { return(rindex(s, c)); } #else char* strrchr(s, c) register char* s; register int c; { register char* r; r = 0; do if (*s == c) r = s; while(*s++); return(r); } #endif #endif 0707070000000000351006440044230044230000010000000441570113300003100000000670comp/strspn.c Ugsf Ggsf #include "FEATURE/strspn" #ifdef _lib_strspn int _lib_dummy; #else /* * Return the number of characters in the maximum leading segment * of string which consists solely of characters from charset. */ int strspn(string, charset) char* string; register char* charset; { register char* p; register char* q; for (q = string; *q; q++) { for (p = charset; *p && *p != *q; p++); if (!*p) break; } return(q - string); } #endif 0707070000000000361006440044230044230000010000000441570114000003100000000726comp/strtod.c Ugsf Ggsf #include "FEATURE/strtod" #ifdef _lib_strtod int _lib_dummy; #else #include <ctype.h> extern double atof(); double strtod(s, e) register char* s; char** e; { double n; n = atof(s); if (e) { while (isspace(*s)) s++; if (*s == '-' || *s == '+') s++; while (isdigit(*s)) s++; if (*s == '.') while (isdigit(*++s)); if (*s == 'e' || *s == 'E') { if (*++s == '-' || *s == '+') s++; while (isdigit(*s)) s++; } *e = s; } return(n); } #endif 0707070000000000371006440044230044230000010000000472226272700003100000001520comp/strtok.c Ugsf Ggsf #include "FEATURE/strtok" #ifdef _lib_strtok int _lib_dummy; #else /* * uses strpbrk and strspn to break string into tokens on * sequentially subsequent calls. returns 0 when no * non-separator characters remain. * `subsequent' calls are calls with first argument 0. */ extern int strspn(); extern char* strpbrk(); char* strtok(string, sepset) char* string char* sepset; { register char* p; register char* q; register char* r; static char* savept; /*first or subsequent call*/ /* return if no tokens remaining */ if (!(p = string ? string : savept)) return(0); /* skip leading separators */ /* return if no tokens remaining */ if (!*(q = p + strspn(p, sepset))) return(0); /* move past token */ if (!(r = strpbrk(q, sepset))) savept = 0; /* this is last token */ else { *r = 0; savept = ++r; } return(q); } #endif 0707070000000000401006440044230044230000010000000472226275000003100000002577comp/strtol.c Ugsf Ggsf #include "FEATURE/strtol" #ifdef _lib_strtol int _lib_dummy; #else /* @(#)strtol.c 2.1 */ /*LINTLIBRARY*/ #include <ctype.h> #define DIGIT(x) (isdigit(x) ? (x) - '0' : \ islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A') #define MBASE ('z' - 'a' + 1 + 10) long strtol(str, ptr, base) register char* str; char** ptr; register int base; { register long val; register int c; int xx, neg = 0; if (ptr != (char **)0) *ptr = str; /* in case no number is formed */ if (base < 0 || base > MBASE) return (0); /* base is invalid -- should be a fatal error */ if (!isalnum(c = *str)) { while (isspace(c)) c = *++str; switch (c) { case '-': neg++; case '+': /* fall-through */ c = *++str; } } if (base == 0) if (c != '0') base = 10; else if (str[1] == 'x' || str[1] == 'X') base = 16; else base = 8; /* * for any base > 10, the digits incrementally following * 9 are assumed to be "abc...z" or "ABC...Z" */ if (!isalnum(c) || (xx = DIGIT(c)) >= base) return (0); /* no number formed */ if (base == 16 && c == '0' && isxdigit(str[2]) && (str[1] == 'x' || str[1] == 'X')) c = *(str += 2); /* skip over leading "0x" or "0X" */ for (val = -DIGIT(c); isalnum(c = *++str) && (xx = DIGIT(c)) < base; ) /* accumulate neg avoids surprises near MAXLONG */ val = base * val - xx; if (ptr != (char **)0) *ptr = str; return (neg ? val : -val); } #endif 0707070000000000411006440044230044230000010000000451516404100003200000000313comp/symlink.c Ugsf Ggsf #include "FEATURE/symlink" #ifdef _lib_symlink int _lib_dummy; #else #include <errno.h> extern int errno; /*ARGSUSED*/ int symlink(a, b) char* a; char* b; { errno = EINVAL; return(-1); } #endif 0707070000000000421006440044230044230000010000000447445616000003100000000265comp/system.c Ugsf Ggsf /* * libx system(3) */ extern int cmdrun(); int system(cmd) char* cmd; { char* sh[4]; sh[0] = "sh"; sh[1] = "-c"; sh[2] = cmd; sh[3] = 0; return(cmdrun((char*)0, sh)); } 0707070000000000431006440044230044230000010000000441570116500003100000001051comp/tmpnam.c Ugsf Ggsf #include "FEATURE/tmpnam" #ifdef _lib_tmpnam int _lib_dummy; #else #include <stdio.h> #ifndef P_tmpdir #define P_tmpdir "/usr/tmp/" #endif #ifndef L_tmpnam #define L_tmpnam (sizeof(P_tmpdir)+10) #endif static char buf[L_tmpnam]; static char seed[] = { 'a', 'a', 'a', 0 }; extern char* mktemp(); extern char* strcopy(); char* tmpnam(p) register char* p; { register char* q; if (!p) p = buf; (void)strcopy(strcopy(strcopy(p, P_tmpdir), seed), "XXXXXX"); q = seed; while (*q == 'z') *q++ = 'a'; if (*q) ++*q; return(mktemp(p)); } #endif 0707070000000000441006440044230044230000010000000472226407000003100000000235comp/unlink.c Ugsf Ggsf #include "FEATURE/unlink" #ifdef _lib_unlink int _lib_dummy; #else extern int remove(); int unlink(path) char* path; { retrun(remove(path)); } #endif 0707070000000000451006440044230044230000010000000441570117100003000000000202comp/vfork.c Ugsf Ggsf #include "FEATURE/vfork" #ifdef _lib_vfork int _lib_dummy; #else extern int fork(); int vfork() { return(fork()); } #endif 0707070000000000461006440044230044230000010000000475152536600003000000003136dir/dirlib.h Ugsf Ggsf /* * AT&T Bell Laboratories * * directory stream access library private definitions * handles 3d and preroot file systems */ #include <preroot.h> #undef DIR #define DIR _SYS_DIR_ #undef opendir #define opendir _SYS_opendir #undef readdir #define readdir _SYS_readdir #undef rewinddir #define rewinddir _SYS_rewinddir #undef seekdir #define seekdir _SYS_seekdir #undef telldir #define telldir _SYS_telldir #undef closedir #define closedir _SYS_closedir #define _dir_local 1 #include <lclparam.h> #include <fsinfo.h> #include <dirent.h> #include <limits.h> #include <hash.h> #undef DIR typedef struct { int dd_fd; /* file descriptor */ int dd_loc; /* offset in block */ int dd_size; /* valid data in block */ char* dd_buf; /* directory block */ /* the rest are for 3d and preroot fs */ unsigned char covered[sizeof(int)*CHAR_BIT]; /* covered directory fds */ ino_t opaque; /* opaque inode number */ HASHTABLE* overlay; /* directory overlay hash */ short numfd; /* number of covered fds */ short nxtfd; /* next covered fd index */ short fs3d; /* 3d in effect */ } DIR; /* directory stream descriptor */ #undef opendir extern DIR* opendir(); #undef readdir extern struct dirent* readdir(); #undef rewinddir extern void rewinddir(); #undef seekdir extern void seekdir(); #undef telldir extern long telldir(); #undef closedir extern void closedir(); #ifndef DIRBLKSIZ #ifdef DIRBLK #define DIRBLKSIZ DIRBLK #else #ifdef DIRBUF #define DIRBLKSIZ DIRBUF #else #ifdef DEV_BSIZE #define DIRBLKSIZ DEV_BSIZE #else #define DIRBLKSIZ 4096 #endif #endif #endif #endif 0707070000000000471006440044230044230000010000000475137311700003100000004774dir/opendir.c Ugsf Ggsf /* * opendir, closedir * * open|close directory stream * * POSIX compatible directory stream access routines: * * #include <sys/types.h> * #include <dirent.h> * * NOTE: readdir() returns a pointer to struct dirent */ #include "dirlib.h" #include <errno.h> #if !lint static char id[] = "\n@(#)directory (AT&T Bell Laboratories) 04/01/90\0\n"; #endif static DIR* freedirp; /* always keep one dirp */ extern int errno; extern char* malloc(); extern char* strcopy(); extern void free(); extern int open(); extern int close(); extern int fclex(); extern int fstat(); DIR* opendir(path) register char* path; { register DIR* dirp = 0; register int fd; dev_t dev; ino_t ino; struct stat st; if ((fd = open(path, 0)) < 0) return(0); if (fstat(fd, &st) < 0 || (st.st_mode & S_IFMT) != S_IFDIR && (errno = ENOTDIR) || fclex(fd, 1) || !(dirp = freedirp ? freedirp : (DIR*)malloc(sizeof(DIR) + DIRBLKSIZ))) { (void)close(fd); if (dirp) { if (!freedirp) freedirp = dirp; else free((char*)dirp); } return(0); } freedirp = 0; dirp->dd_fd = fd; dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ dirp->dd_buf = (char*)dirp + sizeof(DIR); /* * handle 3d and preroot fs */ dirp->numfd = dirp->nxtfd = 0; if (dirp->fs3d = fs3d(2)) { char buf[PATH_MAX]; dirp->opaque = 0; path = strcopy(buf, path); while (dirp->numfd < sizeof(dirp->covered) / sizeof(dirp->covered[0])) { path = strcopy(path, "/..."); if ((fd = open(buf, 0)) < 0) break; /* * check for non-dirs or dirs covered by virtual dir */ dev = st.st_dev; ino = st.st_ino; if (fstat(fd, &st) || ino == st.st_ino && dev == st.st_dev) (void)close(fd); else if ((st.st_mode & S_IFMT) != S_IFDIR) { (void)close(fd); break; } else { fclex(fd, 1); dirp->covered[dirp->numfd++] = fd; } } } #if defined(FS_PREROOT) else if ((fd = realopen(path, 0, 0)) >= 0) { dev = st.st_dev; ino = st.st_ino; if (fstat(fd, &st) || ino == st.st_ino && dev == st.st_dev || (st.st_mode & S_IFMT) != S_IFDIR) (void)close(fd); else { fclex(fd, 1); dirp->covered[dirp->numfd++] = fd; } } #endif dirp->overlay = dirp->numfd ? hashalloc((HASHTABLE*)0, HASH_set, HASH_ALLOCATE, 0) : 0; return(dirp); } void closedir(dirp) register DIR* dirp; { if (dirp) { (void)close(dirp->dd_fd); while (dirp->nxtfd < dirp->numfd) (void)close(dirp->covered[dirp->nxtfd++]); if (dirp->overlay) hashfree(dirp->overlay); if (!freedirp) freedirp = dirp; else free((char*)dirp); } } 0707070000000000501006440044230044230000010000000471771071500003100000002357dir/readdir.c Ugsf Ggsf /* * readdir * * read from directory stream * * NOTE: directory entries must fit within DIRBLKSIZ boundaries */ #include "dirlib.h" struct dirent* readdir(dirp) register DIR* dirp; { register struct dirent* dp; for (;;) { if (dirp->dd_loc >= dirp->dd_size) { if (dirp->dd_size < 0) return(0); dirp->dd_loc = 0; if ((dirp->dd_size = getdents(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) { uncover: if (dirp->nxtfd < dirp->numfd) { (void)close(dirp->dd_fd); dirp->dd_fd = dirp->covered[dirp->nxtfd++]; dirp->dd_loc = 0; dirp->opaque = 0; continue; } return(0); } } dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc]; if (dp->d_reclen <= 0) goto uncover; dirp->dd_loc += dp->d_reclen; if (dp->d_ino) { if (dirp->fs3d) { register char* s = dp->d_name; /* * skip opaque and hidden entries */ if (*s++ == '.' && *s++ == '.' && *s++ == '.') { if (!*s) dirp->opaque = dp->d_ino; continue; } } if (dirp->overlay) { if (hashget(dirp->overlay, dp->d_name)) continue; if (dirp->nxtfd < dirp->numfd) hashput(dirp->overlay, 0, (char*)1); } if (dp->d_ino == dirp->opaque) continue; return(dp); } } /*NOTREACHED*/ } 0707070000000000511006440044230044230000010000000445642251000003300000000277dir/rewinddir.c Ugsf Ggsf /* * rewinddir * * rewind directory stream * provided for POSIX compatibility */ #include "dirlib.h" #undef rewinddir void rewinddir(dirp) register DIR *dirp; { seekdir(dirp, 0L); } 0707070000000000521006440044230044230000010000000440504372400003100000001005dir/seekdir.c Ugsf Ggsf /* * seekdir * * seek on directory stream */ #include "dirlib.h" extern long lseek(); void seekdir(dirp, loc) register DIR *dirp; long loc; { long base; /* file location of block */ long offset; /* offset within block */ if (telldir(dirp) != loc) { offset = loc % DIRBLKSIZ; base = loc - offset; (void)lseek(dirp->dd_fd, base, 0); dirp->dd_loc = dirp->dd_size = 0; /* * skip some entries */ while (dirp->dd_loc < offset) if (!readdir(dirp)) break; /* "can't happen" */ } } 0707070000000000531006440044230044230000010000000440504373000003100000000334dir/telldir.c Ugsf Ggsf /* * telldir * * get offset of directory stream pointer */ #include "dirlib.h" extern long lseek(); long telldir(dirp) DIR *dirp; { return(lseek(dirp->dd_fd, 0L, 1) - (long)dirp->dd_size + (long)dirp->dd_loc); } 0707070000000000541006440044230044230000010000000472006660200003400000005102hash/hashalloc.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #if !lint static char id[] = "\n@(#)hash (AT&T Bell Laboratories) 11/11/90\0\n"; #endif #include "hashlib.h" #if !__STDC__ #include <varargs.h> #endif struct hashinfo _hash_info_; /* * create a new hash table */ #if __STDC__ HASHTABLE* hashalloc(HASHTABLE* ref, ...) #else HASHTABLE* hashalloc(va_alist) va_dcl #endif { va_list ap; #if !__STDC__ register HASHTABLE* ref; #endif #if __STDC__ va_start(ap, ref); #else va_start(ap); ref = va_arg(ap, HASHTABLE*); #endif ref = hashvalloc(ref, ap); va_end(ap); return(ref); } /* * varargs interface to hashalloc() */ HASHTABLE* hashvalloc(ref, ap) register HASHTABLE* ref; va_list ap; { register HASHTABLE* tab; int internal; if (!(tab = (HASHTABLE*)calloc(1, sizeof(HASHTABLE)))) goto bad; if (ref) { tab->flags = ref->flags & ~HASH_RESET; tab->root = ref->root; internal = HASH_INTERNAL; } else { if (!(tab->root = (HASHROOT*)calloc(1, sizeof(HASHROOT)))) goto bad; tab->root->meanchain = HASHMEANCHAIN; internal = 0; } tab->size = HASHMINSIZE; for (;;) switch (va_arg(ap, int)) { case HASH_alloc: if (ref) goto bad; tab->root->alloc = va_arg(ap, HASHPTR); break; case HASH_clear: tab->flags &= ~(va_arg(ap, int) & ~internal); break; case HASH_compare: if (ref) goto bad; tab->root->compare = va_arg(ap, HASHINT); break; case HASH_free: if (ref) goto bad; tab->root->free = va_arg(ap, HASHINT); break; case HASH_hash: if (ref) goto bad; tab->root->hash = va_arg(ap, HASHFUN); break; case HASH_meanchain: if (ref) goto bad; tab->root->meanchain = va_arg(ap, int); break; case HASH_name: tab->name = va_arg(ap, char*); break; case HASH_namesize: if (ref) goto bad; tab->root->namesize = va_arg(ap, int); break; case HASH_set: tab->flags |= (va_arg(ap, int) & ~internal); break; case HASH_size: tab->size = va_arg(ap, int); if (tab->size & (tab->size - 1)) tab->flags |= HASH_FIXED; break; case HASH_table: tab->table = va_arg(ap, HASHBUCKET**); tab->flags |= HASH_STATIC; break; case 0: if (tab->flags & HASH_SCOPE) { if (!(tab->scope = ref)) goto bad; ref->frozen++; } if (!tab->table && !(tab->table = (HASHBUCKET**)calloc(1, sizeof(HASHBUCKET*) * tab->size))) goto bad; if (!ref) { tab->root->flags = tab->flags & HASH_INTERNAL; tab->root->next = hash_info.list; hash_info.list = tab->root; } tab->next = tab->root->references; tab->root->references = tab; return(tab); default: goto bad; } bad: (void)hashfree(tab); return(0); } 0707070000000000551006440044230044230000010000000467350644100003300000010352hash/hashdump.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include <stdio.h> #include "hashlib.h" static void dumproot(); static void dumptable(); static void dumpflags(); static void dumpbucket(); /* * dump hash table accounting info * if tab is 0 then dump all tables in hash_info.list * flags are HASH_* flags that specifiy optional dump info */ void hashdump(fp, tab, flags) register FILE* fp; register HASHTABLE* tab; int flags; { register HASHROOT* root; fprintf(fp, "\nhash table information:\n\n"); if (tab) dumproot(fp, tab->root, flags); else for (root = hash_info.list; root; root = root->next) dumproot(fp, root, flags); fflush(fp); } /* * dump hash table root info */ static void dumproot(fp, root, flags) register FILE* fp; register HASHROOT* root; register int flags; { register HASHTABLE* tab; fprintf(fp, " root\n"); fprintf(fp, " address: 0x%08lx\n", (unsigned long)root); fprintf(fp, " flags: "); dumpflags(fp, root->flags); if (root->namesize) fprintf(fp, "namesize=%d ", root->namesize); if (root->alloc) fprintf(fp, "alloc=0x%08lx ", (unsigned long)root->alloc); if (root->compare) fprintf(fp, "compare=0x%08lx ", (unsigned long)root->compare); if (root->free) fprintf(fp, "free=0x%08lx ", (unsigned long)root->free); if (root->hash) fprintf(fp, "hash=0x%08lx ", (unsigned long)root->hash); fprintf(fp, "\n"); fprintf(fp, " meanchain: %d\n", root->meanchain); fprintf(fp, " accesses: %d\n", root->accesses); fprintf(fp, " collisions: %d\n", root->collisions); fprintf(fp, "\n"); for (tab = root->references; tab; tab = tab->next) dumptable(fp, tab, flags); } /* * dump info on a single table */ static void dumptable(fp, tab, flags) register FILE* fp; register HASHTABLE* tab; register int flags; { HASHTABLE* scope; int level; fprintf(fp, " name: %s", tab->name ? tab->name : "*no name*"); if (scope = tab->scope) { level = 1; while (scope = scope->scope) level++; fprintf(fp, " level %d scope on 0x%08lx", level, (unsigned long)tab->scope); } fprintf(fp, "\n"); fprintf(fp, " address: 0x%08lx\n", (unsigned long)tab); fprintf(fp, " flags: "); if (tab->frozen) fprintf(fp, "frozen=%d ", tab->frozen); dumpflags(fp, tab->flags); fprintf(fp, "\n"); fprintf(fp, " size: %d\n", tab->size); fprintf(fp, " buckets: %d\n", tab->buckets); fprintf(fp, "\n"); if ((flags | tab->flags) & HASH_BUCKET) dumpbucket(fp, tab, flags); } /* * dump HASH_* flags */ static void dumpflags(fp, flags) register FILE* fp; register int flags; { if (flags & HASH_ALLOCATE) fprintf(fp, "allocate "); if (flags & HASH_BUCKET) fprintf(fp, "bucket "); if (flags & HASH_FIXED) fprintf(fp, "fixed "); if (flags & HASH_HASHED) fprintf(fp, "hashed "); if (flags & HASH_RESIZE) fprintf(fp, "resize "); if (flags & HASH_SCANNING) fprintf(fp, "scanning "); if (flags & HASH_STATIC) fprintf(fp, "static "); if (flags & HASH_VALUE) fprintf(fp, "value "); } /* * dump hash table bucket info */ /*ARGSUSED*/ static void dumpbucket(fp, tab, flags) register FILE* fp; register HASHTABLE* tab; int flags; { register HASHBUCKET** sp; register HASHBUCKET* b; HASHBUCKET** sx; int n; unsigned char* s; sx = tab->table + tab->size; for (sp = tab->table; sp < sx; sp++) { n = 0; for (b = *sp; b; b = b->next) if (!(b->hash & HASH_DELETED) && (!(tab->flags & HASH_VALUE) || b->value)) n++; if (n) { fprintf(fp, "%5d %2d :", sp - tab->table, n); for (b = *sp; b; b = b->next) if (!(b->hash & HASH_DELETED) && (!(tab->flags & HASH_VALUE) || b->value)) { if (n = tab->root->namesize) { fprintf(fp, " 0x"); s = (unsigned char*)hashname(b); while (n-- > 0) fprintf(fp, "%02x", *s++); } else fprintf(fp, " %s", hashname(b)); if (b->hash & HASH_FLAGS) { fprintf(fp, "|"); if (b->hash & HASH_HIDES) fprintf(fp, "hides|"); if (b->hash & HASH_HIDDEN) fprintf(fp, "hidden|"); if (b->hash & HASH_KEEP) fprintf(fp, "keep|"); if (b->hash & HASH_OPAQUED) fprintf(fp, "opaque|"); } if (tab->flags & HASH_VALUE) fprintf(fp, "=0x%08lx", (long)b->value); } fprintf(fp, "\n"); } } fprintf(fp, "\n"); } 0707070000000000561006440044230044230000010000000467522022400003300000003204hash/hashfree.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * free (remove) a hash table * can be called for partially constructed tables * scope covered table pointer is returned * root info freed when last reference freed */ HASHTABLE* hashfree(tab) register HASHTABLE* tab; { register HASHBUCKET** sp; register HASHBUCKET* b; register HASHBUCKET* p; HASHBUCKET** sx; HASHROOT* rp; HASHTABLE* tp; HASHINT freevalue; HASHINT freebucket; if (!tab) return(0); if (tab->table) { freebucket = (HASHINT)free; freevalue = 0; if (tab->root->free) { if (tab->root->flags & HASH_BUCKET) freebucket = tab->root->free; else freevalue = tab->root->free; } sx = &tab->table[tab->size]; sp = &tab->table[0]; while (sp < sx) { b = *sp++; while (b) { if (freevalue && b->value) (void)(*freevalue)(b->value); p = b; b = b->next; if (!(p->hash & HASH_KEEP)) (*freebucket)(p); } } if ((tab->flags & (HASH_RESIZE|HASH_STATIC)) != HASH_STATIC) free(tab->table); } if (tab->root) { /* * remove from the table lists */ if ((tp = tab->root->references) != tab) { for (; tp; tp = tp->next) if (tp->next == tab) { tp->next = tab->next; break; } } else if (!(tab->root->references = tp->next)) { if ((rp = hash_info.list) != tab->root) { for (; rp; rp = rp->next) if (rp->next == tab->root) { rp->next = tab->root->next; break; } } else hash_info.list = rp->next; } if (!(tab->root->references)) free(tab->root); } if (tp = tab->scope) tp->frozen--; free(tab); return(tp); } 0707070000000000571006440044230044230000010000000475447420200003200000001474hash/hashlib.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library private definitions */ #include <limits.h> #include <hash.h> #define HASHMINSIZE (1<<4) /* min table slots (power of 2) */ #define HASHMEANCHAIN 2 /* def resize mean chain len */ #define HASHMOD(t,h) (h &= (t->size - 1)) #define HASHVAL(x) ((x)&~HASH_FLAGS) #define HASH(r,n,h) if (r->hash) h = r->namesize ? (*r->hash)(n, r->namesize) : (*r->hash)(n);\ else\ {\ register const char* _hash_s1 = n;\ h = 0;\ if (r->namesize)\ {\ register const char* _hash_s2 = _hash_s1 + r->namesize;\ while (_hash_s1 < _hash_s2) HASHPART(h, *_hash_s1++);\ }\ else while (*_hash_s1) HASHPART(h, *_hash_s1++);\ } extern char* calloc(); extern char* malloc(); extern char* memcpy(); extern int strlen(); extern void free(); 0707070000000000601006440044230044230000010000000475447433400003300000012052hash/hashlook.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * hash table lookup */ #if __STDC__ || __cplusplus char* hashlook(register HASHTABLE* tab, const char* name, int flags, const char* value) #else #ifndef const #define const #endif char* hashlook(tab, name, flags, value) register HASHTABLE* tab; char* name; int flags; char* value; #endif { register HASHBUCKET* b; register unsigned int n; HASHTABLE* top; HASHBUCKET* prev; unsigned int i; static const char* lastname; static unsigned int lasthash; tab->root->accesses++; top = tab; if (name) { hash_info.table = tab; if (flags & (HASH_BUCKET|HASH_INSTALL)) { hash_info.last = (HASHBUCKET*)name; name = hashname(hash_info.last); } else hash_info.last = 0; lastname = name; if (flags & HASH_BUCKET) n = hash_info.last->hash; else if (tab->flags & HASH_HASHED) n = ((unsigned int)name) >> 3; else HASH(tab->root, name, n); lasthash = i = HASHVAL(n); for (;;) { HASHMOD(tab, n); for (prev = 0, b = tab->table[n]; b; prev = b, b = b->next) { if (i == HASHVAL(b->hash) && ((b->hash & (HASH_DELETED|HASH_OPAQUED)) != HASH_DELETED || (flags & (HASH_CREATE|HASH_DELETE|HASH_INSTALL)))) { if (!tab->root->compare) { register char* s1 = hashname(b); register const char* s2 = name; if (tab->root->namesize) { register char* s3 = s1 + tab->root->namesize; while (*s1++ == *s2++) if (s1 >= s3) goto found; } else while (*s1 == *s2++) if (!*s1++) goto found; } else if (tab->root->namesize) { if (!(*tab->root->compare)(hashname(b), name, tab->root->namesize)) goto found; } else if (!(*tab->root->compare)(hashname(b), name)) goto found; } tab->root->collisions++; } if (!tab->scope || (flags & (HASH_CREATE|HASH_INSTALL|HASH_NOSCOPE)) == HASH_NOSCOPE) break; tab = tab->scope; n = i; } } else { tab = hash_info.table; name = lastname; prev = 0; n = i = lasthash; HASHMOD(tab, n); if (b = hash_info.last) { /* * found the bucket */ found: if (prev && !(tab->flags & HASH_SCANNING)) { /* * migrate popular buckets to the front */ prev->next = b->next; b->next = tab->table[n]; tab->table[n] = b; } switch (flags & (HASH_CREATE|HASH_DELETE|HASH_INSTALL)) { case HASH_CREATE: case HASH_INSTALL: if (tab != top && !(flags & HASH_SCOPE)) break; if (flags & HASH_OPAQUE) b->hash |= HASH_OPAQUED; goto exists; case HASH_DELETE: value = 0; if (tab == top || (flags & HASH_SCOPE)) { if (flags & HASH_OPAQUE) b->hash &= ~HASH_OPAQUED; else if (!(tab->root->flags & HASH_BUCKET)) { if (tab->root->free && b->value) { (*tab->root->free)(b->value); b->value = 0; } else if (tab->flags & HASH_VALUE) { value = b->value; b->value = 0; } } if (tab->frozen || (b->hash & (HASH_KEEP|HASH_OPAQUED))) b->hash |= HASH_DELETED; else { tab->buckets--; tab->table[n] = b->next; if (tab->root->free && (tab->root->flags & HASH_BUCKET)) (*tab->root->free)(b); else free(b); } } return((char*)value); default: if (!(b->hash & HASH_DELETED)) goto exists; return(0); } } } if (!(flags & (HASH_CREATE|HASH_INSTALL))) return(0); /* * create a new bucket */ if (tab == top) prev = 0; else { if (prev = b) { name = (b->hash & HASH_HIDES) ? b->name : (char*)b; i |= HASH_HIDES; } if (!(flags & HASH_SCOPE)) tab = top; } /* * check for table expansion */ if (!tab->frozen && !(tab->flags & HASH_FIXED) && tab->buckets > tab->root->meanchain * tab->size) hashsize(tab, tab->size << 1); if (flags & HASH_INSTALL) { b = hash_info.last; i |= HASH_KEEP; } else { if (flags & HASH_VALUE) { tab->flags |= HASH_VALUE; n = sizeof(HASHBUCKET); } else if (!(flags & HASH_FIXED)) n = sizeof(HASHHEADER); else if ((n = (int)value) < sizeof(HASHHEADER)) n = sizeof(HASHHEADER); if (!prev && (tab->flags & HASH_ALLOCATE)) { int m = tab->root->namesize ? tab->root->namesize : strlen(name) + 1; if (!(b = (HASHBUCKET*)calloc(1, n + m))) return(0); b->name = (char*)b + n; (void)memcpy(b->name, name, m); } else { if (!(b = (HASHBUCKET*)calloc(1, n))) return(0); b->name = (char*)name; } } b->hash = n = i; HASHMOD(tab, n); b->next = tab->table[n]; tab->table[n] = b; tab->buckets++; if (flags & HASH_OPAQUE) { b->hash |= HASH_DELETED|HASH_OPAQUED; return(0); } exists: /* * finally got the bucket */ b->hash &= ~HASH_DELETED; hash_info.last = b; hash_info.table = tab; switch (flags & (HASH_CREATE|HASH_VALUE)) { case HASH_CREATE|HASH_VALUE: if (tab->root->free && !(tab->root->flags & HASH_BUCKET) && b->value) (*tab->root->free)(b->value); if (value && tab->root->alloc) value = (*tab->root->alloc)(value); b->value = (char*)value; return((char*)hashname(b)); case HASH_VALUE: return(b->value); default: return((char*)b); } } 0707070000000000611006440044230044230000010000000466426707700003300000004205hash/hashscan.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * hash table sequential scan * * HASHPOSITION pos; * HASHBUCKET* b; * hashscan(tab, flags, &pos); * while (b = hashnext(&pos)) ...; * hashdone(&pos); */ /* * initialize pos for scan on table */ void hashscan(tab, flags, pos) register HASHTABLE* tab; register int flags; register HASHPOSITION* pos; { static HASHBUCKET empty; pos->tab = pos->top = tab; pos->bucket = ∅ pos->slot = tab->table - 1; pos->limit = tab->table + tab->size; if (tab->scope && !(flags & HASH_NOSCOPE)) { pos->flags = HASH_SCOPE; do { register HASHBUCKET* b; if (tab->flags & HASH_SCANNING) { register HASHBUCKET** sp = tab->table; register HASHBUCKET** sx = tab->table + tab->size; while (sp < sx) for (b = *sp++; b; b = b->next) b->hash &= ~HASH_HIDDEN; } } while (tab = tab->scope); tab = pos->tab; } else pos->flags = 0; tab->flags |= HASH_SCANNING; tab->frozen++; } /* * return next scan element */ HASHBUCKET* hashnext(pos) register HASHPOSITION* pos; { register HASHBUCKET* b; b = pos->bucket; for (;;) { if (!(b = b->next)) { do { if (++pos->slot >= pos->limit) { pos->tab->flags &= ~HASH_SCANNING; pos->tab->frozen--; if (!pos->flags || !pos->tab->scope) return(0); pos->tab = pos->tab->scope; pos->limit = (pos->slot = pos->tab->table) + pos->tab->size; pos->tab->flags |= HASH_SCANNING; pos->tab->frozen++; } } while (!(b = *pos->slot)); } if (!(b->hash & HASH_DELETED) && (!(pos->tab->flags & HASH_VALUE) || b->value) && (!pos->flags || !(b->hash & (HASH_HIDDEN|HASH_HIDES)))) break; if (b->hash & HASH_HIDES) { register HASHBUCKET* h = (HASHBUCKET*)b->name; if (!(h->hash & HASH_HIDDEN)) { h->hash |= HASH_HIDDEN; if (!(b->hash & HASH_DELETED)) break; } } else b->hash &= ~HASH_HIDDEN; } return(hash_info.last = pos->bucket = b); } /* * terminate scan */ void hashdone(pos) register HASHPOSITION* pos; { if (pos->tab->flags & HASH_SCANNING) { pos->tab->flags &= ~HASH_SCANNING; pos->tab->frozen--; } } 0707070000000000621006440044230044230000010000000445242664000003300000001771hash/hashsize.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * change table size and rehash * size must be a power of 2 */ void hashsize(tab, size) register HASHTABLE* tab; int size; { register HASHBUCKET** old_s; register HASHBUCKET** new_s; register HASHBUCKET* old_b; register HASHBUCKET* new_b; HASHBUCKET** old_sx; unsigned int index; if (size > 0 && size != tab->size && !(size & (size - 1))) { if (!(new_s = (HASHBUCKET**)calloc(size, sizeof(HASHBUCKET*)))) tab->flags |= HASH_FIXED; else { old_sx = (old_s = tab->table) + tab->size; tab->size = size; while (old_s < old_sx) { old_b = *old_s++; while (old_b) { new_b = old_b; old_b = old_b->next; index = new_b->hash; HASHMOD(tab, index); new_b->next = new_s[index]; new_s[index] = new_b; } } if ((tab->flags & (HASH_RESIZE|HASH_STATIC)) != HASH_STATIC) free(tab->table); tab->table = new_s; tab->flags |= HASH_RESIZE; } } } 0707070000000000631006440044230044230000010000000471771043600003300000000771hash/hashwalk.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * apply walker to each active bucket in the table */ int hashwalk(tab, flags, walker) HASHTABLE* tab; int flags; register HASHINT walker; { register HASHBUCKET* b; register int v; HASHPOSITION pos; v = 0; hashscan(tab, flags, &pos); while (b = hashnext(&pos)) if ((v = (*walker)(hashname(b), (tab->flags & HASH_VALUE) ? b->value : (char*)b)) < 0) break; hashdone(&pos); return(v); } 0707070000000000641006440044230044230000010000000475447450300003200000000703hash/memhash.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * return the hash of buffer s of length n */ #if __STDC__ || __cplusplus unsigned int memhash(register const char* s, int n) #else #ifndef const #define const #endif unsigned int memhash(s, n) register char* s; int n; #endif { register const char* e; register unsigned int c; e = s + n; c = 0; while (s < e) HASHPART(c, *s++); return(c); } 0707070000000000651006440044230044230000010000000475446041300003100000001300hash/memsum.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * return a running 32 bit checksum of buffer b of length n * * c is the return value from a previous * memsum() or strsum() call, 0 on the first call * * the result is the same on all implementations */ #if __STDC__ || __cplusplus unsigned long memsum(const char* b, int n, register unsigned long c) #else unsigned long memsum(b, n, c) char* b; int n; register unsigned long c; #endif { register unsigned char* p; register unsigned char* e; p = (unsigned char*)b; e = p + n; while (p < e) HASHPART(c, *p++); #if LONG_MAX > 2147483647 return(c & 0xffffffff); #else return(c); #endif } 0707070000000000661006440044230044230000010000000475446047400003200000000655hash/strhash.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * return the hash of the null terminated string s */ #if __STDC__ || __cplusplus unsigned int strhash(const char* s) #else unsigned int strhash(s) char* s; #endif { register unsigned char* p; register unsigned int i; register unsigned int c; i = 0; p = (unsigned char*)s; while (c = *p++) HASHPART(i, c); return(i); } 0707070000000000671006440044230044230000010000000475446057700003100000001213hash/strsum.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library */ #include "hashlib.h" /* * return a running 32 bit checksum of string s * * c is the return value from a previous * memsum() or strsum() call, 0 on the first call * * the result is the same on all implementations */ #if __STDC__ || __cplusplus unsigned long strsum(const char* s, register unsigned long c) #else unsigned long strsum(s, c) char* s; register unsigned long c; #endif { register unsigned char* p; register int n; p = (unsigned char*)s; while (n = *p++) HASHPART(c, n); #if LONG_MAX > 2147483647 return(c & 0xffffffff); #else return(c); #endif } 0707070000000000701006440044230044230000010000000475434343600003300000002654include/error.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * option, error and message formatter external definitions */ #ifndef ERROR_INFO #include <option.h> #include <errno.h> #ifndef VOID #define VOID char #endif #define ERROR_INFO 0 /* info message -- no err_id */ #define ERROR_WARNING 1 /* warning message */ #define ERROR_ERROR 2 /* error message -- no err_exit */ #define ERROR_FATAL 3 /* error message with err_exit */ #define ERROR_PANIC ERROR_LEVEL /* panic message with err_exit */ #define ERROR_LEVEL 000077 /* level portion of status */ #define ERROR_SYSTEM 000100 /* report system errno message */ #define ERROR_OUTPUT 000200 /* next arg is error fd */ #define ERROR_SOURCE 000400 /* next 2 args are FILE,LINE */ #define ERROR_USAGE 001000 /* usage message */ #define ERROR_PROMPT 002000 /* omit trailing newline */ #define ERROR_NOID 004000 /* omit err_id */ #define ERROR_LIBRARY 010000 /* library routine error */ #if __cplusplus extern "C" { #endif extern int errno; /* system call error status */ #if __cplusplus } #endif #if __STDC__ || __cplusplus || c_plusplus #include <stdarg.h> #if __cplusplus extern "C" { #endif extern char* seterror(int, ...); extern void error(int, ...); extern void liberror(const char*, int, ...); extern void verror(const char*, int, va_list); #if __cplusplus } #endif #else extern char* seterror(); extern void error(); extern void liberror(); extern void verror(); #endif #endif 0707070000000000711006440044230044230000010000000475446100700003400000005664include/ftwalk.h Ugsf Ggsf /* * K. P. Vo * AT&T Bell Laboratories * * ftwalk(3) interface definitions */ #ifndef FTW_DOT #ifndef VOID #define VOID char #endif /* * ftwalk() argument flags */ #define FTW_CHILDREN (1<<0) /* call user function on child dirs too */ #define FTW_DELAY (1<<1) /* do child stat after parent preorder */ #define FTW_DOT (1<<2) /* don't chdir(2) to subdirectories */ #define FTW_MULTIPLE (1<<3) /* path arg is 0 terminated char** argv */ #define FTW_PHYSICAL (1<<4) /* physical rather than logical walk */ #define FTW_POST (1<<5) /* visit descendants before parent */ #define FTW_TWICE (1<<6) /* visit parent before&after descendants*/ #define FTW_USER (1<<10) /* first user flag bit */ struct FTW /* user function arg */ { struct FTW* left; /* left child in cycle check tree */ struct FTW* right; /* right child in cycle check tree */ struct FTW* link; /* identical to this elt on search path */ struct FTW* parent; /* parent in current search path */ union { long number; /* local number */ char* pointer;/* local pointer */ } local; /* local user data */ struct stat statb; /* stat buffer of this object */ char* path; /* full pathname */ short pathlen;/* strlen(path) */ unsigned short info; /* FTW_* type bits */ unsigned short status; /* user function entry/return status */ short level; /* current tree depth */ short namelen;/* strlen(name) */ char name[sizeof(int)]; /* file base name */ }; /* * individual struct FTW size */ #define FTWSIZE(f) ((f)->namelen+1+sizeof(struct FTW)-sizeof(int)) /* * FTW.info type bits */ #define FTW_NS (1<<0) /* stat failed - unknown */ #define FTW_F (1<<1) /* file - not directory or symbolic link*/ #define FTW_SL (1<<2) /* symbolic link */ #define FTW_D (1<<3) /* directory - pre-order visit */ #define FTW_C (1<<4) /* causes cycle */ #define FTW_NR (1<<5) /* cannot read */ #define FTW_NX (1<<6) /* cannot search */ #define FTW_P (1<<7) /* post-order visit */ #define FTW_DC (FTW_D|FTW_C) /* directory - would cause cycle */ #define FTW_DNR (FTW_D|FTW_NR) /* directory - no read permission */ #define FTW_DNX (FTW_D|FTW_NX) /* directory - no search permission */ #define FTW_DP (FTW_D|FTW_P) /* directory - post-order visit */ /* * FTW.status entry values */ #define FTW_NAME (1<<0) /* use FTW.name rather than FTW.path */ #define FTW_PATH (1<<1) /* use FTW.path rather than FTW.name */ /* * FTW.status return values */ #define FTW_AGAIN (1<<2) /* process entry again */ #define FTW_FOLLOW (1<<3) /* follow FTW_SL symlink */ #define FTW_NOPOST (1<<4) /* skip post order visit */ #define FTW_SKIP (1<<5) /* skip FTW_D directory */ #define FTW_STAT (1<<6) /* userf did stat */ #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern int ftwalk(const char* path, int (*userf)(struct FTW*), int flags, int (*comparf)(struct FTW*, struct FTW*)); #if __cplusplus } #endif #else extern int ftwalk(); #endif #endif 0707070000000000721006440044230044230000010000000475434355100003200000014206include/hash.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * hash table library interface definitions */ #ifndef HASH_ALLOCATE #define hash_info _hash_info_ #define vhashalloc hashvalloc #ifndef VOID #define VOID char #endif #define HASH_ALLOCATE (1<<0) /* allocate new key names */ #define HASH_FIXED (1<<1) /* fixed bucket/table size */ #define HASH_HASHED (1<<6) /* key names already hashed */ #define HASH_RESIZE (1<<2) /* table has been resized */ #define HASH_SCANNING (1<<3) /* currently scanning scope */ #define HASH_SCOPE (1<<4) /* push scope / create in bot */ #define HASH_STATIC (1<<5) /* static table allocation */ #define HASH_CREATE (1<<8) /* create bucket if not found */ #define HASH_DELETE (1<<9) /* delete bucket if found */ #define HASH_LOOKUP 0 /* default op */ #define HASH_BUCKET (1<<11) /* name is installed bucket */ #define HASH_INSTALL (1<<12) /* install allocated bucket */ #define HASH_NOSCOPE (1<<13) /* top scope only */ #define HASH_OPAQUE (1<<14) /* opaque bucket */ #define HASH_VALUE (1<<15) /* value bucket field used */ #define HASH_GET (HASH_LOOKUP|HASH_VALUE) #define HASH_NEW (HASH_CREATE|HASH_FIXED) #define HASH_PUT (HASH_CREATE|HASH_VALUE) #define HASH_DELETED (1<<(8*sizeof(int)-1)) /* deleted placeholder */ #define HASH_KEEP (1<<(8*sizeof(int)-2)) /* no free on bucket */ #define HASH_HIDDEN (1<<(8*sizeof(int)-3)) /* hidden by scope */ #define HASH_HIDES (1<<(8*sizeof(int)-4)) /* hides lower scope */ #define HASH_OPAQUED (1<<(8*sizeof(int)-5)) /* opaqued placeholder */ #define HASH_RESET (HASH_RESIZE|HASH_SCOPE|HASH_STATIC) #define HASH_INTERNAL (HASH_BUCKET|HASH_RESIZE|HASH_SCANNING|HASH_STATIC) #define HASH_FLAGS (HASH_DELETED|HASH_HIDDEN|HASH_HIDES|HASH_KEEP|HASH_OPAQUED) #define HASH_alloc 1 #define HASH_clear 2 #define HASH_compare 3 #define HASH_free 4 #define HASH_hash 5 #define HASH_meanchain 6 #define HASH_name 7 #define HASH_namesize 8 #define HASH_set 9 #define HASH_size 10 #define HASH_table 11 #include <hashpart.h> #define hashclear(t,f) ((t)->flags &= ~((f) & ~HASH_INTERNAL)) #define hashdel(t,n) hashlook(t, (char*)(n), HASH_DELETE, (char*)0) #define hashget(t,n) hashlook(t, (char*)(n), HASH_LOOKUP|HASH_VALUE, (char*)0) #define hashlast(t) (hash_info.last) #define hashname(b) ((((b)->hash&HASH_HIDES)?((HASHBUCKET*)((b)->name)):(b))->name) #define hashput(t,n,v) (char*)hashlook(t, (char*)(n), HASH_CREATE|HASH_VALUE, (char*)(v)) #define hashscope(t) ((t)->scope) #define hashset(t,f) ((t)->flags |= ((f) & ~HASH_INTERNAL)) #define Hashbin_t HASHBUCKET #define Hashhdr_t HASHHEADER #define Hashpos_t HASHPOSITION #define Hashtab_t HASHTABLE typedef struct hashbucket HASHBUCKET; typedef struct hashheader HASHHEADER; typedef struct hashposition HASHPOSITION; typedef struct hashroot HASHROOT; typedef struct hashtable HASHTABLE; typedef unsigned int (*HASHFUN)(); typedef int (*HASHINT)(); typedef char* (*HASHPTR)(); /* * the #define's avoid union tags */ #define HASH_HEADER /* common bucket header */ \ HASHBUCKET* next; /* next in collision chain */ \ unsigned int hash; /* hash flags and value */ \ char* name /* key name */ #define HASH_DEFAULT /* HASH_VALUE bucket elements */ \ char* value /* key value */ struct hashheader /* bucket header */ { HASH_HEADER; }; struct hashbucket /* prototype bucket */ { HASH_HEADER; HASH_DEFAULT; }; struct hashposition /* hash scan bucket position */ { HASHTABLE* tab; /* table pointer */ HASHTABLE* top; /* top scope table pointer */ int flags; /* scan flags */ HASHBUCKET* bucket; /* bucket */ HASHBUCKET** slot; /* table slot */ HASHBUCKET** limit; /* slot limit */ }; struct hashroot /* root hash table information */ { int flags; /* flags: see HASH_[A-Z]* */ int namesize; /* fixed name size: 0 => string */ int meanchain; /* resize mean chain length */ HASHFUN hash; /* name hash routine */ HASHINT compare; /* name comparision routine */ HASHPTR alloc; /* value allocation routine */ HASHINT free; /* value free routine */ int accesses; /* number of accesses */ int collisions; /* number of collisions */ HASHROOT* next; /* next in list of all roots */ HASHTABLE* references; /* referencing table list */ }; struct hashtable /* hash table information */ { HASHROOT* root; /* root hash table information */ HASHTABLE* scope; /* scope covered table */ short flags; /* flags: see HASH_[A-Z]* */ short frozen; /* table freeze nesting */ HASHBUCKET** table; /* hash slot table */ int size; /* table size */ int buckets; /* active bucket count */ char* name; /* table name */ HASHTABLE* next; /* root reference list link */ }; struct hashinfo /* library hash info */ { HASHBUCKET* last; /* most recent lookup bucket */ HASHTABLE* table; /* most recent lookup table */ HASHROOT* list; /* root table list */ }; #if __cplusplus extern "C" { #endif extern struct hashinfo hash_info; #if __cplusplus } #endif #if __STDC__ || __cplusplus || c_plusplus #include <stdarg.h> #include <stdio.h> #if __cplusplus extern "C" { #endif extern HASHTABLE* hashalloc(HASHTABLE*, ...); extern HASHTABLE* hashvalloc(HASHTABLE*, va_list); extern void hashdone(HASHPOSITION*); extern void hashdump(FILE*, HASHTABLE*, int); extern HASHTABLE* hashfree(HASHTABLE*); extern char* hashlook(HASHTABLE*, const char*, int, const char*); extern HASHBUCKET* hashnext(HASHPOSITION*); extern void hashscan(HASHTABLE*, int, HASHPOSITION*); extern void hashsize(HASHTABLE*, int); extern int hashwalk(HASHTABLE*, int, HASHINT); extern unsigned int memhash(const char*, int); extern unsigned long memsum(const char*, int, unsigned long); extern unsigned int strhash(const char*); extern unsigned long strsum(const char*, unsigned long); #if __cplusplus } #endif #else extern HASHTABLE* hashalloc(); extern HASHTABLE* hashvalloc(); extern void hashdone(); extern void hashdump(); extern HASHTABLE* hashfree(); extern char* hashlook(); extern HASHBUCKET* hashnext(); extern void hashscan(); extern void hashsize(); extern int hashwalk(); extern unsigned int memhash(); extern unsigned long memsum(); extern unsigned int strhash(); extern unsigned long strsum(); #endif #endif 0707070000000000731006440044230044230000010000000472075301300003600000001053include/hashpart.h Ugsf Ggsf /* * K. P. Vo * G. S. Fowler * AT&T Bell Laboratories * * ``the best'' combined linear congruent checksum/hash/PRNG */ #ifndef HASHPART #define HASH_ADD(h) (0x9c39c33dL) #if __sparc__ || sparc #define HASH_A(h,n) ((((h) << 2) - (h)) << (n)) #define HASH_B(h,n) ((((h) << 4) - (h)) << (n)) #define HASH_C(h,n) ((HASH_A(h,7) + HASH_B(h,0)) << (n)) #define HASH_MPY(h) (HASH_C(h,22)+HASH_C(h,10)+HASH_A(h,6)+HASH_A(h,3)+(h)) #else #define HASH_MPY(h) ((h)*0x63c63cd9L) #endif #define HASHPART(h,c) (h = HASH_MPY(h) + HASH_ADD(h) + (c)) #endif 0707070000000000741006440044230044230000010000000475434364100003000000004055include/ls.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * ls formatter interface definitions */ #ifndef LS_USER #include <fsinfo.h> #ifndef S_IRWXU #ifndef S_IREAD #define S_IREAD 00400 #define S_IWRITE 00200 #define S_IEXEC 00100 #endif #ifndef S_ISUID #define S_ISUID 04000 #endif #ifndef S_ISGID #define S_ISGID 02000 #endif #ifndef S_ISVTX #define S_ISVTX 01000 #endif #ifndef S_IRUSR #define S_IRUSR S_IREAD #define S_IWUSR S_IWRITE #define S_IXUSR S_IEXEC #define S_IRGRP (S_IREAD>>3) #define S_IWGRP (S_IWRITE>>3) #define S_IXGRP (S_IEXEC>>3) #define S_IROTH (S_IREAD>>6) #define S_IWOTH (S_IWRITE>>6) #define S_IXOTH (S_IEXEC>>6) #endif #define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) #define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) #define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) #endif #ifdef stat_blocks #define tblocks(p) (((p)->st_blocks+1)/2) #else #define tblocks(p) iblocks(p) #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern long iblocks(struct stat*); #if __cplusplus } #endif #else extern long iblocks(); #endif #endif #define LS_ATIME (1<<0) /* list st_atime */ #define LS_BLOCKS (1<<1) /* list blocks used by file */ #define LS_CTIME (1<<2) /* list st_ctime */ #define LS_INUMBER (1<<3) /* list st_ino */ #define LS_LONG (1<<4) /* long listing */ #define LS_MARK (1<<5) /* append file name marks */ #define LS_NOGROUP (1<<6) /* omit group name for LS_LONG */ #define LS_NOUSER (1<<7) /* omit user name for LS_LONG */ #define LS_USER (1<<8) /* first user flag bit */ #define LS_W_BLOCKS 5 /* LS_BLOCKS field width */ #define LS_W_INUMBER 7 /* LS_INUMBER field width */ #define LS_W_LONG 55 /* LS_LONG width (w/o names) */ #define LS_W_LINK 4 /* link text width (w/o names) */ #define LS_W_MARK 1 /* LS_MARK field width */ #define LS_W_NAME 9 /* group|user name field width */ #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern char* fmtls(char*, const char*, struct stat*, const char*, const char*, int); #if __cplusplus } #endif #else extern char* fmtls(); #endif #endif 0707070000000000751006440044230044230000010000000434062502300003400000000263include/namval.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * name-value struct support */ #ifndef __NAMVAL_H__ #define __NAMVAL_H__ struct namval { char* name; int value; }; #endif 0707070000000000761006440044230044230000010000000475434371500003400000001715include/option.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * command line option parse assist definitions */ #ifndef __OPTION_H__ #define __OPTION_H__ #if __cplusplus extern "C" { #endif extern char* opt_arg; /* {:,#} string argument */ extern int opt_again; /* see cmdargs() */ extern char** opt_argv; /* most recent argv */ extern int opt_char; /* char pos in argv[opt_index] */ extern int opt_index; /* argv index */ extern char* opt_msg; /* error/usage message buffer */ extern long opt_num; /* # numeric argument */ extern char opt_option[3]; /* current flag {-,+} + option */ extern int opt_pchar; /* prev opt_char for backup */ extern int opt_pindex; /* prev opt_index for backup */ #if __cplusplus } #endif #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern int optget(char**, const char*); extern char* optusage(const char*); #if __cplusplus } #endif #else extern int optget(); extern char* optusage(); #endif #endif 0707070000000000771006440044230044230000010000000475434416200003000000002601include/re.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * regular expression library definitions */ #ifndef RE_ALL #define RE_ALL (1<<0) /* substitute all occurrences */ #define RE_EDSTYLE (1<<1) /* ed(1) style magic characters */ #define RE_LOWER (1<<2) /* substitute to lower case */ #define RE_MATCH (1<<3) /* record matches in reprogram.match */ #define RE_UPPER (1<<4) /* substitute to upper case */ #define RE_EXTERNAL 8 /* first external flag bit */ #define RE_NMATCH ('9'-'0'+1) typedef struct /* sub-expression match */ { char* sp; /* start in source string */ char* ep; /* end in source string */ } rematch; /* * NOTE: reprogram is a pun for the interface routines * allowing the library to change without forcing * users to recompile */ typedef struct /* compiled regular expression program */ { rematch match[RE_NMATCH+1];/* sub-expression match table */ } reprogram; /* * interface routines */ #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern reprogram* recomp(const char*, int); extern int reexec(reprogram*, const char*); extern void refree(reprogram*); extern void reerror(const char*); extern char* resub(reprogram*, const char*, const char*, char*, int); #if __cplusplus } #endif #else extern reprogram* recomp(); extern int reexec(); extern void refree(); extern void reerror(); extern char* resub(); #endif #endif 0707070000000001001006440044230044230000010000000475415720300003200000016426include/sfio.h Ugsf Ggsf #ifndef _SFIO_H /* protect against multiple #includes */ #define _SFIO_H #if __STDC__ || __cplusplus || c_plusplus #define _SFA_(x) x #else #define _SFA_(x) () #endif #ifndef NULL #define NULL 0 #endif #ifndef EOF #define EOF (-1) #endif #ifndef SEEK_SET #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 #endif typedef struct _sfdc_ Sfdisc_t; typedef struct _sfio_ Sfile_t, SFIO; /* discipline structure */ struct _sfdc_ { int (*readf) _SFA_((Sfile_t*, unsigned char*, int, char*)); int (*writef) _SFA_((Sfile_t*, const unsigned char*, int, char*)); long (*seekf) _SFA_((Sfile_t*, long, int, char*)); int (*exceptf) _SFA_((Sfile_t*, int, char*)); char *handle; /* to store any state information */ }; /* a file structure */ struct _sfio_ { unsigned char *next; /* next position to read/write from */ unsigned char *endw; /* end of write buffer */ unsigned char *endr; /* end of read buffer */ unsigned char *endb; /* end of buffer */ struct _sfio_ *push; /* the stream that was pushed on */ short flags; /* type of stream */ short file; /* file descriptor */ long orig; /* where we start in the file */ #ifdef _SFIO_PRIVATE _SFIO_PRIVATE #endif }; /* bits for various types of files */ #define SF_READ 000001 /* open for reading */ #define SF_WRITE 000002 /* open for writing */ #define SF_STRING 000004 /* a string stream */ #define SF_APPEND 000010 /* associated file is in append mode */ #define SF_RELATIVE 000020 /* file pos is relative to starting pos */ #define SF_MALLOC 000040 /* buffered space malloc-ed */ #define SF_LINE 000100 /* line buffering */ #define SF_KEEPFD 000200 /* keep file opened when closing stream */ #define SF_SHARE 000400 /* file stream that is shared */ #define SF_REUSE 001000 /* keep stream space after closing */ #define SF_FLAGS 000777 /* PUBLIC FLAGS PASSABLE TO SFNEW() */ #define SF_SETS 001743 /* flags passable to sfset() */ #define SF_EOF 002000 /* eof was detected */ #define SF_ERROR 004000 /* an error happened */ #define SF_BUFSIZE 8192 /* suggested default buffer size */ #define SF_UNBOUND (-1) /* unbounded buffer size */ #define sfstdin (&_Sfstdin) /* standard input stream */ #define sfstdout (&_Sfstdout) /* standard output stream */ #define sfstderr (&_Sfstderr) /* standard error stream */ #if __cplusplus extern "C" { #endif extern int _Sfi; extern Sfile_t _Sfstdin, _Sfstdout, _Sfstderr; extern Sfile_t *sfnew _SFA_((Sfile_t*, unsigned char*, int, int, int)); extern Sfile_t *sfopen _SFA_((Sfile_t*, const char*, const char*)); extern Sfile_t *sfdopen _SFA_((int, const char*)); extern Sfile_t *sfpopen _SFA_((const char*, const char*, Sfile_t**)); extern Sfile_t *sfstack _SFA_((Sfile_t*, Sfile_t*)); extern Sfile_t *_sftmpfile _SFA_((int)); extern int _sfflsbuf _SFA_((Sfile_t*, int)); extern int _sffilbuf _SFA_((Sfile_t*, int)); extern int _sfsync _SFA_((Sfile_t*)); extern int _sfpeek _SFA_((Sfile_t*, unsigned char**)); extern int sfclrlock _SFA_((Sfile_t*)); extern unsigned char* sfsetbuf _SFA_((Sfile_t*, unsigned char*, int)); extern Sfdisc_t* sfsetdisc _SFA_((Sfile_t*,Sfdisc_t*)); extern int sfnotice _SFA_((void(*)(Sfile_t*, int))); extern int sfset _SFA_((Sfile_t*, int, int)); extern int sfpool _SFA_((Sfile_t*, Sfile_t*, int)); extern int sfread _SFA_((Sfile_t*, unsigned char*, int)); extern int sfwrite _SFA_((Sfile_t*, const unsigned char*, int)); extern int sfmove _SFA_((Sfile_t*, Sfile_t*, long, const char*)); extern int sfclose _SFA_((Sfile_t*)); extern long sftell _SFA_((Sfile_t*)); extern long sfseek _SFA_((Sfile_t*, long, int)); extern int sfllen _SFA_((long)); extern int sfdlen _SFA_((double)); extern int sfputs _SFA_((Sfile_t*, const char*, int)); extern char *sfgets _SFA_((Sfile_t*, char*, int)); extern int sfnputc _SFA_((Sfile_t*, unsigned char, int)); extern int _sfputu _SFA_((Sfile_t*, unsigned long)); extern int _sfputl _SFA_((Sfile_t*, long)); extern long _sfgetl _SFA_((Sfile_t*)); extern unsigned long _sfgetu _SFA_((Sfile_t*)); extern long _sfgetl _SFA_((Sfile_t*)); extern int _sfputd _SFA_((Sfile_t*, double)); extern double sfgetd _SFA_((Sfile_t*)); extern int sfungetc _SFA_((Sfile_t*, int)); extern char *_sfcvt _SFA_((double, int, int*, int*, int)); extern int sfprintf _SFA_((Sfile_t*, const char*, ...)); extern int sfsprintf _SFA_((char*, int, const char*, ...)); extern int sfscanf _SFA_((Sfile_t*, const char*, ...)); extern int sfsscanf _SFA_((const char*, const char*, ...)); #if __STDC__ || __cplusplus #include <stdarg.h> #endif extern int sfvprintf _SFA_((Sfile_t*, const char*, va_list)); extern int sfvscanf _SFA_((Sfile_t*, const char*, va_list)); /* function analogues of fast in-line functions */ extern int sfgetc _SFA_((Sfile_t*)); extern long sfgetl _SFA_((Sfile_t*)); extern unsigned long sfgetu _SFA_((Sfile_t*)); extern int sfputc _SFA_((Sfile_t*,int)); extern int sfputd _SFA_((Sfile_t*,double)); extern int sfputl _SFA_((Sfile_t*,long)); extern int sfputu _SFA_((Sfile_t*,unsigned long)); extern int sfpeek _SFA_((Sfile_t*, unsigned char**)); extern int sfsync _SFA_((Sfile_t*)); extern Sfile_t* sfpushed _SFA_((Sfile_t*)); extern Sfile_t* sftmp _SFA_((int)); extern int sfslen _SFA_((void)); extern int sfulen _SFA_((unsigned long)); extern long sforigin _SFA_((Sfile_t*)); extern int sfclearerr _SFA_((Sfile_t*)); extern int sfeof _SFA_((Sfile_t*)); extern int sferror _SFA_((Sfile_t*)); extern int sffileno _SFA_((Sfile_t*)); extern char* sfecvt _SFA_((double,int,int*,int*)); extern char* sffcvt _SFA_((double,int,int*,int*)); #if __cplusplus } #endif /* fast in-line functions */ #define sfputc(f,c) ((f)->next >= (f)->endw ? \ _sfflsbuf(f,(int)((unsigned char)(c))) : \ (int)(*(f)->next++ = (unsigned char)(c))) #define sfgetc(f) ((f)->next >= (f)->endr ? _sffilbuf(f,1) : (int)(*(f)->next++)) #define sfslen() (_Sfi) #define sffileno(f) ((f)->file) #define sforigin(f) (((f)->flags&SF_STRING) ? 0L : (f)->orig) #define sfeof(f) (((f)->flags&(SF_EOF|SF_STRING)) && (f)->next >= (f)->endb) #define sferror(f) ((f)->flags&SF_ERROR) #define sfclearerr(f) ((f)->flags &= ~(SF_ERROR|SF_EOF)) #define sfpushed(f) ((f)->push) #define sftmp(n) ((n) >= 0 ? _sftmpfile(n) : \ sfnew((Sfile_t*)0,(unsigned char*)0,-1,-1, \ SF_READ|SF_WRITE|SF_STRING)) #define sfpeek(f,bufp) (((bufp) || \ ((f)->flags&(SF_READ|SF_WRITE|SF_STRING)) == \ (SF_READ|SF_WRITE|SF_STRING)) ? _sfpeek(f,bufp) : \ ((f)->endb - (f)->next)) #define sfsync(f) (((f) && (((Sfile_t*)(f))->flags&SF_STRING)) ? 0 : _sfsync(f)) /* coding long integers in a portable and compact fashion */ #define SF_SBITS 6 #define SF_UBITS 7 #define SF_SIGN (1 << SF_SBITS) #define SF_MORE (1 << SF_UBITS) #define SF_U1 SF_MORE #define SF_U2 (SF_U1*SF_U1) #define SF_U3 (SF_U2*SF_U1) #define SF_U4 (SF_U3*SF_U1) #define sfulen(v) ((v) < SF_U1 ? 1 : (v) < SF_U2 ? 2 : \ (v) < SF_U3 ? 3 : (v) < SF_U4 ? 4 : 5) #define sfgetu(f) ((_Sfi = sfgetc(f)) < 0 ? -1 : \ ((_Sfi&SF_MORE) ? _sfgetu(f) : (unsigned long)_Sfi)) #define sfgetl(f) ((_Sfi = sfgetc(f)) < 0 ? -1 : \ ((_Sfi&(SF_MORE|SF_SIGN)) ? _sfgetl(f) : (long)_Sfi)) #define sfputu(f,v) _sfputu((f),(unsigned long)(v)) #define sfputl(f,v) _sfputl((f),(long)(v)) #define sfputd(f,v) _sfputd((f),(double)(v)) #define sfecvt(v,n,d,s) _sfcvt((v),(n),(d),(s),1) #define sffcvt(v,n,d,s) _sfcvt((v),(n),(d),(s),0) #endif /* _SFIO_H */ 0707070000000001011006440044230044230000010000000475445764600003300000002655include/stack.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * stack routine definitions */ #ifndef __STACK_H #define __STACK_H #ifndef VOID #define VOID char #endif typedef struct stacktable* STACK; /* stack pointer */ typedef struct stackposition STACKPOS; /* stack position */ struct stackblock /* stack block cell */ { char** stack; /* actual stack */ struct stackblock* prev; /* previous block in list */ struct stackblock* next; /* next block in list */ }; struct stackposition /* stack position */ { struct stackblock* block; /* current block pointer */ int index; /* index within current block */ }; struct stacktable /* stack information */ { struct stackblock* blocks; /* stack table blocks */ char* error; /* error return value */ int size; /* size of each block */ STACKPOS position; /* current stack position */ }; #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern STACK mkstack(int size, char* error); extern void rmstack(STACK stack); extern void clrstack(STACK stack); extern char* getstack(STACK stack); extern int pushstack(STACK stack, char* value); extern int popstack(STACK stack); extern void posstack(STACK stack, int set, STACKPOS* position); #if __cplusplus } #endif #else extern STACK mkstack(); extern void rmstack(); extern void clrstack(); extern char* getstack(); extern int pushstack(); extern int popstack(); extern void posstack(); #endif #endif 0707070000000001021006440044230044230000010000000474506072000003200000002666include/stak.h Ugsf Ggsf #ifndef STAK_SMALL /* * David Korn * AT&T Bell Laboratories * * Interface definitions for a stack-like storage library * */ #if defined(__STDC__) || __cplusplus || c_plusplus # define __ARGS(args) args #else # define const /*empty*/ # define __ARGS(args) () #endif typedef struct _stak_ { int stakleft; /* number of bytes left in frame */ char *staktop; /* current stack location */ char *stakbot; /* last returned stack location */ short stakref; /* reference count */ #ifdef _STAK_PRIVATE _STAK_PRIVATE #endif /* _STAK_PRIVATE */ } Stak_t; #define STAK_SMALL 1 /* argument to stakcreate */ #if __cplusplus extern "C" { #endif extern Stak_t *stakcreate __ARGS((int)); extern Stak_t *stakinstall __ARGS((Stak_t*, char *(*)(int))); extern int stakdelete __ARGS((Stak_t*)); extern char *stakalloc __ARGS((unsigned)); extern char *stakcopy __ARGS((const char*)); extern char *stakset __ARGS((char*, unsigned)); extern char *stakseek __ARGS((unsigned)); extern int stakputs __ARGS((const char*)); extern char *stakfreeze __ARGS((unsigned)); extern char *_stakgrow __ARGS((unsigned)); #if __cplusplus } #endif extern Stak_t _stak_cur; /* used by macros */ #define staklink(sp) ((sp)->stakref++) #define stakptr(n) (_stak_cur.stakbot+(n)) #define staktell() (_stak_cur.staktop-_stak_cur.stakbot) #define stakputc(c) ((--_stak_cur.stakleft<0? _stakgrow(1):0), \ *_stak_cur.staktop++=(c)) #endif /* STAK_SMALL */ 0707070000000001031006440044230044230000010000000474441023500003300000005417include/stdio.h Ugsf Ggsf /* * AT&T Bell Laboratories * * sfio stdio source emulation */ #ifndef _STDIO_H_ #if __cplusplus || c_plusplus #include <../CC/stdio.h> #ifndef _STDIO_H_ #define _STDIO_H_ #endif #else #define _STDIO_H_ #include <sfio.h> #define _IOFBF 0 #define _IONBF 1 #define _IOLBF 2 #define L_ctermid 9 #define L_cuserid 9 #define P_tmpdir "/usr/tmp/" #define L_tmpnam (sizeof(P_tmpdir)+15) #if __cplusplus || c_plusplus extern "C" { #endif extern char *ctermid _SFA_((char*)); extern char *cuserid _SFA_((char*)); extern char *tmpnam _SFA_((char*)); extern char *tempnam _SFA_((char*)); extern char *_stdgets _SFA_((char*, int n)); extern int _stdprintf _SFA_((const char*, ...)); extern int _stdsprintf _SFA_((char*, const char*, ...)); extern int _stdscanf _SFA_((const char*, ...)); extern int _stdsetvbuf _SFA_((Sfile_t*, char*, int, int)); #if __cplusplus || c_plusplus } #endif #define stdin sfstdin #define stdout sfstdout #define stderr sfstderr #define FILE Sfile_t #define BUFSIZ SF_BUFSIZE #define fopen(f,m) sfopen((Sfile_t*)0,f,m) #define fdopen(fd,m) sfdopen(fd,m) #define freopen(f,m,p) sfopen(p,f,m) #define tmpfile() sftmpfile() #define popen(cmd,m) sfpopen(cmd,m,(Sfile_t**)0) #define fclose(f) sfclose(f) #define pclose(f) sfclose(f) #define fwrite(p,s,n,f) ((_Sfi = sfwrite(f,p,(s)*(n))) <= 0 ? _Sfi : _Sfi/(s)) #define fputc(c,f) sfputc(f,c) #define putc(c,f) sfputc(f,c) #define putw(w,f) (_Sfi = (int)w, sfwrite(f,&_Sfi,sizeof(int)) <= 0 ? 1 : 0) #define putchar(c) sfputc(sfstdout,c) #define fputs(s,f) sfputs(f,s,0) #define puts(s) sfputs(sfstdout,s,'\n') #define fprintf sfprintf #define vfprintf sfvprintf #define vprintf(f,a) sfvprintf(sfstdout,f,a) #define vsprintf _stdvsprintf #define printf _stdprintf #define sprintf _stdsprintf #define fread(p,s,n,f) ((_Sfi = sfread(f,p,(s)*(n))) <= 0 ? _Sfi : _Sfi/(s)) #define fgetc(f) sfgetc(f) #define getc(f) sfgetc(f) #define getw(f) (sfread(f,&_Sfi,sizeof(int)) == sizeof(int) ? _Sfi : -1) #define getchar() sfgetc(sfstdin) #define ungetc(c,f) sfungetc(f,c) #define fgets(s,n,f) sfgets(f,s,n) #define _SIZEOF(s) (sizeof(s) != sizeof(char*) ? sizeof(s) : BUFSIZ) #define gets(s) _stdgets(s,_SIZEOF(s)) #define fscanf sfscanf #define vfscanf sfvscanf #define sscanf sfsscanf #define vscanf(f,a) sfvscanf(sfstdin,f,a) #define scanf _stdscanf #define vsscanf _stdvssanf #define fflush(f) sfsync(f) #define fseek(f,o,t) (sfseek(f,o,t) < 0L ? -1 : 0) #define rewind(f) sfseek((f),0L,0) #define ftell(f) sftell(f) #define setbuf(f,b) sfsetbuf(f,b,(b) ? BUFSIZ : 0) #define setbuffer(f,b,n) sfsetbuf(f,b,n) #define setlinebuf(f) sfsetflag(f,SF_LINE,1) #define setvbuf _stdsetvbuf #define fileno(f) sffileno(f) #define feof(f) sfeof(f) #define ferror(f) sferror(f) #define clearerr(f) (sfclearerr(f),sfclearlock(f)) #endif #endif 0707070000000001041006440044230044230000010000000475434432200003200000001330include/swap.h Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * internal representation conversion support definitions */ #ifndef BYTE #define BYTE 01 /* swap bytes */ #define HALF 02 /* swap halfwords */ #define getbyte(op,p) (*((unsigned char*)(p))) #define putbyte(op,p,n) (*(p)=(n)) #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern char* memswap(int, char*, int); extern int gethalf(int, const char*); extern long getlong(int, const char*); extern void puthalf(int, char*, int); extern void putlong(int, char*, long); #if __cplusplus } #endif #else extern char* memswap(); extern int gethalf(); extern long getlong(); extern void puthalf(); extern void putlong(); #endif #endif 0707070000000001051006440044230044230000010000000432520526300003100000004005include/tar.h Ugsf Ggsf /* * Standard Archive Format * USTAR - Uniform Standard Tape ARchive */ #ifndef TBLOCK #define TBLOCK 512 #define NAMSIZ 100 #define PFXSIZ 155 #define TMODLEN 8 #define TUIDLEN 8 #define TGIDLEN 8 #define TSIZLEN 12 #define TMTMLEN 12 #define TCKSLEN 8 #define TMAGIC "ustar" /* ustar and a null */ #define TMAGLEN 6 #define TVERSION "00" /* 00 and no null */ #define TVERSLEN 2 #define TUNMLEN 32 #define TGNMLEN 32 #define TDEVLEN 8 /* * values used in typeflag field */ #define REGTYPE '0' /* regular file */ #define AREGTYPE 0 /* alternate REGTYPE */ #define LNKTYPE '1' /* hard link */ #define SYMTYPE '2' /* soft link */ #define CHRTYPE '3' /* character special */ #define BLKTYPE '4' /* block special */ #define DIRTYPE '5' /* directory */ #define FIFOTYPE '6' /* FIFO special */ #define CONTYPE '7' /* reserved */ #define SOKTYPE '8' /* socket -- reserved */ #define VERTYPE 'V' /* version -- reserved */ /* * bits used in mode field */ #define TSUID 04000 /* set uid on exec */ #define TSGID 02000 /* set gid on exec */ #define TSVTX 01000 /* sticky bit -- reserved */ /* * file permissions */ #define TUREAD 00400 /* read by owner */ #define TUWRITE 00200 /* write by owner */ #define TUEXEC 00100 /* execute by owner */ #define TGREAD 00040 /* read by group */ #define TGWRITE 00020 /* execute by group */ #define TGEXEC 00010 /* write by group */ #define TOREAD 00004 /* read by other */ #define TOWRITE 00002 /* write by other */ #define TOEXEC 00001 /* execute by other */ struct header { char name[NAMSIZ]; char mode[TMODLEN]; char uid[TUIDLEN]; char gid[TGIDLEN]; char size[TSIZLEN]; char mtime[TMTMLEN]; char chksum[TCKSLEN]; char typeflag; char linkname[NAMSIZ]; char magic[TMAGLEN]; char version[TVERSLEN]; char uname[TUNMLEN]; char gname[TGNMLEN]; char devmajor[TDEVLEN]; char devminor[TDEVLEN]; char prefix[PFXSIZ]; }; union hblock { char dummy[TBLOCK]; struct header dbuf; }; #endif 0707070000000001061006440044230044230000010000000475434632700003000000006372include/tm.h Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support definitions */ #ifndef TM_DEFAULT #define tm_data _tm_data_ #define tm_info _tm_info_ #include <time.h> #ifndef LS_USER #include <sys/types.h> #endif #define tmset() do{if(!tm_info.local.standard)tminit();}while(0) #ifndef VOID #define VOID char #endif #define TM_ADJUST (1<<0) /* local doesn't do leap secs */ #define TM_LEAP (1<<1) /* do leap seconds */ #define TM_UTC (1<<2) /* universal coordinated ref */ #define TM_DST (-60) /* default minutes for DST */ #define TM_LOCALZONE (25 * 60) /* use local time zone offset */ #define TM_MAXLEAP 1 /* max leap secs per leap */ /* * these indices must agree with tm_dform[] */ #define TM_MONTH_3 0 #define TM_MONTH 12 #define TM_DAY_3 24 #define TM_DAY 31 #define TM_TIME 38 #define TM_DATE 39 #define TM_DEFAULT 40 #define TM_MERIDIAN 41 #define TM_UT 43 #define TM_DT 47 #define TM_SUFFIXES 51 #define TM_PARTS 55 #define TM_HOURS 62 #define TM_DAYS 66 #define TM_LAST 69 #define TM_THIS 72 #define TM_NEXT 75 #define TM_EXACT 78 #define TM_NOISE 81 #define TM_NFORM 85 struct tl /* leap second info */ { time_t time; /* the leap second event */ int total; /* inclusive total since epoch */ }; struct tz /* time zone info */ { char* type; /* type name */ char* standard; /* standard time name */ char* daylight; /* daylight or summertime name */ short west; /* minutes west of GMT */ short dst; /* add to tz.west for DST */ }; struct tmdata /* tm library readonly data */ { char** format; /* default TM_* format strings */ char* lex; /* format lex type classes */ char* digit; /* output digits */ short* days; /* days in month i */ short* sum; /* days in months before i */ struct tl* leap; /* leap second table */ struct tz* zone; /* alternate timezone table */ }; struct tminfo /* tm library global info */ { char* deformat; /* TM_DEFAULT override */ int flags; /* flags */ char** format; /* current format strings */ struct tz local; /* local timezone */ }; #if __cplusplus extern "C" { #endif extern struct tmdata tm_data; extern struct tminfo tm_info; #if __cplusplus } #endif #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern time_t time(time_t*); extern time_t tmdate(const char*, char**, time_t*); extern struct tm* tmfix(struct tm*); extern char* tmform(char*, const char*, time_t*); extern int tmgoff(const char*, char**, int); extern void tminit(void); extern time_t tmleap(time_t*); extern int tmlex(const char*, char**, char**, int, char**, int); extern struct tm* tmmake(time_t*); extern char* tmpoff(char*, const char*, int, int); extern time_t tmtime(struct tm*, int); extern char* tmtype(const char*, char**); extern int tmword(const char*, char**, const char*, char**, int); extern int tmzone(const char*, char**, const char*, int*); #if __cplusplus } #endif #else extern time_t time(); extern time_t tmdate(); extern struct tm* tmfix(); extern char* tmform(); extern int tmgoff(); extern void tminit(); extern time_t tmleap(); extern int tmlex(); extern struct tm* tmmake(); extern char* tmpoff(); extern time_t tmtime(); extern char* tmtype(); extern int tmword(); extern int tmzone(); #endif #endif 0707070000000001071006440044230044230000010000000446361053400003000000017542man/ftwalk.3 Ugsf Ggsf .TH FTWALK 3 .SH NAME \fBftwalk\fR \- file tree walker .SH SYNOPSIS .ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i .PP .nf \fB #include <ftwalk.h> ftwalk(char* path, int (*userf)(struct FTW* ftw), int options, int (*comparf)(struct FTW* ftw1, struct FTW* ftw2)) \fR .fi .SH DESCRIPTION .PP \fIFtwalk\fR traverses a directory hierarchy using depth-first search. Upon visiting each file or directory in the hierarchy, it calls the user function \fIuserf\fP to process that file or directory. On a directory object, \fIuserf\fR may be called twice, once in preorder and once in postorder. On a terminal object such as a file or an unreadable directory, \fIuserf\fP is called only once. Cycles due to hard links or symbolic links are detected to avoid infinite loops. .PP \fIPath\fR is the starting point of the search. It may be an absolute path name or a path name relative to the current directory. If \fIpath\fR is a null pointer or points to an empty string, it is treated as if it points to the current (dot) directory. .PP \fIOptions\fR consists of zero or more of the following bits: .IP FTW_CHILDREN: This implies preorder calls to \fIuserf\fR on directory objects. On such a call to \fIuserf\fR, the field \fIftw->link\fR (below) points to a link list of the children of the respective directory. Upon returning from \fIuserf\fP, if the field \fIftw->status\fR of any child object is set to FTW_SKIP (below), that child is pruned from the search. .IP FTW_DELAY: When \fBFTW_CHILDREN\fP is turned on, the fields \fIftw->statb\fP (\fIstruct stat\fP) of children objects remain undefined until these objects are visited. .IP FTW_DOT: Do not use \fIchdir\fR(2) during the traversal. Normally \fIchdir\fR is used so that the base name of the object about to be processed can be used in accessing its data. This can enhance \fIftwalk\fR efficiency but certain program effects such as core dumps may be generated in unexpected places or may not even be generated at all. Whenever \fIchdir\fR generates an error, if possible, the current directory is restored to the starting directory (see FTW_NAME and FTW_PATH). .IP FTW_MULTIPLE: The \fIpath\fP argument is treated as a \fIchar**\fP pointer to a null-terminated array of path names. All hierarchies rooted at these paths will be searched .IP FTW_POST: Calls to the user function are issued only in postorder. That is, \fIuserf\fP is called on a directory only after its descendants have been processed. The absence of this bit indicates that calls to the user functions are issued in preorder. That is, \fIuserf\fP is called on a directory before its descendants are processed. .IP FTW_PHYSICAL: Use \fIlstat\fR(2) instead of \fIstat\fR(2) to get file status and allow detection of symbolic links. In addition, if each component of the absolute path to the starting object has search permission, the absolute path is used for early detection of cycles. .IP FTW_TWICE: Calls to the user function are issued in both preorder and postorder for directory objects. .IP FTW_USER: The first of 6 user defined option bits. These bits are ignored by \fIftwalk\fP. .PP \fIUserf\fR is a user supplied function that is called upon different visits of an object. If the return value of \fIuserf\fR is non-zero, \fIftwalk\fR returns immediately with the same value. The \fIuserf\fP prototype is: .PP .nf int userf(struct FTW* ftw) .fi .PP \fBstruct FTW\fP contains at least the following elements: .PP .nf struct FTW* link; /* link list of children */ struct FTW* parent; /* parent object on the search path */ union { long number; /* local number */ void* pointer; /* local pointer */ } local; /* user defined */ struct stat statb; /* stat buffer of this object */ char* path; /* full pathname */ short pathlen; /* strlen(path) */ unsigned short info; /* type of object */ unsigned short status; /* status of object */ short level; /* depth of object on the search path */ short namelen; /* strlen(name) */ char name[]; /* file name of object */ .fi .PP The \fIlink\fR field is normally NULL. If the option FTW_CHILDREN was turned on, it points to the start of the list of children of the directory being visited in preorder. Finally, if the directory being visited causes a cycle, \fIlink\fR points to the object on the search path that is identical to this directory. Note that if FTW_PHYSICAL was turned on, this may point to a directory that is an ancestor of the starting object. .PP The \fIparent\fR field points to the parent object on the search path. For convenience, a parent object is also supplied for the starting object. In this case, except for the \fIlocal\fR field which is initialized to 0 and the \fIlevel\fR field which contains a negative number, the rest of the structure may be undefined. .PP The \fIinfo\fR field indicates the type of the object being visited and the type of the visit. The types are: .IP FTW_D: A directory being visited in preorder, i.e., none of its children has been visited by the search. .IP FTW_DNX: A directory being visited in preorder that does not have search permission. .IP FTW_DP: A directory being visited in postorder, i.e., all of its descendants have been completely processed. .IP FTW_DC: A directory that causes cycles. This is a terminal object. .IP FTW_DNR: A directory that cannot be opened for reading. This is a terminal object. .IP FTW_F: An ordinary file. .IP FTW_SL: A symbolic link. Unless FTW_FOLLOW (below) is issued by the user function, this object is terminal. .IP FTW_NS: \fIStat\fR failed on this object. The stat buffer \fIstatb\fR is undefined. This object is terminal. .PP The \fIstatus\fR field of \fIstruct FTW\fR is used to communicate information between \fIftwalk\fR and \fIuserf\fR. On calls to \fIuserf\fR, it has one of two values: .IP FTW_NAME: The name of the object as defined in \fIftw->name\fR should be used for accessing its file information. This is because \fIchdir\fR(2) has been used to set the current directory to a suitable place (see FTW_CHDIR). .IP FTW_PATH: The argument \fIpath\fR of \fIuserf\fR should be used for accessing the file information of the object. .PP Upon returning, \fIuserf\fR may set the \fIstatus\fR field to one of the following values: .IP FTW_AGAIN: If this is a directory object being visited in postorder, it will be processed \fIagain\fR as if it had not been visited. .IP FTW_NOPOST: If this is a directory object being visited in preorder, the user function will not be called on its postorder visit. .IP FTW_SKIP: This object and its descendants are pruned from the search. .IP FTW_FOLLOW: If this object is a symbolic link, follow the link to its physical counterpart. .PP \fIComparf\fR, if not NULL, is a pointer to a function used to define a search ordering for children of a directory. If FTW_CHILDREN is turned on, the ordering of the children of a directory is done before the preorder call to \fIuserf\fR on that directory. Therefore, in that case, \fIftw->link\fR will point to the smallest child. .PP The \fIcomparf\fP prototype is: .PP .nf int comparf(struct FTW* ftw1, struct FTW* ftw2) .fi .PP \fIComparf\fR should return a value <0, 0, or >0 to indicate whether \fIftw1\fR is considered smaller, equal, or larger than \fIftw2\fR. .PP \fIFtwalk\fR normally returns 0. On hard errors such as running out of memory, it returns -1. \fIFtwalk\fR may also return other values as discussed with respect to \fIuserf\fR. .SH HISTORY \fIFtwalk\fR performs similar functions as that of the routine \fIftw\fR provided in System V. However, it is more general than \fIftw\fR and suitable for use as a base in implementing popular tools such as \fIls, find, tar, du,\fR and \fIrm\fR. \fIFtwalk\fR also handles symbolic links and hard links gracefully. .SH AUTHORS Phong Vo, Glenn Fowler, Dave Korn .SH SEE ALSO find(1), rm(1), du(1), ls(1), tar(1), stat(2), symlink(2), chdir(3), ftw(3). 0707070000000001101006440044230044230000010000000471772226300002600000027622man/hash.3 Ugsf Ggsf .de L \" literal font .ft 5 .it 1 }N .if !\\$1 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 .. .de LR .}S 5 1 \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" .. .de RL .}S 1 5 \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" .. .de EX \" start example .ta 1i 2i 3i 4i 5i 6i .PP .RS .PD 0 .ft 5 .nf .. .de EE \" end example .fi .ft .PD .RE .PP .. .TH HASH 3 .SH NAME hash \- hash table support .SH SYNOPSIS .L "#include <hash.h>" .SH DESCRIPTION The .I hash routines manipulate collections of dynamic, scoped hash tables. .PP A hash table provides an association between a .I key and its .IR value . A .I key is a sequence of .L char elements and a .I value is a user supplied pointer to the value. Each hash table has a dynamic number of slots, each pointing to the head of a forward linked .IR "collision chain" . .PP Hashing occurs as follows: a .I "hash function" takes a .I key as an argument and returns a non-negative index. The index modulo the table size produces a slot that points to a .IR "collision chain" . The collision chain is sequentially searched until a match is found for .IR key . The hash tables are automatically resized as new entries are added. .PP Each hash table has one key type. The default key type is a pointer to a null-terminated string. The alternate key type is a pointer to a fixed length byte buffer, declared for a given table by the .L hashalloc() function described below. .PP Hash table information is partitioned into two parts for efficient scoping. The .I root part contains fixed information that is shared among a set of related hash tables. The remaining information is maintained on a per-table basis. .PP These basic types are defined in the header file .B hash.h (alternate names are listed in parenthesis): .TP .L "HASHTABLE (Hashtab_t)" The per-table information. The readonly public elements are: .RS .TP .L "int buckets" The number of table entries. .TP .L "char* name" The hash table name. .TP .L "root" The root information. The public elements are: .RS .TP .L "int root->accesses" The number of lookups. .TP .L "int root->collisions" The number of lookup collisions. .RE .TP .L "HASHTABLE* scope" The table that this scope covers, .L NULL if the table is not a scope. .TP .L "int size" The current hash table size. .RE .TP .L "HASHBUCKET (Hashbin_t)" A collision chain hash bucket. The public structure elements are: .RS .TP .L "char* hashname(HASHBUCKET*)" Returns a pointer to the hash bucket key given the bucket pointer. .TP .L "char* value" The value associated with the key. .RE .TP .L "HASHHEADER (Hashhdr_t)" The hash bucket header that must be the first element in all user defined buckets. .L HASH_VALUE may not be used with user defined buckets. .TP .L "HASHPOSITION (Hashpos_t)" Stores the hash table position for .LR hashscan . The public elements are: .RS .TP .L "HASHBUCKET* bucket" The current hash bucket pointer. .RE .PP The routines are: .TP .L "HASHTABLE* hashalloc(HASHTABLE* ref, int op, ...)" Creates a new hash table and returns a pointer to the table. .IR malloc (3) is used to allocate space for the table. .L NULL is returned if the table cannot be created. .L ref is a pointer to a reference hash table that provides default values for unspecified information. The new hash table and .L ref share the same root information. If .L ref is .L NULL then new root information is created for the new table. The remaining arguments appear in .I op-arg pairs, followed by a final .L 0 argument. The .I op-arg pairs are: .RS .TP .L "HASH_alloc, (char(*)()) alloc" .L alloc is a function that is called to process .L HASHBUCKET .L value assignments. The single argument is .L "char* value" and the processed .L char* value is returned. .TP .L "HASH_clear, int flags" .L flags are the .L ref flags to be cleared in the new hash table. See .L HASH_set below. .TP .L "HASH_compare, (int(*)()) compare" Specifies an alternate .I key comparison function. The arguments and return value for .L compare are the same as for .IR strncmp (3) if .L HASH_namesize is specified and .IR strcmp (3) otherwise. The first argument is the .I key from the current hash bucket on the .I "collision chain" and the second argument is the user supplied .IR key . .TP .L "HASH_free, (int(*)()) free" .L free is a function that is called when a hash bucket is freed. If .L HASH_BUCKET was set in .L hashalloc then the hash bucket pointer is passed, otherwise the bucket .L value pointer is passed. .TP .L "HASH_hash, (int(*)()) hash" Specifies an alternate .I key hash function. A .L char* key argument (and, if .L HASH_namesize is specified, an .L int key size argument) is passed to .LR hash . The return value must be a non-negative .LR int . .TP .L "HASH_meanchain, int meanchain" Specifies the mean collision chain length. The hash table is automatically resized when this value is exceeded. The default mean chain length is 2. .TP .L "HASH_name, char* name" Associates .L name with the hash table. Used by .LR hashdump) . .TP .L "HASH_namesize, int namesize" The fixed size in bytes for .I keys in the table. If .L namesize is 0 (the default) then the .I keys are interpreted as null-terminated strings. .TP .L "HASH_set, int flags" Changes the hash table flags by .IR or ing in .LR flags . The flags, which may be .IR or ed together, are: .RS .TP .L HASH_ALLOCATE Keys for new hash table entries are to be copied to data areas obtained from .IR malloc (3). .TP .L HASH_FIXED Fixes the hash table size, disabling any automatic table resizing. .TP .L HASH_SCOPE The new hash table is a scope that is to be pushed on top of .LR ref . .L ref must be .RL non- NULL . .RE .RE .TP .L "HASHTABLE* hashfree(HASHTABLE* tab)" The hash table .L tab is freed. The scope covered table pointer is returned, .L NULL if .L tab is not a scope. .TP .L "char* hashlook(HASHTABLE* tab, char* name, int flags, char* value)" Operates on the key .L name in the hash table .L tab according to .L flags and .LR value . A .L HASHBUCKET pointer is returned unless otherwise noted. There are three basic lookup operations: .RS .TP .L HASH_CREATE .L name is entered into the top level scope if it does not already exist. If .L name also appears in a lower scope and .L HASH_ALLOC is set for the table then the new bucket will share the .L name field value with the lower scope. .TP .L HASH_DELETE .L name is deleted from the top level scope if it exists. .L NULL is returned. .TP .L HASH_LOOKUP The scopes are searched in order from top to bottom for .L name . The bucket pointer for the first occurrence is returned. .L NULL is returned if .L name is not found. .RE The basic operations may be qualified by the following (the qualifiers are restricted to the basic operations in the parenthesized list): .RS .TP .L "HASH_BUCKET (HASH_CREATE,HASH_DELETE,HASH_LOOKUP)" .L name is a pointer to a bucket that has already been entered into the table. .TP .L "HASH_FIXED (HASH_CREATE)" .L value is taken to be the size of the hash bucket to be created for .L name in the top level scope. The minimum bucket size is silently restricted to .LR sizeof(HASHHEADER) . .TP .L "HASH_INSTALL (HASH_CREATE)" .L name is a pointer to a bucket that has not been entered into the table. .TP .L "HASH_NOSCOPE (HASH_LOOKUP)" The lookup is restricted to the top level scope. .TP .L "HASH_OPAQUE (HASH_CREATE,HASH_DELETE)" Sets .L (HASH_CREATE) or clears .L (HASH_DELETE) the .I opaque property for the bucket. An opaque bucket is not visible in lower scopes. .TP .L "HASH_SCOPE (HASH_CREATE,HASH_DELETE)" All scopes are searched for the bucket. If the bucket is not found for .L HASH_CREATE then a new bucket is created in the lowest scope. .TP .L "HASH_VALUE (HASH_CREATE,HASH_LOOKUP)" For .L HASH_CREATE the bucket .L value field is set to .L value and the bucket .L name value is returned. For .L HASH_LOOKUP the bucket .L value field is returned, .L NULL if the bucket is not found. .RE If .L name .L NULL then the name from the most recent .L hashlook() is used, avoiding recomputation of some internal parameters. .TP .L "char* hashget(HASHTABLE* tab, char* name)" Returns the value associated with the key .L name in the hash table .LR tab . If .L name is .L NULL then the name from the most recent .L hashget() is used, avoiding recomputation of some internal parameters. .L NULL is returned if .L name is not in the table. All scope covered tables are searched. .TP .L "HASHBUCKET* hashlast(HASHTABLE* tab)" Returns a pointer to the most recent hash bucket for the most recent hash table. The value is set by .LR hashlook() , .L hashscan() and .LR hashwalk() . .TP .L "char* hashput(HASHTABLE* tab, char* name, char* value)" Set the value of the key .L name to .L value in the top level scope of the hash table .LR tab . .L name is entered into the top level scope if necessary. The (possibly re-allocated) key name pointer is returned (see .LR HASH_ALLOCATE ). .TP .L "int hashwalk(HASHTABLE* tab, int flags, (int(*)()) walker)" The function .L walker is applied to each entry (not covered by a scope starting at .LR tab ) in the hash table .LR tab . If .L flags is .L HASH_NOSCOPE then only the top level hash table is used, otherwise the walk includes all scope covered tables. .L walker is called with .L char* .I key as the first argument and .L char* .I value as the second argument. The walk terminates after the last entry or when .L walker returns a negative value. The return value of the last call to .L walker is returned. Only one walk may be active within a collection of scoped tables. .TP .L "void hashscan(HASHTABLE* tab, int flags, HASHPOSITION* pos)" Initializes .L pos for a sequential scan on the hash table .LR tab . If .L flags is .L HASH_NOSCOPE then only the top level hash table is used, otherwise the scan includes all scope covered tables. Only one scan may be active within a collection of scoped tables. .L hashdone() must be called to terminate the scan. .TP .L "int hashnext(HASHPOSITION* pos)" Generates the next element in the sequential scan set up by .L hashscan() on .LR pos . If no elements remain then .L 0 is returned. Otherwise .L pos->bucket points to the hash bucket of the next element and .L 1 is returned. .TP .L "void hashdone(HASHPOSITION* pos)" Completes a scan initiated by .L hashscan() on .LR pos . .TP .L "int hashset(HASHTABLE* tab, int flags)" Sets the flags for the hash table .L tab by .IR or ing in .LR flags . Only .L HASH_ALLOCATE and .L HASH_FIXED may be set. .TP .L "int hashclear(HASHTABLE* tab, int flags)" Clears the flags for the hash table .L tab by masking out .LR flags . Only .L HASH_ALLOCATE and .L HASH_FIXED may be cleared. .TP .L "void hashdump(FILE* fp, HASHTABLE* tab, int flags)" Dumps hash table accounting info to the output file stream .LR fp . If .L tab is .L NULL then all allocated hash tables are dumped, otherwise only information on .L tab is dumped. If .L flags is .L HASH_BUCKET then the hash bucket .I key-value pairs for each collision chain are also dumped. .TP .L "void hashsize(HASHTABLE* tab, int size)" Changes the size of the hash table .L tab to .L size where .L size must be a power of 2. Explicit calls to this routine are not necessary as hash tables are automatically resized. .TP .L "int strhash(char* name)" Hashes the null terminated character string .L name using a linear congruent pseudo-random number generator algorithm and returns a non-negative .L int hash value. .TP .L "int memhash(char* buf, int siz)" Hashes the buffer .L buf of .L siz bytes using a linear congruent pseudo-random number generator algorithm and returns a non-negative .L int hash value. .TP .L "long strsum(char* name, long sum)" Returns a running 31-bit checksum of the string .L name where .L sum is .L 0 on the first call and the return value from a previous .L memsum or .L strsum call otherwise. The checksum value is consistent across all implementations. .TP .L "long memsum(char* buf, int siz, long sum)" Returns a running 31-bit checksum of buffer .L buf of .L siz bytes where .L sum is .L 0 on the first call and the return value from a previous .L memsum or .L strsum call otherwise. The checksum value is consistent across all implementations. .SH "SEE ALSO" sum(1) 0707070000000001111006440044230044230000010000000467615557100002400000005571man/re.3 Ugsf Ggsf .TH RE 3 .SH NAME recomp, reexec, resub, refree, reerror \(mi regular expression library .SH SYNOPSIS .B #include <re.h> .PP .L reprogram* recomp(char* pattern, int flags) .PP .L int reexec(reprogram* re, char* source) .PP .L void resub(reprogram* re, char* old, char* new, char* destination, int flags) .PP .L void reerror(char* message) .PP .L void refree(reprogram* re) .SH DESCRIPTION .I recomp compiles a regular expression in .B pattern and returns a pointer to a compiled regular expression. The space is allocated by .IR malloc (3) and may be released by .IR refree . Regular expressions are as in .I egrep (see .IR grep (1)) except that newlines are treated as ordinary characters and .B $ matches the end of a null-terminated string. .B flags may be .B RE_EDSTYLE which specifies .IR ed (1) style special characters, .BR \e( , .BR \e) , .BR \e? , .B \e+ and .B \e| for the .IR egrep (1) .BR ( , .BR ) , .BR ? , .B + and .BR | , respectively. .PP .I reexec matches the null-terminated .B source string against the compiled regular expression .I re from a previous call to .IR recomp . If it matches, .I reexec returns a non-zero value. If .B flags is .B RE_MATCH then the array .B re\->match is filled with character pointers to the substrings of .B source that correspond to the parenthesized subexpressions of .BR pattern : .B re\->match[i].sp points to the beginning and .B re\->match[i].ep points just beyond the end of substring .BR i . (Subexpression .B i begins at the .BR i th matched left parenthesis, counting from 1.) Pointers in .B re\->match[0] pick out the substring that corresponds to the entire regular expression. Unused elements of .B re\->match are filled with zeros. Matches involving .BR * , .BR + , and .B ? are extended as far as possible. A maximum of 9 subexpressions will be matched. The structure of elements of .B re\->match is: .nf .ta 8n typedef struct { char* sp; char* ep; } rematch; .fi .LP .I resub places in .I destination a substitution instance of .B old to .B new in .B source in the context of the last .I reexec performed on .IR re\->match . Each instance of .BI \e n , where .I n is a digit, is replaced by the string delimited by .BI re\->match[ n ].sp and .BI re\->match[ n ].ep . Each instance of .B & is replaced by the string delimited by .B re\->match[0].sp and .BR re\->match[0].ep . If .B RE_ALL is set in .B flags then all occurrences of .B old are replaced by .IR new . If .B RE_LOWER .RB [ RE_UPPER ] is set in .B flags then .B old is converted to lower [upper] case. .LP .I reerror, called whenever an error is detected in .I recomp, .I reexec, or .I resub, writes the string .B msg on the standard error file and exits. .I reerror may be replaced to perform special error processing. .SH DIAGNOSTICS .I recomp returns 0 for an invalid expression or other failure. .I reexec returns 1 if .B source is accepted, 0 otherwise. .SH "SEE ALSO" ed(1), grep(1), expr(1) 0707070000000001121006440044230044230000010000000475416250000002600000073727man/sfio.3 Ugsf Ggsf .TH SFIO 3 "21 August 1990" .SH NAME \fBsfio\fR \- safe/fast string/file input/output .SH SYNOPSIS .ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i .PP .nf .ft 5 #include <sfio.h> #define uchar unsigned char #define uint unsigned int #define ulong unsigned long Sfile_t* sfnew(Sfile_t* f, uchar* buf, int size, int fd, int flags); Sfile_t* sfopen(Sfile_t* f, char* string, char* mode); Sfile_t* sfdopen(int fd, char* mode); Sfile_t* sfpopen(char* cmd, char* mode, Sfile_t** fcomp); Sfile_t* sfstack(Sfile_t* base, Sfile_t* top); Sfile_t* sfpushed(Sfile_t* f); Sfile_t* sftmp(int size); int sfpool(Sfile_t* f, Sfile_t* poolf, int mode); Sfdisc_t* sfsetdisc(Sfile_t* f, Sfdisc_t* disc); int sfclose(Sfile_t* f); int sfsync(Sfile_t* f); int sfpeek(Sfile_t* f, uchar** bufp); int sfgetc(Sfile_t* f); int sfungetc(Sfile_t* f, int c); ulong sfgetu(Sfile_t* f); long sfgetl(Sfile_t* f); double sfgetd(Sfile_t* f); char* sfgets(Sfile_t* f, char* buf, int size); int sfread(Sfile_t* f, uchar* buf, int n); int sfscanf(Sfile_t* f, char* format, ...); int sfsscanf(char* s, char* format, ...); int sfvscanf(Sfile_t* f, char* format, va_list args); int sfputc(Sfile_t* f, int c); int sfnputc(Sfile_t* f, int c, int n); int sfputu(Sfile_t* f, ulong v); int sfputl(Sfile_t* f, long v); int sfputd(Sfile_t* f, double v); int sfputs(Sfile_t* f, char* s, int c); int sfwrite(Sfile_t* f, uchar* buf, int n); int sfmove(Sfile_t* fr, Sfile_t* fw, long n, char* seps); int sfprintf(Sfile_t* f, char* format, ...); int sfsprintf(char* s, int size, char* format, ...); int sfvprintf(Sfile_t* f, char* format, va_list args); void sfnotice(void (*noticef)(Sfile_t* f, int type)); int sfset(Sfile_t* f, int flags, int i); uchar* sfsetbuf(Sfile_t* f, uchar* buf, int size); int sffileno(Sfile_t* f); int sfeof(Sfile_t* f); int sferror(Sfile_t* f); int sfclearerr(Sfile_t* f); int sfclrlock(Sfile_t* f); int sfslen(); int sfulen(ulong v); int sfllen(long v); int sfdlen(double v); long sforigin(Sfile_t* f); long sfseek(Sfile_t* f, long addr, int offset); long sftell(Sfile_t* f); char* sfecvt(double v, int n, int* decpt, int* sign); char* sffcvt(double v, int n, int* decpt, int* sign); .fR .fi .SH DESCRIPTION .PP \fIsfio\fP is a library of functions to perform input/output on objects called \fIsfio\fP streams. Each \fIsfio\fP stream may correpond to some file descriptor (see \fIopen(2)\fP) or some piece of primary memory. A notion of stream stack is supported for processing of data from complexes of streams. Streams can be pooled so that their buffers can be synchronized properly when switching streams for io. It is also possible to change io disciplines by setting alternative functions for read, write and seek. .PP A stream abstraction is represented by the type \f5Sfile_t\fP which is defined in the header file \f5<sfio.h>\fP. A stream is locked while it is being accessed by some \fIsfio\fP function. A locked stream cannot be further accessed by operations that may change its internal states (see \f5sfclrlock()\fP). Any such access fails and returns an appropriate error code. .PP During an io request, if a system call \f5read\fP or \f5write()\fP (or their discipline counterparts) is interrupted, unless a discipline function has been defined to process it, the calling \fIsfio\fP function will resume the respective system call as necessary. The interrupt condition is defined by \f5errno\ ==\ EINTR\fP (see \f5errno.h\fP). To prevent infinite loops, this condition is always cleared before the system call is resumed. .PP In general, \fIsfio\fP functions either return integer or pointer values. In the event of an error, a function that returns integer value will return \f5-1\fP while a function that returns a pointer value will return \f5NULL\fP. .PP A number of bit flags define stream types and their operations. Following are the flags: .IP \f5SF_READ\fP: The stream is readable. .IP \f5SF_WRITE\fP: The stream is writable. .IP \f5SF_STRING\fP: The stream is a string (a byte array) that is readable if \f5SF_READ\fP is specified or writable if \f5SF_WRITE\fP is specified. .IP \f5SF_APPEND\fP: The stream is a file opened for appending data. This means that data written to the stream is always appended at the end of the file. On operating systems where there is no primitive to specify at file opening time that a file is opened for append only, \f5lseek()\fP (or its discipline replacement) will be used on the file stream to approximate this behavior. .IP \f5SF_RELATIVE\fP: If the stream corresponds to a file, no seek is allowed backward beyond the starting point as defined by \f5lseek(fd,0L,1)\fP (or its discipline replacement) when the stream is initialized by \f5sfnew()\fP (below). .IP \f5SF_LINE\fP: The stream is line-oriented. For write-streams, this means that the buffer is flushed whenever a new-line character is output. For read-streams, this means that \f5sfpeek()\fP (below) will return a buffer of data which ends with a new-line. Note that the amount of data that can be returned is limited by the buffer size. .IP \f5SF_KEEPFD\fP: The file descriptor of the stream will be kept opened when the stream is closed. .IP \f5SF_MALLOC\fP: To indicate that the stream buffer was obtained via \f5malloc()\fP and can be reallocated or freed by the package. .IP \f5SF_REUSE\fP: This flag can be set (\f5sfset()\fP so that when the stream is closed, its data structure and associated information such as pool and discipline is not destroyed. It can also be used in a call to \f5sfnew()\fP (see below). .IP \f5SF_SHARE\fP: This flag indicates that the associated stream is a file stream that may be operated on by means beyond straightforward \fIsfio\fP usage (e.g., by multiple processes). In this case, each io system call (or its discipline replacement) will be preceded by a \f5lseek()\fP (or its discipline replacement) to ensure that the logical stream location corresponds to the physical file location. .PP \f5sfnew(f,buf,size,fd,flags)\fP is the primitive for creating or renewing streams. For file streams, a number of operations are performed to determine seekability, optimal buffer sizes if not specified, etc. Each stream has a origin. The origin of a \f5SF_STRING\fP stream is always \f50L\fP. If a file stream is not seekable, its origin is defined as \f5-1L\fP. Otherwise, its origin is defined as either the current location or \f50L\fP depending on whether or not the flag \f5SF_RELATIVE\fP is turned on. \f5sfseek()\fP operations are relative to this location. The argument \f5f\fP of \f5sfnew()\fP, if not \f5NULL\fP, is a stream to be modified. If it is \f5NULL\fP, a new stream is created. The argument \f5buf\fP, if not \f5NULL\fP, is a buffer to be used. In this case, \f5size\fP should be positive. If \f5size\fP is 0, the stream is unbuffered. If \f5size\fP is negative, \fIsfio\fP will allocate a buffer. The argument \f5fd\fP is a file descriptor (e.g., from \fIopen()\fP) for io operations if the stream is not an \f5SF_STRING\fP stream. The last argument \f5flags\fP is a bit vector composing from the flags described above. The \f5SF_REUSE\fP flag, if given, indicates that the current attributes of the stream \f5f\fP should be used instead of whatever else is defined by \f5flags\fP. .PP \f5sfopen(f,string,mode)\fP is a high-level function based on \f5sfnew()\fP to create new streams from files or strings. The argument \f5f\fP for \f5sfopen()\fP, if not \f5NULL\fP, is a currently opened stream to be closed and replaced by a new stream corresponding to the object \f5string\fP. The argument \f5mode\fP can be any one of: \f5"r"\fP, \f5"r+"\fP, \f5"w"\fP, \f5"w+"\fP, \f5"a"\fP, \f5"a+"\fP, \f5s\fP and \f5s+\fP. The \f5r\fP, \f5w\fP, and \f5a\fP specify read, write and append mode for file streams. In these cases, the argument \f5string\fP defines a path name to a file. The \f5s\fP specifies that \f5string\fP is a nul-terminated string to be opened for read. The \f5+\fP means that the new stream will be opened for both reading and writing. .PP \f5sfdopen(fd,mode)\fP makes a stream using the file descriptor \f5fd\fP. The \f5mode\fP argument is used in the same way as in \f5sfopen()\fP. .PP \f5sfpopen(cmd,mode,fcomp)\fP opens a stream \f5f\fP which is a pipe to (from) the command \f5cmd\fP if the mode is \f5"w"\fP (\f5"r"\fP). If the mode is \f5"w+"\fP or \f5"r+"\fP, another stream for the opposite operation is created and returned in \f5fcomp\fP. Note that if either of these streams is closed, the other is also closed. .PP \f5sfstack(base,top)\fP is used to push or pop stream stacks. Each stream stack is identified by a \f5base\fP stream via which all io operations are performed. Other streams on the stack are locked so that operations that may change their internal states are forbidden. The type of operations that can be done on a stack is defined by the top level stream. If an io operation is performed and the top level stream reaches the end of file condition or an error condition other than interrupts, it is automatically popped and closed (see also \f5sfsetdisc\fP for alternative handling of these conditions). The first argument of \f5sfstack()\fP specifies the \f5base\fP stream. The second argument, \f5top\fP, if not \f5NULL\fP, is pushed on top of the current top stream. In this case, the \f5base\fP stream pointer is returned. If \f5top\fP is \f5NULL\fP, the stack is popped and the pointer to the popped stream is returned. .PP \f5sfpushed(f)\fP returns the pointer to the stream pushed below \f5f\fP. .PP \f5sftmp(size)\fP creates a stream for writing and reading temporary data. If \f5size\fP is negative, the stream is a pure \f5SF_STRING\fP stream. Otherwise, the stream is originally created as a \f5SF_STRING\fP stream with a buffer of the given \f5size\fP. A discipline is set so that when this buffer is exhausted, a real temporary file will be created. Any attempt to change this discipline will also cause the temporary file to be created. .PP \f5sfpool(f,poolf,mode)\fP manages pools of streams. In a pool of streams, only one stream is current. A stream becomes current when it is used for some io operation. When a new stream is to become current, the current stream is synchronized (see \f5sfsync()\fP) if its type matches the type of the pool. The first argument of \f5sfpool()\fP, \f5f\fP, is the stream to be manipulated. The second argument, \f5poolf\fP, determines the operation to be done on \f5f\fP. If \f5poolf\fP is \f5NULL\fP, \f5f\fP is deleted from its current pool. Otherwise, \f5f\fP is put into the same pool with \f5poolf\fP. If \f5poolf\fP is already in a pool, the third argument is ignored. Otherwise, it determines the type of the new pool. \f5mode\fP can be constructed by bitwise or-ing of \f5SF_READ\fP and \f5SF_WRITE\fP. .PP \f5sfsetdisc(f,disc)\fP changes the io-discipline of the stream \f5f\fP, i.e., to specify alternative functions for read, write, seek, and to handle exceptions. The default discipline consists of the system calls \f5read()\fP, \f5write()\fP, and \f5lseek()\fP. The \f5disc\fP argument is either \f5NULL\fP to reset to the default discipline or a pointer to a \f5Sfdisc_t\fP structure which contains the following fields: .PP .nf \f5int (*readf)();\fP \f5int (*writef)();\fP \f5long (*seekf)();\fP \f5int (*exceptf)();\fP \f5void* handle;\fP .fi .PP The first three fields of \f5Sfdisc_t\fP specify alternative io functions. If any of them is \f5NULL\fP, the corresponding system call is used. A discipline io function, say \f5(*readf)()\fP, is called with 4 arguments. The first argument is the stream pointer. The second and third arguments correspond to the second and third arguments of the respected system call. The fourth argument is the \f5handle\fP field of \f5Sfdisc_t\fP. The exception function, \f5(*exceptf)()\fP, if provided, is called when an exception happens during a read/write operation, when a stream is being closed, or when the discipline is being reset. A read/write operation is said to cause an exception if its return value is zero or negative. It is up to the exception function to determine the type of exception (for example, by examining \f5errno\fP). When \f5(*exceptf)()\fP is called, the stream will be opened for general operations. However, \f5(*exceptf)()\fP should not attempt to close the stream. \f5(*exceptf)()\fP is called as: \f5(*exceptf)(f,type,handle)\fP. \f5type\fP is: \f50\fP when the discipline is being reset, \f5SF_EOF\fP when the stream is being closed, \f5SF_READ\fP when an exception happens during a read operation, and \f5SF_WRITE\fP when an exception happens during a write operation. For the cases of \f5SF_READ\fP and \f5SF_WRITE\fP, the executing \fIsfio\fP function will examine the return value of \f5(*exceptf)()\fP for further actions: \fInegative\fP for immediate return, \fIzero\fP for executing default actions associated with the exception, and \fIpositive\fP for resuming execution. Note that a \f5SF_STRING\fP stream does not perform external io so the io functions are not used. However, an exception occurs whenever an io operation exceeds the stream buffer boundary and \f5(*exceptf)()\fP, if defined, will be called as appropriate. \f5sfsetdisc()\fP returns the pointer to the previous discipline or \f5NULL\fP if an error happened. Finally, it is the application's responsibility to manage the space used by the \f5Sfdisc_t\fP structures. .PP \f5sfclose(f)\fP closes the given stream \f5f\fP and frees up its resources. If \f5f\fP is \f5NULL\fP, all streams are closed. If \f5f\fP is a stack of streams, all streams on the stack are closed. If \f5f\fP is a \f5sfpopen\fP-stream, its companion stream, if any, is also closed. Further, \f5sfclose()\fP will wait until the associated command terminates, then return its exit status. A few file flags affect the behavior of \f5sfclose()\fP. If \f5SF_KEEPFD\fP is on, the underlying file descriptor is not closed. If \f5SF_REUSE\fP is on, \f5sfclose()\fP will only synchronize the buffer and close the file descriptor (subject to \f5SF_KEEPFD\fP). The stream structure is left intact, including pool (\f5sfpool()\fP) or discipline (\f5sfsetdisc()\fP) information. .PP \f5sfsync(f)\fP causes the physical file pointer of the stream \f5f\fP to correspond to its logical position. If \f5f\fP is the base of a stack of streams, all streams on the stack are synchronized. Further, a stacked stream can only be synchronized via its base stream. .PP \f5sfpeek(f,bufp)\fP provides a safe method for enquiring information on the internal buffer of a stream. If \f5bufp\fP is \f5NULL\fP, \f5sfpeek()\fP simply returns the amount of data available in the buffer to read if \f5f\fP is in read mode or the amount of buffer available to write if \f5f\fP is in write mode. If \f5bufp\fP is not \f5NULL\fP, \f5sfpeek()\fP provides access to the buffer. For a read stream, if the buffer is empty, it is filled and, for a write-stream, if the buffer is full, it is flushed. Then, for a read stream, \f5bufp\fP is set to the place in the buffer where data is available and, for a write stream, it is set to where data can be written. The return value of \f5sfseek()\fP indicates how much data or space is available in the buffer. However, if the stream is in \f5SF_LINE|SF_READ\fP mode, the return value will be the data length up to and including the new-line character. In this case, if there is not a new-line character in the buffered data, more data may be read. Note that the buffer location is not advanced by \f5sfpeek()\fP. That must be done by a regular io call such as \f5sfread\fP or \f5sfwrite\fP on the pointer returned in \f5bufp\fP. Finally, \f5sfpeek()\fP treats a read/write-stream like a read-stream (however, see also \f5sfset()\fP). .PP \f5sfgetc(f)\fP returns a byte from the stream \f5f\fP or -1 when an end-of-file or error condition is encountered. .PP \f5sfungetc(f,c)\fP puts the byte \f5c\fP back into the stream \f5f\fP. This is guaranteed to work only after a \f5sfgetc()\fP call. .PP \f5sfgetu(f)\fP, \f5sfgetl(f)\fP, and \f5sfgetd(f)\fP return an \fIunsigned long\fP, a \fIlong\fP value, or a \fIdouble\fP value that was coded in a portable fashion (see \f5sfputu()\fP, \f5sfputl()\fP, and \f5sfputd()\fP). If there is not enough data to decode a value, these functions will return \f5-1\fP and the stream is set in an error state (\f5see \f5sferror()\fP). .PP \f5sfgets(f,buf,size)\fP reads a line of input from the stream \f5f\fP. If \f5buf\fP is not \f5NULL\fP and \f5size\fP is positive, \f5sfgets\fP reads up to \f5size-1\fP characters into the buffer \f5buf\fP. Otherwise, the characters are read into a static area that is dynamically grown as necessary. Thus, in this case, there is no limit to line length. A nul-character is appended after the input characters. \f5sfgets()\fP returns the pointer to the new string or \f5NULL\fP when no data was read due to end-of-file or an error condition. After a string is read, its length can be found using \f5sfslen()\fP. .PP \f5sfread(f,buf,n)\fP reads up to \f5n\fP bytes from the stream \f5f\fP and stores them in the given buffer \f5buf\fP. It returns the number of bytes actually read. .PP \f5sfscanf(f,format,...)\fP scans a number of items from the stream \f5f\fP. The item types are determined from the string \f5format\fP. See \fIfscanf()\fP (UNIX User's Manual, Section 3) for details on predefined formats. The standardly supported formats are: \f5i, I, d, D, u, U, o, O, x, X, f, F, e, E, g, G, c, %, s,\fP and \f5[]\fP. The \f5sfscanf()\fP interface also supports additional formats as described below. .IP The pattern \f5%&\fP indicates that the next argument in the argument list of \f5sfscanf()\fP is a function, say \f5(*extf)()\fP, to process patterns that are not predefined by the \f5sfscanf()\fP interface. The prototype of \f5(*extf)()\fP is: .nf \f5int (*extf)(Sfile_t* f, int fmt, int length, char** rv);\fP .fi \f5f\fP is the same input stream passed to \f5sfvscanf\fP. \f5fmt\fP is the pattern to be processed. \f5length\fP, if non-negative, is the maximum number of input bytes to be read in processing the pattern, \f5rv\fP is used to return the ``address'' of the value to be assigned. \f5(*extf)()\fP returns the size of the value to be assigned. A negative return value from \f5(*extf)()\fP means that the specified pattern cannot be handled. This pattern is treated as if it is not matched. .IP The pattern \f5%@\fP indicates that the next argument in the argument list \f5args\fP is a function, say \f5(*argf)()\fP, to process the values of matched patterns. The prototype of \f5(*argf)()\fP is: .nf \f5int (*argf)(int fmt, char* value, int n)\fP; .fi If the return value of \f5(*argf)()\fP is negative, the processing of the current format string will be stopped (see \f5%$\fP below). \f5fmt\fP determines the type of \f5value\fP: \f5f\fP for \fIfloat\fP, \f5F\fP for \fIdouble\fP, \f5h\fP for \fIshort\fP, \f5d\fP for \fIint\fP, \f5D\fP for \fIlong\fP, \f5s\fP for \fIchar*\fP. Any other value for \f5fmt\fP means that it is an extended pattern and \f5value\fP contains an address to the scanned value. \f5n\fP contains the size of the object if it is a primitive type. If the object is \f5char*\fP or the address of the scanned value of an extended format, \f5n\fP is the length of this object. .IP The pattern \f5%:\fP indicates that the next two arguments in the argument list \f5args\fP define a new pair of format string and a list of arguments of the type \f5va_list\fP (see \f5varargs.h\fP or \f5stdarg.h\fP). The new pair is pushed on top of the stack and the scanning process continues with them. The top pair of format string and argument list is popped when the processing of the format string is stopped. When a new pair is stacked, \f5(*argf)()\fP and \f5(*extf)()\fP are inherited. They are reset when the stack is popped. .PP \f5sfsscanf(s,format,...)\fP is similar to \f5sfscanf()\fP but it scans data from the string \f5s\fP. .PP \f5sfvscanf(f,format,args)\fP is the primitive underlying \f5sfscanf()\fP and \f5sfscanf()\fP. It also provides a portable variable argument interface. Programs that use \f5sfvscanf()\fP must include either of \f5varargs.h\fP or \f5stdargs.h\fP as appropriate. .PP \f5sfputc(f,c)\fP writes the byte \f5c\fP to the stream \f5f\fP. .PP \f5sfnputc(f,c,n)\fP writes the byte \f5c\fP to the stream \f5f\fP \f5n\fP times. It returns the number of bytes successfully written. .PP \f5sfputu(f,v)\fP, \f5sfputl(f,v)\fP write the \fIunsigned long\fP or \fIlong\fP value \f5v\fP in a format that is byte-order transparent. \f5sfputd(f,v)\fP writes the \fIdouble\fP value \f5v\fP in a portable format. Portability across two different machines requires that the bit order in a byte is the same on both machines. \f5sfputd()\fP also relies on the functions \f5ldexp()\fP and \f5frexp()\fP (See \fIfrexp.3\fP) for coding. Upon success, \f5sfputu()\fP, \f5sfputl()\fP and \f5sfputd()\fP return the number of bytes output. .PP \f5sfputs(f,s,c)\fP writes the null-terminated string \f5s\fP to the stream \f5f\fP. If \f5c\fP is not 0, it is a character to be appended after the string has been output. \f5sfputs()\fP returns the number of bytes written. .PP \f5sfwrite(f,buf,n)\fP writes out \f5n\fP bytes from the buffer \f5buf\fP to the stream \f5f\fP. It returns the number of bytes written. .PP \f5sfmove(fr,fw,n,seps)\fP moves \f5n\fP objects from the stream \f5fr\fP to the stream \f5fw\fP. If either \f5fr\fP or \f5fw\fP is \f5NULL\fP, it acts as if it is a stream corresponding to \fI/dev/null\fP. If \f5n\fP is \f5<0\fP, all of \f5fr\fP is moved. If \f5seps\fP is \f5NULL\fP or an empty string, the objects to be moved are bytes. Otherwise, the moved objects are records separated by bytes defined in \f5seps\fP. In \f5seps\fP, if the first two bytes is \f5\e0\fP, it is mapped to the zero byte. All other cases map a byte to itself. \f5sfmove()\fP returns the number of objects moved. .PP \f5sfprintf(f,format,...)\fP writes out data in a format as defined by the string \f5format\fP. See \fIfprintf()\fP (UNIX User's Manual, Section 3) for details on predefined conversion formats. The standardly supported formats are: \f5n, s, c, %, h, i, d, p, u, o, x, X, g, G, e, E, f,\fP and \f5F\fP. \f5sfprintf()\fP also supports additional formats as described below. .IP The pattern \f5%&\fP indicates that the next argument is a function, say \f5(*extf)()\fP, to interpret patterns not yet defined by \f5sfprintf()\fP. The prototype of \f5(*extf)()\fP is: .nf \f5int (*extf)(void* value, int fmt, int precis, char** sp);\fP .fi \f5value\fP is the value to be formatted. \f5fmt\fP is the pattern to format the value. \f5precis\fP is the amount of precision required. \f5sp\fP is used to return the address of a string containing the formatted value. If upon returning from \f5(*extf)()\fP, \f5*sp\fP is \f5NULL\fP, the pattern \f5fmt\fP is treated as if it is not matched. Otherwise, the return value of \f5(*extf)()\fP, if nonnegative, is taken as the length of the string returned in \f5sp\fP. If not, the string is considered null-terminated. The string \f5*sp\fP is processed as if the pattern \f5`s'\fP was specified. .IP The pattern \f5%@\fP indicates that the next argument is a function, say \f5(*argf)()\fP, to get arguments. As long as \f5(*argf)()\fP is defined, the argument list is ignored. The prototype of \f5(*argf)()\fP is: .nf \f5int (*argf)(int fmt, char* val)\fP; .fi \f5fmt\fP is the pattern to be processed. Following are ASCII characters and corresponding types: \f5@\fP for getting a new \f5(*argf)()\fP, \f5&\fP for getting a new \f5(*extf)()\fP, \f51\fP for getting a new format string for stacking, \f52\fP for getting a new argument list for stacking, \f5d\fP for \fIint\fP, \f5D\fP for \fIlong\fP, \f5f\fP for \fIfloat\fP, \f5F\fP for \f5double\fP, and \f5s\fP for \fIchar*\fP. If \f5(*extf)()\fP is defined, and an undefined pattern is encountered, \f5(*argf)()\fP will be called with this pattern. \f5val\fP is an address to store the value to be formatted. The return value of \f5(*argf)()\fP, if negative, stops the processing of the current format (see below). .IP The pattern \f5%:\fP indicates that the next two arguments define a pair of format string and argument list of the type \f5va_list\fP. If the argument getting function \f5(*argf)()\fP is already defined, it is called with the argument \f5fmt\fP being the characters \f51\fP and \fP2\fP for the new format string and argument list respectively. The new pair is stacked on top and processing continue from there. The top pair of format string and argument is popped when the format string is exhausted. When a new pair is pushed, \f5(*argf)()\fP and \f5(*extf)()\fP are inherited. When a pair is popped, these functions will be reset. .PP \f5sfsprintf(s,size,format,...)\fP is similar to \f5sfprintf()\fP but it is used to format the character array \f5s\fP which is of size \f5size\fP. The length of the resulting string can be gotten via \f5sfslen()\fP. .PP \f5sfvprintf(f,format,args)\fP is the primitive underlying \f5sfprintf()\fP and \f5sfsprintf()\fP. It provides a portable variable argument interface. Programs that use \f5sfvprintf()\fP must include either of \f5varargs.h\fP or \f5stdargs.h\fP as appropriate. .PP \f5sfnotice(noticef)\fP sets a function \f5(*noticef)()\fP which will be called whenever a stream is created or closed. \f5(*noticef)()\fP is called with two arguments. The first argument is the stream pointer and the second argument is either \f50\fP or \f5SF_EOF\fP to indicate whether the stream is being opened or being closed. .PP \f5sfset(f,flags,i)\fP sets flags or file descriptor for the stream \f5f\fP. If \f5flags\fP is the value \f5SF_EOF\fP, the file descriptor of the stream is changed to the value in \f5i\fP. In this case, \f5sfset()\fP returns \f5-1\fP on error or \f5i\fP on success. If \f5flags\fP is not \f5SF_EOF\fP, it defines a collection of flags to be turned on or off depending on whether \f5i\fP is non-zero or zero. The flags that can be turned on or off are: \f5SF_READ\fP, \f5SF_WRITE\fP, \f5SF_LINE\fP, \f5SF_KEEPFD\fP, \f5SF_REUSE\fP, \f5SF_MALLOC\fP and \f5SF_SHARE\fP. The flags \f5SF_READ\fP and \f5SF_WRITE\fP can be used in a call to \f5sfset()\fP only if the stream \f5f\fP was opened for both read and write. Turning off one of these flags means that the stream is to be treated as if it was opened with the other flag exclusively (see \f5sfpeek()\fP). In this case, \f5sfset()\fP returns the entire set of flags controlling the stream. Thus, the current set of flags can be found by \f5sfset(f,0,0)\fP. .PP \f5sfsetbuf(f,buf,size)\fP changes the current buffer of the stream \f5f\fP to the new buffer \f5buf\fP. If the stream is a \f5SF_WRITE\fP stream, any data still in the current buffer is thrown away. Thus, if an application desires to preserve such data, it should call \f5sfsync()\fP before trying to switch buffers. If \f5size\fP is positive, \f5buf\fP is taken as a buffer of the given size. If \f5size\fP is zero, the stream will be unbuffered. If \f5size\fP is negative, an internal buffer is allocated. \f5sfsetbuf()\fP returns the address of the old buffer. .PP \f5sffileno(f)\fP returns the file descriptor of the stream \f5f\fP. .PP \f5sfeof(f)\fP tells whether there is any more data in the stream \f5f\fP. .PP \f5sforigin(f)\fP returns the origin location in the stream \f5f\fP (see \f5sfnew()\fP). If this location is \f5-1L\fP, the stream is not seekable. Note that the standard streams \f5sfstdin\fP, \f5sfstdout\fP, and \f5sfstderr\fP, though statically allocated, are not initialized until an operation that may affect its internal structure. Thus, the return value \f50L\fP of \f5sforigin()\fP on such an initialized stream is not reliable. .PP \f5sferror(f)\fP and \f5sfclearerr(f)\fP returns or clears the error condition of the stream \f5f\fP. Note that the error condition of a stream does not prevent further io operations to be performed on them. .PP \f5sfclrlock(f)\fP clears the lock on a locked stream. Though this is unsafe, it is useful for emergency access to a locked stream or to clear a stream left locked because of non-local jumps (e.g., \f5longjmp()\fP). .PP \f5sfslen()\fP returns the length of the string most recently obtained via a \f5sfgets()\fP, \f5sfsprintf()\fP, \f5sfecvt()\fP or \f5sffcvt()\fP call. .PP \f5sfulen(v)\fP, \f5sfllen(v)\fP and \f5sfdlen(v)\fP return the number of bytes required to code the \fIunsigned long\fP, \fIlong\fP or \fIdouble\fP value \f5v\fP. .PP \f5sfseek(f,addr,offset)\fP sets the next read/write location for the stream \f5f\fP at a new address defined by the combination of \f5addr\fP and \f5offset\fP. If \f5offset\fP is 0, \f5addr\fP is offset from the origin of the stream (see \f5sfnew()\fP). If \f5offset\fP is 1, \f5addr\fP is offset from the current location. Note that if \f5f\fP was opened for appending (\f5SF_APPEND\fP) and the last operation done on it was a write operation, the \fIcurrent location\fP is at the physical end of file. If \f5offset\fP is 2, \f5addr\fP is offset from the \fIphysical\fP end of the stream. In all cases, \f5sfseek()\fP is not allowed to seek backward beyond the stream origin. .PP \f5sftell(f)\fP returns the current location in the stream \f5f\fP relative to the stream origin (see \f5sfnew()\fP). As with \f5sfseek()\fP, if \f5f\fP was opened for appending (\f5SF_APPEND\fP) and the last operation done on it was a write operation, the \fIcurrent location\fP is at the physical end of file. If the stream \f5f\fP is unseekable, \f5sftell\fP returns the number of bytes read from or written to \f5f\fP. .PP \f5sfecvt(v,n,decpt,sign)\fP and \f5sffcvt(v,n,decpt,sign)\fP are functions to convert floating values to ASCII. They corresponds to the standard functions \f5ecvt()\fP and \f5fcvt()\fP. The length of the conversion string most recently done by \f5sfecvt()\fP or \f5sffcvt()\fP can be found by \f5sfslen()\fP. .PP .SH HISTORY AND FUTURE CONSIDERATIONS \fIsfio\fP has similar functionality, but is more general than the \fIstdio\fP package. It grows from our dissatisfaction with the awkwardness, fragility and inefficiency in \fIstdio\fP. An example of \fIstdio\fP awkwardness is that even if a stream was opened for read and write, the application code cannot arbitrarily mix read and write operations. An earlier attempt was made at rewriting \fIstdio\fP. This failed due to problems that arise when linking with code based on \fIstdio\fP. Changing the name space reduces this type of problems. It also allows us to both stream-line and extend the interface as appropriate. .SH AUTHORS Kiem-Phong Vo (att!ulysses!kpv) and David G. Korn (att!ulysses!dgk). 0707070000000001131006440044230044230000010000000472454671200002600000014455man/stak.3 Ugsf Ggsf .TH STAK 3 .SH NAME \fBstak\fR \- data stack storage library .SH SYNOPSIS .ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i .PP .nf \f5 #include <stak.h> Stak_t *stakcreate(int \fIflags\fP); Stak_t *stakinstall(Stak_t *\fIstack\fP, char *(\fIoverflow\fP)(int)); int stakdelete(Stak_t *\fIstack\fP); void staklink(Stak_t *\fIstack\fP) char *stakalloc(unsigned \fIsize\fP); char *stakcopy(const char *\fIstring\fP); char *stakset(char *\fIaddress\fP, unsigned \fIoffset\fP); char *stakseek(unsigned \fIoffset\fP); int stakputc(int \fIc\fP); int stakputs(const char *\fIstring\fP); int staktell(void); char *stakptr(unsigned \fIoffset\fP); char *stakfreeze(unsigned \fIextra\fP); \fR .fi .SH DESCRIPTION .PP \f5stak\fP is a package of routines designed to provide efficient stack oriented dynamic storage. A stack abstraction consists of an ordered list of contiguous memory regions, called stack frames, that can hold objects of arbitrary size. A stack is represented by the type \f5Stak_t\fP defined in header \f5<stak.h>\fP. At any instant there is one active stack. Variable size objects can be added to the active stack and programs can reference these objects directly with pointers. In addition, the last object on the stack (referred to here as the current object) can be built incrementally. The current object has an associated offset that determines its current size. While the current object is being built incrementally, its location might change so that it is necessary to reference the object with relative offsets ranging from zero to the current offset of the object. .PP There is a preset initial active stack. To use an additional stack, it is necessary to create it and to install it as the active stack. A stack is created with the \f5stakcreate\fP() function. A \fIflags\fP argument of \f5STAK_SMALL\fP indicates that unused space on the stack should be freed whenever this stack ceases to be the active stack. If successful, \f5stakcreate\fP() returns a pointer to a stack whose reference count is 1. Otherwise, \f5stakcreate\fP() returns a null pointer. The \f5staklink\fP() function increases the reference count for the given \fIstack\fP. The \f5stakinstall\fP() function makes the specified \fIstack\fP the active stack and returns a pointer to the previous active stack. When the \fIoverflow\fP argument is not null, it specifies a function that will be called whenever \f5malloc\fP(3) fails while trying to grow the stack. The \fIoverflow\fP function will be called with the size that was passed to \f5malloc\fP(3). The \fIoverflow\fP function can call \f5exit\fP(3), call \f5longjmp\fP(3) or return. If the \f5overflow\fP function returns, it must return a pointer to a memory region of the given size. The default action is to write an error to standard error and to call \f5exit\fP(2) with a non-zero exit value. When \fIstack\fP is a null pointer, the active stack is not changed but the \fIoverflow\fP function for the active stack can be changed and a pointer to the active stack is returned. The \f5stakdelete\fP() function decrements the reference count and frees the memory associated with the specified stack when the reference count is zero. The effect of subsequent references to objects on the stack are undefined. .PP The \f5stakalloc\fP() function returns an aligned pointer to space on the active stack that can be used to hold any object of the given \fIsize\fP. \f5stakalloc\fP() is similar to \f5malloc\fP(3) except that individual items returned by \f5stakalloc\fP() can not be freed. \f5stakalloc\fP() causes the offset of the current object to be set to zero. .PP The \f5stakcopy\fP() function copies the given string onto the stack and returns a pointer to the \fIstring\fP on the stack. \f5stakcopy\fP() causes the offset of the current object to be set to zero. .PP The \f5stakset\fP() function finds the frame containing the given \fIaddress\fP, frees all frames that were created after the one containing the given \fIaddress\fP, and sets the current object to the given \fIaddress\fP. The top of the current object is set to \fIoffset\fP bytes from current object. If \fIaddress\fP is not the address of an object on the stack the result is undefined. .PP The remaining functions are used to build the current object incrementally. An object that is built incrementally on the stack will always occupy contiguous memory within a stack frame but until \f5stakfreeze\fP() is called, the location in memory for the object can change. There is a current offset associated with the current object that determines where subsequent operations apply. Initially, this offset is zero, and the offset changes as a result of the operations you specify. The \f5stakseek\fP() function is used set the offset for the current object. The \fIoffset\fP argument to \f5stakseek\fP() specifies the new offset for the current object. The frame will be extended or moved if \f5offset\fP causes the new current offset to extend beyond the current frame. \f5stakseek\fP() returns a pointer to the beginning of the current object. The \f5staktell\fP() function gives the offset of the current object. .PP The \f5stakputc\fP() function adds a given character to the current object on the stack. The current offset is advanced by 1. The \f5stakputs\fP() appends the given \fIstring\fP onto the current object in the stack and returns the length of the string. The current offset is advanced by the length of the string. .PP The \f5stakptr\fP() function converts the given \f5offset\fP for the current object into a memory address on the stack. This address is only valid until another stack operation is given. The result is not defined if \fIoffset\fP exceeds the size of the current object. The \f5stakfreeze\fP() function terminates the current object on the stack and returns a pointer to the beginning of this object. If \fIextra\fP is non-zero, \fIextra\fP bytes are added to the stack before the current object is terminated. The first added byte will contain zero and the contents of the remaining bytes are undefined. .PP .SH HISTORY The \f5stak\fP interface was derived from similar routines in the KornShell code that is used for building parse trees and carrying out expansions. It provides an efficient mechanism for grouping dynamically allocated objects so that they can be freed all at once rather than individually. .SH AUTHOR David Korn .SH SEE ALSO \f5exit(2)\fP \f5longjmp(3)\fP \f5malloc(3)\fP 0707070000000001141006440044230044230000010000000456336256100002400000021334man/tm.3 Ugsf Ggsf .de L \" literal font .ft 5 .it 1 }N .if !\\$1 \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 .. .de LR .}S 5 1 \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" .. .de RL .}S 1 5 \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" .. .de EX \" start example .ta 1i 2i 3i 4i 5i 6i .PP .RS .PD 0 .ft 5 .nf .. .de EE \" end example .fi .ft .PD .RE .PP .. .TH TM 3 .SH NAME tm \- time conversion support .SH SYNOPSIS .L "#include <tm.h>" .SH DESCRIPTION The .I tm library supports conversion between string date specifications, .L time_t clock values and .L "struct tm" values. .L localtime() and .L gmtime() (see .IR ctime (3)) are used to determine local time zone information. .PP .L time_t values are the number of seconds since the epoch, .BR "Jan 1 00:00:00 GMT 1970" , with leap seconds omitted. .PP The global variable .L "int tm_info.flags" contains flags that allow all programs using the library to be controlled in a consistent manner. .L tm_info.flags is initialized by the .L tminit() routine described below, and may be explicitly reset after .L tminit() is called. The flags are: .TP .L TM_ADJUST Set by .L tminit() if .L localtime() and .L gmtime() do not compensate for leap seconds. .TP .L TM_LEAP .L time_t values are interpreted as if they include leap seconds. Set by .L tminit() if the .L leap option is set in the .L TM_OPTIONS environment variable. .TP .L TM_UTC Times are relative to .B UTC (universal coordinated time, i.e., .BR GMT ). Otherwise times are relative to the local time zone. Set by .L tminit() if the time zone name matches one of .L tm_info.format[43] through .L tm_info.format[46] described below. If the time zone name is not determined by .L localtime() then the environment variables .L TZNAME (as described in BSD 4.3) and .L TZ (as described in System V) are checked, in order. If this fails then the time zone name is constructed using the local time zone offset. .PP The routines are: .TP .L "time_t tmdate(char* date, char** end, time_t* clock)" Parses the date specification .L date using the .L tm_info.format string table (described below) and returns the equivalent .L time_t value. If .RL non- NULL , .L end is set to the position of the first unrecognized character in .LR date . .L clock is used to provide default values for omitted components in .LR date . If .L clock is .L NULL then the current time is used. .TP .L "struct tm* tmfix(struct tm* tp)" Corrects any out of bounds fields in .L tp and returns .L tp as its value. The corrections start with .L tp->tm_sec and propagate down to .LR tp->tm_year . For example, if .L tp->tm_sec were 61 then it would change to 1 and .L tp->tm_min would be incremented by 1, and so on. .LR tp->tm_wday , .LR tp->tm_yday and .L tp->tm_isdst are not changed as these can be computed from the other fields. .TP .L "char* tmform(char* buf, char* format, time_t* clock)" Formats the date pointed to by .L clock into the buffer .L buf according to the format specification .LR format . If .L format is .L NULL or empty then the string .L tm_info.format[40] is used. If .L clock is .L NULL then the current time is used. A pointer to the end of .L buf (i.e., the terminating .LR "'\e0'" ) is returned. .RS .PP .L format is in the style of .IR printf (3), where .BI % field causes the corresponding fixed size field to be placed in .LR buf , zero padded if necessary, and \e\fIc\fP and \e\fInnn\fP sequences are interpreted as in the C language. Otherwise invalid .BI % field specifications and all other characters in .L format are copied into .L buf without change. String field values are taken from the .L tm_info.format string table. The .I fields are: .TP .PD 0 .B % .B % character. .TP .B a Abbreviated weekday name. .TP .B A Full weekday name. .TP .B b Abbreviated month name. .TP .B c .IR ctime (3) style date without the trailing .BR newline . .TP .B C .IR date (1) style date. .TP .B d Day of month number. .TP .B D Date as .IR mm / dd / yy . .TP .B e Blank padded day of month number. .TP .B E Unpadded day of month number. .TP .B h Abbreviated month name. .TP .B H 24-hour clock hour. .TP .B i International .IR date (1) date that includes the time zone type name. .TP .B I 12-hour clock hour. .TP .B j 1-offset Julian date. .TP .B J 0-offset Julian date. .TP .B l .IR ls (1) .B \-l date that lists recent dates with .IR hh : mm and distant dates with .IR yyyy . .TP .B m Month number. .TP .B M Minutes. .TP .B n .B newline character. .TP .B p Meridian (e.g., .B AM or .BR PM ). .TP .B r 12-hour time as .IR hh : mm : ss .IR meridian . .TP .B R 24-hour time as .IR hh : mm . .TP .B S Seconds. .TP .B t .B tab character. .TP .B T 24-hour time as .IR hh : mm : ss . .TP .B U Week number with Sunday as the first day. .TP .B w Weekday number. .TP .B W Week number with Monday as the first day. .TP .B x Local date style, using .LR tm_info.format[39] , that includes the month, day and year. .TP .B X Local time style, using .LR tm_info.format[38] , that includes the hours and minutes. .TP .B y 2-digit year. .TP .B Y 4-digit year. .TP .B z Time zone type name. .TP .B Z Time zone name. .TP .BI + flag .TP .BI \- flag Temporarily (until .L tmform() returns) sets (+) or clears (\-) the .L tm_info.flags flags specified by .IR flag : .RS .TP .B l .L TM_LEAP .TP .B u .L TM_UTC .RE .TP .B # Number of seconds since the epoch. .PD .RE .TP .L "void tminit()" Implicitly called by the other .I tm library routines to initialize global data, including the .L tm_info.format table and the .L tm_info.flags global flags. Global data should only be modified after an explicit call to .LR tminit() . .TP .L "time_t tmleap(time_t* clock)" Returns a .L time_t value for the time pointed to by .L clock with leap seconds adjusted for external routines that do not handle leap seconds. If .L clock is .L NULL then the current time is used. Adjustments are only done if the .L TM_ADJUST flag is set in .LR tm_info.flags . .TP .L "struct tm* tmmake(time_t* clock)" Returns a pointer to the .L tm struct corresponding to the time pointed to by .LR clock . If .L clock is .L NULL then the current time is used. .TP .L "time_t tmtime(struct tm* tp, int west)" Returns the .L time_t value corresponding to .LR tp . If .L west is .L TM_LOCALZONE then .L tm is relative to the local time zone, otherwise .L west is the number of minutes west of .B UTC with daylight savings time taken into account. .LR tp->tm_wday , .LR tp->tm_yday and .L tp->tm_isdst are ignored in the conversion. .PP The library routines use a table of date strings pointed to by .LR "char** tm_info.format" . The indices in .L tm_info.format are fixed by category. .L tm_info.format may be changed to point to other tables according to local language and date conventions. The contents by index (showing the USA English values) are: .RS .TP .PD 0 .B 0-11 3-character abbreviated month names. .TP .B 12-23 Full month names. .TP .B 24-30 3-character abbreviated weekday names. .TP .B 31-37 Full weekday names. .TP .B 38 .L tmform() local time format used by the .B %X field. .TP .B 39 .L tmform() local date format used by the .B %x field. .TP .B 40 .L tmform() format used if the .L format argument is .L NULL or empty. .TP .B 41-42 Meridian names: AM, PM. .TP .B 43-46 .B UTC time zone names: GMT, UTC, UCT, CUT. .TP .B 47-50 Daylight savings time suffix names: DST. .TP .B 51-54 Suffixes to be ignored when matching strings in .LR tmform() . .TP .B 55-61 Time part names: second, hour, minute, day, week, month, year. .TP .B 62-65 Hours of the day names: midnight, morning, noon, evening. .TP .B 66-68 Relative day names: yesterday, today, tomorrow. .TP .B 69-71 Past relative time references: last, ago, past. .TP .B 72-75 Current relative time references: this, now, current. .TP .B 75-77 Future relative time references: next, hence, coming. .TP .B 78-80 Exact relative time references: exactly. .TP .B 81-85 Noise words to be ignored: at, in, on. .PD .RE .PP Low level support functions and data are described in .LR <tm.h> . .SH EXAMPLES .EX #include <tm.h> main() { int i; time_t t; char buf[128]; struct { char* date; char* format; } x[] = { "now", "%i", "2 months ago", "%C", "this Wednesday noon", "%x %I:%M %p", "last December 25", "%A", 0, 0 }; for (i = 0; x[i].date; i++) { t = tmdate(x[i].date, (char*)0, (time_t*)0); (void)tmform(buf, x[i].format, &t); puts(buf); } } .EE produces .EX Fri Sep 30 12:10:14 USA EDT 1988 Fri Jul 1 00:00:00 EDT 1988 10/05/88 12:00 PM Friday .EE .SH "SEE ALSO" date(1), time(2), ctime(3) .SH BUGS .L "struct tm" values may get clobbered by the .I tm library routines as the .IR ctime (3) routines typically return pointers to a single static .L "struct tm" area. .L tmdate() uses an internal international time zone name table that will probably always be incomplete. 0707070000000001151006440044230044230000010000000461362623700003100000001006misc/calloc.c Ugsf Ggsf /* * since libx provides malloc(), these must be included * to avoid multiple link definitions for some shared * library implementations */ #include "FEATURE/bzero" #ifdef _lib_bzero #define memzero(p,n) bzero(p,n) #else #define memzero(p,n) memset(p,0,n) #endif extern char* malloc(); char* calloc(count, size) register unsigned int count; register unsigned int size; { register char* ptr; if (ptr = malloc(size *= count)) memzero(ptr, size); return(ptr); } void cfree(old) char* old; { free(old); } 0707070000000001161006440044230044230000010000000472745070400003200000002634misc/cmdargs.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * multi-pass commmand line option parse assist * * int fun(char** argv, int last) * * each fun() argument parses as much of argv as * possible starting at (opt_index,opt_char) using * optget() * * if last!=0 then fun is the last pass to view * the current arg, otherwise fun sets opt_again=1 * and another pass will get a crack at it * * 0 fun() return causes immediate cmdargs() 0 return * * cmdargs() returns non-zero if more args remain * to be parsed at opt_index */ #include <option.h> typedef int (*PFI)(); int opt_again; /* repeat last position in next optget */ #if __STDC__ #include <stdarg.h> int cmdargs(char** argv, ...) #else #include <varargs.h> int cmdargs(va_alist) va_dcl #endif { va_list ap; register PFI fun; register PFI rep; int last_index; int last_char; #if !__STDC__ register char **argv; #endif rep = 0; for (;;) { #if __STDC__ va_start(ap, argv); #else va_start(ap); argv = va_arg(ap, char**); #endif while (fun = va_arg(ap, PFI)) { last_index = opt_index; last_char = opt_char; if (!(*fun)(argv, fun == rep) || !argv[opt_index]) return(argv[opt_index] != 0); if (opt_again) { opt_again = 0; opt_index = opt_pindex; opt_char = opt_pchar; } if (!rep || opt_index != last_index || opt_char != last_char) rep = fun; else if (fun == rep) return(1); } va_end(ap); } } 0707070000000001171006440044230044230000010000000460673177200003300000000762misc/cmdclose.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * close a stream opened by cmdopen() * -1 returned if cmdopen() had a problem * otherwise exit() status of command is returned */ #include "cmdlib.h" int cmdclose(fd) register int fd; { register struct cmdinfo* cmd; for (cmd = cmds; cmd; cmd = cmd->next) if (cmd->fd == fd) { (void)close(fd); cmd->fd = -2; if (cmd->pid < 0) { cmd->pid = 0; return(cmd->status); } return(cmdwait(-cmd->pid)); } return(-1); } 0707070000000001201006440044230044230000010000000460673177600003200000000543misc/cmdkill.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * send sig to cmd opened by cmdopen() */ #include "cmdlib.h" int cmdkill(fd, sig) register int fd; int sig; { register struct cmdinfo* cmd; for (cmd = cmds; cmd; cmd = cmd->next) if (cmd->fd == fd) { if (cmd->pid > 0) return(kill(cmd->pid, sig)); break; } errno = ESRCH; return(-1); } 0707070000000001211006440044230044230000010000000470065653000003100000001754misc/cmdlib.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * cmd library definitions */ #include <limits.h> #include <stdio.h> #include <errno.h> #define EXITBITS 8 /* # exit status bits */ #define EXITMAX ((1<<EXITBITS)-1) /* max exit status */ #define EXITED(x) (!((x)&EXITMAX)) #define EXITSTATUS(x) (((x)>>EXITBITS)&EXITMAX) #define TERMINATED(x) (((x)&EXITMAX)!=0) #define TERMSTATUS(x) (((x)&EXITMAX)|(1<<EXITBITS)) #define TERMSIGNAL(x) ((x)&(EXITMAX>>1)) #define TERMCORE(x) ((x)&(1<<(EXITBITS-1))) #ifndef PATH_MAX #define PATH_MAX 1024 #endif struct cmdinfo /* info for each cmd */ { struct cmdinfo* next; /* next in list */ int pid; /* cmd pid, 0 if free */ short fd; /* cmdopen() connection if >= 0 */ short status; /* wait() exit status if pid < 0 */ }; #define cmds _cmd_info_ /* hide external symbol */ extern struct cmdinfo* cmds; /* cmd list */ extern int errno; extern int cmdwait(); extern long lseek(); extern char* malloc(); extern void sigcritical(); 0707070000000001221006440044230044230000010000000473420241300003200000010211misc/cmdopen.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * common command execution support with * proper stdio and wait() syncronization * * _ contains the command path name and is * placed at the top of the environment */ #include "cmdlib.h" static void redirect(); extern char* getenv(); extern char* getshell(); extern char* pathpath(); extern char* putenv(); extern char* strcpy(); /* * fork and exec cmd(argv) according to mode combinations: * * a argv[-1] and argv[0] can be modified * e clear environment * g run with real gid * p paranoid * r cmd stdout pipe fd returned * w cmd stdin pipe fd returned * u run with real uid * * pipe not used when r and w are omitted (no io on return fd) * cmd==0 names the current shell * envv is the child environment * redv is the child redirection vector * even elements duped from the next element * -1 even terminates the list * -1 odd element means close */ int cmdopen(cmd, argv, envv, redv, mode) char* cmd; char** argv; char** envv; int* redv; char* mode; { register struct cmdinfo* proc; register int cmdfd = -1; register char** p; char** v; int* r; int argmod = 0; int envclear = 0; int paranoid = 0; int realgid = 0; int realuid = 0; long pos; char path[PATH_MAX]; char env[PATH_MAX + 2]; int pio[2]; extern char** environ; if (cmd && !pathpath(path, cmd, (char*)0, 011)) return(-1); if (mode) while (*mode) switch (*mode++) { case 'a': argmod = 1; break; case 'e': envclear = 1; break; case 'g': realgid = 1; break; case 'p': paranoid = 1; break; case 'r': cmdfd = 1; break; case 'u': realuid = 1; break; case 'w': cmdfd = 0; break; default: return(-1); } for (proc = cmds; proc; proc = proc->next) if (!proc->pid) break; if (!proc) { if (!(proc = (struct cmdinfo*)malloc(sizeof(struct cmdinfo)))) return(-1); proc->pid = 0; proc->next = cmds; cmds = proc; } if (!putenv((char*)0)) return(-1); if (cmdfd >= 0 && pipe(pio)) return(-1); fflush(stdout); fflush(stderr); sigcritical(1); proc->pid = fork(); sigcritical(0); switch (proc->pid) { case -1: proc->pid = 0; if (cmdfd >= 0) { (void)close(pio[0]); (void)close(pio[1]); } return(-1); case 0: if (paranoid || realgid) (void)setgid(getgid()); if (paranoid || realuid) (void)setuid(getuid()); if ((pos = ftell(stdin)) != lseek(fileno(stdin), 0L, 1)) (void)lseek(fileno(stdin), pos, 0); if (cmdfd >= 0) { redirect(pio[cmdfd], cmdfd); (void)close(pio[!cmdfd]); } if (r = redv) while (*r >= 0) { redirect(*(r + 1), *r); r += 2; } if (envclear) environ = 0; env[0] = '_'; env[1] = '='; if (!putenv(env)) _exit(EXITMAX); if (paranoid && !putenv("PATH=:/bin:/usr/bin")) _exit(EXITMAX); if (p = envv) while (*p) if (!putenv(*p++)) _exit(EXITMAX); #if 0 if ((mode = getenv("EXEC_OPTIONS")) && (*mode == 'n' || *mode == 'v')) { if (*(mode + 1) == 'e' && (p = environ)) while (*p) fprintf(stderr, "%s\n", *p++); fprintf(stderr, "+ %s", cmd ? path : "sh"); if ((p = argv) && *p) while (*++p) fprintf(stderr, " %s", *p); fprintf(stderr, "\n"); if (*mode == 'n') _exit(0); } #endif p = argv; if (cmd) { (void)strcpy(env + 2, path); execv(path, p); if (errno != ENOEXEC) _exit(EXITMAX); /* * try cmd as a shell script */ if (!argmod) { while (*p++); if (!(v = (char**)malloc((p - argv + 2) * sizeof(char**)))) _exit(EXITMAX); p = v + 2; if (*argv) argv++; while (*p++ = *argv++); p = v + 1; } *p = path; *--p = "sh"; } if (!paranoid) { (void)strcpy(env + 2, getshell()); execv(env + 2, p); } (void)strcpy(env + 2, "/bin/sh"); execv(env + 2, p); _exit(EXITMAX); /*NOTREACHED*/ default: if (cmdfd >= 0) { (void)close(pio[cmdfd]); proc->fd = pio[!cmdfd]; } else if ((proc->fd = dup(0)) < 0) (void)cmdclose(proc->fd); return(proc->fd); } } /* * redirect nfd to fd * nfd==-1 means close(fd) */ static void redirect(nfd, fd) int nfd; int fd; { if (nfd != fd) { if (nfd >= 0) { if (dup2(nfd, fd) != fd) _exit(EXITMAX); (void)close(nfd); } else (void)close(fd); } } 0707070000000001231006440044230044230000010000000447753442300003100000000444misc/cmdrun.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * cmdopen() + cmdclose() * no env mods * no redirection * effective=real */ extern int cmdopen(); extern int cmdclose(); int cmdrun(cmd, argv) char* cmd; char** argv; { return(cmdclose(cmdopen(cmd, argv, (char**)0, (int**)0, "gu"))); } 0707070000000001241006440044230044230000010000000470065435500003200000002636misc/cmdwait.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * wait for cmd pid and return exit status * if pid < 0 then table not searched for -pid * -1 returned on pid error */ #include "cmdlib.h" struct cmdinfo* cmds; /* open cmd list */ int cmdwait(pid) register int pid; { register struct cmdinfo* cmd; register int n; struct cmdinfo* slot; int status; int oerrno; long pos; if (pid > 0) { pid = -pid; for (cmd = cmds; cmd; cmd = cmd->next) if (cmd->pid == pid) { cmd->pid = 0; return(cmd->status); } } pid = -pid; oerrno = errno; sigcritical(1); for (;;) { if ((n = wait(&status)) == -1) { oerrno = ESRCH; status = -1; break; } if (EXITED(status)) { status = EXITSTATUS(status); if (status == EXITMAX) status = -1; } else status = TERMSTATUS(status); for (slot = 0, cmd = cmds; cmd; cmd = cmd->next) { if (cmd->pid == n) { if (pid == n) cmd->pid = 0; else { cmd->pid = -n; cmd->status = status; } break; } else if (!slot && !cmd->pid) slot = cmd; } if (pid == n) break; if (!cmd && ((cmd = slot) || (cmd = (struct cmdinfo*)malloc(sizeof(struct cmdinfo))))) { cmd->fd = -2; cmd->pid = -n; cmd->status = status; cmd->next = cmds; cmds = cmd; } } if ((pos = lseek(fileno(stdin), 0L, 1)) != ftell(stdin)) (void)fseek(stdin, pos, 0); sigcritical(0); errno = oerrno; return(status); } 0707070000000001251006440044230044230000010000000405511146200003200000005013misc/cvtatoe.c Ugsf Ggsf /**************************************************************** * * * Copyright (c) 1987 AT&T * * All Rights Reserved * * * * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF * * AT&T * * * * The copyright notice above does not evidence any * * actual or intended publication of such source code * * * ****************************************************************/ /* * this is an ASCII to EBCDIC conversion table * from a proposed BTL standard April 16, 1979 */ static unsigned char atoe[] = { 0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017, 0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037, 0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141, 0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157, 0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326, 0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0232,0155, 0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226, 0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0137,0007, 0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033, 0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0341, 0101,0102,0103,0104,0105,0106,0107,0110, 0111,0121,0122,0123,0124,0125,0126,0127, 0130,0131,0142,0143,0144,0145,0146,0147, 0150,0151,0160,0161,0162,0163,0164,0165, 0166,0167,0170,0200,0212,0213,0214,0215, 0216,0217,0220,0152,0233,0234,0235,0236, 0237,0240,0252,0253,0254,0112,0256,0257, 0260,0261,0262,0263,0264,0265,0266,0267, 0270,0271,0272,0273,0274,0241,0276,0277, 0312,0313,0314,0315,0316,0317,0332,0333, 0334,0335,0336,0337,0352,0353,0354,0355, 0356,0357,0372,0373,0374,0375,0376,0377, }; /* * convert n bytes of ip from ASCII to EBCDIC in op */ void cvtatoe(ip, op, n) register unsigned char *ip; register unsigned char *op; register int n; { while (n-- > 0) *op++ = atoe[*ip++]; } 0707070000000001261006440044230044230000010000000405511165100003200000005013misc/cvtetoa.c Ugsf Ggsf /**************************************************************** * * * Copyright (c) 1987 AT&T * * All Rights Reserved * * * * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF * * AT&T * * * * The copyright notice above does not evidence any * * actual or intended publication of such source code * * * ****************************************************************/ /* * this is an EBCDIC to ASCII conversion table * from a proposed BTL standard April 16, 1979 */ static unsigned char etoa[] = { 0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017, 0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037, 0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007, 0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032, 0040,0240,0241,0242,0243,0244,0245,0246, 0247,0250,0325,0056,0074,0050,0053,0174, 0046,0251,0252,0253,0254,0255,0256,0257, 0260,0261,0041,0044,0052,0051,0073,0176, 0055,0057,0262,0263,0264,0265,0266,0267, 0270,0271,0313,0054,0045,0137,0076,0077, 0272,0273,0274,0275,0276,0277,0300,0301, 0302,0140,0072,0043,0100,0047,0075,0042, 0303,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0304,0305,0306,0307,0310,0311, 0312,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0136,0314,0315,0316,0317,0320, 0321,0345,0163,0164,0165,0166,0167,0170, 0171,0172,0322,0323,0324,0133,0326,0327, 0330,0331,0332,0333,0334,0335,0336,0337, 0340,0341,0342,0343,0344,0135,0346,0347, 0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0350,0351,0352,0353,0354,0355, 0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0356,0357,0360,0361,0362,0363, 0134,0237,0123,0124,0125,0126,0127,0130, 0131,0132,0364,0365,0366,0367,0370,0371, 0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0372,0373,0374,0375,0376,0377, }; /* * convert n bytes of ip from EBCDIC to ASCII in op */ void cvtetoa(ip, op, n) register unsigned char *ip; register unsigned char *op; register int n; { while (n-- > 0) *op++ = etoa[*ip++]; } 0707070000000001271006440044230044230000010000000475453725700003000000021420misc/error.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * error and message formatter * * level is the error level * level >= ERROR_FATAL calls err_exit * level < 0 is for debug tracing * err_write must accept write(2) args */ #include <ctype.h> #include <error.h> #include <namval.h> #include <sig.h> #include <sfio.h> #if !__STDC__ #include <varargs.h> #endif typedef int (*PFI)(); extern int exit(); extern int write(); extern char* strerror(); static PFI err_aux; /* call just before return */ static PFI err_exit = exit; /* error exit routine */ static PFI err_write = write; /* error output routine */ static int err_clear; /* clear error() flags */ static int err_core; /* level>=err_core -> core dump */ static int err_fd = 2; /* write(2) fd */ static int err_errno; /* last reported errno */ static int err_init; /* initialized */ static int err_set; /* set error() flags */ static char* err_id; /* command id */ static char* err_version; /* ERROR_SOURCE command version */ static int* ptr_errors; /* >= ERROR_ERROR count */ static int* ptr_indent; /* debug trace indent level */ static int* ptr_line; /* input|output line number */ static int* ptr_mask; /* multi level debug trace mask */ static int* ptr_trace; /* debug trace level */ static int* ptr_warnings; /* ERROR_WARNING count */ static char** ptr_id; /* command id */ static char** ptr_file; /* input|output file name */ #define OPT_CORE 1 #define OPT_FD 2 #define OPT_LIBRARY 3 #define OPT_MASK 4 #define OPT_SYSTEM 5 #define OPT_TRACE 6 static struct namval options[] = /* environment option names */ { "core", OPT_CORE, "fd", OPT_FD, "library", OPT_LIBRARY, "mask", OPT_MASK, "system", OPT_SYSTEM, "trace", OPT_TRACE, 0, 0 }; /* * called by stropt() to set options */ /*ARGSUSED*/ static int setopt(a, p, n, v) char* a; register struct namval* p; register int n; register char* v; { static int mask; static int trace; extern long strtol(); switch (p->value) { case OPT_CORE: if (n) switch (*v) { case 'e': case 'E': err_core = ERROR_ERROR; break; case 'f': case 'F': err_core = ERROR_FATAL; break; case 'p': case 'P': err_core = ERROR_PANIC; break; default: err_core = strtol(v, (char*)0, 0); break; } else err_core = 0; break; case OPT_FD: err_fd = n ? strtol(v, (char*)0, 0) : -1; break; case OPT_LIBRARY: if (n) err_set |= ERROR_LIBRARY; else err_clear |= ERROR_LIBRARY; break; case OPT_MASK: if (n) mask = strtol(v, (char*)0, 0); else mask = 0; ptr_mask = &mask; break; case OPT_SYSTEM: if (n) err_set |= ERROR_SYSTEM; else err_clear |= ERROR_SYSTEM; break; case OPT_TRACE: if (n) trace = -strtol(v, (char*)0, 0); else trace = 0; ptr_trace = &trace; break; } return(0); } /* * initialize default environment */ static void init() { extern char* getenv(); err_init = 1; (void)stropt(getenv("ERROR_OPTIONS"), options, setopt, (char*)0); } /* * print a name, converting unprintable chars */ static void print(sp, name, delim) register SFIO* sp; register char* name; char* delim; { register int c; while (c = *name++) { if (c & 0200) { c &= 0177; sfputc(sp, '?'); } if (c < ' ') { c += 'A' - 1; sfputc(sp, '^'); } sfputc(sp, c); } sfputs(sp, delim, 0); } /* * functional interface to the error message state * * upper case options are for static values * other options are for pointers to dynamic values * previous value for rightmost option is returned * 0 returned on first unknown option */ #if __STDC__ char* seterror(int op, ...) #else char* seterror(va_alist) va_dcl #endif { va_list ap; char* prev; #if !__STDC__ int op; #endif prev = 0; #if __STDC__ va_start(ap, op); #else va_start(ap); op = va_arg(ap, int); #endif if (!op || !err_init) init(); for (;;) { switch (op) { case 'A': prev = (char*)err_aux; err_aux = va_arg(ap, PFI); break; case 'C': case 'I': prev = (char*)err_id; err_id = va_arg(ap, char*); break; case 'E': prev = (char*)err_exit; err_exit = va_arg(ap, PFI); break; case 'V': prev = (char*)err_version; err_version = va_arg(ap, char*); break; case 'W': prev = (char*)err_write; err_write = va_arg(ap, PFI); break; case 'c': prev = (char*)ptr_id; ptr_id = va_arg(ap, char**); break; case 'f': prev = (char*)ptr_file; ptr_file = va_arg(ap, char**); break; case 'i': prev = (char*)ptr_indent; ptr_indent = va_arg(ap, int*); break; case 'l': prev = (char*)ptr_line; ptr_line = va_arg(ap, int*); break; case 'm': prev = (char*)ptr_mask; ptr_mask = va_arg(ap, int*); if (prev && ptr_mask) *ptr_mask = *((int*)prev); break; case 't': prev = (char*)ptr_trace; ptr_trace = va_arg(ap, int*); if (prev && ptr_trace) *ptr_trace = *((int*)prev); break; case '1': prev = (char*)ptr_warnings; ptr_warnings = va_arg(ap, int*); if (prev && ptr_warnings) *ptr_warnings += *((int*)prev); break; case '2': prev = (char*)ptr_errors; ptr_errors = va_arg(ap, int*); if (prev && ptr_errors) *ptr_errors += *((int*)prev); break; case '+': prev = (char*)err_set; err_set = va_arg(ap, int); break; case '-': prev = (char*)err_clear; err_clear = va_arg(ap, int); break; default: prev = 0; /*FALLTHROUGH*/ case 0: va_end(ap); return(prev); } op = va_arg(ap, int); } } #if __STDC__ void error(int level, ...) #else void error(va_alist) va_dcl #endif { va_list ap; #if !__STDC__ int level; #endif #if __STDC__ va_start(ap, level); #else va_start(ap); level = va_arg(ap, int); #endif verror((char*)0, level, ap); va_end(ap); } #if __STDC__ || __cplusplus void verror(const char* lib, int level, va_list ap) #else void verror(lib, level, ap) char* lib; int level; va_list ap; #endif { register SFIO* sp; register int n; int fd; int flags; char* s; char* format; int indent; int line; int trace; char* file; static int state; if (!err_init) init(); if (level > 0) { flags = level & ~ERROR_LEVEL; level &= ERROR_LEVEL; } else flags = 0; trace = ptr_trace ? *ptr_trace : 0; if (level < trace || lib && (err_clear & ERROR_LIBRARY) || level < 0 && ptr_mask && !((*ptr_mask) & (1<<(-level - 1)))) { if (level >= ERROR_FATAL) (*err_exit)(level - 1); return; } if (trace < 0) flags |= ERROR_LIBRARY|ERROR_SYSTEM; flags |= err_set; flags &= ~err_clear; if (!lib) flags &= ~ERROR_LIBRARY; if (sp = sftmp(SF_UNBOUND)) { file = ptr_id ? *ptr_id : err_id; if (flags & ERROR_USAGE) { if (state & ERROR_USAGE) (void)sfprintf(sp, " "); else { state |= ERROR_USAGE; (void)sfprintf(sp, "Usage: "); } if (file || opt_argv && (file = opt_argv[0])) print(sp, file, " "); } else { state &= ~ERROR_USAGE; if (level && !(flags & ERROR_NOID)) { if (file) print(sp, file, (flags & ERROR_LIBRARY) ? " " : ": "); if (flags & ERROR_LIBRARY) (void)sfprintf(sp, "[%s library]: ", lib); } } line = ptr_line ? *ptr_line : 0; file = ptr_file ? *ptr_file : 0; if (level > 0 && line > 0) { if (file && *file) (void)sfprintf(sp, "\"%s\", ", file); (void)sfprintf(sp, "line %d: ", line); } switch (level) { case 0: break; case ERROR_WARNING: if (ptr_warnings) (*ptr_warnings)++; (void)sfprintf(sp, "warning: "); break; case ERROR_PANIC: if (ptr_errors) (*ptr_errors)++; (void)sfprintf(sp, "panic: "); break; default: if (level < 0) { if (trace < -1) (void)sfprintf(sp, "debug%d:%s", level, level > -10 ? " " : ""); else (void)sfprintf(sp, "debug: "); indent = ptr_indent ? *ptr_indent : 0; for (n = 0; n < indent; n++) { sfputc(sp, ' '); sfputc(sp, ' '); } } else if (ptr_errors) (*ptr_errors)++; break; } fd = (flags & ERROR_OUTPUT) ? va_arg(ap, int) : err_fd; if (flags & ERROR_SOURCE) { /* * source ([version], file, line) message */ file = va_arg(ap, char*); line = va_arg(ap, int); if (err_version) (void)sfprintf(sp, "(%s: %s, line %d) ", err_version, file, line); else (void)sfprintf(sp, "(%s, line %d) ", file, line); } format = va_arg(ap, char*); (void)sfvprintf(sp, format, ap); if (!(flags & ERROR_PROMPT)) { if ((flags & ERROR_SYSTEM) && errno && errno != err_errno) { (void)sfprintf(sp, " [%s]", strerror(errno)); if (err_set & ERROR_SYSTEM) errno = 0; err_errno = (level >= 0) ? 0 : errno; } sfputc(sp, '\n'); } (void)sfseek(sp, 0L, 0); n = sfpeek(sp, (unsigned char**)&s); if (err_write) (void)(*err_write)(fd, s, n); if (err_aux) (void)(*err_aux)(lib, flags, level, s, n); (void)sfclose(sp); } if (level >= err_core && err_core) { (void)signal(SIGQUIT, SIG_DFL); (void)kill(getpid(), SIGQUIT); (void)pause(); } if (level >= ERROR_FATAL) (void)(*err_exit)(level - ERROR_FATAL + 1); } 0707070000000001301006440044230044230000010000000440004232200003300000002414misc/fgetline.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories */ #include <stdio.h> #define LINECHUNK 256 /* line resize increment */ static char* buf; /* current line buffer */ static int siz; /* current buf size */ extern char* malloc(); extern char* realloc(); /* * return next line from fp * if new!=0 then the old buffer space is not reclaimed and * the new buffer space is returned with size strlen(line)+new * otherwise an internal buffer is used for each call * * newline is replaced by 0 * * 0 returned if first char is EOF * otherwise EOF is treated as a newline */ char* fgetline(fp, new) register FILE* fp; int new; { register int c; register char* s; register char* end; if ((!buf || new) && !(buf = malloc(siz = LINECHUNK))) return(0); s = buf; end = s + siz; for (;;) { if (s >= end) { if (!(buf = realloc(buf, siz += LINECHUNK))) return(0); s = buf + siz - LINECHUNK; end = buf + siz; } switch (c = getc(fp)) { case EOF: if (s == buf) { if (new) { free(buf); buf = 0; } return(0); } /*FALLTHROUGH*/ case '\n': *s = 0; return(new ? realloc(buf, siz = buf - s + new) : buf); } *s++ = c; } } /* * free fgetline() buffer */ void ffreeline() { if (buf) { free(buf); buf = 0; } } 0707070000000001311006440044230044230000010000000475137331600002700000000764misc/fs3d.c Ugsf Ggsf /* * AT&T Bell Laboratories * * disable (0) / enable (1) / tell (2) 3d fs operations * the argument must be 0, 2 or a previous fs3d() return value * the return value is the previous state */ #define OP3D 010000 #define ON3D 001000 extern int umask(); int fs3d(n) register int n; { register int o; o = umask(0) | OP3D; switch (n) { case 0: (void)umask(o & ~ON3D); break; case 1: (void)umask(o | ON3D); break; default: (void)umask(o); break; } return((o & ON3D) != 0); } 0707070000000001321006440044230044230000010000000475447470200003100000041407misc/ftwalk.c Ugsf Ggsf /* ** int ftwalk(char *path, int (*userf)(), int flags, int (*comparf)()); ** ** Function to walk a file system graph in a depth-first search. ** Arguments of ftwalk() are: ** ** path: path name(s) of the root(s) of the graph to be search. ** ** userf: a function to be called at each node that is visited. ** Called as: int userf(struct FTW* ftw) ** ftw: a structure containing info about current node. ** See ftwalk.h for info on its fields. ** If func returns non-zero, ftwalk() terminates and returns this ** value to its caller. ** ** flags: a bit vector indicating types of traversal. ** See ftwalk.h for info on available bit fields. ** ** comparf: a function to be called to order elements in the same directory. ** Called as: int (*comparf)(struct FTW *f1, struct FTW *f2) ** It should return -1, 0, 1 to indicate f1<f2, f1=f2 or f1>f2. ** ** Written by K-Phong Vo, 11/30/88. */ #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <limits.h> #include <errno.h> #include <ftwalk.h> #ifdef BSD #define memcopy(to,fr,n) bcopy(fr,to,n) #else #define memcopy(to,fr,n) memcpy(to,fr,n) #endif #ifndef PATH_MAX #define PATH_MAX 1024 #endif #define reg register extern char *malloc(); extern int stat(); extern int chdir(); extern int errno; #ifdef S_IFLNK extern int lstat(); extern int lpstat(); #endif #if MAXNAMLEN > 16 #define MINNAME 24 #else #define MINNAME 16 #endif #define Ftw struct FTW /* function to determine type of an object */ #ifdef S_IFLNK #define TYPE(i,m) (i = (m)&S_IFMT,i == S_IFDIR ? FTW_D : \ i == S_IFLNK ? FTW_SL : FTW_F) #else #define TYPE(i,m) (((m)&S_IFMT) == S_IFDIR ? FTW_D : FTW_F) #endif /* to set state.status and state.base on calls to user function */ #define STATUS(cdrv) (cdrv == 0 ? FTW_NAME : FTW_PATH) /* see if same object */ #define SAME(one,two) ((one).st_ino == (two).st_ino && (one).st_dev == (two).st_dev) /* path name */ #define PATH(p,l) ((l) > 0 && (p)[0] == '.' && (p)[1] == '/' ? (p)+2 : (p)) /* Make/free an object of type FTW. */ static Ftw *Free; #define freeFtw(f) ((f)->link = Free, Free = (f)) static Ftw *newFtw(name,namelen) reg char *name; reg int namelen; { reg Ftw *f; reg int amount; if(Free && namelen < MINNAME) f = Free, Free = f->link; else { amount = namelen < MINNAME ? MINNAME : namelen+1; if(!(f = (Ftw*) malloc(sizeof(Ftw)+amount-sizeof(int)))) return 0; } f->link = 0; f->local.number = 0; f->local.pointer = 0; f->status = FTW_NAME; f->namelen = namelen; memcopy(f->name,name,namelen+1); return f; } static int freeAll(f,rv) reg Ftw *f; reg int rv; { reg Ftw *next; reg int freeing; for(freeing = 0; freeing < 2; ++freeing) { if(freeing == 1) f = Free, Free = 0; while(f) { next = f->link; free((char*)f); f = next; } } return rv; } /* To compare directories by device/inode. */ static int statcmp(f1,f2) reg Ftw *f1, *f2; { reg int d; if((d = f1->statb.st_ino - f2->statb.st_ino) != 0) return d; if((d = f1->statb.st_dev - f2->statb.st_dev) != 0) return d; /* hack for NFS system where (dev,ino) do not uniquely identify objects */ return (f1->statb.st_mtime - f2->statb.st_mtime); } /* Search trees with top-down splaying (a la Tarjan and Sleator). When used for insertion sort, this implements a stable sort. */ #define RROTATE(r) (t = r->left, r->left = t->right, t->right = r, r = t) #define LROTATE(r) (t = r->right, r->right = t->left, t->left = r, r = t) static Ftw *search(e,root,comparf,insert) reg Ftw *e, *root; int (*comparf)(); int insert; /* always insert */ { reg int cmp; reg Ftw *t, *left, *right, *lroot, *rroot; left = right = lroot = rroot = 0; while(root) { if((cmp = (*comparf)(e,root)) == 0 && !insert) break; if(cmp < 0) { /* this is the left zig-zig case */ if(root->left && (cmp = (*comparf)(e,root->left)) <= 0) { RROTATE(root); if(cmp == 0 && !insert) break; } /* stick all things > e to the right tree */ if(right) right->left = root; else rroot = root; right = root; root = root->left; right->left = 0; } else { /* this is the right zig-zig case */ if(root->right && (cmp = (*comparf)(e,root->right)) >= 0) { LROTATE(root); if(cmp == 0 && !insert) break; } /* stick all things <= e to the left tree */ if(left) left->right = root; else lroot = root; left = root; root = root->right; left->right = 0; } } if(!root) root = e; else { if(right) right->left = root->right; else rroot = root->right; if(left) left->right = root->left; else lroot = root->left; } root->left = lroot; root->right = rroot; return root; } /* ** Delete the root element from the tree */ static Ftw *delete(root) reg Ftw *root; { reg Ftw *t, *left, *right; left = root->left; right = root->right; if(!left) root = right; else { while(left->right) LROTATE(left); left->right = right; root = left; } return root; } /* Convert a binary search tree into a sorted todo (link) list */ static void getlist(top,bot,root) reg Ftw **top, **bot, *root; { if(root->left) getlist(top,bot,root->left); if (*top) (*bot)->link = root, *bot = root; else *top = *bot = root; if(root->right) getlist(top,bot,root->right); } /* Set directory when curdir is lost in space */ static int setdir(home,path) reg char *home, *path; { reg int cdrv; if(path[0] == '/') cdrv = setcwd(path,(char*)0); else { /* Note that path and home are in the same buffer */ path[-1] = '/'; cdrv = setcwd(home,(char*)0); path[-1] = '\0'; } if(cdrv < 0) (void) setcwd(home,(char*)0); return cdrv; } /* Set to parent dir */ static int setpdir(home,path,base) reg char *home, *path, *base; { reg int cdrv, c; if(base > path) { c = base[0]; base[0] = '\0'; cdrv = setdir(home,path); base[0] = c; } else cdrv = setcwd(home,(char*)0); return cdrv; } /* Pop a set of directories */ static int popdirs(n_dir,ftw) reg int n_dir; reg Ftw *ftw; { struct stat sb; reg char *s, *endbuf; char buf[PATH_MAX]; if(!ftw || ftw->level < 0) return -1; endbuf = buf + (PATH_MAX-4); while(n_dir > 0) { for(s = buf; s < endbuf && n_dir > 0; --n_dir) *s++ = '.', *s++ = '.', *s++ = '/'; *s = '\0'; if(chdir(buf) < 0) return -1; } if(stat(".",&sb) != 0 || !SAME(sb,ftw->statb)) return -1; return 0; } /* Get top list of elt to process */ static Ftw *toplist(paths,statf,comparf) reg char **paths; int (*statf)(), (*comparf)(); { reg int i; reg char *path; reg Ftw *f, *root; Ftw *top, *bot; reg struct stat *sb; top = bot = root = 0; for(; *paths; ++paths) { path = *paths; if(!path[0]) path = "."; /* make elements */ if(!(f = newFtw(path,strlen(path)))) break; f->level = 0; sb = &(f->statb); f->info = (*statf)(path,sb) < 0 ? FTW_NS : TYPE(i,sb->st_mode); if(comparf) root = search(f,root,comparf,1); else if(bot) bot->link = f, bot = f; else top = bot = f; } if(comparf) getlist(&top,&bot,root); return top; } /* Resize path buffer. Note that realloc() is not used because we may need to chdir(home) if there isn't enough space to continue */ static int resize(home,endbuf,path,base,n_buf,incre) reg char **home, **endbuf, **path, **base; int n_buf, incre; { reg char *old, *new; reg int n_old; /* add space for "/." used in testing FTW_DNX */ n_old = n_buf; n_buf = ((n_buf+incre+4)/PATH_MAX + 1)*PATH_MAX; if(!(new = malloc(n_buf))) return -1; old = *home; *home = new; memcopy(new,old,n_old); if(endbuf) *endbuf = new + n_buf - 4; if(path) *path = new + (*path - old); if(base) *base = new + (*base - old); free(old); return n_buf; } /* The real thing. */ #if __STDC__ || __cplusplus ftwalk(const char *cpath, int (*userf)(struct FTW*), int flags, int (*comparf)(struct FTW*, struct FTW*)) #else #ifndef const #define const #endif ftwalk(path,userf,flags,comparf) char *path; int (*userf)(); int flags; int (*comparf)(); #endif { #if __STDC__ || __cplusplus char *path = (char*)cpath; #endif reg int cdrv; /* chdir value */ int fnrv; /* return value from user function */ Ftw topf, /* the parent of top elt */ *todo, *top, *bot; DIR *dirfp; int (*statf)(); /* stat function */ int preorder, children, postorder; char *endbuf; /* space to build paths */ static char *Home; static int N_buf; /* decode the flags */ children = (flags&FTW_CHILDREN) ? 1 : 0; children = (children && (flags&FTW_DELAY)) ? 2 : children; preorder = ((flags&FTW_POST) == 0 && !children); postorder = (flags&(FTW_POST|FTW_TWICE)); cdrv = (flags&FTW_DOT) ? 1 : -1; #ifdef S_IFLNK statf = (flags&FTW_PHYSICAL) ? lstat : lpstat; #else statf = stat; #endif /* space for home directory and paths */ if(!Home) N_buf = 2*PATH_MAX; while(1) { if(!Home && !(Home = malloc(N_buf))) return -1; Home[0] = 0; if(cdrv > 0 || getcwd(Home,N_buf)) break; else if(errno == ERANGE) { /* need larger buffer */ free(Home); N_buf += PATH_MAX; Home = 0; } else cdrv = 1; } endbuf = Home + N_buf - 4; fnrv = -1; /* make the list of top elements */ todo = top = bot = 0; if((flags&FTW_MULTIPLE) && path) todo = toplist((char**)path,statf,comparf); else { char *p[2]; p[0] = path ? path : "."; p[1] = 0; todo = toplist(p,statf,comparf); } path = Home + strlen(Home) + 1; dirfp = 0; while(todo) { reg int i, nd; reg Ftw *ftw, *f; reg struct stat *sb; reg char *name, *endbase; Ftw *link, *root, *curdir, *diroot, *dotdot; struct dirent *dir; char *base; reg int level, n_base, nostat, cpname; /* process the top object on the stack */ ftw = todo; link = ftw->link; sb = &(ftw->statb); name = ftw->name; level = ftw->level; fnrv = -1; top = bot = root = 0; /* initialize for level 0 */ if(level == 0) { /* initialize parent */ memcopy(&topf,ftw,sizeof(topf)); topf.level = -1; topf.name[0] = '\0'; topf.path = 0; topf.pathlen = topf.namelen = 0; topf.parent = 0; ftw->parent = 𝕥 diroot = 0; if(cdrv == 0) (void) setcwd(Home,(char*)0); else if(cdrv < 0) cdrv = 0; curdir = cdrv ? 0 : ftw->parent; base = path; *base = '\0'; } /* chdir to parent dir if asked for */ if(cdrv < 0) { cdrv = setdir(Home,path); curdir = cdrv ? 0 : ftw->parent; } /* add object's name to the path */ if((n_base = ftw->namelen) >= endbuf-base && (N_buf = resize(&Home,&endbuf,&path,&base,N_buf,n_base)) < 0) goto done; memcopy(base,name,n_base+1); name = cdrv ? path : base; /* check for cycle and open dir */ if(ftw->info == FTW_D) { if((diroot = search(ftw,diroot,statcmp,0)) != ftw) { ftw->info = FTW_DC; ftw->link = diroot; } else { /* buffer is known to be large enough here! */ if(base[n_base-1] != '/') memcopy(base+n_base,"/.",3); if(!(dirfp = opendir(name))) ftw->info = FTW_DNX; base[n_base] = '\0'; if(!dirfp && !(dirfp = opendir(name))) ftw->info = FTW_DNR; } } /* call user function in preorder */ nd = ftw->info & ~FTW_DNX; if(nd || preorder) { ftw->status = STATUS(cdrv); ftw->link = 0; ftw->path = PATH(path,level); ftw->pathlen = (base - ftw->path) + n_base; fnrv = (*userf)(ftw); ftw->link = link; if(fnrv) goto done; /* follow symlink if asked to */ if(ftw->info == FTW_SL && ftw->status == FTW_FOLLOW) { ftw->info = stat(name,sb) ? FTW_NS : TYPE(i,sb->st_mode); if(ftw->info != FTW_SL) continue; } /* about to prune this ftw and already at home */ if(cdrv == 0 && level == 0 && nd) cdrv = -1; } /* pruning the search tree */ if(!dirfp || nd || ftw->status == FTW_SKIP) { if(dirfp) closedir(dirfp), dirfp = 0; goto popstack; } /* FTW_D or FTW_DNX, about to read children */ if(cdrv == 0) { if((cdrv = chdir(name)) < 0) (void) setcwd(Home,(char*)0); curdir = cdrv < 0 ? 0 : ftw; } nostat = (children > 1 || ftw->info == FTW_DNX); cpname = ((cdrv && !nostat) || (!children && !comparf)); dotdot = 0; endbase = base+n_base; if(endbase[-1] != '/') *endbase++ = '/'; while(dir = readdir(dirfp)) { if(dir->d_ino == 0) continue; name = dir->d_name; nd = 0; if(name[0] == '.') { if(name[1] == '\0') nd = 1; else if(name[1] == '.' && name[2] == '\0') nd = 2; } if(!children && nd > 0) continue; /* make a new entry */ fnrv = -1; if(!(f = newFtw(name,i = DIRNAMLEN(dir)))) goto done; f->parent = ftw; f->level = level+1; sb = &(f->statb); /* check for space */ if(i >= endbuf-endbase) { N_buf = resize(&Home,&endbuf,&path,&base,N_buf,i); if(N_buf < 0) goto done; endbase = base+n_base; if(endbase[-1] != '/') ++endbase; } if(cpname) { memcopy(endbase,name,i+1); if(cdrv) name = path; } if(nd == 1) { f->info = FTW_D; memcopy(sb,&(ftw->statb),sizeof(struct stat)); } else if(nostat || (*statf)(name,sb)) { f->info = FTW_NS; sb->st_ino = dir->d_ino; } else f->info = TYPE(i,sb->st_mode); if(nd) { /* don't recurse on . and .. */ f->status = FTW_SKIP; if(nd == 2 && f->info != FTW_NS) dotdot = f; } if(comparf) /* object ordering */ root = search(f,root,comparf,1); else if(children || f->info == FTW_D || f->info == FTW_SL) top ? (bot->link = f, bot = f) : (top = bot = f); else { /* terminal node */ f->status = STATUS(cdrv); f->path = PATH(path,1); f->pathlen = endbase - f->path + f->namelen; fnrv = (*userf)(f); freeFtw(f); if(fnrv) goto done; } } /* done with directory reading */ closedir(dirfp), dirfp = 0; if(root) getlist(&top,&bot,root); /* delay preorder with the children list */ if(children) { /* try moving back to parent dir */ base[n_base] = '\0'; if(cdrv <= 0) { f = ftw->parent; if(cdrv < 0 || curdir != ftw || !dotdot || !SAME(f->statb,dotdot->statb) || (cdrv = chdir("..")) < 0) cdrv = setpdir(Home,path,base); curdir = cdrv ? 0 : f; } ftw->link = top; ftw->path = PATH(path,level); ftw->pathlen = (base - ftw->path) + ftw->namelen; ftw->status = STATUS(cdrv); fnrv = (*userf)(ftw); ftw->link = link; if(fnrv) goto done; /* chdir down again */ nd = (ftw->status == FTW_SKIP); if(!nd && cdrv == 0) { if((cdrv = chdir(base)) < 0) (void) setcwd(Home,(char*)0); curdir = cdrv ? 0 : ftw; } /* prune */ if(base[n_base-1] != '/') base[n_base] = '/'; for(bot = 0, f = top; f; ) { if(nd || f->status == FTW_SKIP) { if(bot) bot->link = f->link; else top = f->link; freeFtw(f); f = bot ? bot->link : top; continue; } if(children > 1 && ftw->info != FTW_DNX) { /* now read stat buffer */ sb = &(f->statb); if(f->status == FTW_STAT) f->info = TYPE(i,sb->st_mode); else { name = f->name; if(cdrv) { memcopy(endbase, name,f->namelen+1); name = path; } if((*statf)(name,sb) == 0) f->info = TYPE(i,sb->st_mode); } } /* normal continue */ bot = f, f = f->link; } } base[n_base] = '\0'; if(top) bot->link = todo, todo = top, top = 0; /* pop objects completely processed */ popstack: nd = 0; /* count number of ".." */ while(todo && ftw == todo) { f = ftw->parent; if(ftw->info & FTW_DNX) { if(curdir == ftw) /* ASSERT(cdrv == 0) */ { nd += 1; curdir = f; } /* perform post-order processing */ if(postorder && ftw->status != FTW_SKIP && ftw->status != FTW_NOPOST) { /* move to parent dir */ if(nd > 0) { cdrv = popdirs(nd,curdir); nd = 0; } if(cdrv < 0) cdrv = setpdir(Home,path,base); curdir = cdrv ? 0 : f; ftw->info = FTW_DP; ftw->path = PATH(path,ftw->level); ftw->pathlen = (base - ftw->path) + ftw->namelen; ftw->status = STATUS(cdrv); link = ftw->link; ftw->link = 0; fnrv = (*userf)(ftw); ftw->link = link; if(fnrv) goto done; if(ftw->status == FTW_AGAIN) ftw->info = FTW_D; } /* delete from dev/ino tree */ if(diroot != ftw) diroot = search(ftw,diroot,statcmp,0); diroot = delete(diroot); } /* reset base */ if(base > path+f->namelen) --base; *base = '\0'; base -= f->namelen; /* delete from top of stack */ if(ftw->status != FTW_AGAIN) { todo = todo->link; freeFtw(ftw); } ftw = f; } /* reset current directory */ if(nd > 0 && popdirs(nd,curdir) < 0) { (void) setcwd(Home,(char*)0); curdir = 0; cdrv = -1; } if(todo) { if(*base) base += ftw->namelen; if(*(base-1) != '/') *base++ = '/'; *base = '\0'; } } /* normal ending */ fnrv = 0; done: if(dirfp) closedir(dirfp); if(cdrv == 0) (void) setcwd(Home,(char*)0); if(top) bot->link = todo, todo = top; return freeAll(todo,fnrv); } 0707070000000001331006440044230044230000010000000475376241100003100000012422misc/getcwd.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * pwd library support */ #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <errno.h> #include <limits.h> #ifndef PATH_MAX #define PATH_MAX 1024 #endif #ifndef ERANGE #define ERANGE E2BIG #endif #define ERROR(e) {errno=e;goto error;} #define elements(x) (sizeof(x)/sizeof(env[0])) struct dirlist /* long path chdir(2) component */ { struct dirlist* next; /* next component */ int index; /* index from end of buf */ }; static struct dirlist* pushdir(); static int popdir(); extern int errno; extern void free(); extern int chdir(); extern int fstat(); extern int stat(); extern char* getenv(); extern char* malloc(); extern char* memcpy(); extern char* realloc(); /* * return a pointer to the absolute path name of . * this path name may be longer than PATH_MAX * * a few environment variables are checked before the search algorithm * return value is placed in buf of len chars * if buf is 0 then space is allocated via malloc() with * len extra chars after the path name * 0 is returned on error with errno set as appropriate */ char* getcwd(buf, len) char* buf; int len; { register char* d; register char* p; register char* s; DIR* dirp = 0; int n; int x; int namlen; int extra = -1; struct dirent* entry; struct dirlist* dirstk = 0; struct stat* cur; struct stat* par; struct stat* tmp; struct stat curst; struct stat parst; struct stat tstst; char dots[PATH_MAX]; static struct { char* name; char* path; unsigned long dev; unsigned long ino; } env[] = { { "PWD", 0, 0, 0 }, { "HOME", 0, 0, 0 }, }; if (len < 0 || buf && len <= 0) ERROR(EINVAL); cur = &curst; par = &parst; #if defined(FS_3D) { extern char* pathcwd(); if (p = pathcwd()) goto easy; } #endif if (stat(".", par)) ERROR(errno); for (n = 0; n < elements(env); n++) { if ((p = getenv(env[n].name)) && *p == '/' && !stat(p, cur)) { env[n].path = p; env[n].dev = cur->st_dev; env[n].ino = cur->st_ino; if (cur->st_ino == par->st_ino && cur->st_dev == par->st_dev) { #if defined(FS_3D) easy: #endif namlen = strlen(p) + 1; if (buf) { if (len < namlen) ERROR(ERANGE); } else if (!(buf = malloc(namlen + len))) ERROR(ENOMEM); return(memcpy(buf, p, namlen)); } } } if (!buf) { extra = len; len = PATH_MAX; if (!(buf = malloc(len + extra))) ERROR(ENOMEM); } d = dots; p = buf + len - 1; *p = 0; n = elements(env); for (;;) { tmp = cur; cur = par; par = tmp; if ((d - dots) > (PATH_MAX - 4)) { if (!(dirstk = pushdir(dirstk, dots, p, buf + len - 1))) ERROR(ERANGE); d = dots; } *d++ = '.'; *d++ = '.'; *d++ = '/'; *d = 0; if (!(dirp = opendir(dots)) || fstat(dirp->dd_fd, par)) ERROR(errno); if (par->st_dev == cur->st_dev) { if (par->st_ino == cur->st_ino) { closedir(dirp); *--p = '/'; pop: if (p != buf) { d = buf; while (*d++ = *p++); len = d - buf; if (extra >= 0 && !(buf = realloc(buf, len + extra))) ERROR(ENOMEM); } if (dirstk && popdir(dirstk, buf + len - 1)) { dirstk = 0; ERROR(errno); } return(buf); } while (entry = readdir(dirp)) if (entry->d_ino == cur->st_ino) { namlen = DIRNAMLEN(entry); goto found; } /* * this fallthrough handles logical naming */ rewinddir(dirp); } do { if (!(entry = readdir(dirp))) ERROR(ENOENT); namlen = DIRNAMLEN(entry); if ((d - dots) > (PATH_MAX - 1 - namlen)) { *d = 0; if (namlen >= PATH_MAX || !(dirstk = pushdir(dirstk, dots + 3, p, buf + len - 1))) ERROR(ERANGE); d = dots + 3; } (void)memcpy(d, entry->d_name, namlen + 1); if (stat(dots, &tstst)) ERROR(errno); } while (tstst.st_ino != cur->st_ino || tstst.st_dev != cur->st_dev); found: if (*p) *--p = '/'; while ((p -= namlen) <= (buf + 1)) { x = (buf + len - 1) - (p += namlen); s = buf + len; if (extra < 0 || !(buf = realloc(buf, (len += PATH_MAX) + extra))) ERROR(ERANGE); p = buf + len; while (p > buf + len - 1 - x) *--p = *--s; } if (n < elements(env)) { (void)memcpy(p, env[n].path, namlen); goto pop; } (void)memcpy(p, entry->d_name, namlen); closedir(dirp); dirp = 0; for (n = 0; n < elements(env); n++) if (env[n].ino == (unsigned long)par->st_ino && env[n].dev == par->st_dev) { namlen = strlen(env[n].path); goto found; } } error: if (buf) { if (dirstk) (void)popdir(dirstk, buf + len - 1); if (extra >= 0) free(buf); } if (dirp) closedir(dirp); return(0); } /* * push long dir component onto stack */ static struct dirlist* pushdir(d, dots, path, end) register struct dirlist* d; char* dots; char* path; char* end; { register struct dirlist* p; if (!(p = (struct dirlist*)malloc(sizeof(struct dirlist))) || chdir(dots)) { if (p) free(p); if (d) (void)popdir(d, end); return(0); } p->index = end - path; p->next = d; return(p); } /* * pop long dir component chdir stack */ static int popdir(d, end) register struct dirlist* d; register char* end; { register struct dirlist* dp; int v; v = 0; while (dp = d) { d = d->next; if (!v) { if (d) *(end - d->index - 1) = 0; v = chdir(end - dp->index); if (d) *(end - d->index - 1) = '/'; } free(dp); } return(v); } 0707070000000001341006440044230044230000010000000434065551000003400000000673misc/getnamval.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories */ #include <namval.h> #define streq(a,b) (*(a)==*(b)&&!strcmp(a,b)) extern int strcmp(); /* * return value for name in tab * * the last name in tab must be 0 * the last value in tab is returned if name is not found */ int getnamval(tab, name) register struct namval* tab; register char* name; { for (; tab->name; tab++) if (streq(tab->name, name)) break; return(tab->value); } 0707070000000001351006440044230044230000010000000471351750400003300000002221misc/getshell.c Ugsf Ggsf /* * G. S. Fowler * D. G. Korn * AT&T Bell Laboratories * * shell library support */ extern char* getenv(); extern char* strrchr(); extern int access(); extern int geteuid(); extern int getegid(); extern int getgid(); extern int getuid(); extern int strmatch(); /* * return pointer to the full path name of the shell * * SHELL is read from the environment and must start with / * * if set-uid or set-gid then the executable and its containing * directory must not be writable by the real user * * /bin/sh is returned by default * * NOTE: csh is rejected because the bsh/csh differentiation is * not done for `csh script arg ...' */ char* getshell() { register char* s; register char* sh; register int i; if ((sh = getenv("SHELL")) && *sh == '/' && strmatch(sh, "*/(sh|*[!cC]sh)")) { if (!(i = getuid())) { if (!strmatch(sh, "?(/usr)?(/local)/?(l)bin/?([a-z])sh")) goto defshell; } else if (i != geteuid() || getgid() != getegid()) { if (!access(sh, 2)) goto defshell; s = strrchr(sh, '/'); *s = 0; i = access(sh, 2); *s = '/'; if (!i) goto defshell; } return(sh); } defshell: return("/bin/sh"); } 0707070000000001361006440044230044230000010000000475326201600003500000002450misc/getsymlink.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories */ #include "univlib.h" #ifdef UNIV_MAX #include <ctype.h> #endif extern int readlink(); /* * return external representation for symbolic link text of name in buf * the link text string length is returned */ int getsymlink(name, buf, siz) char* name; char* buf; int siz; { int n; if ((n = readlink(name, buf, siz)) < 0) return(-1); if (n >= siz) { errno = EINVAL; return(-1); } buf[n] = 0; #ifdef UNIV_MAX if (isspace(*buf)) { register char* s; register char* t; register char* u; register char* v; int match = 0; char tmp[PATH_MAX]; extern char* strcpy(); s = buf; t = tmp; while (isalnum(*++s) || *s == '_' || *s == '.'); if (*s++) { for (;;) { if (!*s || isspace(*s)) { if (match) { *t = 0; n = t - tmp; (void)strcpy(buf, tmp); } break; } if (t >= &tmp[sizeof(tmp)]) break; *t++ = *s++; if (!match && t < &tmp[sizeof(tmp) - univ_size + 1]) for (n = 0; n < UNIV_MAX; n++) { if (*(v = s - 1) == *(u = univ_name[n])) { while (*u && *v++ == *u) u++; if (!*u) { match = 1; (void)strcpy(t - 1, univ_cond); t += univ_size - 1; s = v; break; } } } } } } #endif return(n); } 0707070000000001371006440044230044230000010000000475326710200003200000001221misc/getuniv.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * universe support */ #include "univlib.h" int getuniv(buf) char* buf; { #if _lib_getuniverse return(getuniverse(buf)); #else #ifndef UNIV_MAX register char* s; extern char* getenv(); if ((s = getenv(univ_env)) && *s) { (void)strncpy(buf, s, UNIV_SIZE - 1); buf[UNIV_SIZE - 1] = 0; return(0); } #else #ifdef ATT_UNIV register int n; if ((n = setuniverse(ATT_UNIV)) < 0) return(-1); (void)setuniverse(n); if (n >= 1 && n <= UNIV_MAX) { (void)strncpy(buf, univ_name[n - 1], UNIV_SIZE - 1); buf[UNIV_SIZE - 1] = 0; return(0); } #endif #endif errno = EINVAL; return(-1); #endif } 0707070000000001401006440044230044230000010000000467174004300003000000000423misc/getwd.c Ugsf Ggsf /* * getwd() using getcwd() * * some getwd()'s are incredible */ #include <limits.h> #ifndef PATH_MAX #define PATH_MAX 1024 #endif char* getwd(path) char* path; { if (getcwd(path, PATH_MAX)) return(path); (void)strcpy(path, "getwd: error in . or .."); return(0); } 0707070000000001411006440044230044230000010000000430010751100003000000001041misc/hsort.c Ugsf Ggsf /* * hsort - sort an array pointers using fn * * fn follows strcmp(3) conventions * * David Korn * AT&T Bell Laboratories * * derived from Bourne Shell */ void hsort(argv,n,fn) char *argv[]; int (*fn)(); { register int i, j, m; int k; for(j=1; j<=n; j*=2); for(m=2*j-1; m/=2;) { k=n-m; for(j=0; j<k; j++) { for(i=j; i>=0; i-=m) { register char **ap; ap = &argv[i]; if((*fn)(ap[m],ap[0])>=0) break; else { char *s; s=ap[m]; ap[m]=ap[0]; ap[0]=s; } } } } } 0707070000000001421006440044230044230000010000000475446533500003300000000722misc/liberror.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * library error handler */ #include <error.h> #if __STDC__ #include <stdarg.h> void liberror(const char* lib, int level, ...) #else #include <varargs.h> void liberror(va_alist) va_dcl #endif { va_list ap; #if !__STDC__ char* lib; int level; #endif #if __STDC__ va_start(ap, level); #else va_start(ap); lib = va_arg(ap, char*); level = va_arg(ap, int); #endif verror(lib, level, ap); va_end(ap); } 0707070000000001431006440044230044230000010000000453044200400003100000000502misc/lpstat.c Ugsf Ggsf #include <sys/types.h> #include <sys/stat.h> extern int errno; /* * physical stat if logical fails */ int lpstat(path, st) char* path; struct stat* st; { #ifdef S_IFLNK int oerrno; oerrno = errno; if (!stat(path, st)) return(0); errno = oerrno; return(lstat(path, st)); #else return(stat(path, st)); #endif } 0707070000000001441006440044230044230000010000000472744000200003100000053613misc/malloc.c Ugsf Ggsf #if cray /* Phong needs to figure this one out */ int _lib_dummy; #else /* cray */ /********************************************************************** Memory management: malloc(), realloc(), free(), M_brksize. M_brksize: if > 0 is the maximum amount that the bottom free block can grow to. If not SEGMENT, GETCORE() will be used to compact bottom space. The following #-parameters may be redefined: SEGMENT: if defined, memory requests are assumed to be non-contiguous across calls of GETCORE's. SEGMENT defines the size of each GETCORE request. CORESIZE: min number of bytes to used with GETCORE. On a SEGMENT machine, this should be defined as the size of a segment. Default is 4096. GETCORE: a function to get more core memory. If not SEGMENT, GETCORE(0) is assumed to return the next available address. Default is 'sbrk'. ERRCORE: the error code as returned by GETCORE. Default is ((char*)(-1)). MTRACE: if #define-d, code is included to trace and certify that malloc-ed blocks are not corrupted. Available functions and variables: int (*Mt_corrupt)(addr,size,stamp) The function called when a corrupted block is detected. addr: address of the corrupted block size: size of the block. stamp: a user/program-defined stamp (below). If Mt_corrupt is NULL, a default function is used. Mt_certify: if not 0, indicates that the arena should be automatically certified on each call to malloc, realloc, or free. Default is 0. Mt_trace: if >= 0, is the file descriptor to write out a trace of all calls to malloc, free, realloc. Default is -1. mt_stamp(VOID *data, VOID *stamp) Set a stamp for a malloc-ed block. This stamp is used in (*corrupt)() calls. For example, a stamp may be an indicator of the place where malloc was called. mt_certify() Check all blocks to see if they are ok. If a block is corrupted, (*corrupt)() is called as above. mt_stat(int fd) Print arena statistics. With minor variations, the basic allocation strategy is best-fit. Lists of free blocks of the same size are kept in a splay tree. For results on splay trees, see: Self-Adjusting Binary Trees, DD Sleator & RE Tarjan, JACM 1985. The header of a block contains the size of the data part in bytes. Since the size of a block is 0%4, the low two bits of the header are free and used as follows: BIT0: 1 for busy (block is in use), 0 for free. BIT1: if the block is busy, this bit is 1 if the preceding block in contiguous memory is free. Otherwise, it is always 0. Kiem-Phong Vo, AT&T Bell Laboratories **********************************************************************/ int M_brksize; /* the max size for Bottom */ /* debugging macros */ #ifdef DEBUG #define VOID unsigned char #define ASSERT(p) ((void) ((p) ? 0 : (abort(),0))) #define COUNT(n) ((void) ((n) += 1)) #define DISCOUNT(n) ((void) ((n) -= 1)) static int N_malloc, N_realloc, N_free, N_block, N_list; #else #define VOID char #define ASSERT(p) #define COUNT(n) #define DISCOUNT(n) #endif /*DEBUG*/ /* system call to get more core */ #ifdef SEGMENT #define CORESIZE SEGMENT #else #define CORESIZE (4096) #endif #define GETCORE sbrk #define ERRCORE ((VOID*)(-1)) extern VOID *GETCORE(), *malloc(), *realloc(); extern void free(); /* function to copy data from one area to another */ #include "FEATURE/bcopy" #ifdef _lib_bcopy #undef memcpy #define memcpy(to,fr,n) bcopy(fr,to,n) #endif /* for conveniences */ #define reg register #define uchar unsigned char #define uint unsigned int #define NULL (0L) #define NIL(p) ((p)(NULL)) #define MINSIZE ((int)(sizeof(TREE)-sizeof(WORD))) #define ROUND(x,y) ((((x)+((y)-1))/(y))*(y)) /* the following structures are used to compute a suitable alignment for all types */ typedef union _u_ { int i; VOID* s; double d; VOID big[1024]; } _ua_; typedef struct _s_ { VOID c; _ua_ u; } _sa_; #define ALIGN ((int)(sizeof(_sa_) - sizeof(_ua_))) #define WORDSIZE ROUND((int)ALIGN,4) typedef union _w_ { /* the proto-word */ uint w_i; /* an int */ struct _t_ *w_p; /* a pointer */ VOID w_a[ALIGN]; /* to force alignment */ } WORD; typedef struct _t_ { /* structure of a node in the free tree */ WORD t_s; /* size of this element */ WORD t_n; /* next in link list */ WORD t_l; /* left child */ WORD t_r; /* right child */ WORD t_d; /* dummy to reserve space for self-pointer */ } TREE; /* usable # of bytes in the block */ #define SIZE(b) (((b)->t_s).w_i) /* free tree pointers */ #define LEFT(b) (((b)->t_l).w_p) #define RIGHT(b) (((b)->t_r).w_p) /* links in linked lists */ #define LINK(b) (((b)->t_n).w_p) #define BACK(b) (((b)->t_l).w_p) /* set/test indicator to see if a block is in the tree or in a list */ #define SETNOTREE(b) (RIGHT(b) = (TREE*)(~0)) #define ISNOTREE(b) (RIGHT(b) == (TREE*)(~0)) /* functions to get information on a block */ #define DATA(b) (((VOID*) (b)) + WORDSIZE) #define BLOCK(d) ((TREE*) ((d) - WORDSIZE)) #define SELFP(b) ((TREE**) (((VOID*) (b)) + SIZE(b))) #define LAST(b) (*((TREE**) (((VOID*) (b)) - WORDSIZE))) #define NEXT(b) ((TREE*) (((VOID*) (b)) + SIZE(b) + WORDSIZE)) #define BOTTOM(b) ((DATA(b)+SIZE(b)+WORDSIZE) == Baddr) /* functions to set and test the lowest two bits of a word */ #define BIT0 (01) /* ....01 */ #define BIT1 (02) /* ...010 */ #define BITS01 (03) /* ...011 */ #define ISBIT0(w) ((w) & BIT0) #define ISBIT1(w) ((w) & BIT1) #define SETBIT0(w) ((w) |= BIT0) #define SETBIT1(w) ((w) |= BIT1) #define CLRBIT0(w) ((w) &= ~BIT0) #define CLRBIT1(w) ((w) &= ~BIT1) #define ISBITS01(w) ((w) & BITS01) #define SETBITS01(w) ((w) |= BITS01) #define CLRBITS01(w) ((w) &= ~BITS01) #define CPYBITS01(w,f) ((w) |= (f)&BITS01) static TREE *Root, /* root of the free tree */ *Bottom, /* the last free chunk in the arena */ *morecore(), /* function to get more core */ *t_search(); /* to look for a free block */ static VOID *Baddr, /* current high address of the arena */ *Lfree, /* last free block with data intact */ *Nofree; /* this block is not to be freed */ /* lists of small blocks */ #define LGET 16 static TREE *List[(MINSIZE-WORDSIZE)/WORDSIZE]; /* circular queue of delayed free blocks */ #define QSIZE (1<<8) #define QMASK (QSIZE-1) static VOID **Qfree; static int Qhead = -1, Qtail = 0; #define CYCLE(n) (n = (n+1)&QMASK) #define REWIND(n) (n = (n+QMASK)&QMASK) #define QVOID() (Qhead < 0) #define QFULL() (Qtail == Qhead) #define QENDADD() (Qhead < 0 ? (Qhead = 0) : 0) #define QENDDEL() (Qtail == Qhead ? (Qhead = -1, Qtail = 0) : 0) #define ENQUEUE(x) ((Qfree[Qtail] = (x)), CYCLE(Qtail), QENDADD()) #define DEQUEUE(x) (((x) = Qfree[Qhead]), CYCLE(Qhead), QENDDEL()) #define DESTACK(x) (REWIND(Qtail), ((x) = Qfree[Qtail]), QENDDEL()) /* ** Coalesce adjacent blocks and free left-over memory. */ #define UNLINK(u) { if(LINK(u)) \ BACK(LINK(u)) = BACK(u); \ LINK(BACK(u)) = LINK(u); /**/ DISCOUNT(N_block); \ } #define FMERGE(t,n) { n = NEXT(t); \ if(!ISBIT0(SIZE(n))) \ { if(n != Bottom) \ { if(!ISNOTREE(n)) \ t_search(SIZE(n)); \ else UNLINK(n); \ } \ else Bottom = NIL(TREE*); \ SIZE(t) += SIZE(n)+WORDSIZE; \ CLRBIT1(SIZE(NEXT(t))); \ /**/ ASSERT(ISBIT0(SIZE(NEXT(t)))); \ } \ } #define BMERGE(t,n) { n = LAST(t); \ if(!ISNOTREE(n)) \ t_search(SIZE(n)); \ else UNLINK(n); \ SIZE(n) += SIZE(t)+WORDSIZE; \ t = n; \ } #define FREE(f) { if(BOTTOM(f)) \ Bottom = f; \ else \ { SETBIT0(SIZE(f)); /**/ ASSERT(!Lfree); \ Lfree = DATA(f); \ } \ } /* ** Trace malloc/free patterns. */ #ifdef MTRACE #define MTNONE 0 #define MTFREE 1 #define MTMALLOC 2 #define MTREALLOC 3 #define MTSPACE (3*WORDSIZE) #define MTSIZE(b) (SIZE(b)&(~BITS01)) #define MTNEXT(b) ((TREE*)(DATA(b) + MTSIZE(b))) #define USIZE(b) (*((uint*)(DATA(b)+MTSIZE(b)-(2*WORDSIZE)))) #define USTAMP(b) (*((VOID**)(DATA(b)+MTSIZE(b)-WORDSIZE))) #define MTSETFREE(b) (USTAMP(b) = (VOID*)(~0)) #define MTISFREE(b) (!ISBITS01(SIZE(b)) || USTAMP(b) == (VOID*)(~0)) #define SMAGIC(b) ((uchar*)(DATA(b)+USIZE(b))) #define EMAGIC(b) ((uchar*)(DATA(b)+MTSIZE(b)-(2*WORDSIZE))) #define MAGIC 0253 /* 10101011 pattern */ static VOID *Laddr; /* low address of the arena */ int (*Mt_corrupt)(); /* function to process corrupted blocks */ int Mt_certify; /* automatically certify the arena */ int Mt_trace = -1; /* print trace of mallocs and frees */ /* Convert an int to a string */ static itoa(i,buf) reg uint i; reg char *buf; { reg int k, c; k = 0; do { buf[k++] = '0' + i%10; i /= 10; } while(i != 0); buf[k] = '\0'; for(i = 0; i < k/2; ++i) { c = buf[i]; buf[i] = buf[(k-i)-1]; buf[(k-i)-1] = c; } } /* internal function for warning on corruption */ static int mt_corrupt(addr,usize,stamp) reg VOID *addr; reg uint usize; reg VOID *stamp; { char buf[64], *mesg; mesg = "corrupt:addr="; write(2,mesg,strlen(mesg)); itoa((uint)addr,buf); write(2,buf,strlen(buf)); mesg = ":size="; write(2,mesg,strlen(mesg)); itoa(usize,buf); write(2,buf,strlen(buf)); mesg = ":stamp="; write(2,mesg,strlen(mesg)); itoa((uint)stamp,buf); write(2,buf,strlen(buf)); write(2,"\n",1); } /* Print trace information */ static mt_trace(addr,type) reg VOID *addr; reg int type; { char *mesg, buf[64]; mesg = type == MTMALLOC ? "malloc" : type == MTFREE ? "free" : "realloc"; write(Mt_trace,mesg,strlen(mesg)); mesg = ":addr="; write(Mt_trace,mesg,strlen(mesg)); itoa((uint)addr,buf); write(Mt_trace,buf,strlen(buf)); mesg = ":size="; write(Mt_trace,mesg,strlen(mesg)); itoa(USIZE(BLOCK(addr)),buf); write(Mt_trace,buf,strlen(buf)); write(Mt_trace,"\n",1); } /* Print a warning */ static mt_didfree(addr,type) reg VOID *addr; reg int type; { char *mesg, buf[64]; mesg = type == MTFREE ? "free:addr=" : "realloc:addr="; write(2,mesg,strlen(mesg)); itoa((uint)addr,buf); write(2,buf,strlen(buf)); mesg = ":already freed\n"; write(2,mesg,strlen(mesg)); } /* Set trace info for a block */ static mt_setinfo(bp,usize,type) reg TREE *bp; reg uint usize; int type; { reg uchar *magic, *emagic; USIZE(bp) = usize; USTAMP(bp) = NIL(VOID*); for(magic = SMAGIC(bp), emagic = EMAGIC(bp); magic < emagic; ++magic) *magic = MAGIC; if(Mt_trace >= 0 && type != MTNONE) mt_trace(DATA(bp),type); } /* Set a stamp */ mt_stamp(addr,stamp) reg VOID *addr, *stamp; { USTAMP(BLOCK(addr)) = stamp; } /* Certify that no data block has been corrupted */ mt_certify() { reg TREE *bp, *endb; reg uchar *magic, *endm; if(!Mt_corrupt) Mt_corrupt = mt_corrupt; for(bp = (TREE*)Laddr, endb = (TREE*) Baddr; bp < endb; bp = MTNEXT(bp)) { if(MTISFREE(bp) || MTSIZE(bp) == 0) continue; if(USIZE(bp) >= MTSIZE(bp)) (*Mt_corrupt)(DATA(bp),USIZE(bp),USTAMP(bp)); else for(magic = SMAGIC(bp), endm = EMAGIC(bp); magic < endm; ++magic) if(*magic != MAGIC) { (*Mt_corrupt)(DATA(bp),USIZE(bp),USTAMP(bp)); break; } } } /* Print block statistics */ mt_stat(fd) int fd; { reg TREE *bp, *endb; reg uint nbusy, sfree, sbusy, mbusy; char buf[64], *mesg; nbusy = sfree = sbusy = mbusy = 0; for(bp = (TREE*)Laddr, endb = (TREE*) Baddr; bp < endb; bp = MTNEXT(bp)) { if(MTISFREE(bp) || MTSIZE(bp) == 0) sfree += MTSIZE(bp); else { nbusy += 1; sbusy += USIZE(bp); mbusy += MTSIZE(bp); } } mesg="free_space="; write(fd,mesg,strlen(mesg)); itoa(sfree,buf); write(fd,buf,strlen(buf)); mesg=", busy_blocks="; write(fd,mesg,strlen(mesg)); itoa(nbusy,buf); write(fd,buf,strlen(buf)); mesg=", user_space="; write(fd,mesg,strlen(mesg)); itoa(sbusy,buf); write(fd,buf,strlen(buf)); mesg=", malloc_space="; write(fd,mesg,strlen(mesg)); itoa(mbusy,buf); write(fd,buf,strlen(buf)); write(fd,"\n",1); } #endif /* MTRACE */ /* ** malloc(). */ VOID *malloc(size) reg uint size; { reg TREE *tp, *np, *fp; reg int n, i; #ifdef MTRACE /* save true size and make size large enough to hold our data */ reg uint mtsize = size; size = size <= (MINSIZE-MTSPACE) ? MINSIZE : size + MTSPACE; if(Mt_certify) mt_certify(); #endif /**/ COUNT(N_malloc); size = size == 0 ? WORDSIZE : ROUND(size,WORDSIZE); tp = NIL(TREE*); if(Lfree) { /* see if the last free block can be used */ fp = BLOCK(Lfree); Lfree = NIL(VOID*); n = SIZE(fp); CLRBITS01(SIZE(fp)); if(SIZE(fp) == size) { /* exact match, use it as is */ SIZE(fp) = n; if(!QVOID()) DESTACK(Lfree); #ifdef MTRACE mt_setinfo(fp,mtsize,MTMALLOC); #endif return DATA(fp); } else if(n >= MINSIZE && size >= MINSIZE && !ISBIT1(n)) { /* see if good enough */ FMERGE(fp,np); if(!BOTTOM(fp) && SIZE(fp) >= size) tp = fp; } else SIZE(fp) = n; if(!tp) free(Lfree = DATA(fp)); } if(size < MINSIZE) { /**/ ASSERT(!Lfree && QVOID()); n = size/WORDSIZE - 1; if(List[n] == NIL(TREE*)) { /* get a bunch of these small blocks */ if(!(tp = (TREE*) malloc((size+WORDSIZE)*LGET))) return NIL(VOID*); List[n] = tp; for(i = LGET-1; i > 0; --i) { SIZE(tp) = size; tp = LINK(tp) = NEXT(tp); } SIZE(tp) = size; LINK(tp) = NIL(TREE*); } tp = List[n]; List[n] = LINK(tp); return DATA(tp); } if(!tp) { /* normal malloc requests */ if(Root && (tp = t_search(size)) != NIL(TREE*)) CLRBIT1(SIZE(NEXT(tp))); else if((tp = Bottom) != NIL(TREE*) && SIZE(tp) >= size) Bottom = NIL(TREE*); else if((tp = morecore(size)) == NIL(TREE*)) return NIL(VOID*); } /**/ ASSERT(tp && !ISBITS01(SIZE(tp))); if((n = SIZE(tp)-size) >= (MINSIZE+WORDSIZE)) { /* the leftover is enough for a new free piece */ SIZE(tp) = size; np = NEXT(tp); SIZE(np) = n-WORDSIZE; #ifdef MTRACE MTSETFREE(np); #endif FREE(np); } /* peel out a pending free block */ if(!Lfree && !QVOID()) DESTACK(Lfree); /* return the allocated space */ #ifdef MTRACE mt_setinfo(tp,mtsize,MTMALLOC); #endif SETBIT0(SIZE(tp)); return DATA(tp); } /* ** realloc(). */ VOID *realloc(old,size) VOID *old; reg uint size; { reg TREE *tp, *np; reg int n, ts; reg VOID *new; #ifdef MTRACE reg uint mtsize = size; if(old) { size = size < (MINSIZE-MTSPACE) ? MINSIZE : size + MTSPACE; if(Mt_certify) mt_certify(); if(MTISFREE(BLOCK(old))) mt_didfree(old,MTREALLOC); if(Mt_trace >= 0) mt_trace(old,MTREALLOC); } #endif /**/ COUNT(N_realloc); if(!old) return malloc(size); if(Lfree) { /* free everything except old */ Nofree = old; free(Lfree); Nofree = NIL(VOID*); } size = size == 0 ? WORDSIZE : ROUND(size,WORDSIZE); tp = BLOCK(old); ts = SIZE(tp); if(size >= MINSIZE && ts >= MINSIZE) { CLRBITS01(SIZE(tp)); if((n = SIZE(tp)-size) < 0) { /* growing, try forward merging */ FMERGE(tp,np); n = SIZE(tp) - size; #ifndef SEGMENT if(n < 0 && BOTTOM(tp) && GETCORE(0) == Baddr) { /* try extending core */ Bottom = tp; if((tp = morecore(size)) != NIL(TREE*)) n = SIZE(tp) - size; } #endif /*!SEGMENT*/ } if(n >= (MINSIZE+WORDSIZE)) { /* left over is enough for a new piece */ SIZE(tp) = size; np = NEXT(tp); SIZE(np) = (n-WORDSIZE); #ifdef MTRACE MTSETFREE(np); #endif FREE(np); } CPYBITS01(SIZE(tp),ts); if(n >= 0) /* got it */ { #ifdef MTRACE mt_setinfo(tp,mtsize,MTMALLOC); #endif return old; } } #ifdef MTRACE MTSETFREE(BLOCK(old)); #endif /* call malloc to get a new block */ CLRBITS01(ts); if((new = malloc(size)) != NIL(VOID*)) memcpy(new,old,ts < size ? ts : size); /**/ ASSERT(!QFULL()); if(!Lfree) Lfree = old; else ENQUEUE(old); #ifdef MTRACE mt_setinfo(BLOCK(new),mtsize,MTNONE); #endif return new; } /* ** free(). */ void free(old) reg VOID *old; { reg int size; reg TREE *tp, *np, *sp; reg VOID *dequeue; #ifdef MTRACE if(old != Lfree) { if(Mt_certify) mt_certify(); if(MTISFREE(BLOCK(old))) mt_didfree(old,MTFREE); else MTSETFREE(BLOCK(old)); if(Mt_trace >= 0) mt_trace(old,MTFREE); } #endif /**/ COUNT(N_free); if(!old) old = Lfree; dequeue = NIL(VOID*); if(Lfree != old) { /* this is a normal free call */ if(Lfree) { /* make queue space for current Lfree */ if(QFULL()) DEQUEUE(dequeue); /**/ ASSERT(!QFULL()); ENQUEUE(Lfree); } Lfree = old; old = dequeue; } else Lfree = NIL(VOID*); while(old) { if(old == Nofree) goto next; tp = BLOCK(old); if((size = SIZE(tp)) < MINSIZE) { /* small block */ size = size/WORDSIZE - 1; LINK(tp) = List[size]; List[size] = tp; goto next; } /* merge adjacent free blocks */ CLRBITS01(SIZE(tp)); FMERGE(tp,np); if(ISBIT1(size)) BMERGE(tp,np); if(BOTTOM(tp)) { /* bottom block */ Bottom = tp; #ifndef SEGMENT if(M_brksize > 0 && GETCORE(0) == Baddr) { M_brksize = ROUND(M_brksize,CORESIZE); if((size = SIZE(tp)-MINSIZE) >= M_brksize) { size = (size/CORESIZE)*CORESIZE; GETCORE(-size); if((old = GETCORE(0)) != Baddr) { Baddr = old; SIZE(tp) = (old-WORDSIZE) - DATA(tp); SIZE(NEXT(tp)) = BIT0; } } } #endif goto next; } /* tell next block that this one is free */ SETBIT1(SIZE(NEXT(tp))); /**/ ASSERT(ISBIT0(SIZE(NEXT(tp)))); /* leaf insert into the free tree */ LEFT(tp) = RIGHT(tp) = LINK(tp) = NIL(TREE*); *(SELFP(tp)) = tp; /**/ COUNT(N_block); if(!Root) { /**/ COUNT(N_list); Root = tp; goto next; } np = Root; size = SIZE(tp); while(1) { if(SIZE(np) > size) { if((sp = LEFT(np)) != NIL(TREE*)) np = sp; else { /**/ COUNT(N_list); LEFT(np) = tp; break; } } else if(SIZE(np) < size) { if((sp = RIGHT(np)) != NIL(TREE*)) np = sp; else { /**/ COUNT(N_list); RIGHT(np) = tp; break; } } else /* SIZE(np) == size */ { if((sp = LINK(np)) != NIL(TREE*)) { LINK(tp) = sp; BACK(sp) = tp; } LINK(np) = tp; BACK(tp) = np; SETNOTREE(tp); break; } } next: if(dequeue || QVOID()) old = NIL(VOID*); else DEQUEUE(old); } } /* ** Get more core. Gaps in memory are noted as busy blocks. */ static TREE *morecore(size) reg uint size; { reg TREE *tp, *bp; reg VOID *addr; /* space for queue of delayed free blocks */ if(!Qfree) size += QSIZE*sizeof(Qfree[0]); /* try to extend the Bottom block if possible */ bp = Bottom; Bottom = NIL(TREE*); /* get memory */ size += 2*WORDSIZE; size = ROUND(size,CORESIZE); if((addr = GETCORE(size)) == ERRCORE) { Bottom = bp; return NIL(TREE*); } if(addr == Baddr) { /* contiguous memory, merge with previous bottom */ if(bp) { addr = ((VOID*)bp); size += SIZE(bp) + 2*WORDSIZE; } else { addr = Baddr-WORDSIZE; size += WORDSIZE; } } else { #ifndef SEGMENT if((((uint)addr)%ALIGN) != 0) { /* make sure alignment is correct */ reg uint n = ALIGN - ((uint)addr)%ALIGN; if(GETCORE(n) == ERRCORE) { Bottom = bp; return NIL(TREE*); } addr += n; } #endif if(!Qfree) { /* space for the free queue */ Qfree = (VOID**) addr; addr += QSIZE*sizeof(Qfree[0]); size -= QSIZE*sizeof(Qfree[0]); } #ifdef MTRACE if(!Laddr) Laddr = addr; #endif } /* new bottom address */ Baddr = addr + size; /* new bottom block */ tp = ((TREE*) addr); SIZE(tp) = size - 2*WORDSIZE; /**/ASSERT((SIZE(tp)%WORDSIZE) == 0); /* reserved the last word to head any noncontiguous memory */ SETBIT0(SIZE(NEXT(tp))); if(bp && bp != tp) { /* non-contiguous memory, free old bottom block */ /**/ ASSERT(!Lfree && QVOID()); SETBIT0(SIZE(bp)); ENQUEUE(DATA(bp)); } return tp; } /* ** Tree rotation functions */ #define RROTATE(t,r) (t = LEFT(r), LEFT(r) = RIGHT(t), RIGHT(t) = r, r = t) #define LROTATE(t,r) (t = RIGHT(r), RIGHT(r) = LEFT(t), LEFT(t) = r, r = t) #define RLINK(r,s,x) (r ? (s = LEFT(s) = x) : (r = s = x)) #define LLINK(r,s,x) (r ? (s = RIGHT(s) = x) : (r = s = x)) #define RTWICE(t,r) (LEFT(LEFT(r)) = RIGHT(t), RIGHT(t) = r, r = t) #define LTWICE(t,r) (RIGHT(RIGHT(r)) = LEFT(t), LEFT(t) = r, r = t) /* ** Look up a suitable element in the tree. If found, delete it from ** the tree and return its address. ** This uses the top-down splay strategy. */ static TREE *t_search(size) reg int size; { reg int cmp; reg TREE *t, *del, *left, *right, *lroot, *rroot; /* find the right one to delete */ del = Root; lroot = rroot = NIL(TREE*); while(del) { /**/ ASSERT(!ISBITS01(size) && !ISBITS01(SIZE(del))); if((cmp = size - SIZE(del)) == 0) break; if(cmp < 0) { if((t = LEFT(del)) == NIL(TREE*)) { RLINK(rroot,right,del); del = NIL(TREE*); } else if((cmp = size - SIZE(t)) <= 0) { /* left,left case */ RROTATE(t,del); if(cmp == 0) break; RLINK(rroot,right,del); del = LEFT(del); } else { /* left, right case */ RLINK(rroot,right,del); LLINK(lroot,left,t); del = RIGHT(t); } } else { if((t = RIGHT(del)) == NIL(TREE*)) { LLINK(lroot,left,del); del = NIL(TREE*); } else if((cmp = size - SIZE(t)) >= 0) { /* right, right case */ LROTATE(t,del); if(cmp == 0) break; LLINK(lroot,left,t); del = RIGHT(del); } else { /* right, left case */ LLINK(lroot,left,del); RLINK(rroot,right,t); del = LEFT(t); } } } if(del) { if(lroot) { RIGHT(left) = LEFT(del); LEFT(del) = lroot; } if(rroot) { LEFT(right) = RIGHT(del); RIGHT(del) = rroot; } } else { if(lroot) RIGHT(left) = NIL(TREE*); if(rroot) { /* get least one > size */ LEFT(right) = NIL(TREE*); while(LEFT(rroot)) { /* left zig-zig case */ if((t = LEFT(LEFT(rroot))) != NIL(TREE*)) RTWICE(t,rroot); else RROTATE(t,rroot); } LEFT(rroot) = lroot; del = rroot; } else { Root = lroot; return NIL(TREE*); } } if((t = LINK(del)) != NIL(TREE*)) { /* start of a non-singleton list */ LEFT(t) = LEFT(del); RIGHT(t) = RIGHT(del); Root = t; /**/ ASSERT(!ISNOTREE(t)); } else { /**/ DISCOUNT(N_list); if((right = RIGHT(del)) != NIL(TREE*)) { /* make least elt of right tree the root */ while(LEFT(right)) { /* left zig-zig case */ if((t = LEFT(LEFT(right))) != NIL(TREE*)) RTWICE(t,right); else RROTATE(t,right); } LEFT(right) = LEFT(del); Root = right; } else Root = LEFT(del); } /**/ DISCOUNT(N_block); return del; } #endif /* cray */ 0707070000000001451006440044230044230000010000000475356526700003100000020504misc/optget.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * command line option parse assist */ char* opt_arg; /* {:,#} string argument */ char** opt_argv; /* most recent argv */ int opt_char; /* char pos in argv[opt_index] */ int opt_index; /* argv index */ char* opt_msg; /* error/usage message buffer */ long opt_num; /* # numeric argument */ char opt_option[3]; /* current flag {-,+} + option */ int opt_pchar; /* prev opt_char for backup */ int opt_pindex; /* prev opt_index for backup */ static char* opt_opts[8]; /* cached opts arguments */ static int opt_nopt; /* opt_opts[] index */ #define elements(x) (sizeof(x)/sizeof(x[0])) #define OPT_MSG 512 static int error(); extern char* malloc(); extern char* optusage(); extern long strtol(); /* * argv: command line argv where argv[0] is command name * * opts: option control string * * ':' option takes string arg * '#' option takes numeric arg (concat option may follow) * '?' (first) following options not in usage * (following # or :) optional arg * (following option or ]) remaining not in usage * '['...']' (following # or :) optional option arg description * (otherwise) mutually exclusive option grouping * ' '... optional argument(s) description (to end of string) * * return: * * 0 no more options * '?' usage: opt_arg points to message sans `Usage: command' * ':' error: opt_arg points to message sans `command:' * * -- or ++ terminates option list and returns 0 * * -? puts usage message sans command name in opt_arg and returns '?' * * if any # option is specified then numeric options (e.g., -123) * are associated with the leftmost # option in opts */ int optget(argv, opts) register char** argv; char* opts; { register int c; register char* s; int n; char* e; opt_pindex = opt_index; opt_pchar = opt_char; for (;;) { if (!opt_index) { opt_index = 1; opt_char = 0; } if (!opt_char) { if (opt_index == 1) { opt_argv = argv; opt_nopt = 0; if (*opts != '?') opt_opts[opt_nopt++] = opts; } if (!(s = argv[opt_index]) || (opt_option[0] = *s++) != '-' && opt_option[0] != '+' || !*s) return(0); if (*s++ == opt_option[0] && !*s) { opt_index++; return(0); } opt_char++; } if (c = opt_option[1] = argv[opt_index][opt_char++]) break; opt_char = 0; opt_index++; } if ((!opt_nopt || opt_opts[opt_nopt - 1] != opts) && opt_nopt < elements(opt_opts) && *opts != '?') { n = 0; do if (n >= opt_nopt) { opt_opts[opt_nopt++] = opts; break; } while (opt_opts[n++] != opts); } if (c == '?') { opt_arg = optusage((char*)0); return(c); } e = 0; if (c == ':' || c == '#' || c == ' ' || c == '[' || c == ']') s = ""; else { s = opts; while (*s) { if (*s == c) break; if (*s == ' ') { s = ""; break; } if (*s == ':' || *s == '#') { if (*++s == '?') s++; if (*s == '[') { n = 1; while (*++s) { if (*s == '[') n++; else if (*s == ']' && !--n) { s++; break; } } n = 0; } } else { if (!e && *s == '#' && s > opts) e = s - 1; s++; } } } if (!*s) { if (c < '0' || c > '9' || !e) return(error("")); c = opt_option[1] = *(s = e); opt_char--; } opt_arg = 0; if (*++s == ':' || *s == '#') { if (*(opt_arg = &argv[opt_index++][opt_char])) { if (*s == '#') { opt_num = strtol(opt_arg, &e, 0); if (e == opt_arg) { if (*(s + 1) == '?') { opt_arg = 0; opt_index--; return(c); } else c = error(s); } else if (*e) { opt_char += e - opt_arg; opt_index--; return(c); } } } else if (opt_arg = argv[opt_index]) { opt_index++; if (*(s + 1) == '?' && (*opt_arg == '-' || *opt_arg == '+')) { if (*(opt_arg + 1)) opt_index--; opt_arg = 0; } else if (*s == '#') { opt_num = strtol(opt_arg, &e, 0); if (*e) { if (*(s + 1) == '?') { opt_arg = 0; opt_index--; } else c = error(s); } } } else if (*(s + 1) != '?') c = error(s); opt_char = 0; } return(c); } /* * return pointer to usage message sans `Usage: command' * if opts is 0 then opt_opts is used */ char* optusage(opts) char* opts; { register int c; register char* p; register char* s; register char* t; char* b; char* x; char* z; char** o; char** v; char** e; int n; int m; if (opts) { o = &opts; e = o + 1; } else { o = opt_opts; e = o + opt_nopt; } if (e == o) return("[* call optget() before optusage() *]"); if (!opt_msg && !(opt_msg = malloc(OPT_MSG))) return("[* out of space *]"); s = opt_msg; for (v = o; v < e; v++) { p = *v; while ((c = *p++) && c != ' ' && c != '?') { if (c == '[') { if (s != opt_msg) *s++ = ' '; *s++ = '['; b = s; m = 1; for (;;) { if (!(c = *p)) break; p++; if (c == '[') { m++; if (s != b) { *s++ = ' '; *s++ = '|'; *s++ = ' '; } *s++ = '['; b = s; } else if (c == ']') { *s++ = ']'; if (!--m) break; } else { if (s != b) { *s++ = ' '; *s++ = '|'; *s++ = ' '; } *s++ = '-'; *s++ = c; if (*p == ':' && (t = "arg") || *p == '#' && (t = "num")) { if (c = (*++p == '?')) { p++; *s++ = '['; } else *s++ = ' '; if (*p == '[') { n = 1; while (*s = *++p) { if (*p == '[') n++; else if (*p == ']' && !--n) { p++; break; } s++; } } else while (*s = *t++) s++; if (c) *s++ = ']'; } } } } else if (*p == ':' || *p == '#') { if (*++p == '?') p++; if (*p == '[') { n = 1; while (*++p) { if (*p == '[') n++; else if (*p == ']' && !--n) { p++; break; } } } } } } b = s; for (v = o; v < e; v++) { p = *v; while ((c = *p++) && c != ' ' && c != '?') { if (c == '[') { m = 1; for (;;) { if (!(c = *p)) break; p++; if (c == '[') m++; else if (c == ']' && !--m) break; } } else if (*p == ':' || *p == '#') { if (*++p == '?') p++; if (*p == '[') { n = 1; while (*++p) { if (*p == '[') n++; else if (*p == ']' && !--n) { p++; break; } } } } else { if (s == b) { if (s != opt_msg) *s++ = ' '; *s++ = '['; *s++ = '-'; } *s++ = c; } } } if (s != b) *s++ = ']'; x = 0; z = 0; for (v = o; v < e; v++) { p = *v; while (c = *p++) { if (c == '[') { m = 1; for (;;) { if (!(c = *p)) break; p++; if (c == '[') m++; else if (c == ']' && !--m) break; } } else if (c == ' ') { x = p; break; } else if (c == '?') z = s; else if (*p == ':' && (t = "arg") || *p == '#' && (t = "num")) { if (s != b) *s++ = ' '; *s++ = '['; *s++ = '-'; *s++ = c; if (c = (*++p == '?')) { p++; *s++ = '['; } else *s++ = ' '; if (*p == '[') { n = 1; while (*s = *++p) { if (*p == '[') n++; else if (*p == ']' && !--n) { p++; break; } s++; } } else while (*s = *t++) s++; if (c) *s++ = ']'; *s++ = ']'; if (z) s = z; } } } if (p = x) { if (s != opt_msg) *s++ = ' '; while (*s = *p++) s++; } return(opt_msg); } /* * point opt_arg to an error message for opt_option * p points to opts location for opt_option * optget() return value is returned */ static int error(p) register char* p; { register char* s; register char* t; int n; if (!opt_msg && !(opt_msg = malloc(OPT_MSG))) opt_arg = "[* out of space *]"; else { s = opt_arg = opt_msg; *s++ = opt_option[0]; *s++ = opt_option[1]; *s++ = ':'; *s++ = ' '; if (*p == '#' || *p == ':') { if (*p == '#') { t = "numeric "; while (*s = *t++) s++; } if (*++p == '[') { n = 1; while (*s = *++p) { if (*s == '[') n++; else if (*s == ']' && !--n) break; s++; } *s++ = ' '; } p = "argument expected"; } else p = "unknown option"; while (*s++ = *p++); } return(':'); } 0707070000000001461006440044230044230000010000000474310516700003500000002731misc/pathaccess.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return path to file a/b with access mode using : separated dirs * both a and b may be 0 * if (mode&PATH_REG) then path must not be a directory * if (mode&PATH_ABS) then path must be rooted * path returned in path buffer */ #include <limits.h> #include <sys/types.h> #include <sys/stat.h> #define PATH_RWX 007 #define PATH_REG 010 #define PATH_ABS 020 #ifndef PATH_MAX #define PATH_MAX 1024 #endif static char* pathcat(); extern int access(); extern char* getcwd(); extern char* pathcanon(); char* pathaccess(path, dirs, a, b, mode) register char* path; register char* dirs; char* a; char* b; register int mode; { int sep = ':'; char cwd[PATH_MAX]; struct stat st; do { dirs = pathcat(path, dirs, sep, a, b); (void)pathcanon(path); if (!access(path, mode & PATH_RWX)) { if ((mode & PATH_REG) && (stat(path, &st) || (st.st_mode & S_IFMT) == S_IFDIR)) continue; if (*path == '/' || !(mode & PATH_ABS)) return(path); dirs = getcwd(cwd, sizeof(cwd)); sep = 0; } } while (dirs); return(0); } /* * single dir support for pathaccess() */ static char* pathcat(path, dirs, sep, a, b) char* path; register char* dirs; int sep; char* a; register char* b; { register char* s; s = path; while (*dirs && *dirs != sep) *s++ = *dirs++; if (s != path) *s++ = '/'; if (a) { while (*s = *a++) s++; if (b) *s++ = '/'; } else if (!b) b = "."; if (b) while (*s++ = *b++); return(*dirs ? ++dirs : 0); } 0707070000000001471006440044230044230000010000000460171260700003400000002736misc/pathcanon.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * in-place path name canonicalization -- preserves the logical view * pointer to trailing 0 in path returned * * remove redundant .'s and /'s * move ..'s to the front * /.. preserved (for pdu and newcastle hacks) * FS_3D handles ... * * longer pathname possible if FS_3D ... involved */ char* pathcanon(path) char* path; { register char* r; register char* s; register char* t; register int dots; dots = 0; r = s = t = path; for (;;) switch (*t++ = *s++) { case '.': dots++; break; case 0: s--; /*FALLTHROUGH*/ case '/': while (*s == '/') s++; switch (dots) { case 1: t -= 2; break; case 2: if (t - 5 < r) r = t; else for (t -= 5; t > r && *(t - 1) != '/'; t--); break; case 3: #if defined(FS_3D) { char* x; char* o; int c; extern char* pathnext(); o = t; if ((t -= 5) <= path) t = path + 1; c = *t; *t = 0; if (x = pathnext(path, s - (*s != 0))) { r = path; if (t == r + 1) x = r; s = t = x; } else { *t = c; t = o; } } #else r = t; #endif break; } if (!*s) { if (t > path && !*(t - 1)) t--; if (t == path) *t++ = '.'; #if DONT_PRESERVE_TRAILING_SLASH else if (t > path + 1 && *(t - 1) == '/') t--; #else else if ((s <= path || *(s - 1) != '/') && t > path + 1 && *(t - 1) == '/') t--; #endif *t = 0; return(t); } dots = 0; break; default: dots = 4; break; } } 0707070000000001501006440044230044230000010000000471404133700003400000000306misc/pathcheck.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * no-op stub for runtime validation * the tool name and argv[0] are passed */ /*ARGSUSED*/ void pathcheck(tool, arg0) char* tool; char* arg0; { } 0707070000000001511006440044230044230000010000000475330642500003200000010735misc/pathkey.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * generate 14 char lookup key for lang path in key * based on 32-bit checksum on path * * if key==0 then space is malloc'd * if attr != 0 then attribute var assignments placed here: * ATTRIBUTES list of attribute names */ #include <limits.h> #include <ctype.h> #include <preroot.h> #include <stdio.h> #define elements(x) (sizeof(x)/sizeof(x[0])) char* pathkey(key, attr, lang, path) char* key; char* attr; char* lang; register char* path; { register char* s; register char* k; char* t; char* flags; char** p; int c; unsigned long n; char buf[15]; char* usr[16]; char* env[elements(usr) + 3]; char* ver[2]; char tmp[PATH_MAX]; extern char* getenv(); extern int getuniv(); extern unsigned long memsum(); extern char* strcopy(); extern char* strdup(); extern int strlen(); extern char* strchr(); extern char* strrchr(); extern char** environ; for (c = 0; c < elements(env); c++) env[c] = 0; if (!key) key = buf; n = 0; /* * trailing flags in path */ if (flags = strchr(path, ' ')) { if (flags == path) flags = 0; else { (void)strcpy(tmp, path); *(flags = tmp + (flags - path)) = 0; path = tmp; } } /* * 3D */ if (fs3d(2) && (c = mount(path, tmp, 012|(PATH_MAX<<4))) > 1 && c < PATH_MAX) path = tmp; /* * preroot */ if (attr) attr = strcopy(attr, "PREROOT='"); #if FS_PREROOT if (k = getenv(PR_BASE)) { if (s = strrchr(k, '/')) k = s + 1; n = memsum(k, strlen(k), n); } if (attr && (getpreroot(attr, path) || getpreroot(attr, (char*)0))) attr += strlen(attr); #else if ((k = getenv("VIRTUAL_ROOT")) && *k == '/') { n = memsum(k, strlen(k), n); if (attr) attr = strcopy(attr, k); } #endif /* * universe */ if (attr) attr = strcopy(attr, "' UNIVERSE='"); if (!getuniv(buf)) { n = memsum(buf, strlen(buf), n); if (attr) attr = strcopy(attr, buf); } /* * environment * * ${VERSION_ENVIRONMENT} : list of alternate env vars * ${VERSION_<lang>} * ${VERSION_<base(path)>} * ${<toupper(base(path))>VER} */ if (attr) *attr++ = '\''; k = getenv("VERSION_ENVIRONMENT"); c = 0; while (c < elements(usr)) { usr[c++] = k; if (k) for (;;) { if (!*k) { k = 0; break; } if (*k++ == ':') break; } } ver[0] = lang; ver[1] = k = (s = strrchr(path, '/')) ? s + 1 : path; s = buf; if (isdigit(*k)) { if (*k == '3' && *(k + 1) == 'b') { /* * cuteness never pays */ k += 2; *s++ = 'B'; *s++ = 'B'; *s++ = 'B'; } else *s++ = 'U'; } for (; (c = *k) && s < &buf[sizeof(buf) - 1]; k++) { if (!isalnum(c)) c = '_'; else if (islower(c)) c = toupper(c); *s++ = c; } *s = 0; for (p = environ; *p; p++) { s = "VERSION_"; for (k = *p; *k && *k == *s; k++, s++); if (*k && !*s) { for (c = 0; c < elements(ver); c++) if (!env[c] && (s = ver[c])) { for (t = k; *t && *t != '=' && *t++ == *s; s++); if (*t == '=' && (!*s || (s - ver[c]) > 1)) { env[c] = *p; goto found; } } } if (!env[2]) { s = buf; for (k = *p; *k && *s++ == *k; k++); if ((s - buf) > 2 && k[0] == 'V' && k[1] == 'E' && k[2] == 'R' && k[3] == '=') { env[2] = *p; goto found; } } for (c = 0; c < elements(usr) && (s = usr[c]); c++) if (!env[c + elements(env) - elements(usr)]) { for (k = *p; *k && *k == *s; k++, s++); if (*k == '=' && (!*s || *s == ':')) { env[c + elements(env) - elements(usr)] = *p; goto found; } } found: ; } for (c = 0; c < elements(env); c++) if (k = env[c]) { if (attr) { *attr++ = ' '; while ((*attr++ = *k++) != '='); *attr++ = '\''; attr = strcopy(attr, k); *attr++ = '\''; } else while (*k && *k++ != '='); n = memsum(k, strlen(k), n); } if (attr) { attr = strcopy(attr, " ATTRIBUTES='PREROOT UNIVERSE"); for (c = 0; c < elements(env); c++) if (k = env[c]) { *attr++ = ' '; while ((*attr = *k++) != '=') attr++; } *attr++ = '\''; *attr = 0; } /* * now the normal stuff */ if (flags) *flags = ' '; s = path + strlen(path); (void)sprintf(key, "%08lX", memsum(path, s - path, n)); k = key + 14; *k = 0; if (!flags) t = path; else if ((t = s - 4) < flags) t = flags + 1; for (;;) { if (--s < t) { if (t == path) break; s = flags - 2; t = path; } if (*s != '/' && *s != ' ') { *--k = *s; if (k <= key + 8) break; } } while (k > key + 8) *--k = '.'; return(key == buf ? strdup(key) : key); } 0707070000000001521006440044230044230000010000000475401160400003300000002547misc/pathpath.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return full path to p with mode access using $PATH * if a!=0 then it and $0 and $_ with $PWD are used for * related root searching * the related root must have a bin subdir * full path returned in path buffer */ extern char* getenv(); extern char* pathaccess(); extern char* strchr(); extern char* strcopy(); char* pathpath(path, p, a, mode) register char* path; char* p; char* a; int mode; { register char* s; char* x; extern char** environ; extern char** opt_argv; static char* cmd; if (s = a) { x = s; a = p; p = ".."; if (strchr(s, '/') || ((s = cmd) || opt_argv && (s = *opt_argv)) && strchr(s, '/') || (s = *environ) && *s++ == '_' && *s++ == '=' && strchr(s, '/') || *x && !access(x, 0) && (s = getenv("PWD")) && *s == '/') { if (!cmd) cmd = s; s = strcopy(path, s); for (;;) { do if (s <= path) goto normal; while (*--s == '/'); do if (s <= path) goto normal; while (*--s != '/'); (void)strcpy(s + 1, "bin"); if (!access(path, 0)) { if (s = pathaccess(path, path, p, a, mode)) return(s); goto normal; } } normal: ; } } if (!a && strchr(p, '/')) x = ""; else if (!(x = getenv("PATH"))) x = ":/bin:/usr/bin"; if (!(s = pathaccess(path, x, p, a, mode)) && !*x && (x = getenv("FPATH"))) s = pathaccess(path, x, p, a, mode); return(s); } 0707070000000001531006440044230044230000010000000475507470200003400000004433misc/pathprobe.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return in path the full path name of the probe(1) * information for lang and tool using proc * if attr != 0 then path attribute assignments placed here * * if path==0 then the space is malloc'd * * op: * * -1 return path name with no generation * 0 verbose probe * 1 silent probe * * 0 returned if the info does not exist and cannot be generated */ #include <limits.h> #include <ls.h> #ifndef PROBE #define PROBE "probe" #endif #ifndef PATH_MAX #define PATH_MAX 1024 #endif extern int access(); extern int cmdrun(); extern char* malloc(); extern char* pathpath(); extern char* pathkey(); extern int stat(); extern char* strchr(); extern char* strcopy(); extern char* strcpy(); extern char* strncpy(); extern char* strdup(); char* pathprobe(path, attr, lang, tool, proc, op) char* path; char* attr; char* lang; char* tool; char* proc; int op; { register char* p; register char* k; register char** ap; int n; char* e; char* probe; char buf[PATH_MAX]; char cmd[PATH_MAX]; char lib[PATH_MAX]; char* arg[6]; time_t ptime; struct stat st; if (*proc != '/') { if (p = strchr(proc, ' ')) { n = p - proc; proc = strncpy(buf, proc, n); *(proc + n) = 0; } if (!(proc = pathpath(cmd, proc, (char*)0, 031))) return(0); if (p) (void)strcpy(proc + strlen(proc), p); } if (!path) path = buf; probe = PROBE; p = strcopy(lib, "lib/"); p = strcopy(p, probe); *p++ = '/'; p = strcopy(k = p, lang); *p++ = '/'; p = strcopy(p, tool); *p++ = '/'; e = strcopy(p, probe); if (!pathpath(path, lib, "", 021) || stat(path, &st)) return(0); ptime = st.st_mtime; (void)pathkey(p, attr, lang, proc); p = path + strlen(path) - (e - k); (void)strcpy(p, k); if (op >= 0 && !stat(path, &st)) { if (ptime <= st.st_mtime || ptime <= st.st_ctime) op = -1; else if (st.st_mode & S_IWUSR) { if (op == 0) error(0, "%s probe information for %s language processor %s must be manually regenerated", tool, lang, proc); op = -1; } } if (op >= 0) { (void)strcpy(p, probe); ap = arg; *ap++ = path; if (op > 0) *ap++ = "-s"; *ap++ = lang; *ap++ = tool; *ap++ = proc; *ap = 0; if (cmdrun(path, arg)) return(0); (void)strcpy(p, k); if (access(path, 4)) return(0); } return(path == buf ? strdup(path) : path); } 0707070000000001541006440044230044230000010000000473127621400003300000003552misc/pathtemp.c Ugsf Ggsf /* * AT&T Bell Laboratories * * generate a temp file path name * * [<dir>/][<pfx>]<pid><suf> * * length(<suf>)==3 * length(<pfx>)<=PREFIX * length(<pfx>)+length(<pid>)+length(<suf>)==BASE * * tmpnam(p) pathtemp(p, 0, 0) * tempnam(d, p) pathtemp(0, d, p) * * if buf==0 then space is malloc'd * otherwise sizeof(buf) must be >= strlen(dir) + BASE + 2 * dir and pfx may be 0 * if dir is 0 then sizeof(buf) must be >= TOTAL or it must * be a previous pathtemp() return with the same dir and pfx * only first PREFIX chars of pfx are used */ #define TOTAL 128 #define BASE 14 #define PREFIX 6 #define TMPENV "TMPDIR" #define TMP1 "/tmp" #define TMP2 "/usr/tmp" #define LOSEED 'a' #define HISEED 'z' extern char* getenv(); extern char* malloc(); extern int access(); extern int strlen(); char* pathtemp(buf, dir, pfx) char* buf; register char* dir; char* pfx; { register char* p; register char* s; int pid; static char* tmpdir; static char seed[] = { LOSEED - 1, LOSEED, LOSEED, 0 }; if ((!dir || *dir && access(dir, 3)) && !(dir = tmpdir)) { if ((!(dir = getenv(TMPENV)) || !*dir || strlen(dir) >= (TOTAL - BASE - 2) || access(dir, 3)) && access(dir = TMP1, 3) && access(dir = TMP2, 3)) return(0); tmpdir = dir; } if (!(s = buf) && !(s = malloc(strlen(dir) + BASE + 2))) return(0); for (p = s; *p = *dir++; p++); if (p > s && *(p - 1) != '/') *p++ = '/'; if (pfx) { dir = pfx; pfx = p; while (*dir && p < pfx + PREFIX) *p++ = *dir++; } else pfx = p; pfx = dir = p + (BASE - (p - pfx) - sizeof(seed) + 1); pid = getpid(); while (--dir >= p) { *dir = pid % 10 + '0'; pid /= 10; } p = pfx; dir = seed; while (*p++ = *dir++); do { for (p = pfx; *p == HISEED; *p++ = LOSEED); if (!*p) { if (!buf) free(s); s = 0; break; } ++*p; } while (!access(s, 0)); p = seed; dir = pfx; while (*p++ = *dir++); return(s); } 0707070000000001551006440044230044230000010000000474114261300003100000000664misc/perror.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * perror() using strerror() */ #include <stdio.h> #include "FEATURE/strerror" #ifdef _lib_strerror int _lib_dummy; #else extern int errno; extern int write(); extern char* strerror(); void perror(s) char* s; { char buf[1024]; if (s && *s) sprintf(buf, "%s: %s\n", s, strerror(errno)); else sprintf(buf, "%s\n", strerror(errno)); (void)write(2, buf, strlen(buf)); } #endif 0707070000000001561006440044230044230000010000000475137333500003100000003546misc/putenv.c Ugsf Ggsf /* * put name=value in the environment * pointer to name=value returned * environ==0 is ok * * putenv("N=V") add N=V * putenv("N") delete N * putenv(0) expect more (pre-fork optimization) * * _ always placed at the top */ #define INCREMENT 16 /* environ increment */ extern char** environ; extern char* malloc(); extern char* realloc(); extern char* strchr(); char* putenv(key) char* key; { static char** envv; /* recorded environ */ static char** next; /* next free slot */ static char** last; /* last free slot (0) */ register char** v = environ; register char** p = envv; register char* s; register char* t; int n; if (p && !v) { next = p; *++next = 0; } else if (p != v || !v) { if (v) { while (*v++); n = v - environ + INCREMENT; v = environ; } else n = INCREMENT; if (!p || (last - p + 1) < n) { if (p) free(p); else if (fs3d(2)) { (void)close(open(".", 0)); v = environ; } if (!(p = (char**)malloc(n * sizeof(char**)))) return(0); last = p + n - 1; } envv = environ = p; if (v && v[0] && v[0][0] == '_' && v[0][1] == '=') *p++ = *v++; else *p++ = "_="; if (!v) *p = 0; else while (*p = *v++) if (p[0][0] == '_' && p[0][1] == '=') envv[0] = *p; else p++; next = p; p = envv; } else if (next == last) { n = last - v + INCREMENT + 1; if (!(p = (char**)realloc(p, n * sizeof(char**)))) return(0); last = p + n - 1; next = last - INCREMENT; envv = environ = p; } if (!key) return(*p); for (; s = *p; p++) { t = key; do { if (!*t || *t == '=') { if (*s == '=') { if (!*t) { s = *p; v = p++; while (*v++ = *p++); next--; return(s); } return(*p = key); } break; } } while (*t++ == *s++); } if (!strchr(key, '=')) return(key); p = next; *++next = 0; return(*p = key); } 0707070000000001571006440044230044230000010000000475326177400003500000001603misc/putsymlink.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories */ #include "univlib.h" extern int symlink(); /* * create symbolic name from external representation text in buf * the arg order matches link(2) */ int putsymlink(buf, name) char* buf; char* name; { register char* t = buf; #ifdef UNIV_MAX register char* s = buf; register char* v; int n; char tmp[PATH_MAX]; extern int strncmp(); while (*s) { if (*s++ == univ_cond[0] && !strncmp(s - 1, univ_cond, univ_size)) { s--; t = tmp; for (n = 0; n < UNIV_MAX; n++) if (*univ_name[n]) { *t++ = ' '; #ifdef ATT_UNIV *t++ = '1' + n; *t++ = ':'; #else for (v = univ_name[n]; *t = *v++; t++); *t++ = '%'; #endif for (v = buf; v < s; *t++ = *v++); for (v = univ_name[n]; *t = *v++; t++); for (v = s + univ_size; *t = *v++; t++); } t = tmp; break; } } #endif return(symlink(t, name)); } 0707070000000001601006440044230044230000010000000473215504000003000000002451misc/query.c Ugsf Ggsf /* * AT&T Bell Laboratories * * output printf prompt and read response * if format==0 then verify that interaction is possible * * return: * * 0 [1yY+] * -1 [qQ] or EOF * 1 otherwise * * if quit>=0 then [qQ] or EOF calls exit(quit) */ #include <stdio.h> extern int errno; #if __STDC__ #include <stdarg.h> int query(int quit, char* format, ...) #else #include <varargs.h> int query(va_alist) va_dcl #endif { va_list ap; register int n; register int c; #if !__STDC__ int quit; char* format; #endif static FILE* rfp; static FILE* wfp; if (!rfp) { c = errno; if (isatty(fileno(stdin))) rfp = stdin; else if (!(rfp = fopen("/dev/tty", "r"))) return(-1); if (isatty(fileno(stderr))) wfp = stderr; else if (!(wfp = fopen("/dev/tty", "w"))) return(-1); errno = c; } #if __STDC__ va_start(ap, format); #else va_start(ap); quit = va_arg(ap, int); format = va_arg(ap, char*); #endif if (!format) return(0); fflush(stdout); vfprintf(wfp, format, ap); fflush(wfp); for (n = c = getc(rfp);; c = getc(rfp)) switch (c) { case EOF: n = c; /*FALLTHROUGH*/ case '\n': switch (n) { case EOF: case 'q': case 'Q': if (quit >= 0) exit(quit); return(-1); case '1': case 'y': case 'Y': case '+': return(0); default: return(1); } } va_end(ap); } 0707070000000001611006440044230044230000010000000434534132200003100000002730misc/setcwd.c Ugsf Ggsf /* * K. P. Vo * G. S. Fowler * AT&T Bell Laboratories */ #include <limits.h> #include <errno.h> #ifndef PATH_MAX #define PATH_MAX 1024 #endif extern int errno; #if DEBUG #undef PATH_MAX #define PATH_MAX 16 static int vchdir(path) char* path; { int n; if (strlen(path) >= PATH_MAX) { errno = ENAMETOOLONG; n = -1; } else n = chdir(path); liberror("setcwd", -1, "chdir(%s)=%d", path, n); return(n); } #define chdir(p) vchdir(p) #endif /* * set the current directory to path * if path is long and home!=0 then setcwd(home,0) * is called on intermediate chdir errors */ int setcwd(path, home) register char* path; char* home; { register char* s; register int n; int r; r = 0; for (;;) { /* * this should work 99% of the time */ if (!chdir(path)) return(r); /* * chdir failed */ n = strlen(path); if (n < PATH_MAX) return(-1); #ifdef ENAMETOOLONG if (errno != ENAMETOOLONG) return(-1); #endif /* * path is too long */ for (;;) { /* * get a short prefix component */ s = path + PATH_MAX; while (--s >= path) if (*s == '/') break; if (s <= path) break; /* * chdir to the prefix */ *s = '\0'; if (chdir(path)) break; *s++ = '/'; /* * do the remainder */ if ((n -= s - path) < PATH_MAX) { if (chdir(s)) break; return(r); } path = s; } /* * try to recover back to home */ if (!(path = home)) return(-1); home = 0; r = -1; } } 0707070000000001621006440044230044230000010000000475327610200003200000001244misc/setuniv.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * set universe by name */ #include "univlib.h" #define streq(a,b) (*(a)==*(b)&&!strcmp(a,b)) int setuniv(buf) char* buf; { #if _lib_getuniverse return(setuniverse(buf)); #else #ifndef UNIV_MAX char tmp[32]; extern char* putenv(); extern char* strdup(); (void)sprintf(tmp, "%s=%-*.*s", univ_env, UNIV_SIZE - 1, UNIV_SIZE - 1, buf); if ((buf = strdup(tmp)) && putenv(buf)) return(0); errno = ENOMEM; return(-1); #else #ifdef ATT_UNIV register int n; for (n = 0; n < UNIV_MAX; n++) if (streq(buf, univ_name[n])) return(setuniverse(n + 1) >= 0 ? 0 : -1); #endif errno = EINVAL; return(-1); #endif #endif } 0707070000000001631006440044230044230000010000000471770731000003200000004521misc/sigcrit.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * signal critical region support */ #include <sig.h> #define elements(x) (sizeof(x)/sizeof(x[0])) #include "FEATURE/sigsetmask" static int signals[] = /* held inside critical region */ { SIGINT, SIGQUIT, SIGHUP, }; #ifndef SIG_SETMASK #ifndef _lib_sigsetmask static long hold; /* held signal mask */ /* * hold last signal for later delivery */ static void interrupt(sig) int sig; { (void)signal(sig, interrupt); hold |= sigmask(sig); } #endif #endif /* * critical signal region handler * * op>0 push region, return region level * op==0 pop region, return region level * op<0 return non-zero if any signals held in current region * * signals[] held until region popped */ int sigcritical(op) int op; { register int i; static int level; #ifdef SIG_SETMASK static sigset_t mask; sigset_t nmask; #else #ifdef _lib_sigsetmask static long mask; #else static signal_t handler[elements(signals)]; #endif #endif if (op > 0) { if (!level++) { #ifdef SIG_SETMASK (void)sigemptyset(&nmask); for (i = 0; i < elements(signals); i++) (void)sigaddset(&nmask, signals[i]); (void)sigprocmask(SIG_BLOCK, &nmask, &mask); #else #ifdef _lib_sigsetmask mask = 0; for (i = 0; i < elements(signals); i++) mask |= sigmask(signals[i]); mask = sigblock(mask); #else hold = 0; for (i = 0; i < elements(signals); i++) if ((handler[i] = signal(signals[i], interrupt)) == SIG_IGN) { (void)signal(signals[i], SIG_IGN); hold &= ~sigmask(signals[i]); } #endif #endif } return(level); } else if (!op) { if (!--level) { #ifdef SIG_SETMASK (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t*)0); #else #ifdef _lib_sigsetmask (void)sigsetmask(mask); #else for (i = 0; i < elements(signals); i++) (void)signal(signals[i], handler[i]); if (hold) { for (i = 0; i < elements(signals); i++) if (hold & sigmask(signals[i])) (void)kill(getpid(), signals[i]); (void)pause(); } #endif #endif } return(level); } else { #ifdef SIG_SETMASK (void)sigpending(&nmask); for (i = 0; i < elements(signals); i++) if (sigismember(&nmask, signals[i])) return(1); return(0); #else #ifdef _lib_sigsetmask /* no way to get pending signals without installing handler */ return(0); #else return(hold != 0); #endif #endif } } 0707070000000001641006440044230044230000010000000471771116600003000000005225misc/stack.c Ugsf Ggsf /* * G. S. Fowler * * stack routines */ #include "stack.h" #if !lint static char id[] = "\n@(#)stack (AT&T Bell Laboratories) 05/01/84\0\n"; #endif extern char *malloc(); /* * create a new stack */ STACK mkstack(size, error) register int size; char *error; { register STACK stack; register struct stackblock *b; if (size <= 0) size = 100; if (!(stack = (STACK)malloc(sizeof(struct stacktable)))) return((STACK)0); if (!(b = (struct stackblock*)malloc(sizeof(struct stackblock)))) { free(stack); return((STACK)0); } if (!(b->stack = (char**)malloc(sizeof(char*)*size))) { free(b); free(stack); return((STACK)0); } stack->blocks = b; stack->size = size; stack->error = error; stack->position.block = b; stack->position.index = -1; b->next = (struct stackblock*)0; b->prev = (struct stackblock*)0; return(stack); } /* * remove a stack */ void rmstack(stack) register STACK stack; { register struct stackblock *b; for (b = stack->blocks; b; b = b->next) { free(b->stack); free(b); } free(stack); } /* * clear stack */ void clrstack(stack) register STACK stack; { stack->position.block = stack->blocks; stack->position.index = -1; } /* * get value on top of stack */ char* getstack(stack) register STACK stack; { if (stack->position.index < 0) return(stack->error); else return(stack->position.block->stack[stack->position.index]); } /* * push value on to stack */ int pushstack(stack, value) register STACK stack; char *value; { register struct stackblock *b; if (++stack->position.index >= stack->size) { b = stack->position.block; if (!b->next) { if (!(b->next = (struct stackblock*)malloc(sizeof(struct stackblock)))) return(-1); b = b->next; if (!(b->stack = (char**)malloc(sizeof(char*)*stack->size))) return(-1); b->prev = stack->position.block; b->next = (struct stackblock*)0; stack->position.block = b; } stack->position.index = 0; } stack->position.block->stack[stack->position.index] = value; return(0); } /* * pop value off stack */ int popstack(stack) register STACK stack; { /* * return: * * -1 if stack empty before pop * 0 if stack empty after pop * 1 if stack not empty before & after pop */ if (stack->position.index < 0) return(-1); else if (--stack->position.index < 0) { if (!stack->position.block->prev) return(0); stack->position.block = stack->position.block->prev; stack->position.index = stack->size - 1; return(1); } else return(1); } /* * set|get stack position */ void posstack(stack, set, position) register STACK stack; int set; STACKPOS *position; { if (set) stack->position = *position; else *position = stack->position; } 0707070000000001651006440044230044230000010000000473060502400002700000020644misc/stak.c Ugsf Ggsf /* * Routines to implement a stack-like storage library * * A stack consists of a link list of variable size frames * The beginning of each frame is initialized with a frame structure * that contains a pointer to the previous frame and a pointer to the * end of the current frame. * * David Korn * AT&T Bell Laboratories * Room 3C-526B * Murray Hill, N. J. 07974 * Tel. x7975 * ulysses!dgk * */ extern char *malloc(); extern char *strcpy(); #ifdef USE_REALLOC /* can only be used when realloc() to smaller size will not move data */ extern char *realloc(); #endif /* USE_REALLOC */ #define _STAK_PRIVATE \ short stakflags; /* stack attributes */ \ struct _stak_ *stakcur; /* current stack pointer */ \ char *stakbase; /* base of current stack frame */ \ char *stakend; /* end of current stack frame */ \ char *(*stakoverflow)(); /* called when malloc fails */ #include "stak.h" #define STAK_MYSIZE 2 /* local argument to stakcreate */ #define STAK_FSIZE (1024*sizeof(int)) #define round(a,b) ((((a)+b)-1)&~((b)-1)) #ifdef STAKSTATS static struct { int create; int delete; int install; int alloc; int copy; int puts; int seek; int set; int grow; int addsize; int delsize; int movsize; } _stakstats; # define increment(x) (_stakstats.x++) # define count(x,n) (_stakstats.x += (n)) #else # define increment(x) # define count(x,n) #endif /* STAKSTATS */ struct frame { char *prev; char *end; }; static char *overflow(); static const char Omsg[] = "malloc failed while growing stack\n"; static int minsize = STAK_FSIZE; Stak_t _stak_cur = { 0, /* stakleft */ (char*)(&_stak_cur), /* staktop */ (char*)(&_stak_cur), /* stakbot */ 1, /* stakref */ 0, /* stakflags */ &_stak_cur, /* stakcur */ (char*)(&_stak_cur), /* stakbase */ (char*)(&_stak_cur), /* stakend */ overflow /* stakoverflow */ }; /* * create a stack * minsize is normally STAK_FSIZE but may be larger when set by _stakgrow() */ Stak_t *stakcreate(flags) register int flags; { register Stak_t *sp; register char *cp; register struct frame *fp; register int size,fsize; if(flags&STAK_MYSIZE) fsize = minsize; #ifndef USE_REALLOC else if(flags&STAK_SMALL) fsize = STAK_FSIZE/16; #endif /* USE_REALLOC */ else fsize = STAK_FSIZE; minsize = STAK_FSIZE; size = fsize + sizeof(struct frame)+sizeof(Stak_t); if((cp=malloc(size))==0) return((Stak_t*)0); increment(create); count(addsize,size); sp = (Stak_t*)cp; sp->stakcur = sp; cp += sizeof(Stak_t); fp = (struct frame*)cp; fp->prev = 0; sp->stakbase = cp; sp->stakref = 1; cp += sizeof(struct frame); sp->staktop = sp->stakbot = cp; sp->stakflags = (flags&STAK_SMALL); sp->stakoverflow = _stak_cur.stakoverflow; sp->stakend = fp->end = cp+fsize; sp->stakleft = fsize; return(sp); } /* * return a pointer to the current stack * if <sp> is not null, it becomes the new current stack * <oflow> becomes the new overflow function */ #if defined(__STDC__) Stak_t *stakinstall(Stak_t *sp, char *(*oflow)(int)) #else Stak_t *stakinstall(sp,oflow) Stak_t *sp; char *(*oflow)(); #endif /* __STDC__ */ { Stak_t *oldsp = _stak_cur.stakcur; increment(install); if(sp) { #ifdef USE_REALLOC register struct frame *fp; register char *cp; /* only works if realloc() to reduce does not relocate */ if(_stak_cur.stakflags&STAK_SMALL) { /* shrink the last frame */ fp = (struct frame*)(cp=_stak_cur.stakbase); if(fp->prev==0) cp = (char*)oldsp; _stak_cur.stakend = fp->end = _stak_cur.staktop; _stak_cur.stakleft = 0; if(realloc(cp,_stak_cur.stakend-cp)!=cp) return(0); } #endif /* USE_REALLOC */ *oldsp = _stak_cur; _stak_cur = *sp; } else sp = oldsp; if(oflow) sp->stakoverflow = (char*(*)())oflow; return(oldsp); } /* * terminate a stack and free up the space */ stakdelete(sp) Stak_t *sp; { register char *cp = sp->stakbase; register struct frame *fp; if(--sp->stakref>0) return(1); increment(delete); while(1) { fp = (struct frame*)cp; if(fp->prev) { cp = fp->prev; free((char*)fp); } else break; } /* now free the first frame */ if(sp != &_stak_cur) free((void*)sp); return(0); } /* * reset the bottom of the current stack back to <loc> * if <loc> is not in this stack, then the stack is reset to the beginning * otherwise, the top of the stack is set to stakbot+<offset> * */ char *stakset(loc,offset) register char *loc; unsigned offset; { register Stak_t *sp = &_stak_cur; register char *cp; register struct frame *fp; if(sp==sp->stakcur) return(sp->stakbot); increment(set); while(1) { /* see whether <loc> is in current stack frame */ if(loc>=(cp=sp->stakbase) && loc<=sp->stakend) { sp->stakbot = cp + round(loc-cp,sizeof(char*)); sp->staktop = loc+offset; goto found; } fp = (struct frame*)cp; if(fp->prev) { sp->stakbase = fp->prev; sp->stakend = ((struct frame*)(fp->prev))->end; free(cp); } else break; } /* set stack back to the beginning */ sp->staktop = sp->stakbot = ((char*)(sp->stakcur+1))+sizeof(struct frame); found: sp->stakleft = sp->stakend - sp->staktop; return(sp->stakbot); } /* * allocate <n> bytes on the current stack */ #if defined(__STDC__) char *stakalloc(register unsigned n) #else char *stakalloc(n) register unsigned n; #endif /* __STDC__ */ { register Stak_t *sp = &_stak_cur; register char *old; increment(alloc); n = round(n,sizeof(char*)); if((sp->stakleft += ((sp->staktop-sp->stakbot)-(int)n)) <=0) _stakgrow(n); old = sp->stakbot; sp->stakbot = sp->staktop = old+n; return(old); } /* * begin a new stack word of at least <n> bytes */ char *stakseek(n) register unsigned n; { register Stak_t *sp = &_stak_cur; increment(seek); if((sp->stakleft += ((sp->staktop-sp->stakbot)-(int)n)) <=0) _stakgrow(n); sp->staktop = sp->stakbot+n; return(sp->stakbot); } /* * put the string <str> onto the stack * returns the length of the string */ int stakputs(str) register const char *str; { register Stak_t *sp = &_stak_cur; register const char *cp=str; register int n; while(*cp++); n = cp-str; increment(puts); if((sp->stakleft -= n) <=0) _stakgrow(n); strcpy(sp->staktop,str); sp->staktop += --n; return(n); } /* * advance the stack to the current top * if extra is non-zero, first add a extra bytes and zero the first */ char *stakfreeze(extra) register unsigned extra; { register Stak_t *sp = &_stak_cur; register char *old = sp->stakbot; register char *top = sp->staktop; if(extra) { if(extra > sp->stakleft) { top = _stakgrow(extra); old = sp->stakbot; } *top = 0; top += extra; } sp->staktop = sp->stakbot += round(top-old,sizeof(char*)); sp->stakleft = sp->stakend-sp->staktop; return(old); } /* * copy string <str> onto the stack as a new stack word */ char *stakcopy(str) const char *str; { register Stak_t *sp = &_stak_cur; register char *cp = (char*)str; register int n; while(*cp++); n = round(cp-str,sizeof(char*)); increment(copy); if((sp->stakleft += ((sp->staktop-sp->stakbot)-n)) <=0) _stakgrow(n); strcpy(cp=sp->stakbot,str); sp->stakbot = sp->staktop = cp+n; return(cp); } /* * add a new stack frame of size >= <n> to the current stack. * if <n> > 0, copy the bytes from stakbot to staktop to the new stack * if <n> is zero, then copy the remainder of the stack frame from stakbot * to the end is copied into the new stack frame */ char *_stakgrow(size) unsigned size; { register int n = size; register Stak_t *sp = &_stak_cur; register struct frame *fp; register char *cp; register unsigned m = (n?sp->staktop:sp->stakend)-sp->stakbot; n += (m + sizeof(struct frame)+1); if(sp->stakflags&STAK_SMALL) #ifndef USE_REALLOC n = round(n,STAK_FSIZE/16); else #endif /* !USE_REALLOC */ n = round(n,STAK_FSIZE); /* check for first time default stack reference */ if(sp==sp->stakcur) { minsize = n; if((sp = stakcreate(STAK_MYSIZE))==0) sp = (Stak_t*)overflow(sizeof(Stak_t)); _stak_cur = *sp; return(sp->stakbot); } cp = malloc(n); if(cp==(char*)0) cp = (*sp->stakoverflow)(n); increment(grow); count(addsize,n); fp = (struct frame*)cp; fp->prev = sp->stakbase; sp->stakbase = cp; sp->stakend = fp->end = cp+n; sp->stakleft = n-(m+size+sizeof(struct frame)); cp = (char*)(fp+1); if(m) memcpy(cp,sp->stakbot,m); count(movsize,m); sp->stakbot = cp; return(sp->staktop = sp->stakbot+m); } static char *overflow(n) int n; { (&n,1); write(2,Omsg, sizeof(Omsg)-1); exit(2); /* NOTREACHED */ return(0); } 0707070000000001661006440044230044230000010000000475327573300003300000000560misc/univdata.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * universe common data */ #include "univlib.h" #ifndef UNIV_MAX char univ_env[] = "__UNIVERSE__"; #else #ifndef NUMUNIV char* univ_name[] = { "att", "ucb" }; int univ_max = sizeof(univ_name) / sizeof(univ_name[0]); #endif char univ_cond[] = "$(UNIVERSE)"; int univ_size = sizeof(univ_cond) - 1; #endif 0707070000000001671006440044230044230000010000000475326251000003200000001376misc/univlib.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * universe support * * symbolic link external representation has trailing '\0' and $(...) style * conditionals where $(...) corresponds to a kernel object (i.e., probably * not environ) * * universe symlink conditionals use $(UNIVERSE) */ #include "FEATURE/universe" #ifdef _bin_universe #include <limits.h> #include <ls.h> #ifdef _sys_universe #include <sys/universe.h> #endif #ifndef PATH_MAX #define PATH_MAX 1024 #endif #ifdef NUMUNIV #define UNIV_MAX NUMUNIV #else #define UNIV_MAX univ_max extern char* univ_name[]; extern int univ_max; #endif extern char univ_cond[]; extern int univ_size; #else #define UNIV_SIZE 9 extern char univ_env[]; #endif #include <errno.h> extern int errno; 0707070000000001701006440044230044230000010000000460411345100002700000003067port/copy.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * copy from rfd to wfd (with conditional mmap hacks) */ #if sun #include "FEATURE/mmap" #ifdef _lib_mmap #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> #define MAPSIZE (1024*256) extern int munmap(); extern caddr_t mmap(); #endif #endif #define round(x,y) (((x)+(y)-1)&~((y)-1)) #define BUFSIZ 4096 /* * copy n bytes from rfd to wfd * actual byte count returned * if n<=0 then ``good'' size is used */ long copy(rfd, wfd, n) int rfd; int wfd; int n; { register long c; #ifdef MAPSIZE off_t pos; off_t mapsize; char* mapbuf; struct stat st; extern int fstat(); extern off_t lseek(); #endif static int bufsiz; static char* buf; extern char* malloc(); if (n <= 0 || n >= BUFSIZ * 2) { #if MAPSIZE if (!fstat(rfd, &st) && (st.st_mode & S_IFMT) == S_IFREG && (pos = lseek(rfd, (off_t)0, 1)) != ((off_t)-1)) { if (pos >= st.st_size) return(0); mapsize = st.st_size - pos; if (mapsize > MAPSIZE) mapsize = (mapsize > n && n > 0) ? n : MAPSIZE; if (mapsize >= BUFSIZ * 2 && (mapbuf = mmap((caddr_t)0, mapsize, PROT_READ, MAP_SHARED, rfd, pos)) != ((caddr_t)-1)) { if (write(wfd, mapbuf, mapsize) != mapsize || lseek(rfd, mapsize, 1) == ((off_t)-1)) return(-1); (void)munmap(mapbuf, mapsize); return(mapsize); } } #endif if (n <= 0) n = BUFSIZ; } if (n > bufsiz) { if (buf) free(buf); bufsiz = round(n, BUFSIZ); if (!(buf = malloc(bufsiz))) return(-1); } if ((c = read(rfd, buf, n)) > 0 && write(wfd, buf, c) != c) c = -1; return(c); } 0707070000000001711006440044230044230000010000000454126366000003000000000624port/fclex.c Ugsf Ggsf /* * set|clear file descriptor close-on-exec flag */ #include <errno.h> #include <fcntl.h> #ifndef F_SETFD #include <sys/filio.h> /* 9th edition */ #endif extern int errno; int fclex(fd, flag) int fd; int flag; { flag &= 01; #ifdef F_SETFD return(fcntl(fd, F_SETFD, flag)); #else #ifdef FIOCLEX return(ioctl(fd, flag ? FIOCLEX : FIONCLEX, 0)); #else errno = EINVAL; return(-1); #endif #endif } 0707070000000001721006440044230044230000010000000473371751100003100000032604port/genhdr.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * generate libx header files * usually controlled by mkhdr * * genhdr hdr * * NOTE: two's complement binary integral representation assumed */ #if !lint static char id[] = "\n@(#)genhdr (ulysses!gsf) 12/11/90\0\n"; #endif #include "FEATURE/dir" #include "FEATURE/getdents" #include <lcllimits.h> #include <lclparam.h> #include <lcldirent.h> #include <lclstdio.h> #if !defined(_lcl_dirent) && defined(_sys_dir) #include <sys/dir.h> #endif #ifndef SIG_IGN #include <signal.h> #endif union _u_ { long u1; char* u2; double u3; char u4[1024]; }; struct _s_ { char s1; union _u_ s2; }; struct _m_ { char* text; char* name; int value; }; #define elements(x) (sizeof(x)/sizeof(x[0])) #define round(x,y) (((x)+((y)-1))&~((y)-1)) static struct _m_ map[] = { #ifdef SIGABRT "Abort", "ABRT", SIGABRT, #endif #ifdef SIGALRM "Alarm call", "ALRM", SIGALRM, #endif #ifdef SIGAPOLLO "Apollo", "APOLLO", SIGAPOLLO, #endif #ifdef SIGBUS "Bus error", "BUS", SIGBUS, #endif #ifdef SIGCHLD "Child status change", "CHLD", SIGCHLD, #endif #ifdef SIGCLD "Death of child", "CLD", SIGCLD, #endif #ifdef SIGCONT "Stopped process continued", "CONT", SIGCONT, #endif #ifdef SIGDEBUG "Debug trap", "DEBUG", SIGDEBUG, #endif #ifdef SIGEMT "EMT trap", "EMT", SIGEMT, #endif #ifdef SIGERR "ERR trap", "ERR", SIGERR, #endif #ifdef SIGEXIT "Exit", "EXIT", SIGEXIT, #endif #ifdef SIGFPE "Floating exception", "FPE", SIGFPE, #endif #ifdef SIGHUP "Hangup", "HUP", SIGHUP, #endif #ifdef SIGILL "Illegal instruction", "ILL", SIGILL, #endif #ifdef SIGINT "Interrupt", "INT", SIGINT, #endif #ifdef SIGIO "IO possible", "IO", SIGIO, #endif #ifdef SIGIOT "IOT trap", "IOT", SIGIOT, #endif #ifdef SIGKILL "Killed", "KILL", SIGKILL, #endif #ifdef SIGLAB "LAB trap", "LAB", SIGLAB, #endif #ifdef SIGKILL "Killed", "KILL", SIGKILL, #endif #ifdef SIGLOST "Resources lost", "LOST", SIGLOST, #endif #ifdef SIGPHONE "Phone status change", "PHONE", SIGPHONE, #endif #ifdef SIGPIPE "Broken Pipe", "PIPE", SIGPIPE, #endif #ifdef SIGPOLL "Poll event", "POLL", SIGPOLL, #endif #ifdef SIGPROF "Profiling time alarm", "PROF", SIGPROF, #endif #ifdef SIGPWR "Power fail", "PWR", SIGPWR, #endif #ifdef SIGQUIT "Quit", "QUIT", SIGQUIT, #endif #ifdef SIGSEGV "Memory fault", "SEGV", SIGSEGV, #endif #ifdef SIGSSTOP "Sendable stop", "SSTOP", SIGSSTOP, #endif #ifdef gould "Stack overflow", "STKOV", 28, #endif #ifdef SIGSTOP "Stopped (signal)", "STOP", SIGSTOP, #endif #ifdef SIGSYS "Bad system call", "SYS", SIGSYS, #endif #ifdef SIGTERM "Terminated", "TERM", SIGTERM, #endif #ifdef SIGTINT "Interrupt (terminal)", "TINT", SIGTINT, #endif #ifdef SIGTRAP "Trace/BPT trap", "TRAP", SIGTRAP, #endif #ifdef SIGTSTP "Stopped", "TSTP", SIGTSTP, #endif #ifdef SIGTTIN "Stopped (tty input)", "TTIN", SIGTTIN, #endif #ifdef SIGTTOU "Stopped (tty output)", "TTOU", SIGTTOU, #endif #ifdef SIGURG "Urgent IO", "URG", SIGURG, #endif #ifdef SIGUSR1 "User signal 1", "USR1", SIGUSR1, #endif #ifdef SIGUSR2 "User signal 2", "USR2", SIGUSR2, #endif #ifdef SIGVTALRM "Virtual time alarm", "VTALRM", SIGVTALRM, #endif #ifdef SIGWINCH "Window change", "WINCH", SIGWINCH, #endif #ifdef SIGWIND "Window change", "WIND", SIGWIND, #endif #ifdef SIGWINDOW "Window change", "WINDOW", SIGWINDOW, #endif #ifdef SIGXCPU "CPU time limit", "XCPU", SIGXCPU, #endif #ifdef SIGXFSZ "File size limit", "XFSZ", SIGXFSZ, #endif 0 }; static int index[64]; main(argc, argv) int argc; char** argv; { register int i; register int j; register int k; int align0; int align1; int align2; unsigned long bit1; unsigned long bit2; unsigned long bits0; unsigned long bits1; unsigned long bits2; union _u_ u; union _u_ v; char c; unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; unsigned long val; char* hdr; if (argc != 2 || !(hdr = *++argv)) hdr = "UNKNOWN"; if (!strcmp(hdr, "align")) { u.u2 = u.u4; v.u2 = u.u2 + 1; bit1 = u.u1 ^ v.u1; v.u2 = u.u2 + 2; bit2 = u.u1 ^ v.u1; align0 = sizeof(struct _s_) - sizeof(union _u_); bits0 = 0; k = 0; for (j = 0; j < align0; j++) { u.u2 = u.u4 + j; bits1 = 0; for (i = 0; i < align0; i++) { v.u2 = u.u2 + i; bits1 |= u.u1 ^ v.u1; } if (!bits0 || bits1 < bits0) { bits0 = bits1; k = j; } } align1 = round(align0, 2); u.u2 = u.u4 + k; for (bits1 = bits0; i < align1; i++) { v.u2 = u.u2 + i; bits1 |= u.u1 ^ v.u1; } align2 = round(align0, 4); for (bits2 = bits1; i < align2; i++) { v.u2 = u.u2 + i; bits2 |= u.u1 ^ v.u1; } printf("typedef unsigned %s INTEGRAL;\n", sizeof(char*) >= sizeof(long) ? "long" : sizeof(char*) >= sizeof(int) ? "int" : "short"); printf("\n"); printf("#define CHUNK %d\n", sizeof(char*) >= 4 ? 8192 : 1024); printf("#define INTEGRAL %s\n", sizeof(char*) >= sizeof(long) ? "long" : sizeof(char*) >= sizeof(int) ? "int" : "short"); printf("#define INTEGER(x) ((INTEGRAL)(x))\n"); printf("#define POINTER(x) ((char*)(x))\n"); if (bits2 == (align2 - 1)) printf("#define ROUND(x,y) POINTER(INTEGER((x)+(y)-1)&~((y)-1))\n"); else printf("#define ROUND(x,y) POINTER(INTEGER(ALIGN(x)+(((y)+%d)/%d)-1)&~((((y)+%d)/%d)-1))\n", align0, align0, align0, align0); printf("\n"); if (align0 == align2) { printf("#define BOUND BOUND2\n"); printf("#define ALIGN(x) ALIGN2(x)\n"); printf("#define TRUNC(x) TRUNC2(x)\n"); } else if (align0 == align1) { printf("#define BOUND BOUND1\n"); printf("#define ALIGN(x) ALIGN1(x)\n"); printf("#define TRUNC(x) TRUNC1(x)\n"); } else { printf("#define BOUND 1\n"); printf("#define ALIGN(x) POINTER(x)\n"); printf("#define TRUNC(x) POINTER(x)\n"); } printf("\n"); printf("#define BIT1 0x%lx\n", bit1); if (align1 == align2) { printf("#define BOUND1 BOUND2\n"); printf("#define ALIGN1(x) ALIGN2(x)\n"); printf("#define TRUNC1(x) TRUNC2(x)\n"); } else { printf("#define BOUND1 %d\n", align1); printf("#define ALIGN1(x) TRUNC1((x)+%d)\n", align1 - 1); printf("#define TRUNC1(x) POINTER(INTEGER((x)+%d)&0x%lx)\n", align1 - 1, ~(bits0|bits1)); } printf("#define CLRBIT1(x) POINTER(INTEGER(x)&0x%lx)\n", ~bit1); printf("#define SETBIT1(x) POINTER(INTEGER(x)|0x%lx)\n", bit1); printf("#define TSTBIT1(x) POINTER(INTEGER(x)&0x%lx)\n", bit1); printf("\n"); printf("#define BIT2 0x%lx\n", bit2); printf("#define BOUND2 %d\n", align2); printf("#define ALIGN2(x) TRUNC2((x)+%d)\n", align2 - 1); printf("#define TRUNC2(x) POINTER(INTEGER(x)&0x%lx)\n", ~(bits0|bits1|bits2)); printf("#define CLRBIT2(x) POINTER(INTEGER(x)&0x%lx)\n", ~bit2); printf("#define SETBIT2(x) POINTER(INTEGER(x)|0x%lx)\n", bit2); printf("#define TSTBIT2(x) POINTER(INTEGER(x)&0x%lx)\n", bit2); printf("\n"); } else if (!strcmp(hdr, "dirent")) { #ifdef _lib_getdents printf("#define _dir_getdents 1 /* getdents() in library */\n"); #endif #ifdef rewinddir printf("#define _dir_rewinddir 1 /* rewinddir locally defined */\n"); #endif #ifdef _sys_dir printf("#define _dir_sys 1 /* #include <sys/dir.h> ok */\n"); #endif printf("\n"); } else if (!strcmp(hdr, "fsinfo")) { #ifdef BUFFERSIZE val = BUFFERSIZE; #else #ifdef MAXBSIZE val = MAXBSIZE; #else #ifdef SBUFSIZE val = SBUFSIZE; #else #ifdef BUFSIZ val = BUFSIZ; #else if (sizeof(char*) > 4) val = 8192; else if (sizeof(char*) < 4) val = 512; else val = 4096; #endif #endif #endif #endif printf("#define BUFFERSIZE %lu\n", val); printf("\n"); } else if (!strcmp(hdr, "limits")) { /* * <limits.h> with *constant* valued macros */ #ifdef CHAR_BIT val = CHAR_BIT; printf("#undef CHAR_BIT\n"); #else uc = 0; uc = ~uc; val = 1; while (uc >>= 1) val++; #endif printf("#define CHAR_BIT %lu\n", val); c = 0; c = ~c; uc = 0; uc = ~uc; us = 0; us = ~us; ui = 0; ui = ~ui; ul = 0; ul = ~ul; #ifdef UCHAR_MAX val = UCHAR_MAX; printf("#undef UCHAR_MAX\n"); #else val = uc; #endif printf("#if __STDC__\n"); printf("#define UCHAR_MAX %luU\n", val); printf("#else\n"); printf("#define UCHAR_MAX %lu\n", val); printf("#endif\n"); #ifdef SCHAR_MIN val = -(SCHAR_MIN); printf("#undef SCHAR_MIN\n"); #else val = (unsigned char)(uc >> 1) + 1; #endif printf("#define SCHAR_MIN -%lu\n", val); #ifdef SCHAR_MAX val = SCHAR_MAX; printf("#undef SCHAR_MAX\n"); #else val = (unsigned char)(uc >> 1); #endif printf("#define SCHAR_MAX %lu\n", val); if (c < 0) { #ifdef CHAR_MIN printf("#undef CHAR_MIN\n"); #endif printf("#define CHAR_MIN SCHAR_MIN\n"); #ifdef CHAR_MAX printf("#undef CHAR_MAX\n"); #endif printf("#define CHAR_MAX SCHAR_MAX\n"); } else { #ifdef CHAR_MIN printf("#undef CHAR_MIN\n"); #endif printf("#define CHAR_MIN 0\n"); #ifdef CHAR_MAX printf("#undef CHAR_MAX\n"); #endif printf("#define CHAR_MAX UCHAR_MAX\n"); } #ifdef USHRT_MAX val = USHRT_MAX; printf("#undef USHRT_MAX\n"); #else val = us; #endif printf("#if __STDC__\n"); printf("#define USHRT_MAX %luU\n", val); printf("#else\n"); printf("#define USHRT_MAX %lu\n", val); printf("#endif\n"); #ifdef SHRT_MIN val = -(SHRT_MIN); printf("#undef SHRT_MIN\n"); #else val = (unsigned short)(us >> 1) + 1; #endif printf("#define SHRT_MIN -%lu\n", val); #ifdef SHRT_MAX val = SHRT_MAX; printf("#undef SHRT_MAX\n"); #else val = (unsigned short)(us >> 1); #endif printf("#define SHRT_MAX %lu\n", val); if (ui == us) { #ifdef UINT_MAX printf("#undef UINT_MAX\n"); #endif printf("#define UINT_MAX USHRT_MAX\n"); #ifdef INT_MIN printf("#undef INT_MIN\n"); #endif printf("#define INT_MIN SHRT_MIN\n"); #ifdef INT_MAX printf("#undef INT_MAX\n"); #endif printf("#define INT_MAX SHRT_MAX\n"); } else { #ifdef UINT_MAX val = UINT_MAX; printf("#undef UINT_MAX\n"); #else val = ui; #endif printf("#if __STDC__\n"); printf("#define UINT_MAX %luU\n", val); printf("#else\n"); printf("#define UINT_MAX %lu\n", val); printf("#endif\n"); #ifdef INT_MIN val = -(INT_MIN); printf("#undef INT_MIN\n"); #else val = (unsigned int)(ui >> 1) + 1; #endif printf("#define INT_MIN -%lu\n", val); #ifdef INT_MAX val = INT_MAX; printf("#undef INT_MAX\n"); #else val = (unsigned int)(ui >> 1); #endif printf("#define INT_MAX %lu\n", val); } if (ul == ui) { #ifdef ULONG_MAX printf("#undef ULONG_MAX\n"); #endif printf("#define ULONG_MAX UINT_MAX\n"); #ifdef LONG_MIN printf("#undef LONG_MIN\n"); #endif printf("#define LONG_MIN INT_MIN\n"); #ifdef LONG_MAX printf("#undef LONG_MAX\n"); #endif printf("#define LONG_MAX INT_MAX\n"); } else { #ifdef ULONG_MAX val = ULONG_MAX; printf("#undef ULONG_MAX\n"); #else val = ui; #endif printf("#if __STDC__\n"); printf("#define ULONG_MAX %luU\n", val); printf("#else\n"); printf("#define ULONG_MAX %lu\n", val); printf("#endif\n"); #ifdef LONG_MIN val = -(LONG_MIN); printf("#undef LONG_MIN\n"); #else val = (unsigned long)(ul >> 1) + 1; #endif printf("#define LONG_MIN -%lu\n", val); #ifdef LONG_MAX val = LONG_MAX; printf("#undef LONG_MAX\n"); #else val = (unsigned long)(ul >> 1); #endif printf("#define LONG_MAX %lu\n", val); } /* * POSIX values */ printf("\n"); printf("/*\n"); printf(" * system implementation limits\n"); printf(" */\n"); printf("\n"); #ifdef ARG_MAX val = ARG_MAX; printf("#undef ARG_MAX\n"); #else #ifdef NCARGS val = NCARGS; #else val = 5120; #endif #endif printf("#define ARG_MAX %lu\n", val); #ifdef MAX_CANON val = MAX_CANON; printf("#undef MAX_CANON\n"); #else #ifdef CANBSIZ val = CANBSIZ; #else val = 256; #endif #endif printf("#define MAX_CANON %lu\n", val); #ifdef LINK_MAX val = LINK_MAX; printf("#undef LINK_MAX\n"); #else #ifdef MAXLINK val = MAXLINK; #else #ifdef SHRT_MAX val = SHRT_MAX; #else val = (unsigned short)(us >> 1); #endif #endif #endif printf("#define LINK_MAX %lu\n", val); #ifdef NGROUPS_MAX val = NGROUPS_MAX; printf("#undef NGROUPS_MAX\n"); #else #ifdef NGROUPS val = NGROUPS; #else val = 0; #endif #endif printf("#define NGROUPS_MAX %lu\n", val); #ifdef PATH_MAX val = PATH_MAX; printf("#undef PATH_MAX\n"); #else #ifdef MAXPATHLEN val = MAXPATHLEN; #else val = 1024; #endif #endif printf("#define PATH_MAX %lu\n", val); #ifdef OPEN_MAX val = OPEN_MAX; printf("#undef OPEN_MAX\n"); #else val = 2; while ((i = dup(0)) >= 0) if (i > val) val = i; #endif printf("#define OPEN_MAX %lu\n", val); #ifdef OPEN_MAX_CEIL val = OPEN_MAX_CEIL; printf("#undef OPEN_MAX_CEIL\n"); printf("#define OPEN_MAX_CEIL %lu\n", val); #else printf("#define OPEN_MAX_CEIL OPEN_MAX\n"); #endif printf("\n"); } else if (!strcmp(hdr, "sigdata")) { /* * sigdata.h for sigdata.c */ k = 0; for (i = 0; map[i].name; i++) if ((j = map[i].value) > 0 && j < elements(index)) { if (j > k) k = j; index[j] = i; } printf("int sig_max = %d;\n", k); printf("\n"); printf("char* sig_name[] =\n"); printf("{\n"); for (i = 0; i <= k; i++) if (j = index[i]) printf(" \"%s\",\n", map[j].name); else printf(" \"%d\",\n", i); printf("};\n"); printf("\n"); printf("char* sig_text[] =\n"); printf("{\n"); for (i = 0; i <= k; i++) if (j = index[i]) printf(" \"%s\",\n", map[j].text); else printf(" \"Signal %d\",\n", i); printf("};\n"); } else { fprintf(stderr, "Usage: genhdr align ^ dirent ^ fsinfo ^ limits ^ sigdata\n"); exit(1); } exit(0); } 0707070000000001731006440044230044230000010000000460145424500003200000001551port/iblocks.c Ugsf Ggsf /* * return number of blocks, including indirect block count * given stat info * * for systems not supporting stat.st_blocks */ #include <lclparam.h> #include <fsinfo.h> #ifndef stat_blocks #ifndef B_DIRECT #define B_DIRECT 10 #endif #ifdef BITFS #define B_SIZE BSIZE(st->st_dev) #define B_INDIRECT NINDIR(st->st_dev) #else #ifdef BSIZE #define B_SIZE BSIZE #else #define B_SIZE 1024 #endif #ifdef NINDIR #define B_INDIRECT NINDIR #else #define B_INDIRECT 128 #endif #endif #endif long iblocks(st) struct stat* st; { #ifdef stat_blocks return((st->st_blocks + 1) / 2); #else long b; long t; t = b = (st->st_size + B_SIZE - 1) / B_SIZE; if ((b -= B_DIRECT) > 0) { t += (b - 1) / B_INDIRECT + 1; if ((b -= B_INDIRECT) > 0) { t += (b - 1) / (B_INDIRECT * B_INDIRECT) + 1; if (b > B_INDIRECT * B_INDIRECT) t++; } } return(t); #endif } 0707070000000001741006440044230044230000010000000475447175700003100000022652port/mkhdr.sh Ugsf Ggsf : # # mkhdr hdr [ genhdr ] [ cc [ ccflags ] ] # # @(#)mkhdr (ulysses!gsf) 01/31/91 # case $# in 0) echo "Usage: $0 hdr [ genhdr ] [ cc [ ccflags ] ]" >&2; exit 1 ;; esac hdr=$1 shift case $1 in "") genhdr= ;; *) genhdr=$1 ;; esac case $# in 0) ;; *) shift ;; esac cc=${1-cc} case $# in 0) ;; *) shift ;; esac tmp=x.$$ trap 'code=$?; rm -f $tmp.?; exit $code' 0 1 2 3 case $hdr in align) case $genhdr in "") echo "$0: $hdr: genhdr arg required" >&2; exit 1 ;; esac cat <<! /* * AT&T Bell Laboratories * alignment and pointer pun definitions * : : generated by $0 and $genhdr : : */ #ifndef __ALIGN_H__ #define __ALIGN_H__ ! $genhdr $hdr || exit 1 cat <<! #endif ! ;; dirent) case $genhdr in "") echo "$0: $hdr: genhdr arg required" >&2; exit 1 ;; esac cat<<! /* * AT&T Bell Laboratories * directory stream access definitions * * #include <sys/types.h> * #include <dirent.h> * * : : generated by $0 and $genhdr : : */ #ifndef __DIRENT_H__ #include <lcldirent.h> #ifndef __DIRENT_H__ #define __DIRENT_H__ #endif ! $genhdr $hdr || exit 1 for i in "" "#ifndef d_ino #define d_ino d_fileno #endif" "#ifndef d_fileno #define d_fileno d_ino #endif" do cat > $tmp.c <<! #include <sys/types.h> #include <lcldirent.h> #ifdef _lcl_dirent static struct dirent dir; #else #include <sys/dir.h> static struct direct dir; #endif $i int n1 = sizeof(dir.d_ino); int n2 = sizeof(dir.d_fileno); ! if $cc -I. ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then break fi done nl= case $i in ?*) nl=1 echo "$i" ;; esac cat > $tmp.c <<! #include <sys/types.h> #include <lcldirent.h> #ifdef _lcl_dirent static struct dirent dir; #else #include <sys/dir.h> static struct direct dir; #endif int n1 = sizeof(dir.d_namlen); ! if $cc -I. ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then nl=1 echo "#define _dir_namlen 1 /* dirent.d_namlen */" fi case $nl in ?*) echo ;; esac cat <<! #ifndef _lcl_dirent #ifdef _dir_sys #include <sys/dir.h> #else #undef _dir_rewinddir #define DIRSIZ 14 struct direct { short d_ino; char d_name[DIRSIZ]; }; #endif #ifdef _dir_rewinddir /* * variable length directory entry format */ #define _dir_variable #ifndef dirent #define dirent direct #endif #else /* * fixed length directory entry format */ #define _dir_fixed #ifndef DIRSIZ #define DIRSIZ 14 /* maximum entry link length */ #endif #ifndef MAXNAMLEN #define MAXNAMLEN DIRSIZ /* maximum filename length */ #endif #ifdef _dir_getdents struct dirent /* data from local getdents() */ { long d_ino; /* file number of entry */ long d_off; /* entry seek offset */ unsigned short d_reclen; /* length of this record */ char d_name[1]; /* link name */ }; #else #ifndef _dir_namlen #define _dir_namlen 1 #endif struct dirent /* data from readdir() */ { long d_fileno; /* file number of entry */ unsigned short d_reclen; /* length of this record */ unsigned short d_namlen; /* strlen(d_name) */ char d_name[1]; /* link name */ }; #endif typedef struct { int dd_fd; /* file descriptor */ int dd_loc; /* offset in block */ int dd_size; /* amount of valid data */ char* dd_buf; /* directory block */ } DIR; /* stream data from opendir() */ extern DIR* opendir(); extern struct dirent* readdir(); extern long telldir(); extern void seekdir(); extern void closedir(); #if !_dir_local #define rewinddir(dirp) seekdir(dirp,0L) #endif #endif #endif #if _dir_namlen #define DIRNAMLEN(d) ((d)->d_namlen) #else #define DIRNAMLEN(d) strlen((d)->d_name) #endif #endif ! ;; fsinfo) case $genhdr in "") echo "$0: $hdr: genhdr arg required" >&2; exit 1 ;; esac cat <<! /* * AT&T Bell Laboratories * file system user interface definitions * : : generated by $0 and $genhdr : : */ #ifndef __FSINFO_H__ #define __FSINFO_H__ #ifndef __LCLPARAM_H__ #ifndef S_IFMT #ifndef TM_DEFAULT #include <sys/types.h> #endif #include <sys/stat.h> #endif #endif ! nl= for i in blocks blksize do cat > $tmp.c <<! #include <sys/types.h> #include <sys/stat.h> static struct stat st; int bytes = sizeof(st.st_$i); ! if $cc ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then case $nl in "") nl=1 echo ;; esac echo "#define stat_$i 1 /* struct stat has st_$i */" fi done cat > $tmp.c <<! #include <sys/types.h> #include <sys/stat.h> #ifndef major #include <sys/param.h> #ifndef major #include <sys/sysmacros.h> #endif "#ifndef major" = #ifdef major "#define major(x)" = major((x)) #else "#define major(x)" = ((int)(((unsigned)(x)>>8)&0377)) #endif "#endif" = "#ifndef minor" = #ifdef minor "#define minor(x)" = minor((x)) #else "#define minor(x)" = ((int)((x)&0377)) #endif "#endif" = "#ifndef makedev" = #ifdef makedev "#define makedev(x,y)" = makedev((x),(y)) #else "#define makedev(x,y)" = ((dev_t)((((x)&0377)<<8)|((y)&0377))) #endif "#endif" = #endif ! if $cc ${1+"$@"} -E $tmp.c > $tmp.i 2>/dev/null then sed -e '/"#/!d' -e 's/.*#/#/' -e 's/"[^=]*=//' $tmp.i else cat <<! #ifndef major #define major(x) ((int)(((unsigned)(x)>>8)&0377)) #endif #ifndef minor #define minor(x) ((int)((x)&0377)) #endif #ifndef makedev #define makedev(x,y) ((dev_t)((((x)&0377)<<8)|((y)&0377))) #endif ! fi echo $genhdr $hdr || exit 1 cat <<! #endif ! ;; lclparam) HDR=LCLPARAM cat <<! /* * AT&T Bell Laboratories * <sys/param.h> + <sys/types.h> + <sys/stat.h> * : : generated by $0 : : */ #ifndef __${HDR}_H__ #define __${HDR}_H__ ! for i in "#include <sys/param.h>" "#include <sys/param.h> #ifndef S_IFDIR #include <sys/stat.h> #endif" "#include <sys/param.h> #ifndef S_IFDIR #include <sys/types.h> #include <sys/stat.h> #endif" "#ifndef S_IFDIR #include <sys/types.h> #include <sys/stat.h> #endif" do echo "$i struct stat V_stat_V; F_stat_F() { V_stat_V.st_mode = 0; }" > $tmp.c if $cc ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then echo "$i" break fi done cat <<! #endif ! ;; lcl*) lcl=`echo $hdr | sed -e 's/lcl//'` HDR=`echo $hdr | tr '[a-z]' '[A-Z]'` cat <<! /* * AT&T Bell Laboratories * untrusted local <$lcl.h> * : : generated by $0 : : */ #ifndef __${HDR}_H__ #define __${HDR}_H__ ! echo "#include <$lcl.h>" > $tmp.c if $cc ${1+"$@"} -E $tmp.c > $tmp.i 2>/dev/null then f=`sed -e '/^#[line ]*1[ ][ ]*"\/.*\/'$lcl'\.h"/!d' -e '/\/sys\/'$lcl'\.h"/d' -e s'/.*"\(.*\)".*/\1/' $tmp.i` else f= fi case $lcl in dirent) case $f in "") h=sys/dir ;; *) h=dirent ;; esac v= for i in DIR opendir readdir rewinddir seekdir telldir closedir do cat > $tmp.c <<! #include <sys/types.h> #include <$h.h> #ifndef $i ( #endif ! if $cc ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then v="$v $i" fi done case $v in ?*) echo "#if _dir_local" for i in $v do echo "#undef $i" done echo "#endif" ;; esac ;; esac case $f in "") echo "/* no local <$lcl.h> */" ;; *) echo "/* begin local <$lcl.h> */" cat $f cat <<! /* end local <$lcl.h> */ #undef _lcl_$lcl #define _lcl_$lcl 1 ! ;; esac cat <<! #endif ! ;; limits) case $genhdr in "") echo "$0: $hdr: genhdr arg required" >&2; exit 1 ;; esac cat <<! /* * AT&T Bell Laboratories * C language implementation integral type sizes * : : generated by $0 and $genhdr : : */ #ifndef __LIMITS_H__ #include <lcllimits.h> #ifndef __LIMITS_H__ #define __LIMITS_H__ #endif ! $genhdr $hdr || exit 1 cat <<! #endif ! ;; preroot)cat <<! /* * AT&T Bell Laboratories * preroot interface definitions * : : generated by $0 : : */ #ifndef __PREROOT_H__ #define __PREROOT_H__ ! if (/etc/preroot / /bin/echo) >/dev/null 2>&1 then cat <<! #define FS_PREROOT 1 /* preroot enabled */ #define PR_BASE "CCS" /* preroot base env var */ #define PR_COMMAND "/etc/preroot" /* the preroot command */ #define PR_REAL "/dev/.." /* real root pathname */ #define PR_SILENT "CCSQUIET" /* no command trace */ #if __STDC__ || __cplusplus || c_plusplus #if __cplusplus extern "C" { #endif extern char* getpreroot(char* path, char* cmd); extern int ispreroot(); extern int realopen(char* path, int mode, int perm); extern void setpreroot(int argc, char** argv, char* dir); #if __cplusplus } #endif #else extern char* getpreroot(); extern int ispreroot(); extern int realopen(); extern void setpreroot(); #endif ! else echo "/* preroot not enabled */" fi cat <<! #endif ! ;; sig) cat <<! /* * AT&T Bell Laboratories * signal support * : : generated by $0 : : */ #ifndef __SIG_H__ #define __SIG_H__ #include <signal.h> #ifndef sigmask #define sigmask(s) (1<<((s)-1)) #endif ! cat > $tmp.c <<! #include <signal.h> #ifdef TYPE #if __STDC__ typedef TYPE (*signal_t)(int); #else typedef TYPE (*signal_t)(); #endif #endif signal_t f() { signal_t handler; handler = signal(1, SIG_IGN); return(handler); } ! if $cc ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then : else for i in void int do $cc ${1+"$@"} -c -DTYPE=$i $tmp.c >/dev/null 2>&1 && break done cat <<! #if __STDC__ typedef $i (*signal_t)(int); #else typedef $i (*signal_t)(); #endif ! fi cat <<! #endif ! ;; sigdata)case $genhdr in "") echo "$0: $hdr: genhdr arg required" >&2; exit 1 ;; esac cat <<! /* * AT&T Bell Laboratories * signal name/text tables * : : generated by $0 and $genhdr : : */ ! $genhdr $hdr || exit 1 ;; ttyinfo) HDR=TTYINFO cat <<! /* * AT&T Bell Laboratories * tty info * : : generated by $0 : : */ #ifndef __${HDR}_H__ #define __${HDR}_H__ ! x="/* no local tty info */" for i in sgtty termio termios sys/termios sys/ttyio sys/ioctl do echo "#include <$i.h>" > $tmp.c if $cc ${1+"$@"} -c $tmp.c >/dev/null 2>&1 then x="#include <$i.h>" break fi done cat <<! $x #endif ! ;; *) echo "$0: $hdr: unknown header" >&2 exit 1 ;; esac 0707070000000001751006440044230044230000010000000466623227100003200000000025port/sigdata.c Ugsf Ggsf #include "sigdata.h" 0707070000000001761006440044230044230000010000000474213166300003000000004770port/touch.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * touch file access and modify times of file * if force>0 then file will be created if it doesn't exist * if force<0 then times are taken verbatim * times have one second granularity * * (time_t)(-1) retain old time * 0 use current time */ #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include "FEATURE/utime" #if _hdr_utime && _lib_utime #include <utime.h> #endif extern int errno; int touch(file, atime, mtime, force) char* file; time_t atime; time_t mtime; int force; { int n; int fd; int oerrno = errno; #if _lib_utime time_t now; struct stat st; #if _hdr_utime struct utimbuf ut; #else time_t ut[2]; #endif extern int close(); extern int creat(); extern int stat(); extern time_t time(); extern int utime(); if (force >= 0) { if (atime == (time_t)(-1) || mtime == (time_t)(-1)) { if (stat(file, &st)) st.st_atime = st.st_mtime = 0; if (atime == (time_t)(-1)) atime = st.st_atime; if (mtime == (time_t)(-1)) mtime = st.st_mtime; } if (!atime || !mtime) #if _hdr_utime if (atime || mtime) #endif { (void)time(&now); if (!atime) atime = now; if (!mtime) mtime = now; } } #if _hdr_utime ut.actime = atime; ut.modtime = mtime; n = utime(file, (force < 0 || atime || mtime) ? &ut : (struct utimbuf*)0); #else ut[0] = atime; ut[1] = mtime; n = utime(file, ut); #endif if (n) #else if (mtime) { /* * NOTE: the emulation allows atime to change * for mtime only requests */ errno = EINVAL; return(-1); } #endif { #if _lib_utime if (errno == ENOENT) #else extern int access(); if (access(file, 0)) #endif { if (!force || (fd = creat(file, 0666)) < 0) return(-1); close(fd); errno = oerrno; #if _lib_utime #if _hdr_utime return((force < 0 || atime || mtime) ? utime(file, &ut) : 0); #else return((atime != now || mtime != now) ? utime(file, ut) : 0); #endif #else return(0); #endif } #if !_hdr_utime || !_lib_utime #if _lib_utime if (atime == now && mtime == now && (fd = open(file, 2)) >= 0) #else if ((fd = open(file, 2)) >= 0) #endif { char c; extern long lseek(); extern int open(); extern int read(); extern int write(); if (read(fd, &c, 1) == 1) { if (lseek(fd, 0L, 0) == 0L && write(fd, &c, 1) == 1) { errno = oerrno; n = 0; } close(fd); } else { close(fd); if ((fd = creat(file, 0666)) >= 0) { close(fd); errno = oerrno; n = 0; } } } #endif } return(n); } 0707070000000001771006440044230044230000010000000463744205000003200000002660port/winsize.c Ugsf Ggsf /* * AT&T Bell Laboratories * return terminal rows and cols */ #include <ttyinfo.h> #include "FEATURE/jioctl" #ifdef _hdr_jioctl #define winsize jwinsize #include <jioctl.h> #undef winsize #else #ifdef _sys_jioctl #define winsize jwinsize #include <sys/jioctl.h> #undef winsize #endif #endif static int ttctl(); void winsize(rows, cols) register int* rows; register int* cols; { #ifdef TIOCGSIZE struct ttysize ts; if (!ttctl(TIOCGSIZE, &ts) && ts.ts_lines > 0 && ts.ts_cols > 0) { if (rows) *rows = ts.ts_lines; if (cols) *cols = ts.ts_cols; } else #else #ifdef TIOCGWINSZ struct winsize ws; if (!ttctl(TIOCGWINSZ, &ws) && ws.ws_col > 0 && ws.ws_row > 0) { if (rows) *rows = ws.ws_row; if (cols) *cols = ws.ws_col; } else #else #ifdef JWINSIZE struct jwinsize ws; if (!ttctl(JWINSIZE, &ws) && ws.bytesx > 0 && ws.bytesy > 0) { if (rows) *rows = ws.bytesy; if (cols) *cols = ws.bytesx; } else #endif #endif #endif { char* s; extern int atoi(); extern char* getenv(); if (rows) *rows = (s = getenv("LINES")) ? atoi(s) : 0; if (cols) *cols = (s = getenv("COLUMNS")) ? atoi(s) : 0; } } /* * tty ioctl() -- no cache */ static int ttctl(op, tt) int op; char* tt; { register int fd; register int v; extern int ioctl(); for (fd = 0; fd <= 2; fd++) if (!ioctl(fd, op, tt)) return(0); if ((fd = open("/dev/tty", 0)) >= 0) { v = ioctl(fd, op, tt); (void)close(fd); return(v); } return(-1); } 0707070000000002001006440044230044230000010000000470170002700004000000005736preroot/getpreroot.c Ugsf Ggsf /* * AT&T Bell Laboratories * return the real absolute pathname of the preroot dir for cmd * if cmd==0 then current preroot path returned */ #include <preroot.h> #if FS_PREROOT #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <errno.h> #include <limits.h> #include <stdio.h> #ifndef PATH_MAX #define PATH_MAX 1024 #endif #ifndef ERANGE #define ERANGE E2BIG #endif #define ERROR(e) {errno=e;goto error;} extern int errno; extern char* strdup(); char* getpreroot(path, cmd) char* path; char* cmd; { register int c; register char* p; register FILE* fp; char buf[PATH_MAX]; if (!path) path = buf; if (cmd) { (void)sprintf(buf, "set x `%s= %s - </dev/null 2>&1`\nwhile :\ndo\nshift\ncase $# in\n[012]) break ;;\nesac\ncase \"$1 $2\" in\n\"+ %s\") echo $3; break ;;\nesac\ndone\n", PR_SILENT, cmd, PR_COMMAND); if (!(fp = popen(buf, "rug"))) return(0); for (p = path; (c = getc(fp)) != EOF && c != '\n'; *p++ = c); *p = 0; (void)pclose(fp); if (path == p) return(0); return(path == buf ? strdup(path) : path); } else { char* d; DIR* dirp = 0; int namlen; int euid; int ruid; struct dirent* entry; struct stat* cur; struct stat* par; struct stat* tmp; struct stat curst; struct stat parst; struct stat tstst; char dots[PATH_MAX]; cur = &curst; par = &parst; if ((ruid = getuid()) != (euid = geteuid())) (void)setuid(ruid); if (stat(PR_REAL, cur) || stat("/", par) || cur->st_dev == par->st_dev && cur->st_ino == par->st_ino) ERROR(ENOTDIR); /* * like getcwd() but starting at the preroot */ d = dots; *d++ = '/'; p = path + PATH_MAX - 1; *p = 0; for (;;) { tmp = cur; cur = par; par = tmp; if ((d - dots) > (PATH_MAX - 4)) ERROR(ERANGE); *d++ = '.'; *d++ = '.'; *d = 0; if (!(dirp = opendir(dots)) || fstat(dirp->dd_fd, par)) ERROR(errno); *d++ = '/'; if (par->st_dev == cur->st_dev) { if (par->st_ino == cur->st_ino) { closedir(dirp); *--p = '/'; if (ruid != euid) (void)setuid(euid); if (path == buf) return(strdup(p)); if (path != p) { d = path; while (*d++ = *p++); } return(path); } while (entry = readdir(dirp)) if (entry->d_ino == cur->st_ino) { namlen = DIRNAMLEN(entry); goto found; } /* * this fallthrough handles logical naming */ rewinddir(dirp); } do { if (!(entry = readdir(dirp))) ERROR(ENOENT); namlen = DIRNAMLEN(entry); if ((d - dots) > (PATH_MAX - 1 - namlen)) ERROR(ERANGE); (void)memcpy(d, entry->d_name, namlen + 1); if (stat(dots, &tstst)) ERROR(errno); } while (tstst.st_ino != cur->st_ino || tstst.st_dev != cur->st_dev); found: if (*p) *--p = '/'; if ((p -= namlen) <= (path + 1)) ERROR(ERANGE); (void)memcpy(p, entry->d_name, namlen); closedir(dirp); dirp = 0; } error: if (dirp) closedir(dirp); if (ruid != euid) (void)setuid(euid); } return(0); } #else int _lib_dummy; #endif 0707070000000002011006440044230044230000010000000451442135700003700000001636preroot/ispreroot.c Ugsf Ggsf /* * AT&T Bell Laboratories * return 1 if dir [any dir] is the preroot */ #include <preroot.h> #if FS_PREROOT #include <sys/types.h> #include <sys/stat.h> static int same(); int ispreroot(dir) char* dir; { static int prerooted = -1; if (dir) return(same("/", dir)); if (prerooted < 0) prerooted = !same("/", PR_REAL); return(prerooted); } /* * return 1 if files a and b are the same under preroot * * NOTE: the kernel disables preroot for set-uid processes */ static int same(a, b) char* a; char* b; { int i; int euid; int ruid; struct stat ast; struct stat bst; extern int geteuid(); extern int getuid(); extern int setuid(); extern int stat(); if ((ruid = getuid()) != (euid = geteuid())) (void)setuid(ruid); i = !stat(a, &ast) && !stat(b, &bst) && ast.st_dev == bst.st_dev && ast.st_ino == bst.st_ino; if (ruid != euid) (void)setuid(euid); return(i); } #else int _lib_dummy; #endif 0707070000000002021006440044230044230000010000000451416302400003600000000767preroot/realopen.c Ugsf Ggsf /* * AT&T Bell Laboratories * disable preroot and open path relative to the real root */ #include <preroot.h> #if FS_PREROOT #include <limits.h> #ifndef PATH_MAX #define PATH_MAX 1024 #endif int realopen(path, mode, perm) char* path; int mode; int perm; { char buf[PATH_MAX + 8]; extern int open(); extern char* strcopy(); if (*path != '/' || !ispreroot((char*)0)) return(-1); (void)strcopy(strcopy(buf, PR_REAL), path); return(open(buf, mode, perm)); } #else int _lib_dummy; #endif 0707070000000002031006440044230044230000010000000460465034500004000000002117preroot/setpreroot.c Ugsf Ggsf /* * AT&T Bell Laboratories * force current command to run under dir preroot */ #include <preroot.h> #if FS_PREROOT #include <limits.h> #include <stdio.h> #ifndef PATH_MAX #define PATH_MAX 1024 #endif extern char* getenv(); extern char* malloc(); extern char* pathpath(); void setpreroot(argv, dir) register char** argv; char* dir; { register char* s; register char** ap; int argc; char* cmd; char** av; char buf[PATH_MAX]; extern char** opt_argv; if ((argv || (argv = opt_argv)) && (dir || (dir = getenv(PR_BASE)) && *dir) && !ispreroot(dir) && (*(cmd = *argv++) == '/' || (cmd = pathpath(buf, cmd, (char*)0, 031)))) { argc = 3; for (ap = argv; *ap++; argc++); if (av = (char**)malloc(argc * sizeof(char**))) { ap = av; *ap++ = PR_COMMAND; *ap++ = dir; *ap++ = cmd; while (*ap++ = *argv++); if (!(s = getenv(PR_SILENT)) || !*s) { fprintf(stderr, "+"); ap = av; while (s = *ap++) fprintf(stderr, " %s", s); fprintf(stderr, "\n"); fflush(stderr); } execv(*av, av); free(av); } } } #else int _lib_dummy; #endif 0707070000000002041006440044230044230000010000000475453717200002700000022664re/recomp.c Ugsf Ggsf /* * AT&T Bell Laboratories * * regular expression compiler * * derived from the 9th edition regexp(3): * * \[0-9] sub-expression references allowed in patterns * * 8 bit transparent * * ed(1) style syntax supported as option */ #include "relib.h" #if DEBUG #include <stdio.h> #endif typedef struct Node /* parser info */ { Inst* first; Inst* last; } Node; #define NSTACK 32 /* misc stack depth */ struct state { Node andstack[NSTACK]; Node* andp; int atorstack[NSTACK]; int* atorp; int subidstack[NSTACK]; /* parallel to atorstack */ int* subidp; int cursubid; /* current sub-expression id */ int refsubid; /* reference sub-expression id */ int lastwasand; /* last token was operand */ int nbra; unsigned char* exprp; /* next source expression char */ int nclass; Class* classp; Inst* freep; int errors; int flags; /* RE_MATCH if '\[0-9]' */ }; static struct state* re; /* compiler state */ #if __STDC__ || __cplusplus extern int chresc(const char*, char**); extern char* memset(char*, int, int); extern char* strcopy(char*, const char*); #else extern int chresc(); extern char* memset(); extern char* strcopy(); #endif static void rcerror(s) char* s; { re->errors++; reerror(s); } static void reerr2(s, c) register char* s; int c; { char buf[100]; s = strcopy(buf, s); *s++ = c; *s = 0; rcerror(buf); } static void cant(s) char* s; { char buf[100]; (void)strcopy(strcopy(buf, "internal error: "), s); rcerror(buf); } static Inst* newinst(t) int t; { re->freep->type = t; re->freep->left = 0; re->freep->right = 0; return(re->freep++); } static void pushand(f, l) Inst* f; Inst* l; { if (re->andp >= &re->andstack[NSTACK]) cant("operand stack overflow"); re->andp->first = f; re->andp->last = l; re->andp++; } static Node* popand(op) int op; { register Inst* inst; if (re->andp <= &re->andstack[0]) { reerr2("missing operand for ", op); inst = newinst(NOP); pushand(inst, inst); } return(--re->andp); } static void pushator(t) int t; { if (re->atorp >= &re->atorstack[NSTACK]) cant("operator stack overflow"); *re->atorp++ = t; *re->subidp++ = re->cursubid; } static int popator() { if (re->atorp <= &re->atorstack[0]) cant("operator stack underflow"); re->subidp--; return(*--re->atorp); } static void evaluntil(pri) register int pri; { register Node* op1; register Node* op2; register Inst* inst1; register Inst* inst2; while (pri == RBRA || re->atorp[-1] >= pri) { switch(popator()) { case LBRA: /* * must have been RBRA */ op1 = popand('('); inst2 = newinst(RBRA); inst2->subid = *re->subidp; op1->last->next = inst2; inst1 = newinst(LBRA); inst1->subid = *re->subidp; inst1->next = op1->first; pushand(inst1, inst2); return; case OR: op2 = popand('|'); op1 = popand('|'); inst2 = newinst(NOP); op2->last->next = inst2; op1->last->next = inst2; inst1 = newinst(OR); inst1->right = op1->first; inst1->left = op2->first; pushand(inst1, inst2); break; case CAT: op2 = popand(0); op1 = popand(0); op1->last->next = op2->first; pushand(op1->first, op2->last); break; case STAR: op2 = popand('*'); inst1 = newinst(OR); op2->last->next = inst1; inst1->right = op2->first; pushand(inst1, inst1); break; case PLUS: op2 = popand('+'); inst1 = newinst(OR); op2->last->next = inst1; inst1->right = op2->first; pushand(op2->first, inst1); break; case QUEST: op2 = popand('?'); inst1 = newinst(OR); inst2 = newinst(NOP); inst1->left = inst2; inst1->right = op2->first; op2->last->next = inst2; pushand(inst1, inst2); break; default: cant("unknown operator in evaluntil()"); break; } } } static void operator(t) register int t; { register int thisisand = 0; switch (t) { case LBRA: if (re->cursubid < RE_NMATCH) re->cursubid++; re->nbra++; if (re->lastwasand) operator(CAT); pushator(t); re->lastwasand = 0; break; case RBRA: if (--re->nbra < 0) rcerror("unmatched )"); evaluntil(t); re->lastwasand = 1; break; case STAR: case QUEST: case PLUS: thisisand = 1; /* fall through ... */ default: evaluntil(t); pushator(t); re->lastwasand = thisisand; break; } } static void operand(t) int t; { register Inst* i; /* * catenate is implicit */ if (re->lastwasand) operator(CAT); i = newinst(t); switch (t) { case CCLASS: i->cclass = re->classp[re->nclass - 1].map; break; case SUBEXPR: i->subid = re->refsubid; break; } pushand(i, i); re->lastwasand = 1; } static void optimize(pp) Prog* pp; { register Inst* inst; register Inst* target; for (inst = pp->firstinst; inst->type != END; inst++) { target = inst->next; while (target->type == NOP) target = target->next; inst->next = target; } } #if DEBUG static void dumpstack() { Node* stk; int* ip; printf("operators\n"); for (ip = re->atorstack; ip < re->atorp; ip++) printf("0%o\n", *ip); printf("operands\n"); for (stk = re->andstack; stk < re->andp; stk++) printf("0%o\t0%o\n", stk->first->type, stk->last->type); } static void dump(pp) Prog* pp; { Inst* l; l = pp->firstinst; do { printf("%d:\t0%o\t%d\t%d\n", l-pp->firstinst, l->type, l->left-pp->firstinst, l->right-pp->firstinst); } while (l++->type); } #endif static int nextc() { register int c; switch (c = *re->exprp++) { case 0: rcerror("missing ] in character class"); break; case '\\': if (!(c = chresc((char*)re->exprp - 1, (char**)&re->exprp))) rcerror("trailing \\ is invalid"); break; case ']': c = 0; break; } return(c); } static void bldcclass() { register int c1; register int c2; register char* map; register int negate; if (re->nclass >= NCLASS) reerr2("too many character classes -- limit ", NCLASS + '0'); map = re->classp[re->nclass++].map; (void)memset(map, 0, elements(re->classp[0].map)); /* * we have already seen the '[' */ if (*re->exprp == '^') { re->exprp++; negate = 1; } else negate = 0; if (*re->exprp == ']') { re->exprp++; setbit(map, ']'); } if (*re->exprp == '-') { re->exprp++; setbit(map, '-'); } while (c1 = c2 = nextc()) { if (*re->exprp == '-') { re->exprp++; c2 = nextc(); } for (; c1 <= c2; c1++) setbit(map, c1); } if (negate) for (c1 = 0; c1 < elements(re->classp[0].map); c1++) map[c1] = ~map[c1]; /* * always exclude '\0' */ clrbit(map, 0); } static int lex() { register int c; switch(c = *re->exprp++) { case 0: c = END; re->exprp--; break; case '\\': switch (c = *re->exprp++) { case 0: re->exprp--; rcerror("trailing \\ is invalid"); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if ((c - '0') > re->cursubid) reerr2("invalid sub-expression reference \\", c); else { re->refsubid = c - '0'; re->flags |= RE_MATCH; c = SUBEXPR; } break; case '?': if (re->flags & RE_EDSTYLE) c = QUEST; break; case '+': if (re->flags & RE_EDSTYLE) c = PLUS; break; case '|': if (re->flags & RE_EDSTYLE) c = OR; break; case '(': if (re->flags & RE_EDSTYLE) c = LBRA; break; case ')': if (re->flags & RE_EDSTYLE) c = RBRA; break; case '<': if (re->flags & RE_EDSTYLE) c = BID; break; case '>': if (re->flags & RE_EDSTYLE) c = EID; break; default: c = chresc((char*)re->exprp - 2, (char**)&re->exprp); break; } break; case '*': c = STAR; break; case '.': c = ANY; break; case '^': c = BOL; break; case '$': c = EOL; break; case '[': c = CCLASS; bldcclass(); break; case '?': if (!(re->flags & RE_EDSTYLE)) c = QUEST; break; case '+': if (!(re->flags & RE_EDSTYLE)) c = PLUS; break; case '|': if (!(re->flags & RE_EDSTYLE)) c = OR; break; case '(': if (!(re->flags & RE_EDSTYLE)) c = LBRA; break; case ')': if (!(re->flags & RE_EDSTYLE)) c = RBRA; break; case '<': if (!(re->flags & RE_EDSTYLE)) c = BID; break; case '>': if (!(re->flags & RE_EDSTYLE)) c = EID; break; } return(c); } #if __STDC__ || __cplusplus reprogram* recomp(const char* s, int reflags) #else reprogram* recomp(s, reflags) char* s; int reflags; #endif { register int token; Prog* pp; struct state restate; /* * get memory for the program */ if (!(pp = (Prog*)malloc(sizeof(Prog) + 3 * sizeof(Inst) * strlen(s)))) { rcerror("out of memory"); return(0); } re = &restate; re->freep = pp->firstinst; re->classp = pp->class; re->errors = 0; re->flags = reflags & ((1<<RE_EXTERNAL) - 1); /* * go compile the sucker */ re->exprp = (unsigned char*)s; re->nclass = 0; re->nbra = 0; re->atorp = re->atorstack; re->andp = re->andstack; re->subidp = re->subidstack; re->lastwasand = 0; re->cursubid = 0; /* * start with a low priority operator to prime parser */ pushator(START - 1); while ((token = lex()) != END) { if (token >= OPERATOR) operator(token); else operand(token); } /* * close with a low priority operator */ evaluntil(START); /* * force END */ operand(END); evaluntil(START); #if DEBUG dumpstack(); #endif if (re->nbra) rcerror("unmatched ("); re->andp--; /* * re->andp points to first and only operand */ pp->startinst = re->andp->first; pp->flags = re->flags; #if DEBUG dump(pp); #endif optimize(pp); #ifdef DEBUG printf("start: %d\n", re->andp->first-pp->firstinst); dump(pp); #endif if (re->errors) { free(pp); pp = 0; } return((reprogram*)pp); } /* * free program compiled by recomp() */ void refree(pp) reprogram* pp; { free(pp); } 0707070000000002051006440044230044230000010000000475446313600003000000000400re/reerror.c Ugsf Ggsf /* * AT&T Bell Laboratories * * regular expression error routine */ #include <re.h> #include <error.h> #if __STDC__ || __cplusplus void reerror(const char* s) #else void reerror(s) char* s; #endif { liberror("re", 3, "regular expression: %s", s); } 0707070000000002061006440044230044230000010000000475453466200002700000011530re/reexec.c Ugsf Ggsf /* * AT&T Bell Laboratories * * regular expression executor */ #include "relib.h" #include <ctype.h> #define LISTINCREMENT 8 typedef struct List { Inst* inst; /* instruction of the thread */ Subexp se; /* matched sub-expressions this thread */ } List; /* * note optimization in addinst: * *p must be pending when addinst called; if *l has been looked * at already, the optimization is a bug. */ static List* newthread(p, ip, sep) register List* p; /* list to add to */ register Inst* ip; /* instruction to add */ register Subexp* sep; /* pointers to sub-expressions */ { for (; p->inst; p++) if (p->inst == ip) { if (sep->m[0].sp < p->se.m[0].sp) p->se = *sep; return(0); } p->inst = ip; p->se = *sep; (++p)->inst = 0; return(p); } static void newmatch(mp, np) register Subexp* mp; register Subexp* np; { if (!mp->m[0].sp || np->m[0].sp < mp->m[0].sp || np->m[0].sp == mp->m[0].sp && np->m[0].ep > mp->m[0].ep) *mp = *np; } #if __STDC__ || __cplusplus int reexec(reprogram* aprogp, const char* starts) #else #ifndef const #define const #endif int reexec(progp, starts) Prog* progp; /* program to run */ char* starts; /* string to run program on */ #endif { #if __STDC__ || __cplusplus Prog* progp = (Prog*)aprogp; #endif register int flag = 0; register Inst* inst; register List* tlp; register const char* s; Subexp* mp; int checkstart; int startchar; List* tl; /* this list, next list */ List* nl; /* this list, next list */ List* tle; /* ends of this and next list */ List* nle; /* ends of this and next list */ List* list[2]; List* liste[2]; int match = 0; static int listsize = LISTINCREMENT; static Subexp sempty; /* empty set of matches */ startchar = progp->startinst->type < TOKEN ? progp->startinst->type : 0; mp = (progp->flags & RE_MATCH) ? &progp->subexp : 0; list[0] = 0; Restart: match = 0; checkstart = startchar; sempty.m[0].sp = 0; if (mp) mp->m[0].sp = mp->m[0].ep = 0; if (!list[0]) { if (!(list[0] = (List*)malloc(2 * listsize * sizeof(List)))) reerror("list overflow"); list[1] = list[0] + listsize; liste[0] = list[0] + listsize - 1; liste[1] = list[1] + listsize - 1; } list[0][0].inst = list[1][0].inst = 0; /* * execute machine once for each character, including terminal '\0' */ s = starts; do { /* * fast check for first char */ if (checkstart && *s != startchar) continue; tl = list[flag]; tle = liste[flag]; nl = list[flag ^= 1]; nle = liste[flag]; nl->inst = 0; /* * add first instruction to this list */ sempty.m[0].sp = (char*)s; (void)newthread(tl, progp->startinst, &sempty); /* * execute machine until this list is empty */ for (tlp = tl; inst = tlp->inst; tlp++) { /* * assignment = */ Switchstmt: switch (inst->type) { case LBRA: tlp->se.m[inst->subid].sp = (char*)s; inst = inst->next; goto Switchstmt; case RBRA: tlp->se.m[inst->subid].ep = (char*)s; inst = inst->next; goto Switchstmt; case ANY: goto Addinst; case BOL: if (s == starts) { inst = inst->next; goto Switchstmt; } break; case EOL: if (!*s) { inst = inst->next; goto Switchstmt; } break; case BID: if (s == starts || !isalnum(*(s - 1)) && *(s - 1) != '_') { inst = inst->next; goto Switchstmt; } break; case EID: if (!*s || !isalnum(*s) && *s != '_') { inst = inst->next; goto Switchstmt; } break; case CCLASS: if (tstbit(inst->cclass, *s)) goto Addinst; break; case OR: /* * evaluate right choice later */ if (newthread(tlp, inst->right, &tlp->se) == tle) goto Realloc; /* * efficiency: advance and re-evaluate */ inst = inst->left; goto Switchstmt; case SUBEXPR: { const char* ss; const char* ms = (char*)tlp->se.m[inst->subid].sp; const char* me = (char*)tlp->se.m[inst->subid].ep; #if DEBUG { int c; c = *me; *me = 0; error(-1, "subexpression %d ref=\"%s\"", inst->subid, ms); *me = c; error(-1, "subexpression %d src=\"%s\"", inst->subid, s); } #endif if (ms == me) { inst = inst->next; goto Switchstmt; } for (ss = s; ms < me && *ss++ == *ms; ms++); if (ms == me) { s = ss - 1; goto Addinst; } } break; case END: /* * match! */ match = 1; tlp->se.m[0].ep = (char*)s; if (mp) newmatch(mp, &tlp->se); break; default: /* * regular character */ if (inst->type == *s) { Addinst: if (newthread(nl, inst->next, &tlp->se) == nle) goto Realloc; } break; } } checkstart = startchar && !nl->inst; } while (*s++); return(match); Realloc: free(list[0]); list[0] = 0; listsize += LISTINCREMENT; goto Restart; } 0707070000000002071006440044230044230000010000000475356670400002600000004633re/relib.h Ugsf Ggsf /* * AT&T Bell Laboratories * * regular expression library private definitions */ #include <re.h> #include <limits.h> #define NCLASS 16 /* max # [...] expressions */ #define elements(x) (sizeof(x)/sizeof(x[0])) #define clrbit(set,bit) (set[(bit)/CHAR_BIT]&=~(1<<((bit)%CHAR_BIT))) #define setbit(set,bit) (set[(bit)/CHAR_BIT]|=(1<<((bit)%CHAR_BIT))) #define tstbit(set,bit) ((set[(bit)/CHAR_BIT]&(1<<((bit)%CHAR_BIT)))!=0) typedef struct /* sub-expression match table */ { rematch m[RE_NMATCH + 2]; } Subexp; typedef struct /* character class bit vector */ { char map[UCHAR_MAX / CHAR_BIT + 1]; } Class; typedef struct Inst /* machine instruction */ { int type; /* <TOKEN ==> literal, otherwise action */ union { int sid; /* sub-expression id for RBRA and LBRA */ struct Inst *other; /* for right child */ char *cls; /* CCLASS bit vector */ } u; struct Inst *left; /* left child */ } Inst; #define next left #define subid u.sid #define right u.other #define cclass u.cls /* * NOTE: subexp must be the first element to match reprogram.match */ typedef struct /* compiled program */ { Subexp subexp; /* sub-expression matches */ int flags; /* RE_* flags */ Inst *startinst; /* start pc */ Class class[NCLASS]; /* .data */ Inst firstinst[5]; /* .text */ } Prog; /* * tokens and actions * * TOKEN<=x<OPERATOR are tokens, i.e. operands for operators * >=OPERATOR are operators, value == precedence */ #define TOKEN (UCHAR_MAX+1) #define ANY (UCHAR_MAX+1) /* `.' any character */ #define NOP (UCHAR_MAX+2) /* no operation (internal) */ #define BOL (UCHAR_MAX+3) /* `^' beginning of line */ #define EOL (UCHAR_MAX+4) /* `$' end of line */ #define BID (UCHAR_MAX+5) /* `\<' begin identifier */ #define EID (UCHAR_MAX+6) /* `\>' end identifier */ #define CCLASS (UCHAR_MAX+7) /* `[]' character class */ #define SUBEXPR (UCHAR_MAX+8) /* `\#' sub-expression */ #define END (UCHAR_MAX+9) /* terminate: match found */ #define OPERATOR (UCHAR_MAX+11) #define START (UCHAR_MAX+11) /* start, stack marker */ #define RBRA (UCHAR_MAX+12) /* `)' right bracket */ #define LBRA (UCHAR_MAX+13) /* `(' left bracket */ #define OR (UCHAR_MAX+14) /* `|' alternation */ #define CAT (UCHAR_MAX+15) /* concatentation (implicit) */ #define STAR (UCHAR_MAX+16) /* `*' closure */ #define PLUS (UCHAR_MAX+17) /* a+ == aa* */ #define QUEST (UCHAR_MAX+18) /* a? == 0 or 1 a's */ 0707070000000002101006440044230044230000010000000475447565300002600000003614re/resub.c Ugsf Ggsf /* * AT&T Bell Laboratories * * regular expression match substitution */ #include "relib.h" #include <ctype.h> /* * do a single substitution */ /*ARGSUSED*/ #if __STDC__ || __cplusplus static char* sub(register const char* sp, register char* dp, register rematch* mp, int flags) #else static char* sub(sp, dp, mp, flags) register char* sp; register char* dp; register rematch* mp; int flags; #endif { register int i; char* s; for (;;) switch (*dp = *sp++) { case 0: return(dp); case '\\': switch (i = *sp++) { case 0: sp--; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': i -= '0'; if (mp[i].sp) { s = mp[i].sp; while (s < mp[i].ep) *dp++ = *s++; } break; default: *dp++ = chresc(sp - 2, &s); sp = s; break; } break; case '&': if (mp[0].sp) { s = mp[0].sp; while (s < mp[0].ep) *dp++ = *s++; } break; default: dp++; break; } } /* * ed(1) style substitute using matches from last reexec() */ #if __STDC__ || __cplusplus char* resub(reprogram* re, register const char* op, const char* sp, register char* dp, int flags) #else char* resub(re, op, sp, dp, flags) reprogram* re; /* compiled re */ register char* op; /* original subject string */ char* sp; /* substitution string */ register char* dp; /* destination string */ int flags; /* RE_ALL, RE_LOWER, RE_UPPER */ #endif { register rematch* mp; mp = re->match; do { while (op < mp->sp) *dp++ = *op++; op = dp; dp = sub(sp, dp, mp, flags); if (flags & (RE_LOWER|RE_UPPER)) { while (op < dp) { if (flags & RE_LOWER) { if (isupper(*op)) *(char*)op = tolower(*op); } else if (islower(*op)) *(char*)op = toupper(*op); op++; } } op = mp->ep; } while ((flags & RE_ALL) && *op && mp->sp != mp->ep && reexec(re, op)); while (*dp++ = *op++); return(--dp); } 0707070000000002111006440044230044230000010000000474665052300003600000000223sfio/_sfclearerr.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfclearerr(reg Sfile_t* f) #else sfclearerr(f) reg Sfile_t *f; #endif { return _SFCLEARERR(f); } 0707070000000002121006440044230044230000010000000474665201700003200000000567sfio/_sfecvt.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus char *sfecvt(reg double dval, int n_digit, int* decpt, int* sign) #else char *sfecvt(dval,n_digit,decpt,sign) reg double dval; /* value to convert */ int n_digit; /* number of digits wanted */ int *decpt; /* to return decimal point */ int *sign; /* to return sign */ #endif { return _SFECVT(dval,n_digit,decpt,sign); } 0707070000000002131006440044230044230000010000000474665044200003100000000204sfio/_sfeof.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfeof(reg Sfile_t* f) #else sfeof(f) reg Sfile_t *f; #endif { return _SFEOF(f); } 0707070000000002141006440044230044230000010000000474665042000003300000000212sfio/_sferror.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sferror(reg Sfile_t* f) #else sferror(f) reg Sfile_t *f; #endif { return _SFERROR(f); } 0707070000000002151006440044230044230000010000000474665204700003200000000567sfio/_sffcvt.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus char *sffcvt(reg double dval, int n_digit, int* decpt, int* sign) #else char *sffcvt(dval,n_digit,decpt,sign) reg double dval; /* value to convert */ int n_digit; /* number of digits wanted */ int *decpt; /* to return decimal point */ int *sign; /* to return sign */ #endif { return _SFFCVT(dval,n_digit,decpt,sign); } 0707070000000002161006440044230044230000010000000474665210000003400000000215sfio/_sffileno.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sffileno(reg Sfile_t* f) #else sffileno(f) reg Sfile_t *f; #endif { return _SFFILENO(f); } 0707070000000002171006440044230044230000010000000474665002500003200000000207sfio/_sfgetc.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfgetc(reg Sfile_t* f) #else sfgetc(f) reg Sfile_t *f; #endif { return _SFGETC(f); } 0707070000000002201006440044230044230000010000000474665144100003200000000221sfio/_sfgetl.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus long sfgetl(reg Sfile_t* f) #else long sfgetl(f) reg Sfile_t *f; #endif { return _SFGETL(f); } 0707070000000002211006440044230044230000010000000474665146500003200000000223sfio/_sfgetu.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus ulong sfgetu(reg Sfile_t* f) #else ulong sfgetu(f) reg Sfile_t *f; #endif { return _SFGETU(f); } 0707070000000002221006440044230044230000010000000474736247100003100000002073sfio/_sfhdr.h Ugsf Ggsf #include "sfhdr.h" /* This header file defines analogues for all public macro functions. The analogues are used for building function analogues. */ #define _SFPUTC(f,c) sfputc(f,c) #define _SFGETC(f) sfgetc(f) #define _SFSLEN() sfslen() #define _SFFILENO(f) sffileno(f) #define _SFORIGIN(f) sforigin(f) #define _SFEOF(f) sfeof(f) #define _SFERROR(f) sferror(f) #define _SFCLEARERR(f) sfclearerr(f) #define _SFPUSHED(f) sfpushed(f) #define _SFTMP(s) sftmp(s) #define _SFPEEK(f,bp) sfpeek(f,bp) #define _SFSYNC(f) sfsync(f) #define _SFULEN(v) sfulen(v) #define _SFGETU(f) sfgetu(f) #define _SFGETL(f) sfgetl(f) #define _SFPUTU(f,v) sfputu(f,v) #define _SFPUTL(f,v) sfputl(f,v) #define _SFPUTD(f,v) sfputd(f,v) #define _SFECVT(v,n,d,s) sfecvt(v,n,d,s) #define _SFFCVT(v,n,d,s) sffcvt(v,n,d,s) #undef sfputc #undef sfgetc #undef sfslen #undef sffileno #undef sforigin #undef sfeof #undef sferror #undef sfclearerr #undef sfpushed #undef sftmp #undef sfpeek #undef sfsync #undef sfulen #undef sfgetu #undef sfgetl #undef sfputu #undef sfputl #undef sfputd #undef sfecvt #undef sffcvt 0707070000000002231006440044230044230000010000000474665047000003400000000227sfio/_sforigin.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus long sforigin(reg Sfile_t* f) #else long sforigin(f) reg Sfile_t *f; #endif { return _SFORIGIN(f); } 0707070000000002241006440044230044230000010000000474665110500003200000000322sfio/_sfpeek.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfpeek(reg Sfile_t* f, uchar** bp) #else sfpeek(f,bp) reg Sfile_t *f; /* file to peek */ uchar **bp; /* start of data area */ #endif { return _SFPEEK(f,bp); } 0707070000000002251006440044230044230000010000000474670025400003400000000237sfio/_sfpushed.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus Sfile_t* sfpushed(reg Sfile_t* f) #else Sfile_t* sfpushed(f) reg Sfile_t *f; #endif { return _SFPUSHED(f); } 0707070000000002261006440044230044230000010000000474664775400003200000000242sfio/_sfputc.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfputc(reg Sfile_t* f, reg int c) #else sfputc(f,c) reg Sfile_t *f; reg int c; #endif { return _SFPUTC(f,c); } 0707070000000002271006440044230044230000010000000474665164200003200000000247sfio/_sfputd.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfputd(reg Sfile_t* f, reg double v) #else sfputd(f,v) reg Sfile_t *f; reg double v; #endif { return _SFPUTD(f,v); } 0707070000000002301006440044230044230000010000000474665160400003200000000243sfio/_sfputl.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfputl(reg Sfile_t* f, reg long v) #else sfputl(f,v) reg Sfile_t *f; reg long v; #endif { return _SFPUTL(f,v); } 0707070000000002311006440044230044230000010000000474665155000003200000000245sfio/_sfputu.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfputu(reg Sfile_t* f, reg ulong v) #else sfputu(f,v) reg Sfile_t *f; reg ulong v; #endif { return _SFPUTU(f,v); } 0707070000000002321006440044230044230000010000000474665007600003200000000065sfio/_sfslen.c Ugsf Ggsf #include "_sfhdr.h" sfslen() { return _SFSLEN(); } 0707070000000002331006440044230044230000010000000474665120500003200000000251sfio/_sfsync.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus _sfsync(reg Sfile_t* f) #else _sfsync(f) reg Sfile_t *f; /* stream to be synchronized */ #endif { return _SFSYNC(f); } 0707070000000002341006440044230044230000010000000474665070500003100000000214sfio/_sftmp.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus Sfile_t* sftmp(reg int n) #else Sfile_t* sftmp(n) reg int n; #endif { return _SFTMP(n); } 0707070000000002351006440044230044230000010000000474665133500003200000000201sfio/_sfulen.c Ugsf Ggsf #include "_sfhdr.h" #if __STDC__ || __cplusplus sfulen(reg ulong v) #else sfulen(v) reg ulong v; #endif { return _SFULEN(v); } 0707070000000002361006440044230044230000010000000475416407600003200000003720sfio/sfclose.c Ugsf Ggsf #include "sfhdr.h" /* Close a given file stream. If the file stream is associated with ** a process via sfpopen(), both streams will be closed. The closed ** stream is synced. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfclose(reg Sfile_t *f) #else sfclose(f) reg Sfile_t *f; #endif { reg int rv, flags; if(!f) { /* close-all */ while(1) { reg Sfpool_t *p; /* the "goto" is because the lists change after each sfclose */ for(p = &_Sfpool; p != NIL(Sfpool_t*); p = p->fore) for(f = p->head; f; f = f->fore) if(!SFFROZEN(f)) goto close_f; close_f: if(!f) return 0; (void) sfclose(f); } } if(SFFROZEN(f)) return -1; flags = f->flags; /* closing a stack of streams */ while(f->push) if(sfclose((*_Sfstack)(f,NIL(Sfile_t*))) < 0) return -1; /* tell the register function */ if(_Sfnotify) (*_Sfnotify)(f,SF_EOF); /* this is from popen */ if(_Sfpclose && (flags&SF_PROCESS)) return (*_Sfpclose)(f); /* sync file pointer */ f->mode &= ~SF_POOL; rv = sfsync(f); /* terminate discipline */ if(f->disc && f->disc->exceptf) (*(f->disc->exceptf))(f,SF_EOF,f->disc->handle); /* free space used */ if(!(flags&SF_REUSE)) { /* remove from the list of active streams */ if(f->pool) { if(_Sfpmove) (*_Sfpmove)(f,-1); else { if(f->fore) f->fore->back = f->back; if(f->back) f->back->fore = f->fore; else f->pool->head = f->fore; } f->pool = NIL(Sfpool_t*); f->fore = f->back = NIL(Sfile_t*); } f->disc = NIL(Sfdisc_t*); if(f->data && (flags&SF_MALLOC)) { free((char*)f->data); f->data = NIL(uchar*); f->size = 0; } } if(!(flags&(SF_KEEPFD|SF_STRING))) while(close(f->file) < 0 && errno == EINTR) errno = 0; f->file = -1; if(!(flags&SF_REUSE) && f != sfstdin && f != sfstdout && f != sfstderr) SFFREE(f); else { f->mode = 0; f->flags = 0; f->here = f->orig = 0L; f->endb = f->endr = f->endw = f->next = f->data; } return rv; } 0707070000000002371006440044230044230000010000000475414054700003400000000610sfio/sfclrlock.c Ugsf Ggsf #include "sfhdr.h" /* Function to clear a locked stream. ** This is useful for programs that longjmp from the mid of an sfio function. ** There is no guarantee on data integrity in such a case. ** ** Written by Kiem-Phong Vo (07/20/90). */ #if __STDC__ || __cplusplus sfclrlock(reg Sfile_t* f) #else sfclrlock(f) reg Sfile_t *f; #endif { f->mode &= ~SF_LOCK; return sfset(f,f->flags,1); } 0707070000000002401006440044230044230000010000000471533620500003000000005424sfio/sfcvt.c Ugsf Ggsf #include "sfhdr.h" /* Convert a floating point value to ASCII ** This function unifies fcvt() and ecvt() in libc.a. ** ** Written by Kiem-Phong Vo (06/27/90) */ #define INTPART (IDIGITS/2) #define INFINITE (_Sfi = 3, "Inf") #define ZERO (_Sfi = 1, "0") #if __STDC__ || __cplusplus char *_sfcvt(reg double dval, int n_digit, int* decpt, int* sign, int e_format) #else char *_sfcvt(dval,n_digit,decpt,sign,e_format) reg double dval; /* value to convert */ int n_digit; /* number of digits wanted */ int *decpt; /* to return decimal point */ int *sign; /* to return sign */ int e_format; /* doing e-format */ #endif { #ifdef NATIVE /* NATIVE *cvt() can do this faster than we can */ reg char *sp; extern char *fcvt(), *ecvt(); sp = e_format ? ecvt(dval,n_digit,decpt,sign) : fcvt(dval,n_digit,decpt,sign); _Sfi = strlen(sp); return sp; #else reg long n, v, w; reg char *sp, *ep, *buf, *endsp; static char *Buf; /* set up local buffer */ if(!Buf && !(Buf = malloc(MAXDIGITS))) return INFINITE; *sign = *decpt = 0; if(dval == 0.) return ZERO; else if(*sign = (dval < 0.)) /* assignment = */ dval = -dval; n = 0; if(dval >= (double)MAXLONG) { /* scale to a small enough number to fit an int */ v = MAXEXP10-1; do { if(dval < _Sfpos10[v]) v -= 1; else { dval *= _Sfneg10[v]; if((n += (1<<v)) >= IDIGITS) return INFINITE; } } while(dval >= (double)MAXLONG); } else if(dval < 1e-1) { /* scale to get rid of leading zeros */ v = MAXEXP10-1; do { if(dval > _Sfneg10[v]) v -= 1; else { dval *= _Sfpos10[v]; if((n -= (1<<v)) <= -IDIGITS) return ZERO; } } while(dval < 1e-1); } *decpt = (int)n; buf = sp = Buf+INTPART; if((v = (int)dval) != 0) { /* translate the integer part */ dval -= (double)v; sfucvt(v,sp,n,w,ep); n = buf-sp; if((*decpt += (int)n) >= IDIGITS) return INFINITE; buf = sp; sp = Buf+INTPART; } else n = 0; /* remaining number of digits to compute; add 1 for later rounding */ n = ((e_format || *decpt <= 0) ? 1 : *decpt+1) - n; if(n_digit > 0) n += n_digit; if((ep = (sp+n)) > (endsp = Buf+(MAXDIGITS-2))) ep = endsp; if(sp > ep) sp = ep; else while(sp < ep) { /* generate fractional digits */ if(dval <= 0.) { /* fill with 0's */ do { *sp++ = '0'; } while(sp < ep); goto done; } *sp++ = (char)('0' + (n = (int)(dval *= 10.))); dval -= (double)n; } if(ep <= buf) ep = buf+1; else if(ep < endsp) { /* round the last digit */ *--sp += 5; while(*sp > '9') { *sp = '0'; if(sp > buf) *--sp += 1; else { /* next power of 10 */ *sp = '1'; *decpt += 1; if(!e_format) { /* add one more 0 for %f precision */ ep[-1] = '0'; ep += 1; } } } } done: *--ep = '\0'; _Sfi = ep-buf; return buf; #endif /*NATIVE*/ } 0707070000000002411006440044230044230000010000000471533623700003100000001116sfio/sfdlen.c Ugsf Ggsf #include "sfhdr.h" /* Return the length of a double value if coded in a portable format ** ** Written by Kiem-Phong Vo (08/05/90) */ #if __STDC__ || __cplusplus sfdlen(reg double v) #else sfdlen(v) reg double v; #endif { #define N_ARRAY (16*sizeof(double)) reg int n, w; reg double x; int exp; if(v < 0) v = -v; /* make the magnitude of v < 1 */ if(v != 0.) v = frexp(v,&exp); else exp = 0; for(w = 1; w <= N_ARRAY; ++w) { /* get 2^SF_PRECIS precision at a time */ n = (int)(x = ldexp(v,SF_PRECIS)); if((v = x-n) <= 0.) break; } return 1 + sfulen(exp) + w; } 0707070000000002421006440044230044230000010000000475453567200003200000001611sfio/sfdopen.c Ugsf Ggsf #include "sfhdr.h" /* Open a stream given a file descriptor. ** ** Written by Kiem-Phong Vo (06/27/90). */ #if !__STDC__ && !__cplusplus #ifndef const #define const #endif #endif Sfile_t *sfdopen(fd,mode) reg int fd; reg const char *mode; { reg int sflags; reg Sfile_t *f; if(fd < 0 || !mode || !mode[0]) return NIL(Sfile_t*); /* construct the open flags */ sflags = 0; while(1) switch(*mode++) { case 'w' : sflags = SF_WRITE; break; case 'a' : (void) lseek(fd,0L,2); sflags = SF_WRITE | SF_APPEND; break; case 'r' : sflags = SF_READ; break; case '+' : sflags |= SF_READ|SF_WRITE; case 'b' : break; case 0 : goto e_mode; default : return NIL(Sfile_t*); } e_mode: if(!sflags) return NIL(Sfile_t*); if((f = sfnew(NIL(Sfile_t*),NIL(uchar*),-1,fd,sflags)) != NIL(Sfile_t*)) if(mode[0] != 'r' && f->mode != SF_WRITE) _sfmode(f,SF_WRITE); return f; } 0707070000000002431006440044230044230000010000000474736226600003300000003334sfio/sfexcept.c Ugsf Ggsf #include "sfhdr.h" /* Function to handle io exceptions. ** Written by Kiem-Phong Vo (8/18/90) */ #if __STDC__ || __cplusplus _sfexcept(reg Sfile_t* f, reg int type, reg int io) #else _sfexcept(f,type,io) reg Sfile_t *f; /* stream where the exception happened */ reg int type; /* io type that was performed */ reg int io; /* the io return value that indicated exception */ #endif { reg int d; reg uchar *data; reg int (*exceptf)_SFA_((Sfile_t*,int,char*)); reg char *handle; f->flags |= io < 0 ? SF_ERROR : SF_EOF; exceptf = f->disc ? f->disc->exceptf : NIL(int(*)_SFA_((Sfile_t*,int,char*))); handle = f->disc ? f->disc->handle : NIL(char*); if(exceptf) { /* check with discipline function */ SFOPEN(f); d = (*exceptf)(f,type,handle); SFLOCK(f); if(d < 0) return SF_EDONE; else if(d > 0) return SF_EDISC; } /* handle default cases for string streams */ if((f->mode&SF_STRING) && io >= 0) { if(type == SF_READ || (f->size >= 0 && !(f->flags&SF_MALLOC))) goto chk_stack; /* extend buffer */ if((d = f->size) < 0) d = 0; d = ((d+io+SF_GRAIN)/SF_GRAIN)*SF_GRAIN; data = (uchar*)(f->size > 0 ? realloc((char*)f->data,d) : malloc(d)); if(!data) goto chk_stack; f->flags |= SF_MALLOC; f->endr = f->endw = f->data = data; f->endb = data+d; f->next = data+(f->size > 0 ? f->size : 0); f->size = d; return SF_ECONT; } if(errno == EINTR) { /* if just an interrupt, we can continue */ errno = 0; f->flags &= ~(SF_EOF|SF_ERROR); return SF_ECONT; } chk_stack: if(f->push && ((type == SF_READ && f->next >= f->endb) || (type == SF_WRITE && f->next <= f->data))) { /* pop the stack */ SFOPEN(f); sfclose((*_Sfstack)(f,NIL(Sfile_t*))); return SF_ESTACK; } return SF_EDONE; } 0707070000000002441006440044230044230000010000000475416411700003300000003666sfio/sfextern.c Ugsf Ggsf #include "sfhdr.h" /* External variables used by sfio ** Written by Kiem-Phong Vo (06/27/90) */ Sfile_t _Sfstdin = { NIL(uchar*), /* next */ NIL(uchar*), /* endw */ NIL(uchar*), /* endr */ NIL(uchar*), /* endb */ NIL(Sfile_t*), /* push */ SF_READ, /* flags */ 0, /* file */ 0L, /* orig */ 0, /* size */ NIL(uchar*), /* data */ 0L, /* here */ 0, /* mode: will be set by sfmode() */ "", /* tiny */ NIL(Sfdisc_t*), /* disc */ &_Sfpool, /* pool */ NIL(Sfile_t*), /* back */ &_Sfstdout /* fore */ }; Sfile_t _Sfstdout = { NIL(uchar*), /* next */ NIL(uchar*), /* endw */ NIL(uchar*), /* endr */ NIL(uchar*), /* endb */ NIL(Sfile_t*), /* push */ SF_WRITE, /* flags */ 1, /* file */ 0L, /* orig */ 0, /* size */ NIL(uchar*), /* data */ 0L, /* here */ 0, /* mode: will be set by sfmode() */ "", /* tiny */ NIL(Sfdisc_t*), /* disc */ &_Sfpool, /* pool */ &_Sfstdin, /* back */ &_Sfstderr /* fore */ }; Sfile_t _Sfstderr = { NIL(uchar*), /* next */ NIL(uchar*), /* endw */ NIL(uchar*), /* endr */ NIL(uchar*), /* endb */ NIL(Sfile_t*), /* push */ SF_WRITE, /* flags */ 2, /* file */ 0L, /* orig */ 0, /* size */ NIL(uchar*), /* data */ 0L, /* here */ 0, /* mode: will be set by sfmode() */ "", /* tiny */ NIL(Sfdisc_t*), /* disc */ &_Sfpool, /* pool */ &_Sfstdout, /* back */ NIL(Sfile_t*) /* fore */ }; Sfpool_t _Sfpool = /* the discrete pool of streams */ { 0, &_Sfstdin, NIL(Sfpool_t*), NIL(Sfpool_t*) }; Sfile_t *_Sffree; /* free list of streams */ Fa_t *_Fafree; /* free list of format/arglist stack objects */ int _Sfi; /* for fast integer decoding */ int (*_Sfpclose)_SFA_((Sfile_t*)); /* to close a sfpopen-stream */ int (*_Sfpmove)_SFA_((Sfile_t*, int)); /* to move a stream in a pool */ Sfile_t *(*_Sfstack)_SFA_((Sfile_t*, Sfile_t*));/* to manipulate a stack of streams */ void (*_Sfnotify)_SFA_((Sfile_t*, int)); /* to register streams */ 0707070000000002451006440044230044230000010000000472652346300003300000004430sfio/sffilbuf.c Ugsf Ggsf #include "sfhdr.h" /* Fill the buffer of a stream with data. ** sffilbuf behaves differently based on the second argument 'type'. ** If type > 0, the first byte read is returned. ** If type == 0 and in line mode, sffilbuf tries to read up to \n and ** if \n is detected, the number of bytes up to \n is returned. ** In all other cases, the number of bytes read is returned. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _sffilbuf(reg Sfile_t* f, int type) #else _sffilbuf(f,type) reg Sfile_t *f; /* fill the read buffer of this stream */ int type; /* see above */ #endif { reg int r, n; reg uchar *s, *data, *endb, *line, c; reg int (*readf) _SFA_((Sfile_t*, uchar*, int, char*)); reg long (*seekf) _SFA_((Sfile_t*, long, int, char*)); reg char *handle; redo_loop: if(f->mode != SF_READ && SFMODE(f,SF_READ) < 0) return -1; SFLOCK(f); readf = f->disc ? f->disc->readf : NIL(int(*) _SFA_((Sfile_t*,uchar*,int,char*))); seekf = f->disc ? f->disc->seekf : NIL(long(*) _SFA_((Sfile_t*,long,int,char*))); handle = f->disc ? f->disc->handle : NIL(char*); if(((endb = f->endb) - f->next) <= 0) { /* no more string data */ if(f->mode&SF_STRING) { r = 0; goto at_eof; } endb = f->next = f->endb = f->endr = f->data; } else if(type > 0) goto done; line = NIL(uchar*); n = f->size - (endb - f->data); data = endb; while(n > 0) { if(f->flags&SF_SHARE) f->here = SEEKF(seekf,f,f->here,0,handle); if((r = READF(readf,f,data,n,handle)) > 0) { f->here += r; f->endb = (endb += r); if(type > 0) /* return a char */ goto done; /* normal filbuf */ if(type < 0 || !(f->flags&SF_LINE)) goto done; /* must see a \n */ c = endb[-1]; endb[-1] = '\n'; s = data; while(*s++ != '\n') ; endb[-1] = c; if(s < endb || c == '\n') { line = s; goto done; } /* read some more */ n -= r; data += r; } else { /* eof or error */ at_eof : switch(_sfexcept(f,SF_READ,r)) { case SF_ESTACK : if(f->next < (endb = f->endb)) goto done; /* else fall through */ case SF_EDISC : SFopen(f); goto redo_loop; case SF_EDONE : goto done; } } } done: r = type > 0 ? (f->next < endb ? (int)(*f->next++) : EOF) : ((line ? line : endb) - f->next); SFOPEN(f); return r; } 0707070000000002461006440044230044230000010000000475116766300003300000005016sfio/sfflsbuf.c Ugsf Ggsf #include "sfhdr.h" /* Write a buffer out to a file descriptor or ** extending a buffer for a SF_STRING stream. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _sfflsbuf(reg Sfile_t* f, reg int c) #else _sfflsbuf(f,c) reg Sfile_t *f; /* write out the buffered content of this stream */ reg int c; /* if c>=0, c is also written out */ #endif { reg int n, w; reg uchar *data; reg int (*writef) _SFA_((Sfile_t*, const uchar*, int, char*)); reg long (*seekf) _SFA_((Sfile_t*, long, int, char*)); reg char *handle; uchar outc; int inpc = c; redo_loop: if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; SFLOCK(f); writef = f->disc ? f->disc->writef : NIL(int(*)_SFA_((Sfile_t*, const uchar*, int, char*))); seekf = f->disc ? f->disc->seekf : NIL(long(*)_SFA_((Sfile_t*, long, int, char*))); handle = f->disc ? f->disc->handle : NIL(char*); n = f->next - (data = f->data); if(n >= f->size && (f->mode&SF_STRING)) { /* at eof */ w = 0; goto at_eof; } if(c >= 0) { /* there is still space in the buffer */ if(n < f->size) { *f->next++ = c; w = 1; if(c != '\n' || (f->flags&SF_STRING) || !(f->flags&SF_LINE)) goto done; n += 1; c = -1; } else if(n == 0) { /* unbuffered io */ outc = (uchar)c; data = &outc; n = 1; c = -1; } } else if(n <= 0) { /* no op */ w = 0; goto done; } /* write data to file */ f->next = f->data; for(;;) { /* make sure we are at the right place before writing */ #ifdef NO_OFLAGS /* simulate append mode */ if(f->flags&SF_APPEND) f->here = SEEKF(seekf,f,0L,2,handle); else /* no, it doesn't dangle */ #endif if(f->flags&SF_SHARE) f->here = SEEKF(seekf,f,f->here,0,handle); if((w = WRITEF(writef,f,data,n,handle)) > 0) { /* successful write */ f->here += w; if((n -= w) > 0) data += w; else if(c < 0) goto done; else if(c == '\n' && (f->flags&SF_LINE)) { /* line buffering */ outc = '\n'; data = &outc; n = 1; c = -1; } else { *f->next++ = c; goto done; } } else { at_eof : if(data == &outc) c = outc; else { /* save unwritten data */ if(data != f->data) memcpy((char*)f->data,(char*)data,n); f->next = f->data+n; } switch(_sfexcept(f,SF_WRITE,w)) { default : case SF_EDISC : case SF_ESTACK : SFopen(f); goto redo_loop; case SF_EDONE : if(c >= 0 && f->next < f->endb) *f->next++ = c; w = -1; goto done; } } } done : SFOPEN(f); return (inpc < 0 || w < 0) ? w : inpc; } 0707070000000002471006440044230044230000010000000471533746700003100000001357sfio/sfgetd.c Ugsf Ggsf #include "sfhdr.h" /* Read a portably coded double value ** ** Written by Kiem-Phong Vo (08/05/90) */ #if __STDC__ || __cplusplus double sfgetd(Sfile_t* f) #else double sfgetd(f) Sfile_t *f; #endif { reg uchar *s, *ends, c; reg double v; reg int p, sign, exp; if((sign = sfgetc(f)) < 0 || (exp = (int)sfgetu(f)) < 0) return -1.; SFLOCK(f); v = 0.; for(;;) { /* fast read for data */ if(SFRPEEK(f,s,p) <= 0) { f->flags |= SF_ERROR; v = -1.; goto done; } for(ends = s+p; s < ends; ) { c = *s++; v += SFUVALUE(c); v = ldexp(v,-SF_PRECIS); if(!(c&SF_MORE)) { f->next = s; goto done; } } f->next = s; } done: v = ldexp(v,(sign&02) ? -exp : exp); if(sign&01) v = -v; SFOPEN(f); return v; } 0707070000000002501006440044230044230000010000000471531654200003100000001407sfio/sfgetl.c Ugsf Ggsf #include "sfhdr.h" /* Read a long value coded in a portable format. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus long _sfgetl(reg Sfile_t* f) #else long _sfgetl(f) reg Sfile_t *f; #endif { reg uchar *s, *ends, c; reg int p; reg long v; if(_Sfi&SF_SIGN) return -SFSVALUE(_Sfi)-1; SFLOCK(f); v = SFUVALUE(_Sfi); for(;;) { if(SFRPEEK(f,s,p) <= 0) { f->flags |= SF_ERROR; v = -1; goto done; } for(ends = s+p; s < ends;) { c = *s++; if(c&SF_MORE) v = ((ulong)v << SF_UBITS) | SFUVALUE(c); else { /* special translation for this byte */ v = ((ulong)v << SF_SBITS) | SFSVALUE(c); f->next = s; v = (c&SF_SIGN) ? -v-1 : v; goto done; } } f->next = s; } done : SFOPEN(f); return v; } 0707070000000002511006440044230044230000010000000475215125400003100000003510sfio/sfgets.c Ugsf Ggsf #include "sfhdr.h" /* Read a line into a buffer. The line length is saved in the ** stream buffer and can be accessed via sfslen(). If the buffer ** size n is <= 0, the string will be kept in a static area. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus char *sfgets(reg Sfile_t *f, char* us, reg int n) #else char *sfgets(f,us,n) reg Sfile_t *f; /* stream to read from */ char *us; /* space to read into */ reg int n; /* max number of bytes to read */ #endif { reg uchar *ps, *s; reg int p; static uchar *Sfs; static int Sfn; if(f->mode != SF_READ && SFMODE(f,SF_READ) < 0) return NIL(char*); SFLOCK(f); if(n <= 0 || !us) { us = (char*)Sfs; n = -1; } else n -= 1; s = (uchar*)us; while(n) { /* peek the read buffer for data */ if(SFRPEEK(f,ps,p) <= 0) break; /* set amount copyable right now */ if(p > n) { if(n > 0) p = n; else { /* make sure our buffer has space */ n = s - Sfs; if(n >= Sfn-1) { Sfn += SF_GRAIN; Sfs = Sfs ? (uchar*)realloc((char*)Sfs,Sfn) : (uchar*)malloc(Sfn); if(!Sfs) { /* can't get more space */ Sfs = (uchar*)us; Sfn -= SF_GRAIN; break; } else { us = (char*)Sfs; s = Sfs+n; } } /* copy at most this much */ if(p > (n = (Sfn-1)-n)) p = n; n = -1; } } if((f->flags&SF_STRING) && !(f->flags&SF_WRITE)) { reg uchar *endps = ps+p; while(ps < endps && (*s++ = *ps++) != '\n') ; } else { reg int c = ps[p-1]; ps[p-1] = '\n'; while((*s++ = *ps++) != '\n') ; if((ps - f->next) == p) s[-1] = c; f->next[p-1] = c; } /* gobble up read data */ f->next = ps; if(ps[-1] == '\n') break; else if(n > 0) n -= p; } if((_Sfi = s - ((uchar*)us)) <= 0) us = NIL(char*); else *s = '\0'; done : SFOPEN(f); return us; } 0707070000000002521006440044230044230000010000000473117502400003100000001252sfio/sfgetu.c Ugsf Ggsf #include "sfhdr.h" /* Read an unsigned long value coded in a portable format. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus ulong _sfgetu(reg Sfile_t* f) #else ulong _sfgetu(f) reg Sfile_t *f; #endif { reg uchar *s, *ends, c; reg int p; reg ulong v; if(f->mode != SF_READ && SFMODE(f,SF_READ) < 0) return -1L; SFLOCK(f); v = SFUVALUE(_Sfi); for(;;) { if(SFRPEEK(f,s,p) <= 0) { f->flags |= SF_ERROR; v = (ulong)(-1); goto done; } for(ends = s+p; s < ends;) { c = *s++; v = (v << SF_UBITS) | SFUVALUE(c); if(!(c&SF_MORE)) { f->next = s; goto done; } } f->next = s; } done: SFOPEN(f); return v; } 0707070000000002531006440044230044230000010000000475447604400003000000023455sfio/sfhdr.h Ugsf Ggsf #ifndef _SFHDR_H #define _SFHDR_H /* Internal definitions for sfio. ** Written by Kiem-Phong Vo (07/16/90) ** AT&T Bell Laboratories */ /* the parts of Sfio_t private to sfio functions */ #define _SFIO_PRIVATE \ int size; /* buffer size */ \ unsigned char *data; /* data buffer */ \ long here; /* current physical location */ \ unsigned char mode; /* current io mode */ \ unsigned char tiny[1];/* for unbuffered read stream */ \ struct _sfdc_ *disc; /* discipline */ \ struct _sfpl_ *pool; /* the pool containing this */ \ struct _sfio_ *back; /* backward link in pool */ \ struct _sfio_ *fore; /* forward link in pool */ #include "sfio.h" #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <ctype.h> #include <fcntl.h> #if __STDC__ || __cplusplus #include <stdarg.h> #else #include <varargs.h> #endif #define uchar unsigned char #define ulong unsigned long #define uint unsigned int #define reg register #define NIL(p) ((p)0) /* stream pool structure. */ typedef struct _sfpl_ { int mode; /* type of pool */ Sfile_t *head; /* head of pool's stream list */ struct _sfpl_ *back; /* linked list of pools */ struct _sfpl_ *fore; } Sfpool_t; /* extension structures for sfvprintf/sfvscanf */ typedef int(*Argf_s)_SFA_((char,char*,uint)); typedef int(*Extf_s)_SFA_((Sfile_t*,int,int,char**)); typedef int(*Argf_p)_SFA_((int,char*)); typedef int(*Extf_p)_SFA_((char*,int,int,char*)); typedef struct _fa_ { char *form; /* format string */ va_list args; /* corresponding arglist */ union { Argf_s s; /* argf for sfvscanf */ Argf_p p; /* argf for sfvprintf */ } argf; union { Extf_s s; /* extf for sfvscanf */ Extf_p p; /* extf for sfvprintf */ } extf; struct _fa_ *next; /* next on the stack */ } Fa_t; #define FAMALLOC(f) ((f = _Fafree) ? (_Fafree = f->next, f) : \ (f = (Fa_t*)malloc(sizeof(Fa_t)))) #define FAFREE(f) (f->next = _Fafree, _Fafree = f) /* function to clear an sfio structure */ #define SFCLEAR(f) \ ((f)->next = (f)->endw = (f)->endr = (f)->endb = (f)->data = NIL(uchar*), \ (f)->flags = 0, (f)->file = -1, (f)->orig = (f)->here = -1L, \ (f)->mode = 0, (f)->size = 0, (f)->disc = NIL(Sfdisc_t*), \ (f)->pool = NIL(Sfpool_t*), (f)->push = (f)->back = (f)->fore = NIL(Sfile_t*)) /* get the real value of a byte in a coded long or ulong */ #define SFUVALUE(v) ((v)&(SF_MORE-1)) #define SFSVALUE(v) ((v)&(SF_SIGN-1)) /* amount of precision to get in each iteration during coding of doubles */ #define SF_PRECIS (SF_UBITS-1) /* garin size for buffer increment */ #define SF_GRAIN 1024 /* bits for the mode field */ #define SF_SYNC 0010 /* stream was synced */ #define SF_PUSH 0020 /* stream has been pushed */ #define SF_LOCK 0040 /* stream is locked for io op */ #define SF_POOL 0200 /* stream is in a pool but not current */ /* check to see if the stream can be accessed */ #define SFFROZEN(f) ((f)->mode&(SF_PUSH|SF_LOCK)) /* NOTE: these flags share the same space with the public flags */ #define SF_PROCESS 0010000 /* this stream is sfpopen */ #define SF_PUTC 0020000 /* sfputc ok on this stream */ #define SF_GETC 0040000 /* sfgetc ok on this stream */ #define SF_BOTH 0100000 /* both read/write */ /* lock/open a stream */ #define SFlock(f) ((f)->mode |= SF_LOCK) #define SFopen(f) ((f)->mode &= ~SF_LOCK) #define SFLOCK(f) (SFlock(f), (f)->endr = (f)->endw = (f)->data) #define SFOPEN(f) (SFopen(f), \ (f)->endr = ((f)->flags&SF_GETC) ? (f)->endb : (f)->data, \ (f)->endw = ((f)->flags&SF_PUTC) ? (f)->endb : (f)->data) /* short-hand for common stream types */ #define SF_RDWR (SF_READ|SF_WRITE) #define SF_RDSTR (SF_READ|SF_STRING) #define SF_WRSTR (SF_WRITE|SF_STRING) /* exception types */ #define SF_EDONE 0 /* stop this operation and return */ #define SF_EDISC 1 /* discipline says it's ok */ #define SF_ESTACK 2 /* stack was popped */ #define SF_ECONT 3 /* can continue normally */ /* more than this for a line buffer, we might as well flush */ #define HIFORLINE 128 /* read/write/seek functions with disciplines */ #define READF(rdfn,f,d,n,hdl) ((rdfn) ? (*(rdfn))(f,d,n,hdl) : read((f)->file,d,n)) #define WRITEF(wrfn,f,d,n,hdl) ((wrfn) ? (*(wrfn))(f,d,n,hdl) : write((f)->file,(char*)d,n)) #define SEEKF(skfn,f,p,o,hdl) ((skfn) ? (*(skfn))(f,p,o,hdl) : lseek((f)->file,p,o)) /* control flags for open() */ #ifndef O_CREAT /* V9 */ #define NO_OFLAGS #define O_CREAT 004 #define O_TRUNC 010 #define O_APPEND 020 #ifndef O_RDONLY #define O_RDONLY 000 #endif #ifndef O_WRONLY #define O_WRONLY 001 #endif #ifndef O_RDWR #define O_RDWR 002 #endif #endif /* floating point to ascii conversion */ #define MAXLONG ((long)(((ulong)~0L) >> 1)) #define MAXEXP10 6 #define MAXPOW10 (1 << MAXEXP10) #define FDIGITS 60 /* max allowed fractional digits */ #define IDIGITS 1536 /* max number of digits in int part */ #define MAXDIGITS (((FDIGITS+IDIGITS)/sizeof(int) + 1)*sizeof(int)) /* sfucvt() converts decimal integers to ASCII */ #define SFDIGIT(v,scale,digit) \ { if(v < 5*scale) \ if(v < 2*scale) \ if(v < 1*scale) \ { digit = '0'; } \ else { digit = '1'; v -= 1*scale; } \ else if(v < 3*scale) \ { digit = '2'; v -= 2*scale; } \ else if(v < 4*scale) \ { digit = '3'; v -= 3*scale; } \ else { digit = '4'; v -= 4*scale; } \ else if(v < 7*scale) \ if(v < 6*scale) \ { digit = '5'; v -= 5*scale; } \ else { digit = '6'; v -= 6*scale; } \ else if(v < 8*scale) \ { digit = '7'; v -= 7*scale; } \ else if(v < 9*scale) \ { digit = '8'; v -= 8*scale; } \ else { digit = '9'; v -= 9*scale; } \ } #define sfucvt(v,s,n,w,list) \ { list = (char*)_Sfdec; \ while((ulong)v >= 100000) \ { w = v; v = ((ulong)v)/100000; n = ((ulong)w) - ((ulong)v)*100000; \ SFDIGIT(n,10000,s[-5]); \ SFDIGIT(n,1000,s[-4]); \ SFDIGIT(n,100,s[-3]); \ *--s = (char)('0' + ((n = (uchar)list[n])&017)); \ *--s = (char)('0' + (n >> 4)); \ s -= 3; \ } \ if(v >= 100) \ { if(v >= 1000) \ { if(v >= 10000) \ { w = 3; \ SFDIGIT(v,10000,s[-5]); \ } \ else w = 2; \ SFDIGIT(v,1000,s[-4]); \ } \ else w = 1; \ SFDIGIT(v,100,s[-3]); \ *--s = (char)('0' + ((n = (uchar)list[v])&017)); \ *--s = (char)('0' + (n >> 4)); \ s -= w; \ } \ else \ { *--s = (char)('0' + ((n = (uchar)list[v])&017)); \ if((n >>= 4) > 0) \ *--s = (char)('0' + n); \ } \ } /* fast peek of a stream */ #define SFAVAIL(f,s,n) ((n) = (f)->endb - ((s) = (f)->next) ) #define SFRPEEK(f,s,n) (SFAVAIL((f),(s),(n)) > 0 ? (n) : \ ((SFopen(f), (n) = _sffilbuf(f,-1), SFLOCK(f)), \ (n) <= 0 ? -1 : SFAVAIL(f,s,n))) #define SFWPEEK(f,s,n) (SFAVAIL((f),(s),(n)) > 0 ? (n) : \ ((SFopen(f), (n) = _sfflsbuf(f,-1), SFLOCK(f)), \ (n) < 0 ? -1 : SFAVAIL(f,s,n))) #define SFMODE(f,m) ((f)->mode != SF_STRING ? _sfmode((f),(m)) : \ (((f)->flags&(m)) == (m) ? 0 : -1)) /* malloc and free of streams */ #define SFFREE(f) (f->fore = _Sffree, _Sffree = f) #define SFALLOC(f) ((f = _Sffree) ? (_Sffree = f->fore, f) : \ (f = (Sfile_t*)malloc(sizeof(Sfile_t)))) /* handy functions */ #define min(x,y) ((x) < (y) ? (x) : (y)) #define max(x,y) ((x) > (y) ? (x) : (y)) /* fast functions for memory copy and memory clear */ #ifdef LIBX #include "FEATURE/bcopy" #include "FEATURE/atexit" #include "FEATURE/onexit" #include "FEATURE/on_exit" #else #ifdef BSD #define _lib_bcopy #define _lib_on_exit #else #ifdef V9 #define _lib_onexit #endif /*V9*/ #endif /*BSD*/ #endif /*LIBX*/ #ifdef _lib_bcopy #undef memcpy #define memcpy(to,fr,n) bcopy((fr),(to),(n)) #define memclear(s,n) bzero((s),(n)) #else #define memclear(s,n) memset((s),'\0',(n)) #endif #ifndef _lib_atexit #ifdef _lib_on_exit #define atexit on_exit #else #ifdef _lib_onexit #define atexit onexit #endif /*onexit*/ #endif /*on_exit*/ #endif /*atexit*/ #ifdef atexit #define _lib_atexit #endif /* note that MEMCPY advances the associated pointers */ #define MEMCPY(to,fr,n) \ switch(n) \ { default : memcpy((char*)to,(char*)fr,n); to += n; fr += n; break; \ case 7 : *to++ = *fr++; \ case 6 : *to++ = *fr++; \ case 5 : *to++ = *fr++; \ case 4 : *to++ = *fr++; \ case 3 : *to++ = *fr++; \ case 2 : *to++ = *fr++; \ case 1 : *to++ = *fr++; \ case 0 : break; \ } #define MEMSET(s,c,n) \ switch(n) \ { default : memset((char*)s,(char)c,n); s += n; break; \ case 7 : *s++ = c; \ case 6 : *s++ = c; \ case 5 : *s++ = c; \ case 4 : *s++ = c; \ case 3 : *s++ = c; \ case 2 : *s++ = c; \ case 1 : *s++ = c; \ case 0 : break; \ } #ifdef __cplusplus extern "C" { #endif extern Fa_t *_Fafree; extern Sfile_t *_Sffree; extern Sfpool_t _Sfpool; extern double _Sfpos10[MAXEXP10], _Sfneg10[MAXEXP10]; extern uchar _Sfdec[]; extern int (*_Sfpclose)_SFA_((Sfile_t*)); extern int (*_Sfpmove)_SFA_((Sfile_t*, int)); extern Sfile_t *(*_Sfstack)_SFA_((Sfile_t*, Sfile_t*)); extern void (*_Sfnotify)_SFA_((Sfile_t*, int)); extern int errno; extern int _sfmode _SFA_((Sfile_t*, int)); extern int _sfexcept _SFA_((Sfile_t*, int, int)); extern double frexp _SFA_((double, int*)), ldexp _SFA_((double,int)); extern double strtod _SFA_((char*, char**)); extern char *malloc _SFA_((int)); extern char *realloc _SFA_((char*,int)); extern char *mktemp _SFA_((char*)); extern int unlink _SFA_((char*)); extern void free _SFA_((char*)); extern int strlen _SFA_((const char*)); extern int isatty _SFA_((int)); extern void memset _SFA_((char*,char,int)); #ifdef _lib_bcopy extern void bcopy _SFA_((char*,char*,int)); #ifndef __cplusplus extern void bzero _SFA_((char*,int)); #endif #else extern void memcpy _SFA_((void*,void*,int)); #endif extern int read _SFA_((int,void*,int)); extern int write _SFA_((int,void*,int)); extern long lseek _SFA_((int,long,int)); extern int open _SFA_((char*, int, int)); extern int close _SFA_((int)); extern int dup _SFA_((int)); extern void _exit _SFA_((int)); extern int atexit _SFA_((void(*)())); #if __cplusplus } #endif #endif /* _SFHDR_H */ 0707070000000002541006440044230044230000010000000471531670300003100000000447sfio/sfllen.c Ugsf Ggsf #include "sfhdr.h" /* Get size of a long value coded in a portable format ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfllen(reg long v) #else sfllen(v) reg long v; #endif { if(v < 0) v = -(v+1); v = (ulong)v >> SF_SBITS; return 1 + (v > 0 ? sfulen(v) : 0); } 0707070000000002551006440044230044230000010000000475414055600003100000004660sfio/sfmode.c Ugsf Ggsf #include "sfhdr.h" /* Switch the given stream to a desired mode ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _sfmode(reg Sfile_t* f, reg int wanted) #else _sfmode(f,wanted) reg Sfile_t *f; /* change r/w mode and sync file pointer for this stream */ reg int wanted; /* desired mode */ #endif { reg int n, rv; reg long addr, (*seekf)_SFA_((Sfile_t*,long,int,char*)); reg char *handle; if(SFFROZEN(f)) return -1; SFLOCK(f); rv = 0; if(f->mode&SF_POOL) { /* move to head of pool */ if(f != f->pool->head) { if(SFFROZEN(f->pool->head)) { SFOPEN(f); return -1; } (*_Sfpmove)(f,0); } f->mode &= ~SF_POOL; if((n = f->mode&~SF_LOCK) != 0 && (wanted == 0 || n == wanted)) goto done; } seekf = f->disc ? f->disc->seekf : NIL(long(*)_SFA_((Sfile_t*,long,int,char*))); handle = f->disc ? f->disc->handle : NIL(char*); switch(f->mode&~SF_LOCK) { case 0: /* initializing an unitialized std-stream */ SFopen(f); (void) sfnew(f,NIL(uchar*),-1,f->file,f->flags); goto done; case SF_WRITE: /* switching to SF_READ */ if(!(f->flags&SF_READ)) rv = -1; else { /* reset buffer */ SFopen(f); if((rv = _sfflsbuf(f,-1)) < 0) goto done; SFLOCK(f); if(f->flags&SF_APPEND) f->here = SEEKF(seekf,f,0L,1,handle); if(f->size == 0) { /* unbuffered */ f->data = f->tiny; f->size = sizeof(f->tiny); } f->next = f->endr = f->endw = f->endb = f->data; f->mode = SF_READ; if(f->size > 1 && f->orig >= 0) (void) sfseek(f,f->here-f->orig,0); } goto done; case SF_SYNC: /* a previously sync-ed read stream */ if(wanted == SF_WRITE) { /* can't do it */ if(!(f->flags&SF_WRITE)) rv = -1; else goto do_write; } else { /* just reset the pointers */ f->mode = SF_READ|SF_LOCK; addr = f->here + (f->endb - f->next); if((addr = SEEKF(seekf,f,addr,0,handle)) < 0) rv = -1; else f->here = addr; } goto done; case SF_READ: /* switching to SF_WRITE */ if(!(f->flags&SF_WRITE)) { rv = -1; goto done; } if((n = f->endb-f->data) > 0) { /* reset file pointer */ addr = f->here - n; if((addr = SEEKF(seekf,f,addr,0,handle)) < 0) { rv = -1; goto done; } else f->here = addr; } do_write: if(f->data == f->tiny) { f->endb = f->data = f->next = NIL(uchar*); f->size = 0; } else f->endb = f->data + f->size; f->mode = SF_WRITE; goto done; } done : SFopen(f); sfset(f,f->flags,1); return rv; } 0707070000000002561006440044230044230000010000000475416165400003100000010230sfio/sfmove.c Ugsf Ggsf #include "sfhdr.h" #if sparc #include <sys/mman.h> #define MAPSIZE (256*1024) #endif /* Move data from one stream to another. ** This code is written so that it'll work even in the presence ** of stacking streams, pool, and discipline. ** If you must change it, be gentle. ** ** Written by Kiem-Phong Vo (12/07/90) */ #if __STDC__ || __cplusplus sfmove(Sfile_t* fr, Sfile_t* fw, reg long n, const char* rs) #else sfmove(fr,fw,n,rs) Sfile_t *fr; /* moving data from this stream */ Sfile_t *fw; /* moving data to this stream */ reg long n; /* number of bytes/records to move. <0 for unbounded move */ reg char *rs; /* record separators */ #endif { reg uchar *cp, *next; reg int r, w, rc; reg int direct; reg long n_move; uchar rbuf[SF_GRAIN]; char rsv[(uchar)(~0)]; #if sparc caddr_t mbuf = (caddr_t)(-1); off_t msize = 0; #endif if(!fr) return 0; if(rs) { /* set up the mapping to determine which byte is a separator */ if(*rs) { memclear(rsv,sizeof(rsv)); if(rs[0] == '\\' && rs[1] == '0') { /* coding of the zero byte */ rsv[rc = 0] = 1; rs += 2; } else rc = (uchar)(*rs); /* coding of the rest of the bytes */ while(r = (uchar)(*rs++)) rsv[r] = 1; rs = rsv; } else rs = NIL(char*); } for(n_move = 0; n != 0; ) { /* get the input stream into the right mode */ if(fr->mode != SF_READ && SFMODE(fr,SF_READ) < 0) break; /* try reading a block of data */ direct = 0; if((r = fr->endb - (next = fr->next)) <= 0) { /* sffilbuf handles stack and discipline */ if(fr->disc || fr->push) { (void)_sffilbuf(fr,-1); if((r = fr->endb - (next = fr->next)) <= 0) break; } /* no more data */ else if(fr->flags&SF_STRING) break; /* try direct read */ else { #if sparc /* try memory mapping for fast read */ struct stat st; if(mbuf != (caddr_t)(-1)) { /* release previous mapped space */ munmap(mbuf,msize); mbuf = (caddr_t)(-1); } if(fr->orig >= 0 && (n < 0 || n >= SF_BUFSIZE) && fstat(fr->file,&st) >= 0 && (st.st_mode&S_IFMT) == S_IFREG) { if((msize = st.st_size - fr->here) > MAPSIZE) msize = MAPSIZE; if(msize > n && n > 0) msize = n; mbuf = mmap(NIL(caddr_t),msize,PROT_READ, MAP_SHARED,fr->file,fr->here); if(mbuf != (caddr_t)(-1)) { /* advance read pointer */ (void)lseek(fr->file,msize,1); next = (uchar*)mbuf; r = msize; goto r_done; } } #endif /* get a decent size buffer to work with */ if((w = fr->size) >= sizeof(rbuf)) next = fr->data; else { next = rbuf; w = sizeof(rbuf); } if(!rs && n > 0 && n < w) w = (int)n; while((r = read(fr->file,next,w)) < 0 && errno == EINTR) errno = 0; if(r <= 0) break; /* for future sfseek's correctness */ r_done: fr->next = fr->endb = fr->endr = fr->data; direct = 1; } } if(!rs) { if(n > 0) { if(n < r) r = (int)n; n -= r; } n_move += r; } else { /* count lines */ reg uchar *endb = next+r; reg int string = (fr->flags&SF_STRING); if(!direct) SFlock(fr); if(!string) { w = endb[-1]; endb[-1] = rc; } else w = 0; for(cp = next; cp < endb; ) { /* find the line extent */ if(string) while(cp < endb && !rs[*cp++]) ; else while(!rs[*cp++]) ; if(cp < endb || w == rc) { n_move += 1; if(n > 0 && (n -= 1) == 0) break; } } if(!string) endb[-1] = w; r = cp-next; if(!direct) SFopen(fr); else if(cp < endb) (void) lseek(fr->file,(long)(cp-endb),1); } /* advance read pointer */ if(direct) fr->here += r; else fr->next += r; /* write out data */ if(fw) { if(fw->mode != SF_WRITE && SFMODE(fw,SF_WRITE) < 0) goto w_error; if((fw->endb - (cp = fw->next)) > r) { SFlock(fw); MEMCPY(cp,next,r); fw->next = cp; SFopen(fw); } else if((w = sfwrite(fw,next,r)) != r) { /* write error */ if(w > 0) { r -= w; if(!rs) n_move -= r; } w_error : (void) sfseek(fr,(long)(-r),1); break; } } } #if sparc if(mbuf != (caddr_t)(-1)) munmap(mbuf,msize); #endif return n_move; } 0707070000000002571006440044230044230000010000000475416406200003000000006536sfio/sfnew.c Ugsf Ggsf #include "sfhdr.h" /* Fundamental function to create a new stream. ** The argument flags defines the type of stream and the scheme ** of buffering. ** ** Written by Kiem-Phong Vo (06/27/90) */ /* to be done on exit */ static int _Cleanup = 0; static void _cleanup() { /* sync all streams */ if(_Cleanup >= 0) { _Cleanup = -1; sfsync(NIL(Sfile_t*)); } } #if __STDC__ || __cplusplus Sfile_t *sfnew(Sfile_t* oldf, uchar* buf, int size, int file, int flags) #else Sfile_t *sfnew(oldf,buf,size,file,flags) Sfile_t *oldf; /* old stream to be reused */ uchar *buf; /* a buffer to read/write, if NULL, will be allocated */ int size; /* buffer size if buf is given or desired buffer size */ int file; /* file descriptor to read/write from */ int flags; /* type of file stream */ #endif { reg Sfile_t *f; reg long (*seekf)_SFA_((Sfile_t*,long,int,char*)); reg char *handle; if(!_Cleanup) { _Cleanup = 1; (void)atexit(_cleanup); } if((oldf && SFFROZEN(oldf)) || (!oldf && !(flags&SF_RDWR))) return NIL(Sfile_t*); /* make a stream structure */ if(oldf) { f = oldf; if(flags&SF_REUSE) flags = f->flags; if((f->mode&SF_STRING) && f->data && (f->flags&SF_MALLOC)) { free((char*)f->data); f->data = f->endb = f->next = NIL(uchar*); f->size = 0; } } else { if(file >= 0 && file <= 2 && !(flags&SF_STRING)) { /* reuse a sfstd-stream if possible */ f = file == 0 ? sfstdin : file == 1 ? sfstdout : sfstderr; if(f->file >= 0 || (f == sfstdin && (flags&SF_RDWR) != SF_READ) || (f != sfstdin && (flags&SF_RDWR) != SF_WRITE)) f = NIL(Sfile_t*); } else f = NIL(Sfile_t*); if(!f && !SFALLOC(f)) return NIL(Sfile_t*); SFCLEAR(f); } /* stream type */ f->mode = (flags&SF_STRING) ? SF_STRING : ((flags&SF_WRITE) && oldf && (oldf->mode&SF_WRITE)) ? SF_WRITE : (flags&SF_READ) ? SF_READ : SF_WRITE; f->flags = (flags&SF_FLAGS)&~SF_REUSE; if((f->flags&SF_RDWR) == SF_RDWR) f->flags |= SF_BOTH; if(f->mode&SF_STRING) { /* note that f->here is set in sfsetbuf() */ f->file = -1; f->orig = 0L; } else { SFLOCK(f); f->file = file; f->orig = 0L; if((f == sfstdin || f == sfstdout || f == sfstderr) && !f->data && isatty(file)) { /* this stream is not seekable */ f->orig = -1L; if(f != sfstdin) f->flags |= SF_LINE; } if(f->orig == 0L) { /* set seek location */ seekf = (oldf && oldf->disc) ? oldf->disc->seekf : NIL(long(*)_SFA_((Sfile_t*,long,int,char*))); handle = (oldf && oldf->disc) ? oldf->disc->handle : NIL(char*); f->orig = SEEKF(seekf,f,0L,(flags&SF_APPEND) ? 2 : 1,handle); if(f->orig > 0 && !(flags&SF_RELATIVE)) f->orig = 0L; } f->here = f->orig > 0L ? f->orig : 0L; if(!f->data && !buf && size < 0) { /* special cases for stream buffer size */ if(f == sfstderr) size = 0; else if(f->orig < 0L && (f->mode&SF_WRITE) && (f->flags&SF_LINE)) size = SF_GRAIN; else size = SF_BUFSIZE; } } /* set buffer pointers */ SFOPEN(f); sfset(f,f->flags,1); if(!(flags&SF_STRING) && oldf && size < 0) { buf = f->data; size = f->size; f->data = f->next = f->endr = f->endw = f->endb = NIL(uchar*); f->size = 0; } sfsetbuf(f,buf,size); if(!oldf) { /* link to the list of active streams */ f->pool = &_Sfpool; f->fore = _Sfpool.head; if(_Sfpool.head) _Sfpool.head->back = f; _Sfpool.head = f; } if(_Sfnotify) (*_Sfnotify)(f,0); return f; } 0707070000000002601006440044230044230000010000000475416404000003300000000422sfio/sfnotify.c Ugsf Ggsf #include "sfhdr.h" /* Set the function to be called when a stream is opened or closed ** ** Written by Kiem-Phong Vo (01/06/91) */ #if __STDC__ || __cplusplus sfnotify(void (*notify)(Sfile_t*, int)) #else sfnotify(notify) void (*notify)(); #endif { _Sfnotify = notify; } 0707070000000002611006440044230044230000010000000472663404400003200000001657sfio/sfnputc.c Ugsf Ggsf #include "sfhdr.h" /* Write out a character n times ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfnputc(reg Sfile_t* f, reg uchar c, reg int n) #else sfnputc(f,c,n) reg Sfile_t *f; /* file to write */ reg uchar c; /* char to be written */ reg int n; /* number of time to repeat */ #endif { reg uchar *ps; reg int p, w; uchar buf[128]; if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; SFLOCK(f); /* write into a suitable buffer */ if((p = (f->endb-(ps = f->next))) < n) { ps = buf; p = sizeof(buf); } if(p > n) p = n; MEMSET(ps,c,p); ps -= p; w = n; if(ps == f->next) { /* simple sfwrite */ f->next += p; if(c == '\n') { SFopen(f); _sfflsbuf(f,-1); } goto done; } for(;;) { /* hard write of data */ SFopen(f); if((p = sfwrite(f,ps,p)) <= 0 || (n -= p) <= 0) { w -= n; goto done; } SFLOCK(f); if(p > n) p = n; } done : SFOPEN(f); return w; } 0707070000000002621006440044230044230000010000000474736437700003100000004455sfio/sfopen.c Ugsf Ggsf #include "sfhdr.h" /* Open a file/string for IO. ** If f is not nil, it is taken as an existing stream that should be ** closed and its structure reused for the new stream. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus Sfile_t *sfopen(reg Sfile_t* f, const char* file, const char* mode) #else Sfile_t *sfopen(f,file,mode) reg Sfile_t *f; /* old stream structure */ char *file; /* file/string to be opened */ reg char *mode; /* mode of the stream */ #endif { reg int fd, oflags, sflags, oldfd; if((f && SFFROZEN(f)) || !file || !mode) return NIL(Sfile_t*); oldfd = -1; if(f) { /* reuse the space of this stream */ f->flags |= SF_REUSE; f->flags &= ~SF_KEEPFD; /* force closing of f->file */ oldfd = f->file; (void) sfclose(f); } /* construct the open flags */ sflags = 0; while(1) switch(*mode++) { case 'w' : oflags = O_WRONLY | O_TRUNC | O_CREAT; sflags = SF_WRITE; break; case 'a' : oflags = O_WRONLY | O_APPEND | O_CREAT; sflags = SF_WRITE | SF_APPEND; break; case 'r' : oflags = O_RDONLY; sflags = SF_READ; break; case '+' : oflags = (oflags & ~(O_RDONLY|O_WRONLY))|O_RDWR; sflags |= SF_READ|SF_WRITE; break; case 's' : sflags = SF_STRING|SF_READ; break; case 'b' : break; case 0 : goto e_mode; default : return NIL(Sfile_t*); } e_mode :; if(sflags&SF_STRING) return sfnew(f,(uchar*)file,strlen(file),-1,sflags); else if(!sflags || !file[0]) return NIL(Sfile_t*); /* open the file */ #ifndef NO_OFLAGS fd = open((char*)file,oflags,0666); #else if((fd = open(file,oflags&03)) < 0 && (oflags&O_CREAT) && (fd = creat(file,0666)) >= 0 && !(oflags&O_WRONLY)) { /* the file now exists, reopen it for read/write */ (void) close(fd); fd = open(file,oflags&03); } else if(fd >= 0) { /* truncate file */ if(oflags&O_TRUNC) { reg int tf = creat(file,0666); (void)close(tf); } /* make sure file pointer is at the top */ if((oflags&O_RDWR) && !(oflags&O_APPEND)) (void)lseek(fd,0L,0); } #endif if(fd < 0) return NIL(Sfile_t*); if(oldfd >= 0 && fd != oldfd && (oldfd = dup(fd)) >= 0) { /* freopen desires fd == oldfd */ (void) close(fd); fd = oldfd; } if(!(f = sfnew(f,NIL(uchar*),-1,fd,sflags)) ) (void) close(fd); else if(mode[0] != 'r' && f->mode != SF_WRITE) _sfmode(f,SF_WRITE); return f; } 0707070000000002631006440044230044230000010000000474736457400003100000004673sfio/sfpeek.c Ugsf Ggsf #include "sfhdr.h" /* Return the portion of the internal stream buffer available ** for reading/writing. If a stream is SF_READ and the buffer is ** empty, it will be filled. If a stream is SF_WRITE and the buffer ** full, it will be flushed. ** A peek on a SF_READ stream that is line buffered will return the ** portion of data up to \n. ** Note also that this function does not advance the buffer pointer. ** That must be done by an appropriate sfread or sfwrite call. ** ** Written by Kiem-Phong Vo (06/27/90). */ #if __STDC__ || __cplusplus _sfpeek(reg Sfile_t* f, uchar** bp) #else _sfpeek(f,bp) reg Sfile_t *f; /* file to peek */ uchar **bp; /* start of data area */ #endif { reg int n; reg uchar *s, *ends; reg int c, o, a; /* for consistency the desired mode for a RDWR stream is always READ */ n = (f->flags&SF_RDWR) == SF_RDWR ? SF_READ : (f->mode&SF_RDWR); if(f->mode != n && SFMODE(f,n) < 0) return -1; SFLOCK(f); if((f->flags&(SF_RDWR|SF_STRING)) == (SF_RDWR|SF_STRING)) { /* a read/write string stream, update current end */ if((o = f->next-f->data) > f->here && o != f->orig) f->here = f->orig = o; n = (f->data+f->here)-f->next; if(!bp) goto done; } else if((n = f->endb - f->next) == 0) { SFopen(f); if(f->flags&SF_READ) _sffilbuf(f,-1); else _sfflsbuf(f,-1); SFLOCK(f); n = f->endb - f->next; } if(n <= 0 || (f->mode&SF_WRITE) || !(f->flags&SF_READ) || !(f->flags&SF_LINE)) { /* normal business */ *bp = f->next; goto done; } /* in line-buffering read mode, find \n */ n = (ends = f->endb) - (s = f->next); if((f->flags&SF_STRING) && !(f->flags&SF_WRITE)) { /* must do this slowly */ while(s < ends && *s++ != '\n') ; c = s[-1]; } else { /* fast loop */ c = ends[-1]; ends[-1] = '\n'; while(*s++ != '\n') ; ends[-1] = c; } /* we are done */ if(s < ends || c == '\n' || (f->flags&SF_STRING)) { n = s - (*bp = f->next); goto done; } /* must read more, try to align data by moving it back */ if((f->mode&SF_READ) && (o = f->next - f->data) > 0) { /* shift left data, make sure alignment is correct */ a = f->size >= (2*SF_GRAIN) ? SF_GRAIN : ((f->size/2)/sizeof(void*)+1)*sizeof(void*); if((c = (n/a + 1)*a - n) > o) { n = ends - (*bp = f->next); goto done; } else if(c < o) { /* copy data */ ends = f->next; f->next = s = f->data+c; f->endb = s+n; MEMCPY(s,ends,n); } } SFopen(f); n = _sffilbuf(f,0); *bp = f->next; done: SFOPEN(f); return n; } 0707070000000002641006440044230044230000010000000475414060400003100000007016sfio/sfpool.c Ugsf Ggsf #include "sfhdr.h" /* Management of pools of streams. ** If pf is not nil, f is pooled with pf and f becomes current; ** otherwise, f is isolated from its pool. flag can be any of: ** 0, SF_READ, SF_WRITE or SF_READ|SFWRITE to indicate the type ** of stream that gets synced when a stream becomes non-current. ** If flag is 0, the pool type is unchanged. ** ** Written by Kiem-Phong Vo (6/27/90). */ static Sfpool_t *Pfree; /* list of free pools */ #if __STDC__ || __cplusplus static void delpool(reg Sfpool_t* p) #else static delpool(p) reg Sfpool_t *p; #endif { if(p == &_Sfpool) return; if(p->fore) p->fore->back = p->back; if(p->back) p->back->fore = p->fore; p->fore = Pfree; Pfree = p; } #if __STDC__ || __cplusplus static Sfpool_t *newpool(reg int mode) #else static Sfpool_t *newpool(mode) reg int mode; #endif { reg Sfpool_t *p; if(Pfree) { /* from the free list */ p = Pfree; Pfree = p->fore; } else p = (Sfpool_t*) malloc(sizeof(Sfpool_t)); p->mode = mode; p->head = NIL(Sfile_t*); /* insert into chain of pools */ if((p->fore = _Sfpool.fore) != NIL(Sfpool_t*)) p->fore->back = p; p->back = &_Sfpool; _Sfpool.fore = p; return p; } #if __STDC__ || __cplusplus static sfpmove(reg Sfile_t* f, reg int type) #else static sfpmove(f,type) reg Sfile_t *f; reg int type; /* <0 : deleting, 0: move-to-front, >0: inserting */ #endif { reg Sfpool_t *p; reg Sfile_t *head; SFLOCK(f); p = f->pool; if(type < 0) { /* deleting from pool */ if(f->fore) f->fore->back = f->back; if(f->back) f->back->fore = f->fore; else p->head = f->fore; f->pool = NIL(Sfpool_t*); if(p != &_Sfpool) { if(!(head = p->head)) delpool(p); else if(!head->fore) { /* remove the last one */ sfpmove(head,-1); head->pool = &_Sfpool; sfpmove(head,1); } } } else if(type > 0) { /* insertion */ if((head = p->head) != NIL(Sfile_t*)) { /* right after current head */ if((f->fore = head->fore) != NIL(Sfile_t*)) f->fore->back = f; f->back = head; head->fore = f; f->mode |= SF_POOL; SFopen(f); sfset(f,f->flags,1); } else { f->fore = f->back = NIL(Sfile_t*); p->head = f; } } else if(p != &_Sfpool && (head = p->head) && head != f && !SFFROZEN(head)) { /* syn head stream before moving it */ if(head->mode&p->mode) sfsync(head); head->mode |= SF_POOL; sfset(head,head->flags,1); if(f->fore) f->fore->back = f->back; f->back->fore = f->fore; f->back = NIL(Sfile_t*); f->fore = head; head->back = f; p->head = f; f->mode &= ~SF_POOL; } SFOPEN(f); return 0; } #if __STDC__ || __cplusplus sfpool(reg Sfile_t* f, reg Sfile_t* pf, reg int mode) #else sfpool(f,pf,mode) reg Sfile_t *f; reg Sfile_t *pf; reg int mode; #endif { reg Sfpool_t *p; /* function to move a stream in a pool */ _Sfpmove = sfpmove; if(!f || f == pf || /* nothing to do */ (!pf && f->pool == &_Sfpool) || /* already isolated */ /* new pool but type is unknown */ (pf && pf->pool == &_Sfpool && (mode&SF_RDWR) == 0)) return -1; if(SFFROZEN(f) || (!f->mode && _sfmode(f,0) < 0)) return -1; if(pf && (SFFROZEN(pf) || (!pf->mode && _sfmode(pf,0) < 0))) return -1; /* isolate it from current pool */ p = f->pool; sfpmove(f,-1); if(!pf) { /* add to the discrete pool */ f->pool = &_Sfpool; sfpmove(f,1); return 0; } if((p = pf->pool) == &_Sfpool) { /* making a new pool */ sfpmove(pf,-1); p = newpool(mode&SF_RDWR); pf->pool = p; sfpmove(pf,1); } if(f->pool != p) { /* insert f into the pool */ f->pool = p; sfpmove(f,1); } return 0; } 0707070000000002651006440044230044230000010000000474661552600003200000007510sfio/sfpopen.c Ugsf Ggsf #include "sfhdr.h" /* fork function to use */ #ifdef LIBX #include "FEATURE/vfork" #else #ifdef BSD #define _lib_vfork #endif #ifdef sparc #define _hdr_vfork #endif #endif /*LIBX*/ #ifdef _lib_vfork #define fork vfork #ifdef _hdr_vfork #include <vfork.h> #endif #endif #if __cplusplus extern "C" { #endif extern int fork(); extern int wait _SFA_((int*)); extern int pipe _SFA_((int*)); extern int execl _SFA_((char*,char*,...)); #if __cplusplus } #endif /* pipe ends */ #define READ 0 #define WRITE 1 /* to keep track of opened processes */ typedef struct _sfp_ { int pid; /* process id */ Sfile_t *one; /* streams associated with */ Sfile_t *two; struct _sfp_ *fore; /* link list */ } Popen_t; static Popen_t *Process; #if __STDC__ || __cplusplus static _sfpclose(reg Sfile_t* f) #else static _sfpclose(f) reg Sfile_t *f; /* stream to close */ #endif { reg Popen_t *last, *p; int pid, status; /* find the associated process structure */ for(last = NIL(Popen_t*), p = Process; p; last = p, p = p->fore) if(f == p->one || f == p->two) break; if(!p || (p->one && SFFROZEN(p->one)) || (p->two && SFFROZEN(p->two))) return -1; /* close the associated streams */ if(p->one) { p->one->flags &= ~SF_PROCESS; sfclose(p->one); } if(p->two) { p->two->flags &= ~SF_PROCESS; sfclose(p->two); } /* wait for process termination */ while((pid = wait(&status)) != p->pid && pid != -1) ; /* delete from process table */ if(last) last->fore = p->fore; else Process = p->fore; free((char*)p); return (pid == -1 ? -1 : status); } #if __STDC__ || __cplusplus Sfile_t *sfpopen(const char* command, const char* mode, Sfile_t** compf) #else Sfile_t *sfpopen(command,mode,compf) char *command; /* command to execute */ char *mode; /* mode of the stream */ Sfile_t **compf; /* to return the companion stream if mode is "x+" */ #endif { reg int pid, keep, ckeep, flg, cflg; reg Sfile_t *f, *cf; reg Popen_t *p; int parent[2], child[2]; /* sanity check */ if(!command || !command[0] || !mode || (mode[0] != 'r' && mode[0] != 'w')) return NIL(Sfile_t*); /* set the close function */ _Sfpclose = _sfpclose; /* make a process structure */ if(!(p = (Popen_t*) malloc(sizeof(Popen_t))) ) return NIL(Sfile_t*); /* make pipes */ parent[0] = parent[1] = child[0] = child[1] = -1; if(pipe(parent) < 0) goto error; if(mode[1] == '+' && pipe(child) < 0) goto error; f = cf = NIL(Sfile_t*); switch(pid = fork()) { default : /* in parent process */ /* determine which pipe ends to keep */ if(mode[0] == 'r') { keep = READ; ckeep = WRITE; flg = SF_READ; cflg = SF_WRITE; } else { keep = WRITE; ckeep = READ; flg = SF_WRITE; cflg = SF_READ; } /* make the streams */ if(!(f = sfnew(NIL(Sfile_t*),NIL(uchar*),-1,parent[keep],flg))) goto error; close(parent[!keep]); if(mode[1] == '+') { /* make the companion stream */ if(!(cf = sfnew(NIL(Sfile_t*),NIL(uchar*),-1,child[ckeep],cflg))) goto error; close(child[!ckeep]); *compf = cf; cf->flags |= SF_PROCESS; } /* save process info */ f->flags |= SF_PROCESS; p->one = f; p->two = cf; p->pid = pid; p->fore = Process; Process = p; return f; case 0 : /* in child process */ /* determine what to keep */ if(mode[0] == 'r') { keep = WRITE; ckeep = READ; } else { keep = READ; ckeep = WRITE; } /* make std-streams */ close(keep); if(dup(parent[keep]) != keep) _exit(127); close(parent[!keep]); if(mode[1] == '+') { close(ckeep); if(dup(child[ckeep]) != ckeep) _exit(127); close(child[!ckeep]); } /* now exec the command */ execl("/bin/sh", "sh", "-c", command, NIL(char*)); _exit(127); return NIL(Sfile_t*); case -1 : /* error */ error: close(parent[0]); close(parent[1]); close(child[0]); close(child[1]); free((char*)p); if(f) sfclose(f); if(cf) sfclose(cf); return NIL(Sfile_t*); } } 0707070000000002661006440044230044230000010000000475414061500003300000002114sfio/sfprintf.c Ugsf Ggsf #include "sfhdr.h" /* Print data with a given format ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfprintf(Sfile_t *f, const char *form, ...) #else sfprintf(f,form,va_alist) reg Sfile_t *f; /* file stream to print to */ reg char *form; /* print format */ va_dcl #endif { va_list args; reg int rv; #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvprintf(f,form,args); va_end(args); return rv; } #if __STDC__ || __cplusplus sfsprintf(char *s, int n, const char *form, ...) #else sfsprintf(s,n,form,va_alist) reg char *s; reg int n; reg char *form; va_dcl #endif { va_list args; Sfile_t f; reg int rv; if(!s || n <= 0) return -1; /* make a fake stream */ SFCLEAR(&f); f.flags = SF_STRING|SF_WRITE; f.mode = SF_STRING; f.size = n-1; f.data = f.next = f.endr = (uchar*)s; f.endb = f.endw = f.data+f.size; sfset(&f,f.flags,1); #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvprintf(&f,form,args); *f.next = '\0'; _Sfi = f.next - f.data; va_end(args); return rv; } 0707070000000002671006440044230044230000010000000473120005600003100000002144sfio/sfputd.c Ugsf Ggsf #include "sfhdr.h" /* Write out a double value in a portable format ** ** Written by Kiem-Phong Vo (08/05/90) */ #if __STDC__ || __cplusplus _sfputd(Sfile_t* f, reg double v) #else _sfputd(f,v) Sfile_t *f; reg double v; #endif { #define N_ARRAY (16*sizeof(double)) reg int n, w; reg double x; reg uchar *s, *ends; int exp; uchar c[N_ARRAY]; if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; /* get the sign of v */ if(v < 0) { v = -v; n = 01; } else n = 0; /* make the magnitude of v < 1 */ if(v != 0.) v = frexp(v,&exp); else exp = 0; /* code the sign of v and exp */ if((w = exp) < 0) { n |= 02; w = -w; } /* write out the signs and the exp */ if(sfputc(f,n) < 0 || (w = sfputu(f,w)) < 0) return -1; w += 1; s = (ends = &c[0])+sizeof(c); while(s > ends) { /* get 2^SF_PRECIS precision at a time */ n = (int)(x = ldexp(v,SF_PRECIS)); *--s = n|SF_MORE; if((v = x-n) <= 0.) break; } /* last byte is not SF_MORE */ ends = &c[0] + sizeof(c) -1; *ends &= ~SF_MORE; /* write out coded bytes */ n = ends - s + 1; return sfwrite(f,s,n) == n ? w+n : -1; } 0707070000000002701006440044230044230000010000000473117771500003100000002121sfio/sfputl.c Ugsf Ggsf #include "sfhdr.h" /* Write out a long value in a portable format ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _sfputl(reg Sfile_t* f, reg long v) #else _sfputl(f,v) reg Sfile_t *f; /* write a portable long to this stream */ reg long v; /* the value to be written */ #endif { #define N_ARRAY (2*sizeof(long)) reg uchar *s, *ps; reg int n, p; uchar c[N_ARRAY]; if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; s = ps = &(c[N_ARRAY-1]); if(v < 0) { /* add 1 to avoid 2-complement problems with -MAXINT */ v = -(v+1); *s = (uchar)(SFSVALUE(v) | SF_SIGN); } else *s = (uchar)(SFSVALUE(v)); v = (ulong)v >> SF_SBITS; while(v > 0) { *--s = (uchar)(SFUVALUE(v) | SF_MORE); v = (ulong)v >> SF_UBITS; } n = (ps-s)+1; /* write the hard way */ if(n > 7 || SFWPEEK(f,ps,p) < n) return sfwrite(f,s,n); SFLOCK(f); switch(n) { case 7 : *ps++ = *s++; case 6 : *ps++ = *s++; case 5 : *ps++ = *s++; case 4 : *ps++ = *s++; case 3 : *ps++ = *s++; case 2 : *ps++ = *s++; case 1 : *ps++ = *s++; } f->next = ps; SFOPEN(f); return n; } 0707070000000002711006440044230044230000010000000475116744600003100000002642sfio/sfputs.c Ugsf Ggsf #include "sfhdr.h" /* Put out a nul-terminated string ** ** Written by Kiem-Phong Vo */ #if __STDC__ || __cplusplus sfputs(reg Sfile_t* f, const char* s, int t) #else sfputs(f,s,t) reg Sfile_t *f; char *s; int t; #endif { reg int p; reg uchar *os, *ps; reg int n; if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; SFLOCK(f); if(f->size <= 0 || (uchar*)s == f->next) { /* unbuffered stream or writing after sfpeek() */ n = strlen((char*)s); SFopen(f); if((p = sfwrite(f,(uchar*)s,n)) == n && t != 0 && sfputc(f,t) >= 0) p += 1; goto done; } os = (uchar*)s; while(1) { /* peek buffer for space */ if(SFWPEEK(f,ps,p) <= 0) break; /* fast copy loop */ while((*ps++ = *os++) != '\0' && --p > 0) ; if(ps[-1] == '\0') { /* done */ p = -1; if(t != 0) /* add the last char if any */ ps[-1] = t; else { ps -= 1; os -= 1; } } /* move the write pointer */ f->next = ps; if(p < 0) break; } p = (char*)os - s; if((f->flags&SF_LINE) && !(f->flags&SF_STRING)) { /* see if we need to flush the buffer */ if(t == '\n') t = HIFORLINE; else if((t = (ps = f->next) - (os = f->data)) < HIFORLINE && t > 0) { /* long check for embedded \n */ n = os[0]; os[0] = '\n'; while(*--ps != '\n') ; if(ps > os || n == '\n') t = HIFORLINE; os[0] = n; } if(t >= HIFORLINE) { SFopen(f); (void) _sfflsbuf(f,-1); } } done : SFOPEN(f); return p; } 0707070000000002721006440044230044230000010000000473117761300003100000001705sfio/sfputu.c Ugsf Ggsf #include "sfhdr.h" /* Write out an unsigned long value in a portable format. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _sfputu(reg Sfile_t* f, reg ulong v) #else _sfputu(f,v) reg Sfile_t *f; /* write a portable ulong to this stream */ reg ulong v; /* the unsigned value to be written */ #endif { #define N_ARRAY (2*sizeof(long)) reg uchar *s, *ps; reg int n, p; uchar c[N_ARRAY]; if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; /* code v as integers in base SF_UBASE */ s = ps = &(c[N_ARRAY-1]); *s = (uchar)SFUVALUE(v); while((v >>= SF_UBITS) > 0) *--s = (uchar)(SFUVALUE(v) | SF_MORE); n = (ps-s)+1; if(n > 7 || SFWPEEK(f,ps,p) < n) return sfwrite(f,s,n); SFLOCK(f); switch(n) { case 7 : *ps++ = *s++; case 6 : *ps++ = *s++; case 5 : *ps++ = *s++; case 4 : *ps++ = *s++; case 3 : *ps++ = *s++; case 2 : *ps++ = *s++; case 1 : *ps++ = *s++; } f->next = ps; SFOPEN(f); return n; } 0707070000000002731006440044230044230000010000000474537763700003100000004201sfio/sfread.c Ugsf Ggsf #include "sfhdr.h" /* Read n bytes from a tream into a buffer ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfread(reg Sfile_t* f, reg uchar* s, reg int n) #else sfread(f,s,n) reg Sfile_t *f; /* read from this stream */ reg uchar *s; /* buffer to read into */ reg int n; /* number of bytes to be read */ #endif { reg uchar *data; reg int r; reg int (*readf) _SFA_((Sfile_t*, uchar*, int, char*)); reg long (*seekf) _SFA_((Sfile_t*, long, int, char*)); reg char *handle; reg uchar *begs = s; /* true start of buffer */ redo_loop: if(f->mode != SF_READ && SFMODE(f,SF_READ) < 0) return -1; SFLOCK(f); if(s == f->next) { /* fast read after sfpeek() */ if((r = f->endb - f->next) > n) r = n <= 0 ? 0 : n; if(r > 0) f->next = (s += r); goto done; } readf = f->disc ? f->disc->readf : NIL(int(*)_SFA_((Sfile_t*, uchar*, int, char*))); seekf = f->disc ? f->disc->seekf : NIL(long(*)_SFA_((Sfile_t*, long, int, char*))); handle = f->disc ? f->disc->handle : NIL(char*); if((r = f->endb - (data = f->next)) > n) r = n <= 0 ? 0 : n; for(;;) { /* copy data - note that s is advanced too */ MEMCPY(s,data,r); f->next += r; if((n -= r) <= 0) goto done; if(f->flags&SF_STRING) { r = 0; goto at_eof; } /* read directly into requested buffer */ f->next = f->endb = f->endr = f->data; while(n >= (r = f->size)) { /* unbuffered read */ if(r <= 1) r = n; else { /* read by a round-up unit */ if(r > SF_GRAIN) r = SF_GRAIN; r = (n/r)*r; } if(f->flags&SF_SHARE) f->here = SEEKF(seekf,f,f->here,0,handle); if((r = READF(readf,f,s,r,handle)) > 0) { f->here += r; s += r; if((n -= r) <= 0) goto done; } else { /* eof or error */ at_eof: switch(_sfexcept(f,SF_READ,r)) { case SF_EDISC : case SF_ESTACK : SFopen(f); goto redo_loop; case SF_EDONE : goto done; default : continue; } } } /* fill our buffer and continue */ SFopen(f); if((r = _sffilbuf(f,-1)) <= 0) goto done; SFLOCK(f); if(r > n) r = n; data = f->next; } done : SFOPEN(f); return s-begs; } 0707070000000002741006440044230044230000010000000475414062400003200000002014sfio/sfscanf.c Ugsf Ggsf #include "sfhdr.h" /* Read formated data from a stream ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfscanf(Sfile_t *f, const char *form, ...) #else sfscanf(f,form,va_alist) reg Sfile_t *f; /* file to be scanned */ reg char *form; /* scanning format */ va_dcl #endif { va_list args; reg int rv; #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvscanf(f,form,args); va_end(args); return rv; } #if __STDC__ || __cplusplus sfsscanf(const char *s, const char *form,...) #else sfsscanf(s,form,va_alist) reg char *s; reg char *form; va_dcl #endif { va_list args; Sfile_t f; reg int rv; if(!s) return -1; /* make a fake stream */ SFCLEAR(&f); f.flags = SF_STRING|SF_READ; f.mode = SF_STRING; f.size = strlen((char*)s); f.data = f.next = f.endw = (uchar*)s; f.endb = f.endr = f.data+f.size; sfset(&f,f.flags,1); #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvscanf(&f,form,args); va_end(args); return rv; } 0707070000000002751006440044230044230000010000000471606707700003100000007342sfio/sfseek.c Ugsf Ggsf #include "sfhdr.h" /* Set the IO pointer to a specific location in the stream ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus long sfseek(reg Sfile_t* f, reg long p, reg int type) #else long sfseek(f,p,type) reg Sfile_t *f; /* seek to a new location in this stream */ reg long p; /* place to seek to */ int type; /* 0: from org, 1: from here, 2: from end */ #endif { reg long r, s; reg long (*seekf)_SFA_((Sfile_t*,long,int,char*)); reg char *handle; /* set the stream to the right mode */ if((!f->mode || (f->mode&~(SF_RDWR|SF_STRING))) && _sfmode(f,0) < 0) return -1; if(type < 0 || type > 2 || f->orig < 0L) return -1; /* lock the stream for internal manipulations */ SFLOCK(f); /* clear error and eof bits */ f->flags &= ~(SF_EOF|SF_ERROR); if(f->mode&SF_STRING) { /* actual current end of data */ if((f->flags&SF_WRITE) && (s = f->next-f->data) > f->here && s != f->orig) f->here = s; /* new location */ if(type == 1) p += f->next - f->data; else if(type == 2) p += f->here; if(p < 0 || p > f->size) { p = -1; goto done; } f->next = f->data+p; f->orig = p; /* use this to determine if writes occured */ /* clear the part skipped over */ if(p > f->here) memclear((char*)(f->data+f->here),(int)(p-f->here)); goto done; } seekf = f->disc ? f->disc->seekf : NIL(long(*)_SFA_((Sfile_t*,long,int,char*))); handle = f->disc ? f->disc->handle : NIL(char*); /* currently known seek location */ s = f->here + ((f->mode&SF_READ) ? f->next-f->endb : f->next-f->data); if(type == 1 && p == 0 && !(f->flags&(SF_APPEND|SF_SHARE)) ) { /* certify current location only */ if((p = SEEKF(seekf,f,f->here,0,handle)) != f->here) p = -1; else p = s - f->orig; goto done; } if(f->mode&SF_WRITE) { if((f->flags&(SF_APPEND|SF_SHARE)) || (type == 0 ? p+f->orig : type == 1 ? p+s : -1) != s) { /* sync physical and virtual views */ SFopen(f); if(_sfflsbuf(f,-1) < 0) { p = -1; goto done; } SFLOCK(f); s = f->here; } if(f->flags&SF_APPEND) { /* the true location for a SF_APPEND stream */ s = f->here = SEEKF(seekf,f,0L,2,handle); r = p + (type == 0 ? f->orig : s); } else if(!(f->flags&SF_SHARE)) r = type == 0 ? p+f->orig : type == 1 ? p+s : -1; else r = -1; if(r == s) { /* at where we are supposed to be */ p = r - f->orig; goto done; } } else if(type < 2 && !(f->flags&(SF_SHARE|SF_APPEND)) && (r = p + (type == 0 ? f->orig : s)) > f->here) { /* move forward by reading */ if(f->next == f->endb) f->endb = f->endr = f->next = f->data; if(r < (s + (f->size - (f->endb-f->data)))) { SFopen(f); _sffilbuf(f,-1); SFLOCK(f); } } if(type < 2) { /* place to seek to */ p += type == 0 ? f->orig : s; if((f->mode&SF_READ) && !(f->flags&(SF_SHARE|SF_APPEND)) && p >= (f->here - (f->endb-f->data)) && p <= f->here) { /* still in bound, safe to just move the pointer */ f->next = f->endb - (f->here-p); p -= f->orig; goto done; } /* now must seek */ p = SEEKF(seekf,f,p,0,handle); } else p = SEEKF(seekf,f,p,2,handle); /* moved backward too far */ if(p >= 0 && p < f->orig) { SEEKF(seekf,f,f->here,0,handle); p = -1; } if(p < 0) goto done; f->here = p; if(f->mode&SF_READ) { /* any buffered data is invalid */ f->next = f->endr = f->endb = f->data; /* seek to a rounded boundary to improve performance */ if((s = f->size) > SF_GRAIN) s = SF_GRAIN; r = s > 1 ? (p/s)*s : p; if(r < p && r >= f->orig && SEEKF(seekf,f,r,0,handle) == r) { /* now fill buffer */ f->here = r; SFopen(f); (void) _sffilbuf(f,-1); SFLOCK(f); if(f->here < p) { p = -1; goto done; } f->next = f->endb - (f->here-p); } } p -= f->orig; done : SFOPEN(f); return p; } 0707070000000002761006440044230044230000010000000475414161200003000000003101sfio/sfset.c Ugsf Ggsf #include "sfhdr.h" /* Set some control flags or file descript for the stream ** ** Written by Kiem-Phong Vo (07/16/90) */ #define RDSTRING(f) ((f->flags&SF_RDSTR) == SF_RDSTR) #define WRSTRING(f) ((f->flags&SF_WRSTR) == SF_WRSTR) #define RDSTREAM(f) (f->mode&SF_READ) #define WRSTREAM(f) ((f->mode&SF_WRITE) && !(f->flags&SF_LINE)) #if __STDC__ || __cplusplus sfset(reg Sfile_t* f, reg int flags, reg int i) #else sfset(f,flags,i) reg Sfile_t *f; reg int flags; reg int i; #endif { if(flags == SF_EOF) { /* changing file descriptor */ if(SFFROZEN(f)) return -1; f->file = i; return i; } if(!f->mode) /* a std-stream */ (void)sfnew(f,NIL(uchar*),-1,f->file,f->flags); else if(SFFROZEN(f)) return 0; SFLOCK(f); /* can't touch this mode */ if(!(f->flags&SF_BOTH)) flags &= ~SF_RDWR; /* must have at least one read/write mode */ else if(!i && (flags&SF_RDWR) && (flags&SF_RDWR) != SF_RDWR) f->flags |= SF_RDWR; if(i) f->flags |= (flags&SF_SETS); else f->flags &= ~(flags&SF_SETS); if(!(f->mode&(SF_PUSH|SF_POOL)) && (RDSTRING(f) || RDSTREAM(f))) f->flags |= SF_GETC; else f->flags &= ~SF_GETC; if(!(f->mode&(SF_PUSH|SF_POOL)) && (WRSTRING(f) || WRSTREAM(f))) f->flags |= SF_PUTC; else f->flags &= ~SF_PUTC; if(f->orig < 0) f->flags &= ~(SF_RELATIVE|SF_SHARE|SF_APPEND); SFOPEN(f); if(!(f->mode&SF_STRING)) { /* if mode is exclusive, f must be in the right mode */ flags = f->flags&SF_RDWR; if((flags == SF_WRITE && !(f->mode&SF_WRITE)) || (flags == SF_READ && !(f->mode&(SF_READ|SF_SYNC))) ) _sfmode(f,flags); } return f->flags; } 0707070000000002771006440044230044230000010000000474537763700003300000005127sfio/sfsetbuf.c Ugsf Ggsf #include "sfhdr.h" #ifdef LIBX #include <fsinfo.h> #else #ifdef BSD #define stat_blksize #endif #endif /* Set a (new) buffer for a stream. ** If size < 0, it is assigned a suitable value depending on the ** kind of stream. The actual buffer size allocated is dependent ** on how much memory is available. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus uchar *sfsetbuf(reg Sfile_t* f, reg uchar* buf, reg int size) #else uchar *sfsetbuf(f,buf,size) reg Sfile_t *f; /* stream to be buffered */ reg uchar *buf; /* new buffer, !NULL if size > 0 */ reg int size; /* buffer size, -1 for default size */ #endif { reg int sf_malloc; reg uchar *obuf; if(!f->mode) { /* a std-stream */ obuf = f->data; (void)sfnew(f,buf,size,f->file,f->flags); return obuf; } /* set the stream to the right mode */ if((f->mode&~(SF_RDWR|SF_STRING)) && _sfmode(f,0) < 0) return NIL(uchar*); /* pure read/string streams must have a valid string */ if((f->flags&(SF_RDWR|SF_STRING)) == SF_RDSTR && (size < 0 || !buf)) size = 0; /* sync stream before switching buffer */ if((f->mode&SF_READ) && f->next < f->endb) sfsync(f); /* lock for internal work */ SFLOCK(f); /* get buffer space */ sf_malloc = 0; if(size < 0) { /* define a default size suitable for block transfer */ buf = NIL(uchar*); if(f->mode&SF_STRING) size = SF_GRAIN; else { /* try to set an optimal size for io */ struct stat sb; if(fstat(f->file,&sb) < 0) size = SF_GRAIN; else { if(f->mode&SF_READ) { /* maybe only need small buffer */ if((size = (int)sb.st_size) > SF_BUFSIZE) size = SF_BUFSIZE; size = ((size+SF_GRAIN-1)/SF_GRAIN)*SF_GRAIN; } #ifdef stat_blksize if(size <= 0 || size > sb.st_blksize) size = (int)sb.st_blksize; #endif if(size <= 0) size = SF_BUFSIZE; } } } if(size > 0 && !buf) { /* try to allocate it */ while(!(buf = (uchar*) malloc(size)) && size > 0) size /= 2; if(size > 0) sf_malloc = SF_MALLOC; else if(f->mode&SF_STRING) { SFOPEN(f); return NIL(uchar*); } } if(size == 0 && (f->mode&SF_READ)) { /* use the internal buffer */ size = sizeof(f->tiny); buf = f->tiny; sf_malloc = 0; } /* current buffer */ obuf = f->data; /* set up new buffer */ f->size = size; f->next = f->data = f->endr = f->endw = buf; f->endb = (f->mode&SF_READ) ? buf : buf+size; if(f->mode&SF_STRING) { f->orig = 0L; f->here = sf_malloc ? 0L : size; } if(obuf && obuf != buf && (f->flags&SF_MALLOC)) { free((char*)obuf); obuf = NIL(uchar*); } f->flags = (f->flags & ~SF_MALLOC)|sf_malloc; SFOPEN(f); return obuf; } 0707070000000003001006440044230044230000010000000471532037700003400000001066sfio/sfsetdisc.c Ugsf Ggsf #include "sfhdr.h" /* Set a new discipline for a stream. ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus Sfdisc_t* sfsetdisc(reg Sfile_t* f, reg Sfdisc_t* disc) #else Sfdisc_t* sfsetdisc(f,disc) reg Sfile_t *f; reg Sfdisc_t *disc; #endif { reg Sfdisc_t *old; /* set the stream to the right mode */ if((!f->mode || (f->mode&~(SF_RDWR|SF_STRING))) && _sfmode(f,0) < 0) return NIL(Sfdisc_t*); /* now set the new discipline */ if((old = f->disc) && old->exceptf) (*(old->exceptf))(f,0,old->handle); f->disc = disc; return old; } 0707070000000003011006440044230044230000010000000472060046300003400000002707sfio/sfsetflag.c Ugsf Ggsf #include "sfhdr.h" /* Set some control flags for the stream ** ** Written by Kiem-Phong Vo (07/16/90) */ #define RDSTRING(f) ((f->flags&SF_RDSTR) == SF_RDSTR) #define WRSTRING(f) ((f->flags&SF_WRSTR) == SF_WRSTR) #define RDSTREAM(f) (f->mode&SF_READ) #define WRSTREAM(f) ((f->mode&SF_WRITE) && !(f->flags&SF_LINE)) #if __STDC__ || __cplusplus sfsetflag(reg Sfile_t* f, reg int flags, reg int on) #else sfsetflag(f,flags,on) reg Sfile_t *f; reg int flags; reg int on; #endif { if(!f->mode) /* a std-stream */ (void)sfnew(f,NIL(uchar*),-1,f->file,f->flags); else if(SFFROZEN(f)) return 0; SFLOCK(f); /* can't touch this mode */ if(!(f->flags&SF_BOTH)) flags &= ~SF_RDWR; /* must have at least one read/write mode */ else if(!on && (flags&SF_RDWR) && (flags&SF_RDWR) != SF_RDWR) f->flags |= SF_RDWR; if(on) f->flags |= (flags&SF_SETS); else f->flags &= ~(flags&SF_SETS); if(!(f->mode&(SF_PUSH|SF_POOL)) && (RDSTRING(f) || RDSTREAM(f))) f->flags |= SF_GETC; else f->flags &= ~SF_GETC; if(!(f->mode&(SF_PUSH|SF_POOL)) && (WRSTRING(f) || WRSTREAM(f))) f->flags |= SF_PUTC; else f->flags &= ~SF_PUTC; if(f->orig < 0) f->flags &= ~(SF_RELATIVE|SF_SHARE|SF_APPEND); SFOPEN(f); if(!(f->mode&SF_STRING)) { /* if mode is exclusive, f must be in the right mode */ flags = f->flags&SF_RDWR; if((flags == SF_WRITE && !(f->mode&SF_WRITE)) || (flags == SF_READ && !(f->mode&(SF_READ|SF_SYNC))) ) _sfmode(f,flags); } return f->flags; } 0707070000000003021006440044230044230000010000000475414166000003200000003200sfio/sfstack.c Ugsf Ggsf #include "sfhdr.h" /* Push/pop streams ** ** Written by Kiem-Phong Vo (07/10/90) */ #if __STDC__ || __cplusplus Sfile_t *sfstack(reg Sfile_t* f1,reg Sfile_t* f2) #else Sfile_t *sfstack(f1,f2) reg Sfile_t *f1, *f2; #endif { Sfile_t tmp; reg Sfile_t *rf; /* can't push on something that is currently frozen */ if(SFFROZEN(f1) || (f2 && SFFROZEN(f2))) return NIL(Sfile_t*); /* initializing std-streams */ if((!f1->mode && _sfmode(f1,0) < 0) || (f2 && !f2->mode && _sfmode(f2,0) < 0)) return NIL(Sfile_t*); /* give access to other internal functions */ _Sfstack = sfstack; if(!f2) { /* popping */ if(!f1->push) return NIL(Sfile_t*); f2 = f1->push; } else if(_Sfpmove && f1->pool && f1->pool != &_Sfpool && !f1->back) { /* get something else to the front since f1 will be locked */ for(rf = f1->fore; rf; rf = rf->fore) { if(SFFROZEN(rf)) continue; (*_Sfpmove)(rf,0); break; } } SFLOCK(f1); SFLOCK(f2); /* swap image */ tmp = *f2; *f2 = *f1; *f1 = tmp; if(f1->pool != f2->pool) { /* reset pool pointers */ if(f1->pool) { if(f1->back) f1->back->fore = f1; else f1->pool->head = f1; if(f1->fore) f1->fore->back = f1; } if(f2->pool) { if(f2->back) f2->back->fore = f2; else f2->pool->head = f2; if(f2->fore) f2->fore->back = f2; } } if(f2->push != f2) { /* freeze the pushed stream */ f2->mode |= SF_PUSH; f2->flags &= ~(SF_GETC|SF_PUTC); f1->push = f2; rf = f1; } else { /* unfreeze the just exposed stream */ f1->mode &= ~SF_PUSH; SFopen(f1); sfset(f1,f1->flags,1); f2->push = NIL(Sfile_t*); rf = f2; } SFOPEN(f1); SFOPEN(f2); return rf; } 0707070000000003031006440044230044230000010000000471532054500003300000005004sfio/sfstrtod.c Ugsf Ggsf #include "sfhdr.h" /* Convert a double value represented in an ASCII format into ** the internal double representation. ** ** Written by David Korn and Kiem-Phong Vo (06/27/90) */ #ifdef NATIVE int _Sfstrtod; #else #define BATCH (2*sizeof(int)) /* accumulate this many digits at a time */ #define IPART 0 /* doing integer part */ #define FPART 1 /* doing fractional part */ #define EPART 2 /* doing exponent part */ #if __STDC__ || __cplusplus static double pow10(reg int n) #else static double pow10(n) reg int n; #endif { reg int m, pow; reg double dval, d, *pow10; /* set up look up table */ if((pow = n) < 0) { pow10 = _Sfneg10; pow = -pow; } else pow10 = _Sfpos10; /* reduce to a low exponent */ dval = 1.; if(pow >= MAXPOW10) { d = pow10[MAXEXP10-1]*pow10[MAXEXP10-1]; for(m = pow/MAXPOW10; m > 0; --m) dval *= d; pow = pow%MAXPOW10; } /* fast loop for the rest */ for(m = 1; m <= pow;) { if(m&pow) dval *= *pow10; pow10 += 1; if(n < 0) pow >>= 1; else m <<= 1; } return dval; } #if __STDC__ || __cplusplus double strtod(reg char* s, char** retp) #else double strtod(s,retp) reg char *s; /* string to convert */ char **retp; /* to return the remainder of string */ #endif { reg int n, c, m; reg double dval; reg int mode, fexp, sign, expsign; /* skip initial blanks */ while(isspace(*s)) ++s; /* get the sign */ if((sign = (*s == '-')) || *s == '+') s += 1; mode = IPART; fexp = expsign = 0; dval = 0.; while(*s) { /* accumulate a handful of the digits */ for(m = BATCH, n = 0; m > 0; --m, ++s) { /* get and process a char */ c = *s; if(isdigit(c)) n = 10*n + (c - '0'); else break; } /* number of digits accumulated */ m = BATCH-m; if(mode == IPART) { /* doing the integer part */ if(dval == 0.) dval = (double)n; else dval = dval*pow10(m) + (double)n; } else if(mode == FPART) { /* doing the fractional part */ fexp -= m; if(n > 0) dval += n*pow10(fexp); } else if(n) { /* doing the exponent part */ if(expsign) n = -n; dval *= pow10(n); } if(!c) break; if(m < BATCH) { /* detected a non-digit */ if(c == '.') { /* start the fractional part or no match */ if(mode != IPART) break; mode = FPART; s += 1; } else if(c == 'e' || c == 'E') { if(mode == EPART) break; mode = EPART; c = *++s; if((expsign = (c == '-')) || c == '+') s += 1; } else break; } } if(retp) *retp = s; return sign ? -dval : dval; } #endif /* NATIVE */ 0707070000000003041006440044230044230000010000000473061527500003100000003471sfio/sfsync.c Ugsf Ggsf #include "sfhdr.h" static char *Version = "\n@(#)sfio (AT&T Bell Laboratories) 12/07/90\0\n"; /* Synchronize data in buffers with the file system. ** If f is nil, all streams are sync-ed ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _sfsync(reg Sfile_t* f) #else _sfsync(f) reg Sfile_t *f; /* stream to be synchronized */ #endif { reg int n, rv, flag; if(!f) { /* use recursion to handle the sync-all case */ reg Sfpool_t *p; rv = 0; for(p = &_Sfpool; p != NIL(Sfpool_t*); p = p->fore) for(f = p->head; f != NIL(Sfile_t*); f = f->fore) { /* can't sync these */ if(SFFROZEN(f)) continue; /* make sure pool list is not rearranged */ flag = f->mode&SF_POOL; f->mode &= ~SF_POOL; if(sfsync(f) < 0) rv = -1; f->mode |= flag; } return rv; } if(f->mode == 0 || (f->mode&SF_SYNC)) return 0; if((f->mode&~(SF_RDWR|SF_STRING)) && _sfmode(f,0) < 0) return -1; rv = 0; for(; f; f = f->push) { /* pretend that this stream is not on a stack */ SFLOCK(f); flag = f->mode&SF_PUSH; f->mode &= ~SF_PUSH; if(f->mode&SF_WRITE) { /* sync the buffer, make sure pool don't move */ SFopen(f); flag = f->mode&SF_POOL; f->mode &= ~SF_POOL; if(_sfflsbuf(f,-1) < 0) rv = -1; f->mode |= flag; SFLOCK(f); } else if((f->mode&SF_READ) && !(f->flags&SF_SHARE) && f->orig >= 0 && (n = f->endb-f->next) > 0) { /* make sure the file pointer is at the right place */ reg long (*seekf)_SFA_((Sfile_t*,long,int,char*)); reg char *handle; f->mode = SF_SYNC|SF_LOCK; seekf = f->disc ? f->disc->seekf : NIL(long(*)_SFA_((Sfile_t*,long,int,char*))); handle = f->disc ? f->disc->handle : NIL(char*); f->here -= n; if(SEEKF(seekf,f,f->here,0,handle) < 0) rv = -1; } f->mode |= flag; SFOPEN(f); } return rv; } 0707070000000003051006440044230044230000010000000471442321200003200000002404sfio/sftable.c Ugsf Ggsf #include "sfhdr.h" /* tables to aid fast look-up of powers of ten */ double _Sfpos10[MAXEXP10] = { 1e1, 1e2, 1e4, 1e8, 1e16, 1e32 }; double _Sfneg10[MAXEXP10] = { 1e-1, 1e-2, 1e-4, 1e-8, 1e-16, 1e-32 }; /* codes for digits of numbers in the range [0-100) */ uchar _Sfdec[] = { (0<<4)|0, (0<<4)|1, (0<<4)|2, (0<<4)|3, (0<<4)|4, (0<<4)|5, (0<<4)|6, (0<<4)|7, (0<<4)|8, (0<<4)|9, (1<<4)|0, (1<<4)|1, (1<<4)|2, (1<<4)|3, (1<<4)|4, (1<<4)|5, (1<<4)|6, (1<<4)|7, (1<<4)|8, (1<<4)|9, (2<<4)|0, (2<<4)|1, (2<<4)|2, (2<<4)|3, (2<<4)|4, (2<<4)|5, (2<<4)|6, (2<<4)|7, (2<<4)|8, (2<<4)|9, (3<<4)|0, (3<<4)|1, (3<<4)|2, (3<<4)|3, (3<<4)|4, (3<<4)|5, (3<<4)|6, (3<<4)|7, (3<<4)|8, (3<<4)|9, (4<<4)|0, (4<<4)|1, (4<<4)|2, (4<<4)|3, (4<<4)|4, (4<<4)|5, (4<<4)|6, (4<<4)|7, (4<<4)|8, (4<<4)|9, (5<<4)|0, (5<<4)|1, (5<<4)|2, (5<<4)|3, (5<<4)|4, (5<<4)|5, (5<<4)|6, (5<<4)|7, (5<<4)|8, (5<<4)|9, (6<<4)|0, (6<<4)|1, (6<<4)|2, (6<<4)|3, (6<<4)|4, (6<<4)|5, (6<<4)|6, (6<<4)|7, (6<<4)|8, (6<<4)|9, (7<<4)|0, (7<<4)|1, (7<<4)|2, (7<<4)|3, (7<<4)|4, (7<<4)|5, (7<<4)|6, (7<<4)|7, (7<<4)|8, (7<<4)|9, (8<<4)|0, (8<<4)|1, (8<<4)|2, (8<<4)|3, (8<<4)|4, (8<<4)|5, (8<<4)|6, (8<<4)|7, (8<<4)|8, (8<<4)|9, (9<<4)|0, (9<<4)|1, (9<<4)|2, (9<<4)|3, (9<<4)|4, (9<<4)|5, (9<<4)|6, (9<<4)|7, (9<<4)|8, (9<<4)|9, }; 0707070000000003061006440044230044230000010000000471532062000003100000001222sfio/sftell.c Ugsf Ggsf #include "sfhdr.h" /* Tell the current location in a given stream ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus long sftell(reg Sfile_t* f) #else long sftell(f) reg Sfile_t *f; #endif { reg long here; /* set the stream to the right mode */ if((!f->mode || (f->mode&~(SF_RDWR|SF_STRING))) && _sfmode(f,0) < 0) return -1; if(f->mode&SF_STRING) return (long)(f->next-f->data); /* let sfseek() handle the hard case */ if(f->orig >= 0 && (f->flags&(SF_SHARE|SF_APPEND))) return sfseek(f,0L,1); here = f->here + ((f->mode&SF_WRITE) ? f->next-f->data : f->next-f->endb); return here - (f->orig > 0 ? f->orig : 0L); } 0707070000000003071006440044230044230000010000000474537763700003400000003635sfio/sftmpfile.c Ugsf Ggsf #include "sfhdr.h" #ifndef F_SETFD #ifndef FIOCLEX #ifdef V9 #include <sys/filio.h> #endif /*V9*/ #endif /*FIOCLEX*/ #endif /*F_SETFD*/ /* Create a temporary stream for read/write. ** The stream is originally created as a memory-resident stream. ** When this memory is exceeded, a real temp file will be created. ** The temp file creation sequence is somewhat convoluted so that ** pool/stack/discipline will work correctly. ** ** Written by David Korn and Kiem-Phong Vo (12/10/90) */ #if __STDC__ || __cplusplus static _tmpexcept(Sfile_t* f, int type, char* hdl) #else static _tmpexcept(f,type,hdl) Sfile_t *f; int type; char *hdl; #endif { reg int here, extent; Sfile_t newf; /* do nothing cases */ if(type == SF_EOF || type == SF_READ) return 0; /* get the extent of current data */ here = extent = f->next-f->data; if(extent < f->here) extent = (int)(f->here); /* try to create the temp file */ SFCLEAR(&newf); hdl = mktemp("/tmp/sfXXXXXXXX"); if(!sfopen(&newf,hdl,"w+")) return -1; /* remove the temp file and set close-on-exec */ while(unlink(hdl) < 0 && errno == EINTR) errno = 0; #ifdef F_SETFD (void)fcntl(newf.file,F_SETFD,0); #else #ifdef FIOCLEX (void)ioctl(newf.file,FIOCLEX,0); #endif #endif /* now remake the old stream into the new image */ f->disc = NIL(Sfdisc_t*); if(!sfnew(f,NIL(uchar*),-1,newf.file,SF_READ|SF_WRITE)) { while(close(newf.file) < 0 && errno == EINTR) errno = 0; return -1; } (void)sfwrite(f,f->data,extent); (void)sfseek(f,(long)here,0); return 1; } #if __STDC__ || __cplusplus Sfile_t* _sftmpfile(int s) #else Sfile_t* _sftmpfile(s) int s; #endif { reg Sfile_t *f; static Sfdisc_t Tmpdisc; /* make this a memory resident stream at first */ if(!(f = sfnew(NIL(Sfile_t*),NIL(uchar*),s,-1,SF_STRING|SF_READ|SF_WRITE))) return NIL(Sfile_t*); /* set up a discipline for out-of-bound, etc. */ Tmpdisc.exceptf = _tmpexcept; sfsetdisc(f,&Tmpdisc); return f; } 0707070000000003101006440044230044230000010000000471532064700003300000001215sfio/sfungetc.c Ugsf Ggsf #include "sfhdr.h" /* Push back one byte to a given SF_READ stream ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfungetc(reg Sfile_t* f, reg int c) #else sfungetc(f,c) reg Sfile_t *f; /* push back one byte to this stream */ reg int c; /* the value to be pushed back */ #endif { reg uchar *cp; if(c < 0 || (f->mode != SF_READ && SFMODE(f,SF_READ) < 0) || f->next <= f->data) return -1; SFLOCK(f); if(*(cp = --f->next) != (uchar)c) { if((f->flags&SF_STRING) && !(f->flags&SF_WRITE)) { /* avoid writing into a constant string */ f->next += 1; c = -1; } else *cp = (uchar)c; } SFOPEN(f); return c; } 0707070000000003111006440044230044230000010000000475116762500003400000030047sfio/sfvprintf.c Ugsf Ggsf #include "sfhdr.h" /* The engine for formatting data ** ** Written by Kiem-Phong Vo (06/27/90) */ #define HIGHBIT (~(((ulong)~0L) >> 1)) #define F_LEFT 00001 /* left justification (-) */ #define F_SIGN 00002 /* must set a sign - or + */ #define F_BLANK 00004 /* if not - and +, then prepend a blank */ #define F_ZERO 00010 /* zero padding on the left side */ #define F_ALTER 00020 /* various alternative formats (#) */ #define F_PAD 00040 /* some kind of padding is needed */ #define F_REPEAT 00100 /* repeat the pattern until precision is exhausted */ #define F_0X 00200 /* must add a zero for prefix of hex format */ #define F_MINUS 00400 /* has a minus sign */ #define F_PREFIX (F_MINUS|F_SIGN|F_BLANK|F_0X) #define F_LONG 01000 /* object is long */ #define F_FLOAT 02000 /* %fFeEgG format */ #define F_GFORMAT 04000 /* a %gG format */ #define FPRECIS 6 /* default precision for floats */ #define GETARG(elt,arge,argf,args,type,fmt) \ { if(!argf) \ elt = va_arg(args,type); \ else if((*argf)(fmt,(char*)(&arge)) < 0) \ goto pop_fa; \ else elt = arge; \ } #if __STDC__ || __cplusplus sfvprintf(Sfile_t* f, const char* form, va_list args) #else sfvprintf(f,form,args) Sfile_t *f; /* file to print to */ char *form; /* format to use */ va_list args; /* arg list if argf == 0 */ #endif { reg long n, lval; reg char *sp, *ssp, *d; reg long v; reg int flags; reg char *ep, *endep, *endsp, *endd; reg int precis, width, n_output, r; int fmt, sign, decpt; double dval; long al; int ai, *ap; char *as; Argf_p argf; Extf_p extf; va_list alist; reg Fa_t *fa, *fast; char buf[MAXDIGITS]; char data[SF_GRAIN]; /* fast io system */ #define SFflush(f,c) (SFopen(f), r = _sfflsbuf(f,(int)c), SFLOCK(f), r) #define SFwrite(f,s,n) (SFopen(f), r = sfwrite(f,(uchar*)s,(int)n), SFLOCK(f), r) #define SFnputc(f,c,n) (SFopen(f), r = sfnputc(f,(uchar)c,(int)n), SFLOCK(f), r) #define SFSET(f) (d = (char*)f->next, endd = (char*)f->endb) #define SFINIT(f) (SFSET(f), n_output = 0) #define SFEND(f) ((n_output += (uchar*)d - f->next), (f->next = (uchar*)d)) #define SFPUTC(f,c) \ { if(d >= endd) \ { SFEND(f); if(SFflush(f,c) < 0) break; n_output += 1; SFSET(f); } \ else { *d++ = (char)c; } \ } #define SFNPUTC(f,c,n) \ { if((endd-d) < n) \ { SFEND(f); if(SFnputc(f,c,n) != n) break; n_output += (int)n; SFSET(f); } \ else { while(n--) *d++ = (char)c; } \ } #define SFWRITE(f,s,n) \ { if((endd-d) < n) \ { SFEND(f); if(SFwrite(f,s,n) != n) break; n_output += (int)n; SFSET(f); } \ else MEMCPY(d,s,(int)n); \ } /* make sure stream is in write mode and buffer is not NULL */ if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; SFLOCK(f); if(f->data == NIL(uchar*)) { f->data = f->next = (uchar*)data; f->endw = f->endb = f->data+sizeof(data); } SFINIT(f); argf = NIL(Argf_p); extf = NIL(Extf_p); fast = NIL(Fa_t*); loop_fa : while(n = *form++) { flags = 0; if(n != '%') { /* collect the non-pattern chars */ sp = ssp = (char*)(form-1); while((n = *++ssp) && n != '%') ; form = endsp = ssp; goto do_output; } endep = ep = NIL(char*); endsp = sp = buf+(sizeof(buf)-1); width = precis = -1; loop_flags: /* LOOP FOR FLAGS, WIDTH AND PRECISION */ switch(fmt = *form++) { case '-' : flags |= F_LEFT; goto loop_flags; case ' ' : flags |= F_BLANK; goto loop_flags; case '+' : flags |= F_SIGN; goto loop_flags; case '#' : flags |= F_ALTER; goto loop_flags; case '.' : /* done with width */ if(width < 0) width = 0; goto loop_flags; case '*' : /* variable width or precision */ GETARG(lval,ai,argf,args,int,'d'); if(width >= 0) precis = (int)lval; else if((width = (int)lval) < 0) { /* left justification */ width = (int)(-lval); flags |= F_LEFT; } flags |= F_PAD; goto loop_flags; case '0' : /* defining width or precision */ if(width < 0) flags |= F_ZERO; /* fall thru */ case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : lval = fmt - '0'; for(n = *form; isdigit(n); n = *++form) lval = lval*10 + (n - '0'); if(width < 0) width = (int)lval; else precis = (int)lval; flags |= F_PAD; goto loop_flags; case 'l' : flags |= F_LONG; case 'h' : /* no short */ goto loop_flags; /* PRINTF DIRECTIVES */ case '&' : /* change extension function */ if(!argf) extf = va_arg(args,Extf_p); else if((*argf)('&',(char*)(&extf)) < 0) goto pop_fa; continue; case '@' : /* change argument getting function */ if(!argf) argf = va_arg(args,Argf_p); else if((*argf)('@',(char*)(&argf)) < 0) goto pop_fa; continue; case ':' : /* stack a pair of format/arglist */ if(!FAMALLOC(fa)) goto done; fa->form = (char*)form; GETARG(form,form,argf,args,char*,'1'); if(!form) form = ""; GETARG(alist,alist,argf,args,va_list,'2'); fa->args = args; fa->argf.p = argf; fa->extf.p = extf; args = alist; fa->next = fast; fast = fa; continue; default : /* unknown directive */ if(extf) { /* call the extension function */ GETARG(sp,as,argf,args,char*,fmt); n = (*extf)(sp,fmt,precis,(char*)(&as)); if((sp = as) != NIL(char*)) goto s_format; } /* treat as text */ form -= 1; continue; case 's': /* a string */ GETARG(sp,as,argf,args,char*,'s'); n = -1; if(!sp) { /* standard error string for null pointer */ endsp = (sp = "(null)") + 6; flags = 0; } else { /* set other bound */ s_format: if(n < 0) { ssp = sp-1; while(*++ssp) ; n = ssp-sp; } if(precis >= 0 && precis < n) n = precis; endsp = sp+n; } flags &= ~(F_SIGN|F_BLANK|F_ALTER); precis = 0; break; case 'n': /* return current output length */ GETARG(ap,ap,argf,args,int*,'n'); SFEND(f); *ap = n_output; continue; case 'c': /* a character */ GETARG(fmt,fmt,argf,args,int,'d'); case '%' : flags = (flags&~(F_SIGN|F_BLANK|F_ZERO))|F_REPEAT; if(precis <= 0) precis = 1; break; case 'i': /* signed integer */ case 'd': if(flags&F_LONG) { GETARG(lval,al,argf,args,long,'D'); } else { GETARG(lval,ai,argf,args,int,'d'); } if(lval < 0) { flags |= F_MINUS; if(lval == HIGHBIT) { /* avoid overflow */ lval = ((ulong)HIGHBIT)/10; *--sp = (char)('0' + ((ulong)HIGHBIT - (((ulong)HIGHBIT)/10)*10)); } else lval = -lval; } goto base_10; case 'p': /* pointer value */ GETARG(ssp,as,argf,args,char*,'p'); lval = (long)ssp; flags = (flags&~(F_SIGN|F_BLANK))|F_ALTER; fmt = 'x'; goto base_16; case 'u': /* unsigned value */ case 'o': case 'x': case 'X': if(flags&F_LONG) { GETARG(lval,al,argf,args,long,'D'); } else { GETARG(lval,ai,argf,args,int,'d'); } flags &= ~(F_SIGN|F_BLANK); if(fmt == 'o') { /* base 8 conversion */ do { *--sp = (char)('0' + (lval&07)); } while(lval = (ulong)lval >> 3); if((flags&F_ALTER) && *sp != '0') *--sp = '0'; } else if(fmt == 'u') { /* base 10 unsigned conversion */ base_10: sfucvt(lval,sp,n,v,ssp); } else { /* base 16 conversion */ base_16: if((flags&F_ALTER) && lval) flags |= F_0X; ssp = fmt == 'X' ? "0123456789ABCDEF":"0123456789abcdef"; do { *--sp = ssp[lval&017]; } while(lval = ((ulong)lval) >> 4); } precis -= (endsp-sp); break; case 'g': /* ultimately becomes %e or %f */ case 'G': GETARG(dval,dval,argf,args,double,'F'); precis = precis < 0 ? FPRECIS : precis == 0 ? 1 : precis; ep = sfecvt(dval,min(precis,FDIGITS),&decpt,&sign); if(dval == 0.) decpt = 1; else if(*ep == 'I') goto infinite; if(!(flags&F_ALTER)) { /* zap trailing 0s */ if((n = sfslen()) > precis) n = precis; while((n -= 1) >= 1 && ep[n] == '0') ; n += 1; } else n = precis; flags = (flags & ~F_ZERO) | F_GFORMAT; if(decpt < -3 || decpt > precis) { precis = (int)(n-1); goto e_format; } else { precis = (int)(n - decpt); goto f_format; } case 'e': /* double value in scientific notation */ case 'E': /* convert data into ascii */ GETARG(dval,dval,argf,args,double,'F'); n = (precis = precis < 0 ? FPRECIS : precis)+1; ep = sfecvt(dval,(int)min(n,FDIGITS),&decpt,&sign); e_format: /* now build the x.yyyy string */ if(isalpha(*ep)) goto infinite; sp = endsp = buf+1; /* reserve space for sign */ *endsp++ = *ep ? *ep++ : '0'; if(precis > 0 || (flags&F_ALTER)) *endsp++ = '.'; ssp = endsp; endep = ep+precis; while((*endsp++ = *ep++) && ep <= endep) ; precis -= (endsp -= 1) - ssp; /* build the exponent */ ep = endep = buf+(sizeof(buf)-1); if(dval != 0.) { if((n = decpt - 1) < 0) n = -n; while(n > 9) { lval = n; n /= 10; *--ep = (char)('0' + (lval - n*10)); } } else n = 0; *--ep = (char)('0' + n); if(endep-ep <= 1) /* at least 2 digits */ *--ep = '0'; /* the e/Exponent separator and sign */ *--ep = (decpt > 0 || dval == 0.) ? '+' : '-'; *--ep = isupper(fmt) ? 'E' : 'e'; flags = (flags&~F_ZERO)|F_FLOAT; goto end_efg; case 'f': /* float or double in xxx.yyy notation */ case 'F': GETARG(dval,dval,argf,args,double,'F'); precis = precis < 0 ? FPRECIS : precis; ep = sffcvt(dval,min(precis,FDIGITS),&decpt,&sign); f_format: /* data before the '.' */ if(isalpha(*ep)) { infinite: endsp = (sp = ep)+sfslen(); ep = endep; precis = 0; goto end_efg; } endsp = sp = buf+1; /* save a space for sign */ endep = ep+decpt; while(ep < endep && (*endsp++ = *ep++)) ; if(endsp == sp) *endsp++ = '0'; if(precis > 0 || (flags&F_ALTER)) *endsp++ = '.'; if((n = -decpt) > 0) { /* output zeros for negative exponent */ ssp = endsp + min(n,precis); precis -= (int)n; while(endsp < ssp) *endsp++ = '0'; } ssp = endsp; endep = ep+precis; while((*endsp++ = *ep++) && ep <= endep) ; precis -= (endsp -= 1) - ssp; ep = endep; flags |= F_FLOAT; end_efg: if(sign) { /* if a %gG, output the sign now */ if(flags&F_GFORMAT) *--sp = '-'; else flags |= F_MINUS; } break; } if(!flags) goto do_output; else if(flags&(F_MINUS|F_SIGN|F_BLANK)) fmt = (flags&F_MINUS) ? '-' : (flags&F_SIGN) ? '+' : ' '; n = (endsp-sp) + (endep-ep) + (precis <= 0 ? 0 : precis) + ((flags&F_0X) ? 2 : (flags&F_PREFIX) ? 1 : 0); if((lval = width-n) > 0) { /* check for padding */ if(!(flags&F_ZERO)) { /* right padding */ if(flags&F_LEFT) lval = -lval; else if(flags&F_PREFIX) { /* blank padding, output prefix now */ *--sp = fmt; if((flags&F_0X)) *--sp = '0'; flags &= ~F_PREFIX; } } } else lval = 0; if(flags&F_PREFIX) { /* output prefix */ if(flags&F_0X) SFPUTC(f,'0'); SFPUTC(f,fmt); if(fmt != ' ') flags |= F_ZERO; } if((n = lval) > 0) { /* left padding */ v = (flags&F_ZERO) ? '0' : ' '; SFNPUTC(f,v,n); } if((n = precis) > 0 && ((flags&F_REPEAT) || !(flags&F_FLOAT))) { /* repeated chars or padding for integer precision */ v = (flags&F_REPEAT) ? fmt : '0'; SFNPUTC(f,v,n); precis = 0; } do_output: if((n = endsp-sp) > 0) SFWRITE(f,sp,n); if(flags&(F_FLOAT|F_LEFT)) { /* F_FLOAT: right padding for float precision */ if((n = precis) > 0) SFNPUTC(f,'0',n); /* F_FLOAT: the exponent of %eE */ if((n = endep-(sp=ep)) > 0) SFWRITE(f,sp,n); /* F_LEFT: right padding */ if((n = -lval) > 0) SFNPUTC(f,' ',n); } } pop_fa: if(fa = fast) { /* pop the format stack and continue */ form = fa->form; args = fa->args; argf = fa->argf.p; extf = fa->extf.p; fast = fa->next; FAFREE(fa); goto loop_fa; } done: SFEND(f); r = f->next - f->data; if((d = (char*)f->data) == data) f->data = NIL(uchar*); f->next = f->data; f->endw = f->endb = f->data+f->size; if(r > 0 && (d == data || ((f->flags&SF_LINE) && !(f->flags&SF_STRING)))) { SFopen(f); (void) sfwrite(f,(uchar*)d,r); } else f->next += r; SFOPEN(f); return n_output; } 0707070000000003121006440044230044230000010000000475157210100003300000022010sfio/sfvscanf.c Ugsf Ggsf #include "sfhdr.h" /* The main engine for reading formatted data ** ** Written by Kiem-Phong Vo (06/27/90) */ #define S_NORMAL 0 /* argument is a pointer to a normal object */ #define S_LONG 1 /* argument is a pointer to a long object */ #define S_SHORT 2 /* argument is a pointer to a short object */ #define a2f(s) strtod(s,NIL(char**)) #define A_SIZE (1<<8) /* alphabet */ #if __STDC__ || __cplusplus static char *setclass(reg char* form, reg char* accept) #else static char *setclass(form,accept) reg char *form; /* format string */ reg char *accept; /* accepted characters are set to 1 */ #endif { reg int fmt, c, yes; if((fmt = *form++) == '^') { /* we want the complement of this set */ yes = 0; fmt = *form++; } else yes = 1; for(c = 0; c < A_SIZE; ++c) accept[c] = !yes; if(fmt == ']' || fmt == '-') { /* special first char */ accept[fmt] = yes; fmt = *form++; } for(; fmt != ']'; fmt = *form++) { /* done */ if(!fmt) return (form-1); /* interval */ if(fmt != '-' || form[0] == ']' || form[-2] > form[0]) accept[fmt] = yes; else for(c = form[-2]+1; c < form[0]; ++c) accept[c] = yes; } return form; } #define SETARG(val,argf,args,type,fmt,form) \ { if(!argf) \ *va_arg(args,type*) = (type)val; \ else if((*argf)(fmt,(char*)(&val),sizeof(val)) < 0) \ form = ""; \ } #if __STDC__ || __cplusplus sfvscanf(Sfile_t* f, reg const char* form, va_list args) #else sfvscanf(f,form,args) Sfile_t *f; /* file to be scanned */ reg char *form; /* scanning format */ va_list args; #endif { reg int fmt, inp; reg char *d; reg int skip, size, length, n_match; reg Sfile_t *sf; reg char *sp; char accept[MAXDIGITS]; reg char *endd; Argf_s argf; Extf_s extf; reg Fa_t *fa, *fast; va_list alist; /* fast io system */ #define SFSET(f) (d = (char*)f->next, endd = (char*)f->endb) #define SFEND(f) (f->next = (uchar*)d) #define SFFILL(f,c) (SFEND(f), (SFopen(f),c = _sffilbuf(f,1),SFLOCK(f)), SFSET(f), c) #define SFGETC(f,c) (d >= endd ? SFFILL(f,c) : (c = (int)(*d++))) #define SFUNGETC(f,c) (--d) if(f->mode != SF_READ && SFMODE(f,SF_READ) < 0) return -1; SFLOCK(f); SFSET(f); n_match = 0; inp = -1; sf = NIL(Sfile_t*); argf = NIL(Argf_s); extf = NIL(Extf_s); fast = NIL(Fa_t*); loop_fa : while(fmt = *form++) { switch(fmt) { default : /* literal match */ literal : if(SFGETC(f,inp) != fmt) { /* premature eof */ if(inp < 0) return -1; SFUNGETC(f,inp); goto done; } continue; case ' ' : /* skip blanks */ case '\t': case '\n': do { SFGETC(f,inp); } while(isspace(inp) || inp == '\n'); if(inp < 0) goto done; else SFUNGETC(f,inp); continue; case '%' : /* matching some pattern */ skip = 0; switch(fmt = *form++) { case '%' : /* match % literally */ goto literal; case '@' : /* set argument getting function */ argf = va_arg(args,Argf_s); continue; case '&' : /* set extension function */ extf = va_arg(args,Extf_s); continue; case ':' : /* stack a pair of format/arglist */ if(!FAMALLOC(fa)) goto done; fa->form = (char*)form; if(!(form = va_arg(args,char*))) form = ""; alist = va_arg(args,va_list); fa->args = args; args = alist; fa->extf.s = extf; fa->argf.s = argf; fa->next = fast; fast = fa; continue; case '*' : /* skip one argument */ skip = 1; fmt = *form++; default : /* scan length */ length = 0; while(isdigit(fmt)) { length = length*10 + (fmt - '0'); fmt = *form++; } /* size of object to be assigned */ if(fmt == 'l') { size = S_LONG; fmt = *form++; } else if(fmt == 'h') { size = S_SHORT; fmt = *form++; } else size = S_NORMAL; /* canonicalize format */ switch(fmt) { case 'D' : case 'I' : case 'U' : size = S_LONG; case 'i' : case 'u' : fmt = 'd'; break; case 'O' : size = S_LONG; fmt = 'o'; break; case 'X' : size = S_LONG; fmt = 'x'; break; case 'E' : case 'F' : case 'G' : size = S_LONG; case 'e' : case 'f' : case 'g' : fmt = 'f'; break; } } } /* scan length */ if(length == 0) length = fmt == 'c' ? 1 : SF_BUFSIZE; /* define the first input character */ if(fmt == 'c' || fmt == '[') SFGETC(f,inp); else { /* skip starting blanks */ do { SFGETC(f,inp); } while(isspace(inp) || inp == '\n') ; } if(inp < 0) goto done; if(fmt == 'f') { /* a float or double */ reg char *val; reg int dot, exponent; double dval; val = accept; if(length >= MAXDIGITS) length = MAXDIGITS-1; dot = exponent = 0; do { if(isdigit(inp)) *val++ = inp; else if(inp == '.') { /* too many dots */ if(dot++ > 0) break; *val++ = '.'; } else if(inp == 'e' || inp == 'E') { /* too many e,E */ if(exponent++ > 0) break; *val++ = inp; SFGETC(f,inp); if(inp == '-' || inp == '+' || isdigit(inp)) *val++ = inp; else break; } else if(inp == '-' || inp == '+') { /* too many signs */ if(val > accept) break; *val++ = inp; } else break; } while(--length > 0 && SFGETC(f,inp) >= 0); if(val > accept) { /* there is something to convert */ n_match += 1; *val = '\0'; if(!skip) { /* assign */ dval = a2f(accept); switch(size) { case S_LONG: SETARG(dval,argf,args,double,'F',form); break; case S_SHORT : case S_NORMAL: SETARG(dval,argf,args,float,'f',form); break; } } } } else if(fmt == 's' || fmt == 'c' || fmt == '[') { n_match += 1; sp = NIL(char*); if(!skip) { if(!argf) sp = va_arg(args,char*); else if(!sf) sf = sfnew(NIL(Sfile_t*),NIL(uchar*),-1,-1, SF_STRING|SF_WRITE); else sfseek(sf,0L,0); } if(fmt == 's') { /* copy a string */ do { if(isspace(inp) || inp == '\n') break; if(sp) *sp++ = inp; else if(!skip && sf) sfputc(sf,inp); } while(--length > 0 && SFGETC(f,inp) >= 0); } else if(fmt == 'c') { /* copy characters */ do { if(sp) *sp++ = inp; else if(!skip && sf) sfputc(sf,inp); } while(--length > 0 && SFGETC(f,inp) >= 0); } else { /* copy characters from a class */ form = setclass((char*)form,accept); do { if(!accept[inp]) break; if(sp) *sp++ = inp; else if(!skip && sf) sfputc(sf,inp); } while(--length > 0 && SFGETC(f,inp) >= 0); } if(sp) { if(fmt != 'c' || length > 1) *sp = '\0'; } else if(!skip && sf) { sfputc(sf,'\0'); if((*argf)('s',(char*)sf->data,sf->next-sf->data) < 0) form = ""; } } else if(fmt == 'd' || fmt == 'o' || fmt == 'x') { /* some integer type */ long lval; reg int base, sign; base = fmt == 'o' ? 8 : fmt == 'x' ? 16 : 10; if(inp == '-' || inp == '+') { /* get the sign */ sign = inp == '-' ? -1 : 1; SFGETC(f,inp); length -= 1; } else sign = 1; if(inp < 0) goto done; /* skip leading 0's */ do { if(inp != '0') break; } while(--length > 0 && SFGETC(f,inp) >= 0); /* now convert */ lval = 0; if(base == 10) { if(length > 0) do { if(inp < '0' || inp > '9') break; lval = (lval << 3) + (lval << 1) + (inp - '0'); } while(--length > 0 && SFGETC(f,inp) >= 0); } else if(base == 8) { if(length > 0) do { if(inp < '0' || inp > '7') break; lval = (lval << 3) + (inp - '0'); } while(--length > 0 && SFGETC(f,inp) >= 0); } else /* base 16 */ { if(length > 0 && (inp == 'x' || inp == 'X')) { /* skip leading x */ SFGETC(f,inp); length -= 1; } if(length > 0) do { if(inp >= '0' && inp <= '9') inp = inp - '0'; else if(inp >= 'a' && inp <= 'f') inp = (inp - 'a') + 10; else if(inp >= 'A' && inp <= 'F') inp = (inp - 'A') + 10; else break; lval = (lval << 4) + inp; } while(--length > 0 && SFGETC(f,inp) >= 0); } /* assign */ n_match += 1; if(sign < 0) lval = -lval; if(!skip) switch(size) { case S_SHORT : SETARG(lval,argf,args,short,'h',form); break; case S_NORMAL : SETARG(lval,argf,args,int,'d',form); break; case S_LONG : SETARG(lval,argf,args,long,'D',form); break; } } else if(extf) { /* call extension function */ char *rv; int n; SFEND(f); SFOPEN(f); n = (*extf)(f,fmt,length,&rv); SFLOCK(f); SFSET(f); if(n >= 0) { n_match += 1; if(!skip) { if(!argf) { sp = va_arg(args,char*); while(n--) *sp++ = *rv++; } else if((*argf)(fmt,rv,n) < 0) form = ""; } } continue; } if(inp < 0) break; else if(length > 0) SFUNGETC(f,inp); } if(fa = fast) { /* check for stacked formats/arglists */ form = fa->form; args = fa->args; argf = fa->argf.s; extf = fa->extf.s; fast = fa->next; FAFREE(fa); goto loop_fa; } done: if(sf) sfclose(sf); SFEND(f); SFOPEN(f); return (n_match == 0 && inp < 0) ? -1 : n_match; } 0707070000000003131006440044230044230000010000000475453670000003200000005643sfio/sfwrite.c Ugsf Ggsf #include "sfhdr.h" /* Write data out to the file system ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus sfwrite(reg Sfile_t* f, reg const uchar* s, reg int n) #else sfwrite(f,s,n) reg Sfile_t *f; /* write to this stream */ reg uchar *s; /* buffer to be written */ reg int n; /* number of bytes */ #endif { reg uchar *data; reg int w; reg int line_fls; reg int (*writef)_SFA_((Sfile_t*, const uchar*, int, char*)); reg long (*seekf)_SFA_((Sfile_t*, long, int, char*)); reg char *handle; #if __STDC__ || __cplusplus reg const uchar *begs; #else reg uchar *begs; #endif begs = s; redo_loop: if(f->mode != SF_WRITE && SFMODE(f,SF_WRITE) < 0) return -1; SFLOCK(f); writef = f->disc ? f->disc->writef : NIL(int(*)_SFA_((Sfile_t*,const uchar*,int,char*))); seekf = f->disc ? f->disc->seekf : NIL(long(*)_SFA_((Sfile_t*, long, int, char*))); handle = f->disc ? f->disc->handle : NIL(char*); /* see if must flush because of line buffering */ line_fls = 0; if((f->flags&SF_LINE) && !(f->flags&SF_STRING)) { if(n >= HIFORLINE) line_fls = 1; else for(data = (uchar*)s+n-1; data >= (uchar*)s;) if(*data-- == '\n') { line_fls = 1; break; } } if((uchar*)s == (data = f->next)) { /* user wrote directly into this buffer */ if((w = f->endb - data) > n) w = n <= 0 ? 0 : n; f->next += w; s += w; if((n -= w) <= 0) goto done; data += w; } if((w = f->endb - data) == f->size && w <= n && !(f->mode&SF_STRING)) goto do_write; else if(w > n) w = n; for(;;) { /* copy data - note that s is advanced too */ MEMCPY(data,s,w); f->next += w; if((n -= w) <= 0) goto done; if(f->mode&SF_STRING) { w = n; goto at_eof; } if(f->next > f->data) { /* clear buffer before direct writes */ SFopen(f); if(_sfflsbuf(f,-1) < 0) goto done; SFLOCK(f); } do_write : while(n >= (w = f->size) || line_fls) { if(w <= 1 || line_fls) /* unbuffered write */ w = n; else { /* write using a round-up unit */ if(w > SF_GRAIN) w = SF_GRAIN; w = (n/w)*w; } #ifdef NO_OFLAGS /* simulate append mode */ if(f->flags&SF_APPEND) f->here = SEEKF(seekf,f,0L,2,handle); else /* not really dangling */ #endif if(f->flags&SF_SHARE) f->here = SEEKF(seekf,f,f->here,0,handle); if((w = WRITEF(writef,f,s,w,handle)) > 0) { /* successful write */ f->here += w; s += w; if((n -= w) <= 0) goto done; } else { /* a write exception occured */ at_eof : switch(_sfexcept(f,SF_WRITE,w)) { case SF_EDISC : case SF_ESTACK : SFopen(f); goto redo_loop; case SF_EDONE : goto done; default : if(f->mode&SF_STRING) goto set_copy; else continue; } } } /* prepare to copy data into buffer */ set_copy: data = f->next; if((w = f->endb - data) > n) w = n; } done : SFOPEN(f); if(line_fls && f->next > f->data) _sfflsbuf(f,-1); return s-begs; } 0707070000000003141006440044230044230000010000000475242176100003300000000153stdio/sprintf.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" #undef sprintf #define _stdsprintf sprintf #include "stdsprintf.c" 0707070000000003151006440044230044230000010000000473126373400003300000000474stdio/stdgets.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" /* Stdio gets() ** ** Written by Kiem-Phong Vo (12/10/90) */ #if __STDC__ || __cplusplus char *_stdgets(reg char *s, reg int n) #else char *_stdgets(s,n) reg char *s; reg int n; #endif { if(!s || sfgets(sfstdin,s,n) != s) return NIL(char*); s[_Sfi--] = '\0'; return s; } 0707070000000003161006440044230044230000010000000473126376300003500000000652stdio/stdprintf.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" /* printf function ** ** Written by Kiem-Phong Vo (12/10/90) */ #if __STDC__ || __cplusplus _stdprintf(const char *form, ...) #else _stdprintf(form,va_alist) reg char *form; /* print format */ va_dcl #endif { va_list args; reg int rv; #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvprintf(sfstdout,form,args); va_end(args); return rv; } 0707070000000003171006440044230044230000010000000473227016700003400000000671stdio/stdscanf.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" /* Read formatted data from a stream ** ** Written by Kiem-Phong Vo (06/27/90) */ #if __STDC__ || __cplusplus _stdscanf(const char *form, ...) #else _stdscanf(form,va_alist) reg char *form; /* scanning format */ va_dcl #endif { va_list args; reg int rv; #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvscanf(sfstdin,form,args); va_end(args); return rv; } 0707070000000003201006440044230044230000010000000475414265500003600000001066stdio/stdsetvbuf.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" /* Stdio function setvbuf() ** ** Written by Kiem-Phong Vo (12/10/90) */ #if __STDC__ || __cplusplus _stdsetvbuf(Sfile_t* f, char *buf, int type, int size) #else _stdsetvbuf(f,buf,type,size) Sfile_t *f; char *buf; int type; int size; #endif { if(type == _IOLBF) sfset(f,SF_LINE,1); else if((f->flags&SF_STRING)) return -1; else if(type == _IONBF) { sfsync(f); sfsetbuf(f,NIL(uchar*),0); } else if(type == _IOFBF) { if(size == 0) size = SF_BUFSIZE; sfsync(f); sfsetbuf(f,(uchar*)buf,size); } return 0; } 0707070000000003211006440044230044230000010000000475414267000003600000001316stdio/stdsprintf.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" /* sprintf function ** ** Written by Kiem-Phong Vo (12/10/90) */ #if __STDC__ || __cplusplus _stdsprintf(char *s, const char *form, ...) #else _stdsprintf(s,form,va_alist) reg char *s; reg char *form; va_dcl #endif { va_list args; Sfile_t f; reg int rv; if(!s) return -1; /* make a fake stream */ SFCLEAR(&f); f.flags = SF_STRING|SF_WRITE; f.mode = SF_STRING; f.size = 4*SF_BUFSIZE; f.data = f.next = f.endr = (uchar*)s; f.endb = f.endw = f.data+f.size; sfset(&f,f.flags,1); #if __STDC__ || __cplusplus va_start(args,form); #else va_start(args); #endif rv = sfvprintf(&f,form,args); *f.next = '\0'; _Sfi = f.next - f.data; va_end(args); return rv; } 0707070000000003221006440044230044230000010000000475414270100003700000001041stdio/stdvsprintf.c Ugsf Ggsf #include "sfhdr.h" #if __STDC__ || __cplusplus _stdvsprintf(char *s, const char *form, va_list args) #else _stdvsprintf(s,form,args) register char *s; register char *form; va_list args; #endif { Sfile_t f; reg int rv; if(!s) return -1; /* make a fake stream */ SFCLEAR(&f); f.flags = SF_STRING|SF_WRITE; f.mode = SF_STRING; f.size = 4*SF_BUFSIZE; f.data = f.next = f.endr = (uchar*)s; f.endb = f.endw = f.data+f.size; sfset(&f,f.flags,1); rv = sfvprintf(&f,form,args); *f.next = '\0'; _Sfi = f.next - f.data; return rv; } 0707070000000003231006440044230044230000010000000475414271000003600000000754stdio/stdvsscanf.c Ugsf Ggsf #include "sfhdr.h" #if __STDC__ || __cplusplus _stdvsscanf(char *s, const char *form, va_list args) #else _stdvsscanf(s,form,args) register char *s; register char *form; va_list args; #endif { Sfile_t f; reg int rv; if(!s) return -1; /* make a fake stream */ SFCLEAR(&f); f.flags = SF_STRING|SF_READ; f.mode = SF_STRING; f.size = strlen((char*)s); f.data = f.next = f.endr = (uchar*)s; f.endb = f.endw = f.data+f.size; sfset(&f,f.flags,1); return sfvscanf(&f,form,args); } 0707070000000003241006440044230044230000010000000475242201400003400000000157stdio/vsprintf.c Ugsf Ggsf #include "sfhdr.h" #include "stdio.h" #undef vsprintf #define _stdvsprintf vsprintf #include "stdvsprintf.c" 0707070000000003251006440044230044230000010000000417047315600003300000002753string/chresc.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return the next character in the string s * \ character constants are converted * p is updated to point to the next character in s */ int chresc(s, p) register char* s; char** p; { register char* q; register int c; switch (c = *s++) { case 0: return(0); case '\\': switch (c = *s++) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': c -= '0'; q = s + 2; while (s < q) switch (*s) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': c = (c << 3) + *s++ - '0'; break; default: q = s; break; } break; case 'a': c = '\007'; break; case 'b': c = '\b'; break; case 'f': c = '\f'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = '\013'; break; case 'x': c = 0; q = s; while (q) switch (*s) { case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': c = (c << 4) + *s++ - 'a' + 10; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': c = (c << 4) + *s++ - 'A' + 10; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': c = (c << 4) + *s++ - '0'; break; default: q = 0; break; } break; case 'E': c = '\033'; break; case 0: s--; break; } break; } if (p) *p = s; return(c); } 0707070000000003261006440044230044230000010000000414141332000003100000000756string/ctoi.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * convert a 0 terminated character constant string to an int */ #include <limits.h> extern int chresc(/* char* string, char** next */); int ctoi(s) register char* s; { register int c; register int n; register int x; char* p; c = 0; for (n = 0; n < sizeof(int) * CHAR_BIT; n += CHAR_BIT) { switch (x = *s++) { case '\\': x = chresc(s - 1, &p); s = p; break; case 0: return(c); } c |= x << n; } return(c); } 0707070000000003271006440044230044230000010000000474114302000003700000001560string/fmtelapsed.c Ugsf Ggsf /* * return pointer to formatted elapsed time for t 1/n secs * compatible with strelapsed() * 8 consecutive calls before overwrite * return value length is at most 6 */ #include <stdio.h> #define elements(x) (sizeof(x)/sizeof(x[0])) char* fmtelapsed(t, n) register unsigned long t; register int n; { register unsigned long s; static int amt[] = { 1, 60, 60, 24, 7, 4, 12, 20 }; static char chr[] = "smhdwMYS"; static char tms[8][7]; static int tm; if (t == 0L) return("0"); if (t == ~0L) return("%"); if (++tm >= elements(tms)) tm = 0; s = t / n; if (s < 60) (void)sprintf(tms[tm], "%d.%02ds", s % 100, (t * 100 / n) % 100); else { for (n = 1; n < elements(amt) - 1; n++) { if ((t = s / amt[n]) < amt[n + 1]) break; s = t; } (void)sprintf(tms[tm], "%d%c%02d%c", (s / amt[n]) % 100, chr[n], s % amt[n], chr[n - 1]); } return(tms[tm]); } 0707070000000003301006440044230044230000010000000474560131600003300000001453string/fmtgid.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * gid number -> name */ #include <stdio.h> #include <hash.h> #define getgrgid _SYS_getgrgid #include <grp.h> #undef getgrgid extern char* strdup(); extern struct group* getgrgid(); /* * return gid name given gid number */ char* fmtgid(gid) int gid; { register char* name; register struct group* gr; static HASHTABLE* gidtab; static char buf[sizeof(int) * 3 + 1]; if (!gidtab && !(gidtab = hashalloc((HASHTABLE*)0, HASH_set, HASH_ALLOCATE, HASH_namesize, sizeof(gid), HASH_name, "gidnum", 0))) (void)sprintf(name = buf, "%d", gid); else if (!(name = hashget(gidtab, &gid))) { if (gr = getgrgid(gid)) name = gr->gr_name; else (void)sprintf(name = buf, "%d", gid); (void)hashput(gidtab, (char*)0, name = strdup(name)); } return(name); } 0707070000000003311006440044230044230000010000000475445730400003200000004325string/fmtls.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * ls formatter */ #include <ls.h> #include <tm.h> #include <stdio.h> #ifndef S_IFLNK #define S_IFLNK 0120000 #endif extern char* fmtmode(); extern char* fmtuid(); extern char* fmtgid(); /* * ls formatter * * buf results placed here * name file name * st file stat buffer * info optional info * link link text if != 0 * flags LS_* flags * * return end of formatted buf */ #if __STDC__ || __cplusplus char* fmtls(char* buf, const char* name, register struct stat* st, const char* info, const char* link, register int flags) #else char* fmtls(buf, name, st, info, link, flags) char* buf; char* name; register struct stat* st; char* info; char* link; register int flags; #endif { register char* s; time_t tm; s = buf; if (flags & LS_INUMBER) { (void)sprintf(s, "%*lu ", LS_W_INUMBER - 1, (unsigned long)st->st_ino); while (*++s); } if (flags & LS_BLOCKS) { (void)sprintf(s, "%*lu ", LS_W_BLOCKS - 1, (unsigned long)tblocks(st)); while (*++s); } if (flags & LS_LONG) { (void)sprintf(s, "%s%3u", fmtmode(st->st_mode), (unsigned int)st->st_nlink); while (*++s); if (!(flags & LS_NOUSER)) { (void)sprintf(s, " %-*s", LS_W_NAME - 1, fmtuid(st->st_uid)); while (*++s); } if (!(flags & LS_NOGROUP)) { (void)sprintf(s, " %-*s", LS_W_NAME - 1, fmtgid(st->st_gid)); while (*++s); } switch (st->st_mode & S_IFMT) { case S_IFBLK: case S_IFCHR: (void)sprintf(s, " %3u,%3u ", (unsigned int)major(st->st_rdev), (unsigned int)minor(st->st_rdev)); break; default: (void)sprintf(s, "%8lu ", (unsigned long)st->st_size); break; } while (*++s); tm = (flags & LS_ATIME) ? st->st_atime : (flags & LS_CTIME) ? st->st_ctime : st->st_mtime; s = tmform(s, "%?%l", &tm); *s++ = ' '; } if (info) { while (*s = *info++) s++; *s++ = ' '; } while (*s = *name++) s++; if (flags & LS_MARK) switch (st->st_mode & S_IFMT) { case S_IFDIR: *s++ = '/'; break; case S_IFLNK: *s++ = '@'; break; case S_IFREG: if (st->st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) *s++ = '*'; break; } if (link) { (void)sprintf(s, " %s %s", (st->st_mode & S_IFMT) == S_IFLNK ? "->" : "==", link); while (*++s); } *s = 0; return(s); } 0707070000000003321006440044230044230000010000000462626300400003400000000642string/fmtmode.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return ls -l style file mode string given file mode bits */ #include "modelib.h" char* fmtmode(mode) register int mode; { register char* s; register struct modeop* p; static char buf[MODELEN + 1]; s = buf; for (p = modetab; p < &modetab[MODELEN]; p++) *s++ = p->name[((mode & p->mask1) >> p->shift1) | ((mode & p->mask2) >> p->shift2)]; return(buf); } 0707070000000003331006440044230044230000010000000474537706700003400000004557string/fmtperm.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return strperm() expression for perm */ #include <ls.h> char* fmtperm(perm) register int perm; { register char* s; register char* p; char* o; static char buf[32]; s = buf; /* * ugo */ p = s; *s++ = '+'; o = s; if (perm & S_ISVTX) *s++ = 't'; if ((perm & (S_ISUID|S_ISGID)) == (S_ISUID|S_ISGID)) { perm &= ~(S_ISUID|S_ISGID); *s++ = 's'; } if ((perm & (S_IRUSR|S_IRGRP|S_IROTH)) == (S_IRUSR|S_IRGRP|S_IROTH)) { perm &= ~(S_IRUSR|S_IRGRP|S_IROTH); *s++ = 'r'; } if ((perm & (S_IWUSR|S_IWGRP|S_IWOTH)) == (S_IWUSR|S_IWGRP|S_IWOTH)) { perm &= ~(S_IWUSR|S_IWGRP|S_IWOTH); *s++ = 'w'; } if ((perm & (S_IXUSR|S_IXGRP|S_IXOTH)) == (S_IXUSR|S_IXGRP|S_IXOTH)) { perm &= ~(S_IXUSR|S_IXGRP|S_IXOTH); *s++ = 'x'; } if (s == o) s = p; /* * ug */ p = s; if (s > buf) *s++ = ','; *s++ = 'u'; *s++ = 'g'; *s++ = '+'; o = s; if ((perm & (S_IRUSR|S_IRGRP)) == (S_IRUSR|S_IRGRP)) { perm &= ~(S_IRUSR|S_IRGRP); *s++ = 'r'; } if ((perm & (S_IWUSR|S_IWGRP)) == (S_IWUSR|S_IWGRP)) { perm &= ~(S_IWUSR|S_IWGRP); *s++ = 'w'; } if ((perm & (S_IXUSR|S_IXGRP)) == (S_IXUSR|S_IXGRP)) { perm &= ~(S_IXUSR|S_IXGRP); *s++ = 'x'; } if (s == o) s = p; /* * u */ p = s; if (s > buf) *s++ = ','; *s++ = 'u'; *s++ = '+'; o = s; if (perm & S_ISUID) *s++ = 's'; if (perm & S_IRUSR) *s++ = 'r'; if (perm & S_IWUSR) *s++ = 'w'; if (perm & S_IXUSR) *s++ = 'x'; if (s == o) s = p; /* * go */ p = s; if (s > buf) *s++ = ','; *s++ = 'g'; *s++ = 'o'; *s++ = '+'; o = s; if ((perm & (S_IRGRP|S_IROTH)) == (S_IRGRP|S_IROTH)) { perm &= ~(S_IRGRP|S_IROTH); *s++ = 'r'; } if ((perm & (S_IWGRP|S_IWOTH)) == (S_IWGRP|S_IWOTH)) { perm &= ~(S_IWGRP|S_IWOTH); *s++ = 'w'; } if ((perm & (S_IXGRP|S_IXOTH)) == (S_IXGRP|S_IXOTH)) { perm &= ~(S_IXGRP|S_IXOTH); *s++ = 'x'; } if (s == o) s = p; /* * g */ p = s; if (s > buf) *s++ = ','; *s++ = 'g'; *s++ = '+'; o = s; if (perm & S_ISGID) *s++ = 's'; if (perm & S_IRGRP) *s++ = 'r'; if (perm & S_IWGRP) *s++ = 'w'; if (perm & S_IXGRP) *s++ = 'x'; if (s == o) s = p; /* * o */ p = s; if (s > buf) *s++ = ','; *s++ = 'o'; *s++ = '+'; o = s; if (perm & S_IROTH) *s++ = 'r'; if (perm & S_IWOTH) *s++ = 'w'; if (perm & S_IXOTH) *s++ = 'x'; if (s == o) s = p; if (s == buf) *s++ = '0'; *s = 0; return(buf); } 0707070000000003341006440044230044230000010000000474560133300003300000001455string/fmtuid.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * uid number -> name */ #include <stdio.h> #include <hash.h> #define getpwuid _SYS_getpwuid #include <pwd.h> #undef getpwuid extern char* strdup(); extern struct passwd* getpwuid(); /* * return uid name given uid number */ char* fmtuid(uid) int uid; { register char* name; register struct passwd* pw; static HASHTABLE* uidtab; static char buf[sizeof(int) * 3 + 1]; if (!uidtab && !(uidtab = hashalloc((HASHTABLE*)0, HASH_set, HASH_ALLOCATE, HASH_namesize, sizeof(uid), HASH_name, "uidnum", 0))) (void)sprintf(name = buf, "%d", uid); else if (!(name = hashget(uidtab, &uid))) { if (pw = getpwuid(uid)) name = pw->pw_name; else (void)sprintf(name = buf, "%d", uid); (void)hashput(uidtab, (char*)0, name = strdup(name)); } return(name); } 0707070000000003351006440044230044230000010000000475445740200003400000001123string/gethalf.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * internal representation conversion support */ #include <swap.h> #include <limits.h> /* * construct a short from buffer p according to swap op {BYTE,HALF} */ #define GETHALF(p,B0,B1) ((p[B0]<<(CHAR_BIT))|(p[B1])) #if __STDC__ || __cplusplus int gethalf(register int op, const char* p) #else int gethalf(op, p) register int op; char* p; #endif { register unsigned char* b; b = (unsigned char*)p; switch (op) { case 0: case HALF: return(GETHALF(b, 0, 1)); case BYTE: case BYTE|HALF: return(GETHALF(b, 1, 0)); } return(0); } 0707070000000003361006440044230044230000010000000475445754300003400000001366string/getlong.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * internal representation conversion support */ #include <swap.h> #include <limits.h> /* * construct a long from buffer p according to swap op {HALF,LONG} */ #define GETLONG(p,B0,B1,B2,B3) ((((long)p[B0])<<(CHAR_BIT*3))|(((long)p[B1])<<(CHAR_BIT*2))|(((long)p[B2])<<(CHAR_BIT))|(((long)p[B3]))) #if __STDC__ || __cplusplus long getlong(register int op, const char* p) #else long getlong(op, p) register int op; char* p; #endif { register unsigned char* b; b = (unsigned char*)p; switch (op) { case 0: return(GETLONG(b, 0, 1, 2, 3)); case BYTE: return(GETLONG(b, 1, 0, 3, 2)); case HALF: return(GETLONG(b, 2, 3, 0, 1)); case BYTE|HALF: return(GETLONG(b, 3, 2, 1, 0)); } return(0); } 0707070000000003371006440044230044230000010000000441570120400003300000000461string/memdup.c Ugsf Ggsf #include "FEATURE/memdup" #ifdef _lib_memdup int _lib_dummy; #else /* * return a copy of s of n chars using malloc */ extern char* malloc(); extern char* memcpy(); char* memdup(s, n) register char* s; register int n; { register char* t; return((t = malloc(n)) ? memcpy(t, s, n) : 0); } #endif 0707070000000003401006440044230044230000010000000445376040600003400000001455string/memswap.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * internal representation conversion support */ #include <swap.h> /* * swap buffer b of n bytes according to swap op {BYTE,HALF} in place */ char* memswap(op, b, n) int op; char* b; register int n; { register char* p; register int c; p = b; switch (op) { case BYTE: n = (n + 1) / 2; while (n--) { c = *p; *p = *(p + 1); *(p + 1) = c; p += 2; } break; case HALF: n = (n + 3) / 4; while (n--) { c = *p; *p = *(p + 2); *(p + 2) = c; c = *(p + 3); *(p + 3) = *(p + 1); *(p + 1) = c; p += 4; } break; case BYTE|HALF: n = (n + 3) / 4; while (n--) { c = *p; *p = *(p + 3); *(p + 3) = c; c = *(p + 1); *(p + 1) = *(p + 2); *(p + 2) = c; p += 4; } break; } return(b); } 0707070000000003411006440044230044230000010000000462626502300003500000001340string/modedata.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * fmtmode() and strperm() readonly data */ #include "modelib.h" #include <sys/types.h> #include <sys/stat.h> struct modeop modetab[MODELEN] = { 0170000, 12, 0000000, 0, "?pc?d?b?-Cl?s???", 0000400, 8, 0000000, 0, "-r", 0000200, 7, 0000000, 0, "-w", 0004000, 10, 0000100, 6, "-xSs", 0000040, 5, 0000000, 0, "-r", 0000020, 4, 0000000, 0, "-w", #ifdef S_ICCTYP 0003000, 8, 0000010, 3, "-x-xSs-x", #else #ifdef S_ENFMT 0002000, 9, 0000010, 3, "-xls", #else 0002000, 9, 0000010, 3, "-xSs", #endif #endif 0000004, 2, 0000000, 0, "-r", 0000002, 1, 0000000, 0, "-w", #ifdef S_ICCTYP 0003000, 8, 0000001, 0, "-xyY-xeE", #else 0001000, 8, 0000001, 0, "-xTt", #endif }; 0707070000000003421006440044230044230000010000000462626505100003400000001010string/modelib.h Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * fmtmode() and strperm() common definitions */ #ifndef __LIBMODE_H__ #define __LIBMODE_H__ #define MODELEN 10 #define modetab _mode_table_ /* data hiding */ struct modeop /* ops for each char in mode string */ { int mask1; /* first mask */ int shift1; /* first shift count */ int mask2; /* second mask */ int shift2; /* second shift count */ char* name; /* mode char using mask/shift as index */ }; extern struct modeop modetab[]; #endif 0707070000000003431006440044230044230000010000000434221053700003400000000735string/puthalf.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * internal representation conversion support */ #include <swap.h> #include <limits.h> /* * put a short into buffer p according to swap op {HALF,LONG} */ #define PUTHALF(p,n,B0,B1) (p[B0]=n>>(CHAR_BIT),p[B1]=n) void puthalf(op, p, n) register int op; register char* p; register int n; { switch (op) { case 0: case HALF: PUTHALF(p, n, 0, 1); break; case BYTE: case BYTE|HALF: PUTHALF(p, n, 1, 0); break; } } 0707070000000003441006440044230044230000010000000434221037400003400000001147string/putlong.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * internal representation conversion support */ #include <swap.h> #include <limits.h> /* * put a long into buffer p according to swap op {HALF,LONG} */ #define PUTLONG(p,n,B0,B1,B2,B3) (p[B0]=n>>(CHAR_BIT*3),p[B1]=n>>(CHAR_BIT*2),p[B2]=n>>(CHAR_BIT),p[B3]=n) void putlong(op, p, n) register int op; register char* p; register long n; { switch (op) { case 0: PUTLONG(p, n, 0, 1, 2, 3); break; case BYTE: PUTLONG(p, n, 1, 0, 3, 2); break; case HALF: PUTLONG(p, n, 2, 3, 0, 1); break; case BYTE|HALF: PUTLONG(p, n, 3, 2, 1, 0); break; } } 0707070000000003451006440044230044230000010000000414141335100003400000000266string/strcopy.c Ugsf Ggsf /* * copy t into s, return a pointer to the end of s ('\0') */ char* strcopy(s, t) register char* s; register char* t; { if (!t) return(s); while (*s++ = *t++); return(--s); } 0707070000000003461006440044230044230000010000000441570121100003300000000512string/strdup.c Ugsf Ggsf #include "FEATURE/strdup" #ifdef _lib_strdup int _lib_dummy; #else /* * return a copy of s using malloc */ extern char* malloc(); extern char* memcpy(); extern int strlen(); char* strdup(s) register char *s; { register char* t; register int n; return((t = malloc(n = strlen(s) + 1)) ? memcpy(t, s, n) : 0); } #endif 0707070000000003471006440044230044230000010000000462647553000003700000001663string/strelapsed.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * parse elapsed time in 1/n secs from s * compatible with fmtelapsed() * if e!=0 then it is set to first unrecognized char */ #include <ctype.h> unsigned long strelapsed(s, e, n) register char* s; char** e; int n; { register int c; register unsigned long v; unsigned long t = 0; int f = 0; int m; char* last; while (isspace(*s)) s++; while (*(last = s)) { v = 0; while ((c = *s++) >= '0' && c <= '9') v = v * 10 + c - '0'; v *= n; if (c == '.') for (m = n; (c = *s++) >= '0' && c <= '9';) f += (m /= 10) * (c - '0'); switch (c) { case 'S': v *= 20; case 'Y': v *= 12; case 'M': v *= 4; case 'w': v *= 7; case 'd': v *= 24; case 'h': v *= 60; case 'm': v *= 60; break; case '0': s--; case 's': v += f; f = 0; break; default: goto done; } t += v; } done: if (e) *e = last; return(t); } 0707070000000003501006440044230044230000010000000475335032200003500000001032string/strerror.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return error message string given errno */ #include "FEATURE/strerror" #ifdef _lib_strerror int _lib_dummy; #else /* * the define/undef makes the non-macro sprintf visible below (huh?) */ #define _stdsprintf sprintf #include <stdio.h> #undef sprintf char* strerror(err) int err; { static char msg[28]; extern int sys_nerr; extern char* sys_errlist[]; if (err > 0 && err <= sys_nerr) return(sys_errlist[err]); (void)sprintf(msg, "Error %d", err); return(msg); } #endif 0707070000000003511006440044230044230000010000000414141276200003300000000745string/stresc.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * convert \x character constants in s in place * the length of the converted s is returned (may have imbedded \0's) */ extern int chresc(/* char* string, char** next */); int stresc(s) register char* s; { register char* t; register int c; char* b; char* p; b = t = s; for (;;) { switch (c = *s++) { case '\\': c = chresc(s - 1, &p); s = p; break; case 0: *t = 0; return(t - b); } *t++ = c; } } 0707070000000003521006440044230044230000010000000466675504700003400000011764string/streval.c Ugsf Ggsf /* * G. S. Fowler * D. G. Korn * AT&T Bell Laboratories * * long integer arithmetic expression evaluator * long constants may be represented as: * * 0ooo octal * 0[xX]hhh hexadecimal * ddd decimal * n#ccc base n, 2 <= b <= 36 * * NOTE: all operands are evaluated as both the parse * and evaluation are done on the fly */ #include <ctype.h> #define getchr() (*cur.nextchr++) #define peekchr() (*cur.nextchr) #define ungetchr() (cur.nextchr--) #define pushchr(s) {struct vars old;old=cur;cur.nextchr=(s);cur.errmsg=0 #define popchr() cur=old;} #define error(msg) return(seterror(msg)) struct vars /* vars stacked per invocation */ { char* nextchr; /* next char in current expression */ char* errchr; /* next char after error */ char* errmsg; /* error message text */ }; static struct vars cur; static long (*convert)(); /* external conversion routine */ static long expr(); /* subexpression evaluator */ static long seterror(); /* set error message string */ extern long strton(); /* * evaluate an integer arithmetic expression in s * * (long)(*convert)(char* string, char** end) is a user supplied * conversion routine that is called when unknown chars are encountered * in s string points to the part to be converted and end is adjusted to * point to the next non-converted character; if string is 0 then end * points to an error message string * * NOTE: (*convert)() may call streval() */ long streval(s, end, conv) char* s; char** end; long (*conv)(); { long n; pushchr(s); convert = conv; n = expr(0); if (peekchr() == ':') (void)seterror("invalid use of :"); if (cur.errmsg) { if (convert) (void)(*convert)((char*)0, &cur.errmsg); cur.nextchr = cur.errchr; n = 0; } if (end) *end = cur.nextchr; popchr(); return(n); } /* * evaluate a subexpression with precedence */ static long expr(precedence) register int precedence; { register int c; register long n; register long x; char* pos; int operand = 1; while (isspace(c = getchr())); switch (c) { case 0: ungetchr(); error("more tokens expected"); case '-': n = -expr(12); break; case '+': n = expr(12); break; case '!': n = !expr(12); break; case '~': n = ~expr(12); break; default: ungetchr(); n = 0; operand = 0; break; } for (;;) { switch (c = getchr()) { case 0: goto done; case ')': if (!precedence) error("too many )'s"); goto done; case '(': n = expr(1); if (getchr() != ')') { ungetchr(); error("closing ) expected"); } gotoperand: if (operand) error("operator expected"); operand = 1; continue; case '?': if (precedence > 1) goto done; if (peekchr() == ':') { getchr(); x = expr(2); if (!n) n = x; } else { x = expr(2); if (getchr() != ':') { ungetchr(); error(": expected for ? operator"); } if (n) { n = x; (void)expr(2); } else n = expr(2); } break; case ':': goto done; case '|': if (peekchr() == '|') { if (precedence > 2) goto done; getchr(); x = expr(3); n = n || x; } else { if (precedence > 3) goto done; x = expr(4); n |= x; } break; case '^': if (precedence > 4) goto done; x = expr(5); n ^= x; break; case '&': if (peekchr() == '&') { if (precedence > 2) goto done; getchr(); x = expr(3); n = n && x; } else { if (precedence > 5) goto done; x = expr(6); n &= x; } break; case '=': case '!': if (peekchr() != '=') error("operator syntax error"); if (precedence > 6) goto done; getchr(); x = expr(7); if (c == '=') n = n == x; else n = n != x; break; case '<': case '>': if (peekchr() == c) { if (precedence > 8) goto done; getchr(); x = expr(9); if (c == '<') n <<= x; else n >>= x; } else { if (precedence > 7) goto done; if (peekchr() == '=') { getchr(); x = expr(8); if (c == '<') n = n <= x; else n = n >= x; } else { x = expr(8); if (c == '<') n = n < x; else n = n > x; } } break; case '+': case '-': if (precedence > 9) goto done; x = expr(10); if (c == '+') n += x; else n -= x; break; case '*': case '/': case '%': if (precedence > 10) goto done; x = expr(11); if (c == '*') n *= x; else if (x == 0) error("divide by zero"); else if (c == '/') n /= x; else n %= x; break; default: if (isspace(c)) continue; pos = --cur.nextchr; if (isdigit(c)) n = strton(cur.nextchr, &cur.nextchr, 0); else if (convert) n = (*convert)(cur.nextchr, &cur.nextchr); if (cur.nextchr == pos) error("syntax error"); goto gotoperand; } if (cur.errmsg) return(0); if (!operand) error("operand expected"); } done: ungetchr(); if (!operand) error("operand expected"); return(n); } /* * set error message string */ static long seterror(msg) char* msg; { if (!cur.errmsg) cur.errmsg = msg; cur.errchr = cur.nextchr; cur.nextchr = ""; return(0); } 0707070000000003531006440044230044230000010000000474561126300003300000002131string/strgid.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * gid name -> number */ #include <hash.h> #define getpwnam _SYS_getpwnam #define getgrnam _SYS_getgrnam #include <pwd.h> #include <grp.h> #undef getpwnam #undef getgrnam extern struct passwd* getpwnam(); extern struct group* getgrnam(); typedef struct { HASH_HEADER; int id; } bucket; /* * return gid number given gid/uid name * gid attempted first, then uid->pw_gid * -1 on first error for a given name * -2 on subsequent errors for a given name */ int strgid(name) char* name; { register struct group* gr; register struct passwd* pw; register bucket* b; static HASHTABLE* gidtab; if (!gidtab && !(gidtab = hashalloc((HASHTABLE*)0, HASH_set, HASH_ALLOCATE, HASH_name, "gidnam", 0))) return(-1); if (b = (bucket*)hashlook(gidtab, name, HASH_LOOKUP|HASH_FIXED, (char*)sizeof(bucket))) return(b->id); if (!(b = (bucket*)hashlook(gidtab, (char*)0, HASH_CREATE|HASH_FIXED, (char*)sizeof(bucket)))) return(-1); if (gr = getgrnam(name)) return(b->id = gr->gr_gid); if (pw = getpwnam(name)) return(b->id = pw->pw_gid); b->id = -2; return(-1); } 0707070000000003541006440044230044230000010000000472462027300003500000017615string/strmatch.c Ugsf Ggsf /* * D. G. Korn * G. S. Fowler * AT&T Bell Laboratories * * match shell file patterns -- derived from Bourne and Korn shell gmatch() * * sh pattern egrep RE description * ---------- -------- ----------- * * .* 0 or more chars * ? . any single char * [.] [.] char class * [!.] [^.] negated char class * [[:.:]] [[:.:]] ctype class * [[=.=]] [[=.=]] equivalence class * *(.) (.)* 0 or more of * +(.) (.)+ 1 or more of * ?(.) (.)? 0 or 1 of * (.) (.) 1 of * @(.) (.) 1 of * a|b a|b a or b * a&b a and b * !(.) none of * * \ used to escape metacharacters * * *, ?, (, |, &, ), [, \ must be \'d outside of [...] * only ] must be \'d inside [...] * * BUG: unbalanced ) terminates top level pattern */ #include <ctype.h> #ifndef isequiv #define isequiv(a,s) ((a)==(s)) #endif #ifndef isxdigit #define isxdigit(c) ((c)>='0'&&(c)<='9'||(c)>='a'&&(c)<='f'||(c)>='A'&&(c)<='F') #endif #define CODE(n,c1,c2,c3,c4,c5) (((n)<<25)|(((c1)-'a')<<20)|(((c2)-'a')<<15)|(((c3)-'a')<<10)|(((c4)-'a')<<5)|((c5)-'a')) #ifdef MULTIBYTE #include "national.h" #define REGISTER #define C_MASK (3<<(7*ESS_MAXCHAR)) /* character classes */ #define getchar(x) mb_getchar((unsigned char**)(&(x))) static int mb_getchar(); #else #define REGISTER register #define getchar(x) (*x++) #endif #define getsource(s,e) (((s)>=(e))?0:getchar(s)) static char* endmatch; static int minmatch; static int grpmatch(); static int onematch(); static char* gobble(); /* * strmatch compares the string s with the shell pattern p * returns 1 for match 0 otherwise */ int strmatch(s, p) register char* s; char* p; { minmatch = 0; return(grpmatch(s, p, s + strlen(s), (char*)0)); } /* * leading substring match * first char after end of substring returned * 0 returned if no match * m: (0-min, 1-max) match */ char* submatch(s, p, m) register char* s; char* p; int m; { endmatch = 0; minmatch = !m; (void)grpmatch(s, p, s + strlen(s), (char*)0); return(endmatch); } /* * match any pattern in a group * | and & subgroups are parsed here */ static int grpmatch(s, p, e, g) char* s; register char* p; char* e; char* g; { register char* a; do { a = p; do { if (!onematch(s, a, e, g)) break; } while (a = gobble(a, '&')); if (!a) return(1); } while (p = gobble(p, '|')); return(0); } /* * match a single pattern * e is the end (0) of the substring in s * g marks the start of a repeated subgroup pattern */ static int onematch(s, p, e, g) char* s; REGISTER char* p; char* e; char* g; { register int pc; register int sc; register int n; char* olds; char* oldp; do { olds = s; sc = getsource(s, e); switch (pc = getchar(p)) { case '(': case '*': case '?': case '+': case '@': case '!': if (pc == '(' || *p == '(') { char* subp; s = olds; oldp = p - 1; subp = p + (pc != '('); if (!(p = gobble(subp, 0))) return(0); if (pc == '*' || pc == '?' || pc == '+' && oldp == g) { if (onematch(s, p, e, (char*)0)) return(1); if (!sc || !getsource(s, e)) return(0); } if (pc == '*' || pc == '+') p = oldp; pc = (pc != '!'); do { if (grpmatch(olds, subp, s, (char*)0) == pc && onematch(s, p, e, oldp)) return(1); } while (s < e && getchar(s)); return(0); } else if (pc == '*') { /* * several stars are the same as one */ while (*p == '*') if (*(p + 1) == '(') break; else p++; oldp = p; switch (pc = getchar(p)) { case '@': case '!': case '+': n = *p == '('; break; case '(': case '[': case '?': case '*': n = 1; break; case 0: endmatch = minmatch ? olds : e; /*FALLTHROUGH*/ case '|': case '&': case ')': return(1); case '\\': if (!(pc = getchar(p))) return(0); /*FALLTHROUGH*/ default: n = 0; break; } p = oldp; for (;;) { if ((n || pc == sc) && onematch(olds, p, e, (char*)0)) return(1); if (!sc) return(0); olds = s; sc = getsource(s, e); } } else if (pc != '?' && pc != sc) return(0); break; case 0: endmatch = olds; if (minmatch) return(1); /*FALLTHROUGH*/ case '|': case '&': case ')': return(!sc); case '[': { int ok = 0; int invert; n = 0; if (invert = *p == '!') p++; for (;;) { if (!(pc = getchar(p))) return(0); else if (pc == '[' && (*p == ':' || *p == '=')) { char* v; int x = 0; n = getchar(p); v = p; for (;;) { if (!(pc = getchar(p))) return(0); if (pc == n && *p == ']') break; x++; } pc = getchar(p); if (ok) /* skip */; else if (n == ':') switch (CODE(x, v[0], v[1], v[2], v[3], v[4])) { case CODE(5,'a','l','n','u','m'): if (isalnum(sc)) ok = 1; break; case CODE(5,'a','l','p','h','a'): if (isalpha(sc)) ok = 1; break; case CODE(5,'c','n','t','r','l'): if (iscntrl(sc)) ok = 1; break; case CODE(5,'d','i','g','i','t'): if (isdigit(sc)) ok = 1; break; case CODE(5,'g','r','a','p','h'): if (isgraph(sc)) ok = 1; break; case CODE(5,'l','o','w','e','r'): if (islower(sc)) ok = 1; break; case CODE(5,'p','r','i','n','t'): if (isprint(sc)) ok = 1; break; case CODE(5,'p','u','n','c','t'): if (ispunct(sc)) ok = 1; break; case CODE(5,'s','p','a','c','e'): if (isspace(sc)) ok = 1; break; case CODE(5,'u','p','p','e','r'): if (isupper(sc)) ok = 1; break; case CODE(6,'x','d','i','g','i'): if (v[5] != 't') return(0); if (isxdigit(sc)) ok = 1; break; default: return(0); } else { pc = getchar(v); if (isequiv(sc, pc)) ok = 1; } n = 1; } else if (pc == ']' && n) { if (ok != invert) break; return(0); } else if (pc == '-' && n && *p != ']') { if (!(pc = getchar(p)) || pc == '\\' && !(pc = getchar(p))) return(0); #ifdef MULTIBYTE /* * must be in same char set */ if ((n & C_MASK) != (pc & C_MASK)) { if (sc == pc) ok = 1; } else #endif if (sc >= n && sc <= pc || sc == pc) ok = 1; } else if (pc == '\\' && !(pc = getchar(p))) return(0); else { if (sc == pc) ok = 1; n = pc; } } } break; case '\\': if (!(pc = getchar(p))) return(0); /*FALLTHROUGH*/ default: if (pc != sc) return(0); break; } } while (sc); return(0); } /* * gobble chars up to <sub> or ) keeping track of (...) and [...] * sub must be one of { '|', '&', 0 } * 0 returned if s runs out */ static char* gobble(s, sub) register char* s; register int sub; { register int p = 0; register char* b = 0; for (;;) switch (getchar(s)) { case '\\': if (getchar(s)) break; /*FALLTHROUGH*/ case 0: return(0); case '[': if (!b) b = s; break; case ']': if (b && b != (s - 1)) b = 0; break; case '(': if (!b) p++; break; case ')': if (!b && p-- <= 0) return(sub ? 0 : s); break; case '&': if (!b && !p && sub == '&') return(s); break; case '|': if (!b && !p) { if (sub == '|') return(s); else if (sub == '&') return(0); } break; } } #ifdef MULTIBYTE /* * return the next char in (*address) which may be from one to three bytes * the character set designation is in the bits defined by C_MASK */ static int mb_getchar(address) unsigned char** address; { register unsigned char* cp = *(unsigned char**)address; register int c = *cp++; register int size; int d; if (size = echarset(c)) { d = (size == 1 ? c : 0); c = size; size = in_csize(c); c <<= 7 * (ESS_MAXCHAR - size); if (d) { size--; c = (c << 7) | (d & ~HIGHBIT); } while (size-- > 0) c = (c << 7) | ((*cp++) & ~HIGHBIT); } *address = cp; return(c); } #endif 0707070000000003551006440044230044230000010000000474537722500003400000000765string/strmode.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * return file mode bits given ls -l style file mode string */ #include "modelib.h" int strmode(s) register char* s; { register int c; register char* t; register struct modeop* p; int mode; mode = 0; for (p = modetab; (c = *s++) && p < &modetab[MODELEN]; p++) for (t = p->name; *t; t++) if (*t == c) { c = t - p->name; mode |= (p->mask1 & (c << p->shift1)) | (p->mask2 & (c << p->shift2)); break; } return(mode); } 0707070000000003561006440044230044230000010000000473411030000003300000002755string/stropt.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories */ #include <namval.h> #include <ctype.h> /* * parse option expression in s using options in tab * options match * * [no]name[=['"]value["']] ... * * f is called for each option * * (*f)(void* a, struct namval* p, int n, char* v) * * a from stropt * p matching tab entry * n 0 if option had ``no'' prefix * v option value pointer * * for unmatched options p has the sentinel tab value * * names in s may be shorter than tab names * longer names must have a prefix that matches a tab name * the first match is returned */ int stropt(s, tab, f, a) register char* s; struct namval* tab; int (*f)(); char* a; { register char* v; register char* t; struct namval* p; int c; int n; struct namval u; if (s) for (;;) { while (isspace(*s)) s++; if (*s == 'n' && *(s + 1) == 'o') { s += 2; n = 0; } else n = 1; if (!*s) break; for (p = tab; t = p->name; p++) { for (v = s; *t && *t++ == *v; v++); if (!*t || isspace(*v) || *v == '=') break; } if (!t) { u.name = v = s; u.value = p->value; p = &u; } while (*v && !isspace(*v) && *v != '=') v++; if (*v == '=') { if (t) t = 0; else *(t = v) = 0; s = ++v; if ((c = *s) != '"' && c != '\'') while (*s && !isspace(*s)) s++; else { v++; while (*++s && *s != c); } } else { s = v; t = 0; } c = *s; *s = 0; n = (*f)(a, p, n, v); if (*s = c) s++; if (t) *t = '='; if (n) return(n); } return(0); } 0707070000000003571006440044230044230000010000000462626317300003400000003714string/strperm.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * apply file permission expression expr to perm * * each expression term must match * * [ugoa]*[-&+|=]?[rwxst0-7]* * * terms may be combined using , * * if non-null, e points to the first unrecognized char in expr */ #include <ls.h> int strperm(expr, e, perm) char* expr; char** e; register int perm; { register int c; register int typ; register int who; int num; int op; for (;;) { op = num = who = typ = 0; for (;;) { switch (c = *expr++) { case 'u': who |= S_ISVTX|S_ISUID|S_IRWXU; continue; case 'g': who |= S_ISVTX|S_ISGID|S_IRWXG; continue; case 'o': who |= S_ISVTX|S_IRWXO; continue; case 'a': who = S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; continue; default: if (c >= '0' && c <= '7') c = '='; expr--; /*FALLTHROUGH*/ case '=': case '+': case '|': case '-': case '&': op = c; for (;;) { switch (c = *expr++) { case 'r': typ |= S_IRUSR|S_IRGRP|S_IROTH; continue; case 'w': typ |= S_IWUSR|S_IWGRP|S_IWOTH; continue; case 'x': typ |= S_IXUSR|S_IXGRP|S_IXOTH; continue; case 's': typ |= S_ISUID|S_ISGID; continue; case 't': typ |= S_ISVTX; continue; case ',': case 0: if (who) typ &= who; switch (op) { default: perm &= ~who; /*FALLTHROUGH*/ case '+': case '|': perm |= typ; break; case '-': perm &= ~typ; break; case '&': perm &= typ; break; } if (c) break; /*FALLTHROUGH*/ default: if (c < '0' || c > '7') { if (e) *e = expr - 1; return(perm); } num = (num <<= 3) | (c - '0'); if (*expr < '0' || *expr > '7') { typ |= num; num = 0; } continue; } break; } break; } break; } } } 0707070000000003601006440044230044230000010000000474114313700003600000001071string/strsignal.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * if sig>=0 then return signal text for signal sig * otherwise return signal name for signal -sig * * data defined in sigdata.c */ #include <stdio.h> extern int sig_max; extern char* sig_name[]; extern char* sig_text[]; char* strsignal(sig) register int sig; { static char buf[20]; if (sig >= 0) { if (sig <= sig_max) return(sig_text[sig]); (void)sprintf(buf, "Signal %d", sig); } else { sig = -sig; if (sig <= sig_max) return(sig_name[sig]); (void)sprintf(buf, "%d", sig); } return(buf); } 0707070000000003611006440044230044230000010000000474114315000003400000003572string/strtape.c Ugsf Ggsf /* * local device pathname for portable tape unit specification is returned * if e is non-null then it is set to the next unused char in s * * <unit><density>[<no-rewind>] * {0-7}[l,m,h][n] */ #include <stdio.h> char* strtape(s, e) register char* s; register char** e; { int mtunit; int mtdensity; char* mtrewind; static char tapefile[sizeof("/dev/Xrmt/XXX")]; switch (*s) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': mtunit = *s++; break; default: mtunit = '1'; break; } if (!access("/dev/rmt/.", 0)) { /* * system V */ switch (*s) { case 'l': case 'm': case 'h': mtdensity = *s++; break; default: mtdensity = 'm'; break; } switch (*s) { case 'n': mtrewind = "n"; s++; break; default: mtrewind = ""; break; } (void)sprintf(tapefile, "/dev/rmt/%c%c%s", mtunit, mtdensity, mtrewind); if (access(tapefile, 0)) (void)sprintf(tapefile, "/dev/rmt/ctape%c%s", mtunit, mtrewind); if (access(tapefile, 0)) (void)sprintf(tapefile, "/dev/rmt/%c%c%s", mtunit, mtdensity, mtrewind); } else if (!access("/dev/nrmt0", 0)) { /* * 9th edition */ switch (*s) { case 'l': mtunit = '0'; s++; break; case 'm': mtunit = '1'; s++; break; case 'h': mtunit = '2'; s++; break; } switch (*s) { case 'n': mtrewind = "n"; s++; break; default: mtrewind = ""; break; } (void)sprintf(tapefile, "/dev/%srmt%c", mtrewind, mtunit); } else { /* * BSD */ mtunit -= '0'; switch (*s) { case 'l': s++; break; case 'm': mtunit |= 010; s++; break; case 'h': mtunit |= 020; s++; break; default: mtunit |= 010; break; } switch (*s) { case 'n': mtunit |= 040; s++; break; } (void)sprintf(tapefile, "/dev/rmt%d", mtunit); } if (e) *e = s; return(tapefile); } 0707070000000003621006440044230044230000010000000466627672300003300000002331string/strton.c Ugsf Ggsf /* * AT&T Bell Laboratories * * convert string to long integer * if non-null e will point to first unrecognized char in s * if m>1 and no multipler was specified then the result is multiplied by m * * integer numbers are of the form: * * [sign][base][number][multiplier] * * base: nnn# base nnn * 0[xX] hex * 0 octal * [1-9] decimal * * number: [0-9a-zA-Z]* * * multiplier: . pseudo-float (100) + subsequent digits * [bB] block (512) * [cC] char (1) * [gG] giga (1024*1024*1024) * [kK] kilo (1024) * [mM] mega (1024*1024) */ long strton(s, e, m) register char* s; char** e; int m; { register long n; register int neg; char* p; extern long strtol(); if (neg = (n = strtol(s, &p, 0)) < 0) n = -n; if (*p == '#') n = strtol(++p, &p, n); switch (*p++) { case 'b': case 'B': n *= 512; break; case 'c': case 'C': break; case 'g': case 'G': n *= 1024 * 1024 * 1024; break; case 'k': case 'K': n *= 1024; break; case 'm': case 'M': n *= 1024 * 1024; break; case '.': n *= 100; for (m = 10; *p >= '0' && *p <= '9'; m /= 10) n += m * (*p++ - '0'); break; default: p--; if (m > 1) n *= m; break; } if (e) *e = p; return(neg ? -n : n); } 0707070000000003631006440044230044230000010000000474561124100003300000001570string/struid.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * uid name -> number */ #include <hash.h> #define getpwnam _SYS_getpwnam #include <pwd.h> #undef getpwnam extern struct passwd* getpwnam(); typedef struct { HASH_HEADER; int id; } bucket; /* * return uid number given uid name * -1 on first error for a given name * -2 on subsequent errors for a given name */ int struid(name) char* name; { register struct passwd* pw; register bucket* b; static HASHTABLE* uidtab; if (!uidtab && !(uidtab = hashalloc((HASHTABLE*)0, HASH_set, HASH_ALLOCATE, HASH_name, "uidnam", 0))) return(-1); if (b = (bucket*)hashlook(uidtab, name, HASH_LOOKUP|HASH_FIXED, (char*)sizeof(bucket))) return(b->id); if (!(b = (bucket*)hashlook(uidtab, (char*)0, HASH_CREATE|HASH_FIXED, (char*)sizeof(bucket)))) return(-1); if (pw = getpwnam(name)) return(b->id = pw->pw_uid); b->id = -2; return(-1); } 0707070000000003641006440044230044230000010000000471771124000003000000003626string/tok.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * token stream routines */ struct tok /* token stream state */ { union { char* end; /* end ('\0') of last token */ struct tok* nxt; /* next in free list */ } ptr; char chr; /* replace *end with this */ char flg; /* ==0 => don't restore string */ }; typedef struct tok TOK; static struct tok* freelist; extern char* malloc(); /* * open a new token stream on s * if f==0 then string is not restored */ char* tokopen(s, f) register char* s; int f; { register TOK* p; if (p = freelist) freelist = freelist->ptr.nxt; else if (!(p = (TOK*)malloc(sizeof(TOK)))) return(0); p->chr = *(p->ptr.end = s); p->flg = f; return((char*)p); } /* * close a token stream * restore the string to its original state */ void tokclose(u) char* u; { register TOK* p = (TOK*)u; if (p->flg) *p->ptr.end = p->chr; p->ptr.nxt = freelist; freelist = p; } /* * return next space separated token * "\n" is returned as a token * 0 returned when no tokens remain * "..." and '...' quotes are honored with \ escapes */ char* tokread(u) char* u; { register TOK* p = (TOK*)u; register char* s; register char* r; register int q; register int c; /* * restore string on each call */ if (!p->chr) return(0); s = p->ptr.end; if (p->flg) *s = p->chr; else if (!*s) s++; /* * skip leading space */ while (*s == ' ' || *s == '\t') s++; if (!*s) { p->ptr.end = s; p->chr = 0; return(0); } /* * find the end of this token */ r = s; q = 0; for (;;) switch (c = *r++) { case '\n': if (s == (r - 1) && !q) r++; /*FALLTHROUGH*/ case ' ': case '\t': if (q) break; /*FALLTHROUGH*/ case 0: if (s == --r) { p->ptr.end = r; p->chr = 0; } else { p->chr = *(p->ptr.end = r); *r = 0; } return(s); case '\\': if (*r) r++; break; case '"': case '\'': if (c == q) q = 0; else if (!q) q = c; break; } } 0707070000000003651006440044230044230000010000000474236214100002700000012474tm/tmdata.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support readonly data */ #include <tm.h> /* * default format strings -- must agree with TM_* indices */ static char* format[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "%H:%M:%S", "%m/%d/%y", "%a %b %e %T %Z %Y", "AM", "PM", "GMT", "UTC", "UCT", "CUT", "DST", "", "", "", "s", "es", "", "", "second", "minute", "hour", "day", "week", "month", "year", "midnight", "morning", "noon", "evening", "yesterday", "today", "tomorrow", "last", "ago", "past", "this", "now", "current", "next", "hence", "coming", "exactly", "", "", "at", "on", "in", "", }; /* * format[] lex type classes */ static char lex[] = { TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH_3, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_MONTH, TM_DAY_3, TM_DAY_3, TM_DAY_3, TM_DAY_3, TM_DAY_3, TM_DAY_3, TM_DAY_3, TM_DAY, TM_DAY, TM_DAY, TM_DAY, TM_DAY, TM_DAY, TM_DAY, TM_TIME, TM_DATE, TM_DEFAULT, TM_MERIDIAN, TM_MERIDIAN, TM_UT, TM_UT, TM_UT, TM_UT, TM_DT, TM_DT, TM_DT, TM_DT, TM_SUFFIXES, TM_SUFFIXES, TM_SUFFIXES, TM_SUFFIXES, TM_PARTS, TM_PARTS, TM_PARTS, TM_PARTS, TM_PARTS, TM_PARTS, TM_PARTS, TM_HOURS, TM_HOURS, TM_HOURS, TM_HOURS, TM_DAYS, TM_DAYS, TM_DAYS, TM_LAST, TM_LAST, TM_LAST, TM_THIS, TM_THIS, TM_THIS, TM_NEXT, TM_NEXT, TM_NEXT, TM_EXACT, TM_EXACT, TM_EXACT, TM_NOISE, TM_NOISE, TM_NOISE, TM_NOISE, }; /* * output format digits */ static char digit[] = "0123456789"; /* * number of days in month i */ static short days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; /* * sum of days in months before month i */ static short sum[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; /* * leap second time_t and accumulated adjustments * (reverse order -- biased for recent dates) * * tl.time is the seconds since the epoch for the leap event * * adding: the first additional second * subtracting: the first dissappearing second */ static struct tl leap[] = { 662688015, 16, /* Dec 31 23:59:60 GMT 1990 */ 631152014, 15, /* Dec 31 23:59:60 GMT 1989 */ 567993613, 14, /* Dec 31 23:59:60 GMT 1987 */ 489024012, 13, /* Jun 30 23:59:60 GMT 1985 */ 425865611, 12, /* Jun 30 23:59:60 GMT 1983 */ 394329610, 11, /* Jun 30 23:59:60 GMT 1982 */ 362793609, 10, /* Jun 30 23:59:60 GMT 1981 */ 315532808, 9, /* Dec 31 23:59:60 GMT 1979 */ 283996807, 8, /* Dec 31 23:59:60 GMT 1978 */ 252460806, 7, /* Dec 31 23:59:60 GMT 1977 */ 220924805, 6, /* Dec 31 23:59:60 GMT 1976 */ 189302404, 5, /* Dec 31 23:59:60 GMT 1975 */ 157766403, 4, /* Dec 31 23:59:60 GMT 1974 */ 126230402, 3, /* Dec 31 23:59:60 GMT 1973 */ 94694401, 2, /* Dec 31 23:59:60 GMT 1972 */ 78796800, 1, /* Jun 30 23:59:60 GMT 1972 */ 0, 0, /* can reference (tl+1) */ 0, 0 }; /* * time zones * * the UTC entries must be first * * zones with the same type are contiguous with all but the * first entry for the type having a null type * * tz.standard is the sentinel */ static struct tz zone[] = { 0, "GMT", 0, ( 0 * 60), 0, /* UTC */ 0, "UCT", 0, ( 0 * 60), 0, /* UTC */ 0, "UTC", 0, ( 0 * 60), 0, /* UTC */ 0, "CUT", 0, ( 0 * 60), 0, /* UTC */ "USA", "HST", 0, (10 * 60), 0, /* Hawaii */ 0, "YST", "YDT", ( 9 * 60), TM_DST, /* Yukon */ 0, "PST", "PDT", ( 8 * 60), TM_DST, /* Pacific */ 0, "PST", "PPET", ( 8 * 60), TM_DST, /* Pacific pres elect */ 0, "MST", "MDT", ( 7 * 60), TM_DST, /* Mountain */ 0, "CST", "CDT", ( 6 * 60), TM_DST, /* Central */ 0, "EST", "EDT", ( 5 * 60), TM_DST, /* Eastern */ "CAN", "AST", "ADT", ( 4 * 60), TM_DST, /* Atlantic */ 0, "NST", 0, ( 3 * 60 + 30), 0, /* Newfoundland */ "GBR", "", "BST", ( 0 * 60), TM_DST, /* British Summer */ "EUR", "WET", 0, ( 0 * 60), TM_DST, /* Western Eurpoean */ 0, "CET", 0, -( 1 * 60), TM_DST, /* Central European */ 0, "MET", 0, -( 1 * 60), TM_DST, /* Middle European */ 0, "EET", 0, -( 2 * 60), TM_DST, /* Eastern Eurpoean */ "ISR", "IST", "IDT", -( 3 * 60), TM_DST, /* Israel */ "CHN", "HKT", 0, -( 8 * 60), 0, /* Hong Kong */ "KOR", "KST", "KDT", -( 8 * 60), TM_DST, /* Korea */ "SNG", "SST", 0, -( 8 * 60), 0, /* Singapore */ "JPN", "JST", 0, -( 9 * 60), 0, /* Japan */ "AUS", "AWST", 0, -( 8 * 60), 0, /* Australia Western */ 0, "WST", 0, -( 8 * 60), 0, /* Australia Western */ 0, "ACST", 0, -( 9 * 60 + 30),TM_DST, /* Australia Central */ 0, "CST", 0, -( 9 * 60 + 30),TM_DST, /* Australia Central */ 0, "AEST", 0, -(10 * 60), TM_DST, /* Australia Eastern */ 0, "EST", 0, -(10 * 60), TM_DST, /* Australia Eastern */ "NZL", "NZST", "NZDT", -(12 * 60), TM_DST, /* New Zealand */ 0, 0, 0, 0, 0 }; struct tmdata tm_data = { format, lex, digit, days, sum, leap, zone }; 0707070000000003661006440044230044230000010000000475446227400002700000020134tm/tmdate.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support * * relative times inspired by Steve Bellovin's netnews getdate(3) */ #include <tm.h> #include <ctype.h> #define twodig(s,n) (n = (*s++ - '0') * 10, n += *s++ - '0') #define BREAK (1<<0) #define DAY (1<<1) #define EXACT (1<<2) #define HOLD (1<<3) #define HOUR (1<<4) #define LAST (1<<5) #define MDAY (1<<6) #define MONTH (1<<7) #define NEXT (1<<8) #define THIS (1<<9) #define YEAR (1<<10) #define YYMMDDHHMMSS (1<<11) #define ZONE (1<<12) #if __STDC__ || __cplusplus #if __cplusplus extern "C" { #endif extern long strtol(const char*, char**, int); #if __cplusplus } #endif #else extern long strtol(); #endif /* * parse date expression in s and return time_t value * * if non-null, e points to the first invalid sequence in s * clock provides default values */ time_t #if __STDC__ || __cplusplus tmdate(register const char* s, char** e, time_t* clock) #else tmdate(s, e, clock) register char* s; char** e; time_t* clock; #endif { register struct tm* tm; register int n; int state; time_t now; char* t; char* last; char* type; int dst; int zone; int i; int j; int k; int l; int m; reset: /* * use clock for defaults */ tm = tmmake(clock); dst = TM_DST; state = 0; type = 0; zone = 0; /* * get <weekday year month day hour minutes seconds ?[ds]t [ap]m> */ for (;;) { state &= (state & HOLD) ? ~(HOLD) : ~(EXACT|LAST|NEXT|THIS); n = -1; while (isspace(*s) || *s == ',' || *s == '-') s++; if (!*(last = (char*)s)) break; if (*s == '#') { if (!isdigit(*++s)) break; now = strtol(s, &t, 0); clock = &now; s = t; goto reset; } if (isdigit(*s)) { n = strtol(s, &t, 10); if (!(state & (LAST|NEXT|THIS)) && (!*t && (t - s) > 4 || *t == '.' && (t - s) == 4)) { /* * old date(1) format * * [yy[mm]]ddhhmm[.ss] * hhmm.ss */ if (state & YYMMDDHHMMSS) break; state |= YYMMDDHHMMSS; if ((t - s) < 10) m = tm->tm_year; else if (twodig(s, m) < 38) m += 100; if ((t - s) < 8) l = tm->tm_mon; else if (twodig(s, l) <= 0 || l > 12) break; if ((t - s) < 6) k = tm->tm_mon; else if (twodig(s, k) < 1 || k > 31) break; if ((t - s) < 4) break; if (twodig(s, j) > 24) break; if (twodig(s, i) > 59) break; if ((t - s) == 2) twodig(s, n); else if (t - s) break; else if (*t != '.') n = 0; else n = strtol(t + 1, &t, 10); if (n > (59 + TM_MAXLEAP)) break; tm->tm_year = m; tm->tm_mon = l - 1; tm->tm_mday = k; tm->tm_hour = j; tm->tm_min = i; tm->tm_sec = n; s = t; continue; } s = t; if (*s == ':') { if ((state & HOUR) || n > 24 || *s++ != ':' || !isdigit(*s)) break; i = n; n = strtol(s, &t, 10); s = t; if (n > 59) break; j = n; if (*s == ':') { if (!isdigit(*++s)) break; n = strtol(s, &t, 10); s = t; if (n > (59 + TM_MAXLEAP)) break; } else n = 0; tm->tm_sec = n; tm->tm_min = j; tm->tm_hour = i; continue; } } while (isspace(*s) || *s == ',' || *s == '-') s++; if (isalpha(*s)) { if ((j = tmlex(s, &t, tm_info.format, TM_NFORM, tm_info.format + TM_SUFFIXES, TM_PARTS - TM_SUFFIXES)) >= 0) { s = t; switch (tm_data.lex[j]) { case TM_EXACT: state |= HOLD|EXACT; continue; case TM_LAST: state |= HOLD|LAST; continue; case TM_THIS: state |= HOLD|THIS; n = 0; continue; case TM_NEXT: state |= HOLD|NEXT; continue; case TM_MERIDIAN: if (n > 0) { if (n > 24) goto done; tm->tm_hour = n; } if (j == TM_MERIDIAN) { if (tm->tm_hour == 12) tm->tm_hour = 0; } else if (tm->tm_hour < 12) tm->tm_hour += 12; if (n > 0) goto clear_min; continue; case TM_DAY_3: j += TM_DAY - TM_DAY_3; /*FALLTHROUGH*/ case TM_DAY: case TM_PARTS: case TM_HOURS: case TM_DAYS: if (n == -1) n = 1; if (!(state & (LAST|NEXT|THIS))) for (;;) { while (isspace(*s) || *s == ',') s++; if ((k = tmlex(s, &t, tm_info.format + TM_LAST, TM_NOISE - TM_LAST, (char**)0, 0)) >= 0) { s = t; if (k <= 2) state |= LAST; else if (k <= 5) state |= THIS; else if (k <= 8) state |= NEXT; else state |= EXACT; } else break; } if (state & LAST) n = -n; else if (!(state & NEXT)) n--; switch (j) { case TM_DAYS+0: tm->tm_mday--; goto clear_hour; case TM_DAYS+1: goto clear_hour; case TM_DAYS+2: tm->tm_mday++; goto clear_hour; case TM_PARTS+0: tm->tm_sec += n; continue; case TM_PARTS+1: tm->tm_min += n; goto clear_sec; case TM_PARTS+2: tm->tm_hour += n; goto clear_min; case TM_PARTS+3: tm->tm_mday += n; goto clear_hour; case TM_PARTS+4: tm->tm_mday += 7 * n - tm->tm_wday + 1; goto clear_hour; case TM_PARTS+5: tm->tm_mon += n; goto clear_mday; case TM_PARTS+6: tm->tm_year += n; goto clear_mon; case TM_HOURS+0: tm->tm_mday += n; goto clear_hour; case TM_HOURS+1: tm->tm_mday += n; tm->tm_hour = 6; goto clear_min; case TM_HOURS+2: tm->tm_mday += n; tm->tm_hour = 12; goto clear_min; case TM_HOURS+3: tm->tm_mday += n; tm->tm_hour = 18; goto clear_min; default: j -= tm->tm_wday + TM_DAY; if (state & (LAST|NEXT|THIS)) { if (j < 0) j += 7; } else if (j > 0) j -= 7; tm->tm_mday += j + n * 7; if (state & (LAST|NEXT|THIS)) goto clear_hour; continue; } break; case TM_MONTH_3: j += TM_MONTH - TM_MONTH_3; /*FALLTHROUGH*/ case TM_MONTH: if (state & MONTH) goto done; state |= MONTH; i = tm->tm_mon; tm->tm_mon = j - TM_MONTH; if (n < 0) { while (isspace(*s) || *s == ',' || *s == '-') s++; if (isdigit(*s)) { n = strtol(s, &t, 10); if (n <= 31) s = t; else n = -1; } } if (n >= 0) { if (n > 31) goto done; state |= MDAY; tm->tm_mday = n; } if (state & (LAST|NEXT|THIS)) { n = i; goto rel_month; } continue; case TM_UT: if (state & ZONE) goto done; state |= ZONE; zone += tmgoff(s, &t, 0); s = t; continue; case TM_DT: if (!dst) goto done; if (!(state & ZONE)) { dst = tm_info.local.dst; zone = tm_info.local.west; } zone += tmgoff(s, &t, dst); s = t; dst = 0; state |= ZONE; continue; case TM_NOISE: continue; } } if (!(state & ZONE) && (j = tmzone(s, &t, type, &dst)) != TM_LOCALZONE) { s = t; zone += j; state |= ZONE; continue; } if (!type && (type = tmtype(s, &t))) { s = t; continue; } state |= BREAK; } else if (*s == '/') { if (!isdigit(*++s) || (state & MONTH) || n == 0 || n > 12) break; i = n - 1; n = strtol(s, &t, 10); s = t; if (n <= 0 || n > 31) break; if (*s == '/' && !isdigit(*(s + 1))) break; state |= MONTH|MDAY; if (*s == '/') s++; tm->tm_mday = n; n = tm->tm_mon; tm->tm_mon = i; if (state & (LAST|NEXT|THIS)) { rel_month: if (state & LAST) tm->tm_year -= (tm->tm_mon < n) ? 0 : 1; else tm->tm_year += ((state & NEXT) ? 1 : 0) + ((tm->tm_mon < n) ? 1 : 0); if (state & MDAY) goto clear_hour; goto clear_mday; } continue; } if (n < 0 || (state & YEAR)) break; state |= YEAR; if (n > 1900) n -= 1900; if (n < 38) n += 100; tm->tm_year = n; if (state & BREAK) { last = t; break; } continue; clear_mon: if (state & EXACT) continue; tm->tm_mon = 0; clear_mday: if (state & EXACT) continue; tm->tm_mday = 1; clear_hour: if (state & EXACT) continue; tm->tm_hour = 0; clear_min: if (state & EXACT) continue; tm->tm_min = 0; clear_sec: if (state & EXACT) continue; tm->tm_sec = 0; } done: if (e) *e = last; return(tmtime(tmfix(tm), (state & ZONE) ? zone : TM_LOCALZONE)); } 0707070000000003671006440044230044230000010000000460420200600002600000002370tm/tmfix.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> /* * correct out of bounds fields in tp * * tm_wday, tm_yday and tm_isdst are not changed * as these can be computed from the other fields * * tp is the return value */ struct tm* #if __STDC__ || __cplusplus tmfix(register struct tm* tp) #else tmfix(tp) register struct tm* tp; #endif { register int n; if ((n = tp->tm_sec) < 0) { tp->tm_min -= (59 - n) / 60; tp->tm_sec = 60 - (-n) % 60; } else if (n > (59 + TM_MAXLEAP)) { tp->tm_min += n / 60; tp->tm_sec %= 60; } if ((n = tp->tm_min) < 0) { tp->tm_hour -= (59 - n) / 60; tp->tm_min = 60 - (-n) % 60; } else if (n > 59) { tp->tm_hour += n / 60; tp->tm_min %= 60; } if ((n = tp->tm_hour) < 0) { tp->tm_mday -= (23 - n) / 24; tp->tm_hour = 24 - (-n) % 24; } else if (n > 59) { tp->tm_mday += n / 24; tp->tm_mday %= 24; } while (tp->tm_mday < 1) { if (--tp->tm_mon < 0) { tp->tm_mon = 11; tp->tm_year--; } tp->tm_mday += tm_data.days[tp->tm_mon]; } while (tp->tm_mday > (n = tm_data.days[tp->tm_mon] + (tp->tm_mon == 1 && !(tp->tm_year % 4)))) { tp->tm_mday -= n; if (++tp->tm_mon > 11) { tp->tm_mon = 0; tp->tm_year++; } } return(tp); } 0707070000000003701006440044230044230000010000000475446222500002700000013770tm/tmform.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> #include <stdio.h> #define elements(x) (sizeof(x)/sizeof(x[0])) #define warped(t,n) ((t)<((n)-6L*30L*24L*60L*60L)||(t)>((n)+60L*60L)) #if __STDC__ || __cplusplus static char* number(char*, long, int); #else static char* number(); #endif extern time_t time(); /* * format date given clock * end of buf is returned */ char* #if __STDC__ || __cplusplus tmform(char* buf, const char* format, time_t* clock) #else tmform(buf, format, clock) char* buf; char* format; time_t* clock; #endif { register char* cp; register char* p; register int n; int c; int i; int flags; struct tm* tp; char* stack[4]; char** sp; time_t now; tp = tmmake(clock); if (!format || !*format) format = tm_info.deformat; flags = tm_info.flags; sp = &stack[0]; cp = buf; for (;;) { if (!(c = *format++)) { if (sp <= &stack[0]) break; format = *--sp; continue; } if (c != '%') { *cp++ = c; continue; } switch (*format++) { case 0: format--; continue; case '%': *cp++ = '%'; continue; case '?': if (tm_info.deformat != tm_info.format[TM_DEFAULT]) format = tm_info.deformat; else if (!*format) format = tm_info.format[TM_DEFAULT]; continue; case 'a': /* abbreviated day of week name */ n = TM_DAY_3 + tp->tm_wday; goto index; case 'A': /* day of week name */ n = TM_DAY + tp->tm_wday; goto index; case 'b': /* abbreviated month name */ case 'h': n = TM_MONTH_3 + tp->tm_mon; goto index; case 'B': /* month name */ n = TM_MONTH + tp->tm_mon; goto index; case 'c': /* `ctime(3)' date sans newline */ p = "%a %b %e %T %Y"; goto push; case 'C': /* `date(1)' date */ p = "%a %b %e %T %Z %Y"; goto push; case 'd': /* day of month */ cp = number(cp, (long)tp->tm_mday, 2); continue; case 'D': /* date */ p = "%m/%d/%y"; goto push; case 'E': /* no pad day of month */ cp = number(cp, (long)tp->tm_mday, 0); continue; case 'e': /* blank padded day of month */ cp = number(cp, (long)tp->tm_mday, -2); continue; case 'H': /* hour (0 - 23) */ cp = number(cp, (long)tp->tm_hour, 2); continue; case 'i': /* international `date(1)' date */ p = "%a %b %e %T %z %Z %Y"; goto push; case 'I': /* hour (0 - 12) */ if ((n = tp->tm_hour) > 12) n -= 12; else if (n == 0) n = 12; cp = number(cp, (long)n, 2); continue; case 'J': /* Julian date (0 offset) */ cp = number(cp, (long)tp->tm_yday, 3); continue; case 'j': /* Julian date (1 offset) */ cp = number(cp, (long)(tp->tm_yday + 1), 3); continue; case 'l': /* `ls -l' date */ p = "%b %e %H:%M"; if (clock) { (void)time(&now); if (warped(*clock, now)) p = "%b %e %Y"; } goto push; case 'm': /* month number */ cp = number(cp, (long)(tp->tm_mon + 1), 2); continue; case 'M': /* minutes */ cp = number(cp, (long)tp->tm_min, 2); continue; case 'n': *cp++ = '\n'; continue; case 'o': /* TM_DEFAULT override */ p = tm_info.deformat; goto push; case 'O': /* TM_DEFAULT */ p = tm_info.format[TM_DEFAULT]; goto push; case 'p': /* meridian */ n = TM_MERIDIAN + (tp->tm_hour >= 12); goto index; case 'r': p = "%I:%M:%S %p"; goto push; case 'R': p = "%H:%M"; goto push; case 'S': /* seconds */ cp = number(cp, (long)tp->tm_sec, 2); continue; case 't': *cp++ = '\t'; continue; case 'T': p = "%H:%M:%S"; goto push; case 'U': /* week number, Sunday as first day */ i = tp->tm_yday - tp->tm_wday; week: if (i >= -3 ) { n = (i + 1) / 7 + 1; if (i % 7 >= 4) n++; } else n = 52; cp = number(cp, (long)n, 2); continue; case 'w': /* weekday number */ cp = number(cp, (long)tp->tm_wday, 0); continue; case 'W': /* week number, Monday as first day */ if (tp->tm_wday == 0) i = tp->tm_yday - 6; else i = tp->tm_yday - tp->tm_wday + 1; goto week; case 'x': p = tm_info.format[TM_DATE]; goto push; case 'X': p = tm_info.format[TM_TIME]; goto push; case 'y': /* year in the form yy */ cp = number(cp, (long)tp->tm_year, 2); continue; case 'Y': /* year in the form ccyy */ cp = number(cp, (long)(1900 + tp->tm_year), 4); continue; case 'z': /* time zone type */ if (!(tm_info.flags & TM_UTC) && (p = tm_info.local.type)) goto string; continue; case 'Z': /* time zone */ p = (tm_info.flags & TM_UTC) ? tm_info.format[TM_UT] : tp->tm_isdst ? tm_info.local.daylight : tm_info.local.standard; goto string; case '-': case '+': switch (*format++) { case 0: format--; continue; case 'l': n = TM_LEAP; break; case 'u': n = TM_UTC; break; } if (c == '+') { if (!(tm_info.flags & n)) { tm_info.flags |= n; tp = tmmake(clock); } } else if (tm_info.flags & n) { tm_info.flags &= ~n; tp = tmmake(clock); } continue; case '#': /* seconds since the epoch */ if (clock) now = *clock; else (void)time(&now); cp = number(cp, (long)now, 0); continue; default: *cp++ = c; *cp++ = *(format - 1); continue; } index: p = tm_info.format[n]; string: while (*cp = *p++) cp++; continue; push: if (sp < &stack[elements(stack)]) { *sp++ = (char*)format; format = p; } continue; } tm_info.flags = flags; *cp = 0; return(cp); } /* * format n with padding p into s * return end of s * * p: <0 blank padding * 0 no padding * >0 0 padding */ static char* #if __STDC__ || __cplusplus number(register char* s, register long n, register int p) #else number(s, n, p) register char* s; register long n; register int p; #endif { #ifdef cray char format[32]; if (p > 0) (void)sprintf(format, "%%0%dlu", p); else if (p < 0) (void)sprintf(format, "%%%dlu", -p); else (void)sprintf(format, "%%lu"); (void)sprintf(s, format, n); #else if (p > 0) (void)sprintf(s, "%0*lu", p, n); else if (p < 0) (void)sprintf(s, "%*lu", -p, n); else (void)sprintf(s, "%lu", n); #endif while (*s) s++; return(s); } 0707070000000003711006440044230044230000010000000475446175200002700000001657tm/tmgoff.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> #include <ctype.h> #if __STDC__ || __cplusplus #if __cplusplus extern "C" { #endif extern long strtol(const char*, char**, int); #if __cplusplus } #endif #else extern long strtol(); #endif /* * return minutes offset from [[-+]hh[:mm[:ss]]] expression * * if e is non-null then it points to the first unrecognized char in s * d returned if no offset in s */ int #if __STDC__ || __cplusplus tmgoff(register const char* s, char** e, int d) #else tmgoff(s, e, d) register char* s; char** e; int d; #endif { register int n; char* t; if (isdigit(n = *s) || n == '-' || n == '+') { n = strtol(s, &t, 10); if (t > s) { n *= 60; if (*t == ':') n += (n < 0 ? -1 : 1) * strtol(t + 1, &t, 10); if (*t == ':') (void)strtol(t + 1, &t, 10); } else n = d; } else { n = d; t = (char*)s; } if (e) *e = t; return(n); } 0707070000000003721006440044230044230000010000000475434564600002700000012467tm/tminit.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> #include <ctype.h> #include <namval.h> #define TM_type (-1) static struct namval options[] = { "adjust", TM_ADJUST, "format", TM_DEFAULT, "leap", TM_LEAP, "type", TM_type, "utc", TM_UTC, 0, 0 }; struct tminfo tm_info; char* tzname[2]; /* POSIX time zone names */ #if __STDC__ || __cplusplus #if __cplusplus extern "C" { #endif static int tzwest(time_t*, int*); static int tmopt(char*, struct namval*, int, const char*); extern char* getenv(const char*); extern char* strchr(const char*, int); extern char* strdup(const char*); extern void stropt(char*, struct namval*, int (*)(char*, struct namval*, int, const char*), char*); #if __cplusplus } #endif #else static int tzwest(); static int tmopt(); extern char* getenv(); extern char* strchr(); extern char* strdup(); #endif /* * initialize tm data */ void tminit() { register struct tz* zp; register int n; register char* s; int i; int m; int isdst; char* t; struct tm* tp; time_t now; char buf[20]; /* * only do this stuff once */ if (tm_info.local.standard) return; /* * tm_info.format language support goes here */ tm_info.format = tm_data.format; tm_info.deformat = tm_data.format[TM_DEFAULT]; /* * tm_info.local */ (void)time(&now); n = tzwest(&now, &isdst); /* * compute local DST offset by roaming * through the last 12 months until tzwest() changes */ for (i = 0; i < 12; i++) { now -= 31 * 24 * 60 * 60; if ((m = tzwest(&now, &isdst)) != n) { if (!isdst) { isdst = n; n = m; m = isdst; } m -= n; break; } } tm_info.local.west = n; tm_info.local.dst = m; /* * now get the time zone names */ if (tzname[0]) { /* * POSIX */ tm_info.local.standard = tzname[0]; tm_info.local.daylight = tzname[1]; } else if ((s = getenv("TZNAME")) && *s && (s = strdup(s))) { /* * BSD */ tm_info.local.standard = s; if (s = strchr(s, ',')) *s++ = 0; else s = ""; tm_info.local.daylight = s; } else if ((s = getenv("TZ")) && *s && *s != ':' && (s = strdup(s))) { /* * POSIX style but skipped by localtime() */ tm_info.local.standard = s; if (*++s && *++s && *++s) { *s++ = 0; (void)tmgoff(s, &t, 0); s = t; } else s = ""; tm_info.local.daylight = s; } else { /* * tm_data.zone table lookup */ t = 0; for (zp = &tm_data.zone[0]; zp->standard; zp++) { if (zp->type) t = zp->type; if (zp->west == n && zp->dst == m) { tm_info.local.type = t; tm_info.local.standard = zp->standard; if (!(s = zp->daylight)) { s = tmpoff(buf, zp->standard, 0, 0); *s++ = ' '; (void)tmpoff(s, tm_info.format[TM_DT], m, TM_DST); s = strdup(buf); } tm_info.local.daylight = s; break; } } if (!zp->standard) { /* * not in the table */ s = tmpoff(buf, tm_info.format[TM_UT], n, 0); tm_info.local.standard = strdup(buf); *s++ = ' '; (void)tmpoff(s, tm_info.format[TM_UT], m, TM_DST); tm_info.local.daylight = strdup(buf); } } /* * set the options */ stropt(getenv("TM_OPTIONS"), options, tmopt, (char*)0); /* * the time zone type is probably related to the locale */ if (!tm_info.local.type) { s = tm_info.local.standard; t = 0; for (zp = &tm_data.zone[0]; zp->standard; zp++) { if (zp->type) t = zp->type; if (tmword(s, (char**)0, zp->standard, (char**)0, 0)) { tm_info.local.type = t; break; } } } /* * tm_info.flags */ if (!(tm_info.flags & TM_ADJUST)) { now = (time_t)78811200; /* Jun 30 1972 23:59:60 */ tp = (struct tm*)localtime(&now); if (tp->tm_sec != 60) tm_info.flags |= TM_ADJUST; } if (!(tm_info.flags & TM_UTC)) { s = tm_info.local.standard; for (zp = &tm_data.zone[0]; !zp->type && zp->standard; zp++) if (tmword(s, (char**)0, zp->standard, (char**)0, 0)) { tm_info.flags |= TM_UTC; break; } } } /* * stropt() option handler */ /*ARGSUSED*/ static int #if __STDC__ || __cplusplus tmopt(char* a, struct namval* p, int n, const char* v) #else tmopt(a, p, n, v) char* a; struct namval* p; int n; char* v; #endif { char* s; switch (p->value) { case TM_DEFAULT: tm_info.deformat = (n && (n = strlen(v)) > 0 && (n < 2 || v[n-2] != '%' || v[n-1] != '?')) ? strdup(v) : tm_info.format[TM_DEFAULT]; break; case TM_type: tm_info.local.type = (n && *v) ? ((s = tmtype(v, (char**)0)) ? s : strdup(v)) : 0; break; default: if (n) tm_info.flags |= p->value; else tm_info.flags &= ~p->value; break; } return(0); } /* * return minutes west of GMT for local time clock * * isdst will point to non-zero if DST is in effect * this routine also kicks in the local initialization */ static int #if __STDC__ || __cplusplus tzwest(time_t* clock, int* isdst) #else tzwest(clock, isdst) time_t* clock; int* isdst; #endif { register struct tm* tp; register int n; register int m; int h; /* * convert to GMT assuming local time */ tp = (struct tm*)gmtime(clock); n = tp->tm_yday; h = tp->tm_hour; m = tp->tm_min; /* * localtime() handles DST and GMT offset */ tp = (struct tm*)localtime(clock); if (n = tp->tm_yday - n) { if (n > 1) n = -1; else if (n < -1) n = 1; } *isdst = tp->tm_isdst; return((h - tp->tm_hour - n * 24) * 60 + m - tp->tm_min); } 0707070000000003731006440044230044230000010000000444527264400002700000001036tm/tmleap.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> /* * return clock with leap seconds adjusted * for direct localtime() access */ time_t #if __STDC__ || __cplusplus tmleap(register time_t* clock) #else tmleap(clock) register time_t* clock; #endif { register struct tl* lp; time_t now; tmset(); if (clock) now = *clock; else (void)time(&now); if (tm_info.flags & TM_ADJUST) { for (lp = &tm_data.leap[0]; now < (lp->time - lp->total); lp++); now += lp->total; } return(now); } 0707070000000003741006440044230044230000010000000475434572700002600000001531tm/tmlex.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> #include <ctype.h> /* * return the tab table index that matches s ignoring case and .'s * * ntab and nsuf are the number of elements in tab and suf, * -1 for 0 sentinel * * all isalpha() chars in str must match * suf is a table of nsuf valid str suffixes * if e is non-null then it will point to first unmatched char in str * which will always be non-isalpha() */ int #if __STDC__ || __cplusplus tmlex(register const char* s, char** e, char** tab, register int ntab, char** suf, int nsuf) #else tmlex(s, e, tab, ntab, suf, nsuf) register char* s; char** e; char** tab; register int ntab; char** suf; int nsuf; #endif { register char** p; for (p = tab; ntab-- && *p; p++) if (tmword(s, e, *p, suf, nsuf)) return(p - tab); return(-1); } 0707070000000003751006440044230044230000010000000444527267200002700000001505tm/tmmake.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> /* * return tm struct for clock * leap seconds accounted for in return value */ struct tm* #if __STDC__ || __cplusplus tmmake(time_t* clock) #else tmmake(clock) time_t* clock; #endif { register struct tm* tp; register struct tl* lp; int leapsec; time_t now; tmset(); if (clock) now = *clock; else (void)time(&now); leapsec = 0; if ((tm_info.flags & (TM_ADJUST|TM_LEAP)) == (TM_ADJUST|TM_LEAP) && now > 0) { for (lp = &tm_data.leap[0]; now < lp->time; lp++); if (lp->total) { if (now == lp->time && (leapsec = (lp->total - (lp+1)->total)) < 0) leapsec = 0; now -= lp->total; } } tp = (tm_info.flags & TM_UTC) ? (struct tm*)gmtime(&now) : (struct tm*)localtime(&now); tp->tm_sec += leapsec; return(tp); } 0707070000000003761006440044230044230000010000000475434575400002700000001217tm/tmpoff.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> #include <stdio.h> /* * append p and hh:mm part of n to s * * n ignored if n==d * end of s is returned */ char* #if __STDC__ || __cplusplus tmpoff(register char* s, register const char* p, register int n, int d) #else tmpoff(s, p, n, d) register char* s; register char* p; register int n; int d; #endif { while (*s = *p++) s++; if (n != d) { if (n < 0) { n = -n; *s++ = '-'; } else *s++ = '+'; (void)sprintf(s, "%d", n / 60); while (*++s); if (n %= 60) { (void)sprintf(s, ":%02d", n); while (*++s); } } return(s); } 0707070000000003771006440044230044230000010000000444527276500002700000002633tm/tmtime.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> /* * convert struct tm to time_t * * if west==TM_LOCALZONE then the local timezone is used * otherwise west is the number of minutes west * of GMT with DST taken into account */ time_t #if __STDC__ || __cplusplus tmtime(register struct tm* tp, int west) #else tmtime(tp, west) register struct tm* tp; int west; #endif { register time_t clock; register struct tl* lp; int n; int sec; time_t now; tmset(); clock = (tp->tm_year * (4 * 365 + 1) - 69) / 4 - 70 * 365; if ((n = tp->tm_mon) > 11) n = 11; if (n > 1 && !(tp->tm_year % 4)) clock++; clock += tm_data.sum[n] + tp->tm_mday - 1; clock *= 24; clock += tp->tm_hour; clock *= 60; clock += tp->tm_min; clock *= 60; clock += sec = tp->tm_sec; if (!(tm_info.flags & TM_UTC)) { /* * time zone adjustments */ if (west == TM_LOCALZONE) { clock += tm_info.local.west * 60; now = clock; if (tmmake(&now)->tm_isdst) clock += tm_info.local.dst * 60; } else clock += west * 60; } if (tm_info.flags & TM_LEAP) { /* * leap second adjustments */ if (clock > 0) { for (lp = &tm_data.leap[0]; clock < lp->time - (lp+1)->total; lp++); clock += lp->total; n = lp->total - (lp+1)->total; if (clock <= (lp->time + n) && (n > 0 && sec > 59 || n < 0 && sec > (59 + n) && sec <= 59)) clock -= n; } } return(clock); } 0707070000000004001006440044230044230000010000000475434616600002700000001216tm/tmtype.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> /* * return the tm_data.zone[] time zone type name for s * * if e is non-null then it will point to the first * unmatched char in s * * 0 returned for no match */ char* #if __STDC__ || __cplusplus tmtype(register const char* s, char** e) #else tmtype(s, e) register char* s; char** e; #endif { register struct tz* zp; register char* t; tmset(); zp = &tm_info.local; do { if ((t = zp->type) && tmword(s, e, t, (char**)0, 0)) return(t); if (zp == &tm_info.local) zp = &tm_data.zone[0]; else zp++; } while (zp->standard); return(0); } 0707070000000004011006440044230044230000010000000475447574200002700000002326tm/tmword.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> #include <ctype.h> /* * match s against t ignoring case and .'s * * suf is an n element table of suffixes that may trail s * if all isalpha() chars in s match then 1 is returned * and if e is non-null it will point to the first unmatched * char in s, otherwise 0 is returned */ int #if __STDC__ || __cplusplus tmword(register const char* s, char** e, register const char* t, char** suf, int n) #else tmword(s, e, t, suf, n) register char* s; char** e; register char* t; char** suf; int n; #endif { register int c; #if __STDC__ || __cplusplus const char* b; #else char* b; #endif if (*s && *t) { b = s; while (c = *s++) { if (c != '.') { if (!isalpha(c) || c != *t && (islower(c) ? toupper(c) : tolower(c)) != *t) break; t++; } } s--; if (!isalpha(c)) { if (e) *e = (char*)s; return(1); } if (!*t && s > (b + 1)) { b = s; while (n-- && (t = *suf++)) { s = b; while (isalpha(c = *s++) && (c == *t || (islower(c) ? toupper(c) : tolower(c)) == *t)) t++; if (!*t && !isalpha(c)) { if (e) *e = (char*)s - 1; return(1); } } } } return(0); } 0707070000000004021006440044230044230000010000000475446240000002700000002352tm/tmzone.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * time conversion support */ #include <tm.h> /* * return minutes west of GMT for timezone name and type * * if type==0 then all time zone types match * otherwise type must be a value returned by tmtype() * * if end is non-null then it will point to the next * unmatched char in name * * if dst is non-null then it will point to the DST * offset for standard zones and 0 for daylight zones * * TM_LOCALZONE returned for no match */ int #if __STDC__ || __cplusplus tmzone(register const char* name, char** end, const char* type, int* dst) #else tmzone(name, end, type, dst) register char* name; char** end; char* type; int* dst; #endif { register struct tz* zp; register char* prev; tmset(); zp = &tm_info.local; prev = 0; do { if (zp->type) prev = zp->type; if (!type || type == prev || !prev) { if (tmword(name, end, zp->standard, (char**)0, 0)) { if (dst) *dst = zp->dst; return(zp->west); } if (zp->dst && zp->daylight && tmword(name, end, zp->daylight, (char**)0, 0)) { if (dst) *dst = 0; return(zp->west + zp->dst); } } if (zp == &tm_info.local) zp = &tm_data.zone[0]; else zp++; } while (zp->standard); return(TM_LOCALZONE); } 0707070000000004031006440044230044230000010000000452433643200003100000001741vec/vecargs.c Ugsf Ggsf /* * G. S. Fowler * AT&T Bell Laboratories * * string vector argv insertion */ #include <ctype.h> extern char* malloc(); extern void vecfree(); /* * insert the string vector vec between * (*argvp)[0] and (*argvp)[1], sliding (*argvp)[1] ... over * null and blank args are deleted * * vecfree(vec) always called * * -1 returned if insertion failed */ int vecargs(vec, argcp, argvp) register char** vec; int* argcp; char*** argvp; { register char** argv; register char** oargv; char** ovec; char* s; int num; if (!vec) return(-1); if ((num = (char**)(*(vec - 1)) - vec) > 0) { if (!(argv = (char**)malloc((num + *argcp + 1) * sizeof(char*)))) { vecfree(vec, 0); return(-1); } oargv = *argvp; *argvp = argv; *argv++ = *oargv++; ovec = vec; while (s = *argv = *vec++) { while (isspace(*s)) s++; if (*s) argv++; } vecfree(ovec, 1); while (*argv = *oargv++) argv++; *argcp = argv - *argvp; } else vecfree(vec, 0); return(0); } 0707070000000004041006440044230044230000010000000452433442300003100000001246vec/vecfile.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * string vector load support */ #include <sys/types.h> #include <sys/stat.h> extern char** vecload(); extern int close(); extern int fstat(); extern char* malloc(); extern int open(); /* * load a string vector from lines in file */ char** vecfile(file) char* file; { register int n; register char* buf; register char** vec; int fd; struct stat st; vec = 0; if ((fd = open(file, 0)) >= 0) { if (!fstat(fd, &st) && (n = st.st_size) > 0 && (buf = malloc(n + 1))) { if (read(fd, buf, n) == n) { buf[n] = 0; vec = vecload(buf); } if (!vec) free(buf); } (void)close(fd); } return(vec); } 0707070000000004051006440044230044230000010000000452433425200003100000000641vec/vecfree.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * file to string vector support */ extern void free(); /* * free a string vector generated by vecload() * * retain!=0 frees the string pointers but retains the string data * in this case the data is permanently allocated */ void vecfree(vec, retain) register char** vec; int retain; { if (vec) { if (*(vec -= 2) && !retain) free(*vec); free(vec); } } 0707070000000004061006440044230044230000010000000452435623600003100000002115vec/vecload.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * string vector load support */ extern char** malloc(); /* * load a string vector from lines in buf * buf may be modified on return * * each line in buf is treated as a new vector element * lines with # as first char are comments * \ as the last char joins consecutive lines * * the vector ends with a 0 sentinel * * the string array pointer is returned */ char** vecload(buf) char* buf; { register char* s; register int n; register char** p; char** vec; vec = 0; n = (*buf == '#') ? -1 : 0; for (s = buf;; s++) { if (*s == '\n') { if (s > buf && *(s - 1) == '\\') *(s - 1) = *s = ' '; else { *s = 0; if (*(s + 1) != '#') { n++; if (!*(s + 1)) break; } } } else if (!*s) { n++; break; } } if (n < 0) n = 0; if (p = (char**)malloc((n + 3) * sizeof(char*))) { *p++ = s = buf; vec = ++p; if (n > 0) for (;;) { if (*s != '#') { *p++ = s; if (--n <= 0) break; } while (*s) s++; s++; } *p = 0; *(vec - 1) = (char*)p; } return(vec); } 0707070000000004071006440044230044230000010000000460214101600003300000000566vec/vecstring.c Ugsf Ggsf /* * Glenn Fowler * AT&T Bell Laboratories * * string vector load support */ extern char** vecload(); extern char* strdup(); /* * load a string vector from lines in str */ char** vecstring(str) char* str; { register char* buf; register char** vec; if (!str || !*str || !(buf = strdup(str))) vec = 0; else if (!(vec = vecload(buf))) free(buf); return(vec); } 0707070000000004101006440044230044230000010000000475522432300002300000432567Mamfile Ugsf Ggsf note # # make abstract machine file generated from Makefile # # setv AS as setv ASFLAGS setv AR ar setv ARFLAGS cr setv CC cc setv CCFLAGS "-O" setv CPP "$CC -E" setv CPIO cpio setv CPIOFLAGS setv F77 f77 setv INSTALLROOT $HOME setv LD ld setv LDFLAGS setv LEX lex setv LEXFLAGS setv LPR lpr setv LPRFLAGS setv M4FLAGS setv MAKE nmake setv MAKEFLAGS setv PR pr setv PRFLAGS setv TAR tar setv YACC yacc setv YACCFLAGS -d make install make all make libx.a attr arch make opendir.o make dir/opendir.c attr perm attr scan make /usr/include/errno.h attr perm attr scan attr impl make /usr/include/sys/errno.h attr perm attr scan attr impl done /usr/include/sys/errno.h done /usr/include/errno.h make dir/dirlib.h attr perm attr scan attr impl make include/hash.h attr perm attr scan attr impl done include/hash.h make limits.h make mkhdr make port/mkhdr.sh attr perm attr scan done port/mkhdr.sh prev port/mkhdr.sh exec case '' in .... "") cp port/mkhdr.sh mkhdr .... ;; .... *) { .... i=`(read x; echo $x) < port/mkhdr.sh` .... case $i in .... \#!*) echo $i ;; .... esac .... echo .... cat port/mkhdr.sh .... } > mkhdr .... ;; .... esac .... chmod u+w,+x mkhdr done mkhdr make genhdr make genhdr.o make port/genhdr.c attr perm attr scan make lclstdio.h prev mkhdr exec mkhdr lclstdio "" "$CC" $CCFLAGS > lclstdio.h attr scan attr impl done lclstdio.h make lcldirent.h prev mkhdr exec mkhdr lcldirent "" "$CC" $CCFLAGS > lcldirent.h attr scan attr impl done lcldirent.h make lclparam.h prev mkhdr exec mkhdr lclparam "" "$CC" $CCFLAGS > lclparam.h attr scan attr impl done lclparam.h make lcllimits.h prev mkhdr exec mkhdr lcllimits "" "$CC" $CCFLAGS > lcllimits.h attr scan attr impl done lcllimits.h make FEATURE/getdents exec : generate local FEATURE information for getdents .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for getdents */' .... case "getdents" in .... *.*) f=getdents .... i=getdents .... ;; .... *) f=getdents .... i=getdents .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/getdents .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/getdents make FEATURE/dir exec : generate local FEATURE information for dir .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for dir */' .... case "dir" in .... *.*) f=dir .... i=dir .... ;; .... *) f=dir .... i=dir .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/dir .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/dir done port/genhdr.c prev port/genhdr.c exec $CC $CCFLAGS -I. -c port/genhdr.c done genhdr.o exec $CC $CCFLAGS $LDFLAGS -o genhdr genhdr.o done genhdr exec mkhdr limits " genhdr" "$CC" $CCFLAGS > limits.h attr scan attr impl prev lcllimits.h done limits.h make dirent.h prev mkhdr prev genhdr exec mkhdr dirent " genhdr" "$CC" $CCFLAGS > dirent.h attr scan attr impl prev lcldirent.h done dirent.h make fsinfo.h prev mkhdr prev genhdr exec mkhdr fsinfo " genhdr" "$CC" $CCFLAGS > fsinfo.h attr scan attr impl done fsinfo.h prev lclparam.h make preroot.h prev mkhdr exec mkhdr preroot "" "$CC" $CCFLAGS > preroot.h attr scan attr impl done preroot.h done dir/dirlib.h done dir/opendir.c prev dir/opendir.c exec $CC $CCFLAGS -I. -Idir -Iinclude -c dir/opendir.c done opendir.o make readdir.o make dir/readdir.c attr perm attr scan prev dir/dirlib.h done dir/readdir.c prev dir/readdir.c exec $CC $CCFLAGS -I. -Idir -Iinclude -c dir/readdir.c done readdir.o make rewinddir.o make dir/rewinddir.c attr perm attr scan prev dir/dirlib.h done dir/rewinddir.c prev dir/rewinddir.c exec $CC $CCFLAGS -I. -Idir -Iinclude -c dir/rewinddir.c done rewinddir.o make seekdir.o make dir/seekdir.c attr perm attr scan prev dir/dirlib.h done dir/seekdir.c prev dir/seekdir.c exec $CC $CCFLAGS -I. -Idir -Iinclude -c dir/seekdir.c done seekdir.o make telldir.o make dir/telldir.c attr perm attr scan prev dir/dirlib.h done dir/telldir.c prev dir/telldir.c exec $CC $CCFLAGS -I. -Idir -Iinclude -c dir/telldir.c done telldir.o make getcwd.o make misc/getcwd.c attr perm attr scan prev limits.h prev /usr/include/errno.h prev dirent.h make /usr/include/sys/stat.h done /usr/include/sys/stat.h make /usr/include/sys/types.h done /usr/include/sys/types.h done misc/getcwd.c prev misc/getcwd.c exec $CC $CCFLAGS -I. -c misc/getcwd.c done getcwd.o make setcwd.o make misc/setcwd.c attr perm attr scan prev /usr/include/errno.h prev limits.h done misc/setcwd.c prev misc/setcwd.c setv DEBUG -UDEBUG exec $CC $CCFLAGS -I. "$DEBUG" -c misc/setcwd.c done setcwd.o make getshell.o make misc/getshell.c attr perm attr scan done misc/getshell.c prev misc/getshell.c exec $CC $CCFLAGS -c misc/getshell.c done getshell.o make hashalloc.o make hash/hashalloc.c attr perm attr scan make hash/hashlib.h attr perm attr scan attr impl prev include/hash.h prev limits.h done hash/hashlib.h done hash/hashalloc.c prev hash/hashalloc.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashalloc.c done hashalloc.o make hashdump.o make hash/hashdump.c attr perm attr scan prev hash/hashlib.h make include/stdio.h done include/stdio.h done hash/hashdump.c prev hash/hashdump.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashdump.c done hashdump.o make hashfree.o make hash/hashfree.c attr perm attr scan prev hash/hashlib.h done hash/hashfree.c prev hash/hashfree.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashfree.c done hashfree.o make hashlook.o make hash/hashlook.c attr perm attr scan prev hash/hashlib.h done hash/hashlook.c prev hash/hashlook.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashlook.c done hashlook.o make hashscan.o make hash/hashscan.c attr perm attr scan prev hash/hashlib.h done hash/hashscan.c prev hash/hashscan.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashscan.c done hashscan.o make hashsize.o make hash/hashsize.c attr perm attr scan prev hash/hashlib.h done hash/hashsize.c prev hash/hashsize.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashsize.c done hashsize.o make hashwalk.o make hash/hashwalk.c attr perm attr scan prev hash/hashlib.h done hash/hashwalk.c prev hash/hashwalk.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/hashwalk.c done hashwalk.o make memhash.o make hash/memhash.c attr perm attr scan prev hash/hashlib.h done hash/memhash.c prev hash/memhash.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/memhash.c done memhash.o make memsum.o make hash/memsum.c attr perm attr scan prev hash/hashlib.h done hash/memsum.c prev hash/memsum.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/memsum.c done memsum.o make strhash.o make hash/strhash.c attr perm attr scan prev hash/hashlib.h done hash/strhash.c prev hash/strhash.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/strhash.c done strhash.o make strsum.o make hash/strsum.c attr perm attr scan prev hash/hashlib.h done hash/strsum.c prev hash/strsum.c exec $CC $CCFLAGS -I. -Ihash -Iinclude -c hash/strsum.c done strsum.o make cvtatoe.o make misc/cvtatoe.c attr perm attr scan done misc/cvtatoe.c prev misc/cvtatoe.c exec $CC $CCFLAGS -c misc/cvtatoe.c done cvtatoe.o make cvtetoa.o make misc/cvtetoa.c attr perm attr scan done misc/cvtetoa.c prev misc/cvtetoa.c exec $CC $CCFLAGS -c misc/cvtetoa.c done cvtetoa.o make chresc.o make string/chresc.c attr perm attr scan done string/chresc.c prev string/chresc.c exec $CC $CCFLAGS -c string/chresc.c done chresc.o make ctoi.o make string/ctoi.c attr perm attr scan prev limits.h done string/ctoi.c prev string/ctoi.c exec $CC $CCFLAGS -I. -c string/ctoi.c done ctoi.o make streval.o make string/streval.c attr perm attr scan make /usr/include/ctype.h attr perm attr scan attr impl done /usr/include/ctype.h done string/streval.c prev string/streval.c exec $CC $CCFLAGS -c string/streval.c done streval.o make strmatch.o make string/strmatch.c attr perm attr scan prev /usr/include/ctype.h done string/strmatch.c prev string/strmatch.c exec $CC $CCFLAGS -c string/strmatch.c done strmatch.o make strcopy.o make string/strcopy.c attr perm attr scan done string/strcopy.c prev string/strcopy.c exec $CC $CCFLAGS -c string/strcopy.c done strcopy.o make strmode.o make string/strmode.c attr perm attr scan make string/modelib.h attr perm attr scan attr impl done string/modelib.h done string/strmode.c prev string/strmode.c exec $CC $CCFLAGS -Istring -c string/strmode.c done strmode.o make stresc.o make string/stresc.c attr perm attr scan done string/stresc.c prev string/stresc.c exec $CC $CCFLAGS -c string/stresc.c done stresc.o make stropt.o make string/stropt.c attr perm attr scan prev /usr/include/ctype.h make include/namval.h attr perm attr scan attr impl done include/namval.h done string/stropt.c prev string/stropt.c exec $CC $CCFLAGS -Iinclude -c string/stropt.c done stropt.o make strtape.o make string/strtape.c attr perm attr scan prev include/stdio.h done string/strtape.c prev string/strtape.c exec $CC $CCFLAGS -Iinclude -c string/strtape.c done strtape.o make tok.o make string/tok.c attr perm attr scan done string/tok.c prev string/tok.c exec $CC $CCFLAGS -c string/tok.c done tok.o make pathaccess.o make misc/pathaccess.c attr perm attr scan prev /usr/include/sys/stat.h prev /usr/include/sys/types.h prev limits.h done misc/pathaccess.c prev misc/pathaccess.c exec $CC $CCFLAGS -I. -c misc/pathaccess.c done pathaccess.o make pathcanon.o make misc/pathcanon.c attr perm attr scan done misc/pathcanon.c prev misc/pathcanon.c exec $CC $CCFLAGS -c misc/pathcanon.c done pathcanon.o make pathcheck.o make misc/pathcheck.c attr perm attr scan done misc/pathcheck.c prev misc/pathcheck.c exec $CC $CCFLAGS -c misc/pathcheck.c done pathcheck.o make pathpath.o make misc/pathpath.c attr perm attr scan done misc/pathpath.c prev misc/pathpath.c exec $CC $CCFLAGS -c misc/pathpath.c done pathpath.o make pathkey.o make misc/pathkey.c attr perm attr scan prev include/stdio.h prev preroot.h prev /usr/include/ctype.h prev limits.h done misc/pathkey.c prev misc/pathkey.c exec $CC $CCFLAGS -I. -Iinclude -c misc/pathkey.c done pathkey.o make pathprobe.o make misc/pathprobe.c attr perm attr scan make include/ls.h attr perm attr scan attr impl prev fsinfo.h done include/ls.h prev limits.h done misc/pathprobe.c prev misc/pathprobe.c exec $CC $CCFLAGS -I. -Iinclude -c misc/pathprobe.c done pathprobe.o make pathtemp.o make misc/pathtemp.c attr perm attr scan done misc/pathtemp.c prev misc/pathtemp.c exec $CC $CCFLAGS -c misc/pathtemp.c done pathtemp.o make cmdargs.o make misc/cmdargs.c attr perm attr scan make include/option.h attr perm attr scan attr impl done include/option.h done misc/cmdargs.c prev misc/cmdargs.c exec $CC $CCFLAGS -Iinclude -c misc/cmdargs.c done cmdargs.o make fs3d.o make misc/fs3d.c attr perm attr scan done misc/fs3d.c prev misc/fs3d.c exec $CC $CCFLAGS -c misc/fs3d.c done fs3d.o make ftwalk.o make misc/ftwalk.c attr perm attr scan make include/ftwalk.h attr perm attr scan attr impl done include/ftwalk.h prev /usr/include/errno.h prev limits.h prev dirent.h prev /usr/include/sys/stat.h prev /usr/include/sys/types.h done misc/ftwalk.c prev misc/ftwalk.c exec $CC $CCFLAGS -I. -Iinclude -c misc/ftwalk.c done ftwalk.o make perror.o make misc/perror.c attr perm attr scan make FEATURE/strerror exec : generate local FEATURE information for strerror .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strerror */' .... case "strerror" in .... *.*) f=strerror .... i=strerror .... ;; .... *) f=strerror .... i=strerror .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strerror .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strerror prev include/stdio.h done misc/perror.c prev misc/perror.c exec $CC $CCFLAGS -I. -Iinclude -c misc/perror.c done perror.o make putenv.o make misc/putenv.c attr perm attr scan done misc/putenv.c prev misc/putenv.c exec $CC $CCFLAGS -c misc/putenv.c done putenv.o make calloc.o make misc/calloc.c attr perm attr scan make FEATURE/bzero exec : generate local FEATURE information for bzero .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for bzero */' .... case "bzero" in .... *.*) f=bzero .... i=bzero .... ;; .... *) f=bzero .... i=bzero .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/bzero .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/bzero done misc/calloc.c prev misc/calloc.c exec $CC $CCFLAGS -I. -c misc/calloc.c done calloc.o make malloc.o make misc/malloc.c attr perm attr scan make FEATURE/bcopy exec : generate local FEATURE information for bcopy .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for bcopy */' .... case "bcopy" in .... *.*) f=bcopy .... i=bcopy .... ;; .... *) f=bcopy .... i=bcopy .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/bcopy .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/bcopy done misc/malloc.c prev misc/malloc.c exec $CC $CCFLAGS -I. "$DEBUG" -c misc/malloc.c done malloc.o make getnamval.o make misc/getnamval.c attr perm attr scan prev include/namval.h done misc/getnamval.c prev misc/getnamval.c exec $CC $CCFLAGS -Iinclude -c misc/getnamval.c done getnamval.o make optget.o make misc/optget.c attr perm attr scan done misc/optget.c prev misc/optget.c exec $CC $CCFLAGS -c misc/optget.c done optget.o make hsort.o make misc/hsort.c attr perm attr scan done misc/hsort.c prev misc/hsort.c exec $CC $CCFLAGS -c misc/hsort.c done hsort.o make query.o make misc/query.c attr perm attr scan prev include/stdio.h done misc/query.c prev misc/query.c exec $CC $CCFLAGS -Iinclude -c misc/query.c done query.o make error.o make misc/error.c attr perm attr scan make include/sfio.h done include/sfio.h make sig.h prev mkhdr exec mkhdr sig "" "$CC" $CCFLAGS > sig.h attr scan attr impl done sig.h prev include/namval.h make include/error.h attr perm attr scan attr impl done include/error.h prev /usr/include/ctype.h done misc/error.c prev misc/error.c exec $CC $CCFLAGS -I. -Iinclude -c misc/error.c done error.o make liberror.o make misc/liberror.c attr perm attr scan prev include/error.h done misc/liberror.c prev misc/liberror.c exec $CC $CCFLAGS -Iinclude -c misc/liberror.c done liberror.o make strerror.o make string/strerror.c attr perm attr scan prev FEATURE/strerror done string/strerror.c prev string/strerror.c exec $CC $CCFLAGS -I. -Iinclude -c string/strerror.c done strerror.o make strsignal.o make string/strsignal.c attr perm attr scan prev include/stdio.h done string/strsignal.c prev string/strsignal.c exec $CC $CCFLAGS -Iinclude -c string/strsignal.c done strsignal.o make fmtelapsed.o make string/fmtelapsed.c attr perm attr scan prev include/stdio.h done string/fmtelapsed.c prev string/fmtelapsed.c exec $CC $CCFLAGS -Iinclude -c string/fmtelapsed.c done fmtelapsed.o make fmtls.o make string/fmtls.c attr perm attr scan prev include/stdio.h make include/tm.h attr perm attr scan attr impl done include/tm.h prev include/ls.h done string/fmtls.c prev string/fmtls.c exec $CC $CCFLAGS -I. -Iinclude -c string/fmtls.c done fmtls.o make fmtmode.o make string/fmtmode.c attr perm attr scan prev string/modelib.h done string/fmtmode.c prev string/fmtmode.c exec $CC $CCFLAGS -Istring -c string/fmtmode.c done fmtmode.o make fmtperm.o make string/fmtperm.c attr perm attr scan prev include/ls.h done string/fmtperm.c prev string/fmtperm.c exec $CC $CCFLAGS -I. -Iinclude -c string/fmtperm.c done fmtperm.o make fmtuid.o make string/fmtuid.c attr perm attr scan make /usr/include/pwd.h attr perm attr scan attr impl done /usr/include/pwd.h prev include/hash.h prev include/stdio.h done string/fmtuid.c prev string/fmtuid.c exec $CC $CCFLAGS -Iinclude -c string/fmtuid.c done fmtuid.o make fmtgid.o make string/fmtgid.c attr perm attr scan make /usr/include/grp.h attr perm attr scan attr impl done /usr/include/grp.h prev include/hash.h prev include/stdio.h done string/fmtgid.c prev string/fmtgid.c exec $CC $CCFLAGS -Iinclude -c string/fmtgid.c done fmtgid.o make strelapsed.o make string/strelapsed.c attr perm attr scan prev /usr/include/ctype.h done string/strelapsed.c prev string/strelapsed.c exec $CC $CCFLAGS -c string/strelapsed.c done strelapsed.o make strperm.o make string/strperm.c attr perm attr scan prev include/ls.h done string/strperm.c prev string/strperm.c exec $CC $CCFLAGS -I. -Iinclude -c string/strperm.c done strperm.o make struid.o make string/struid.c attr perm attr scan prev /usr/include/pwd.h prev include/hash.h done string/struid.c prev string/struid.c exec $CC $CCFLAGS -Iinclude -c string/struid.c done struid.o make strgid.o make string/strgid.c attr perm attr scan prev /usr/include/grp.h prev /usr/include/pwd.h prev include/hash.h done string/strgid.c prev string/strgid.c exec $CC $CCFLAGS -Iinclude -c string/strgid.c done strgid.o make stack.o make misc/stack.c attr perm attr scan make include/stack.h attr perm attr scan attr impl done include/stack.h done misc/stack.c prev misc/stack.c exec $CC $CCFLAGS -Iinclude -c misc/stack.c done stack.o make stak.o make misc/stak.c attr perm attr scan make include/stak.h attr perm attr scan attr impl done include/stak.h done misc/stak.c prev misc/stak.c exec $CC $CCFLAGS -Iinclude -c misc/stak.c done stak.o make memswap.o make string/memswap.c attr perm attr scan make include/swap.h attr perm attr scan attr impl done include/swap.h done string/memswap.c prev string/memswap.c exec $CC $CCFLAGS -Iinclude -c string/memswap.c done memswap.o make gethalf.o make string/gethalf.c attr perm attr scan prev limits.h prev include/swap.h done string/gethalf.c prev string/gethalf.c exec $CC $CCFLAGS -I. -Iinclude -c string/gethalf.c done gethalf.o make getlong.o make string/getlong.c attr perm attr scan prev limits.h prev include/swap.h done string/getlong.c prev string/getlong.c exec $CC $CCFLAGS -I. -Iinclude -c string/getlong.c done getlong.o make puthalf.o make string/puthalf.c attr perm attr scan prev limits.h prev include/swap.h done string/puthalf.c prev string/puthalf.c exec $CC $CCFLAGS -I. -Iinclude -c string/puthalf.c done puthalf.o make putlong.o make string/putlong.c attr perm attr scan prev limits.h prev include/swap.h done string/putlong.c prev string/putlong.c exec $CC $CCFLAGS -I. -Iinclude -c string/putlong.c done putlong.o make fgetline.o make misc/fgetline.c attr perm attr scan prev include/stdio.h done misc/fgetline.c prev misc/fgetline.c exec $CC $CCFLAGS -Iinclude -c misc/fgetline.c done fgetline.o make sigcrit.o make misc/sigcrit.c attr perm attr scan make FEATURE/sigsetmask exec : generate local FEATURE information for sigsetmask .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for sigsetmask */' .... case "sigsetmask" in .... *.*) f=sigsetmask .... i=sigsetmask .... ;; .... *) f=sigsetmask .... i=sigsetmask .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/sigsetmask .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/sigsetmask prev sig.h done misc/sigcrit.c prev misc/sigcrit.c exec $CC $CCFLAGS -I. -c misc/sigcrit.c done sigcrit.o make sigunblock.o make comp/sigunblock.c attr perm attr scan prev sig.h make FEATURE/sigunblock exec : generate local FEATURE information for sigunblock .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for sigunblock */' .... case "sigunblock" in .... *.*) f=sigunblock .... i=sigunblock .... ;; .... *) f=sigunblock .... i=sigunblock .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/sigunblock .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/sigunblock done comp/sigunblock.c prev comp/sigunblock.c exec $CC $CCFLAGS -I. -c comp/sigunblock.c done sigunblock.o make cmdopen.o make misc/cmdopen.c attr perm attr scan make misc/cmdlib.h attr perm attr scan attr impl prev /usr/include/errno.h prev include/stdio.h prev limits.h done misc/cmdlib.h done misc/cmdopen.c prev misc/cmdopen.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/cmdopen.c done cmdopen.o make cmdclose.o make misc/cmdclose.c attr perm attr scan prev misc/cmdlib.h done misc/cmdclose.c prev misc/cmdclose.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/cmdclose.c done cmdclose.o make cmdrun.o make misc/cmdrun.c attr perm attr scan done misc/cmdrun.c prev misc/cmdrun.c exec $CC $CCFLAGS -c misc/cmdrun.c done cmdrun.o make cmdwait.o make misc/cmdwait.c attr perm attr scan prev misc/cmdlib.h done misc/cmdwait.c prev misc/cmdwait.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/cmdwait.c done cmdwait.o make cmdkill.o make misc/cmdkill.c attr perm attr scan prev misc/cmdlib.h done misc/cmdkill.c prev misc/cmdkill.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/cmdkill.c done cmdkill.o make recomp.o make re/recomp.c attr perm attr scan make re/relib.h attr perm attr scan attr impl prev limits.h make include/re.h attr perm attr scan attr impl done include/re.h done re/relib.h done re/recomp.c prev re/recomp.c exec $CC $CCFLAGS -I. -Ire -Iinclude "$DEBUG" -c re/recomp.c done recomp.o make reerror.o make re/reerror.c attr perm attr scan prev include/error.h prev include/re.h done re/reerror.c prev re/reerror.c exec $CC $CCFLAGS -Iinclude -c re/reerror.c done reerror.o make reexec.o make re/reexec.c attr perm attr scan prev /usr/include/ctype.h prev re/relib.h done re/reexec.c prev re/reexec.c exec $CC $CCFLAGS -I. -Ire -Iinclude "$DEBUG" -c re/reexec.c done reexec.o make resub.o make re/resub.c attr perm attr scan prev /usr/include/ctype.h prev re/relib.h done re/resub.c prev re/resub.c exec $CC $CCFLAGS -I. -Ire -Iinclude -c re/resub.c done resub.o make tmdate.o make tm/tmdate.c attr perm attr scan prev /usr/include/ctype.h prev include/tm.h done tm/tmdate.c prev tm/tmdate.c exec $CC $CCFLAGS -Iinclude -c tm/tmdate.c done tmdate.o make tmfix.o make tm/tmfix.c attr perm attr scan prev include/tm.h done tm/tmfix.c prev tm/tmfix.c exec $CC $CCFLAGS -Iinclude -c tm/tmfix.c done tmfix.o make tmform.o make tm/tmform.c attr perm attr scan prev include/stdio.h prev include/tm.h done tm/tmform.c prev tm/tmform.c exec $CC $CCFLAGS -Iinclude -c tm/tmform.c done tmform.o make tmgoff.o make tm/tmgoff.c attr perm attr scan prev /usr/include/ctype.h prev include/tm.h done tm/tmgoff.c prev tm/tmgoff.c exec $CC $CCFLAGS -Iinclude -c tm/tmgoff.c done tmgoff.o make tminit.o make tm/tminit.c attr perm attr scan prev include/namval.h prev /usr/include/ctype.h prev include/tm.h done tm/tminit.c prev tm/tminit.c exec $CC $CCFLAGS -Iinclude -c tm/tminit.c done tminit.o make tmleap.o make tm/tmleap.c attr perm attr scan prev include/tm.h done tm/tmleap.c prev tm/tmleap.c exec $CC $CCFLAGS -Iinclude -c tm/tmleap.c done tmleap.o make tmlex.o make tm/tmlex.c attr perm attr scan prev /usr/include/ctype.h prev include/tm.h done tm/tmlex.c prev tm/tmlex.c exec $CC $CCFLAGS -Iinclude -c tm/tmlex.c done tmlex.o make tmmake.o make tm/tmmake.c attr perm attr scan prev include/tm.h done tm/tmmake.c prev tm/tmmake.c exec $CC $CCFLAGS -Iinclude -c tm/tmmake.c done tmmake.o make tmpoff.o make tm/tmpoff.c attr perm attr scan prev include/stdio.h prev include/tm.h done tm/tmpoff.c prev tm/tmpoff.c exec $CC $CCFLAGS -Iinclude -c tm/tmpoff.c done tmpoff.o make tmtime.o make tm/tmtime.c attr perm attr scan prev include/tm.h done tm/tmtime.c prev tm/tmtime.c exec $CC $CCFLAGS -Iinclude -c tm/tmtime.c done tmtime.o make tmtype.o make tm/tmtype.c attr perm attr scan prev include/tm.h done tm/tmtype.c prev tm/tmtype.c exec $CC $CCFLAGS -Iinclude -c tm/tmtype.c done tmtype.o make tmword.o make tm/tmword.c attr perm attr scan prev /usr/include/ctype.h prev include/tm.h done tm/tmword.c prev tm/tmword.c exec $CC $CCFLAGS -Iinclude -c tm/tmword.c done tmword.o make tmzone.o make tm/tmzone.c attr perm attr scan prev include/tm.h done tm/tmzone.c prev tm/tmzone.c exec $CC $CCFLAGS -Iinclude -c tm/tmzone.c done tmzone.o make vecargs.o make vec/vecargs.c attr perm attr scan prev /usr/include/ctype.h done vec/vecargs.c prev vec/vecargs.c exec $CC $CCFLAGS -c vec/vecargs.c done vecargs.o make vecfile.o make vec/vecfile.c attr perm attr scan prev /usr/include/sys/stat.h prev /usr/include/sys/types.h done vec/vecfile.c prev vec/vecfile.c exec $CC $CCFLAGS -c vec/vecfile.c done vecfile.o make vecfree.o make vec/vecfree.c attr perm attr scan done vec/vecfree.c prev vec/vecfree.c exec $CC $CCFLAGS -c vec/vecfree.c done vecfree.o make vecload.o make vec/vecload.c attr perm attr scan done vec/vecload.c prev vec/vecload.c exec $CC $CCFLAGS -c vec/vecload.c done vecload.o make vecstring.o make vec/vecstring.c attr perm attr scan done vec/vecstring.c prev vec/vecstring.c exec $CC $CCFLAGS -c vec/vecstring.c done vecstring.o make getsymlink.o make misc/getsymlink.c attr perm attr scan make misc/univlib.h attr perm attr scan attr impl prev /usr/include/errno.h prev limits.h make FEATURE/universe exec : generate local FEATURE information for universe .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for universe */' .... case "universe" in .... *.*) f=universe .... i=universe .... ;; .... *) f=universe .... i=universe .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/universe .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/universe done misc/univlib.h done misc/getsymlink.c prev misc/getsymlink.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/getsymlink.c done getsymlink.o make putsymlink.o make misc/putsymlink.c attr perm attr scan prev misc/univlib.h done misc/putsymlink.c prev misc/putsymlink.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/putsymlink.c done putsymlink.o make univdata.o make misc/univdata.c attr perm attr scan prev misc/univlib.h done misc/univdata.c prev misc/univdata.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/univdata.c done univdata.o make getuniv.o make misc/getuniv.c attr perm attr scan prev misc/univlib.h done misc/getuniv.c prev misc/getuniv.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/getuniv.c done getuniv.o make setuniv.o make misc/setuniv.c attr perm attr scan prev misc/univlib.h done misc/setuniv.c prev misc/setuniv.c exec $CC $CCFLAGS -I. -Imisc -Iinclude -c misc/setuniv.c done setuniv.o make winsize.o make port/winsize.c attr perm attr scan make FEATURE/jioctl exec : generate local FEATURE information for jioctl .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for jioctl */' .... case "jioctl" in .... *.*) f=jioctl .... i=jioctl .... ;; .... *) f=jioctl .... i=jioctl .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/jioctl .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/jioctl make ttyinfo.h prev mkhdr exec mkhdr ttyinfo "" "$CC" $CCFLAGS > ttyinfo.h attr scan attr impl done ttyinfo.h done port/winsize.c prev port/winsize.c exec $CC $CCFLAGS -I. -c port/winsize.c done winsize.o make fclex.o make port/fclex.c attr perm attr scan make /usr/include/fcntl.h attr perm attr scan attr impl done /usr/include/fcntl.h prev /usr/include/errno.h done port/fclex.c prev port/fclex.c exec $CC $CCFLAGS -c port/fclex.c done fclex.o make sigdata.o make port/sigdata.c attr perm attr scan make sigdata.h prev mkhdr prev genhdr exec mkhdr sigdata " genhdr" "$CC" $CCFLAGS > sigdata.h attr scan attr impl done sigdata.h done port/sigdata.c prev port/sigdata.c exec $CC $CCFLAGS -I. -c port/sigdata.c done sigdata.o make touch.o make port/touch.c attr perm attr scan make FEATURE/utime exec : generate local FEATURE information for utime .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for utime */' .... case "utime" in .... *.*) f=utime .... i=utime .... ;; .... *) f=utime .... i=utime .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/utime .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/utime prev /usr/include/errno.h prev /usr/include/sys/stat.h prev /usr/include/sys/types.h done port/touch.c prev port/touch.c exec $CC $CCFLAGS -I. -c port/touch.c done touch.o make lpstat.o make misc/lpstat.c attr perm attr scan prev /usr/include/sys/stat.h prev /usr/include/sys/types.h done misc/lpstat.c prev misc/lpstat.c exec $CC $CCFLAGS -c misc/lpstat.c done lpstat.o make memcmp.o make comp/memcmp.c attr perm attr scan make FEATURE/memcmp exec : generate local FEATURE information for memcmp .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for memcmp */' .... case "memcmp" in .... *.*) f=memcmp .... i=memcmp .... ;; .... *) f=memcmp .... i=memcmp .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/memcmp .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/memcmp done comp/memcmp.c prev comp/memcmp.c exec $CC $CCFLAGS -I. -c comp/memcmp.c done memcmp.o make memcpy.o make comp/memcpy.c attr perm attr scan make FEATURE/bcopy done FEATURE/bcopy make FEATURE/memcpy exec : generate local FEATURE information for memcpy .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for memcpy */' .... case "memcpy" in .... *.*) f=memcpy .... i=memcpy .... ;; .... *) f=memcpy .... i=memcpy .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/memcpy .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/memcpy done comp/memcpy.c prev comp/memcpy.c exec $CC $CCFLAGS -I. -c comp/memcpy.c done memcpy.o make memdup.o make string/memdup.c attr perm attr scan make FEATURE/memdup exec : generate local FEATURE information for memdup .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for memdup */' .... case "memdup" in .... *.*) f=memdup .... i=memdup .... ;; .... *) f=memdup .... i=memdup .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/memdup .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/memdup done string/memdup.c prev string/memdup.c exec $CC $CCFLAGS -I. -c string/memdup.c done memdup.o make memset.o make comp/memset.c attr perm attr scan make FEATURE/memset exec : generate local FEATURE information for memset .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for memset */' .... case "memset" in .... *.*) f=memset .... i=memset .... ;; .... *) f=memset .... i=memset .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/memset .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/memset done comp/memset.c prev comp/memset.c exec $CC $CCFLAGS -I. -c comp/memset.c done memset.o make mkdir.o make comp/mkdir.c attr perm attr scan make FEATURE/mkdir exec : generate local FEATURE information for mkdir .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for mkdir */' .... case "mkdir" in .... *.*) f=mkdir .... i=mkdir .... ;; .... *) f=mkdir .... i=mkdir .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/mkdir .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/mkdir done comp/mkdir.c prev comp/mkdir.c exec $CC $CCFLAGS -I. -c comp/mkdir.c done mkdir.o make rmdir.o make comp/rmdir.c attr perm attr scan make FEATURE/rmdir exec : generate local FEATURE information for rmdir .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for rmdir */' .... case "rmdir" in .... *.*) f=rmdir .... i=rmdir .... ;; .... *) f=rmdir .... i=rmdir .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/rmdir .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/rmdir done comp/rmdir.c prev comp/rmdir.c exec $CC $CCFLAGS -I. -c comp/rmdir.c done rmdir.o make remove.o make comp/remove.c attr perm attr scan make FEATURE/remove exec : generate local FEATURE information for remove .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for remove */' .... case "remove" in .... *.*) f=remove .... i=remove .... ;; .... *) f=remove .... i=remove .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/remove .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/remove done comp/remove.c prev comp/remove.c exec $CC $CCFLAGS -I. -c comp/remove.c done remove.o make rename.o make comp/rename.c attr perm attr scan make FEATURE/rename exec : generate local FEATURE information for rename .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for rename */' .... case "rename" in .... *.*) f=rename .... i=rename .... ;; .... *) f=rename .... i=rename .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/rename .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/rename done comp/rename.c prev comp/rename.c exec $CC $CCFLAGS -I. -c comp/rename.c done rename.o make link.o make comp/link.c attr perm attr scan make FEATURE/link exec : generate local FEATURE information for link .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for link */' .... case "link" in .... *.*) f=link .... i=link .... ;; .... *) f=link .... i=link .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/link .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/link done comp/link.c prev comp/link.c exec $CC $CCFLAGS -I. -c comp/link.c done link.o make unlink.o make comp/unlink.c attr perm attr scan make FEATURE/unlink exec : generate local FEATURE information for unlink .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for unlink */' .... case "unlink" in .... *.*) f=unlink .... i=unlink .... ;; .... *) f=unlink .... i=unlink .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/unlink .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/unlink done comp/unlink.c prev comp/unlink.c exec $CC $CCFLAGS -I. -c comp/unlink.c done unlink.o make strtok.o make comp/strtok.c attr perm attr scan make FEATURE/strtok exec : generate local FEATURE information for strtok .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strtok */' .... case "strtok" in .... *.*) f=strtok .... i=strtok .... ;; .... *) f=strtok .... i=strtok .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strtok .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strtok done comp/strtok.c prev comp/strtok.c exec $CC $CCFLAGS -I. -c comp/strtok.c done strtok.o make strspn.o make comp/strspn.c attr perm attr scan make FEATURE/strspn exec : generate local FEATURE information for strspn .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strspn */' .... case "strspn" in .... *.*) f=strspn .... i=strspn .... ;; .... *) f=strspn .... i=strspn .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strspn .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strspn done comp/strspn.c prev comp/strspn.c exec $CC $CCFLAGS -I. -c comp/strspn.c done strspn.o make strpbrk.o make comp/strpbrk.c attr perm attr scan make FEATURE/strpbrk exec : generate local FEATURE information for strpbrk .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strpbrk */' .... case "strpbrk" in .... *.*) f=strpbrk .... i=strpbrk .... ;; .... *) f=strpbrk .... i=strpbrk .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strpbrk .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strpbrk done comp/strpbrk.c prev comp/strpbrk.c exec $CC $CCFLAGS -I. -c comp/strpbrk.c done strpbrk.o make strdup.o make string/strdup.c attr perm attr scan make FEATURE/strdup exec : generate local FEATURE information for strdup .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strdup */' .... case "strdup" in .... *.*) f=strdup .... i=strdup .... ;; .... *) f=strdup .... i=strdup .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strdup .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strdup done string/strdup.c prev string/strdup.c exec $CC $CCFLAGS -I. -c string/strdup.c done strdup.o make strchr.o make comp/strchr.c attr perm attr scan make FEATURE/index exec : generate local FEATURE information for index .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for index */' .... case "index" in .... *.*) f=index .... i=index .... ;; .... *) f=index .... i=index .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/index .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/index make FEATURE/strchr exec : generate local FEATURE information for strchr .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strchr */' .... case "strchr" in .... *.*) f=strchr .... i=strchr .... ;; .... *) f=strchr .... i=strchr .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strchr .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strchr done comp/strchr.c prev comp/strchr.c exec $CC $CCFLAGS -I. -c comp/strchr.c done strchr.o make strrchr.o make comp/strrchr.c attr perm attr scan make FEATURE/rindex exec : generate local FEATURE information for rindex .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for rindex */' .... case "rindex" in .... *.*) f=rindex .... i=rindex .... ;; .... *) f=rindex .... i=rindex .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/rindex .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/rindex make FEATURE/strrchr exec : generate local FEATURE information for strrchr .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strrchr */' .... case "strrchr" in .... *.*) f=strrchr .... i=strrchr .... ;; .... *) f=strrchr .... i=strrchr .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strrchr .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strrchr done comp/strrchr.c prev comp/strrchr.c exec $CC $CCFLAGS -I. -c comp/strrchr.c done strrchr.o make strtod.o make comp/strtod.c attr perm attr scan make FEATURE/strtod exec : generate local FEATURE information for strtod .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strtod */' .... case "strtod" in .... *.*) f=strtod .... i=strtod .... ;; .... *) f=strtod .... i=strtod .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strtod .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strtod done comp/strtod.c prev comp/strtod.c exec $CC $CCFLAGS -I. -c comp/strtod.c done strtod.o make strtol.o make comp/strtol.c attr perm attr scan make FEATURE/strtol exec : generate local FEATURE information for strtol .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for strtol */' .... case "strtol" in .... *.*) f=strtol .... i=strtol .... ;; .... *) f=strtol .... i=strtol .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/strtol .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/strtol done comp/strtol.c prev comp/strtol.c exec $CC $CCFLAGS -I. -c comp/strtol.c done strtol.o make strton.o make string/strton.c attr perm attr scan done string/strton.c prev string/strton.c exec $CC $CCFLAGS -c string/strton.c done strton.o make sigsetmask.o make comp/sigsetmask.c attr perm attr scan prev FEATURE/sigsetmask done comp/sigsetmask.c prev comp/sigsetmask.c exec $CC $CCFLAGS -I. -c comp/sigsetmask.c done sigsetmask.o make mktemp.o make comp/mktemp.c attr perm attr scan make FEATURE/mktemp exec : generate local FEATURE information for mktemp .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for mktemp */' .... case "mktemp" in .... *.*) f=mktemp .... i=mktemp .... ;; .... *) f=mktemp .... i=mktemp .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/mktemp .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/mktemp done comp/mktemp.c prev comp/mktemp.c exec $CC $CCFLAGS -I. -c comp/mktemp.c done mktemp.o make tmpnam.o make comp/tmpnam.c attr perm attr scan make FEATURE/tmpnam exec : generate local FEATURE information for tmpnam .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for tmpnam */' .... case "tmpnam" in .... *.*) f=tmpnam .... i=tmpnam .... ;; .... *) f=tmpnam .... i=tmpnam .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/tmpnam .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/tmpnam done comp/tmpnam.c prev comp/tmpnam.c exec $CC $CCFLAGS -I. -Iinclude -c comp/tmpnam.c done tmpnam.o make vfork.o make comp/vfork.c attr perm attr scan make FEATURE/vfork exec : generate local FEATURE information for vfork .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for vfork */' .... case "vfork" in .... *.*) f=vfork .... i=vfork .... ;; .... *) f=vfork .... i=vfork .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/vfork .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/vfork done comp/vfork.c prev comp/vfork.c exec $CC $CCFLAGS -I. -c comp/vfork.c done vfork.o make killpg.o make comp/killpg.c attr perm attr scan make FEATURE/killpg exec : generate local FEATURE information for killpg .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for killpg */' .... case "killpg" in .... *.*) f=killpg .... i=killpg .... ;; .... *) f=killpg .... i=killpg .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/killpg .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/killpg done comp/killpg.c prev comp/killpg.c exec $CC $CCFLAGS -I. -c comp/killpg.c done killpg.o make lstat.o make comp/lstat.c attr perm attr scan make FEATURE/lstat exec : generate local FEATURE information for lstat .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for lstat */' .... case "lstat" in .... *.*) f=lstat .... i=lstat .... ;; .... *) f=lstat .... i=lstat .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/lstat .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/lstat done comp/lstat.c prev comp/lstat.c exec $CC $CCFLAGS -I. -c comp/lstat.c done lstat.o make readlink.o make comp/readlink.c attr perm attr scan make FEATURE/readlink exec : generate local FEATURE information for readlink .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for readlink */' .... case "readlink" in .... *.*) f=readlink .... i=readlink .... ;; .... *) f=readlink .... i=readlink .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/readlink .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/readlink done comp/readlink.c prev comp/readlink.c exec $CC $CCFLAGS -I. -c comp/readlink.c done readlink.o make symlink.o make comp/symlink.c attr perm attr scan make FEATURE/symlink exec : generate local FEATURE information for symlink .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for symlink */' .... case "symlink" in .... *.*) f=symlink .... i=symlink .... ;; .... *) f=symlink .... i=symlink .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/symlink .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/symlink done comp/symlink.c prev comp/symlink.c exec $CC $CCFLAGS -I. -c comp/symlink.c done symlink.o make setpgid.o make comp/setpgid.c attr perm attr scan make FEATURE/setpgid exec : generate local FEATURE information for setpgid .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for setpgid */' .... case "setpgid" in .... *.*) f=setpgid .... i=setpgid .... ;; .... *) f=setpgid .... i=setpgid .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/setpgid .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/setpgid done comp/setpgid.c prev comp/setpgid.c exec $CC $CCFLAGS -I. -c comp/setpgid.c done setpgid.o make atexit.o make comp/atexit.c attr perm attr scan make FEATURE/_cleanup exec : generate local FEATURE information for _cleanup .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for _cleanup */' .... case "_cleanup" in .... *.*) f=_cleanup .... i=_cleanup .... ;; .... *) f=_cleanup .... i=_cleanup .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/_cleanup .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/_cleanup make FEATURE/on_exit exec : generate local FEATURE information for on_exit .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for on_exit */' .... case "on_exit" in .... *.*) f=on_exit .... i=on_exit .... ;; .... *) f=on_exit .... i=on_exit .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/on_exit .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/on_exit make FEATURE/onexit exec : generate local FEATURE information for onexit .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for onexit */' .... case "onexit" in .... *.*) f=onexit .... i=onexit .... ;; .... *) f=onexit .... i=onexit .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/onexit .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/onexit make FEATURE/atexit exec : generate local FEATURE information for atexit .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for atexit */' .... case "atexit" in .... *.*) f=atexit .... i=atexit .... ;; .... *) f=atexit .... i=atexit .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/atexit .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/atexit done comp/atexit.c prev comp/atexit.c exec $CC $CCFLAGS -I. -c comp/atexit.c done atexit.o make getdents.o make comp/getdents.c attr perm attr scan prev FEATURE/dir make FEATURE/readdir exec : generate local FEATURE information for readdir .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for readdir */' .... case "readdir" in .... *.*) f=readdir .... i=readdir .... ;; .... *) f=readdir .... i=readdir .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/readdir .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/readdir make FEATURE/dirread exec : generate local FEATURE information for dirread .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for dirread */' .... case "dirread" in .... *.*) f=dirread .... i=dirread .... ;; .... *) f=dirread .... i=dirread .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/dirread .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/dirread make FEATURE/getdirentries exec : generate local FEATURE information for getdirentries .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for getdirentries */' .... case "getdirentries" in .... *.*) f=getdirentries .... i=getdirentries .... ;; .... *) f=getdirentries .... i=getdirentries .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/getdirentries .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/getdirentries prev dirent.h prev fsinfo.h prev FEATURE/getdents done comp/getdents.c prev comp/getdents.c exec $CC $CCFLAGS -I. -c comp/getdents.c done getdents.o make getwd.o make misc/getwd.c attr perm attr scan prev limits.h done misc/getwd.c prev misc/getwd.c exec $CC $CCFLAGS -I. -c misc/getwd.c done getwd.o make copy.o make port/copy.c attr perm attr scan make FEATURE/mmap exec : generate local FEATURE information for mmap .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for mmap */' .... case "mmap" in .... *.*) f=mmap .... i=mmap .... ;; .... *) f=mmap .... i=mmap .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/mmap .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/mmap done port/copy.c prev port/copy.c exec $CC $CCFLAGS -I. -c port/copy.c done copy.o make dup2.o make comp/dup2.c attr perm attr scan make FEATURE/dup2 exec : generate local FEATURE information for dup2 .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for dup2 */' .... case "dup2" in .... *.*) f=dup2 .... i=dup2 .... ;; .... *) f=dup2 .... i=dup2 .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/dup2 .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/dup2 done comp/dup2.c prev comp/dup2.c exec $CC $CCFLAGS -I. -c comp/dup2.c done dup2.o make errno.o make comp/errno.c attr perm attr scan done comp/errno.c prev comp/errno.c exec $CC $CCFLAGS -c comp/errno.c done errno.o make sgetl.o make comp/sgetl.c attr perm attr scan prev limits.h make FEATURE/sgetl exec : generate local FEATURE information for sgetl .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for sgetl */' .... case "sgetl" in .... *.*) f=sgetl .... i=sgetl .... ;; .... *) f=sgetl .... i=sgetl .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/sgetl .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/sgetl done comp/sgetl.c prev comp/sgetl.c exec $CC $CCFLAGS -I. -c comp/sgetl.c done sgetl.o make sputl.o make comp/sputl.c attr perm attr scan prev limits.h make FEATURE/sputl exec : generate local FEATURE information for sputl .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for sputl */' .... case "sputl" in .... *.*) f=sputl .... i=sputl .... ;; .... *) f=sputl .... i=sputl .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/sputl .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/sputl done comp/sputl.c prev comp/sputl.c exec $CC $CCFLAGS -I. -c comp/sputl.c done sputl.o make getpreroot.o make preroot/getpreroot.c attr perm attr scan prev limits.h prev dirent.h prev preroot.h done preroot/getpreroot.c prev preroot/getpreroot.c exec $CC $CCFLAGS -I. -Iinclude -c preroot/getpreroot.c done getpreroot.o make ispreroot.o make preroot/ispreroot.c attr perm attr scan prev preroot.h done preroot/ispreroot.c prev preroot/ispreroot.c exec $CC $CCFLAGS -I. -c preroot/ispreroot.c done ispreroot.o make realopen.o make preroot/realopen.c attr perm attr scan prev limits.h prev preroot.h done preroot/realopen.c prev preroot/realopen.c exec $CC $CCFLAGS -I. -c preroot/realopen.c done realopen.o make setpreroot.o make preroot/setpreroot.c attr perm attr scan prev limits.h prev preroot.h done preroot/setpreroot.c prev preroot/setpreroot.c exec $CC $CCFLAGS -I. -Iinclude -c preroot/setpreroot.c done setpreroot.o make mount.o make comp/mount.c attr perm attr scan make FEATURE/mount exec : generate local FEATURE information for mount .... set - .... if test ! -d FEATURE .... then rm -rf FEATURE .... mkdir FEATURE .... fi .... { .... echo '/* local info for mount */' .... case "mount" in .... *.*) f=mount .... i=mount .... ;; .... *) f=mount .... i=mount .... echo "#undef $i .... int $i;" > x.${!-$$}.c .... cmd=: .... opt= .... if $CC $CCFLAGS -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then if $CC $CCFLAGS -Bstatic -o x.${!-$$}.x x.${!-$$}.c > /dev/null 2>&1 .... then opt=-Bstatic .... else cmd=x.${!-$$}.x .... fi .... fi .... echo "#undef $i .... extern int $i();static int ((*i)())=$i;main(){exit(i==(int((*)()))0);}" > x.${!-$$}.c .... if $CC $CCFLAGS $opt -c x.${!-$$}.c > /dev/null 2>&1 .... then if { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o && $cmd ;} > /dev/null 2>&1 .... then echo "#define _lib_$i 1 /* $i() in default lib(s) */" .... elif { $CC $CCFLAGS $opt -o x.${!-$$}.x x.${!-$$}.o -lm && $cmd ;} > /dev/null 2>&1 .... then echo "#define _mth_$i 1 /* $i() in math lib */" .... fi .... fi .... ;; .... esac .... echo "#include \"$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _hdr_$i 1 /* #include \"$f.h\" ok */" .... fi .... echo "#include \"sys/$f.h\"" > x.${!-$$}.c .... if $CC $CCFLAGS -E x.${!-$$}.c > /dev/null 2>&1 .... then echo "#define _sys_$i 1 /* #include \"sys/$f.h\" ok */" .... fi .... for j in / /usr/ .... do for i in bin etc ucb .... do if test -f $j$i/$f .... then echo "#define _bin_$f 1 /* $f in ?(/usr)/(bin|etc|ucb) */" .... break 2 .... fi .... done .... done .... } > FEATURE/mount .... rm -rf x.${!-$$}.c x.${!-$$}.o x.${!-$$}.x attr scan attr impl done FEATURE/mount done comp/mount.c prev comp/mount.c exec $CC $CCFLAGS -I. -c comp/mount.c done mount.o make popen.o make comp/popen.c attr perm attr scan prev include/stdio.h done comp/popen.c prev comp/popen.c exec $CC $CCFLAGS -Iinclude -c comp/popen.c done popen.o make system.o make comp/system.c attr perm attr scan done comp/system.c prev comp/system.c exec $CC $CCFLAGS -c comp/system.c done system.o make iblocks.o make port/iblocks.c attr perm attr scan prev fsinfo.h prev lclparam.h done port/iblocks.c prev port/iblocks.c exec $CC $CCFLAGS -I. -c port/iblocks.c done iblocks.o make modedata.o make string/modedata.c attr perm attr scan prev /usr/include/sys/stat.h prev /usr/include/sys/types.h prev string/modelib.h done string/modedata.c prev string/modedata.c exec $CC $CCFLAGS -Istring -c string/modedata.c done modedata.o make tmdata.o make tm/tmdata.c attr perm attr scan prev include/tm.h done tm/tmdata.c prev tm/tmdata.c exec $CC $CCFLAGS -Iinclude -c tm/tmdata.c done tmdata.o make sfclose.o make sfio/sfclose.c attr perm attr scan make sfio/sfhdr.h attr perm attr scan attr impl make FEATURE/on_exit done FEATURE/on_exit make FEATURE/onexit done FEATURE/onexit prev FEATURE/atexit prev FEATURE/bcopy done sfio/sfhdr.h done sfio/sfclose.c prev sfio/sfclose.c setv LIBX -DLIBX exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfclose.c done sfclose.o make sfclrlock.o make sfio/sfclrlock.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfclrlock.c prev sfio/sfclrlock.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfclrlock.c done sfclrlock.o make sfcvt.o make sfio/sfcvt.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfcvt.c prev sfio/sfcvt.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfcvt.c done sfcvt.o make sfdlen.o make sfio/sfdlen.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfdlen.c prev sfio/sfdlen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfdlen.c done sfdlen.o make sfdopen.o make sfio/sfdopen.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfdopen.c prev sfio/sfdopen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfdopen.c done sfdopen.o make sfexcept.o make sfio/sfexcept.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfexcept.c prev sfio/sfexcept.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfexcept.c done sfexcept.o make sfextern.o make sfio/sfextern.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfextern.c prev sfio/sfextern.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfextern.c done sfextern.o make sffilbuf.o make sfio/sffilbuf.c attr perm attr scan prev sfio/sfhdr.h done sfio/sffilbuf.c prev sfio/sffilbuf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sffilbuf.c done sffilbuf.o make sfflsbuf.o make sfio/sfflsbuf.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfflsbuf.c prev sfio/sfflsbuf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfflsbuf.c done sfflsbuf.o make sfgetd.o make sfio/sfgetd.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfgetd.c prev sfio/sfgetd.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfgetd.c done sfgetd.o make sfgetl.o make sfio/sfgetl.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfgetl.c prev sfio/sfgetl.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfgetl.c done sfgetl.o make sfgets.o make sfio/sfgets.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfgets.c prev sfio/sfgets.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfgets.c done sfgets.o make sfgetu.o make sfio/sfgetu.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfgetu.c prev sfio/sfgetu.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfgetu.c done sfgetu.o make sfllen.o make sfio/sfllen.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfllen.c prev sfio/sfllen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfllen.c done sfllen.o make sfmode.o make sfio/sfmode.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfmode.c prev sfio/sfmode.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfmode.c done sfmode.o make sfmove.o make sfio/sfmove.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfmove.c prev sfio/sfmove.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfmove.c done sfmove.o make sfnew.o make sfio/sfnew.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfnew.c prev sfio/sfnew.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfnew.c done sfnew.o make sfnotify.o make sfio/sfnotify.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfnotify.c prev sfio/sfnotify.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfnotify.c done sfnotify.o make sfnputc.o make sfio/sfnputc.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfnputc.c prev sfio/sfnputc.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfnputc.c done sfnputc.o make sfopen.o make sfio/sfopen.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfopen.c prev sfio/sfopen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfopen.c done sfopen.o make sfpeek.o make sfio/sfpeek.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfpeek.c prev sfio/sfpeek.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfpeek.c done sfpeek.o make sfpool.o make sfio/sfpool.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfpool.c prev sfio/sfpool.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfpool.c done sfpool.o make sfpopen.o make sfio/sfpopen.c attr perm attr scan prev FEATURE/vfork prev sfio/sfhdr.h done sfio/sfpopen.c prev sfio/sfpopen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfpopen.c done sfpopen.o make sfprintf.o make sfio/sfprintf.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfprintf.c prev sfio/sfprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfprintf.c done sfprintf.o make sfputd.o make sfio/sfputd.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfputd.c prev sfio/sfputd.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfputd.c done sfputd.o make sfputl.o make sfio/sfputl.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfputl.c prev sfio/sfputl.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfputl.c done sfputl.o make sfputs.o make sfio/sfputs.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfputs.c prev sfio/sfputs.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfputs.c done sfputs.o make sfputu.o make sfio/sfputu.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfputu.c prev sfio/sfputu.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfputu.c done sfputu.o make sfread.o make sfio/sfread.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfread.c prev sfio/sfread.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfread.c done sfread.o make sfscanf.o make sfio/sfscanf.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfscanf.c prev sfio/sfscanf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfscanf.c done sfscanf.o make sfseek.o make sfio/sfseek.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfseek.c prev sfio/sfseek.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfseek.c done sfseek.o make sfsetbuf.o make sfio/sfsetbuf.c attr perm attr scan prev fsinfo.h prev sfio/sfhdr.h done sfio/sfsetbuf.c prev sfio/sfsetbuf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfsetbuf.c done sfsetbuf.o make sfsetdisc.o make sfio/sfsetdisc.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfsetdisc.c prev sfio/sfsetdisc.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfsetdisc.c done sfsetdisc.o make sfset.o make sfio/sfset.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfset.c prev sfio/sfset.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfset.c done sfset.o make sfstack.o make sfio/sfstack.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfstack.c prev sfio/sfstack.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfstack.c done sfstack.o make sfstrtod.o make sfio/sfstrtod.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfstrtod.c prev sfio/sfstrtod.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfstrtod.c done sfstrtod.o make sfsync.o make sfio/sfsync.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfsync.c prev sfio/sfsync.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfsync.c done sfsync.o make sftable.o make sfio/sftable.c attr perm attr scan prev sfio/sfhdr.h done sfio/sftable.c prev sfio/sftable.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sftable.c done sftable.o make sftell.o make sfio/sftell.c attr perm attr scan prev sfio/sfhdr.h done sfio/sftell.c prev sfio/sftell.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sftell.c done sftell.o make sftmpfile.o make sfio/sftmpfile.c attr perm attr scan prev sfio/sfhdr.h done sfio/sftmpfile.c prev sfio/sftmpfile.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sftmpfile.c done sftmpfile.o make sfungetc.o make sfio/sfungetc.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfungetc.c prev sfio/sfungetc.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfungetc.c done sfungetc.o make sfvprintf.o make sfio/sfvprintf.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfvprintf.c prev sfio/sfvprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfvprintf.c done sfvprintf.o make sfvscanf.o make sfio/sfvscanf.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfvscanf.c prev sfio/sfvscanf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfvscanf.c done sfvscanf.o make sfwrite.o make sfio/sfwrite.c attr perm attr scan prev sfio/sfhdr.h done sfio/sfwrite.c prev sfio/sfwrite.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/sfwrite.c done sfwrite.o make _sfclearerr.o make sfio/_sfclearerr.c attr perm attr scan make sfio/_sfhdr.h attr perm attr scan attr impl prev sfio/sfhdr.h done sfio/_sfhdr.h done sfio/_sfclearerr.c prev sfio/_sfclearerr.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfclearerr.c done _sfclearerr.o make _sffileno.o make sfio/_sffileno.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sffileno.c prev sfio/_sffileno.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sffileno.c done _sffileno.o make _sforigin.o make sfio/_sforigin.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sforigin.c prev sfio/_sforigin.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sforigin.c done _sforigin.o make _sfputl.o make sfio/_sfputl.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfputl.c prev sfio/_sfputl.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfputl.c done _sfputl.o make _sftmp.o make sfio/_sftmp.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sftmp.c prev sfio/_sftmp.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sftmp.c done _sftmp.o make _sfecvt.o make sfio/_sfecvt.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfecvt.c prev sfio/_sfecvt.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfecvt.c done _sfecvt.o make _sfgetc.o make sfio/_sfgetc.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfgetc.c prev sfio/_sfgetc.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfgetc.c done _sfgetc.o make _sfpeek.o make sfio/_sfpeek.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfpeek.c prev sfio/_sfpeek.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfpeek.c done _sfpeek.o make _sfputu.o make sfio/_sfputu.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfputu.c prev sfio/_sfputu.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfputu.c done _sfputu.o make _sfulen.o make sfio/_sfulen.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfulen.c prev sfio/_sfulen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfulen.c done _sfulen.o make _sfeof.o make sfio/_sfeof.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfeof.c prev sfio/_sfeof.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfeof.c done _sfeof.o make _sfgetl.o make sfio/_sfgetl.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfgetl.c prev sfio/_sfgetl.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfgetl.c done _sfgetl.o make _sfpushed.o make sfio/_sfpushed.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfpushed.c prev sfio/_sfpushed.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfpushed.c done _sfpushed.o make _sfslen.o make sfio/_sfslen.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfslen.c prev sfio/_sfslen.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfslen.c done _sfslen.o make _sferror.o make sfio/_sferror.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sferror.c prev sfio/_sferror.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sferror.c done _sferror.o make _sfgetu.o make sfio/_sfgetu.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfgetu.c prev sfio/_sfgetu.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfgetu.c done _sfgetu.o make _sfputc.o make sfio/_sfputc.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfputc.c prev sfio/_sfputc.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfputc.c done _sfputc.o make _sffcvt.o make sfio/_sffcvt.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sffcvt.c prev sfio/_sffcvt.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sffcvt.c done _sffcvt.o make _sfputd.o make sfio/_sfputd.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfputd.c prev sfio/_sfputd.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfputd.c done _sfputd.o make _sfsync.o make sfio/_sfsync.c attr perm attr scan prev sfio/_sfhdr.h done sfio/_sfsync.c prev sfio/_sfsync.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c sfio/_sfsync.c done _sfsync.o make stdgets.o make stdio/stdgets.c attr perm attr scan prev include/stdio.h prev sfio/sfhdr.h done stdio/stdgets.c prev stdio/stdgets.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdgets.c done stdgets.o make stdprintf.o make stdio/stdprintf.c attr perm attr scan prev include/stdio.h prev sfio/sfhdr.h done stdio/stdprintf.c prev stdio/stdprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdprintf.c done stdprintf.o make stdscanf.o make stdio/stdscanf.c attr perm attr scan prev include/stdio.h prev sfio/sfhdr.h done stdio/stdscanf.c prev stdio/stdscanf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdscanf.c done stdscanf.o make stdsetvbuf.o make stdio/stdsetvbuf.c attr perm attr scan prev include/stdio.h prev sfio/sfhdr.h done stdio/stdsetvbuf.c prev stdio/stdsetvbuf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdsetvbuf.c done stdsetvbuf.o make stdsprintf.o make stdio/stdsprintf.c attr perm attr scan prev include/stdio.h prev sfio/sfhdr.h done stdio/stdsprintf.c prev stdio/stdsprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdsprintf.c done stdsprintf.o make stdvsprintf.o make stdio/stdvsprintf.c attr perm attr scan prev sfio/sfhdr.h done stdio/stdvsprintf.c prev stdio/stdvsprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdvsprintf.c done stdvsprintf.o make stdvsscanf.o make stdio/stdvsscanf.c attr perm attr scan prev sfio/sfhdr.h done stdio/stdvsscanf.c prev stdio/stdvsscanf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/stdvsscanf.c done stdvsscanf.o make sprintf.o make stdio/sprintf.c attr perm attr scan prev stdio/stdsprintf.c prev include/stdio.h prev sfio/sfhdr.h done stdio/sprintf.c prev stdio/sprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/sprintf.c done sprintf.o make vsprintf.o make stdio/vsprintf.c attr perm attr scan prev stdio/stdvsprintf.c prev include/stdio.h prev sfio/sfhdr.h done stdio/vsprintf.c prev stdio/vsprintf.c exec $CC $CCFLAGS -I. -Isfio -Iinclude "$LIBX" -c stdio/vsprintf.c done vsprintf.o exec $AR cr libx.a opendir.o readdir.o rewinddir.o seekdir.o telldir.o getcwd.o setcwd.o getshell.o hashalloc.o hashdump.o hashfree.o hashlook.o hashscan.o hashsize.o hashwalk.o memhash.o memsum.o strhash.o strsum.o cvtatoe.o cvtetoa.o chresc.o ctoi.o streval.o strmatch.o strcopy.o strmode.o stresc.o stropt.o strtape.o tok.o pathaccess.o pathcanon.o pathcheck.o pathpath.o pathkey.o pathprobe.o pathtemp.o cmdargs.o fs3d.o ftwalk.o perror.o putenv.o calloc.o malloc.o getnamval.o optget.o hsort.o query.o error.o liberror.o strerror.o strsignal.o fmtelapsed.o fmtls.o fmtmode.o fmtperm.o fmtuid.o fmtgid.o strelapsed.o strperm.o struid.o strgid.o stack.o stak.o memswap.o gethalf.o getlong.o puthalf.o putlong.o fgetline.o sigcrit.o sigunblock.o cmdopen.o cmdclose.o cmdrun.o cmdwait.o cmdkill.o recomp.o reerror.o reexec.o resub.o tmdate.o tmfix.o tmform.o tmgoff.o tminit.o tmleap.o tmlex.o tmmake.o tmpoff.o tmtime.o tmtype.o tmword.o tmzone.o vecargs.o vecfile.o vecfree.o vecload.o vecstring.o getsymlink.o putsymlink.o univdata.o getuniv.o setuniv.o winsize.o fclex.o sigdata.o touch.o lpstat.o memcmp.o memcpy.o memdup.o memset.o mkdir.o rmdir.o remove.o rename.o link.o unlink.o strtok.o strspn.o strpbrk.o strdup.o strchr.o strrchr.o strtod.o strtol.o strton.o sigsetmask.o mktemp.o tmpnam.o vfork.o killpg.o lstat.o readlink.o symlink.o setpgid.o atexit.o getdents.o getwd.o copy.o dup2.o errno.o sgetl.o sputl.o getpreroot.o ispreroot.o realopen.o setpreroot.o mount.o popen.o system.o iblocks.o modedata.o tmdata.o sfclose.o sfclrlock.o sfcvt.o sfdlen.o sfdopen.o sfexcept.o sfextern.o sffilbuf.o sfflsbuf.o sfgetd.o sfgetl.o sfgets.o sfgetu.o sfllen.o sfmode.o sfmove.o sfnew.o sfnotify.o sfnputc.o sfopen.o sfpeek.o sfpool.o sfpopen.o sfprintf.o sfputd.o sfputl.o sfputs.o sfputu.o sfread.o sfscanf.o sfseek.o sfsetbuf.o sfsetdisc.o sfset.o sfstack.o sfstrtod.o sfsync.o sftable.o sftell.o sftmpfile.o sfungetc.o sfvprintf.o sfvscanf.o sfwrite.o _sfclearerr.o _sffileno.o _sforigin.o _sfputl.o _sftmp.o _sfecvt.o _sfgetc.o _sfpeek.o _sfputu.o _sfulen.o _sfeof.o _sfgetl.o _sfpushed.o _sfslen.o _sferror.o _sfgetu.o _sfputc.o _sffcvt.o _sfputd.o _sfsync.o stdgets.o stdprintf.o stdscanf.o stdsetvbuf.o stdsprintf.o stdvsprintf.o stdvsscanf.o sprintf.o vsprintf.o exec (ranlib libx.a) >/dev/null 2>&1 || true done libx.a prev mkhdr prev genhdr done all make $INSTALLROOT/lib exec if test ! -d $INSTALLROOT/lib .... then rm -rf $INSTALLROOT/lib && mkdir $INSTALLROOT/lib || { rm -rf $INSTALLROOT && mkdir $INSTALLROOT && mkdir $INSTALLROOT/lib ;} || true .... fi done $INSTALLROOT/lib make $INSTALLROOT/lib/libx.a attr arch prev libx.a exec { cp libx.a $INSTALLROOT/lib/libx.a 2>/dev/null ;} || true exec (ranlib $INSTALLROOT/lib/libx.a) >/dev/null 2>&1 || true done $INSTALLROOT/lib/libx.a make $INSTALLROOT/man/man3 exec if test ! -d $INSTALLROOT/man/man3 .... then rm -rf $INSTALLROOT/man/man3 && mkdir $INSTALLROOT/man/man3 || { rm -rf $INSTALLROOT/man && mkdir $INSTALLROOT/man && mkdir $INSTALLROOT/man/man3 ;} || true .... fi done $INSTALLROOT/man/man3 make $INSTALLROOT/man/man3/hash.3 make man/hash.3 attr perm done man/hash.3 exec { cp man/hash.3 $INSTALLROOT/man/man3/hash.3 2>/dev/null ;} || true done $INSTALLROOT/man/man3/hash.3 make $INSTALLROOT/man/man3/ftwalk.3 make man/ftwalk.3 attr perm done man/ftwalk.3 exec { cp man/ftwalk.3 $INSTALLROOT/man/man3/ftwalk.3 2>/dev/null ;} || true done $INSTALLROOT/man/man3/ftwalk.3 make $INSTALLROOT/man/man3/re.3 make man/re.3 attr perm done man/re.3 exec { cp man/re.3 $INSTALLROOT/man/man3/re.3 2>/dev/null ;} || true done $INSTALLROOT/man/man3/re.3 make $INSTALLROOT/man/man3/sfio.3 make man/sfio.3 attr perm done man/sfio.3 exec { cp man/sfio.3 $INSTALLROOT/man/man3/sfio.3 2>/dev/null ;} || true done $INSTALLROOT/man/man3/sfio.3 make $INSTALLROOT/man/man3/stak.3 make man/stak.3 attr perm done man/stak.3 exec { cp man/stak.3 $INSTALLROOT/man/man3/stak.3 2>/dev/null ;} || true done $INSTALLROOT/man/man3/stak.3 make $INSTALLROOT/man/man3/tm.3 make man/tm.3 attr perm done man/tm.3 exec { cp man/tm.3 $INSTALLROOT/man/man3/tm.3 2>/dev/null ;} || true done $INSTALLROOT/man/man3/tm.3 make $INSTALLROOT/include exec if test ! -d $INSTALLROOT/include .... then rm -rf $INSTALLROOT/include && mkdir $INSTALLROOT/include || { rm -rf $INSTALLROOT && mkdir $INSTALLROOT && mkdir $INSTALLROOT/include ;} || true .... fi done $INSTALLROOT/include make $INSTALLROOT/include/error.h prev include/error.h exec { cp include/error.h $INSTALLROOT/include/error.h 2>/dev/null ;} || true done $INSTALLROOT/include/error.h make $INSTALLROOT/include/ftwalk.h prev include/ftwalk.h exec { cp include/ftwalk.h $INSTALLROOT/include/ftwalk.h 2>/dev/null ;} || true done $INSTALLROOT/include/ftwalk.h make $INSTALLROOT/include/hash.h prev include/hash.h exec { cp include/hash.h $INSTALLROOT/include/hash.h 2>/dev/null ;} || true done $INSTALLROOT/include/hash.h make $INSTALLROOT/include/hashpart.h exec { cp include/hashpart.h $INSTALLROOT/include/hashpart.h 2>/dev/null ;} || true done $INSTALLROOT/include/hashpart.h make $INSTALLROOT/include/ls.h exec { cp include/ls.h $INSTALLROOT/include/ls.h 2>/dev/null ;} || true done $INSTALLROOT/include/ls.h make $INSTALLROOT/include/namval.h prev include/namval.h exec { cp include/namval.h $INSTALLROOT/include/namval.h 2>/dev/null ;} || true done $INSTALLROOT/include/namval.h make $INSTALLROOT/include/option.h exec { cp include/option.h $INSTALLROOT/include/option.h 2>/dev/null ;} || true done $INSTALLROOT/include/option.h make $INSTALLROOT/include/re.h prev include/re.h exec { cp include/re.h $INSTALLROOT/include/re.h 2>/dev/null ;} || true done $INSTALLROOT/include/re.h make $INSTALLROOT/include/sfio.h exec { cp include/sfio.h $INSTALLROOT/include/sfio.h 2>/dev/null ;} || true done $INSTALLROOT/include/sfio.h make $INSTALLROOT/include/stack.h prev include/stack.h exec { cp include/stack.h $INSTALLROOT/include/stack.h 2>/dev/null ;} || true done $INSTALLROOT/include/stack.h make $INSTALLROOT/include/stak.h prev include/stak.h exec { cp include/stak.h $INSTALLROOT/include/stak.h 2>/dev/null ;} || true done $INSTALLROOT/include/stak.h make $INSTALLROOT/include/stdio.h prev include/stdio.h exec { cp include/stdio.h $INSTALLROOT/include/stdio.h 2>/dev/null ;} || true done $INSTALLROOT/include/stdio.h make $INSTALLROOT/include/swap.h prev include/swap.h exec { cp include/swap.h $INSTALLROOT/include/swap.h 2>/dev/null ;} || true done $INSTALLROOT/include/swap.h make $INSTALLROOT/include/tar.h make include/tar.h attr perm done include/tar.h exec { cp include/tar.h $INSTALLROOT/include/tar.h 2>/dev/null ;} || true done $INSTALLROOT/include/tar.h make $INSTALLROOT/include/tm.h prev include/tm.h exec { cp include/tm.h $INSTALLROOT/include/tm.h 2>/dev/null ;} || true done $INSTALLROOT/include/tm.h make $INSTALLROOT/include/align.h make align.h prev mkhdr prev genhdr exec mkhdr align " genhdr" "$CC" $CCFLAGS > align.h done align.h exec { cp align.h $INSTALLROOT/include/align.h 2>/dev/null ;} || true done $INSTALLROOT/include/align.h make $INSTALLROOT/include/dirent.h prev dirent.h exec { cp dirent.h $INSTALLROOT/include/dirent.h 2>/dev/null ;} || true done $INSTALLROOT/include/dirent.h make $INSTALLROOT/include/fsinfo.h prev fsinfo.h exec { cp fsinfo.h $INSTALLROOT/include/fsinfo.h 2>/dev/null ;} || true done $INSTALLROOT/include/fsinfo.h make $INSTALLROOT/include/limits.h prev limits.h exec { cp limits.h $INSTALLROOT/include/limits.h 2>/dev/null ;} || true done $INSTALLROOT/include/limits.h make $INSTALLROOT/include/sigdata.h prev sigdata.h exec { cp sigdata.h $INSTALLROOT/include/sigdata.h 2>/dev/null ;} || true done $INSTALLROOT/include/sigdata.h make $INSTALLROOT/include/lcldirent.h prev lcldirent.h exec { cp lcldirent.h $INSTALLROOT/include/lcldirent.h 2>/dev/null ;} || true done $INSTALLROOT/include/lcldirent.h make $INSTALLROOT/include/lcllimits.h prev lcllimits.h exec { cp lcllimits.h $INSTALLROOT/include/lcllimits.h 2>/dev/null ;} || true done $INSTALLROOT/include/lcllimits.h make $INSTALLROOT/include/lclparam.h prev lclparam.h exec { cp lclparam.h $INSTALLROOT/include/lclparam.h 2>/dev/null ;} || true done $INSTALLROOT/include/lclparam.h make $INSTALLROOT/include/lclstdio.h prev lclstdio.h exec { cp lclstdio.h $INSTALLROOT/include/lclstdio.h 2>/dev/null ;} || true done $INSTALLROOT/include/lclstdio.h make $INSTALLROOT/include/preroot.h prev preroot.h exec { cp preroot.h $INSTALLROOT/include/preroot.h 2>/dev/null ;} || true done $INSTALLROOT/include/preroot.h make $INSTALLROOT/include/sig.h prev sig.h exec { cp sig.h $INSTALLROOT/include/sig.h 2>/dev/null ;} || true done $INSTALLROOT/include/sig.h make $INSTALLROOT/include/ttyinfo.h prev ttyinfo.h exec { cp ttyinfo.h $INSTALLROOT/include/ttyinfo.h 2>/dev/null ;} || true done $INSTALLROOT/include/ttyinfo.h done install 0707070000000000000000000000000000000000010000000000000000000001300000000000TRAILER!!!