1*48305Sbostic /*-
2*48305Sbostic * Copyright (c) 1989 The Regents of the University of California.
336932Sdonn * All rights reserved.
436932Sdonn *
5*48305Sbostic * %sccs.include.redist.c%
636932Sdonn */
736932Sdonn
836932Sdonn #ifndef lint
936932Sdonn char copyright[] =
10*48305Sbostic "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
1136932Sdonn All rights reserved.\n";
1236932Sdonn #endif /* not lint */
1336932Sdonn
1436932Sdonn #ifndef lint
15*48305Sbostic static char sccsid[] = "@(#)mktab.c 5.2 (Berkeley) 04/18/91";
1636932Sdonn #endif /* not lint */
1736932Sdonn
1836932Sdonn /*
1936932Sdonn * mktab.c
2036932Sdonn *
2136932Sdonn * Function: Build nroff terminal tables in a compiler-independent way.
2236932Sdonn * Usage: cc -Itroff mktab.c tabnnn.c -o mktab; mktab > tabnnn
2336932Sdonn * Date: Sat Feb 25 00:10:06 MST 1989
2436932Sdonn * Author: Donn Seeley
2536932Sdonn * Remarks:
2636932Sdonn * Traditional nroff terminal table construction works by compiling
2736932Sdonn * a C file into a binary that is read directly into nroff as it runs.
2836932Sdonn * If your C compiler or your relocation format differ from what nroff
2936932Sdonn * expects, you lose. This program, when linked with a terminal table
3036932Sdonn * object file, fakes up an 'object' file that looks enough like the
3136932Sdonn * traditional one to fool nroff.
3236932Sdonn */
3336932Sdonn
3436932Sdonn #include <stdio.h>
3536932Sdonn #include "tw.h"
3636932Sdonn
main()3736932Sdonn main()
3836932Sdonn {
3936932Sdonn static struct fake_exec {
4036932Sdonn int bogus[8]; /* bogus[2] == a_data */
4136932Sdonn } fe;
4236932Sdonn register int *bip;
4336932Sdonn register char **tip;
4436932Sdonn register int offset = sizeof t;
4536932Sdonn int buf[sizeof t / sizeof (int)];
4636932Sdonn char *malloc();
4736932Sdonn int twbase = (int *) &t.twinit - &t.bset;
4836932Sdonn
4936932Sdonn /*
5036932Sdonn * Copy the integers at the start of the table.
5136932Sdonn */
5236932Sdonn bcopy((char *) &t, (char *) buf, twbase * sizeof (int));
5336932Sdonn
5436932Sdonn /*
5536932Sdonn * Replace the character pointers in the copy with integer offsets.
5636932Sdonn * This duplicates the effect of relocation offsets.
5736932Sdonn * Take care to count the possibly null control bytes in the codetab
5836932Sdonn * section.
5936932Sdonn */
6036932Sdonn for (bip = &buf[twbase], tip = &t.twinit;
6136932Sdonn tip < &t.codetab[0];
6236932Sdonn ++bip, ++tip)
6336932Sdonn if (*tip) {
6436932Sdonn *bip = offset;
6536932Sdonn offset += strlen(*tip) + 1;
6636932Sdonn } else
6736932Sdonn *bip = 0;
6836932Sdonn for (; tip < &t.zzz; ++bip, ++tip)
6936932Sdonn if (*tip) {
7036932Sdonn *bip = offset;
7136932Sdonn offset += strlen(*tip + 1) + 2;
7236932Sdonn } else
7336932Sdonn *bip = 0;
7436932Sdonn
7536932Sdonn /*
7636932Sdonn * Patch in a fake data segment size field.
7736932Sdonn */
7836932Sdonn fe.bogus[2] = offset;
7936932Sdonn
8036932Sdonn /*
8136932Sdonn * Dump the header and the table.
8236932Sdonn */
8336932Sdonn (void) fwrite((char *) &fe, sizeof fe, 1, stdout);
8436932Sdonn (void) fwrite((char *) buf, sizeof t, 1, stdout);
8536932Sdonn
8636932Sdonn /*
8736932Sdonn * Dump the strings.
8836932Sdonn */
8936932Sdonn for (tip = &t.twinit; tip < &t.codetab[0]; ++tip)
9036932Sdonn if (*tip) {
9136932Sdonn fputs(*tip, stdout);
9236932Sdonn putchar('\0');
9336932Sdonn }
9436932Sdonn for (tip = &t.codetab[0]; tip < &t.zzz; ++tip)
9536932Sdonn if (*tip) {
9636932Sdonn putchar(**tip);
9736932Sdonn fputs(*tip + 1, stdout);
9836932Sdonn putchar('\0');
9936932Sdonn }
10036932Sdonn
10136932Sdonn return 0;
10236932Sdonn }
103