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