Annotation of 43BSDTahoe/new/xns/compiler/misc.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char RCSid[] = "$Header: misc.c,v 2.1 86/10/11 15:47:55 jqj Exp $";
        !             3: #endif
        !             4: 
        !             5: /* $Log:       misc.c,v $
        !             6:  * Revision 2.1  86/10/11  15:47:55  jqj
        !             7:  * in stringtocard(), if passed a null pointer return 0. (per Liebman)
        !             8:  * 
        !             9:  * Revision 2.0  85/11/21  07:21:41  jqj
        !            10:  * 4.3BSD standard release
        !            11:  * 
        !            12:  * Revision 1.3  85/03/11  16:39:50  jqj
        !            13:  * *** empty log message ***
        !            14:  * 
        !            15:  * Revision 1.3  85/03/11  16:39:50  jqj
        !            16:  * Public alpha-test version, released 11 March 1985
        !            17:  * 
        !            18:  * Revision 1.2  85/02/21  11:05:34  jqj
        !            19:  * alpha test version
        !            20:  * 
        !            21:  * Revision 1.1  85/02/15  13:55:34  jqj
        !            22:  * Initial revision
        !            23:  * 
        !            24:  */
        !            25: 
        !            26: #include "compiler.h"
        !            27: 
        !            28: /*
        !            29:  * String allocation.
        !            30:  */
        !            31: char *
        !            32: copy(s)
        !            33:        char *s;
        !            34: {
        !            35:        char *p;
        !            36:        extern char *malloc();
        !            37: 
        !            38:        if ((p = malloc(strlen(s) + 1)) == NULL) {
        !            39:                error(FATAL, "out of string space");
        !            40:        }
        !            41:        (void) strcpy(p, s);
        !            42:        return (p);
        !            43: }
        !            44: 
        !            45: 
        !            46: /*
        !            47:  * like atoi, convert a string to an integer.  Accept
        !            48:  * 1/ numeric string, e.g. "34"
        !            49:  * 2/ hex string, e.g. "0x22"
        !            50:  * 3/ octal string, e.g. "042"
        !            51:  * Handles only positive integers.
        !            52:  */
        !            53: int
        !            54: stringtocard(str)
        !            55:        char *str;
        !            56: {
        !            57:        int val;
        !            58: 
        !            59:        if (str == (char *) NULL)
        !            60:                return(0);      /* sanity check */
        !            61:        if (
        !            62:            sscanf(str, " -0x%x", &val) > 0 ||
        !            63:            sscanf(str, " -0%o", &val) > 0)
        !            64:                return( -val);
        !            65:        if (
        !            66:            sscanf(str, " 0x%x", &val) > 0 ||
        !            67:            sscanf(str, " 0%o", &val) > 0 ||
        !            68:            sscanf(str, " %d", &val) > 0 
        !            69:           )
        !            70:                return(val);
        !            71:        return(0);
        !            72: }
        !            73: 
        !            74: 
        !            75: /*
        !            76:  * Lisp operations.
        !            77:  */
        !            78: list
        !            79: cons(a, b)
        !            80:        list a, b;
        !            81: {
        !            82:        list p;
        !            83: 
        !            84:        if ((p = New(struct cons)) == NIL) {
        !            85:                error(FATAL,"Out of list space.");
        !            86:        }
        !            87:        car(p) = a;
        !            88:        cdr(p) = b;
        !            89:        return (p);
        !            90: }
        !            91: 
        !            92: length(p)
        !            93:        list p;
        !            94: {
        !            95:        int n;
        !            96: 
        !            97:        for (n = 0; p != NIL; p = cdr(p), n++)
        !            98:                ;
        !            99:        return (n);
        !           100: }
        !           101: 
        !           102: list
        !           103: nconc(p, q)
        !           104:        list p, q;
        !           105: {
        !           106:        list pp;
        !           107: 
        !           108:        pp = p;
        !           109:        if (p == NIL)
        !           110:                return (q);
        !           111:        while (cdr(p) != NIL)
        !           112:                p = cdr(p);
        !           113:        cdr(p) = q;
        !           114:        return (pp);
        !           115: }
        !           116: 

unix.superglobalmegacorp.com

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