diff --git a/Makefile b/Makefile index 635650bc4..febd87aff 100644 --- a/Makefile +++ b/Makefile @@ -88,6 +88,7 @@ $(BUILDDIR)/build.$(BUILDSYSTEM): first/ackbuilder.lua Makefile $(BUILD_FILES) $ @$(LUA) first/ackbuilder.lua \ first/build.lua build.lua \ --$(BUILDSYSTEM) \ + DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \ OBJDIR=$(OBJDIR) \ BINDIR=$(BINDIR) \ LIBDIR=$(LIBDIR) \ diff --git a/util/ack/ack.1.X b/util/ack/ack.1.X index 689992ac7..1e35bca81 100644 --- a/util/ack/ack.1.X +++ b/util/ack/ack.1.X @@ -100,7 +100,7 @@ Note: \fIack\fP refuses to overwrite argument \fI.e\fP files. .IP \-t Preserve all intermediate files. If two \fB\-t\fP are used, -\fIack\fP also preserves core dumps and output of failed transformations. +\fIack\fP also preserves output of failed transformations. .IP \-w Suppress all warning messages. diff --git a/util/ack/ack.h b/util/ack/ack.h index 0877a8c0d..01eec8212 100644 --- a/util/ack/ack.h +++ b/util/ack/ack.h @@ -6,6 +6,8 @@ #define RCS_ACK "$Id$" #endif +#include /* size_t, free() */ + /****************************************************************************/ /* User settable options */ /****************************************************************************/ @@ -61,20 +63,29 @@ typedef struct { #define p_cont(elem) ((path *)l_content(elem)) -/* Return values of setpath() */ -enum f_path { F_OK, F_NOMATCH, F_NOPATH } ; - /* Own routines */ -enum f_path getpath(); -enum f_path scan_end(); -extern void noodstop(); -extern char *getvar(); -extern char *keeps(); -extern char *basename(); -extern char *skipblank(); -extern char *firstblank(); -extern char *getcore(); -extern char *changecore(); + +/* rmach.c */ +void setlist(char *); + +/* svars.c */ +void setsvar(char *, char *); +void setpvar(char *, char *(*)(void)); +char *getvar(const char *); + +/* util.c */ +char *ack_basename(const char *); +char *skipblank(char *); +char *firstblank(char *); +void fatal(const char *, ...); +void vprint(const char *, ...); +void fuerror(const char *, ...); +void werror(const char *, ...); +void quit(int); +char *keeps(const char *); +#define throws(str) free(str) +void *getcore(size_t); +void *changecore(void *, size_t); #define freecore(area) free(area) #define DEBUG 1 /* Allow debugging of Ack */ diff --git a/util/ack/build.lua b/util/ack/build.lua index 4394484b4..cb9b66fd4 100644 --- a/util/ack/build.lua +++ b/util/ack/build.lua @@ -18,12 +18,28 @@ normalrule { cprogram { name = "ack", srcs = { - "./*.c", + "./data.c", + "./files.c", + "./grows.c", + "./list.c", + "./main.c", + "./rmach.c", + "./run.c", + "./scan.c", + "./svars.c", + "./trans.c", + "./util.c", "+tables", }, deps = { "h+emheaders", "h+local", + "./ack.h", + "./data.h", + "./dmach.h", + "./grows.h", + "./list.h", + "./trans.h", } } diff --git a/util/ack/data.h b/util/ack/data.h index d6ae07855..ea845c4f7 100644 --- a/util/ack/data.h +++ b/util/ack/data.h @@ -48,4 +48,4 @@ EXTERN path in; /* The current single input pathname */ EXTERN path out; /* The current output pathname */ EXTERN path orig; /* The original input path */ EXTERN char *p_basename; /* The current basename */ -EXTERN char *p_suffix; /* The current input suffix */ +EXTERN const char *p_suffix; /* The current input suffix */ diff --git a/util/ack/files.c b/util/ack/files.c index f2dbc8ed2..e149b90f7 100644 --- a/util/ack/files.c +++ b/util/ack/files.c @@ -16,7 +16,7 @@ static char rcs_id[] = "$Id$" ; #endif -char *add_u(part,ptr) char *ptr ; { +static char *add_u(int part, char *ptr) { if ( part>=26 ) { ptr=add_u(part/26-1,ptr) ; } @@ -24,7 +24,7 @@ char *add_u(part,ptr) char *ptr ; { return ptr+1 ; } -char *unique() { +static char *unique(void) { /* Get the next unique part of the internal filename */ static int u_next = 0 ; static char buf[10] ; @@ -36,7 +36,7 @@ char *unique() { return buf ; } -setfiles(phase) register trf *phase ; { +int setfiles(trf *phase) { /* Set the out structure according to the in structure, the transformation and some global data */ growstring pathname ; @@ -94,18 +94,7 @@ setfiles(phase) register trf *phase ; { return 1 ; } -disc_files(phase) trf *phase ; { - path temp ; - - if ( !phase->t_combine ) { - file_final(&in) ; - } else { - disc_inputs(phase) ; - } - temp=in ; in=out ; out=temp ; -} - -file_final(file) path *file ; { +static void file_final(path *file) { if ( file->p_path ) { if ( !file->p_keep && t_flag<=1 ) { if ( unlink(file->p_path)!=0 ) { @@ -119,7 +108,18 @@ file_final(file) path *file ; { file->p_keep=NO ; } -disc_inputs(phase) trf *phase ; { +void disc_files(trf *phase) { + path temp ; + + if ( !phase->t_combine ) { + file_final(&in) ; + } else { + disc_inputs(phase) ; + } + temp=in ; in=out ; out=temp ; +} + +void disc_inputs(trf *phase) { /* Remove all the input files of this phase */ /* Only for combiners */ register path *l_in ; @@ -132,7 +132,7 @@ disc_inputs(phase) trf *phase ; { l_clear(&phase->t_inputs) ; } -rmfile(file) path *file ; { +void rmfile(path *file) { /* Remove a file, do not complain when is does not exist */ if ( file->p_path ) { if ( t_flag<=1 ) unlink(file->p_path) ; @@ -143,8 +143,7 @@ rmfile(file) path *file ; { } } -void -rmtemps() { +void rmtemps(void) { /* Called in case of disaster, always remove the current output file! */ register list_elem *elem ; @@ -159,7 +158,7 @@ rmtemps() { } } -add_input(file,phase) path *file ; trf *phase ; { +void add_input(path *file, trf *phase) { register path *store ; #ifdef DEBUG if ( debug ) { diff --git a/util/ack/grows.c b/util/ack/grows.c index 81c3c002d..a74e27731 100644 --- a/util/ack/grows.c +++ b/util/ack/grows.c @@ -19,7 +19,7 @@ static char rcs_id[] = "$Id$" ; static char rcs_grows[] = RCS_GROWS ; #endif -gr_add(id,c) register growstring *id ; char c ; { +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 ; @@ -32,8 +32,8 @@ gr_add(id,c) register growstring *id ; char c ; { *(id->gr_string+id->gr_size++)= c ; } -gr_cat(id,string) growstring *id ; char *string ; { - register char *ptr ; +int gr_cat(growstring *id, const char *string) { + const char *ptr ; #ifdef DEBUG if ( id->gr_size && *(id->gr_string+id->gr_size-1) ) { @@ -50,8 +50,7 @@ gr_cat(id,string) growstring *id ; char *string ; { } } -void -gr_throw(id) register growstring *id ; { +void gr_throw(growstring *id) { /* Throw the string away */ if ( id->gr_max==0 ) return ; freecore(id->gr_string) ; @@ -60,11 +59,11 @@ gr_throw(id) register growstring *id ; { id->gr_size=0 ; } -gr_init(id) growstring *id ; { +void gr_init(growstring *id) { id->gr_size=0 ; id->gr_max=0 ; } -char *gr_final(id) growstring *id ; { +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 diff --git a/util/ack/grows.h b/util/ack/grows.h index 9b9511049..04f95aa59 100644 --- a/util/ack/grows.h +++ b/util/ack/grows.h @@ -20,8 +20,8 @@ typedef struct { /* Routines used */ -extern void gr_throw() ; /* To free the core */ -extern int gr_add() ; /* To add one character */ -extern int gr_cat() ; /* concatenate the contents and the string */ -extern int gr_init() ; /* Initialize the bookkeeping */ -extern char *gr_final() ; /* Transform to a stable storage string */ +void gr_throw(growstring *) ; /* To free the core */ +int gr_add(growstring *, int) ; /* To add one character */ +int gr_cat(growstring *, const char *) ; /* To append a string */ +void gr_init(growstring *) ; /* Initialize the bookkeeping */ +char *gr_final(growstring *) ; /* Move to a stable storage string */ diff --git a/util/ack/list.c b/util/ack/list.c index 278f55580..5370e96cb 100644 --- a/util/ack/list.c +++ b/util/ack/list.c @@ -33,7 +33,7 @@ Routines: */ -l_add(header,string) list_head *header ; char *string ; { +void l_add(list_head *header, char *string) { register list_elem *new; /* NOSTRICT */ @@ -49,7 +49,7 @@ l_add(header,string) list_head *header ; char *string ; { header->ca_last= new ; } -l_clear(header) list_head *header ; { +void l_clear(list_head *header) { register list_elem *old, *next; for ( old=header->ca_first ; old ; old= next ) { next= old->ca_next ; @@ -59,7 +59,7 @@ l_clear(header) list_head *header ; { header->ca_last = (list_elem *) 0 ; } -l_throw(header) list_head *header ; { +void l_throw(list_head *header) { register list_elem *old, *next; for ( old=header->ca_first ; old ; old= next ) { throws(l_content(*old)) ; diff --git a/util/ack/list.h b/util/ack/list.h index 3e6d55170..f96d8ce15 100644 --- a/util/ack/list.h +++ b/util/ack/list.h @@ -29,3 +29,7 @@ typedef struct ca_elem list_elem ; /* The decl. for elements */ /* To be used for scanning lists, ptr is the running variable */ #define scanlist(elem,ptr) \ for ( ptr= elem ; ptr; ptr= l_next(*ptr) ) + +void l_add(list_head *, char *); +void l_clear(list_head *); +void l_throw(list_head *); diff --git a/util/ack/main.c b/util/ack/main.c index 99e27dceb..539f42180 100644 --- a/util/ack/main.c +++ b/util/ack/main.c @@ -22,11 +22,20 @@ static char rcs_ack[] = RCS_ACK ; static int sigs[] = { SIGINT, SIGHUP, SIGTERM, 0 } ; static int arg_count; -extern char *getenv(); +static char *srcvar(void); +static char *getsuffix(void); +static void varinit(void); +static void vieuwargs(int, char **); +static void firstarg(char *); +static int process(char *); +static int startrf(trf *); +static void block(trf *); +static int mayprep(void); +static void scanneeds(void); +static void setneeds(const char *, int); +static void noodstop(int); -void vieuwargs(); - -main(argc,argv) char **argv ; { +int main(int argc, char **argv) { register list_elem *elem ; register char *frontend ; register int *n_sig ; @@ -102,7 +111,7 @@ main(argc,argv) char **argv ; { orig.p_path=phase->t_origname ; if ( p_basename ) throws(p_basename) ; if ( orig.p_path ) { - p_basename= keeps(basename(orig.p_path)) ; + p_basename= keeps(ack_basename(orig.p_path)) ; } else { p_basename=0 ; } @@ -115,15 +124,15 @@ main(argc,argv) char **argv ; { exit(0) ; } -char *srcvar() { +static char *srcvar(void) { return orig.p_path ; } -char *getsuffix() { +static char *getsuffix(void) { return strrchr(orig.p_path, SUFCHAR) ; } -varinit() { +static void varinit(void) { /* initialize the string variables */ register char *envstr ; extern char *em_dir; @@ -138,8 +147,7 @@ varinit() { /************************* flag processing ***********************/ -void -vieuwargs(argc,argv) char **argv ; { +void vieuwargs(int argc, char **argv) { register char *argp; register int nextarg ; register int eaten ; @@ -206,14 +214,16 @@ vieuwargs(argc,argv) char **argv ; { case 'r': if ( argp[2]!=SUFCHAR ) { error("-r must be followed by %c",SUFCHAR) ; } - keeptail(&argp[2]); eaten=1 ; + l_add(&tail_list, &argp[2]) ; + eaten=1 ; break ; case '.': if ( rts ) { if ( strcmp(rts,&argp[1])!=0 ) fuerror("Two run-time systems?") ; } else { rts= &argp[1] ; - keephead(rts) ; keeptail(rts) ; + l_add(&head_list, rts) ; + l_add(&tail_list, rts) ; } eaten=1 ; break ; @@ -238,7 +248,7 @@ vieuwargs(argc,argv) char **argv ; { register char *tokeep ; tokeep=keeps(argp) ; if ( argp[1]=='R' ) { - do_Rflag(tokeep); + l_add(&R_list, tokeep) ; } else { *tokeep |= NO_SCAN ; } @@ -251,7 +261,7 @@ vieuwargs(argc,argv) char **argv ; { return ; } -firstarg(argp) register char *argp ; { +static void firstarg(char *argp) { register char *name ; name=strrchr(argp,'/') ; @@ -265,7 +275,7 @@ firstarg(argp) register char *argp ; { /************************* argument processing ***********************/ -process(arg) char *arg ; { +static int process(char *arg) { /* Process files & library arguments */ trf *phase ; register trf *tmp ; @@ -282,7 +292,7 @@ process(arg) char *arg ; { return 1 ; } if ( p_basename ) throws(p_basename) ; - p_basename= keeps(basename(arg)) ; + p_basename= keeps(ack_basename(arg)) ; /* Try to find a path through the transformations */ switch( getpath(&phase) ) { case F_NOPATH : @@ -325,7 +335,7 @@ process(arg) char *arg ; { return startrf(phase) ; } -int startrf(first) trf *first ; { +static int startrf(trf *first) { /* Start the transformations at the indicated phase */ register trf *phase ; @@ -397,7 +407,7 @@ if ( debug ) vprint("Transformation sequence complete for %s\n", return 1 ; } -block(first) trf *first ; { +static void block(trf *first) { /* One of the input files of this phase could not be produced, block all combiners taking their input from this one. */ @@ -406,7 +416,8 @@ block(first) trf *first ; { if ( phase->t_combine ) phase->t_blocked=YES ; } } -mayprep() { + +static int mayprep(void) { int file ; char fc ; file=open(in.p_path,0); @@ -416,15 +427,7 @@ mayprep() { return fc=='#' ; } -keephead(suffix) char *suffix ; { - l_add(&head_list, suffix) ; -} - -keeptail(suffix) char *suffix ; { - l_add(&tail_list, suffix) ; -} - -scanneeds() { +static void scanneeds(void) { register list_elem *elem ; scanlist(l_first(head_list), elem) { setneeds(l_content(*elem),0) ; } l_clear(&head_list) ; @@ -432,7 +435,7 @@ scanneeds() { l_clear(&tail_list) ; } -setneeds(suffix,tail) char *suffix ; { +static void setneeds(const char *suffix, int tail) { trf *phase ; p_suffix= suffix ; @@ -456,3 +459,7 @@ setneeds(suffix,tail) char *suffix ; { break ; } } + +static void noodstop(int sig) { + quit(-3) ; +} diff --git a/util/ack/rmach.c b/util/ack/rmach.c index 1e33e8713..13f904a38 100644 --- a/util/ack/rmach.c +++ b/util/ack/rmach.c @@ -47,19 +47,17 @@ static char rcs_dmach[] = RCS_DMACH ; #define CALL "callname" #define END "end" -extern growstring scanb(); -extern growstring scanvars(); +static void intrf(void) ; +static void open_in(char *) ; +static void close_in(void) ; +static int getinchar(void) ; +static int getln(void) ; -int getln() ; -int getinchar() ; static char *ty_name ; static char *bol ; - -void open_in(); - static char *inname ; -setlist(name) char *name ; { +void setlist(char *name) { /* Name is sought in the internal tables, if not present, the a file of that name is sought in first the current and then the EM Lib directory @@ -92,9 +90,7 @@ setlist(name) char *name ; { #endif } -static int inoptlist(nm) - char *nm ; -{ +static int inoptlist(char *nm) { register char *p=Optlist ; while ( p && *p ) { @@ -107,9 +103,9 @@ static int inoptlist(nm) return 0; } -intrf() { +static void intrf(void) { + /* Read in trf (transformation) */ register trf *new ; - growstring bline ; int twice ; int name_seen=0 ; @@ -130,20 +126,14 @@ intrf() { } else if ( strcmp(ty_name,PROG)==0 ) { if ( new->t_prog ) twice=YES ; - bline= scanb(bol); /* Scan for \ */ - new->t_prog= gr_final(&bline); + new->t_prog= keeps(bol); } else if ( strcmp(ty_name,MAPF)==0 ) { - /* First read the mapflags line - and scan for backslashes */ - bline= scanb(bol) ; - l_add(&new->t_mapf,gr_final(&bline)) ; + l_add(&new->t_mapf,keeps(bol)) ; } else if ( strcmp(ty_name,ARGS)==0 ) { if ( new->t_argd ) twice=YES ; - bline= scanb(bol) ; - new->t_argd= keeps(gr_start(bline)) ; - gr_throw(&bline) ; + new->t_argd= keeps(bol) ; } else if ( strcmp(ty_name,STD_IN)==0 ) { if ( new->t_stdin ) twice=YES ; @@ -234,14 +224,15 @@ intrf() { rts, new->t_rts) ; } rts= new->t_rts ; - keephead(rts) ; keeptail(rts) ; + l_add(&head_list, rts) ; + l_add(&tail_list, rts) ; } #ifdef DEBUG if ( debug>=3 ) { register list_elem *elem ; vprint("%s: from %s to %s '%s'\n", new->t_name,new->t_in ? new->t_in : "(null)",new->t_out,new->t_prog) ; - vprint("\targs: ") ; prns(new->t_argd) ; + vprint("\targs: %s",new->t_argd) ; scanlist( l_first(new->t_mapf), elem ) { vprint("\t%s\n",l_content(*elem)) ; } @@ -264,8 +255,7 @@ static FILE *infile ; static char *inptr ; char *em_dir = EM_DIR; -void -open_in(name) register char *name ; { +static void open_in(char *name) { register dmach *cmac ; gr_init(&rline) ; @@ -298,12 +288,12 @@ open_in(name) register char *name ; { } } -close_in() { +static void close_in(void) { if ( !incore ) fclose(infile) ; gr_throw(&rline) ; } -char *readline() { +static char *readline(void) { /* Get a line from the input, return 0 if at end, The line is stored in a volatile buffer, @@ -355,7 +345,7 @@ char *readline() { } } -int getinchar() { +static int getinchar(void) { register int token ; if ( incore ) { @@ -369,7 +359,7 @@ int getinchar() { return token ; } -int getln() { +static int getln(void) { register char *c_ptr ; do { diff --git a/util/ack/run.c b/util/ack/run.c index 8d0481a58..32cb59fe5 100644 --- a/util/ack/run.c +++ b/util/ack/run.c @@ -5,6 +5,7 @@ */ #include +#include #include #include "ack.h" #include "list.h" @@ -19,19 +20,18 @@ static char rcs_id[] = "$Id$" ; #define ARG_MORE 40 /* The size of args chunks to allocate */ -extern growstring scanvars(); +static int run_exec(trf *, const char *); +static void x_arg(char *); static char **arglist ; /* The first argument */ static unsigned argcount ; /* The current number of arguments */ static unsigned argmax; /* The maximum number of arguments so far */ -int runphase(phase) register trf *phase ; { +int runphase(trf *phase) { register list_elem *elem ; - char *prog ; int result ; - growstring bline ; + char *prog ; int result ; - bline=scanvars(phase->t_prog) ; - prog=gr_final(&bline) ; + prog=phase->t_prog ; if ( v_flag || debug ) { if ( v_flag==1 && !debug ) { vprint("%s",phase->t_name) ; @@ -65,16 +65,19 @@ int runphase(phase) register trf *phase ; { x_arg(l_content(*elem)) ; } x_arg( (char *)0 ) ; - result=run_exec(phase,prog) ; - throws(prog) ; - return result ; + result=run_exec(phase,prog) ; + return result ; } -int run_exec(phase,prog) trf *phase ; char *prog ; { +static int run_exec(trf *phase, const char *prog) { int status, child, waitchild ; - do_flush(); - while ( (child=fork())== -1 ) ; + fflush(stdout) ; + fflush(stderr) ; + child= fork() ; + if ( child== - 1) { + fatal("Cannot fork %s", prog) ; + } if ( child ) { /* The parent */ do { @@ -84,8 +87,6 @@ int run_exec(phase,prog) trf *phase ; char *prog ; { } } while ( waitchild!=child) ; if ( status ) { - if ( status&0200 && (status&0177)!=SIGQUIT && - t_flag<=1 ) unlink("core") ; switch ( status&0177 ) { case 0 : break ; @@ -136,7 +137,7 @@ int run_exec(phase,prog) trf *phase ; char *prog ; { /*NOTREACHED*/ } -x_arg(string) char *string ; { +static void x_arg(char *string) { /* Add one execute argument to the argument vector */ if ( argcount==argmax ) { if ( argmax==0 ) { diff --git a/util/ack/scan.c b/util/ack/scan.c index d020e6a5b..3aaab8492 100644 --- a/util/ack/scan.c +++ b/util/ack/scan.c @@ -15,9 +15,14 @@ static char rcs_id[] = "$Id$" ; #endif -void try(); +static void start_scan(void); +static void try(list_elem *, const char *); +static void scan_found(void); +static int satisfy(trf *, const char *); +static enum f_path scan_end(trf **); +static void find_cpp(void); -enum f_path getpath(first) register trf **first ; { +enum f_path getpath(trf **first) { /* Try to find a transformation path */ start_scan(); @@ -49,7 +54,7 @@ static int suf_found; /* Was the suffix at least recognized ? */ /******************** The hard work ********************/ -start_scan() { +static void start_scan(void) { register list_elem *scan ; scanlist(l_first(tr_list),scan) { @@ -63,8 +68,7 @@ start_scan() { last_ocount= 0 ; } -void -try(f_scan,suffix) list_elem *f_scan; char *suffix; { +static void try(list_elem *f_scan, const char *suffix) { register list_elem *scan ; register trf *trafo ; /* Try to find a transformation path starting at f_scan for a @@ -134,7 +138,7 @@ try(f_scan,suffix) list_elem *f_scan; char *suffix; { } } -scan_found() { +static void scan_found(void) { register list_elem *scan; int ncount, ocount, pcount ; @@ -182,7 +186,7 @@ scan_found() { } } -int satisfy(trafo,suffix) register trf *trafo; char *suffix ; { +static int satisfy(trf *trafo, const char *suffix) { register char *f_char, *l_char ; /* Check whether this transformation is present for the current machine and the parameter suffix is among @@ -207,7 +211,7 @@ int satisfy(trafo,suffix) register trf *trafo; char *suffix ; { return 0 ; } -enum f_path scan_end(first) trf **first ; { /* Finalization */ +static enum f_path scan_end(trf **first) { /* Finalization */ /* Return value indicating whether a transformation was found */ /* Set the flags for the transformation up to, but not including, the combiner @@ -248,7 +252,7 @@ enum f_path scan_end(first) trf **first ; { /* Finalization */ return F_OK ; } -find_cpp() { +static void find_cpp(void) { register list_elem *elem ; scanlist( l_first(tr_list), elem ) { if ( t_cont(*elem)->t_isprep ) { diff --git a/util/ack/svars.c b/util/ack/svars.c index 2d7e4b42c..e540e5d02 100644 --- a/util/ack/svars.c +++ b/util/ack/svars.c @@ -4,6 +4,7 @@ * */ +#include #include "ack.h" #ifndef NORCSID @@ -44,9 +45,6 @@ static char rcs_id[] = "$Id$" ; */ -extern char *getcore(); -extern fatal(); - struct vars { char *v_name; enum { routine, string } v_type; @@ -60,7 +58,7 @@ struct vars { static struct vars *v_first ; -static struct vars *newvar(name) char *name; { +static struct vars *newvar(char *name) { register struct vars *new ; for ( new=v_first ; new ; new= new->v_next ) { @@ -72,36 +70,36 @@ static struct vars *newvar(name) char *name; { return new ; } } - new= (struct vars *)getcore( (unsigned)sizeof (struct vars)); + new= (struct vars *)getcore(sizeof (struct vars)); new->v_name= name ; new->v_next= v_first ; v_first= new ; return new ; } -setsvar(name,str) char *name, *str ; { +void setsvar(char *name, char *str) { register struct vars *new ; new= newvar(name); #ifdef DEBUG - if ( debug>=2 ) vprint("%s=%s\n", name, str) ; + if ( debug>=2 ) vprint("%s=%s\n", new->v_name, str) ; #endif new->v_type= string; new->v_value.v_string= str; } -setpvar(name,rout) char *name, *(*rout)() ; { +void setpvar(char *name, char *(*rout)(void)) { register struct vars *new ; new= newvar(name); #ifdef DEBUG - if ( debug>=2 ) vprint("%s= (*%o)()\n",name,rout) ; + if ( debug>=2 ) vprint("%s= (*%o)()\n", new->v_name, rout) ; #endif new->v_type= routine; new->v_value.v_routine= rout; } -char *getvar(name) char *name ; { +char *getvar(const char *name) { register struct vars *scan ; for ( scan=v_first ; scan ; scan= scan->v_next ) { diff --git a/util/ack/trans.c b/util/ack/trans.c index 3cb2d7ea8..98a75a066 100644 --- a/util/ack/trans.c +++ b/util/ack/trans.c @@ -26,13 +26,17 @@ static int touch_head= NO ; static growstring tail ; static int touch_tail= NO ; -char *headvar(),*tailvar() ; +static char *headvar(void); +static char *tailvar(void); +static void set_Rflag(char *); +static void condit(growstring *, list_head *, list_head *, char *); +static int mapflag(list_head *, const char *); +static int mapexpand(char *, const char *); +static void getcallargs(trf *); +static growstring without_bslash(const char *); +static void getprogram(trf *); -void condit(); -void doassign(); -void set_Rflag(); - -int transform(phase) register trf *phase ; { +int transform(trf *phase) { int ok ; if ( !setfiles(phase) ) { @@ -40,17 +44,19 @@ int transform(phase) register trf *phase ; { return 0 ; } getcallargs(phase) ; + getprogram(phase) ; ok= runphase(phase) ; if ( !ok ) rmfile(&out) ; /* Free the space occupied by the arguments, except for the linker, since we are bound to exit soon and do not foresee further need of memory space */ - if ( !phase->t_linker ) discardargs(phase) ; + if ( !phase->t_linker ) + l_throw(&phase->t_args) ; disc_files(phase) ; return ok ; } -getmapflags(phase) register trf *phase ; { +void getmapflags(trf *phase) { register path *l_in ; register list_elem *elem ; int scanned ; @@ -75,8 +81,9 @@ getmapflags(phase) register trf *phase ; { scanlist(l_first(phase->t_inputs),elem) { l_in = p_cont(*elem) ; if ( mapflag(&(phase->t_mapf),l_in->p_path) ) { - ptr= keeps(getvar(LIBVAR)) ; - clr_noscan(ptr) ; + growstring temp; + temp= without_bslash(getvar(LIBVAR)) ; + ptr= gr_final(&temp); #ifdef DEBUG if ( debug >=4 ) { vprint("phase %s, library %s(%s)\n", @@ -110,16 +117,12 @@ getmapflags(phase) register trf *phase ; { } -do_Rflag(argp) char *argp ; { - l_add(&R_list,argp) ; -} - -char *headvar() { +static char *headvar(void) { if ( !touch_head) return "" ; return gr_start(head) ; } -add_head(str) char *str; { +void add_head(const char *str) { if ( !touch_head) { gr_init(&head) ; touch_head=YES ; @@ -127,12 +130,12 @@ add_head(str) char *str; { gr_cat(&head,str) ; } -char *tailvar() { +static char *tailvar(void) { if ( !touch_tail ) return "" ; return gr_start(tail) ; } -add_tail(str) char *str ; { +void add_tail(const char *str) { if ( !touch_tail ) { gr_init(&tail) ; touch_tail=YES ; @@ -141,7 +144,7 @@ add_tail(str) char *str ; { } -transini() { +void transini(void) { register list_elem *elem ; register trf *phase ; @@ -157,8 +160,7 @@ transini() { setpvar(keeps(TAIL),tailvar) ; } -void -set_Rflag(argp) register char *argp ; { +static void set_Rflag(char *argp) { register char *eos ; register list_elem *prog ; register int length ; @@ -206,72 +208,47 @@ set_Rflag(argp) register char *argp ; { /* */ /**************************************************************************/ -growstring scanb(line) char *line ; { - /* Scan a line for backslashes, setting the NO_SCAN bit in characters - preceded by a backslash. - */ - register char *in_c ; - register int token ; - growstring result ; - enum { TEXT, ESCAPED } state = TEXT ; - - gr_init(&result) ; - for ( in_c= line ; *in_c ; in_c++ ) { - token= *in_c&0377 ; - switch( state ) { - case TEXT : - if ( token==BSLASH ) { - state= ESCAPED ; - } else { - gr_add(&result,token) ; - } - break ; - case ESCAPED : - gr_add(&result,token|NO_SCAN) ; - state=TEXT ; - break ; - } - } - gr_add(&result,0) ; - if ( state!=TEXT ) werror("flag line ends with %c",BSLASH) ; - return result ; -} - -growstring scanvars(line) char *line ; { +static growstring scanvars(const char *line) { /* Scan a line variable replacements started by S_VAR. - Two sequences exist: S_VAR name E_VAR, S_VAR name A_VAR text E_VAR. + Two sequences exist: S_VAR name C_VAR, S_VAR name A_VAR text C_VAR. neither name nor text may contain further replacements. In the first form an error message is issued if the name is not present in the variables, the second form produces text in that case. - The sequence S_VAR S_VAR is transformed into S_VAR. - This to allow later recognition in mapflags, where B_SLASH - would be preventing any recognition. */ - register char *in_c ; - register int token ; - growstring result ; - growstring name ; - register char *tr ; + const char *in_c ; + int token, token_r ; + growstring result, name ; + char *tr ; enum { TEXT, FIRST, NAME, SKIP, COPY } state = TEXT ; + int escaped = NO; gr_init(&result) ; gr_init(&name) ; for ( in_c= line ; *in_c ; in_c++ ) { token= *in_c&0377 ; + token_r= (escaped ? 0 : token); + + /* A backslash escapes the next character. */ + if ( token_r==BSLASH ) { + if ( state==TEXT || state==COPY ) { + /* Keep BSLASH for later scans. */ + gr_add(&result,token) ; + } + escaped= YES; + continue; + } + escaped= NO; + switch( state ) { case TEXT : - if ( token==S_VAR ) { + if ( token_r==S_VAR ) { state= FIRST ; } else { gr_add(&result,token) ; } break ; case FIRST : - switch ( token ) { - case S_VAR : - state= TEXT ; - gr_add(&result,token) ; - break ; + switch ( token_r ) { case A_VAR : case C_VAR : fatal("empty string variable name") ; @@ -282,7 +259,7 @@ growstring scanvars(line) char *line ; { } break ; case NAME: - switch ( token ) { + switch ( token_r ) { case A_VAR : gr_add(&name,0) ; if ( tr=getvar(gr_start(name)) ) { @@ -314,16 +291,17 @@ growstring scanvars(line) char *line ; { } break ; case SKIP : - if ( token==C_VAR ) state= TEXT ; + if ( token_r==C_VAR ) state= TEXT ; break ; case COPY : - if ( token==C_VAR ) state= TEXT ; else { + if ( token_r==C_VAR ) state= TEXT ; else { gr_add(&result,token) ; } break ; } } gr_add(&result,0) ; + if ( escaped ) werror("flag line ends with %c",BSLASH) ; if ( state!=TEXT ) { werror("flag line misses %c",C_VAR) ; gr_throw(&name) ; @@ -331,74 +309,84 @@ growstring scanvars(line) char *line ; { return result ; } -growstring scanexpr(line) char *line ; { +static growstring scanexpr(const char *line) { /* Scan a line for conditional or flag expressions, dependent on the type. The format is S_EXPR suflist M_EXPR suflist T_EXPR tail C_EXPR - the head and tail are passed to treat, together with the + the head and tail are passed to condit(), together with the growstring for futher treatment. Nesting is not allowed. */ - register char *in_c ; - char *heads ; - register int token ; - growstring sufs, tailval ; - growstring result ; + const char *in_c, *heads ; + int token, token_r ; + growstring sufs, tailval, result ; static list_head fsuff, lsuff ; enum { TEXT, FDOT, FSUF, LDOT, LSUF, FTAIL } state = TEXT ; + int escaped = NO; gr_init(&result) ; gr_init(&sufs) ; gr_init(&tailval) ; for ( in_c= line ; *in_c ; in_c++ ) { token= *in_c&0377 ; + token_r= (escaped ? 0 : token); + + /* A backslash escapes the next character. */ + if ( token_r==BSLASH ) { + if ( state==TEXT || state==FTAIL ) { + /* Keep BSLASH for later scans. */ + gr_add(&result,token) ; + } + escaped= YES; + continue; + } + escaped= NO; + switch( state ) { case TEXT : - if ( token==S_EXPR ) { + if ( token_r==S_EXPR ) { state= FDOT ; heads=in_c ; } else gr_add(&result,token) ; break ; case FDOT : - if ( token==M_EXPR ) { + if ( token_r==M_EXPR ) { state=LDOT ; break ; } - token &= ~NO_SCAN ; if ( token!=SUFCHAR ) { error("Missing %c in expression",SUFCHAR) ; } gr_add(&sufs,token) ; state=FSUF ; break ; case FSUF : - if ( token==M_EXPR || (token&~NO_SCAN)==SUFCHAR) { + if ( token_r==M_EXPR || token==SUFCHAR ) { gr_add(&sufs,0) ; l_add(&fsuff,gr_final(&sufs)) ; } - if ( token==M_EXPR ) { + if ( token_r==M_EXPR ) { state=LDOT ; - } else gr_add(&sufs,token&~NO_SCAN) ; + } else gr_add(&sufs,token) ; break ; case LDOT : - if ( token==T_EXPR ) { + if ( token_r==T_EXPR ) { state=FTAIL ; break ; } - token &= ~NO_SCAN ; if ( token!=SUFCHAR ) { error("Missing %c in expression",SUFCHAR) ; } gr_add(&sufs,token) ; state=LSUF ; break ; case LSUF : - if ( token==T_EXPR || (token&~NO_SCAN)==SUFCHAR) { + if ( token_r==T_EXPR || token==SUFCHAR) { gr_add(&sufs,0) ; l_add(&lsuff,gr_final(&sufs)) ; } - if ( token==T_EXPR ) { + if ( token_r==T_EXPR ) { state=FTAIL ; - } else gr_add(&sufs,token&~NO_SCAN) ; + } else gr_add(&sufs,token) ; break ; case FTAIL : - if ( token==C_EXPR ) { + if ( token_r==C_EXPR ) { /* Found one !! */ gr_add(&tailval,0) ; condit(&result,&fsuff,&lsuff,gr_start(tailval)) ; @@ -418,10 +406,8 @@ growstring scanexpr(line) char *line ; { return result ; } -void -condit(line,fsuff,lsuff,tailval) growstring *line ; - list_head *fsuff, *lsuff; - char *tailval ; +static void condit(growstring *line, list_head *fsuff, list_head *lsuff, + char *tailval) { register list_elem *first ; register list_elem *last ; @@ -446,7 +432,7 @@ condit(line,fsuff,lsuff,tailval) growstring *line ; #endif } -int mapflag(maplist,cflag) list_head *maplist ; char *cflag ; { +static int mapflag(list_head *maplist, const char *cflag) { /* Expand a flag expression */ /* The flag "cflag" is checked for each of the mapflags. A mapflag entry has the form @@ -468,12 +454,9 @@ int mapflag(maplist,cflag) list_head *maplist ; char *cflag ; { return 0 ; } -int mapexpand(mapentry,cflag) - char *mapentry, *cflag ; -{ - register char *star ; - register char *ptr ; - register char *space ; +static int mapexpand(char *mapentry, const char *cflag) { + const char *star ; + char *ptr, *space ; int length ; star=strchr(mapentry,STAR) ; @@ -510,10 +493,10 @@ int mapexpand(mapentry,cflag) return 1 ; } -void -doassign(line,star,length) char *line, *star ; { +void doassign(const char *line, const char *star, int length) { growstring varval, name, temp ; - register char *ptr ; + const char *ptr ; + int escaped = NO ; gr_init(&varval) ; gr_init(&name) ; @@ -528,12 +511,21 @@ doassign(line,star,length) char *line, *star ; { } temp= scanvars(ptr+1) ; for ( ptr=gr_start(temp); *ptr; ptr++ ) switch ( *ptr ) { + case BSLASH : + escaped= YES ; + gr_add(&varval,*ptr) ; + break ; case STAR : - if ( star ) { - while ( length-- ) gr_add(&varval,*star++|NO_SCAN) ; + if ( star && !escaped ) { + while ( length-- ) { + gr_add(&varval,BSLASH) ; + gr_add(&varval,*star++) ; + } break ; } + /* FALLTHROUGH */ default : + escaped= NO ; gr_add(&varval,*ptr) ; break ; } @@ -544,15 +536,16 @@ doassign(line,star,length) char *line, *star ; { #define ISBLANK(c) ( (c)==SPACE || (c)==TAB ) -unravel(line,action) char *line ; int (*action)() ; { +static void unravel(const char *line, void (*action)(char *)) { /* Unravel the line, get arguments a la shell */ /* each argument is handled to action */ /* The input string is left intact */ - register char *in_c ; - register int token ; - enum { BLANK, ARG } state = BLANK ; + const char *in_c ; + int token ; + enum { BLANK, ARG, ESCAPED } state = BLANK ; growstring argum ; + /* Loop for each character of line, including final '\0' */ in_c=line ; for (;;) { token= *in_c&0377 ; @@ -560,9 +553,13 @@ unravel(line,action) char *line ; int (*action)() ; { case BLANK : if ( token==0 ) break ; if ( !ISBLANK(token) ) { - state= ARG ; gr_init(&argum) ; - gr_add(&argum,token&~NO_SCAN) ; + gr_add(&argum,token) ; + if ( token == BSLASH ) { + state= ESCAPED ; + } else { + state= ARG ; + } } break ; case ARG : @@ -572,97 +569,106 @@ unravel(line,action) char *line ; int (*action)() ; { gr_throw(&argum) ; state=BLANK ; } else { - gr_add(&argum,token&~NO_SCAN) ; + gr_add(&argum,token) ; + if ( token == BSLASH ) state= ESCAPED ; } break ; + case ESCAPED : + gr_add(&argum,token) ; + state= ARG ; + break ; } if ( token == 0 ) break ; in_c++ ; } } -char *c_rep(string,place,rep) char *string, *place, *rep ; { - /* Produce a string in stable storage produced from 'string' - with the character at place replaced by rep - */ - growstring name ; - register char *nc ; - register char *xc ; - - gr_init(&name) ; - for ( nc=string ; *nc && ncp_path)) ; + gr_init(&argum); + for ( in_c= prefix1 ; *in_c ; in_c++ ) { + gr_add(&argum,*in_c) ; + } + for ( in_c= prefix2 ; *in_c ; in_c++ ) { + gr_add(&argum,*in_c) ; + } + for ( in_c= string ; *in_c ; in_c++ ) { + token= *in_c&0377 ; + if ( escaped ) { + /* Strip BSLASH, keep escaped character. */ + gr_add(&argum,token) ; + escaped= NO ; + continue; + } + switch ( token ) { + case BSLASH: + escaped= YES ; + break; + case C_IN: /* Input file */ + if ( in.p_path ) { /* Not for the combiners */ + for ( tr= in.p_path ; *tr; tr++ ) { + gr_add(&argum,*tr); } + } else { /* For the combiners */ + gr_add(&argum,0); + tr= gr_final(&argum); + in_c++; + scanlist( l_first(*comb_args), elem ) { + char *p = p_cont(*elem)->p_path ; + addargs3(tr,p,in_c) ; + } + throws(tr); + return; } - return ; - } - if ( in.p_path ) { /* Not for the combiners */ - temp=c_rep(string,repc,in.p_path) ; - addargs(temp) ; - throws(temp) ; - } else { /* For the combiners */ - scanlist( l_first(*comb_args), elem ) { - temp=c_rep(string,repc,p_cont(*elem)->p_path); - addargs(temp) ; - throws(temp) ; - } - } - return ; - } - repc=strchr(string,C_OUT) ; - if ( repc ) { - /* replace the outfile token as with the infile token */ + break; + case C_OUT: /* Output file */ #ifdef DEBUG - if ( !out.p_path ) fatal("missing output filename") ; + if ( !out.p_path ) fatal("missing output filename") ; #endif - temp=c_rep(string,repc,out.p_path) ; - addargs(temp) ; - throws(temp) ; - return ; + for ( tr= out.p_path ; *tr ; tr++ ) { + gr_add(&argum,*tr) ; + } + break; + default: + gr_add(&argum,token) ; + break; + } } - temp= keeps(string) ; - clr_noscan(temp) ; - l_add(curargs,temp) ; + gr_add(&argum,0) ; + tr= gr_final(&argum) ; + l_add(curargs,tr) ; } -getcallargs(phase) register trf *phase ; { +static void addargs(char *string) { + addargs3("", "", string) ; +} + +static void getcallargs(trf *phase) { growstring arg1, arg2 ; arg1= scanvars(phase->t_argd) ; #ifdef DEBUG - if ( debug>=3 ) { vprint("\tvars: ") ; prns(gr_start(arg1)) ; } + if ( debug>=3 ) vprint("\tvars: %s", gr_start(arg1)) ; #endif arg2= scanexpr(gr_start(arg1)) ; #ifdef DEBUG - if ( debug>=3 ) { vprint("\texpr: ") ; prns(gr_start(arg2)) ; } + if ( debug>=3 ) vprint("\texpr: %s", gr_start(arg2)) ; #endif gr_throw(&arg1) ; curargs= &phase->t_args ; @@ -671,6 +677,39 @@ getcallargs(phase) register trf *phase ; { gr_throw(&arg2) ; } -discardargs(phase) register trf *phase ; { - l_throw(&phase->t_args) ; +static growstring without_bslash(const char *string) { + /* Strip backslashes from a copy of the string. */ + growstring result; + const char *in_c ; + int token ; + int escaped = NO ; + + gr_init(&result) ; + for ( in_c= string ; *in_c ; in_c++ ) { + token= *in_c&0377 ; + if ( token==BSLASH && !escaped ) { + escaped= YES ; + } else { + gr_add(&result,token); + escaped= NO ; + } + } + gr_add(&result,0); + return result; +} + +static void getprogram(trf *phase) { + growstring prog1, prog2 ; + const char *in_c ; + int token ; + int escaped = NO ; + + /* Expand string variables in program name. */ + prog1= scanvars(phase->t_prog) ; + throws(phase->t_prog) ; + + /* Strip backslashes. */ + prog2= without_bslash(gr_start(prog1)); + gr_throw(&prog1); + phase->t_prog= gr_final(&prog2); } diff --git a/util/ack/trans.h b/util/ack/trans.h index 70be80832..54086a563 100644 --- a/util/ack/trans.h +++ b/util/ack/trans.h @@ -44,3 +44,26 @@ struct transform { } ; #define t_cont(elem) ((trf *)l_content(elem)) + +/* files.c */ +int setfiles(trf *); +void disc_files(trf *); +void disc_inputs(trf *); +void rmfile(path *); +void rmtemps(void); +void add_input(path *, trf *); + +/* run.c */ +int runphase(trf *); + +/* scan.c */ +enum f_path { F_OK, F_NOMATCH, F_NOPATH } ; +enum f_path getpath(trf **); + +/* trans.c */ +int transform(trf *); +void getmapflags(trf *); +void add_head(const char *); +void add_tail(const char *); +void transini(void); +void doassign(const char *, const char *, int); diff --git a/util/ack/util.c b/util/ack/util.c index 419f087e3..b3754f28e 100644 --- a/util/ack/util.c +++ b/util/ack/util.c @@ -32,15 +32,11 @@ extern int n_error; # define STDOUT stderr #endif -void fuerror(const char* fmt, ...); -void werror(const char* fmt, ...); - -char *basename(string) char *string ; { +char *ack_basename(const char *string) { static char retval[256] ; - char *last_dot, *last_start ; - register char *store; - register char *fetch ; - register int ctoken ; + const char *last_dot, *last_start, *fetch ; + char *store ; + int ctoken ; last_dot= (char *)0 ; last_start= string ; @@ -50,9 +46,6 @@ char *basename(string) char *string ; { case '/' : last_start=fetch+1 ; break ; case 0 : goto out ; } - if ( !isascii(ctoken) || !isprint(ctoken) ) { - werror("non-ascii characters in argument %s",string) ; - } } out: if ( ! *last_start ) fuerror("empty filename \"%s\"",string) ; @@ -65,21 +58,14 @@ out: return retval ; } -clr_noscan(str) char *str ; { - register char *ptr ; - for ( ptr=str ; *ptr ; ptr++ ) { - *ptr&= ~NO_SCAN ; - } -} - -char *skipblank(str) char *str ; { +char *skipblank(char *str) { register char *ptr ; for ( ptr=str ; *ptr==SPACE || *ptr==TAB ; ptr++ ) ; return ptr ; } -char *firstblank(str) char *str ; { +char *firstblank(char *str) { register char *ptr ; for ( ptr=str ; *ptr && *ptr!=SPACE && *ptr!=TAB ; ptr++ ) ; @@ -109,15 +95,6 @@ void vprint(const char* fmt, ...) va_end(ap); } -#ifdef DEBUG -prns(s) register char *s ; { - for ( ; *s ; s++ ) { - putc((*s&0377)&~NO_SCAN,STDOUT) ; - } - putc('\n',STDOUT) ; -} -#endif - /* VARARGS1 */ void fuerror(const char *fmt, ...) { /* Fatal user error */ @@ -153,48 +130,36 @@ void error(const char *fmt, ...) { va_end(ap); } -do_flush() { - fflush(stdout) ; - fflush(stderr) ; -} - -void -noodstop() { - quit(-3) ; -} - -quit(code) { +void quit(int code) { rmtemps(); exit(code); } + /****** char *keeps(string) Keep the string in stable storage. throws(string) Remove the string stored by keep from stable storage. + throws() is now a macro in ack.h. ***********/ -char *keeps(str) char *str ; { +char *keeps(const char *str) { register char *result ; result= getcore( (unsigned)(strlen(str)+1) ) ; if ( !result ) fatal("Out of core") ; return strcpy(result,str) ; } -throws(str) char *str ; { - freecore(str) ; -} - -char *getcore(size) unsigned size ; { - register char *retptr ; +void *getcore(size_t size) { + void *retptr ; retptr= calloc(1,size) ; if ( !retptr ) fatal("Out of memory") ; return retptr ; } -char *changecore(ptr,size) char *ptr ; unsigned size ; { - register char *retptr ; +void *changecore(void *ptr, size_t size) { + void *retptr ; retptr= realloc(ptr,size) ; if ( !retptr ) fatal("Out of memory") ;