1 - The names of temporary files are now Ack'hex''unique'.'suffix'.

'hex' is the pid of the current invocation of ack in hex.
    'unique' is a tail unique to this invocation.
2 - The outfile field is used to indicate default naming, can be ovrrriden
    by the -o flag.
3 - Added handling for phases with multiple inputs (ego, linker).
This commit is contained in:
keie 1984-09-10 16:33:03 +00:00
parent 6eda6ac320
commit 31f96c6850

View file

@ -26,25 +26,57 @@
static char rcs_id[] = "$Header$" ; static char rcs_id[] = "$Header$" ;
#endif #endif
char *add_u(part,ptr) char *ptr ; {
if ( part>=26 ) {
ptr=add_u(part/26-1,ptr) ;
}
*ptr= part%26 + 'a' ;
return ptr+1 ;
}
char *unique() {
/* Get the next unique part of the internal filename */
static int u_next = 0 ;
static char buf[10] ;
register char *ptr ;
ptr=add_u(u_next,buf) ;
*ptr=0 ;
u_next++ ;
return buf ;
}
setfiles(phase) register trf *phase ; { setfiles(phase) register trf *phase ; {
/* Set the out structure according to the in structure, /* Set the out structure according to the in structure,
the transformation and some global data */ the transformation and some global data */
growstring pathname ; growstring pathname ;
register list_elem *elem ; register list_elem *elem ;
static int out_used= 0 ;
if ( !phase->t_next && !phase->t_isprep && outfile ) {
if ( out_used ) {
fuerror("only one output file allowed when using the -o flag") ;
} else {
if ( !phase->t_keep ) fatal("Removing result file") ;
phase->t_outfile=outfile ;
out_used++ ;
}
}
if ( phase->t_combine ) { if ( phase->t_combine ) {
out.p_keep=YES ;
out.p_path=outfile ;
out.p_keeps=NO ;
in.p_path= (char *)0 ; in.p_path= (char *)0 ;
in.p_keep=YES ; in.p_keep=YES ;
in.p_keeps=NO ; in.p_keeps=NO ;
}
if ( phase->t_outfile ) {
out.p_path=phase->t_outfile ;
out.p_keeps=NO ;
} else { } else {
gr_init(&pathname) ; gr_init(&pathname) ;
if ( !phase->t_keep && !t_flag ) { if ( !phase->t_keep && !t_flag ) {
gr_cat(&pathname,TMP_DIR) ; gr_cat(&pathname,TMP_DIR) ;
gr_cat(&pathname,"/") ; gr_cat(&pathname,"/") ;
gr_cat(&pathname,template) ; gr_cat(&pathname,template) ;
gr_cat(&pathname,unique()) ;
out.p_keep=NO ; out.p_keep=NO ;
} else { } else {
gr_cat(&pathname,p_basename) ; gr_cat(&pathname,p_basename) ;
@ -56,43 +88,94 @@ setfiles(phase) register trf *phase ; {
} }
scanlist( l_first(arguments), elem) { scanlist( l_first(arguments), elem) {
if ( strcmp(l_content(*elem),out.p_path)==0 ) { if ( strcmp(l_content(*elem),out.p_path)==0 ) {
error("attempt to overwrite argument file") ; error("attempt to overwrite %s",out.p_path) ;
return 0 ; return 0 ;
} }
} }
return 1 ; return 1 ;
} }
disc_files() { disc_files(phase) trf *phase ; {
if ( in.p_path ) { path temp ;
if ( !in.p_keep ) {
if ( unlink(in.p_path)!=0 ) { if ( !phase->t_combine ) {
werror("couldn't unlink %s",in.p_path); file_final(&in) ;
} else {
disc_inputs(phase) ;
}
temp=in ; in=out ; out=temp ;
}
file_final(file) path *file ; {
if ( file->p_path ) {
if ( !file->p_keep && t_flag<=1 ) {
if ( unlink(file->p_path)!=0 ) {
werror("couldn't unlink %s",file->p_path);
} }
} }
if ( in.p_keeps ) throws(in.p_path) ; if ( file->p_keeps ) throws(file->p_path) ;
}
file->p_path= (char *)0 ;
file->p_keeps=NO ;
file->p_keep=NO ;
}
disc_inputs(phase) trf *phase ; {
/* Remove all the input files of this phase */
/* Only for combiners */
register path *l_in ;
register list_elem *elem ;
scanlist( l_first(phase->t_inputs), elem) {
l_in= p_cont(*elem) ;
file_final(l_in) ;
freecore(l_in) ;
}
l_clear(&phase->t_inputs) ;
}
rmfile(file) 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) ;
if ( file->p_keeps ) throws(file->p_path) ;
file->p_path= (char *)0 ;
file->p_keeps=NO ;
file->p_keep=NO ;
} }
in=out ;
out.p_path= (char *)0 ;
out.p_keeps=NO ;
out.p_keep=NO ;
} }
rmtemps() { rmtemps() {
/* Called in case of disaster, always remove the current output file! /* Called in case of disaster, always remove the current output file!
*/ */
if ( out.p_path ) { register list_elem *elem ;
unlink(out.p_path) ;
if ( out.p_keeps ) throws(out.p_path) ; if ( t_flag>1 ) return ;
out.p_path= (char *)0 ; rmfile(&out) ;
out.p_keeps=NO ; file_final(&in) ;
out.p_keep=NO ; scanlist(l_first(tr_list),elem) {
} if ( t_cont(*elem)->t_combine && t_cont(*elem)->t_do ) {
if ( !in.p_keep && in.p_path ) { disc_inputs(t_cont(*elem)) ;
unlink(in.p_path) ; }
if ( in.p_keeps ) throws(in.p_path) ;
in.p_path= (char *)0 ;
out.p_keeps= NO ;
out.p_keep=NO ;
} }
} }
add_input(file,phase) path *file ; trf *phase ; {
register path *store ;
#ifdef DEBUG
if ( debug ) {
vprint("Adding %s to inputs of %s\n",
file->p_path,phase->t_name) ;
}
#endif
if ( !l_first(phase->t_inputs) ) {
/* This becomes the first entry in the input list */
phase->t_origname= orig.p_path ;
}
store= (path *) getcore(sizeof (path)) ;
*store = *file ;
l_add(&phase->t_inputs,(char *)store) ;
/* The task of getting rid of the string is passed to 'phase',
as is the task to get rid of the file itself.
*/
file->p_keeps=NO ; file->p_keep=YES ;
}