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

unix.superglobalmegacorp.com

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