ack/util/ack/grows.c
George Koehler 65278bc9a9 In util/ack, add prototypes and static to functions.
Declare most functions before using them.  I declare some functions in
ack.h and some in trans.h (because trans.h declares type trf).  I
leave declarations of scanb() and scanvars() in .c files because they
need type growstring.  (I can't #include "grows.h" in another header
file as long as grows.h doesn't guard against multiple inclusion.)

Functions used within one file become static.  I remove a few tiny
functions.  I move a few functions or declarations to more convenient
places.  Some functions now return void instead of a garbage int.

I feel that keyword "register" is obsolete, so I removed it from where
I was editing.  This commit doesn't touch mktables.c
2016-11-12 21:12:45 -05:00

75 lines
1.8 KiB
C

/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
*/
/**************************************************************************/
/* */
/* Bookkeeping for growing strings */
/* */
/**************************************************************************/
#include <stdlib.h>
#include "ack.h"
#include "grows.h"
#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
static char rcs_grows[] = RCS_GROWS ;
#endif
int gr_add(growstring *id, int c) {
if ( id->gr_size==id->gr_max) {
if ( id->gr_size==0 ) { /* The first time */
id->gr_max= 2*GR_MORE ;
id->gr_string= getcore(id->gr_max) ;
} else {
id->gr_max += GR_MORE ;
id->gr_string= changecore(id->gr_string,id->gr_max ) ;
}
}
*(id->gr_string+id->gr_size++)= c ;
}
int gr_cat(growstring *id, const char *string) {
const char *ptr ;
#ifdef DEBUG
if ( id->gr_size && *(id->gr_string+id->gr_size-1) ) {
vprint("Non-zero terminated %*s\n",
id->gr_size, id->gr_string ) ;
}
#endif
if ( id->gr_size ) id->gr_size-- ;
ptr=string ;
for (;;) {
gr_add(id,*ptr) ;
if ( *ptr++ ) continue ;
break ;
}
}
void gr_throw(growstring *id) {
/* Throw the string away */
if ( id->gr_max==0 ) return ;
freecore(id->gr_string) ;
id->gr_string = 0 ;
id->gr_max=0 ;
id->gr_size=0 ;
}
void gr_init(growstring *id) {
id->gr_size=0 ; id->gr_max=0 ;
}
char *gr_final(growstring *id) {
/* Throw away the bookkeeping, adjust the string to its final
length and return a pointer to a string to be get rid of with
throws
*/
register char *retval ;
retval= keeps(gr_start(*id)) ;
gr_throw(id) ;
return retval ;
}