|
|
1.1 root 1: 0707070000000000011006440044230044230000010000000475416516000002400000006446Makefile Ugsf Ggsf /*
2: * libx make
3: */
4:
5: VERSION = 3.0
6:
7: .SOURCE : comp dir hash man misc port preroot re \
8: sfio stdio string tm vec
9:
10: .SOURCE.h : include
11:
12: DEBUG ==
13: LIBX == 1
14:
15: HEADERSRC = error.h ftwalk.h hash.h hashpart.h ls.h namval.h \
16: option.h re.h sfio.h stack.h stak.h stdio.h swap.h tar.h tm.h
17:
18: HEADERGEN = align.h dirent.h fsinfo.h limits.h sigdata.h
19:
20: HEADERMK = lcldirent.h lcllimits.h lclparam.h lclstdio.h \
21: preroot.h sig.h ttyinfo.h
22:
23: x $(VERSION) :LIBRARY: README hash.3 ftwalk.3 re.3 sfio.3 stak.3 tm.3 \
24: $(HEADERSRC) \
25: dirlib.h opendir.c readdir.c rewinddir.c seekdir.c telldir.c \
26: getcwd.c setcwd.c getshell.c \
27: hashlib.h hashalloc.c hashdump.c hashfree.c hashlook.c \
28: hashscan.c hashsize.c hashwalk.c \
29: memhash.c memsum.c strhash.c strsum.c \
30: cvtatoe.c cvtetoa.c \
31: chresc.c ctoi.c streval.c strmatch.c strcopy.c \
32: modelib.h strmode.c \
33: stresc.c stropt.c strtape.c tok.c \
34: pathaccess.c pathcanon.c pathcheck.c pathpath.c \
35: pathkey.c pathprobe.c pathtemp.c \
36: cmdargs.c fs3d.c ftwalk.c perror.c putenv.c calloc.c malloc.c \
37: getnamval.c optget.c hsort.c query.c \
38: error.c liberror.c strerror.c strsignal.c \
39: fmtelapsed.c fmtls.c fmtmode.c fmtperm.c fmtuid.c fmtgid.c \
40: strelapsed.c strperm.c struid.c strgid.c stack.c stak.c \
41: memswap.c gethalf.c getlong.c puthalf.c putlong.c \
42: fgetline.c sigcrit.c sigunblock.c \
43: cmdlib.h cmdopen.c cmdclose.c cmdrun.c cmdwait.c cmdkill.c \
44: relib.h recomp.c reerror.c reexec.c resub.c \
45: tmdate.c tmfix.c tmform.c tmgoff.c \
46: tminit.c tmleap.c tmlex.c tmmake.c tmpoff.c \
47: tmtime.c tmtype.c tmword.c tmzone.c \
48: vecargs.c vecfile.c vecfree.c vecload.c vecstring.c \
49: getsymlink.c putsymlink.c univlib.h univdata.c getuniv.c setuniv.c \
50: winsize.c fclex.c sigdata.c touch.c lpstat.c \
51: memcmp.c memcpy.c memdup.c memset.c \
52: mkdir.c rmdir.c remove.c rename.c link.c unlink.c \
53: strtok.c strspn.c strpbrk.c strdup.c strchr.c strrchr.c \
54: strtod.c strtol.c strton.c sigsetmask.c mktemp.c tmpnam.c \
55: vfork.c killpg.c lstat.c readlink.c symlink.c setpgid.c \
56: atexit.c getdents.c getwd.c copy.c dup2.c errno.c sgetl.c sputl.c \
57: getpreroot.c ispreroot.c realopen.c setpreroot.c \
58: mount.c popen.c system.c iblocks.c \
59: modedata.c tmdata.c \
60: sfhdr.h sfclose.c sfclrlock.c sfcvt.c sfdlen.c sfdopen.c \
61: sfexcept.c sfextern.c sffilbuf.c sfflsbuf.c sfgetd.c sfgetl.c \
62: sfgets.c sfgetu.c sfllen.c sfmode.c sfmove.c sfnew.c sfnotify.c \
63: sfnputc.c sfopen.c sfpeek.c sfpool.c sfpopen.c sfprintf.c sfputd.c \
64: sfputl.c sfputs.c sfputu.c sfread.c sfscanf.c sfseek.c \
65: sfsetbuf.c sfsetdisc.c sfset.c sfstack.c sfstrtod.c \
66: sfsync.c sftable.c sftell.c sftmpfile.c sfungetc.c sfvprintf.c \
67: sfvscanf.c sfwrite.c \
68: _sfhdr.h _sfclearerr.c _sffileno.c _sforigin.c _sfputl.c _sftmp.c \
69: _sfecvt.c _sfgetc.c _sfpeek.c _sfputu.c _sfulen.c _sfeof.c _sfgetl.c \
70: _sfpushed.c _sfslen.c _sferror.c _sfgetu.c _sfputc.c _sffcvt.c \
71: _sfputd.c _sfsync.c \
72: stdgets.c stdprintf.c stdscanf.c stdsetvbuf.c stdsprintf.c \
73: stdvsprintf.c stdvsscanf.c sprintf.c vsprintf.c
74:
75: :READONLY: modedata.c sftable.c sigdata.c tmdata.c univdata.c
76:
77: $(INCLUDEDIR) :INSTALLDIR: $(HEADERSRC) $(HEADERGEN) $(HEADERMK)
78:
79: :INSTALLDIR: mkhdr genhdr
80:
81: mkhdr :: mkhdr.sh
82:
83: genhdr :: genhdr.c
84:
85: $(HEADERGEN) : mkhdr genhdr
86: $(*:N=*mkhdr) $(<:B) "$(TARGET:/\\\\/\\/G) $(*:N=*genhdr)" "$(CC)" $(CCFLAGS) > $(<)
87:
88: $(HEADERMK) : mkhdr
89: $(*) $(<:B) "" "$(CC)" $(CCFLAGS) > $(<)
90: 0707070000000000021006440044230044230000010000000441571252600002200000006712README Ugsf Ggsf The advanced software department has been collecting useful C routines
91: in a single library called libx. libx is used by nmake, the nmake cpp
92: (which is mainly based on another library (libpp)), CIA
93: (C information abstractor from Yih-Farn Chen), and a collection
94: of other /bin and /usr/bin commands that benefit from
95: concentrating functionality in libx.
96:
97: More detail is available in the man pages. libx contains:
98:
99: (1) routines to support a generic environment for
100: a variety of UNIX operating system variants
101:
102: (2) routines that update standard libc routines
103:
104: (3) routines shared between several commands
105:
106: If you already have nmake 2.0 or newer installed then use
107: `nmake install' from this directory, otherwise use
108: ship/shipin from the root of the distribution directory tree.
109:
110: Some of the routines not found in section 3:
111:
112: hash: generic, scoped hash table support
113:
114: hashalloc create a hash table or push new scope
115: hashdump debug dump of one or all hash tables
116: hashfree free a hashalloc()'d table
117: hashlook low level name lookup
118: hashscan entry generator for scoped table scan
119: hashsize explicitly change table size (usually automatic)
120: hashwalk apply function to each table entry
121: memhash return hash code for n-char chunk of memory
122: strhash return hash code for null terminated string
123:
124: include: libx support headers
125:
126: align.h compile time type alignmnent support
127: dirent.h POSIX directory(3) interface definitions
128: error.h error() interface definitions
129: ftw.h ftwalk() interface definitions
130: hash.h hash*() interface definitions
131: ls.h strls() interface definitions
132: re.h re*() interface definitions
133: tar.h POSIX ustar format interface definitions
134: tm.h tm*() interface definitions
135:
136: misc:
137:
138: cmdargs apply a sequence of cmd line option parsers
139: cmdopen like popen() but stdin and stdout are specified
140: cvtatoe convert ASCII to EBCDIC
141: cvtetoa convert EBCDIC to ASCII
142: error output generic error and trace messages
143: ftwalk an ftw(3) that works -- used in new tw(1)
144: getcwd uses $PWD if ok, doesn't use /bin/pwd
145: getshell return full path of shell for cmdopen()
146: ooptget optget() for obsolete ar(1) and tar(1) options
147: optget YA getopt(3) but no argc or error message output
148: pathaccess find file with specific acces on list of dirs
149: pathcanon canonicalize path name in place
150: pathcmd return full path name of executable using $PATH
151: pathroot determine `related root' directory for command
152: perror uses strerror()
153: readargs append each line of file to argv[0]
154:
155: re: egrep(1) and ed(1) style re's from V9
156: (not the good awk(1) algorithm)
157:
158: recomp compile re pattern
159: reerror report re*() errors
160: reexec match string using compiled re
161: resub ed(1) style substitute using last reexec()
162:
163: string:
164:
165: chresc return next char in string converting \ sequences
166: ctoi convert char constant string to int
167: strcopy like strcpy(3) but returns end of destination
168: strdup malloc(3) and strcpy(3) smashed together
169: strerror return error message string given errno
170: stresc convert \ sequences in string in place
171: streval evaluate C expression in string
172: strls ls -l format support
173: strmatch Korn shell file pattern match
174: strmode return ls -l style output given st.st_mode
175: strsignal return signal id string given SIG* number
176: strtape convert generic tape unit to /dev/* file
177: token generate space separated tokens in string
178:
179: tm: time conversion support
180:
181: tmdate convert date string to time_t
182: tmform format time_t to date string
183: tmmake return current time_t
184: tmtime convert struct tm to time_t
185: 0707070000000000031006440044230044230000010000000471771066600003100000001610comp/atexit.c Ugsf Ggsf /*
186: * ANSI C atexit()
187: * arrange for func to be called LIFO on exit()
188: */
189:
190: #include "FEATURE/atexit"
191:
192: #ifdef _lib_atexit
193:
194: int _lib_dummy;
195:
196: #else
197:
198: typedef void (*PFV)();
199:
200: #include "FEATURE/onexit"
201:
202: #ifdef _lib_onexit
203:
204: int
205: atexit(func)
206: PFV func;
207: {
208: return(onexit(func));
209: }
210:
211: #else
212:
213: #include "FEATURE/on_exit"
214:
215: #ifdef _lib_on_exit
216:
217: int
218: atexit(func)
219: PFV func;
220: {
221: return(on_exit(func));
222: }
223:
224: #else
225:
226: #include "FEATURE/_cleanup"
227:
228: struct list
229: {
230: struct list* next;
231: PFV func;
232: };
233:
234: static struct list* funclist;
235:
236: extern char* malloc();
237:
238: int
239: atexit(func)
240: PFV func;
241: {
242: register struct list* p;
243:
244: if (!(p = (struct list*)malloc(sizeof(struct list)))) return(-1);
245: p->func = func;
246: p->next = funclist;
247: funclist = p;
248: return(0);
249: }
250:
251: int
252: exit(code)
253: int code;
254: {
255: register struct list* p;
256:
257: for (p = funclist; p; p = p->next)
258: (*p->func)();
259: #ifdef _lib__cleanup
260: _cleanup();
261: #endif
262: _exit(code);
263: }
264:
265: #endif
266:
267: #endif
268:
269: #endif
270: 0707070000000000041006440044230044230000010000000441570075300002700000000512comp/dup2.c Ugsf Ggsf #include "FEATURE/dup2"
271:
272: #ifdef _lib_dup2
273:
274: int _lib_dummy;
275:
276: #else
277:
278: #include <fcntl.h>
279:
280: extern int errno;
281:
282: extern int close();
283: extern int fcntl();
284:
285: int
286: dup2(d1, d2)
287: int d1;
288: int d2;
289: {
290: int save_errno;
291:
292: if (d1 == d2) return(d1);
293: save_errno = errno;
294: (void)close(d2);
295: errno = save_errno;
296: return(fcntl(d1, F_DUPFD, d2));
297: }
298:
299: #endif
300: 0707070000000000051006440044230044230000010000000461342262600003000000000220comp/errno.c Ugsf Ggsf /*
301: * this avoids multiple definitions with some libc's
302: * that define both a libx supplied routine and errno
303: * in the same .o
304: */
305:
306: int errno;
307: 0707070000000000061006440044230044230000010000000474436324700003300000007014comp/getdents.c Ugsf Ggsf #include "FEATURE/getdents"
308: #ifdef _lib_getdents
309:
310: int _lib_dummy;
311:
312: #else
313:
314: /*
315: * getdents
316: *
317: * read directory entries into directory block
318: *
319: * NOTE: directory entries must fit within DIRBLKSIZ boundaries
320: */
321:
322: #include <fsinfo.h>
323: #include <dirent.h>
324: #include <errno.h>
325:
326: #define round(x,y) (((x)+((y)-1))&~((y)-1))
327:
328: #ifndef DIRBLKSIZ
329: #ifdef DIRBLK
330: #define DIRBLKSIZ DIRBLK
331: #else
332: #ifdef DIRBUF
333: #define DIRBLKSIZ DIRBUF
334: #else
335: #ifdef DEV_BSIZE
336: #define DIRBLKSIZ DEV_BSIZE
337: #else
338: #define DIRBLKSIZ 4096
339: #endif
340: #endif
341: #endif
342: #endif
343:
344: #ifndef MAXNAMLEN
345: #define MAXNAMLEN 255
346: #endif
347:
348: int
349: getdents(fd, buf, siz)
350: int fd;
351: char* buf;
352: int siz;
353: {
354: struct stat st;
355:
356: extern int errno;
357:
358: extern int fstat();
359:
360: if (siz < DIRBLKSIZ)
361: {
362: errno = EINVAL;
363: return(-1);
364: }
365: if (fstat(fd, &st)) return(-1);
366: if ((st.st_mode & S_IFMT) != S_IFDIR)
367: {
368: #ifdef ENOTDIR
369: errno = ENOTDIR;
370: #else
371: errno = EBADF;
372: #endif
373: return(-1);
374: }
375: #include "FEATURE/getdirentries"
376: #ifdef _lib_getdirentries
377: {
378: long off;
379:
380: extern int getdirentries();
381:
382: return(getdirentries(fd, buf, siz, &off));
383: }
384: #else
385: #include "FEATURE/dirread"
386: #ifdef _lib_dirread
387: {
388: register char* sp; /* system */
389: register struct dirent* up; /* user */
390: char* u;
391: int n;
392: int m;
393: int i;
394:
395: extern int dirread();
396:
397: m = (siz * 6) / 10;
398: m = round(m, 8);
399: sp = buf + siz - m - 1;
400: if (!(n = dirread(fd, sp, m))) return(0);
401: if (n > 0)
402: {
403: up = (struct dirent*)buf;
404: sp[n] = 0;
405: while (sp < buf + siz - m + n)
406: {
407: i = 0;
408: while (*sp >= '0' && *sp <= '9')
409: i = 10 * i + *sp++ - '0';
410: while (*sp && *sp != '\t') sp++;
411: if (*sp++)
412: {
413: up->d_ino = i;
414: u = up->d_name;
415: while ((*u = *sp++) && u < up->d_name + MAXNAMLEN) u++;
416: *u = 0;
417: up->d_reclen = sizeof(struct dirent) - sizeof(up->d_name) + (
418: #if defined(d_fileno) || defined(d_ino)
419: up->d_namlen =
420: #endif
421: u - up->d_name) + 1;
422: up->d_reclen = round(up->d_reclen, 8);
423: up = (struct dirent*)((char*)up + up->d_reclen);
424: }
425: }
426: return((char*)up - buf);
427: }
428: }
429: #endif
430: {
431: #ifndef _dir_fixed
432: #include "FEATURE/readdir"
433: #ifndef _lib_readdir
434: #define _dir_fixed
435: #endif
436: #endif
437:
438: #ifdef _dir_fixed
439: #ifndef DIRSIZ
440: #include "FEATURE/dir"
441: #ifdef _sys_dir
442: #include <sys/dir.h>
443: #endif
444: #endif
445:
446: #define MAXREC round(sizeof(*up)-sizeof(up->d_name)+sizeof(sp->d_name)+1,8)
447:
448: register struct direct* sp; /* system */
449: register struct dirent* up; /* user */
450: register char* s;
451: register char* u;
452: int n;
453: int m;
454: char tmp[sizeof(sp->d_name) + 1];
455:
456: extern int read();
457: extern int strcpy();
458:
459: /*
460: * we assume sizeof(struct dirent) > sizeof(struct direct)
461: */
462:
463: up = (struct dirent*)buf;
464: n = (siz / MAXREC) * sizeof(struct direct);
465: if ((!(m = n & ~511) || m < MAXREC) && (!(m = n & ~255) || m < MAXREC)) m = n;
466: do
467: {
468: if ((n = read(fd, buf + siz - m, m)) <= 0) break;
469: sp = (struct direct*)(buf + siz - m);
470: while (sp < (struct direct*)(buf + siz - m + n))
471: {
472: if (sp->d_ino)
473: {
474: up->d_ino = sp->d_ino;
475: s = sp->d_name;
476: u = tmp;
477: while (s < sp->d_name + sizeof(sp->d_name) && *s)
478: *u++ = *s++;
479: *u = 0;
480: (void)strcpy(up->d_name, tmp);
481: up->d_reclen = sizeof(struct dirent) - sizeof(up->d_name) + (
482: #if defined(d_fileno) || defined(d_ino)
483: up->d_namlen =
484: #endif
485: u - tmp) + 1;
486: up->d_reclen = round(up->d_reclen, 8);
487: up = (struct dirent*)((char*)up + up->d_reclen);
488: }
489: sp++;
490: }
491: } while (up == (struct dirent*)buf);
492: return((char*)up - buf);
493: #else
494: extern int read();
495:
496: return(read(fd, buf, siz));
497: #endif
498: }
499: #endif
500: }
501:
502: #endif
503: 0707070000000000071006440044230044230000010000000441570077400003100000000234comp/killpg.c Ugsf Ggsf #include "FEATURE/killpg"
504:
505: #ifdef _lib_killpg
506:
507: int _lib_dummy;
508:
509: #else
510:
511: extern int kill();
512:
513: int
514: killpg(g, s)
515: int g;
516: int s;
517: {
518: return(kill(-g, s));
519: }
520:
521: #endif
522: 0707070000000000101006440044230044230000010000000472226401000002700000000275comp/link.c Ugsf Ggsf #include "FEATURE/link"
523:
524: #ifdef _lib_link
525:
526: int _lib_dummy;
527:
528: #else
529:
530: #include <errno.h>
531:
532: extern int errno;
533:
534: int
535: link(from, to)
536: char* from;
537: char* to;
538: {
539: errno = EINVAL;
540: return(-1);
541: }
542:
543: #endif
544: 0707070000000000111006440044230044230000010000000472226261100003000000000336comp/lstat.c Ugsf Ggsf #include "FEATURE/lstat"
545:
546: #ifdef _lib_lstat
547:
548: int _lib_dummy;
549:
550: #else
551:
552: #include <sys/types.h>
553: #include <sys/stat.h>
554:
555: extern int stat();
556:
557: int
558: lstat(path, st)
559: char* path;
560: struct stat* st;
561: {
562: return(stat(path, st));
563: }
564:
565: #endif
566: 0707070000000000121006440044230044230000010000000441570100700003100000000450comp/memcmp.c Ugsf Ggsf #include "FEATURE/memcmp"
567:
568: #ifdef _lib_memcmp
569:
570: int _lib_dummy;
571:
572: #else
573:
574: int
575: memcmp(b1, b2, n)
576: register unsigned char* b1;
577: register unsigned char* b2;
578: unsigned int n;
579: {
580: register unsigned char* e;
581:
582: e = b1 + n;
583: while (b1 < e)
584: if (*b1++ != *b2++)
585: return(*--b1 - *--b2);
586: return(0);
587: }
588:
589: #endif
590: 0707070000000000131006440044230044230000010000000455540707300003100000000627comp/memcpy.c Ugsf Ggsf #include "FEATURE/memcpy"
591:
592: #ifdef _lib_memcpy
593:
594: int _lib_dummy;
595:
596: #else
597:
598: #include "FEATURE/bcopy"
599:
600: #ifdef _lib_bcopy
601:
602: extern void bcopy();
603:
604: char*
605: memcpy(s1, s2, n)
606: char* s1;
607: char* s2;
608: int n;
609: {
610: bcopy(s2, s1, n);
611: return(s1);
612: }
613:
614: #else
615:
616: char*
617: memcpy(s1, s2, n)
618: register char* s1;
619: register char* s2;
620: register int n;
621: {
622: register char* os1 = s1;
623:
624: while (--n >= 0)
625: *s1++ = *s2++;
626: return(os1);
627: }
628:
629: #endif
630:
631: #endif
632: 0707070000000000141006440044230044230000010000000472226263000003100000000331comp/memset.c Ugsf Ggsf #include "FEATURE/memset"
633:
634: #ifdef _lib_memset
635:
636: int _lib_dummy;
637:
638: #else
639:
640: char*
641: memset(sp, c, n)
642: register char *sp, c;
643: register int n;
644: {
645: register char *sp0 = sp;
646:
647: while (--n >= 0)
648: *sp++ = c;
649: return (sp0);
650: }
651:
652: #endif
653: 0707070000000000151006440044230044230000010000000472226263600003000000001270comp/mkdir.c Ugsf Ggsf #include "FEATURE/mkdir"
654:
655: #ifdef _lib_mkdir
656:
657: int _lib_dummy;
658:
659: #else
660:
661: #include <errno.h>
662:
663: extern int errno;
664:
665: extern int _exit();
666: extern int access();
667: extern int chmod();
668: extern int execl();
669: extern int fork();
670: extern int wait();
671:
672: int
673: mkdir(path, mode)
674: char* path;
675: int mode;
676: {
677: register int n;
678: register int pid;
679:
680: n = errno;
681: if (!access(path, 0))
682: {
683: errno = EEXIST;
684: return(-1);
685: }
686: if (errno != ENOENT) return(-1);
687: errno = n;
688: switch (pid = fork())
689: {
690: case -1:
691: return(-1);
692: case 0:
693: execl("/bin/mkdir", "mkdir", path, 0);
694: execl("/usr/5bin/mkdir", "mkdir", path, 0);
695: _exit(1);
696: default:
697: while ((n = wait((int*)0)) >= 0 && n != pid);
698: break;
699: }
700: return(chmod(path, mode));
701: }
702:
703: #endif
704: 0707070000000000161006440044230044230000010000000441570103400003100000002030comp/mktemp.c Ugsf Ggsf #include "FEATURE/mktemp"
705:
706: #ifdef _lib_mktemp
707:
708: int _lib_dummy;
709:
710: #else
711:
712: /* @(#)mktemp.c 1.2 9/24/85 19:52:37 */
713: /*LINTLIBRARY*/
714: /****************************************************************
715: * Routine expects a string of length at least 6, with
716: * six trailing 'X's. These will be overlaid with a
717: * letter and the last (5) digigts of the proccess ID.
718: * If every letter (a thru z) thus inserted leads to
719: * an existing file name, your string is shortened to
720: * length zero upon return (first character set to '\0').
721: ***************************************************************/
722: extern int strlen(), access(), getpid();
723:
724: char *
725: mktemp(as)
726: char *as;
727: {
728: register char *s=as;
729: register unsigned pid;
730:
731: pid = getpid();
732: s += strlen(as); /* point at the terminal null */
733: while(*--s == 'X') {
734: *s = (pid%10) + '0';
735: pid /= 10;
736: }
737: if(*++s) { /* maybe there were no 'X's */
738: *s = 'a';
739: while(access(as, 0) == 0) {
740: if(++*s > 'z') {
741: *as = '\0';
742: break;
743: }
744: }
745: } else
746: if(access(as, 0) == 0)
747: *as = '\0';
748: return(as);
749: }
750:
751: #endif
752: 0707070000000000171006440044230044230000010000000471605023500003000000000317comp/mount.c Ugsf Ggsf #include "FEATURE/mount"
753:
754: #ifdef _lib_mount
755:
756: int _lib_dummy;
757:
758: #else
759:
760: #include <errno.h>
761:
762: extern int errno;
763:
764: /*ARGSUSED*/
765: int
766: mount(a, b, c)
767: char* a;
768: char* b;
769: int c;
770: {
771: errno = EINVAL;
772: return(-1);
773: }
774:
775: #endif
776: 0707070000000000201006440044230044230000010000000475446255100003000000001136comp/popen.c Ugsf Ggsf /*
777: * libx popen(3)
778: */
779:
780: #include <stdio.h>
781:
782: #undef popen
783: #undef pclose
784:
785: extern int cmdopen();
786: extern int cmdclose();
787:
788: #if __STDC__
789: #ifndef fdopen
790: extern FILE* fdopen(int, char*);
791: #endif
792: #endif
793:
794: FILE*
795: popen(cmd, mode)
796: char* cmd;
797: char* mode;
798: {
799: int fd;
800: FILE* fp;
801: char* sh[4];
802:
803: sh[0] = "sh";
804: sh[1] = "-c";
805: sh[2] = cmd;
806: sh[3] = 0;
807: if ((fd = cmdopen((char*)0, sh, (char**)0, (int**)0, mode)) < 0)
808: return(0);
809: if (!(fp = fdopen(fd, mode)))
810: (void)cmdclose(fd);
811: return(fp);
812: }
813:
814: int
815: pclose(fp)
816: FILE* fp;
817: {
818: int fd;
819:
820: if (fp)
821: {
822: fd = fileno(fp);
823: fclose(fp);
824: return(cmdclose(fd));
825: }
826: return(-1);
827: }
828: 0707070000000000211006440044230044230000010000000451516406000003300000000346comp/readlink.c Ugsf Ggsf #include "FEATURE/readlink"
829:
830: #ifdef _lib_readlink
831:
832: int _lib_dummy;
833:
834: #else
835:
836: #include <errno.h>
837:
838: extern int errno;
839:
840: /*ARGSUSED*/
841: int
842: readlink(path, buf, siz)
843: char* path;
844: char* buf;
845: int siz;
846: {
847: errno = EINVAL;
848: return(-1);
849: }
850:
851: #endif
852: 0707070000000000221006440044230044230000010000000472227245200003100000000235comp/remove.c Ugsf Ggsf #include "FEATURE/remove"
853:
854: #ifdef _lib_remove
855:
856: int _lib_dummy;
857:
858: #else
859:
860: extern int unlink();
861:
862: int
863: remove(path)
864: char* path;
865: {
866: return(unlink(path));
867: }
868:
869: #endif
870: 0707070000000000231006440044230044230000010000000472226252400003100000000354comp/rename.c Ugsf Ggsf #include "FEATURE/rename"
871:
872: #ifdef _lib_rename
873:
874: int _lib_dummy;
875:
876: #else
877:
878: extern int link();
879: extern int unlink();
880:
881: int
882: rename(from, to)
883: char* from;
884: char* to;
885: {
886: int n;
887:
888: if (!(n = link(from, to))) (void)unlink(from);
889: return(n);
890: }
891:
892: #endif
893: 0707070000000000241006440044230044230000010000000472226265000003000000001475comp/rmdir.c Ugsf Ggsf #include "FEATURE/rmdir"
894:
895: #ifdef _lib_rmdir
896:
897: int _lib_dummy;
898:
899: #else
900:
901: #include <sys/types.h>
902: #include <sys/stat.h>
903: #include <errno.h>
904:
905: extern int errno;
906:
907: extern int _exit();
908: extern int access();
909: extern int chmod();
910: extern int execl();
911: extern int fork();
912: extern int stat();
913: extern int wait();
914:
915: int
916: rmdir(path)
917: char* path;
918: {
919: register int n;
920: register int pid;
921: struct stat st;
922:
923: if (stat(path, &st) < 0) return(-1);
924: if ((st.st_mode & S_IFMT) != S_IFDIR)
925: {
926: errno = ENOTDIR;
927: return(-1);
928: }
929: switch (pid = fork())
930: {
931: case -1:
932: return(-1);
933: case 0:
934: execl("/bin/rmdir", "rmdir", path, 0);
935: execl("/usr/5bin/rmdir", "rmdir", path, 0);
936: _exit(1);
937: default:
938: while ((n = wait((int*)0)) >= 0 && n != pid);
939: break;
940: }
941: n = errno;
942: if (access(path, 0) < 0)
943: {
944: errno = n;
945: return(0);
946: }
947: errno = EPERM;
948: return(-1);
949: }
950:
951: #endif
952: 0707070000000000251006440044230044230000010000000441570106000003200000000263comp/setpgid.c Ugsf Ggsf #include "FEATURE/setpgid"
953:
954: #ifdef _lib_setpgid
955:
956: int _lib_dummy;
957:
958: #else
959:
960: extern int setpgrp();
961:
962: int
963: setpgid(pid, pgid)
964: int pid;
965: int pgid;
966: {
967: return(setpgrp(pid, pgid));
968: }
969:
970: #endif
971: 0707070000000000261006440044230044230000010000000441570106600003000000001045comp/sgetl.c Ugsf Ggsf #include "FEATURE/sgetl"
972:
973: #ifdef _lib_sgetl
974:
975: int _lib_dummy;
976:
977: #else
978:
979: /*
980: * The intent here is to provide a means to make the value of
981: * bytes in an io-buffer correspond to the value of a long
982: * in the memory while doing the io a `long' at a time.
983: * Files written and read in this way are machine-independent.
984: */
985:
986: #include <limits.h>
987:
988: long
989: sgetl(buffer)
990: register char *buffer;
991: {
992: register long w = 0;
993: register int i = CHAR_BIT * sizeof(long);
994:
995: while ((i -= CHAR_BIT) >= 0)
996: w |= (long) ((unsigned char) *buffer++) << i;
997: return (w);
998: }
999:
1000: #endif
1001: 0707070000000000271006440044230044230000010000000441570107200003500000000206comp/sigsetmask.c Ugsf Ggsf #include "FEATURE/sigsetmask"
1002:
1003: #ifdef _lib_sigsetmask
1004:
1005: int _lib_dummy;
1006:
1007: #else
1008:
1009: int
1010: sigsetmask(mask)
1011: int mask;
1012: {
1013: return(0);
1014: }
1015:
1016: #endif
1017: 0707070000000000301006440044230044230000010000000471770567300003500000000270comp/sigunblock.c Ugsf Ggsf #include "FEATURE/sigunblock"
1018:
1019: #ifdef _lib_sigunblock
1020:
1021: int _lib_dummy;
1022:
1023: #else
1024:
1025: #include <sig.h>
1026:
1027: int
1028: sigunblock(s)
1029: int s;
1030: {
1031: return(sigsetmask(sigsetmask(0) & ~sigmask(s)));
1032: }
1033:
1034: #endif
1035: 0707070000000000311006440044230044230000010000000441570110500003000000001007comp/sputl.c Ugsf Ggsf #include "FEATURE/sputl"
1036:
1037: #ifdef _lib_sputl
1038:
1039: int _lib_dummy;
1040:
1041: #else
1042:
1043: /*
1044: * The intent here is to provide a means to make the value of
1045: * bytes in an io-stream correspond to the value of the long
1046: * in the memory while doing the io a `long' at a time.
1047: * Files written and read in this way are machine-independent.
1048: */
1049:
1050: #include <limits.h>
1051:
1052: void
1053: sputl(w, buffer)
1054: register long w;
1055: register char *buffer;
1056: {
1057: register int i = CHAR_BIT * sizeof(long);
1058:
1059: while ((i -= CHAR_BIT) >= 0)
1060: *buffer++ = (char) (w >> i);
1061: }
1062:
1063: #endif
1064: 0707070000000000321006440044230044230000010000000472226266100003100000000516comp/strchr.c Ugsf Ggsf #include "FEATURE/strchr"
1065:
1066: #ifdef _lib_strchr
1067:
1068: int _lib_dummy;
1069:
1070: #else
1071:
1072: #include "FEATURE/index"
1073:
1074: #ifdef _lib_index
1075:
1076: extern char* index();
1077:
1078: char*
1079: strchr(s, c)
1080: char* s;
1081: int c;
1082: {
1083: return(index(s, c));
1084: }
1085:
1086: #else
1087:
1088: char*
1089: strchr(s, c)
1090: register char* s;
1091: register int c;
1092: {
1093: do if (*s == c) return(s); while(*s++);
1094: return(0);
1095: }
1096:
1097: #endif
1098:
1099: #endif
1100: 0707070000000000331006440044230044230000010000000441570112000003200000000645comp/strpbrk.c Ugsf Ggsf #include "FEATURE/strpbrk"
1101:
1102: #ifdef _lib_strpbrk
1103:
1104: int _lib_dummy;
1105:
1106: #else
1107:
1108: /*
1109: * Return ptr to first occurance of any character from `brkset'
1110: * in the character string `string'; 0 if none exists.
1111: */
1112:
1113: char*
1114: strpbrk(string, brkset)
1115: register char* string;
1116: register char* brkset;
1117: {
1118: register char* p;
1119:
1120: do
1121: {
1122: for (p = brkset; *p && *p != *string; p++);
1123: if (*p) return(string);
1124: } while (*string++);
1125: return(0);
1126: }
1127:
1128: #endif
1129: 0707070000000000341006440044230044230000010000000441570112600003200000000556comp/strrchr.c Ugsf Ggsf #include "FEATURE/strrchr"
1130:
1131: #ifdef _lib_strrchr
1132:
1133: int _lib_dummy;
1134:
1135: #else
1136:
1137: #include "FEATURE/rindex"
1138:
1139: #ifdef _lib_rindex
1140:
1141: extern char* rindex();
1142:
1143: char*
1144: strrchr(s, c)
1145: char* s;
1146: int c;
1147: {
1148: return(rindex(s, c));
1149: }
1150:
1151: #else
1152:
1153: char*
1154: strrchr(s, c)
1155: register char* s;
1156: register int c;
1157: {
1158: register char* r;
1159:
1160: r = 0;
1161: do if (*s == c) r = s; while(*s++);
1162: return(r);
1163: }
1164:
1165: #endif
1166:
1167: #endif
1168: 0707070000000000351006440044230044230000010000000441570113300003100000000670comp/strspn.c Ugsf Ggsf #include "FEATURE/strspn"
1169:
1170: #ifdef _lib_strspn
1171:
1172: int _lib_dummy;
1173:
1174: #else
1175:
1176: /*
1177: * Return the number of characters in the maximum leading segment
1178: * of string which consists solely of characters from charset.
1179: */
1180:
1181: int
1182: strspn(string, charset)
1183: char* string;
1184: register char* charset;
1185: {
1186: register char* p;
1187: register char* q;
1188:
1189: for (q = string; *q; q++)
1190: {
1191: for (p = charset; *p && *p != *q; p++);
1192: if (!*p) break;
1193: }
1194: return(q - string);
1195: }
1196:
1197: #endif
1198: 0707070000000000361006440044230044230000010000000441570114000003100000000726comp/strtod.c Ugsf Ggsf #include "FEATURE/strtod"
1199:
1200: #ifdef _lib_strtod
1201:
1202: int _lib_dummy;
1203:
1204: #else
1205:
1206: #include <ctype.h>
1207:
1208: extern double atof();
1209:
1210: double
1211: strtod(s, e)
1212: register char* s;
1213: char** e;
1214: {
1215: double n;
1216:
1217: n = atof(s);
1218: if (e)
1219: {
1220: while (isspace(*s)) s++;
1221: if (*s == '-' || *s == '+') s++;
1222: while (isdigit(*s)) s++;
1223: if (*s == '.') while (isdigit(*++s));
1224: if (*s == 'e' || *s == 'E')
1225: {
1226: if (*++s == '-' || *s == '+') s++;
1227: while (isdigit(*s)) s++;
1228: }
1229: *e = s;
1230: }
1231: return(n);
1232: }
1233:
1234: #endif
1235: 0707070000000000371006440044230044230000010000000472226272700003100000001520comp/strtok.c Ugsf Ggsf #include "FEATURE/strtok"
1236:
1237: #ifdef _lib_strtok
1238:
1239: int _lib_dummy;
1240:
1241: #else
1242:
1243: /*
1244: * uses strpbrk and strspn to break string into tokens on
1245: * sequentially subsequent calls. returns 0 when no
1246: * non-separator characters remain.
1247: * `subsequent' calls are calls with first argument 0.
1248: */
1249:
1250: extern int strspn();
1251: extern char* strpbrk();
1252:
1253: char*
1254: strtok(string, sepset)
1255: char* string
1256: char* sepset;
1257: {
1258: register char* p;
1259: register char* q;
1260: register char* r;
1261: static char* savept;
1262:
1263: /*first or subsequent call*/
1264: /* return if no tokens remaining */
1265: if (!(p = string ? string : savept)) return(0);
1266: /* skip leading separators */
1267: /* return if no tokens remaining */
1268: if (!*(q = p + strspn(p, sepset))) return(0);
1269: /* move past token */
1270: if (!(r = strpbrk(q, sepset))) savept = 0; /* this is last token */
1271: else
1272: {
1273: *r = 0;
1274: savept = ++r;
1275: }
1276: return(q);
1277: }
1278:
1279: #endif
1280: 0707070000000000401006440044230044230000010000000472226275000003100000002577comp/strtol.c Ugsf Ggsf #include "FEATURE/strtol"
1281:
1282: #ifdef _lib_strtol
1283:
1284: int _lib_dummy;
1285:
1286: #else
1287:
1288: /* @(#)strtol.c 2.1 */
1289: /*LINTLIBRARY*/
1290: #include <ctype.h>
1291: #define DIGIT(x) (isdigit(x) ? (x) - '0' : \
1292: islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')
1293: #define MBASE ('z' - 'a' + 1 + 10)
1294:
1295: long
1296: strtol(str, ptr, base)
1297: register char* str;
1298: char** ptr;
1299: register int base;
1300: {
1301: register long val;
1302: register int c;
1303: int xx, neg = 0;
1304:
1305: if (ptr != (char **)0)
1306: *ptr = str; /* in case no number is formed */
1307: if (base < 0 || base > MBASE)
1308: return (0); /* base is invalid -- should be a fatal error */
1309: if (!isalnum(c = *str)) {
1310: while (isspace(c))
1311: c = *++str;
1312: switch (c) {
1313: case '-':
1314: neg++;
1315: case '+': /* fall-through */
1316: c = *++str;
1317: }
1318: }
1319: if (base == 0)
1320: if (c != '0')
1321: base = 10;
1322: else if (str[1] == 'x' || str[1] == 'X')
1323: base = 16;
1324: else
1325: base = 8;
1326: /*
1327: * for any base > 10, the digits incrementally following
1328: * 9 are assumed to be "abc...z" or "ABC...Z"
1329: */
1330: if (!isalnum(c) || (xx = DIGIT(c)) >= base)
1331: return (0); /* no number formed */
1332: if (base == 16 && c == '0' && isxdigit(str[2]) &&
1333: (str[1] == 'x' || str[1] == 'X'))
1334: c = *(str += 2); /* skip over leading "0x" or "0X" */
1335: for (val = -DIGIT(c); isalnum(c = *++str) && (xx = DIGIT(c)) < base; )
1336: /* accumulate neg avoids surprises near MAXLONG */
1337: val = base * val - xx;
1338: if (ptr != (char **)0)
1339: *ptr = str;
1340: return (neg ? val : -val);
1341: }
1342:
1343: #endif
1344: 0707070000000000411006440044230044230000010000000451516404100003200000000313comp/symlink.c Ugsf Ggsf #include "FEATURE/symlink"
1345:
1346: #ifdef _lib_symlink
1347:
1348: int _lib_dummy;
1349:
1350: #else
1351:
1352: #include <errno.h>
1353:
1354: extern int errno;
1355:
1356: /*ARGSUSED*/
1357: int
1358: symlink(a, b)
1359: char* a;
1360: char* b;
1361: {
1362: errno = EINVAL;
1363: return(-1);
1364: }
1365:
1366: #endif
1367: 0707070000000000421006440044230044230000010000000447445616000003100000000265comp/system.c Ugsf Ggsf /*
1368: * libx system(3)
1369: */
1370:
1371: extern int cmdrun();
1372:
1373: int
1374: system(cmd)
1375: char* cmd;
1376: {
1377: char* sh[4];
1378:
1379: sh[0] = "sh";
1380: sh[1] = "-c";
1381: sh[2] = cmd;
1382: sh[3] = 0;
1383: return(cmdrun((char*)0, sh));
1384: }
1385: 0707070000000000431006440044230044230000010000000441570116500003100000001051comp/tmpnam.c Ugsf Ggsf #include "FEATURE/tmpnam"
1386:
1387: #ifdef _lib_tmpnam
1388:
1389: int _lib_dummy;
1390:
1391: #else
1392:
1393: #include <stdio.h>
1394:
1395: #ifndef P_tmpdir
1396: #define P_tmpdir "/usr/tmp/"
1397: #endif
1398:
1399: #ifndef L_tmpnam
1400: #define L_tmpnam (sizeof(P_tmpdir)+10)
1401: #endif
1402:
1403: static char buf[L_tmpnam];
1404: static char seed[] = { 'a', 'a', 'a', 0 };
1405:
1406: extern char* mktemp();
1407: extern char* strcopy();
1408:
1409:
1410: char*
1411: tmpnam(p)
1412: register char* p;
1413: {
1414: register char* q;
1415:
1416: if (!p) p = buf;
1417: (void)strcopy(strcopy(strcopy(p, P_tmpdir), seed), "XXXXXX");
1418: q = seed;
1419: while (*q == 'z') *q++ = 'a';
1420: if (*q) ++*q;
1421: return(mktemp(p));
1422: }
1423:
1424: #endif
1425: 0707070000000000441006440044230044230000010000000472226407000003100000000235comp/unlink.c Ugsf Ggsf #include "FEATURE/unlink"
1426:
1427: #ifdef _lib_unlink
1428:
1429: int _lib_dummy;
1430:
1431: #else
1432:
1433: extern int remove();
1434:
1435: int
1436: unlink(path)
1437: char* path;
1438: {
1439: retrun(remove(path));
1440: }
1441:
1442: #endif
1443: 0707070000000000451006440044230044230000010000000441570117100003000000000202comp/vfork.c Ugsf Ggsf #include "FEATURE/vfork"
1444:
1445: #ifdef _lib_vfork
1446:
1447: int _lib_dummy;
1448:
1449: #else
1450:
1451: extern int fork();
1452:
1453: int
1454: vfork()
1455: {
1456: return(fork());
1457: }
1458:
1459: #endif
1460: 0707070000000000461006440044230044230000010000000475152536600003000000003136dir/dirlib.h Ugsf Ggsf /*
1461: * AT&T Bell Laboratories
1462: *
1463: * directory stream access library private definitions
1464: * handles 3d and preroot file systems
1465: */
1466:
1467: #include <preroot.h>
1468:
1469: #undef DIR
1470: #define DIR _SYS_DIR_
1471:
1472: #undef opendir
1473: #define opendir _SYS_opendir
1474:
1475: #undef readdir
1476: #define readdir _SYS_readdir
1477:
1478: #undef rewinddir
1479: #define rewinddir _SYS_rewinddir
1480:
1481: #undef seekdir
1482: #define seekdir _SYS_seekdir
1483:
1484: #undef telldir
1485: #define telldir _SYS_telldir
1486:
1487: #undef closedir
1488: #define closedir _SYS_closedir
1489:
1490: #define _dir_local 1
1491:
1492: #include <lclparam.h>
1493: #include <fsinfo.h>
1494: #include <dirent.h>
1495: #include <limits.h>
1496: #include <hash.h>
1497:
1498: #undef DIR
1499:
1500: typedef struct
1501: {
1502: int dd_fd; /* file descriptor */
1503: int dd_loc; /* offset in block */
1504: int dd_size; /* valid data in block */
1505: char* dd_buf; /* directory block */
1506:
1507: /* the rest are for 3d and preroot fs */
1508:
1509: unsigned char covered[sizeof(int)*CHAR_BIT];
1510: /* covered directory fds */
1511: ino_t opaque; /* opaque inode number */
1512: HASHTABLE* overlay; /* directory overlay hash */
1513: short numfd; /* number of covered fds */
1514: short nxtfd; /* next covered fd index */
1515: short fs3d; /* 3d in effect */
1516: } DIR; /* directory stream descriptor */
1517:
1518: #undef opendir
1519: extern DIR* opendir();
1520:
1521: #undef readdir
1522: extern struct dirent* readdir();
1523:
1524: #undef rewinddir
1525: extern void rewinddir();
1526:
1527: #undef seekdir
1528: extern void seekdir();
1529:
1530: #undef telldir
1531: extern long telldir();
1532:
1533: #undef closedir
1534: extern void closedir();
1535:
1536: #ifndef DIRBLKSIZ
1537: #ifdef DIRBLK
1538: #define DIRBLKSIZ DIRBLK
1539: #else
1540: #ifdef DIRBUF
1541: #define DIRBLKSIZ DIRBUF
1542: #else
1543: #ifdef DEV_BSIZE
1544: #define DIRBLKSIZ DEV_BSIZE
1545: #else
1546: #define DIRBLKSIZ 4096
1547: #endif
1548: #endif
1549: #endif
1550: #endif
1551: 0707070000000000471006440044230044230000010000000475137311700003100000004774dir/opendir.c Ugsf Ggsf /*
1552: * opendir, closedir
1553: *
1554: * open|close directory stream
1555: *
1556: * POSIX compatible directory stream access routines:
1557: *
1558: * #include <sys/types.h>
1559: * #include <dirent.h>
1560: *
1561: * NOTE: readdir() returns a pointer to struct dirent
1562: */
1563:
1564: #include "dirlib.h"
1565:
1566: #include <errno.h>
1567:
1568: #if !lint
1569: static char id[] = "\n@(#)directory (AT&T Bell Laboratories) 04/01/90\0\n";
1570: #endif
1571:
1572: static DIR* freedirp; /* always keep one dirp */
1573:
1574: extern int errno;
1575:
1576: extern char* malloc();
1577: extern char* strcopy();
1578: extern void free();
1579: extern int open();
1580: extern int close();
1581: extern int fclex();
1582: extern int fstat();
1583:
1584: DIR*
1585: opendir(path)
1586: register char* path;
1587: {
1588: register DIR* dirp = 0;
1589: register int fd;
1590: dev_t dev;
1591: ino_t ino;
1592: struct stat st;
1593:
1594: if ((fd = open(path, 0)) < 0) return(0);
1595: if (fstat(fd, &st) < 0 ||
1596: (st.st_mode & S_IFMT) != S_IFDIR && (errno = ENOTDIR) ||
1597: fclex(fd, 1) ||
1598: !(dirp = freedirp ? freedirp : (DIR*)malloc(sizeof(DIR) + DIRBLKSIZ)))
1599: {
1600: (void)close(fd);
1601: if (dirp)
1602: {
1603: if (!freedirp) freedirp = dirp;
1604: else free((char*)dirp);
1605: }
1606: return(0);
1607: }
1608: freedirp = 0;
1609: dirp->dd_fd = fd;
1610: dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
1611: dirp->dd_buf = (char*)dirp + sizeof(DIR);
1612:
1613: /*
1614: * handle 3d and preroot fs
1615: */
1616:
1617: dirp->numfd = dirp->nxtfd = 0;
1618: if (dirp->fs3d = fs3d(2))
1619: {
1620: char buf[PATH_MAX];
1621:
1622: dirp->opaque = 0;
1623: path = strcopy(buf, path);
1624: while (dirp->numfd < sizeof(dirp->covered) / sizeof(dirp->covered[0]))
1625: {
1626: path = strcopy(path, "/...");
1627: if ((fd = open(buf, 0)) < 0) break;
1628:
1629: /*
1630: * check for non-dirs or dirs covered by virtual dir
1631: */
1632:
1633: dev = st.st_dev;
1634: ino = st.st_ino;
1635: if (fstat(fd, &st) || ino == st.st_ino && dev == st.st_dev) (void)close(fd);
1636: else if ((st.st_mode & S_IFMT) != S_IFDIR)
1637: {
1638: (void)close(fd);
1639: break;
1640: }
1641: else
1642: {
1643: fclex(fd, 1);
1644: dirp->covered[dirp->numfd++] = fd;
1645: }
1646: }
1647: }
1648: #if defined(FS_PREROOT)
1649: else if ((fd = realopen(path, 0, 0)) >= 0)
1650: {
1651: dev = st.st_dev;
1652: ino = st.st_ino;
1653: if (fstat(fd, &st) || ino == st.st_ino && dev == st.st_dev || (st.st_mode & S_IFMT) != S_IFDIR) (void)close(fd);
1654: else
1655: {
1656: fclex(fd, 1);
1657: dirp->covered[dirp->numfd++] = fd;
1658: }
1659: }
1660: #endif
1661: dirp->overlay = dirp->numfd ? hashalloc((HASHTABLE*)0, HASH_set, HASH_ALLOCATE, 0) : 0;
1662: return(dirp);
1663: }
1664:
1665: void
1666: closedir(dirp)
1667: register DIR* dirp;
1668: {
1669: if (dirp)
1670: {
1671: (void)close(dirp->dd_fd);
1672: while (dirp->nxtfd < dirp->numfd) (void)close(dirp->covered[dirp->nxtfd++]);
1673: if (dirp->overlay) hashfree(dirp->overlay);
1674: if (!freedirp) freedirp = dirp;
1675: else free((char*)dirp);
1676: }
1677: }
1678: 0707070000000000501006440044230044230000010000000471771071500003100000002357dir/readdir.c Ugsf Ggsf /*
1679: * readdir
1680: *
1681: * read from directory stream
1682: *
1683: * NOTE: directory entries must fit within DIRBLKSIZ boundaries
1684: */
1685:
1686: #include "dirlib.h"
1687:
1688: struct dirent*
1689: readdir(dirp)
1690: register DIR* dirp;
1691: {
1692: register struct dirent* dp;
1693:
1694: for (;;)
1695: {
1696: if (dirp->dd_loc >= dirp->dd_size)
1697: {
1698: if (dirp->dd_size < 0) return(0);
1699: dirp->dd_loc = 0;
1700: if ((dirp->dd_size = getdents(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
1701: {
1702: uncover:
1703: if (dirp->nxtfd < dirp->numfd)
1704: {
1705: (void)close(dirp->dd_fd);
1706: dirp->dd_fd = dirp->covered[dirp->nxtfd++];
1707: dirp->dd_loc = 0;
1708: dirp->opaque = 0;
1709: continue;
1710: }
1711: return(0);
1712: }
1713: }
1714: dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc];
1715: if (dp->d_reclen <= 0) goto uncover;
1716: dirp->dd_loc += dp->d_reclen;
1717: if (dp->d_ino)
1718: {
1719: if (dirp->fs3d)
1720: {
1721: register char* s = dp->d_name;
1722:
1723: /*
1724: * skip opaque and hidden entries
1725: */
1726:
1727: if (*s++ == '.' && *s++ == '.' && *s++ == '.')
1728: {
1729: if (!*s) dirp->opaque = dp->d_ino;
1730: continue;
1731: }
1732: }
1733: if (dirp->overlay)
1734: {
1735: if (hashget(dirp->overlay, dp->d_name)) continue;
1736: if (dirp->nxtfd < dirp->numfd) hashput(dirp->overlay, 0, (char*)1);
1737: }
1738: if (dp->d_ino == dirp->opaque) continue;
1739: return(dp);
1740: }
1741: }
1742: /*NOTREACHED*/
1743: }
1744: 0707070000000000511006440044230044230000010000000445642251000003300000000277dir/rewinddir.c Ugsf Ggsf /*
1745: * rewinddir
1746: *
1747: * rewind directory stream
1748: * provided for POSIX compatibility
1749: */
1750:
1751: #include "dirlib.h"
1752:
1753: #undef rewinddir
1754:
1755: void
1756: rewinddir(dirp)
1757: register DIR *dirp;
1758: {
1759: seekdir(dirp, 0L);
1760: }
1761: 0707070000000000521006440044230044230000010000000440504372400003100000001005dir/seekdir.c Ugsf Ggsf /*
1762: * seekdir
1763: *
1764: * seek on directory stream
1765: */
1766:
1767: #include "dirlib.h"
1768:
1769: extern long lseek();
1770:
1771: void
1772: seekdir(dirp, loc)
1773: register DIR *dirp;
1774: long loc;
1775: {
1776: long base; /* file location of block */
1777: long offset; /* offset within block */
1778:
1779: if (telldir(dirp) != loc)
1780: {
1781: offset = loc % DIRBLKSIZ;
1782: base = loc - offset;
1783: (void)lseek(dirp->dd_fd, base, 0);
1784: dirp->dd_loc = dirp->dd_size = 0;
1785:
1786: /*
1787: * skip some entries
1788: */
1789:
1790: while (dirp->dd_loc < offset)
1791: if (!readdir(dirp))
1792: break; /* "can't happen" */
1793: }
1794: }
1795: 0707070000000000531006440044230044230000010000000440504373000003100000000334dir/telldir.c Ugsf Ggsf /*
1796: * telldir
1797: *
1798: * get offset of directory stream pointer
1799: */
1800:
1801: #include "dirlib.h"
1802:
1803: extern long lseek();
1804:
1805: long
1806: telldir(dirp)
1807: DIR *dirp;
1808: {
1809: return(lseek(dirp->dd_fd, 0L, 1) - (long)dirp->dd_size + (long)dirp->dd_loc);
1810: }
1811: 0707070000000000541006440044230044230000010000000472006660200003400000005102hash/hashalloc.c Ugsf Ggsf /*
1812: * G. S. Fowler
1813: * AT&T Bell Laboratories
1814: *
1815: * hash table library
1816: */
1817:
1818: #if !lint
1819: static char id[] = "\n@(#)hash (AT&T Bell Laboratories) 11/11/90\0\n";
1820: #endif
1821:
1822: #include "hashlib.h"
1823:
1824: #if !__STDC__
1825:
1826: #include <varargs.h>
1827:
1828: #endif
1829:
1830: struct hashinfo _hash_info_;
1831:
1832: /*
1833: * create a new hash table
1834: */
1835:
1836: #if __STDC__
1837:
1838: HASHTABLE*
1839: hashalloc(HASHTABLE* ref, ...)
1840:
1841: #else
1842:
1843: HASHTABLE*
1844: hashalloc(va_alist)
1845: va_dcl
1846:
1847: #endif
1848:
1849: {
1850: va_list ap;
1851: #if !__STDC__
1852: register HASHTABLE* ref;
1853: #endif
1854:
1855: #if __STDC__
1856: va_start(ap, ref);
1857: #else
1858: va_start(ap);
1859: ref = va_arg(ap, HASHTABLE*);
1860: #endif
1861: ref = hashvalloc(ref, ap);
1862: va_end(ap);
1863: return(ref);
1864: }
1865:
1866: /*
1867: * varargs interface to hashalloc()
1868: */
1869:
1870: HASHTABLE*
1871: hashvalloc(ref, ap)
1872: register HASHTABLE* ref;
1873: va_list ap;
1874: {
1875: register HASHTABLE* tab;
1876: int internal;
1877:
1878: if (!(tab = (HASHTABLE*)calloc(1, sizeof(HASHTABLE)))) goto bad;
1879: if (ref)
1880: {
1881: tab->flags = ref->flags & ~HASH_RESET;
1882: tab->root = ref->root;
1883: internal = HASH_INTERNAL;
1884: }
1885: else
1886: {
1887: if (!(tab->root = (HASHROOT*)calloc(1, sizeof(HASHROOT)))) goto bad;
1888: tab->root->meanchain = HASHMEANCHAIN;
1889: internal = 0;
1890: }
1891: tab->size = HASHMINSIZE;
1892: for (;;) switch (va_arg(ap, int))
1893: {
1894: case HASH_alloc:
1895: if (ref) goto bad;
1896: tab->root->alloc = va_arg(ap, HASHPTR);
1897: break;
1898: case HASH_clear:
1899: tab->flags &= ~(va_arg(ap, int) & ~internal);
1900: break;
1901: case HASH_compare:
1902: if (ref) goto bad;
1903: tab->root->compare = va_arg(ap, HASHINT);
1904: break;
1905: case HASH_free:
1906: if (ref) goto bad;
1907: tab->root->free = va_arg(ap, HASHINT);
1908: break;
1909: case HASH_hash:
1910: if (ref) goto bad;
1911: tab->root->hash = va_arg(ap, HASHFUN);
1912: break;
1913: case HASH_meanchain:
1914: if (ref) goto bad;
1915: tab->root->meanchain = va_arg(ap, int);
1916: break;
1917: case HASH_name:
1918: tab->name = va_arg(ap, char*);
1919: break;
1920: case HASH_namesize:
1921: if (ref) goto bad;
1922: tab->root->namesize = va_arg(ap, int);
1923: break;
1924: case HASH_set:
1925: tab->flags |= (va_arg(ap, int) & ~internal);
1926: break;
1927: case HASH_size:
1928: tab->size = va_arg(ap, int);
1929: if (tab->size & (tab->size - 1)) tab->flags |= HASH_FIXED;
1930: break;
1931: case HASH_table:
1932: tab->table = va_arg(ap, HASHBUCKET**);
1933: tab->flags |= HASH_STATIC;
1934: break;
1935: case 0:
1936: if (tab->flags & HASH_SCOPE)
1937: {
1938: if (!(tab->scope = ref)) goto bad;
1939: ref->frozen++;
1940: }
1941: if (!tab->table && !(tab->table = (HASHBUCKET**)calloc(1, sizeof(HASHBUCKET*) * tab->size))) goto bad;
1942: if (!ref)
1943: {
1944: tab->root->flags = tab->flags & HASH_INTERNAL;
1945: tab->root->next = hash_info.list;
1946: hash_info.list = tab->root;
1947: }
1948: tab->next = tab->root->references;
1949: tab->root->references = tab;
1950: return(tab);
1951: default:
1952: goto bad;
1953: }
1954: bad:
1955: (void)hashfree(tab);
1956: return(0);
1957: }
1958: 0707070000000000551006440044230044230000010000000467350644100003300000010352hash/hashdump.c Ugsf Ggsf /*
1959: * G. S. Fowler
1960: * AT&T Bell Laboratories
1961: *
1962: * hash table library
1963: */
1964:
1965: #include <stdio.h>
1966:
1967: #include "hashlib.h"
1968:
1969: static void dumproot();
1970: static void dumptable();
1971: static void dumpflags();
1972: static void dumpbucket();
1973:
1974: /*
1975: * dump hash table accounting info
1976: * if tab is 0 then dump all tables in hash_info.list
1977: * flags are HASH_* flags that specifiy optional dump info
1978: */
1979:
1980: void
1981: hashdump(fp, tab, flags)
1982: register FILE* fp;
1983: register HASHTABLE* tab;
1984: int flags;
1985: {
1986: register HASHROOT* root;
1987:
1988: fprintf(fp, "\nhash table information:\n\n");
1989: if (tab) dumproot(fp, tab->root, flags);
1990: else for (root = hash_info.list; root; root = root->next)
1991: dumproot(fp, root, flags);
1992: fflush(fp);
1993: }
1994:
1995: /*
1996: * dump hash table root info
1997: */
1998:
1999: static void
2000: dumproot(fp, root, flags)
2001: register FILE* fp;
2002: register HASHROOT* root;
2003: register int flags;
2004: {
2005: register HASHTABLE* tab;
2006:
2007: fprintf(fp, " root\n");
2008: fprintf(fp, " address: 0x%08lx\n", (unsigned long)root);
2009: fprintf(fp, " flags: ");
2010: dumpflags(fp, root->flags);
2011: if (root->namesize) fprintf(fp, "namesize=%d ", root->namesize);
2012: if (root->alloc) fprintf(fp, "alloc=0x%08lx ", (unsigned long)root->alloc);
2013: if (root->compare) fprintf(fp, "compare=0x%08lx ", (unsigned long)root->compare);
2014: if (root->free) fprintf(fp, "free=0x%08lx ", (unsigned long)root->free);
2015: if (root->hash) fprintf(fp, "hash=0x%08lx ", (unsigned long)root->hash);
2016: fprintf(fp, "\n");
2017: fprintf(fp, " meanchain: %d\n", root->meanchain);
2018: fprintf(fp, " accesses: %d\n", root->accesses);
2019: fprintf(fp, " collisions: %d\n", root->collisions);
2020: fprintf(fp, "\n");
2021: for (tab = root->references; tab; tab = tab->next)
2022: dumptable(fp, tab, flags);
2023: }
2024:
2025: /*
2026: * dump info on a single table
2027: */
2028:
2029: static void
2030: dumptable(fp, tab, flags)
2031: register FILE* fp;
2032: register HASHTABLE* tab;
2033: register int flags;
2034: {
2035: HASHTABLE* scope;
2036: int level;
2037:
2038: fprintf(fp, " name: %s", tab->name ? tab->name : "*no name*");
2039: if (scope = tab->scope)
2040: {
2041: level = 1;
2042: while (scope = scope->scope) level++;
2043: fprintf(fp, " level %d scope on 0x%08lx", level, (unsigned long)tab->scope);
2044: }
2045: fprintf(fp, "\n");
2046: fprintf(fp, " address: 0x%08lx\n", (unsigned long)tab);
2047: fprintf(fp, " flags: ");
2048: if (tab->frozen) fprintf(fp, "frozen=%d ", tab->frozen);
2049: dumpflags(fp, tab->flags);
2050: fprintf(fp, "\n");
2051: fprintf(fp, " size: %d\n", tab->size);
2052: fprintf(fp, " buckets: %d\n", tab->buckets);
2053: fprintf(fp, "\n");
2054: if ((flags | tab->flags) & HASH_BUCKET) dumpbucket(fp, tab, flags);
2055: }
2056:
2057: /*
2058: * dump HASH_* flags
2059: */
2060:
2061: static void
2062: dumpflags(fp, flags)
2063: register FILE* fp;
2064: register int flags;
2065: {
2066: if (flags & HASH_ALLOCATE) fprintf(fp, "allocate ");
2067: if (flags & HASH_BUCKET) fprintf(fp, "bucket ");
2068: if (flags & HASH_FIXED) fprintf(fp, "fixed ");
2069: if (flags & HASH_HASHED) fprintf(fp, "hashed ");
2070: if (flags & HASH_RESIZE) fprintf(fp, "resize ");
2071: if (flags & HASH_SCANNING) fprintf(fp, "scanning ");
2072: if (flags & HASH_STATIC) fprintf(fp, "static ");
2073: if (flags & HASH_VALUE) fprintf(fp, "value ");
2074: }
2075:
2076: /*
2077: * dump hash table bucket info
2078: */
2079:
2080: /*ARGSUSED*/
2081: static void
2082: dumpbucket(fp, tab, flags)
2083: register FILE* fp;
2084: register HASHTABLE* tab;
2085: int flags;
2086: {
2087: register HASHBUCKET** sp;
2088: register HASHBUCKET* b;
2089: HASHBUCKET** sx;
2090: int n;
2091: unsigned char* s;
2092:
2093: sx = tab->table + tab->size;
2094: for (sp = tab->table; sp < sx; sp++)
2095: {
2096: n = 0;
2097: for (b = *sp; b; b = b->next)
2098: if (!(b->hash & HASH_DELETED) && (!(tab->flags & HASH_VALUE) || b->value))
2099: n++;
2100: if (n)
2101: {
2102: fprintf(fp, "%5d %2d :", sp - tab->table, n);
2103: for (b = *sp; b; b = b->next)
2104: if (!(b->hash & HASH_DELETED) && (!(tab->flags & HASH_VALUE) || b->value))
2105: {
2106: if (n = tab->root->namesize)
2107: {
2108: fprintf(fp, " 0x");
2109: s = (unsigned char*)hashname(b);
2110: while (n-- > 0)
2111: fprintf(fp, "%02x", *s++);
2112: }
2113: else fprintf(fp, " %s", hashname(b));
2114: if (b->hash & HASH_FLAGS)
2115: {
2116: fprintf(fp, "|");
2117: if (b->hash & HASH_HIDES) fprintf(fp, "hides|");
2118: if (b->hash & HASH_HIDDEN) fprintf(fp, "hidden|");
2119: if (b->hash & HASH_KEEP) fprintf(fp, "keep|");
2120: if (b->hash & HASH_OPAQUED) fprintf(fp, "opaque|");
2121: }
2122: if (tab->flags & HASH_VALUE) fprintf(fp, "=0x%08lx", (long)b->value);
2123: }
2124: fprintf(fp, "\n");
2125: }
2126: }
2127: fprintf(fp, "\n");
2128: }
2129: 0707070000000000561006440044230044230000010000000467522022400003300000003204hash/hashfree.c Ugsf Ggsf /*
2130: * G. S. Fowler
2131: * AT&T Bell Laboratories
2132: *
2133: * hash table library
2134: */
2135:
2136: #include "hashlib.h"
2137:
2138: /*
2139: * free (remove) a hash table
2140: * can be called for partially constructed tables
2141: * scope covered table pointer is returned
2142: * root info freed when last reference freed
2143: */
2144:
2145: HASHTABLE*
2146: hashfree(tab)
2147: register HASHTABLE* tab;
2148: {
2149: register HASHBUCKET** sp;
2150: register HASHBUCKET* b;
2151: register HASHBUCKET* p;
2152: HASHBUCKET** sx;
2153: HASHROOT* rp;
2154: HASHTABLE* tp;
2155: HASHINT freevalue;
2156: HASHINT freebucket;
2157:
2158: if (!tab) return(0);
2159: if (tab->table)
2160: {
2161: freebucket = (HASHINT)free;
2162: freevalue = 0;
2163: if (tab->root->free)
2164: {
2165: if (tab->root->flags & HASH_BUCKET) freebucket = tab->root->free;
2166: else freevalue = tab->root->free;
2167: }
2168: sx = &tab->table[tab->size];
2169: sp = &tab->table[0];
2170: while (sp < sx)
2171: {
2172: b = *sp++;
2173: while (b)
2174: {
2175: if (freevalue && b->value) (void)(*freevalue)(b->value);
2176: p = b;
2177: b = b->next;
2178: if (!(p->hash & HASH_KEEP)) (*freebucket)(p);
2179: }
2180: }
2181: if ((tab->flags & (HASH_RESIZE|HASH_STATIC)) != HASH_STATIC) free(tab->table);
2182: }
2183: if (tab->root)
2184: {
2185: /*
2186: * remove from the table lists
2187: */
2188:
2189: if ((tp = tab->root->references) != tab)
2190: {
2191: for (; tp; tp = tp->next)
2192: if (tp->next == tab)
2193: {
2194: tp->next = tab->next;
2195: break;
2196: }
2197: }
2198: else if (!(tab->root->references = tp->next))
2199: {
2200: if ((rp = hash_info.list) != tab->root)
2201: {
2202: for (; rp; rp = rp->next)
2203: if (rp->next == tab->root)
2204: {
2205: rp->next = tab->root->next;
2206: break;
2207: }
2208: }
2209: else hash_info.list = rp->next;
2210: }
2211: if (!(tab->root->references)) free(tab->root);
2212: }
2213: if (tp = tab->scope) tp->frozen--;
2214: free(tab);
2215: return(tp);
2216: }
2217: 0707070000000000571006440044230044230000010000000475447420200003200000001474hash/hashlib.h Ugsf Ggsf /*
2218: * G. S. Fowler
2219: * AT&T Bell Laboratories
2220: *
2221: * hash table library private definitions
2222: */
2223:
2224: #include <limits.h>
2225: #include <hash.h>
2226:
2227: #define HASHMINSIZE (1<<4) /* min table slots (power of 2) */
2228: #define HASHMEANCHAIN 2 /* def resize mean chain len */
2229:
2230: #define HASHMOD(t,h) (h &= (t->size - 1))
2231: #define HASHVAL(x) ((x)&~HASH_FLAGS)
2232:
2233: #define HASH(r,n,h) if (r->hash) h = r->namesize ? (*r->hash)(n, r->namesize) : (*r->hash)(n);\
2234: else\
2235: {\
2236: register const char* _hash_s1 = n;\
2237: h = 0;\
2238: if (r->namesize)\
2239: {\
2240: register const char* _hash_s2 = _hash_s1 + r->namesize;\
2241: while (_hash_s1 < _hash_s2) HASHPART(h, *_hash_s1++);\
2242: }\
2243: else while (*_hash_s1) HASHPART(h, *_hash_s1++);\
2244: }
2245:
2246: extern char* calloc();
2247: extern char* malloc();
2248: extern char* memcpy();
2249:
2250: extern int strlen();
2251:
2252: extern void free();
2253: 0707070000000000601006440044230044230000010000000475447433400003300000012052hash/hashlook.c Ugsf Ggsf /*
2254: * G. S. Fowler
2255: * AT&T Bell Laboratories
2256: *
2257: * hash table library
2258: */
2259:
2260: #include "hashlib.h"
2261:
2262: /*
2263: * hash table lookup
2264: */
2265:
2266: #if __STDC__ || __cplusplus
2267: char*
2268: hashlook(register HASHTABLE* tab, const char* name, int flags, const char* value)
2269: #else
2270: #ifndef const
2271: #define const
2272: #endif
2273: char*
2274: hashlook(tab, name, flags, value)
2275: register HASHTABLE* tab;
2276: char* name;
2277: int flags;
2278: char* value;
2279: #endif
2280: {
2281: register HASHBUCKET* b;
2282: register unsigned int n;
2283: HASHTABLE* top;
2284: HASHBUCKET* prev;
2285: unsigned int i;
2286:
2287: static const char* lastname;
2288: static unsigned int lasthash;
2289:
2290: tab->root->accesses++;
2291: top = tab;
2292: if (name)
2293: {
2294: hash_info.table = tab;
2295: if (flags & (HASH_BUCKET|HASH_INSTALL))
2296: {
2297: hash_info.last = (HASHBUCKET*)name;
2298: name = hashname(hash_info.last);
2299: }
2300: else hash_info.last = 0;
2301: lastname = name;
2302: if (flags & HASH_BUCKET) n = hash_info.last->hash;
2303: else if (tab->flags & HASH_HASHED) n = ((unsigned int)name) >> 3;
2304: else HASH(tab->root, name, n);
2305: lasthash = i = HASHVAL(n);
2306: for (;;)
2307: {
2308: HASHMOD(tab, n);
2309: for (prev = 0, b = tab->table[n]; b; prev = b, b = b->next)
2310: {
2311: if (i == HASHVAL(b->hash) && ((b->hash & (HASH_DELETED|HASH_OPAQUED)) != HASH_DELETED || (flags & (HASH_CREATE|HASH_DELETE|HASH_INSTALL))))
2312: {
2313: if (!tab->root->compare)
2314: {
2315: register char* s1 = hashname(b);
2316: register const char* s2 = name;
2317:
2318: if (tab->root->namesize)
2319: {
2320: register char* s3 = s1 + tab->root->namesize;
2321:
2322: while (*s1++ == *s2++)
2323: if (s1 >= s3) goto found;
2324: }
2325: else while (*s1 == *s2++)
2326: if (!*s1++) goto found;
2327: }
2328: else if (tab->root->namesize)
2329: {
2330: if (!(*tab->root->compare)(hashname(b), name, tab->root->namesize)) goto found;
2331: }
2332: else if (!(*tab->root->compare)(hashname(b), name)) goto found;
2333: }
2334: tab->root->collisions++;
2335: }
2336: if (!tab->scope || (flags & (HASH_CREATE|HASH_INSTALL|HASH_NOSCOPE)) == HASH_NOSCOPE) break;
2337: tab = tab->scope;
2338: n = i;
2339: }
2340: }
2341: else
2342: {
2343: tab = hash_info.table;
2344: name = lastname;
2345: prev = 0;
2346: n = i = lasthash;
2347: HASHMOD(tab, n);
2348: if (b = hash_info.last)
2349: {
2350: /*
2351: * found the bucket
2352: */
2353:
2354: found:
2355: if (prev && !(tab->flags & HASH_SCANNING))
2356: {
2357: /*
2358: * migrate popular buckets to the front
2359: */
2360:
2361: prev->next = b->next;
2362: b->next = tab->table[n];
2363: tab->table[n] = b;
2364: }
2365: switch (flags & (HASH_CREATE|HASH_DELETE|HASH_INSTALL))
2366: {
2367: case HASH_CREATE:
2368: case HASH_INSTALL:
2369: if (tab != top && !(flags & HASH_SCOPE)) break;
2370: if (flags & HASH_OPAQUE) b->hash |= HASH_OPAQUED;
2371: goto exists;
2372:
2373: case HASH_DELETE:
2374: value = 0;
2375: if (tab == top || (flags & HASH_SCOPE))
2376: {
2377: if (flags & HASH_OPAQUE) b->hash &= ~HASH_OPAQUED;
2378: else if (!(tab->root->flags & HASH_BUCKET))
2379: {
2380: if (tab->root->free && b->value)
2381: {
2382: (*tab->root->free)(b->value);
2383: b->value = 0;
2384: }
2385: else if (tab->flags & HASH_VALUE)
2386: {
2387: value = b->value;
2388: b->value = 0;
2389: }
2390: }
2391: if (tab->frozen || (b->hash & (HASH_KEEP|HASH_OPAQUED))) b->hash |= HASH_DELETED;
2392: else
2393: {
2394: tab->buckets--;
2395: tab->table[n] = b->next;
2396: if (tab->root->free && (tab->root->flags & HASH_BUCKET)) (*tab->root->free)(b);
2397: else free(b);
2398: }
2399: }
2400: return((char*)value);
2401: default:
2402: if (!(b->hash & HASH_DELETED)) goto exists;
2403: return(0);
2404: }
2405: }
2406: }
2407: if (!(flags & (HASH_CREATE|HASH_INSTALL))) return(0);
2408:
2409: /*
2410: * create a new bucket
2411: */
2412:
2413: if (tab == top) prev = 0;
2414: else
2415: {
2416: if (prev = b)
2417: {
2418: name = (b->hash & HASH_HIDES) ? b->name : (char*)b;
2419: i |= HASH_HIDES;
2420: }
2421: if (!(flags & HASH_SCOPE)) tab = top;
2422: }
2423:
2424: /*
2425: * check for table expansion
2426: */
2427:
2428: if (!tab->frozen && !(tab->flags & HASH_FIXED) && tab->buckets > tab->root->meanchain * tab->size) hashsize(tab, tab->size << 1);
2429: if (flags & HASH_INSTALL)
2430: {
2431: b = hash_info.last;
2432: i |= HASH_KEEP;
2433: }
2434: else
2435: {
2436: if (flags & HASH_VALUE)
2437: {
2438: tab->flags |= HASH_VALUE;
2439: n = sizeof(HASHBUCKET);
2440: }
2441: else if (!(flags & HASH_FIXED)) n = sizeof(HASHHEADER);
2442: else if ((n = (int)value) < sizeof(HASHHEADER)) n = sizeof(HASHHEADER);
2443: if (!prev && (tab->flags & HASH_ALLOCATE))
2444: {
2445: int m = tab->root->namesize ? tab->root->namesize : strlen(name) + 1;
2446: if (!(b = (HASHBUCKET*)calloc(1, n + m))) return(0);
2447: b->name = (char*)b + n;
2448: (void)memcpy(b->name, name, m);
2449: }
2450: else
2451: {
2452: if (!(b = (HASHBUCKET*)calloc(1, n))) return(0);
2453: b->name = (char*)name;
2454: }
2455: }
2456: b->hash = n = i;
2457: HASHMOD(tab, n);
2458: b->next = tab->table[n];
2459: tab->table[n] = b;
2460: tab->buckets++;
2461: if (flags & HASH_OPAQUE)
2462: {
2463: b->hash |= HASH_DELETED|HASH_OPAQUED;
2464: return(0);
2465: }
2466: exists:
2467:
2468: /*
2469: * finally got the bucket
2470: */
2471:
2472: b->hash &= ~HASH_DELETED;
2473: hash_info.last = b;
2474: hash_info.table = tab;
2475: switch (flags & (HASH_CREATE|HASH_VALUE))
2476: {
2477: case HASH_CREATE|HASH_VALUE:
2478: if (tab->root->free && !(tab->root->flags & HASH_BUCKET) && b->value) (*tab->root->free)(b->value);
2479: if (value && tab->root->alloc) value = (*tab->root->alloc)(value);
2480: b->value = (char*)value;
2481: return((char*)hashname(b));
2482: case HASH_VALUE:
2483: return(b->value);
2484: default:
2485: return((char*)b);
2486: }
2487: }
2488: 0707070000000000611006440044230044230000010000000466426707700003300000004205hash/hashscan.c Ugsf Ggsf /*
2489: * G. S. Fowler
2490: * AT&T Bell Laboratories
2491: *
2492: * hash table library
2493: */
2494:
2495: #include "hashlib.h"
2496:
2497: /*
2498: * hash table sequential scan
2499: *
2500: * HASHPOSITION pos;
2501: * HASHBUCKET* b;
2502: * hashscan(tab, flags, &pos);
2503: * while (b = hashnext(&pos)) ...;
2504: * hashdone(&pos);
2505: */
2506:
2507: /*
2508: * initialize pos for scan on table
2509: */
2510:
2511: void
2512: hashscan(tab, flags, pos)
2513: register HASHTABLE* tab;
2514: register int flags;
2515: register HASHPOSITION* pos;
2516: {
2517: static HASHBUCKET empty;
2518:
2519: pos->tab = pos->top = tab;
2520: pos->bucket = ∅
2521: pos->slot = tab->table - 1;
2522: pos->limit = tab->table + tab->size;
2523: if (tab->scope && !(flags & HASH_NOSCOPE))
2524: {
2525: pos->flags = HASH_SCOPE;
2526: do
2527: {
2528: register HASHBUCKET* b;
2529:
2530: if (tab->flags & HASH_SCANNING)
2531: {
2532: register HASHBUCKET** sp = tab->table;
2533: register HASHBUCKET** sx = tab->table + tab->size;
2534:
2535: while (sp < sx)
2536: for (b = *sp++; b; b = b->next)
2537: b->hash &= ~HASH_HIDDEN;
2538: }
2539: } while (tab = tab->scope);
2540: tab = pos->tab;
2541: }
2542: else pos->flags = 0;
2543: tab->flags |= HASH_SCANNING;
2544: tab->frozen++;
2545: }
2546:
2547: /*
2548: * return next scan element
2549: */
2550:
2551: HASHBUCKET*
2552: hashnext(pos)
2553: register HASHPOSITION* pos;
2554: {
2555: register HASHBUCKET* b;
2556:
2557: b = pos->bucket;
2558: for (;;)
2559: {
2560: if (!(b = b->next))
2561: {
2562: do
2563: {
2564: if (++pos->slot >= pos->limit)
2565: {
2566: pos->tab->flags &= ~HASH_SCANNING;
2567: pos->tab->frozen--;
2568: if (!pos->flags || !pos->tab->scope) return(0);
2569: pos->tab = pos->tab->scope;
2570: pos->limit = (pos->slot = pos->tab->table) + pos->tab->size;
2571: pos->tab->flags |= HASH_SCANNING;
2572: pos->tab->frozen++;
2573: }
2574: } while (!(b = *pos->slot));
2575: }
2576: if (!(b->hash & HASH_DELETED) && (!(pos->tab->flags & HASH_VALUE) || b->value) && (!pos->flags || !(b->hash & (HASH_HIDDEN|HASH_HIDES)))) break;
2577: if (b->hash & HASH_HIDES)
2578: {
2579: register HASHBUCKET* h = (HASHBUCKET*)b->name;
2580:
2581: if (!(h->hash & HASH_HIDDEN))
2582: {
2583: h->hash |= HASH_HIDDEN;
2584: if (!(b->hash & HASH_DELETED)) break;
2585: }
2586: }
2587: else b->hash &= ~HASH_HIDDEN;
2588: }
2589: return(hash_info.last = pos->bucket = b);
2590: }
2591:
2592: /*
2593: * terminate scan
2594: */
2595:
2596: void
2597: hashdone(pos)
2598: register HASHPOSITION* pos;
2599: {
2600: if (pos->tab->flags & HASH_SCANNING)
2601: {
2602: pos->tab->flags &= ~HASH_SCANNING;
2603: pos->tab->frozen--;
2604: }
2605: }
2606: 0707070000000000621006440044230044230000010000000445242664000003300000001771hash/hashsize.c Ugsf Ggsf /*
2607: * G. S. Fowler
2608: * AT&T Bell Laboratories
2609: *
2610: * hash table library
2611: */
2612:
2613: #include "hashlib.h"
2614:
2615: /*
2616: * change table size and rehash
2617: * size must be a power of 2
2618: */
2619:
2620: void
2621: hashsize(tab, size)
2622: register HASHTABLE* tab;
2623: int size;
2624: {
2625: register HASHBUCKET** old_s;
2626: register HASHBUCKET** new_s;
2627: register HASHBUCKET* old_b;
2628: register HASHBUCKET* new_b;
2629: HASHBUCKET** old_sx;
2630: unsigned int index;
2631:
2632: if (size > 0 && size != tab->size && !(size & (size - 1)))
2633: {
2634: if (!(new_s = (HASHBUCKET**)calloc(size, sizeof(HASHBUCKET*)))) tab->flags |= HASH_FIXED;
2635: else
2636: {
2637: old_sx = (old_s = tab->table) + tab->size;
2638: tab->size = size;
2639: while (old_s < old_sx)
2640: {
2641: old_b = *old_s++;
2642: while (old_b)
2643: {
2644: new_b = old_b;
2645: old_b = old_b->next;
2646: index = new_b->hash;
2647: HASHMOD(tab, index);
2648: new_b->next = new_s[index];
2649: new_s[index] = new_b;
2650: }
2651: }
2652: if ((tab->flags & (HASH_RESIZE|HASH_STATIC)) != HASH_STATIC) free(tab->table);
2653: tab->table = new_s;
2654: tab->flags |= HASH_RESIZE;
2655: }
2656: }
2657: }
2658: 0707070000000000631006440044230044230000010000000471771043600003300000000771hash/hashwalk.c Ugsf Ggsf /*
2659: * G. S. Fowler
2660: * AT&T Bell Laboratories
2661: *
2662: * hash table library
2663: */
2664:
2665: #include "hashlib.h"
2666:
2667: /*
2668: * apply walker to each active bucket in the table
2669: */
2670:
2671: int
2672: hashwalk(tab, flags, walker)
2673: HASHTABLE* tab;
2674: int flags;
2675: register HASHINT walker;
2676: {
2677: register HASHBUCKET* b;
2678: register int v;
2679: HASHPOSITION pos;
2680:
2681: v = 0;
2682: hashscan(tab, flags, &pos);
2683: while (b = hashnext(&pos))
2684: if ((v = (*walker)(hashname(b), (tab->flags & HASH_VALUE) ? b->value : (char*)b)) < 0)
2685: break;
2686: hashdone(&pos);
2687: return(v);
2688: }
2689: 0707070000000000641006440044230044230000010000000475447450300003200000000703hash/memhash.c Ugsf Ggsf /*
2690: * G. S. Fowler
2691: * AT&T Bell Laboratories
2692: *
2693: * hash table library
2694: */
2695:
2696: #include "hashlib.h"
2697:
2698: /*
2699: * return the hash of buffer s of length n
2700: */
2701:
2702: #if __STDC__ || __cplusplus
2703: unsigned int
2704: memhash(register const char* s, int n)
2705: #else
2706: #ifndef const
2707: #define const
2708: #endif
2709: unsigned int
2710: memhash(s, n)
2711: register char* s;
2712: int n;
2713: #endif
2714: {
2715: register const char* e;
2716: register unsigned int c;
2717:
2718: e = s + n;
2719: c = 0;
2720: while (s < e) HASHPART(c, *s++);
2721: return(c);
2722: }
2723: 0707070000000000651006440044230044230000010000000475446041300003100000001300hash/memsum.c Ugsf Ggsf /*
2724: * G. S. Fowler
2725: * AT&T Bell Laboratories
2726: *
2727: * hash table library
2728: */
2729:
2730: #include "hashlib.h"
2731:
2732: /*
2733: * return a running 32 bit checksum of buffer b of length n
2734: *
2735: * c is the return value from a previous
2736: * memsum() or strsum() call, 0 on the first call
2737: *
2738: * the result is the same on all implementations
2739: */
2740:
2741: #if __STDC__ || __cplusplus
2742: unsigned long
2743: memsum(const char* b, int n, register unsigned long c)
2744: #else
2745: unsigned long
2746: memsum(b, n, c)
2747: char* b;
2748: int n;
2749: register unsigned long c;
2750: #endif
2751: {
2752: register unsigned char* p;
2753: register unsigned char* e;
2754:
2755: p = (unsigned char*)b;
2756: e = p + n;
2757: while (p < e) HASHPART(c, *p++);
2758: #if LONG_MAX > 2147483647
2759: return(c & 0xffffffff);
2760: #else
2761: return(c);
2762: #endif
2763: }
2764: 0707070000000000661006440044230044230000010000000475446047400003200000000655hash/strhash.c Ugsf Ggsf /*
2765: * G. S. Fowler
2766: * AT&T Bell Laboratories
2767: *
2768: * hash table library
2769: */
2770:
2771: #include "hashlib.h"
2772:
2773: /*
2774: * return the hash of the null terminated string s
2775: */
2776:
2777: #if __STDC__ || __cplusplus
2778: unsigned int
2779: strhash(const char* s)
2780: #else
2781: unsigned int
2782: strhash(s)
2783: char* s;
2784: #endif
2785: {
2786: register unsigned char* p;
2787: register unsigned int i;
2788: register unsigned int c;
2789:
2790: i = 0;
2791: p = (unsigned char*)s;
2792: while (c = *p++) HASHPART(i, c);
2793: return(i);
2794: }
2795: 0707070000000000671006440044230044230000010000000475446057700003100000001213hash/strsum.c Ugsf Ggsf /*
2796: * G. S. Fowler
2797: * AT&T Bell Laboratories
2798: *
2799: * hash table library
2800: */
2801:
2802: #include "hashlib.h"
2803:
2804: /*
2805: * return a running 32 bit checksum of string s
2806: *
2807: * c is the return value from a previous
2808: * memsum() or strsum() call, 0 on the first call
2809: *
2810: * the result is the same on all implementations
2811: */
2812:
2813: #if __STDC__ || __cplusplus
2814: unsigned long
2815: strsum(const char* s, register unsigned long c)
2816: #else
2817: unsigned long
2818: strsum(s, c)
2819: char* s;
2820: register unsigned long c;
2821: #endif
2822: {
2823: register unsigned char* p;
2824: register int n;
2825:
2826: p = (unsigned char*)s;
2827: while (n = *p++) HASHPART(c, n);
2828: #if LONG_MAX > 2147483647
2829: return(c & 0xffffffff);
2830: #else
2831: return(c);
2832: #endif
2833: }
2834: 0707070000000000701006440044230044230000010000000475434343600003300000002654include/error.h Ugsf Ggsf /*
2835: * G. S. Fowler
2836: * AT&T Bell Laboratories
2837: *
2838: * option, error and message formatter external definitions
2839: */
2840:
2841: #ifndef ERROR_INFO
2842:
2843: #include <option.h>
2844: #include <errno.h>
2845:
2846: #ifndef VOID
2847: #define VOID char
2848: #endif
2849:
2850: #define ERROR_INFO 0 /* info message -- no err_id */
2851: #define ERROR_WARNING 1 /* warning message */
2852: #define ERROR_ERROR 2 /* error message -- no err_exit */
2853: #define ERROR_FATAL 3 /* error message with err_exit */
2854: #define ERROR_PANIC ERROR_LEVEL /* panic message with err_exit */
2855:
2856: #define ERROR_LEVEL 000077 /* level portion of status */
2857: #define ERROR_SYSTEM 000100 /* report system errno message */
2858: #define ERROR_OUTPUT 000200 /* next arg is error fd */
2859: #define ERROR_SOURCE 000400 /* next 2 args are FILE,LINE */
2860: #define ERROR_USAGE 001000 /* usage message */
2861: #define ERROR_PROMPT 002000 /* omit trailing newline */
2862: #define ERROR_NOID 004000 /* omit err_id */
2863: #define ERROR_LIBRARY 010000 /* library routine error */
2864:
2865: #if __cplusplus
2866: extern "C" {
2867: #endif
2868:
2869: extern int errno; /* system call error status */
2870:
2871: #if __cplusplus
2872: }
2873: #endif
2874:
2875: #if __STDC__ || __cplusplus || c_plusplus
2876: #include <stdarg.h>
2877: #if __cplusplus
2878: extern "C" {
2879: #endif
2880: extern char* seterror(int, ...);
2881: extern void error(int, ...);
2882: extern void liberror(const char*, int, ...);
2883: extern void verror(const char*, int, va_list);
2884: #if __cplusplus
2885: }
2886: #endif
2887: #else
2888: extern char* seterror();
2889: extern void error();
2890: extern void liberror();
2891: extern void verror();
2892: #endif
2893:
2894: #endif
2895: 0707070000000000711006440044230044230000010000000475446100700003400000005664include/ftwalk.h Ugsf Ggsf /*
2896: * K. P. Vo
2897: * AT&T Bell Laboratories
2898: *
2899: * ftwalk(3) interface definitions
2900: */
2901:
2902: #ifndef FTW_DOT
2903:
2904: #ifndef VOID
2905: #define VOID char
2906: #endif
2907:
2908: /*
2909: * ftwalk() argument flags
2910: */
2911:
2912: #define FTW_CHILDREN (1<<0) /* call user function on child dirs too */
2913: #define FTW_DELAY (1<<1) /* do child stat after parent preorder */
2914: #define FTW_DOT (1<<2) /* don't chdir(2) to subdirectories */
2915: #define FTW_MULTIPLE (1<<3) /* path arg is 0 terminated char** argv */
2916: #define FTW_PHYSICAL (1<<4) /* physical rather than logical walk */
2917: #define FTW_POST (1<<5) /* visit descendants before parent */
2918: #define FTW_TWICE (1<<6) /* visit parent before&after descendants*/
2919:
2920: #define FTW_USER (1<<10) /* first user flag bit */
2921:
2922: struct FTW /* user function arg */
2923: {
2924: struct FTW* left; /* left child in cycle check tree */
2925: struct FTW* right; /* right child in cycle check tree */
2926: struct FTW* link; /* identical to this elt on search path */
2927: struct FTW* parent; /* parent in current search path */
2928: union
2929: {
2930: long number; /* local number */
2931: char* pointer;/* local pointer */
2932: } local; /* local user data */
2933: struct stat statb; /* stat buffer of this object */
2934: char* path; /* full pathname */
2935: short pathlen;/* strlen(path) */
2936: unsigned short info; /* FTW_* type bits */
2937: unsigned short status; /* user function entry/return status */
2938: short level; /* current tree depth */
2939: short namelen;/* strlen(name) */
2940: char name[sizeof(int)]; /* file base name */
2941: };
2942:
2943: /*
2944: * individual struct FTW size
2945: */
2946:
2947: #define FTWSIZE(f) ((f)->namelen+1+sizeof(struct FTW)-sizeof(int))
2948:
2949: /*
2950: * FTW.info type bits
2951: */
2952:
2953: #define FTW_NS (1<<0) /* stat failed - unknown */
2954: #define FTW_F (1<<1) /* file - not directory or symbolic link*/
2955: #define FTW_SL (1<<2) /* symbolic link */
2956: #define FTW_D (1<<3) /* directory - pre-order visit */
2957:
2958: #define FTW_C (1<<4) /* causes cycle */
2959: #define FTW_NR (1<<5) /* cannot read */
2960: #define FTW_NX (1<<6) /* cannot search */
2961: #define FTW_P (1<<7) /* post-order visit */
2962:
2963: #define FTW_DC (FTW_D|FTW_C) /* directory - would cause cycle */
2964: #define FTW_DNR (FTW_D|FTW_NR) /* directory - no read permission */
2965: #define FTW_DNX (FTW_D|FTW_NX) /* directory - no search permission */
2966: #define FTW_DP (FTW_D|FTW_P) /* directory - post-order visit */
2967:
2968: /*
2969: * FTW.status entry values
2970: */
2971:
2972: #define FTW_NAME (1<<0) /* use FTW.name rather than FTW.path */
2973: #define FTW_PATH (1<<1) /* use FTW.path rather than FTW.name */
2974:
2975: /*
2976: * FTW.status return values
2977: */
2978:
2979: #define FTW_AGAIN (1<<2) /* process entry again */
2980: #define FTW_FOLLOW (1<<3) /* follow FTW_SL symlink */
2981: #define FTW_NOPOST (1<<4) /* skip post order visit */
2982: #define FTW_SKIP (1<<5) /* skip FTW_D directory */
2983: #define FTW_STAT (1<<6) /* userf did stat */
2984:
2985: #if __STDC__ || __cplusplus || c_plusplus
2986: #if __cplusplus
2987: extern "C" {
2988: #endif
2989: extern int ftwalk(const char* path, int (*userf)(struct FTW*), int flags, int (*comparf)(struct FTW*, struct FTW*));
2990: #if __cplusplus
2991: }
2992: #endif
2993: #else
2994: extern int ftwalk();
2995: #endif
2996:
2997: #endif
2998: 0707070000000000721006440044230044230000010000000475434355100003200000014206include/hash.h Ugsf Ggsf /*
2999: * G. S. Fowler
3000: * AT&T Bell Laboratories
3001: *
3002: * hash table library interface definitions
3003: */
3004:
3005: #ifndef HASH_ALLOCATE
3006:
3007: #define hash_info _hash_info_
3008: #define vhashalloc hashvalloc
3009:
3010: #ifndef VOID
3011: #define VOID char
3012: #endif
3013:
3014: #define HASH_ALLOCATE (1<<0) /* allocate new key names */
3015: #define HASH_FIXED (1<<1) /* fixed bucket/table size */
3016: #define HASH_HASHED (1<<6) /* key names already hashed */
3017: #define HASH_RESIZE (1<<2) /* table has been resized */
3018: #define HASH_SCANNING (1<<3) /* currently scanning scope */
3019: #define HASH_SCOPE (1<<4) /* push scope / create in bot */
3020: #define HASH_STATIC (1<<5) /* static table allocation */
3021:
3022: #define HASH_CREATE (1<<8) /* create bucket if not found */
3023: #define HASH_DELETE (1<<9) /* delete bucket if found */
3024: #define HASH_LOOKUP 0 /* default op */
3025:
3026: #define HASH_BUCKET (1<<11) /* name is installed bucket */
3027: #define HASH_INSTALL (1<<12) /* install allocated bucket */
3028: #define HASH_NOSCOPE (1<<13) /* top scope only */
3029: #define HASH_OPAQUE (1<<14) /* opaque bucket */
3030: #define HASH_VALUE (1<<15) /* value bucket field used */
3031:
3032: #define HASH_GET (HASH_LOOKUP|HASH_VALUE)
3033: #define HASH_NEW (HASH_CREATE|HASH_FIXED)
3034: #define HASH_PUT (HASH_CREATE|HASH_VALUE)
3035:
3036: #define HASH_DELETED (1<<(8*sizeof(int)-1)) /* deleted placeholder */
3037: #define HASH_KEEP (1<<(8*sizeof(int)-2)) /* no free on bucket */
3038: #define HASH_HIDDEN (1<<(8*sizeof(int)-3)) /* hidden by scope */
3039: #define HASH_HIDES (1<<(8*sizeof(int)-4)) /* hides lower scope */
3040: #define HASH_OPAQUED (1<<(8*sizeof(int)-5)) /* opaqued placeholder */
3041:
3042: #define HASH_RESET (HASH_RESIZE|HASH_SCOPE|HASH_STATIC)
3043: #define HASH_INTERNAL (HASH_BUCKET|HASH_RESIZE|HASH_SCANNING|HASH_STATIC)
3044: #define HASH_FLAGS (HASH_DELETED|HASH_HIDDEN|HASH_HIDES|HASH_KEEP|HASH_OPAQUED)
3045:
3046: #define HASH_alloc 1
3047: #define HASH_clear 2
3048: #define HASH_compare 3
3049: #define HASH_free 4
3050: #define HASH_hash 5
3051: #define HASH_meanchain 6
3052: #define HASH_name 7
3053: #define HASH_namesize 8
3054: #define HASH_set 9
3055: #define HASH_size 10
3056: #define HASH_table 11
3057:
3058: #include <hashpart.h>
3059:
3060: #define hashclear(t,f) ((t)->flags &= ~((f) & ~HASH_INTERNAL))
3061: #define hashdel(t,n) hashlook(t, (char*)(n), HASH_DELETE, (char*)0)
3062: #define hashget(t,n) hashlook(t, (char*)(n), HASH_LOOKUP|HASH_VALUE, (char*)0)
3063: #define hashlast(t) (hash_info.last)
3064: #define hashname(b) ((((b)->hash&HASH_HIDES)?((HASHBUCKET*)((b)->name)):(b))->name)
3065: #define hashput(t,n,v) (char*)hashlook(t, (char*)(n), HASH_CREATE|HASH_VALUE, (char*)(v))
3066: #define hashscope(t) ((t)->scope)
3067: #define hashset(t,f) ((t)->flags |= ((f) & ~HASH_INTERNAL))
3068:
3069: #define Hashbin_t HASHBUCKET
3070: #define Hashhdr_t HASHHEADER
3071: #define Hashpos_t HASHPOSITION
3072: #define Hashtab_t HASHTABLE
3073:
3074: typedef struct hashbucket HASHBUCKET;
3075: typedef struct hashheader HASHHEADER;
3076: typedef struct hashposition HASHPOSITION;
3077: typedef struct hashroot HASHROOT;
3078: typedef struct hashtable HASHTABLE;
3079: typedef unsigned int (*HASHFUN)();
3080: typedef int (*HASHINT)();
3081: typedef char* (*HASHPTR)();
3082:
3083: /*
3084: * the #define's avoid union tags
3085: */
3086:
3087: #define HASH_HEADER /* common bucket header */ \
3088: HASHBUCKET* next; /* next in collision chain */ \
3089: unsigned int hash; /* hash flags and value */ \
3090: char* name /* key name */
3091:
3092: #define HASH_DEFAULT /* HASH_VALUE bucket elements */ \
3093: char* value /* key value */
3094:
3095: struct hashheader /* bucket header */
3096: {
3097: HASH_HEADER;
3098: };
3099:
3100: struct hashbucket /* prototype bucket */
3101: {
3102: HASH_HEADER;
3103: HASH_DEFAULT;
3104: };
3105:
3106: struct hashposition /* hash scan bucket position */
3107: {
3108: HASHTABLE* tab; /* table pointer */
3109: HASHTABLE* top; /* top scope table pointer */
3110: int flags; /* scan flags */
3111: HASHBUCKET* bucket; /* bucket */
3112: HASHBUCKET** slot; /* table slot */
3113: HASHBUCKET** limit; /* slot limit */
3114: };
3115:
3116: struct hashroot /* root hash table information */
3117: {
3118: int flags; /* flags: see HASH_[A-Z]* */
3119: int namesize; /* fixed name size: 0 => string */
3120: int meanchain; /* resize mean chain length */
3121: HASHFUN hash; /* name hash routine */
3122: HASHINT compare; /* name comparision routine */
3123: HASHPTR alloc; /* value allocation routine */
3124: HASHINT free; /* value free routine */
3125: int accesses; /* number of accesses */
3126: int collisions; /* number of collisions */
3127: HASHROOT* next; /* next in list of all roots */
3128: HASHTABLE* references; /* referencing table list */
3129: };
3130:
3131: struct hashtable /* hash table information */
3132: {
3133: HASHROOT* root; /* root hash table information */
3134: HASHTABLE* scope; /* scope covered table */
3135: short flags; /* flags: see HASH_[A-Z]* */
3136: short frozen; /* table freeze nesting */
3137: HASHBUCKET** table; /* hash slot table */
3138: int size; /* table size */
3139: int buckets; /* active bucket count */
3140: char* name; /* table name */
3141: HASHTABLE* next; /* root reference list link */
3142: };
3143:
3144: struct hashinfo /* library hash info */
3145: {
3146: HASHBUCKET* last; /* most recent lookup bucket */
3147: HASHTABLE* table; /* most recent lookup table */
3148: HASHROOT* list; /* root table list */
3149: };
3150:
3151: #if __cplusplus
3152: extern "C" {
3153: #endif
3154:
3155: extern struct hashinfo hash_info;
3156:
3157: #if __cplusplus
3158: }
3159: #endif
3160:
3161: #if __STDC__ || __cplusplus || c_plusplus
3162:
3163: #include <stdarg.h>
3164: #include <stdio.h>
3165:
3166: #if __cplusplus
3167: extern "C" {
3168: #endif
3169: extern HASHTABLE* hashalloc(HASHTABLE*, ...);
3170: extern HASHTABLE* hashvalloc(HASHTABLE*, va_list);
3171: extern void hashdone(HASHPOSITION*);
3172: extern void hashdump(FILE*, HASHTABLE*, int);
3173: extern HASHTABLE* hashfree(HASHTABLE*);
3174: extern char* hashlook(HASHTABLE*, const char*, int, const char*);
3175: extern HASHBUCKET* hashnext(HASHPOSITION*);
3176: extern void hashscan(HASHTABLE*, int, HASHPOSITION*);
3177: extern void hashsize(HASHTABLE*, int);
3178: extern int hashwalk(HASHTABLE*, int, HASHINT);
3179:
3180: extern unsigned int memhash(const char*, int);
3181: extern unsigned long memsum(const char*, int, unsigned long);
3182: extern unsigned int strhash(const char*);
3183: extern unsigned long strsum(const char*, unsigned long);
3184: #if __cplusplus
3185: }
3186: #endif
3187: #else
3188: extern HASHTABLE* hashalloc();
3189: extern HASHTABLE* hashvalloc();
3190: extern void hashdone();
3191: extern void hashdump();
3192: extern HASHTABLE* hashfree();
3193: extern char* hashlook();
3194: extern HASHBUCKET* hashnext();
3195: extern void hashscan();
3196: extern void hashsize();
3197: extern int hashwalk();
3198:
3199: extern unsigned int memhash();
3200: extern unsigned long memsum();
3201: extern unsigned int strhash();
3202: extern unsigned long strsum();
3203: #endif
3204:
3205: #endif
3206: 0707070000000000731006440044230044230000010000000472075301300003600000001053include/hashpart.h Ugsf Ggsf /*
3207: * K. P. Vo
3208: * G. S. Fowler
3209: * AT&T Bell Laboratories
3210: *
3211: * ``the best'' combined linear congruent checksum/hash/PRNG
3212: */
3213:
3214: #ifndef HASHPART
3215:
3216: #define HASH_ADD(h) (0x9c39c33dL)
3217:
3218: #if __sparc__ || sparc
3219:
3220: #define HASH_A(h,n) ((((h) << 2) - (h)) << (n))
3221: #define HASH_B(h,n) ((((h) << 4) - (h)) << (n))
3222: #define HASH_C(h,n) ((HASH_A(h,7) + HASH_B(h,0)) << (n))
3223: #define HASH_MPY(h) (HASH_C(h,22)+HASH_C(h,10)+HASH_A(h,6)+HASH_A(h,3)+(h))
3224:
3225: #else
3226:
3227: #define HASH_MPY(h) ((h)*0x63c63cd9L)
3228:
3229: #endif
3230:
3231: #define HASHPART(h,c) (h = HASH_MPY(h) + HASH_ADD(h) + (c))
3232:
3233: #endif
3234: 0707070000000000741006440044230044230000010000000475434364100003000000004055include/ls.h Ugsf Ggsf /*
3235: * G. S. Fowler
3236: * AT&T Bell Laboratories
3237: *
3238: * ls formatter interface definitions
3239: */
3240:
3241: #ifndef LS_USER
3242:
3243: #include <fsinfo.h>
3244:
3245: #ifndef S_IRWXU
3246: #ifndef S_IREAD
3247: #define S_IREAD 00400
3248: #define S_IWRITE 00200
3249: #define S_IEXEC 00100
3250: #endif
3251: #ifndef S_ISUID
3252: #define S_ISUID 04000
3253: #endif
3254: #ifndef S_ISGID
3255: #define S_ISGID 02000
3256: #endif
3257: #ifndef S_ISVTX
3258: #define S_ISVTX 01000
3259: #endif
3260: #ifndef S_IRUSR
3261: #define S_IRUSR S_IREAD
3262: #define S_IWUSR S_IWRITE
3263: #define S_IXUSR S_IEXEC
3264: #define S_IRGRP (S_IREAD>>3)
3265: #define S_IWGRP (S_IWRITE>>3)
3266: #define S_IXGRP (S_IEXEC>>3)
3267: #define S_IROTH (S_IREAD>>6)
3268: #define S_IWOTH (S_IWRITE>>6)
3269: #define S_IXOTH (S_IEXEC>>6)
3270: #endif
3271:
3272: #define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
3273: #define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
3274: #define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
3275: #endif
3276:
3277: #ifdef stat_blocks
3278: #define tblocks(p) (((p)->st_blocks+1)/2)
3279: #else
3280: #define tblocks(p) iblocks(p)
3281: #if __STDC__ || __cplusplus || c_plusplus
3282: #if __cplusplus
3283: extern "C" {
3284: #endif
3285: extern long iblocks(struct stat*);
3286: #if __cplusplus
3287: }
3288: #endif
3289: #else
3290: extern long iblocks();
3291: #endif
3292: #endif
3293:
3294: #define LS_ATIME (1<<0) /* list st_atime */
3295: #define LS_BLOCKS (1<<1) /* list blocks used by file */
3296: #define LS_CTIME (1<<2) /* list st_ctime */
3297: #define LS_INUMBER (1<<3) /* list st_ino */
3298: #define LS_LONG (1<<4) /* long listing */
3299: #define LS_MARK (1<<5) /* append file name marks */
3300: #define LS_NOGROUP (1<<6) /* omit group name for LS_LONG */
3301: #define LS_NOUSER (1<<7) /* omit user name for LS_LONG */
3302:
3303: #define LS_USER (1<<8) /* first user flag bit */
3304:
3305: #define LS_W_BLOCKS 5 /* LS_BLOCKS field width */
3306: #define LS_W_INUMBER 7 /* LS_INUMBER field width */
3307: #define LS_W_LONG 55 /* LS_LONG width (w/o names) */
3308: #define LS_W_LINK 4 /* link text width (w/o names) */
3309: #define LS_W_MARK 1 /* LS_MARK field width */
3310: #define LS_W_NAME 9 /* group|user name field width */
3311:
3312: #if __STDC__ || __cplusplus || c_plusplus
3313: #if __cplusplus
3314: extern "C" {
3315: #endif
3316: extern char* fmtls(char*, const char*, struct stat*, const char*, const char*, int);
3317: #if __cplusplus
3318: }
3319: #endif
3320: #else
3321: extern char* fmtls();
3322: #endif
3323:
3324: #endif
3325: 0707070000000000751006440044230044230000010000000434062502300003400000000263include/namval.h Ugsf Ggsf /*
3326: * G. S. Fowler
3327: * AT&T Bell Laboratories
3328: *
3329: * name-value struct support
3330: */
3331:
3332: #ifndef __NAMVAL_H__
3333: #define __NAMVAL_H__
3334:
3335: struct namval
3336: {
3337: char* name;
3338: int value;
3339: };
3340:
3341: #endif
3342: 0707070000000000761006440044230044230000010000000475434371500003400000001715include/option.h Ugsf Ggsf /*
3343: * G. S. Fowler
3344: * AT&T Bell Laboratories
3345: *
3346: * command line option parse assist definitions
3347: */
3348:
3349: #ifndef __OPTION_H__
3350: #define __OPTION_H__
3351:
3352: #if __cplusplus
3353: extern "C" {
3354: #endif
3355:
3356: extern char* opt_arg; /* {:,#} string argument */
3357: extern int opt_again; /* see cmdargs() */
3358: extern char** opt_argv; /* most recent argv */
3359: extern int opt_char; /* char pos in argv[opt_index] */
3360: extern int opt_index; /* argv index */
3361: extern char* opt_msg; /* error/usage message buffer */
3362: extern long opt_num; /* # numeric argument */
3363: extern char opt_option[3]; /* current flag {-,+} + option */
3364: extern int opt_pchar; /* prev opt_char for backup */
3365: extern int opt_pindex; /* prev opt_index for backup */
3366:
3367: #if __cplusplus
3368: }
3369: #endif
3370:
3371: #if __STDC__ || __cplusplus || c_plusplus
3372: #if __cplusplus
3373: extern "C" {
3374: #endif
3375: extern int optget(char**, const char*);
3376: extern char* optusage(const char*);
3377: #if __cplusplus
3378: }
3379: #endif
3380: #else
3381: extern int optget();
3382: extern char* optusage();
3383: #endif
3384:
3385: #endif
3386: 0707070000000000771006440044230044230000010000000475434416200003000000002601include/re.h Ugsf Ggsf /*
3387: * G. S. Fowler
3388: * AT&T Bell Laboratories
3389: *
3390: * regular expression library definitions
3391: */
3392:
3393: #ifndef RE_ALL
3394:
3395: #define RE_ALL (1<<0) /* substitute all occurrences */
3396: #define RE_EDSTYLE (1<<1) /* ed(1) style magic characters */
3397: #define RE_LOWER (1<<2) /* substitute to lower case */
3398: #define RE_MATCH (1<<3) /* record matches in reprogram.match */
3399: #define RE_UPPER (1<<4) /* substitute to upper case */
3400: #define RE_EXTERNAL 8 /* first external flag bit */
3401:
3402: #define RE_NMATCH ('9'-'0'+1)
3403:
3404: typedef struct /* sub-expression match */
3405: {
3406: char* sp; /* start in source string */
3407: char* ep; /* end in source string */
3408: } rematch;
3409:
3410: /*
3411: * NOTE: reprogram is a pun for the interface routines
3412: * allowing the library to change without forcing
3413: * users to recompile
3414: */
3415:
3416: typedef struct /* compiled regular expression program */
3417: {
3418: rematch match[RE_NMATCH+1];/* sub-expression match table */
3419: } reprogram;
3420:
3421: /*
3422: * interface routines
3423: */
3424:
3425: #if __STDC__ || __cplusplus || c_plusplus
3426: #if __cplusplus
3427: extern "C" {
3428: #endif
3429: extern reprogram* recomp(const char*, int);
3430: extern int reexec(reprogram*, const char*);
3431: extern void refree(reprogram*);
3432: extern void reerror(const char*);
3433: extern char* resub(reprogram*, const char*, const char*, char*, int);
3434: #if __cplusplus
3435: }
3436: #endif
3437: #else
3438: extern reprogram* recomp();
3439: extern int reexec();
3440: extern void refree();
3441: extern void reerror();
3442: extern char* resub();
3443: #endif
3444:
3445: #endif
3446: 0707070000000001001006440044230044230000010000000475415720300003200000016426include/sfio.h Ugsf Ggsf #ifndef _SFIO_H /* protect against multiple #includes */
3447: #define _SFIO_H
3448:
3449: #if __STDC__ || __cplusplus || c_plusplus
3450: #define _SFA_(x) x
3451: #else
3452: #define _SFA_(x) ()
3453: #endif
3454:
3455: #ifndef NULL
3456: #define NULL 0
3457: #endif
3458: #ifndef EOF
3459: #define EOF (-1)
3460: #endif
3461: #ifndef SEEK_SET
3462: #define SEEK_SET 0
3463: #define SEEK_CUR 1
3464: #define SEEK_END 2
3465: #endif
3466:
3467: typedef struct _sfdc_ Sfdisc_t;
3468: typedef struct _sfio_ Sfile_t, SFIO;
3469:
3470: /* discipline structure */
3471: struct _sfdc_
3472: {
3473: int (*readf) _SFA_((Sfile_t*, unsigned char*, int, char*));
3474: int (*writef) _SFA_((Sfile_t*, const unsigned char*, int, char*));
3475: long (*seekf) _SFA_((Sfile_t*, long, int, char*));
3476: int (*exceptf) _SFA_((Sfile_t*, int, char*));
3477: char *handle; /* to store any state information */
3478: };
3479:
3480: /* a file structure */
3481: struct _sfio_
3482: {
3483: unsigned char *next; /* next position to read/write from */
3484: unsigned char *endw; /* end of write buffer */
3485: unsigned char *endr; /* end of read buffer */
3486: unsigned char *endb; /* end of buffer */
3487: struct _sfio_ *push; /* the stream that was pushed on */
3488: short flags; /* type of stream */
3489: short file; /* file descriptor */
3490: long orig; /* where we start in the file */
3491: #ifdef _SFIO_PRIVATE
3492: _SFIO_PRIVATE
3493: #endif
3494: };
3495:
3496: /* bits for various types of files */
3497: #define SF_READ 000001 /* open for reading */
3498: #define SF_WRITE 000002 /* open for writing */
3499: #define SF_STRING 000004 /* a string stream */
3500: #define SF_APPEND 000010 /* associated file is in append mode */
3501: #define SF_RELATIVE 000020 /* file pos is relative to starting pos */
3502: #define SF_MALLOC 000040 /* buffered space malloc-ed */
3503: #define SF_LINE 000100 /* line buffering */
3504: #define SF_KEEPFD 000200 /* keep file opened when closing stream */
3505: #define SF_SHARE 000400 /* file stream that is shared */
3506: #define SF_REUSE 001000 /* keep stream space after closing */
3507: #define SF_FLAGS 000777 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
3508: #define SF_SETS 001743 /* flags passable to sfset() */
3509:
3510: #define SF_EOF 002000 /* eof was detected */
3511: #define SF_ERROR 004000 /* an error happened */
3512:
3513: #define SF_BUFSIZE 8192 /* suggested default buffer size */
3514: #define SF_UNBOUND (-1) /* unbounded buffer size */
3515:
3516: #define sfstdin (&_Sfstdin) /* standard input stream */
3517: #define sfstdout (&_Sfstdout) /* standard output stream */
3518: #define sfstderr (&_Sfstderr) /* standard error stream */
3519:
3520: #if __cplusplus
3521: extern "C"
3522: {
3523: #endif
3524:
3525: extern int _Sfi;
3526: extern Sfile_t _Sfstdin, _Sfstdout, _Sfstderr;
3527:
3528: extern Sfile_t *sfnew _SFA_((Sfile_t*, unsigned char*, int, int, int));
3529: extern Sfile_t *sfopen _SFA_((Sfile_t*, const char*, const char*));
3530: extern Sfile_t *sfdopen _SFA_((int, const char*));
3531: extern Sfile_t *sfpopen _SFA_((const char*, const char*, Sfile_t**));
3532: extern Sfile_t *sfstack _SFA_((Sfile_t*, Sfile_t*));
3533: extern Sfile_t *_sftmpfile _SFA_((int));
3534: extern int _sfflsbuf _SFA_((Sfile_t*, int));
3535: extern int _sffilbuf _SFA_((Sfile_t*, int));
3536: extern int _sfsync _SFA_((Sfile_t*));
3537: extern int _sfpeek _SFA_((Sfile_t*, unsigned char**));
3538: extern int sfclrlock _SFA_((Sfile_t*));
3539: extern unsigned char* sfsetbuf _SFA_((Sfile_t*, unsigned char*, int));
3540: extern Sfdisc_t* sfsetdisc _SFA_((Sfile_t*,Sfdisc_t*));
3541: extern int sfnotice _SFA_((void(*)(Sfile_t*, int)));
3542: extern int sfset _SFA_((Sfile_t*, int, int));
3543: extern int sfpool _SFA_((Sfile_t*, Sfile_t*, int));
3544: extern int sfread _SFA_((Sfile_t*, unsigned char*, int));
3545: extern int sfwrite _SFA_((Sfile_t*, const unsigned char*, int));
3546: extern int sfmove _SFA_((Sfile_t*, Sfile_t*, long, const char*));
3547: extern int sfclose _SFA_((Sfile_t*));
3548: extern long sftell _SFA_((Sfile_t*));
3549: extern long sfseek _SFA_((Sfile_t*, long, int));
3550: extern int sfllen _SFA_((long));
3551: extern int sfdlen _SFA_((double));
3552: extern int sfputs _SFA_((Sfile_t*, const char*, int));
3553: extern char *sfgets _SFA_((Sfile_t*, char*, int));
3554: extern int sfnputc _SFA_((Sfile_t*, unsigned char, int));
3555: extern int _sfputu _SFA_((Sfile_t*, unsigned long));
3556: extern int _sfputl _SFA_((Sfile_t*, long));
3557: extern long _sfgetl _SFA_((Sfile_t*));
3558: extern unsigned long _sfgetu _SFA_((Sfile_t*));
3559: extern long _sfgetl _SFA_((Sfile_t*));
3560: extern int _sfputd _SFA_((Sfile_t*, double));
3561: extern double sfgetd _SFA_((Sfile_t*));
3562: extern int sfungetc _SFA_((Sfile_t*, int));
3563: extern char *_sfcvt _SFA_((double, int, int*, int*, int));
3564: extern int sfprintf _SFA_((Sfile_t*, const char*, ...));
3565: extern int sfsprintf _SFA_((char*, int, const char*, ...));
3566: extern int sfscanf _SFA_((Sfile_t*, const char*, ...));
3567: extern int sfsscanf _SFA_((const char*, const char*, ...));
3568:
3569: #if __STDC__ || __cplusplus
3570: #include <stdarg.h>
3571: #endif
3572: extern int sfvprintf _SFA_((Sfile_t*, const char*, va_list));
3573: extern int sfvscanf _SFA_((Sfile_t*, const char*, va_list));
3574:
3575: /* function analogues of fast in-line functions */
3576: extern int sfgetc _SFA_((Sfile_t*));
3577: extern long sfgetl _SFA_((Sfile_t*));
3578: extern unsigned long sfgetu _SFA_((Sfile_t*));
3579: extern int sfputc _SFA_((Sfile_t*,int));
3580: extern int sfputd _SFA_((Sfile_t*,double));
3581: extern int sfputl _SFA_((Sfile_t*,long));
3582: extern int sfputu _SFA_((Sfile_t*,unsigned long));
3583: extern int sfpeek _SFA_((Sfile_t*, unsigned char**));
3584: extern int sfsync _SFA_((Sfile_t*));
3585: extern Sfile_t* sfpushed _SFA_((Sfile_t*));
3586: extern Sfile_t* sftmp _SFA_((int));
3587: extern int sfslen _SFA_((void));
3588: extern int sfulen _SFA_((unsigned long));
3589: extern long sforigin _SFA_((Sfile_t*));
3590: extern int sfclearerr _SFA_((Sfile_t*));
3591: extern int sfeof _SFA_((Sfile_t*));
3592: extern int sferror _SFA_((Sfile_t*));
3593: extern int sffileno _SFA_((Sfile_t*));
3594: extern char* sfecvt _SFA_((double,int,int*,int*));
3595: extern char* sffcvt _SFA_((double,int,int*,int*));
3596:
3597: #if __cplusplus
3598: }
3599: #endif
3600:
3601: /* fast in-line functions */
3602: #define sfputc(f,c) ((f)->next >= (f)->endw ? \
3603: _sfflsbuf(f,(int)((unsigned char)(c))) : \
3604: (int)(*(f)->next++ = (unsigned char)(c)))
3605: #define sfgetc(f) ((f)->next >= (f)->endr ? _sffilbuf(f,1) : (int)(*(f)->next++))
3606: #define sfslen() (_Sfi)
3607: #define sffileno(f) ((f)->file)
3608: #define sforigin(f) (((f)->flags&SF_STRING) ? 0L : (f)->orig)
3609: #define sfeof(f) (((f)->flags&(SF_EOF|SF_STRING)) && (f)->next >= (f)->endb)
3610: #define sferror(f) ((f)->flags&SF_ERROR)
3611: #define sfclearerr(f) ((f)->flags &= ~(SF_ERROR|SF_EOF))
3612: #define sfpushed(f) ((f)->push)
3613: #define sftmp(n) ((n) >= 0 ? _sftmpfile(n) : \
3614: sfnew((Sfile_t*)0,(unsigned char*)0,-1,-1, \
3615: SF_READ|SF_WRITE|SF_STRING))
3616:
3617: #define sfpeek(f,bufp) (((bufp) || \
3618: ((f)->flags&(SF_READ|SF_WRITE|SF_STRING)) == \
3619: (SF_READ|SF_WRITE|SF_STRING)) ? _sfpeek(f,bufp) : \
3620: ((f)->endb - (f)->next))
3621: #define sfsync(f) (((f) && (((Sfile_t*)(f))->flags&SF_STRING)) ? 0 : _sfsync(f))
3622:
3623: /* coding long integers in a portable and compact fashion */
3624: #define SF_SBITS 6
3625: #define SF_UBITS 7
3626: #define SF_SIGN (1 << SF_SBITS)
3627: #define SF_MORE (1 << SF_UBITS)
3628: #define SF_U1 SF_MORE
3629: #define SF_U2 (SF_U1*SF_U1)
3630: #define SF_U3 (SF_U2*SF_U1)
3631: #define SF_U4 (SF_U3*SF_U1)
3632: #define sfulen(v) ((v) < SF_U1 ? 1 : (v) < SF_U2 ? 2 : \
3633: (v) < SF_U3 ? 3 : (v) < SF_U4 ? 4 : 5)
3634: #define sfgetu(f) ((_Sfi = sfgetc(f)) < 0 ? -1 : \
3635: ((_Sfi&SF_MORE) ? _sfgetu(f) : (unsigned long)_Sfi))
3636: #define sfgetl(f) ((_Sfi = sfgetc(f)) < 0 ? -1 : \
3637: ((_Sfi&(SF_MORE|SF_SIGN)) ? _sfgetl(f) : (long)_Sfi))
3638: #define sfputu(f,v) _sfputu((f),(unsigned long)(v))
3639: #define sfputl(f,v) _sfputl((f),(long)(v))
3640: #define sfputd(f,v) _sfputd((f),(double)(v))
3641:
3642: #define sfecvt(v,n,d,s) _sfcvt((v),(n),(d),(s),1)
3643: #define sffcvt(v,n,d,s) _sfcvt((v),(n),(d),(s),0)
3644:
3645: #endif /* _SFIO_H */
3646: 0707070000000001011006440044230044230000010000000475445764600003300000002655include/stack.h Ugsf Ggsf /*
3647: * G. S. Fowler
3648: * AT&T Bell Laboratories
3649: *
3650: * stack routine definitions
3651: */
3652:
3653: #ifndef __STACK_H
3654:
3655: #define __STACK_H
3656:
3657: #ifndef VOID
3658: #define VOID char
3659: #endif
3660:
3661: typedef struct stacktable* STACK; /* stack pointer */
3662: typedef struct stackposition STACKPOS; /* stack position */
3663:
3664: struct stackblock /* stack block cell */
3665: {
3666: char** stack; /* actual stack */
3667: struct stackblock* prev; /* previous block in list */
3668: struct stackblock* next; /* next block in list */
3669: };
3670:
3671: struct stackposition /* stack position */
3672: {
3673: struct stackblock* block; /* current block pointer */
3674: int index; /* index within current block */
3675: };
3676:
3677: struct stacktable /* stack information */
3678: {
3679: struct stackblock* blocks; /* stack table blocks */
3680: char* error; /* error return value */
3681: int size; /* size of each block */
3682: STACKPOS position; /* current stack position */
3683: };
3684:
3685: #if __STDC__ || __cplusplus || c_plusplus
3686:
3687: #if __cplusplus
3688: extern "C" {
3689: #endif
3690:
3691: extern STACK mkstack(int size, char* error);
3692: extern void rmstack(STACK stack);
3693: extern void clrstack(STACK stack);
3694: extern char* getstack(STACK stack);
3695: extern int pushstack(STACK stack, char* value);
3696: extern int popstack(STACK stack);
3697: extern void posstack(STACK stack, int set, STACKPOS* position);
3698:
3699: #if __cplusplus
3700: }
3701: #endif
3702:
3703: #else
3704:
3705: extern STACK mkstack();
3706: extern void rmstack();
3707: extern void clrstack();
3708: extern char* getstack();
3709: extern int pushstack();
3710: extern int popstack();
3711: extern void posstack();
3712:
3713: #endif
3714:
3715: #endif
3716: 0707070000000001021006440044230044230000010000000474506072000003200000002666include/stak.h Ugsf Ggsf #ifndef STAK_SMALL
3717: /*
3718: * David Korn
3719: * AT&T Bell Laboratories
3720: *
3721: * Interface definitions for a stack-like storage library
3722: *
3723: */
3724:
3725: #if defined(__STDC__) || __cplusplus || c_plusplus
3726: # define __ARGS(args) args
3727: #else
3728: # define const /*empty*/
3729: # define __ARGS(args) ()
3730: #endif
3731:
3732: typedef struct _stak_
3733: {
3734: int stakleft; /* number of bytes left in frame */
3735: char *staktop; /* current stack location */
3736: char *stakbot; /* last returned stack location */
3737: short stakref; /* reference count */
3738: #ifdef _STAK_PRIVATE
3739: _STAK_PRIVATE
3740: #endif /* _STAK_PRIVATE */
3741: } Stak_t;
3742:
3743: #define STAK_SMALL 1 /* argument to stakcreate */
3744:
3745: #if __cplusplus
3746: extern "C"
3747: {
3748: #endif
3749: extern Stak_t *stakcreate __ARGS((int));
3750: extern Stak_t *stakinstall __ARGS((Stak_t*, char *(*)(int)));
3751: extern int stakdelete __ARGS((Stak_t*));
3752: extern char *stakalloc __ARGS((unsigned));
3753: extern char *stakcopy __ARGS((const char*));
3754: extern char *stakset __ARGS((char*, unsigned));
3755: extern char *stakseek __ARGS((unsigned));
3756: extern int stakputs __ARGS((const char*));
3757: extern char *stakfreeze __ARGS((unsigned));
3758: extern char *_stakgrow __ARGS((unsigned));
3759: #if __cplusplus
3760: }
3761: #endif
3762:
3763: extern Stak_t _stak_cur; /* used by macros */
3764:
3765: #define staklink(sp) ((sp)->stakref++)
3766: #define stakptr(n) (_stak_cur.stakbot+(n))
3767: #define staktell() (_stak_cur.staktop-_stak_cur.stakbot)
3768: #define stakputc(c) ((--_stak_cur.stakleft<0? _stakgrow(1):0), \
3769: *_stak_cur.staktop++=(c))
3770:
3771: #endif /* STAK_SMALL */
3772: 0707070000000001031006440044230044230000010000000474441023500003300000005417include/stdio.h Ugsf Ggsf /*
3773: * AT&T Bell Laboratories
3774: *
3775: * sfio stdio source emulation
3776: */
3777:
3778: #ifndef _STDIO_H_
3779:
3780: #if __cplusplus || c_plusplus
3781:
3782: #include <../CC/stdio.h>
3783:
3784: #ifndef _STDIO_H_
3785: #define _STDIO_H_
3786: #endif
3787:
3788: #else
3789:
3790: #define _STDIO_H_
3791:
3792: #include <sfio.h>
3793:
3794: #define _IOFBF 0
3795: #define _IONBF 1
3796: #define _IOLBF 2
3797: #define L_ctermid 9
3798: #define L_cuserid 9
3799: #define P_tmpdir "/usr/tmp/"
3800: #define L_tmpnam (sizeof(P_tmpdir)+15)
3801:
3802: #if __cplusplus || c_plusplus
3803: extern "C"
3804: {
3805: #endif
3806:
3807: extern char *ctermid _SFA_((char*));
3808: extern char *cuserid _SFA_((char*));
3809: extern char *tmpnam _SFA_((char*));
3810: extern char *tempnam _SFA_((char*));
3811: extern char *_stdgets _SFA_((char*, int n));
3812: extern int _stdprintf _SFA_((const char*, ...));
3813: extern int _stdsprintf _SFA_((char*, const char*, ...));
3814: extern int _stdscanf _SFA_((const char*, ...));
3815: extern int _stdsetvbuf _SFA_((Sfile_t*, char*, int, int));
3816:
3817: #if __cplusplus || c_plusplus
3818: }
3819: #endif
3820:
3821: #define stdin sfstdin
3822: #define stdout sfstdout
3823: #define stderr sfstderr
3824: #define FILE Sfile_t
3825: #define BUFSIZ SF_BUFSIZE
3826:
3827: #define fopen(f,m) sfopen((Sfile_t*)0,f,m)
3828: #define fdopen(fd,m) sfdopen(fd,m)
3829: #define freopen(f,m,p) sfopen(p,f,m)
3830: #define tmpfile() sftmpfile()
3831: #define popen(cmd,m) sfpopen(cmd,m,(Sfile_t**)0)
3832: #define fclose(f) sfclose(f)
3833: #define pclose(f) sfclose(f)
3834:
3835: #define fwrite(p,s,n,f) ((_Sfi = sfwrite(f,p,(s)*(n))) <= 0 ? _Sfi : _Sfi/(s))
3836: #define fputc(c,f) sfputc(f,c)
3837: #define putc(c,f) sfputc(f,c)
3838: #define putw(w,f) (_Sfi = (int)w, sfwrite(f,&_Sfi,sizeof(int)) <= 0 ? 1 : 0)
3839: #define putchar(c) sfputc(sfstdout,c)
3840: #define fputs(s,f) sfputs(f,s,0)
3841: #define puts(s) sfputs(sfstdout,s,'\n')
3842: #define fprintf sfprintf
3843: #define vfprintf sfvprintf
3844: #define vprintf(f,a) sfvprintf(sfstdout,f,a)
3845: #define vsprintf _stdvsprintf
3846: #define printf _stdprintf
3847: #define sprintf _stdsprintf
3848:
3849: #define fread(p,s,n,f) ((_Sfi = sfread(f,p,(s)*(n))) <= 0 ? _Sfi : _Sfi/(s))
3850: #define fgetc(f) sfgetc(f)
3851: #define getc(f) sfgetc(f)
3852: #define getw(f) (sfread(f,&_Sfi,sizeof(int)) == sizeof(int) ? _Sfi : -1)
3853: #define getchar() sfgetc(sfstdin)
3854: #define ungetc(c,f) sfungetc(f,c)
3855: #define fgets(s,n,f) sfgets(f,s,n)
3856: #define _SIZEOF(s) (sizeof(s) != sizeof(char*) ? sizeof(s) : BUFSIZ)
3857: #define gets(s) _stdgets(s,_SIZEOF(s))
3858: #define fscanf sfscanf
3859: #define vfscanf sfvscanf
3860: #define sscanf sfsscanf
3861: #define vscanf(f,a) sfvscanf(sfstdin,f,a)
3862: #define scanf _stdscanf
3863: #define vsscanf _stdvssanf
3864:
3865: #define fflush(f) sfsync(f)
3866: #define fseek(f,o,t) (sfseek(f,o,t) < 0L ? -1 : 0)
3867: #define rewind(f) sfseek((f),0L,0)
3868: #define ftell(f) sftell(f)
3869: #define setbuf(f,b) sfsetbuf(f,b,(b) ? BUFSIZ : 0)
3870: #define setbuffer(f,b,n) sfsetbuf(f,b,n)
3871: #define setlinebuf(f) sfsetflag(f,SF_LINE,1)
3872: #define setvbuf _stdsetvbuf
3873:
3874: #define fileno(f) sffileno(f)
3875: #define feof(f) sfeof(f)
3876: #define ferror(f) sferror(f)
3877: #define clearerr(f) (sfclearerr(f),sfclearlock(f))
3878:
3879: #endif
3880:
3881: #endif
3882: 0707070000000001041006440044230044230000010000000475434432200003200000001330include/swap.h Ugsf Ggsf /*
3883: * Glenn Fowler
3884: * AT&T Bell Laboratories
3885: *
3886: * internal representation conversion support definitions
3887: */
3888:
3889: #ifndef BYTE
3890:
3891: #define BYTE 01 /* swap bytes */
3892: #define HALF 02 /* swap halfwords */
3893:
3894: #define getbyte(op,p) (*((unsigned char*)(p)))
3895: #define putbyte(op,p,n) (*(p)=(n))
3896:
3897: #if __STDC__ || __cplusplus || c_plusplus
3898: #if __cplusplus
3899: extern "C" {
3900: #endif
3901: extern char* memswap(int, char*, int);
3902: extern int gethalf(int, const char*);
3903: extern long getlong(int, const char*);
3904: extern void puthalf(int, char*, int);
3905: extern void putlong(int, char*, long);
3906: #if __cplusplus
3907: }
3908: #endif
3909: #else
3910: extern char* memswap();
3911: extern int gethalf();
3912: extern long getlong();
3913: extern void puthalf();
3914: extern void putlong();
3915: #endif
3916:
3917: #endif
3918: 0707070000000001051006440044230044230000010000000432520526300003100000004005include/tar.h Ugsf Ggsf /*
3919: * Standard Archive Format
3920: * USTAR - Uniform Standard Tape ARchive
3921: */
3922:
3923: #ifndef TBLOCK
3924:
3925: #define TBLOCK 512
3926: #define NAMSIZ 100
3927: #define PFXSIZ 155
3928:
3929: #define TMODLEN 8
3930: #define TUIDLEN 8
3931: #define TGIDLEN 8
3932: #define TSIZLEN 12
3933: #define TMTMLEN 12
3934: #define TCKSLEN 8
3935:
3936: #define TMAGIC "ustar" /* ustar and a null */
3937: #define TMAGLEN 6
3938: #define TVERSION "00" /* 00 and no null */
3939: #define TVERSLEN 2
3940: #define TUNMLEN 32
3941: #define TGNMLEN 32
3942: #define TDEVLEN 8
3943:
3944: /*
3945: * values used in typeflag field
3946: */
3947:
3948: #define REGTYPE '0' /* regular file */
3949: #define AREGTYPE 0 /* alternate REGTYPE */
3950: #define LNKTYPE '1' /* hard link */
3951: #define SYMTYPE '2' /* soft link */
3952: #define CHRTYPE '3' /* character special */
3953: #define BLKTYPE '4' /* block special */
3954: #define DIRTYPE '5' /* directory */
3955: #define FIFOTYPE '6' /* FIFO special */
3956: #define CONTYPE '7' /* reserved */
3957: #define SOKTYPE '8' /* socket -- reserved */
3958: #define VERTYPE 'V' /* version -- reserved */
3959:
3960: /*
3961: * bits used in mode field
3962: */
3963:
3964: #define TSUID 04000 /* set uid on exec */
3965: #define TSGID 02000 /* set gid on exec */
3966: #define TSVTX 01000 /* sticky bit -- reserved */
3967:
3968: /*
3969: * file permissions
3970: */
3971:
3972: #define TUREAD 00400 /* read by owner */
3973: #define TUWRITE 00200 /* write by owner */
3974: #define TUEXEC 00100 /* execute by owner */
3975: #define TGREAD 00040 /* read by group */
3976: #define TGWRITE 00020 /* execute by group */
3977: #define TGEXEC 00010 /* write by group */
3978: #define TOREAD 00004 /* read by other */
3979: #define TOWRITE 00002 /* write by other */
3980: #define TOEXEC 00001 /* execute by other */
3981:
3982: struct header
3983: {
3984: char name[NAMSIZ];
3985: char mode[TMODLEN];
3986: char uid[TUIDLEN];
3987: char gid[TGIDLEN];
3988: char size[TSIZLEN];
3989: char mtime[TMTMLEN];
3990: char chksum[TCKSLEN];
3991: char typeflag;
3992: char linkname[NAMSIZ];
3993: char magic[TMAGLEN];
3994: char version[TVERSLEN];
3995: char uname[TUNMLEN];
3996: char gname[TGNMLEN];
3997: char devmajor[TDEVLEN];
3998: char devminor[TDEVLEN];
3999: char prefix[PFXSIZ];
4000: };
4001:
4002: union hblock
4003: {
4004: char dummy[TBLOCK];
4005: struct header dbuf;
4006: };
4007:
4008: #endif
4009: 0707070000000001061006440044230044230000010000000475434632700003000000006372include/tm.h Ugsf Ggsf /*
4010: * Glenn Fowler
4011: * AT&T Bell Laboratories
4012: *
4013: * time conversion support definitions
4014: */
4015:
4016: #ifndef TM_DEFAULT
4017:
4018: #define tm_data _tm_data_
4019: #define tm_info _tm_info_
4020:
4021: #include <time.h>
4022: #ifndef LS_USER
4023: #include <sys/types.h>
4024: #endif
4025:
4026: #define tmset() do{if(!tm_info.local.standard)tminit();}while(0)
4027:
4028: #ifndef VOID
4029: #define VOID char
4030: #endif
4031:
4032: #define TM_ADJUST (1<<0) /* local doesn't do leap secs */
4033: #define TM_LEAP (1<<1) /* do leap seconds */
4034: #define TM_UTC (1<<2) /* universal coordinated ref */
4035:
4036: #define TM_DST (-60) /* default minutes for DST */
4037: #define TM_LOCALZONE (25 * 60) /* use local time zone offset */
4038: #define TM_MAXLEAP 1 /* max leap secs per leap */
4039:
4040: /*
4041: * these indices must agree with tm_dform[]
4042: */
4043:
4044: #define TM_MONTH_3 0
4045: #define TM_MONTH 12
4046: #define TM_DAY_3 24
4047: #define TM_DAY 31
4048: #define TM_TIME 38
4049: #define TM_DATE 39
4050: #define TM_DEFAULT 40
4051: #define TM_MERIDIAN 41
4052:
4053: #define TM_UT 43
4054: #define TM_DT 47
4055: #define TM_SUFFIXES 51
4056: #define TM_PARTS 55
4057: #define TM_HOURS 62
4058: #define TM_DAYS 66
4059: #define TM_LAST 69
4060: #define TM_THIS 72
4061: #define TM_NEXT 75
4062: #define TM_EXACT 78
4063: #define TM_NOISE 81
4064:
4065: #define TM_NFORM 85
4066:
4067: struct tl /* leap second info */
4068: {
4069: time_t time; /* the leap second event */
4070: int total; /* inclusive total since epoch */
4071: };
4072:
4073: struct tz /* time zone info */
4074: {
4075: char* type; /* type name */
4076: char* standard; /* standard time name */
4077: char* daylight; /* daylight or summertime name */
4078: short west; /* minutes west of GMT */
4079: short dst; /* add to tz.west for DST */
4080: };
4081:
4082: struct tmdata /* tm library readonly data */
4083: {
4084: char** format; /* default TM_* format strings */
4085: char* lex; /* format lex type classes */
4086: char* digit; /* output digits */
4087: short* days; /* days in month i */
4088: short* sum; /* days in months before i */
4089: struct tl* leap; /* leap second table */
4090: struct tz* zone; /* alternate timezone table */
4091: };
4092:
4093: struct tminfo /* tm library global info */
4094: {
4095: char* deformat; /* TM_DEFAULT override */
4096: int flags; /* flags */
4097: char** format; /* current format strings */
4098: struct tz local; /* local timezone */
4099: };
4100:
4101: #if __cplusplus
4102: extern "C" {
4103: #endif
4104:
4105: extern struct tmdata tm_data;
4106: extern struct tminfo tm_info;
4107:
4108: #if __cplusplus
4109: }
4110: #endif
4111:
4112: #if __STDC__ || __cplusplus || c_plusplus
4113: #if __cplusplus
4114: extern "C" {
4115: #endif
4116: extern time_t time(time_t*);
4117:
4118: extern time_t tmdate(const char*, char**, time_t*);
4119: extern struct tm* tmfix(struct tm*);
4120: extern char* tmform(char*, const char*, time_t*);
4121: extern int tmgoff(const char*, char**, int);
4122: extern void tminit(void);
4123: extern time_t tmleap(time_t*);
4124: extern int tmlex(const char*, char**, char**, int, char**, int);
4125: extern struct tm* tmmake(time_t*);
4126: extern char* tmpoff(char*, const char*, int, int);
4127: extern time_t tmtime(struct tm*, int);
4128: extern char* tmtype(const char*, char**);
4129: extern int tmword(const char*, char**, const char*, char**, int);
4130: extern int tmzone(const char*, char**, const char*, int*);
4131: #if __cplusplus
4132: }
4133: #endif
4134: #else
4135: extern time_t time();
4136:
4137: extern time_t tmdate();
4138: extern struct tm* tmfix();
4139: extern char* tmform();
4140: extern int tmgoff();
4141: extern void tminit();
4142: extern time_t tmleap();
4143: extern int tmlex();
4144: extern struct tm* tmmake();
4145: extern char* tmpoff();
4146: extern time_t tmtime();
4147: extern char* tmtype();
4148: extern int tmword();
4149: extern int tmzone();
4150: #endif
4151:
4152: #endif
4153: 0707070000000001071006440044230044230000010000000446361053400003000000017542man/ftwalk.3