Annotation of coherent/d/usr/lib/misc/misc.h, revision 1.1.1.1

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: #ifdef M68000
                     14: #define ptrdiff(a, b) ((long)a - (long)b)
                     15: #else
                     16: #ifdef LARGE
                     17: #define ptrdiff(a, b) (((((long)a>>16)-((long)b>>16))<<4)+((int)a-(int)b))
                     18: #else
                     19: #define ptrdiff(a, b) ((int)a - (int)b)
                     20: #endif
                     21: #endif
                     22: 
                     23: #include <stdio.h>
                     24: extern fatal();                /* like fprintf(stderr, ...); exit(0); */
                     25: extern char * getline();/* char * getline(FILE *fp, int *lineNo);
                     26:                         * gets lines off a file treats # to end of line
                     27:                         * as comment, discards \ [ \t\n] through end of
                     28:                         * line to create continuations. */
                     29: extern usage();                /* like fatal but message starts usage: */
                     30: extern FILE *xopen();  /* xopen(filename, access); fopen or die */
                     31: extern char *pathn();  /* pathn("helpfile", "LIBPATH", ",,\lib", "r");
                     32:                         * gets full pathname given an filename
                     33:                         * env var with path, default path and access rights */
                     34: extern xdump();                /* xdump(ptr, size) hex dumps an area */
                     35: extern long randl();   /* IEEE random number (random bits) */
                     36: extern srandl();       /* srandl(unsigned long s1, s2); */
                     37: extern unsigned short crc16(); /* crc16(char *p) calculate 16 bit crc */
                     38: extern char *ask();    /* ask(reply, msg);
                     39:                         * like printf(msg, ...) returns a user reply */
                     40: extern int yn();       /* like printf(msg, ...) returns yes=1 or no=0 reply */
                     41: extern char *alloc();  /* get space or die */
                     42: extern void banner();  /* banner("Done", 3) prints a banner saying
                     43:                         * Done with 3 spaces infront. */
                     44: extern strcmpl();      /* case insensative strcmp() */
                     45: extern char *lcase();  /* convert string to lower case */
                     46: extern char *ucase();  /* convert string to upper case */
                     47: extern char *newcpy(); /* make a malloced copy of a string */
                     48: extern char *match();  /* match(s1, pat, fin)
                     49:                         * finds pat in s1 by pnmatch rules
                     50:                         * returns start of pattern or NULL
                     51:                         * places pointer to end in *fin
                     52:                         */
                     53: extern char *replace(); /* replace(s1, pat, s3, all, matcher)
                     54:                         * search s1 for pat and replace by s3.
                     55:                         * Using matcher which is a pointer to
                     56:                         * a function that looks externally like match.
                     57:                         * Returns a new malloced string or NULL
                     58:                         * does all if all != 0 else first. */
                     59: extern char * span();  /* span(s1, matcher, fin)
                     60:                         * matches all chars passing function
                     61:                         * matcher. Looks like match. */
                     62: extern char * skip();  /* skip(s1, matcher, fin)
                     63:                         * matches all chars not passing function
                     64:                         * matcher. Looks like match. */
                     65: extern approx();       /* approx(double a, double b) 1 if == within epsilon */
                     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: /*
                     87:  * Definitions etc. for regexp(3) routines.
                     88:  *
                     89:  * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
                     90:  * not the System V one.
                     91:  *
                     92:  * This is a modification of the University of Toronto regexp() package.
                     93:  * Mostly to fit in cleanly with Coherent's libmisc. The original can
                     94:  * be gotten free on mwcbbs.
                     95:  */
                     96: #define NSUBEXP  10
                     97: typedef struct regexp {
                     98:        char *startp[NSUBEXP];
                     99:        char *endp[NSUBEXP];
                    100:        char regstart;          /* Internal use only. */
                    101:        char reganch;           /* Internal use only. */
                    102:        char *regmust;          /* Internal use only. */
                    103:        int regmlen;            /* Internal use only. */
                    104:        char program[1];        /* Unwarranted chumminess with compiler. */
                    105: } regexp;
                    106: 
                    107: extern regexp *regcomp();
                    108: extern int regexec();
                    109: extern void regsub();
                    110: extern void regerror();
                    111: /*
                    112:  * The first byte of the regexp internal "program" is actually this magic
                    113:  * number; the start node begins in the second byte.
                    114:  */
                    115: #define        REG_MAGIC       (char)0234
                    116: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.