Pristine Ack-5.5
[Ack-5.5.git] / util / opt / cleanup.c
1 #ifndef NORCSID
2 static char rcsid[] = "$Id: cleanup.c,v 2.6 1994/06/24 10:39:49 ceriel Exp $";
3 #endif
4
5 #include <stdio.h>
6 #include "param.h"
7 #include "types.h"
8 #include "assert.h"
9 #include <em_pseu.h>
10 #include <em_spec.h>
11 #include <em_mes.h>
12 #include "lookup.h"
13 #include "ext.h"
14
15 /*
16  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
17  * See the copyright notice in the ACK home directory, in the file "Copyright".
18  *
19  * Author: Hans van Staveren
20  */
21
22
23 cleanup() {
24         FILE *infile;
25         register c;
26         register sym_p *spp,sp;
27
28         for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
29                 for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
30                         if ((sp->s_flags & SYMOUT) == 0)
31                                 outdef(sp);
32         if(!Lflag)
33                 return;
34         c=fclose(outfile);
35         assert(c != EOF);
36         outfile = stdout;
37         infile = fopen(template,"r");
38         if (infile == NULL)
39                 error("temp file disappeared");
40         outshort(sp_magic);
41         /* Attempt to first output the word_size message */
42         while ((c = getc(infile)) != sp_cend && c != EOF) {
43                 putc(c, outfile);
44         }
45         if (c == sp_cend) putc(c, outfile);
46         outinst(ps_mes);
47         outint(ms_ext);
48         for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
49                 for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
50                         if ((sp->s_flags&(SYMDEF|SYMGLOBAL)) == (SYMDEF|SYMGLOBAL))
51                                 outsym(sp);
52         putc(sp_cend,outfile);
53         while ( (c=getc(infile)) != EOF)
54                 putc(c,outfile);
55         c=fclose(infile);
56         assert(c != EOF);
57         c=unlink(template);
58         assert(c == 0);
59 }