Annotation of 42BSD/games/trek/utility.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)utility.c  4.1     (Berkeley)      3/23/83";
                      3: #endif not lint
                      4: 
                      5: /*
                      6: **  ASSORTED UTILITY ROUTINES
                      7: */
                      8: 
                      9: /*
                     10: **  BLOCK MOVE
                     11: **
                     12: **     Moves a block of storage of length `l' bytes from the data
                     13: **     area pointed to by `a' to the area pointed to by `b'.
                     14: **     Returns the address of the byte following the `b' field.
                     15: **     Overflow of `b' is not tested.
                     16: */
                     17: 
                     18: char *bmove(a, b, l)
                     19: char   *a, *b;
                     20: int    l;
                     21: {
                     22:        register int            n;
                     23:        register char           *p, *q;
                     24: 
                     25:        p = a;
                     26:        q = b;
                     27:        n = l;
                     28:        while (n--)
                     29:                *q++ = *p++;
                     30:        return (q);
                     31: }
                     32: 
                     33: 
                     34: /*
                     35: **  STRING EQUALITY TEST
                     36: **     null-terminated strings `a' and `b' are tested for
                     37: **     absolute equality.
                     38: **     returns one if equal, zero otherwise.
                     39: */
                     40: 
                     41: sequal(a, b)
                     42: char   *a, *b;
                     43: {
                     44:        register char           *p, *q;
                     45: 
                     46:        p = a;
                     47:        q = b;
                     48:        while (*p || *q)
                     49:                if (*p++ != *q++)
                     50:                        return(0);
                     51:        return(1);
                     52: }
                     53: 
                     54: 
                     55: /*
                     56: **  STRING CONCATENATE
                     57: **
                     58: **     The strings `s1' and `s2' are concatenated and stored into
                     59: **     `s3'.  It is ok for `s1' to equal `s3', but terrible things
                     60: **     will happen if `s2' equals `s3'.  The return value is is a
                     61: **     pointer to the end of `s3' field.
                     62: */
                     63: 
                     64: char *concat(s1, s2, s3)
                     65: char   *s1, *s2, *s3;
                     66: {
                     67:        register char           *p;
                     68:        register char           *q;
                     69: 
                     70:        p = s3;
                     71:        q = s1;
                     72:        while (*q)
                     73:                *p++ = *q++;
                     74:        q = s2;
                     75:        while (*q)
                     76:                *p++ = *q++;
                     77:        *p = 0;
                     78:        return (p);
                     79: }
                     80: 
                     81: 
                     82: /*
                     83: **  FIND STRING LENGTH
                     84: **
                     85: **     The length of string `s' (excluding the null byte which
                     86: **             terminates the string) is returned.
                     87: */
                     88: 
                     89: length(s)
                     90: char   *s;
                     91: {
                     92:        register int    l;
                     93:        register char   *p;
                     94: 
                     95:        l = 0;
                     96:        p = s;
                     97:        while (*p++)
                     98:                l++;
                     99:        return(l);
                    100: }
                    101: 
                    102: 
                    103: /*
                    104: **  SYSTEM ERROR
                    105: */
                    106: 
                    107: syserr(p0, p1, p2, p3, p4, p5)
                    108: {
                    109:        extern int      errno;
                    110: 
                    111:        printf("\n\07TREK SYSERR: ");
                    112:        printf(p0, p1, p2, p3, p4, p5);
                    113:        printf("\n");
                    114:        if (errno)
                    115:                printf("\tsystem error %d\n", errno);
                    116:        exit(-1);
                    117: }

unix.superglobalmegacorp.com

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