|
|
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/select.h>
45:
46: extern void fatal(); /* like fprintf(stderr, ...); exit(1); */
47: extern char * getline();/* char * getline(FILE *fp, int *lineNo);
48: * gets lines off a file treats # to end of line
49: * as comment, discards \ [ \t\n] through end of
50: * line to create continuations. */
51: extern usage(); /* like fatal but message starts usage: */
52: extern FILE *xopen(); /* xopen(filename, access); fopen or die */
53: extern char *basename(); /* return the last filename on a path */
54: extern char *pathn(); /* pathn("helpfile", "LIBPATH", ",,\lib", "r");
55: * gets full pathname given an filename
56: * env var with path, default path and access rights */
57: extern xdump(); /* xdump(ptr, size) hex dumps an area */
58: extern long randl(); /* IEEE random number (random bits) */
59: extern srandl(); /* srandl(unsigned long s1, s2); */
60: extern unsigned short crc16(); /* crc16(char *p) calculate 16 bit crc */
61: extern char *ask(); /* ask(reply, msg);
62: * like printf(msg, ...) returns a user reply */
63: extern int yn(); /* like printf(msg, ...) returns yes=1 or no=0 reply */
64: extern char *alloc(); /* get space or die */
65: extern void banner(); /* banner("Done", 3) prints a banner saying
66: * Done with 3 spaces infront. */
67: extern int copyd(); /* copyd(FILE *outfile, FILE *infile, long length)
68: * Copys infile to outfile for length efficiently.
69: * on failure copys all it can read and returns 0.
70: * returns 1 on success */
71: extern strcmpl(); /* case insensative strcmp() */
72: extern char *lcase(); /* convert string to lower case */
73: extern char *ucase(); /* convert string to upper case */
74: extern char *newcpy(); /* make a malloced copy of a string */
75: extern char *match(); /* match(s1, pat, fin)
76: * finds pat in s1 by pnmatch rules
77: * returns start of pattern or NULL
78: * places pointer to end in *fin
79: */
80: extern char *replace(); /* replace(s1, pat, s3, all, matcher)
81: * search s1 for pat and replace by s3.
82: * Using matcher which is a pointer to
83: * a function that looks externally like match.
84: * Returns a new malloced string or NULL
85: * does all if all != 0 else first. */
86: extern char * span(); /* span(s1, matcher, fin)
87: * matches all chars passing function
88: * matcher. Looks like match. */
89: extern char * skip(); /* skip(s1, matcher, fin)
90: * matches all chars not passing function
91: * matcher. Looks like match. */
92: extern void tocont(); /* Enter NL to continue */
93: extern approx(); /* approx(double a, double b) 1 if == within epsilon */
94: extern double epsilon;
95: extern int is_fs(); /* is_fs(char *special) test if special is filesystem */
96: extern void vinit(); /* vinit(char * workFileName, unsigned storAmt);
97: * Init the software virtual system telling it how much
98: * storage it may use for buffers */
99: extern void vshutdown(); /* Shut down the virtual system and free its storage */
100: extern unsigned vopen(); /* vopen(long amt); Set up a virtual object amt
101: * bytes long and return a vid number. */
102: extern char *vfind(); /* vfind(int vid, long disp, int dirty);
103: * Point to a byte disp bytes into vid, set the
104: * dirty bit if dirty == 1 */
105: extern char *trim(); /* trim(char *s); remove trailing whitespace from s */
106: extern void splitter(); /* splitter(FILE *ofp, char *line, int limit)
107: * split line into limit size chunks by inserting
108: * \ \n and put the results to ofp. */
109: extern strchrtr();
110: /* strchrtr(char *from, char *to, int c, int d)
111: * Find c in from and return the corresponding char
112: * in to or def if there is none.
113: */
114: /*
115: * Definitions etc. for regexp(3) routines.
116: *
117: * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
118: * not the System V one.
119: *
120: * This is a modification of the University of Toronto regexp() package.
121: * Mostly to fit in cleanly with Coherent's libmisc. The original can
122: * be gotten free on mwcbbs.
123: */
124: #define NSUBEXP 10
125: typedef struct regexp {
126: char *startp[NSUBEXP];
127: char *endp[NSUBEXP];
128: char regstart; /* Internal use only. */
129: char reganch; /* Internal use only. */
130: char *regmust; /* Internal use only. */
131: int regmlen; /* Internal use only. */
132: char program[1]; /* Unwarranted chumminess with compiler. */
133: } regexp;
134:
135: extern regexp *regcomp();
136: extern int regexec();
137: extern void regsub();
138: extern void regerror();
139: /*
140: * The first byte of the regexp internal "program" is actually this magic
141: * number; the start node begins in the second byte.
142: */
143: #define REG_MAGIC (char)0234
144: #endif
145:
146: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.