2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
7 /**************************************************************************/
9 /* Bookkeeping for growing strings */
11 /**************************************************************************/
17 static char rcs_id[] = "$Id: grows.c,v 2.4 1994/06/24 10:12:40 ceriel Exp $" ;
18 static char rcs_grows[] = RCS_GROWS ;
21 gr_add(id,c) register growstring *id ; char c ; {
22 if ( id->gr_size==id->gr_max) {
23 if ( id->gr_size==0 ) { /* The first time */
24 id->gr_max= 2*GR_MORE ;
25 id->gr_string= getcore(id->gr_max) ;
27 id->gr_max += GR_MORE ;
28 id->gr_string= changecore(id->gr_string,id->gr_max ) ;
31 *(id->gr_string+id->gr_size++)= c ;
34 gr_cat(id,string) growstring *id ; char *string ; {
38 if ( id->gr_size && *(id->gr_string+id->gr_size-1) ) {
39 vprint("Non-zero terminated %*s\n",
40 id->gr_size, id->gr_string ) ;
43 if ( id->gr_size ) id->gr_size-- ;
47 if ( *ptr++ ) continue ;
52 gr_throw(id) register growstring *id ; {
53 /* Throw the string away */
54 if ( id->gr_max==0 ) return ;
55 freecore(id->gr_string) ;
61 gr_init(id) growstring *id ; {
62 id->gr_size=0 ; id->gr_max=0 ;
65 char *gr_final(id) growstring *id ; {
66 /* Throw away the bookkeeping, adjust the string to its final
67 length and return a pointer to a string to be get rid of with
70 register char *retval ;
71 retval= keeps(gr_start(*id)) ;