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".
6 static char rcsid[] = "$Id: write.c,v 3.6 1994/06/24 10:35:26 ceriel Exp $";
15 extern struct outhead outhead;
16 extern struct outsect outsect[];
28 * Open the output file according to the chosen strategy.
29 * Write away the header and section table: they will not change anymore.
33 register struct outhead *hd = &outhead;
37 wr_sect(outsect, hd->oh_nsect);
38 off_char = OFF_CHAR(*hd);
41 static struct outname *
45 static struct outname namebuf;
47 namebuf.on_foff = (long)0; /* No string name. */
48 namebuf.on_type = (S_MIN + sectindex) | S_SCT;
50 namebuf.on_valu = outsect[sectindex].os_base;
56 * Write out the symbol table and the section names.
60 register struct outname *name;
61 register int sectindex;
62 extern unsigned short NGlobals;
66 assert(!(flagword & SFLAG));
67 name = (struct outname *)address(ALLOGLOB, (ind_t)0);
68 namecpy(name, NGlobals, off_char);
69 wr_name(name, NGlobals);
70 wr_string(mems[ALLOGCHR].mem_base+1, NGChars);
73 for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++)
74 wrt_name(sectname(sectindex), 1);
77 wrt_emit(emit, sectindex, cnt)
83 wr_outsect(sectindex);
87 wrt_nulls(sectindex, cnt)
90 static char nullbuf[BUFSIZ];
92 wr_outsect(sectindex);
94 register int n = cnt >= BUFSIZ ? BUFSIZ : cnt;
95 wr_emit(nullbuf, (long)n);
100 wrt_name(name, writename)
101 register struct outname *name;
104 assert(!(flagword & SFLAG));
105 if (name->on_mptr != (char *)0) {
106 register long len = strlen(name->on_mptr) + 1;
108 wr_string(name->on_mptr, len);
109 name->on_foff = off_char;
112 name->on_foff = (long)0;
114 if (writename) wr_name(name, 1);