Annotation of 40BSD/cmd/pi/string.c, revision 1.1

1.1     ! root        1: /* Copyright (c) 1979 Regents of the University of California */
        !             2: 
        !             3: static char sccsid[] = "@(#)string.c 1.1 8/27/80";
        !             4: 
        !             5: #include "whoami.h"
        !             6: #include "0.h"
        !             7: #ifndef PI01
        !             8: #ifndef PXP
        !             9: #include "send.h"
        !            10: #endif
        !            11: #endif
        !            12: 
        !            13: /*
        !            14:  * STRING SPACE DECLARATIONS
        !            15:  *
        !            16:  * Strng is the base of the current
        !            17:  * string space and strngp the
        !            18:  * base of the free area therein.
        !            19:  * Strp is the array of descriptors.
        !            20:  */
        !            21: #ifndef PI0
        !            22: STATIC char strings[STRINC];
        !            23: STATIC char *strng = strings;
        !            24: STATIC char *strngp = strings;
        !            25: #else
        !            26: char   *strng, *strngp;
        !            27: #endif
        !            28: #ifndef PI01
        !            29: #ifndef PXP
        !            30: STATIC char *strp[20];
        !            31: STATIC char **stract strp;
        !            32: int    strmax;
        !            33: #endif
        !            34: #endif
        !            35: 
        !            36: #ifndef PI01
        !            37: #ifndef PXP
        !            38: #ifndef PI0
        !            39: initstring()
        !            40: #else
        !            41: initstring(strings)
        !            42:        char *strings;
        !            43: #endif
        !            44: {
        !            45: 
        !            46:        *stract++ = strings;
        !            47: #ifdef PI0
        !            48:        strng = strngp = strings;
        !            49: #endif
        !            50:        strmax = STRINC * 2;
        !            51: }
        !            52: #endif
        !            53: #endif
        !            54: 
        !            55: /*
        !            56:  * Copy a string into the string area.
        !            57:  */
        !            58: char *
        !            59: savestr(cp)
        !            60:        register char *cp;
        !            61: {
        !            62:        register int i;
        !            63: 
        !            64:        i = strlen(cp) + 1;
        !            65:        if (strngp + i >= strng + STRINC) {
        !            66:                strngp = malloc(STRINC);
        !            67:                if (strngp == -1) {
        !            68:                        yerror("Ran out of memory (string)");
        !            69:                        pexit(DIED);
        !            70:                }
        !            71: #ifndef PI01
        !            72: #ifndef PXP
        !            73:                *stract++ = strngp;
        !            74:                strmax =+ STRINC;
        !            75: #endif
        !            76: #endif
        !            77:                strng = strngp;
        !            78:        }
        !            79:        strcpy(strngp, cp);
        !            80:        cp = strngp;
        !            81:        strngp = cp + i;
        !            82: #ifdef PI0
        !            83:        send(RSTRING, cp);
        !            84: #endif
        !            85:        return (cp);
        !            86: }
        !            87: 
        !            88: #ifndef PI1
        !            89: #ifndef PXP
        !            90: esavestr(cp)
        !            91:        char *cp;
        !            92: {
        !            93: 
        !            94: #ifdef PI0
        !            95:        send(REVENIT);
        !            96: #endif
        !            97:        strngp = ( (char *) ( ( (int) (strngp + 1) ) &~ 1 ) );
        !            98:        return (savestr(cp));
        !            99: }
        !           100: #endif
        !           101: #endif
        !           102: 
        !           103: #ifndef PI01
        !           104: #ifndef PXP
        !           105: soffset(cp)
        !           106:        register char *cp;
        !           107: {
        !           108:        register char **sp;
        !           109:        register int i;
        !           110: 
        !           111:        if (cp == NIL || cp == OCT || cp == HEX)
        !           112:                return (-cp);
        !           113:        for (i = STRINC, sp = strp; sp < stract; sp++) {
        !           114:                if (cp >= *sp && cp < (*sp + STRINC))
        !           115:                        return (i + (cp - *sp));
        !           116:                i =+ STRINC;
        !           117:        }
        !           118:        i = nlfund(cp);
        !           119:        if (i != 0)
        !           120:                return (i);
        !           121:        panic("soffset");
        !           122: }
        !           123: #ifdef PI1
        !           124: sreloc(i)
        !           125:        register int i;
        !           126: {
        !           127: 
        !           128:        if (i == 0 || i == -OCT || i == -HEX)
        !           129:                return (-i);
        !           130:        if (i < STRINC) {
        !           131:                if (i >= INL)
        !           132:                        panic("sreloc INL");
        !           133:                i = nl[i].symbol;
        !           134:                if (i == 0)
        !           135:                        panic("sreloc nl[i]");
        !           136:                return (i);
        !           137:        }
        !           138:        if (i > strmax || i < 0)
        !           139:                panic("sreloc");
        !           140:        return (strp[(i / STRINC) - 1] + (i % STRINC));
        !           141: }
        !           142: 
        !           143: evenit()
        !           144: {
        !           145: 
        !           146:        strngp = (strngp + 1) &~ 1;
        !           147: }
        !           148: #endif
        !           149: #endif
        !           150: #endif

unix.superglobalmegacorp.com

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