ack/util/opt/cleanup.c

59 lines
1.4 KiB
C
Raw Permalink Normal View History

/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
* Author: Hans van Staveren
*/
#include <assert.h>
1984-05-17 13:42:36 +00:00
#include <stdio.h>
#include "param.h"
#include "types.h"
#include <em_pseu.h>
#include <em_spec.h>
#include <em_mes.h>
1984-05-17 13:42:36 +00:00
#include "lookup.h"
#include "putline.h"
#include "util.h"
1984-05-17 13:42:36 +00:00
#include "ext.h"
void cleanup(void)
{
1984-05-17 13:42:36 +00:00
FILE *infile;
register int c;
register sym_p *spp, sp;
1984-05-17 13:42:36 +00:00
for (spp = symhash; spp < &symhash[NSYMHASH]; spp++)
for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
if ((sp->s_flags & SYMOUT) == 0)
outdef(sp);
if (!Lflag)
1984-05-17 13:42:36 +00:00
return;
c = fclose(outfile);
1984-05-17 13:42:36 +00:00
assert(c != EOF);
outfile = stdout;
2022-07-17 11:01:11 +00:00
infile = fopen(tempname, "rb");
1984-05-17 13:42:36 +00:00
if (infile == NULL)
error("temp file disappeared");
outshort(sp_magic);
/* Attempt to first output the word_size message */
while ((c = getc(infile)) != sp_cend && c != EOF)
{
putc(c, outfile);
}
if (c == sp_cend)
putc(c, outfile);
1984-05-17 13:42:36 +00:00
outinst(ps_mes);
outint(ms_ext);
for (spp = symhash; spp < &symhash[NSYMHASH]; spp++)
1984-05-17 13:42:36 +00:00
for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
if ((sp->s_flags & (SYMDEF | SYMGLOBAL)) == (SYMDEF | SYMGLOBAL))
1984-05-17 13:42:36 +00:00
outsym(sp);
putc(sp_cend, outfile);
while ((c = getc(infile)) != EOF)
putc(c, outfile);
c = fclose(infile);
1984-05-17 13:42:36 +00:00
assert(c != EOF);
c = remove(tempname);
1984-05-17 13:42:36 +00:00
assert(c == 0);
}