cleanup.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  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".
  4. *
  5. * Author: Hans van Staveren
  6. */
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include "param.h"
  10. #include "types.h"
  11. #include "assert.h"
  12. #include <em_pseu.h>
  13. #include <em_spec.h>
  14. #include <em_mes.h>
  15. #include "lookup.h"
  16. #include "ext.h"
  17. #include "putline.h"
  18. #include "util.h"
  19. void cleanup()
  20. {
  21. FILE *infile;
  22. int c;
  23. sym_p *spp,sp;
  24. for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
  25. for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
  26. if ((sp->s_flags & SYMOUT) == 0)
  27. outdef(sp);
  28. if(!Lflag)
  29. return;
  30. c=fclose(outfile);
  31. assert(c != EOF);
  32. outfile = stdout;
  33. infile = fopen(template,"r");
  34. if (infile == NULL)
  35. error("temp file disappeared");
  36. outshort(sp_magic);
  37. /* Attempt to first output the word_size message */
  38. while ((c = getc(infile)) != sp_cend && c != EOF) {
  39. putc(c, outfile);
  40. }
  41. if (c == sp_cend) putc(c, outfile);
  42. outinst(ps_mes);
  43. outint(ms_ext);
  44. for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
  45. for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
  46. if ((sp->s_flags&(SYMDEF|SYMGLOBAL)) == (SYMDEF|SYMGLOBAL))
  47. outsym(sp);
  48. putc(sp_cend,outfile);
  49. while ( (c=getc(infile)) != EOF)
  50. putc(c,outfile);
  51. c=fclose(infile);
  52. assert(c != EOF);
  53. c=unlink(template);
  54. assert(c == 0);
  55. }