home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / tahoe / strings.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-18  |  2.3 KB  |  96 lines

  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 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.
  11.  */
  12.  
  13. #ifdef notdef
  14. static char sccsid[] = "@(#)strings.c    5.5 (Berkeley) 2/18/88";
  15. #endif /* notdef */
  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.  
  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;
  44.     s += 3;
  45.     s &= ~03;
  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;
  86.     minit();
  87.     index = 0;
  88.     for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
  89.         if (sp->s_topFree == NOSTR)
  90.             continue;
  91.         sp->s_nextFree = sp->s_topFree;
  92.         sp->s_nleft = STRINGSIZE << index;
  93.         index++;
  94.     }
  95. }
  96.