Diff for /gforth/Attic/engine.c between versions 1.32 and 1.33

version 1.32, 1995/12/10 19:02:07 version 1.33, 1995/12/26 17:35:36
Line 19 Line 19
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */  */
   
   #include "config.h"
 #include <ctype.h>  #include <ctype.h>
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
Line 88  int emitcounter; Line 89  int emitcounter;
 #define NULLC '\0'  #define NULLC '\0'
   
 char *cstr(Char *from, UCell size, int clear)  char *cstr(Char *from, UCell size, int clear)
 /* if clear is true, scratch can be reused, otherwise we want more of  /* return a C-string corresponding to the Forth string ( FROM SIZE ).
    the same */     the C-string lives until the next call of cstr with CLEAR being true */
 {  {
   static char *scratch=NULL;    static struct cstr_buffer {
   static unsigned scratchsize=0;      char *buffer;
   static char *nextscratch;      size_t size;
   char *oldnextscratch;    } *buffers=NULL;
     static int nbuffers=0;
     static int used=0;
     struct cstr_buffer *b;
   
     if (buffers==NULL)
       buffers=malloc(0);
   if (clear)    if (clear)
     nextscratch=scratch;      used=0;
   if (scratch==NULL) {    if (used>=nbuffers) {
     scratch=malloc(size+1);      buffers=realloc(buffers,sizeof(struct cstr_buffer)*(used+1));
     nextscratch=scratch;      buffers[used]=(struct cstr_buffer){malloc(0),0};
     scratchsize=size;      nbuffers=used+1;
   }    }
   else if (nextscratch+size>scratch+scratchsize) {    b=&buffers[used];
     char *oldscratch=scratch;    if (size+1 > b->size) {
     scratch = realloc(scratch, (nextscratch-scratch)+size+1);      b->buffer = realloc(b->buffer,size+1);
     nextscratch=scratch+(nextscratch-oldscratch);      b->size = size+1;
     scratchsize=size;  
   }    }
   memcpy(nextscratch,from,size);    memcpy(b->buffer,from,size);
   nextscratch[size]='\0';    b->buffer[size]='\0';
   oldnextscratch = nextscratch;    used++;
   nextscratch += size+1;    return b->buffer;
   return oldnextscratch;  
 }  }
   
 char *tilde_cstr(Char *from, UCell size, int clear)  char *tilde_cstr(Char *from, UCell size, int clear)

Removed from v.1.32  
changed lines
  Added in v.1.33


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>