|
|
1.1 ! root 1: /* (-lgl ! 2: * COHERENT 386 Device Driver Kit release 2.0 ! 3: * Copyright (c) 1982, 1992 by Mark Williams Company. ! 4: * All rights reserved. May not be copied without permission. ! 5: -lgl) */ ! 6: ! 7: /* ! 8: * /usr/include/misc.h ! 9: * Miscellaneous useful user functions. ! 10: * Sugggestions and additions are welcome. ! 11: * ! 12: * Revised Wed Mar 24 16:44:33 1993 CST ! 13: */ ! 14: #ifndef __MISC_H__ ! 15: #define __MISC_H__ ! 16: ! 17: #ifndef OFFSETOF ! 18: ! 19: /* Handy defines */ ! 20: #define OFFSETOF(type, mem) (&((char *)((type *)NULL)->m) - NULL) ! 21: #define ENDOF(x) (((char *)(x))+sizeof(x)) /* end of some thing */ ! 22: #define SETIN(a, b) !((a) & ~(b)) /* a in b */ ! 23: ! 24: #ifdef M68000 ! 25: #define ptrdiff(a, b) ((long)a - (long)b) ! 26: #else ! 27: #ifdef LARGE ! 28: #define ptrdiff(a, b) (((((long)a>>16)-((long)b>>16))<<4)+((int)a-(int)b)) ! 29: #else ! 30: #define ptrdiff(a, b) ((int)a - (int)b) ! 31: #endif ! 32: #endif ! 33: ! 34: #include <stdio.h> ! 35: ! 36: /* ! 37: * Needed for select() ! 38: */ ! 39: struct timeval { ! 40: long tv_sec; ! 41: long tv_usec; ! 42: }; ! 43: ! 44: #include <sys/param.h> ! 45: ! 46: #if NOFILE <= 32 ! 47: typedef int fd_set; ! 48: ! 49: #define FD_ZERO(fdp) {*fdp = 0;} ! 50: #define FD_SET(b,fdp) (*fdp |= 1 << (b)) ! 51: #define FD_ISSET(b,fdp) (*fdp & 1 << (b)) ! 52: #define FD_SETSIZE 32 ! 53: #else ! 54: typedef int fd_set[2]; ! 55: ! 56: #define FD_ZERO(fdp) {(*fdp)[0]=(*fdp)[1]=0;} ! 57: #define FD_SET(b,fdp) ((*fdp)[((b)>>5)&1] |= 1 << ((b)&0x1F)) ! 58: #define FD_ISSET(b,fdp) ((*fdp)[((b)>>5)&1] & 1 << ((b)&0x1F)) ! 59: #define FD_SETSIZE 64 ! 60: #endif ! 61: /* end of select() support */ ! 62: ! 63: extern void fatal(); /* like fprintf(stderr, ...); exit(1); */ ! 64: extern char * getline();/* char * getline(FILE *fp, int *lineNo); ! 65: * gets lines off a file treats # to end of line ! 66: * as comment, discards \ [ \t\n] through end of ! 67: * line to create continuations. */ ! 68: extern usage(); /* like fatal but message starts usage: */ ! 69: extern FILE *xopen(); /* xopen(filename, access); fopen or die */ ! 70: extern char *basename(); /* return the last filename on a path */ ! 71: extern char *pathn(); /* pathn("helpfile", "LIBPATH", ",,\lib", "r"); ! 72: * gets full pathname given an filename ! 73: * env var with path, default path and access rights */ ! 74: extern xdump(); /* xdump(ptr, size) hex dumps an area */ ! 75: extern long randl(); /* IEEE random number (random bits) */ ! 76: extern srandl(); /* srandl(unsigned long s1, s2); */ ! 77: extern unsigned short crc16(); /* crc16(char *p) calculate 16 bit crc */ ! 78: extern char *ask(); /* ask(reply, msg); ! 79: * like printf(msg, ...) returns a user reply */ ! 80: extern int yn(); /* like printf(msg, ...) returns yes=1 or no=0 reply */ ! 81: extern char *alloc(); /* get space or die */ ! 82: extern void banner(); /* banner("Done", 3) prints a banner saying ! 83: * Done with 3 spaces infront. */ ! 84: extern int copyd(); /* copyd(FILE *outfile, FILE *infile, long length) ! 85: * Copys infile to outfile for length efficiently. ! 86: * on failure copys all it can read and returns 0. ! 87: * returns 1 on success */ ! 88: extern strcmpl(); /* case insensative strcmp() */ ! 89: extern char *lcase(); /* convert string to lower case */ ! 90: extern char *ucase(); /* convert string to upper case */ ! 91: extern char *newcpy(); /* make a malloced copy of a string */ ! 92: extern char *match(); /* match(s1, pat, fin) ! 93: * finds pat in s1 by pnmatch rules ! 94: * returns start of pattern or NULL ! 95: * places pointer to end in *fin ! 96: */ ! 97: extern char *replace(); /* replace(s1, pat, s3, all, matcher) ! 98: * search s1 for pat and replace by s3. ! 99: * Using matcher which is a pointer to ! 100: * a function that looks externally like match. ! 101: * Returns a new malloced string or NULL ! 102: * does all if all != 0 else first. */ ! 103: extern char * span(); /* span(s1, matcher, fin) ! 104: * matches all chars passing function ! 105: * matcher. Looks like match. */ ! 106: extern char * skip(); /* skip(s1, matcher, fin) ! 107: * matches all chars not passing function ! 108: * matcher. Looks like match. */ ! 109: extern void tocont(); /* Enter NL to continue */ ! 110: extern approx(); /* approx(double a, double b) 1 if == within epsilon */ ! 111: extern double epsilon; ! 112: extern int is_fs(); /* is_fs(char *special) test if special is filesystem */ ! 113: extern void vinit(); /* vinit(char * workFileName, unsigned storAmt); ! 114: * Init the software virtual system telling it how much ! 115: * storage it may use for buffers */ ! 116: extern void vshutdown(); /* Shut down the virtual system and free its storage */ ! 117: extern unsigned vopen(); /* vopen(long amt); Set up a virtual object amt ! 118: * bytes long and return a vid number. */ ! 119: extern char *vfind(); /* vfind(int vid, long disp, int dirty); ! 120: * Point to a byte disp bytes into vid, set the ! 121: * dirty bit if dirty == 1 */ ! 122: extern char *trim(); /* trim(char *s); remove trailing whitespace from s */ ! 123: extern void splitter(); /* splitter(FILE *ofp, char *line, int limit) ! 124: * split line into limit size chunks by inserting ! 125: * \ \n and put the results to ofp. */ ! 126: extern strchrtr(); ! 127: /* strchrtr(char *from, char *to, int c, int d) ! 128: * Find c in from and return the corresponding char ! 129: * in to or def if there is none. ! 130: */ ! 131: /* ! 132: * Definitions etc. for regexp(3) routines. ! 133: * ! 134: * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], ! 135: * not the System V one. ! 136: * ! 137: * This is a modification of the University of Toronto regexp() package. ! 138: * Mostly to fit in cleanly with Coherent's libmisc. The original can ! 139: * be gotten free on mwcbbs. ! 140: */ ! 141: #define NSUBEXP 10 ! 142: typedef struct regexp { ! 143: char *startp[NSUBEXP]; ! 144: char *endp[NSUBEXP]; ! 145: char regstart; /* Internal use only. */ ! 146: char reganch; /* Internal use only. */ ! 147: char *regmust; /* Internal use only. */ ! 148: int regmlen; /* Internal use only. */ ! 149: char program[1]; /* Unwarranted chumminess with compiler. */ ! 150: } regexp; ! 151: ! 152: extern regexp *regcomp(); ! 153: extern int regexec(); ! 154: extern void regsub(); ! 155: extern void regerror(); ! 156: /* ! 157: * The first byte of the regexp internal "program" is actually this magic ! 158: * number; the start node begins in the second byte. ! 159: */ ! 160: #define REG_MAGIC (char)0234 ! 161: #endif ! 162: ! 163: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.