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".
15 static char rcs_id[] = "$Id: files.c,v 2.7 1994/06/24 10:12:37 ceriel Exp $" ;
18 char *add_u(part,ptr) char *ptr ; {
20 ptr=add_u(part/26-1,ptr) ;
27 /* Get the next unique part of the internal filename */
28 static int u_next = 0 ;
32 ptr=add_u(u_next,buf) ;
38 setfiles(phase) register trf *phase ; {
39 /* Set the out structure according to the in structure,
40 the transformation and some global data */
42 register list_elem *elem ;
43 static int out_used= 0 ;
45 if ( !phase->t_next && !phase->t_isprep && outfile ) {
47 fuerror("only one output file allowed when using the -o flag") ;
49 if ( !phase->t_keep ) fatal("Removing result file") ;
50 phase->t_outfile=outfile ;
54 if ( phase->t_combine ) {
55 in.p_path= (char *)0 ;
59 if ( phase->t_outfile && phase->t_keep ) {
60 out.p_path=phase->t_outfile ;
65 if ( !phase->t_keep && !t_flag ) {
66 gr_cat(&pathname,TMP_DIR) ;
67 gr_cat(&pathname,"/") ;
68 gr_cat(&pathname,template) ;
69 gr_cat(&pathname,unique()) ;
73 gr_cat(&pathname,"Ack") ;
74 gr_cat(&pathname,unique()) ;
75 p_basename=keeps(gr_start(pathname)) ;
76 werror("Output written on %s%s",
77 p_basename,phase->t_out) ;
79 gr_cat(&pathname,p_basename) ;
83 gr_cat(&pathname,phase->t_out) ;
84 out.p_path= gr_final(&pathname) ;
87 scanlist( l_first(arguments), elem) {
88 if ( strcmp(l_content(*elem),out.p_path)==0 ) {
89 error("attempt to overwrite %s",out.p_path) ;
96 disc_files(phase) trf *phase ; {
99 if ( !phase->t_combine ) {
104 temp=in ; in=out ; out=temp ;
107 file_final(file) path *file ; {
108 if ( file->p_path ) {
109 if ( !file->p_keep && t_flag<=1 ) {
110 if ( unlink(file->p_path)!=0 ) {
111 werror("couldn't unlink %s",file->p_path);
114 if ( file->p_keeps ) throws(file->p_path) ;
116 file->p_path= (char *)0 ;
121 disc_inputs(phase) trf *phase ; {
122 /* Remove all the input files of this phase */
123 /* Only for combiners */
124 register path *l_in ;
125 register list_elem *elem ;
126 scanlist( l_first(phase->t_inputs), elem) {
127 l_in= p_cont(*elem) ;
129 freecore((char *)l_in) ;
131 l_clear(&phase->t_inputs) ;
134 rmfile(file) path *file ; {
135 /* Remove a file, do not complain when is does not exist */
136 if ( file->p_path ) {
137 if ( t_flag<=1 ) unlink(file->p_path) ;
138 if ( file->p_keeps ) throws(file->p_path) ;
139 file->p_path= (char *)0 ;
146 /* Called in case of disaster, always remove the current output file!
148 register list_elem *elem ;
150 if ( t_flag>1 ) return ;
153 scanlist(l_first(tr_list),elem) {
154 if ( t_cont(*elem)->t_combine && t_cont(*elem)->t_do ) {
155 disc_inputs(t_cont(*elem)) ;
160 add_input(file,phase) path *file ; trf *phase ; {
161 register path *store ;
164 vprint("Adding %s to inputs of %s\n",
165 file->p_path,phase->t_name) ;
169 if ( !phase->t_origname && orig.p_path[0]!='-' ) {
170 /* This entry decides the name of the result */
171 phase->t_origname= orig.p_path ;
173 store= (path *) getcore(sizeof (path)) ;
175 l_add(&phase->t_inputs,(char *)store) ;
176 /* The task of getting rid of the string is passed to 'phase',
177 as is the task to get rid of the file itself.
179 file->p_keeps=NO ; file->p_keep=YES ;