|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)strings.c 5.9 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: /*
25: * Mail -- a mail program
26: *
27: * String allocation routines.
28: * Strings handed out here are reclaimed at the top of the command
29: * loop each time, so they need not be freed.
30: */
31:
32: #include "rcv.h"
33:
34: /*
35: * Allocate size more bytes of space and return the address of the
36: * first byte to the caller. An even number of bytes are always
37: * allocated so that the space will always be on a word boundary.
38: * The string spaces are of exponentially increasing size, to satisfy
39: * the occasional user with enormous string size requests.
40: */
41:
42: char *
43: salloc(size)
44: {
45: register char *t;
46: register int s;
47: register struct strings *sp;
48: int index;
49:
50: s = size;
51: s += 3;
52: s &= ~03;
53: index = 0;
54: for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
55: if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s)
56: break;
57: if (sp->s_nleft >= s)
58: break;
59: index++;
60: }
61: if (sp >= &stringdope[NSPACE])
62: panic("String too large");
63: if (sp->s_topFree == NOSTR) {
64: index = sp - &stringdope[0];
65: sp->s_topFree = malloc(STRINGSIZE << index);
66: if (sp->s_topFree == NOSTR) {
67: fprintf(stderr, "No room for space %d\n", index);
68: panic("Internal error");
69: }
70: sp->s_nextFree = sp->s_topFree;
71: sp->s_nleft = STRINGSIZE << index;
72: }
73: sp->s_nleft -= s;
74: t = sp->s_nextFree;
75: sp->s_nextFree += s;
76: return(t);
77: }
78:
79: /*
80: * Reset the string area to be empty.
81: * Called to free all strings allocated
82: * since last reset.
83: */
84: sreset()
85: {
86: register struct strings *sp;
87: register int index;
88:
89: if (noreset)
90: return;
91: index = 0;
92: for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
93: if (sp->s_topFree == NOSTR)
94: continue;
95: sp->s_nextFree = sp->s_topFree;
96: sp->s_nleft = STRINGSIZE << index;
97: index++;
98: }
99: }
100:
101: /*
102: * Make the string area permanent.
103: * Meant to be called in main, after initialization.
104: */
105: spreserve()
106: {
107: register struct strings *sp;
108:
109: for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++)
110: sp->s_topFree = NOSTR;
111: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.