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