files.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. *
  4. * This product is part of the Amsterdam Compiler Kit.
  5. *
  6. * Permission to use, sell, duplicate or disclose this software must be
  7. * obtained in writing. Requests for such permissions may be sent to
  8. *
  9. * Dr. Andrew S. Tanenbaum
  10. * Wiskundig Seminarium
  11. * Vrije Universiteit
  12. * Postbox 7161
  13. * 1007 MC Amsterdam
  14. * The Netherlands
  15. *
  16. */
  17. #include "ack.h"
  18. #include "list.h"
  19. #include "trans.h"
  20. #include "grows.h"
  21. #include "data.h"
  22. #include "../../h/em_path.h"
  23. #ifndef NORCSID
  24. static char rcs_id[] = "$Header$" ;
  25. #endif
  26. setfiles(phase) register trf *phase ; {
  27. /* Set the out structure according to the in structure,
  28. the transformation and some global data */
  29. growstring pathname ;
  30. register list_elem *elem ;
  31. if ( phase->t_combine ) {
  32. out.p_keep=YES ;
  33. out.p_path=outfile ;
  34. out.p_keeps=NO ;
  35. in.p_path= (char *)0 ;
  36. in.p_keep=YES ;
  37. in.p_keeps=NO ;
  38. } else {
  39. gr_init(&pathname) ;
  40. if ( !phase->t_keep && !t_flag ) {
  41. gr_cat(&pathname,TMP_DIR) ;
  42. gr_cat(&pathname,"/") ;
  43. gr_cat(&pathname,template) ;
  44. out.p_keep=NO ;
  45. } else {
  46. gr_cat(&pathname,p_basename) ;
  47. out.p_keep=YES ;
  48. }
  49. gr_cat(&pathname,phase->t_out) ;
  50. out.p_path= gr_final(&pathname) ;
  51. out.p_keeps= YES ;
  52. }
  53. scanlist( l_first(arguments), elem) {
  54. if ( strcmp(l_content(*elem),out.p_path)==0 ) {
  55. error("attempt to overwrite argument file") ;
  56. return 0 ;
  57. }
  58. }
  59. return 1 ;
  60. }
  61. disc_files() {
  62. if ( in.p_path ) {
  63. if ( !in.p_keep ) {
  64. if ( unlink(in.p_path)!=0 ) {
  65. werror("couldn't unlink %s",in.p_path);
  66. }
  67. }
  68. if ( in.p_keeps ) throws(in.p_path) ;
  69. }
  70. in=out ;
  71. out.p_path= (char *)0 ;
  72. out.p_keeps=NO ;
  73. out.p_keep=NO ;
  74. }
  75. rmtemps() {
  76. /* Called in case of disaster, always remove the current output file!
  77. */
  78. if ( out.p_path ) {
  79. unlink(out.p_path) ;
  80. if ( out.p_keeps ) throws(out.p_path) ;
  81. out.p_path= (char *)0 ;
  82. out.p_keeps=NO ;
  83. out.p_keep=NO ;
  84. }
  85. if ( !in.p_keep && in.p_path ) {
  86. unlink(in.p_path) ;
  87. if ( in.p_keeps ) throws(in.p_path) ;
  88. in.p_path= (char *)0 ;
  89. out.p_keeps= NO ;
  90. out.p_keep=NO ;
  91. }
  92. }