Annotation of 43BSD/contrib/xns/compiler/misc.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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