Commit | Line | Data |
---|---|---|
761330fe DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
0c5f72fb KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
761330fe DF |
11 | */ |
12 | ||
0c5f72fb | 13 | #ifdef notdef |
9c226cb6 | 14 | static char sccsid[] = "@(#)strings.c 5.6 (Berkeley) %G%"; |
0c5f72fb | 15 | #endif /* notdef */ |
563238c6 KS |
16 | |
17 | /* | |
18 | * Mail -- a mail program | |
19 | * | |
20 | * String allocation routines. | |
21 | * Strings handed out here are reclaimed at the top of the command | |
22 | * loop each time, so they need not be freed. | |
23 | */ | |
24 | ||
25 | #include "rcv.h" | |
26 | ||
563238c6 KS |
27 | /* |
28 | * Allocate size more bytes of space and return the address of the | |
29 | * first byte to the caller. An even number of bytes are always | |
30 | * allocated so that the space will always be on a word boundary. | |
31 | * The string spaces are of exponentially increasing size, to satisfy | |
32 | * the occasional user with enormous string size requests. | |
33 | */ | |
34 | ||
35 | char * | |
36 | salloc(size) | |
37 | { | |
38 | register char *t; | |
39 | register int s; | |
40 | register struct strings *sp; | |
41 | int index; | |
42 | ||
43 | s = size; | |
021f9b0f KB |
44 | s += 3; |
45 | s &= ~03; | |
563238c6 KS |
46 | index = 0; |
47 | for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) { | |
48 | if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s) | |
49 | break; | |
50 | if (sp->s_nleft >= s) | |
51 | break; | |
52 | index++; | |
53 | } | |
54 | if (sp >= &stringdope[NSPACE]) | |
55 | panic("String too large"); | |
56 | if (sp->s_topFree == NOSTR) { | |
57 | index = sp - &stringdope[0]; | |
58 | sp->s_topFree = (char *) calloc(STRINGSIZE << index, | |
59 | (unsigned) 1); | |
60 | if (sp->s_topFree == NOSTR) { | |
61 | fprintf(stderr, "No room for space %d\n", index); | |
62 | panic("Internal error"); | |
63 | } | |
64 | sp->s_nextFree = sp->s_topFree; | |
65 | sp->s_nleft = STRINGSIZE << index; | |
66 | } | |
67 | sp->s_nleft -= s; | |
68 | t = sp->s_nextFree; | |
69 | sp->s_nextFree += s; | |
70 | return(t); | |
71 | } | |
72 | ||
73 | /* | |
74 | * Reset the string area to be empty. | |
75 | * Called to free all strings allocated | |
76 | * since last reset. | |
77 | */ | |
78 | ||
79 | sreset() | |
80 | { | |
81 | register struct strings *sp; | |
82 | register int index; | |
83 | ||
84 | if (noreset) | |
85 | return; | |
563238c6 KS |
86 | index = 0; |
87 | for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) { | |
88 | if (sp->s_topFree == NOSTR) | |
89 | continue; | |
90 | sp->s_nextFree = sp->s_topFree; | |
91 | sp->s_nleft = STRINGSIZE << index; | |
92 | index++; | |
93 | } | |
94 | } |