Annotation of 43BSD/ucb/Mail/strings.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 Regents of the University of California.
        !             3:  * All rights reserved.  The Berkeley software License Agreement
        !             4:  * specifies the terms and conditions for redistribution.
        !             5:  */
        !             6: 
        !             7: #ifndef lint
        !             8: static char *sccsid = "@(#)strings.c   5.2 (Berkeley) 6/21/85";
        !             9: #endif not lint
        !            10: 
        !            11: /*
        !            12:  * Mail -- a mail program
        !            13:  *
        !            14:  * String allocation routines.
        !            15:  * Strings handed out here are reclaimed at the top of the command
        !            16:  * loop each time, so they need not be freed.
        !            17:  */
        !            18: 
        !            19: #include "rcv.h"
        !            20: 
        !            21: /*
        !            22:  * Allocate size more bytes of space and return the address of the
        !            23:  * first byte to the caller.  An even number of bytes are always
        !            24:  * allocated so that the space will always be on a word boundary.
        !            25:  * The string spaces are of exponentially increasing size, to satisfy
        !            26:  * the occasional user with enormous string size requests.
        !            27:  */
        !            28: 
        !            29: char *
        !            30: salloc(size)
        !            31: {
        !            32:        register char *t;
        !            33:        register int s;
        !            34:        register struct strings *sp;
        !            35:        int index;
        !            36: 
        !            37:        s = size;
        !            38:        s++;
        !            39:        s &= ~01;
        !            40:        index = 0;
        !            41:        for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
        !            42:                if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s)
        !            43:                        break;
        !            44:                if (sp->s_nleft >= s)
        !            45:                        break;
        !            46:                index++;
        !            47:        }
        !            48:        if (sp >= &stringdope[NSPACE])
        !            49:                panic("String too large");
        !            50:        if (sp->s_topFree == NOSTR) {
        !            51:                index = sp - &stringdope[0];
        !            52:                sp->s_topFree = (char *) calloc(STRINGSIZE << index,
        !            53:                    (unsigned) 1);
        !            54:                if (sp->s_topFree == NOSTR) {
        !            55:                        fprintf(stderr, "No room for space %d\n", index);
        !            56:                        panic("Internal error");
        !            57:                }
        !            58:                sp->s_nextFree = sp->s_topFree;
        !            59:                sp->s_nleft = STRINGSIZE << index;
        !            60:        }
        !            61:        sp->s_nleft -= s;
        !            62:        t = sp->s_nextFree;
        !            63:        sp->s_nextFree += s;
        !            64:        return(t);
        !            65: }
        !            66: 
        !            67: /*
        !            68:  * Reset the string area to be empty.
        !            69:  * Called to free all strings allocated
        !            70:  * since last reset.
        !            71:  */
        !            72: 
        !            73: sreset()
        !            74: {
        !            75:        register struct strings *sp;
        !            76:        register int index;
        !            77: 
        !            78:        if (noreset)
        !            79:                return;
        !            80:        minit();
        !            81:        index = 0;
        !            82:        for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
        !            83:                if (sp->s_topFree == NOSTR)
        !            84:                        continue;
        !            85:                sp->s_nextFree = sp->s_topFree;
        !            86:                sp->s_nleft = STRINGSIZE << index;
        !            87:                index++;
        !            88:        }
        !            89: }

unix.superglobalmegacorp.com

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