1*36932Sdonn /* 2*36932Sdonn * Copyright (c) 1989 Regents of the University of California. 3*36932Sdonn * All rights reserved. 4*36932Sdonn * 5*36932Sdonn * Redistribution and use in source and binary forms are permitted 6*36932Sdonn * provided that the above copyright notice and this paragraph are 7*36932Sdonn * duplicated in all such forms and that any documentation, 8*36932Sdonn * advertising materials, and other materials related to such 9*36932Sdonn * distribution and use acknowledge that the software was developed 10*36932Sdonn * by the University of California, Berkeley. The name of the 11*36932Sdonn * University may not be used to endorse or promote products derived 12*36932Sdonn * from this software without specific prior written permission. 13*36932Sdonn * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*36932Sdonn * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*36932Sdonn * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*36932Sdonn */ 17*36932Sdonn 18*36932Sdonn #ifndef lint 19*36932Sdonn char copyright[] = 20*36932Sdonn "@(#) Copyright (c) 1989 Regents of the University of California.\n\ 21*36932Sdonn All rights reserved.\n"; 22*36932Sdonn #endif /* not lint */ 23*36932Sdonn 24*36932Sdonn #ifndef lint 25*36932Sdonn static char sccsid[] = "@(#)mktab.c 5.1 (Berkeley) 02/28/89"; 26*36932Sdonn #endif /* not lint */ 27*36932Sdonn 28*36932Sdonn /* 29*36932Sdonn * mktab.c 30*36932Sdonn * 31*36932Sdonn * Function: Build nroff terminal tables in a compiler-independent way. 32*36932Sdonn * Usage: cc -Itroff mktab.c tabnnn.c -o mktab; mktab > tabnnn 33*36932Sdonn * Date: Sat Feb 25 00:10:06 MST 1989 34*36932Sdonn * Author: Donn Seeley 35*36932Sdonn * Remarks: 36*36932Sdonn * Traditional nroff terminal table construction works by compiling 37*36932Sdonn * a C file into a binary that is read directly into nroff as it runs. 38*36932Sdonn * If your C compiler or your relocation format differ from what nroff 39*36932Sdonn * expects, you lose. This program, when linked with a terminal table 40*36932Sdonn * object file, fakes up an 'object' file that looks enough like the 41*36932Sdonn * traditional one to fool nroff. 42*36932Sdonn */ 43*36932Sdonn 44*36932Sdonn #include <stdio.h> 45*36932Sdonn #include "tw.h" 46*36932Sdonn 47*36932Sdonn main() 48*36932Sdonn { 49*36932Sdonn static struct fake_exec { 50*36932Sdonn int bogus[8]; /* bogus[2] == a_data */ 51*36932Sdonn } fe; 52*36932Sdonn register int *bip; 53*36932Sdonn register char **tip; 54*36932Sdonn register int offset = sizeof t; 55*36932Sdonn int buf[sizeof t / sizeof (int)]; 56*36932Sdonn char *malloc(); 57*36932Sdonn int twbase = (int *) &t.twinit - &t.bset; 58*36932Sdonn 59*36932Sdonn /* 60*36932Sdonn * Copy the integers at the start of the table. 61*36932Sdonn */ 62*36932Sdonn bcopy((char *) &t, (char *) buf, twbase * sizeof (int)); 63*36932Sdonn 64*36932Sdonn /* 65*36932Sdonn * Replace the character pointers in the copy with integer offsets. 66*36932Sdonn * This duplicates the effect of relocation offsets. 67*36932Sdonn * Take care to count the possibly null control bytes in the codetab 68*36932Sdonn * section. 69*36932Sdonn */ 70*36932Sdonn for (bip = &buf[twbase], tip = &t.twinit; 71*36932Sdonn tip < &t.codetab[0]; 72*36932Sdonn ++bip, ++tip) 73*36932Sdonn if (*tip) { 74*36932Sdonn *bip = offset; 75*36932Sdonn offset += strlen(*tip) + 1; 76*36932Sdonn } else 77*36932Sdonn *bip = 0; 78*36932Sdonn for (; tip < &t.zzz; ++bip, ++tip) 79*36932Sdonn if (*tip) { 80*36932Sdonn *bip = offset; 81*36932Sdonn offset += strlen(*tip + 1) + 2; 82*36932Sdonn } else 83*36932Sdonn *bip = 0; 84*36932Sdonn 85*36932Sdonn /* 86*36932Sdonn * Patch in a fake data segment size field. 87*36932Sdonn */ 88*36932Sdonn fe.bogus[2] = offset; 89*36932Sdonn 90*36932Sdonn /* 91*36932Sdonn * Dump the header and the table. 92*36932Sdonn */ 93*36932Sdonn (void) fwrite((char *) &fe, sizeof fe, 1, stdout); 94*36932Sdonn (void) fwrite((char *) buf, sizeof t, 1, stdout); 95*36932Sdonn 96*36932Sdonn /* 97*36932Sdonn * Dump the strings. 98*36932Sdonn */ 99*36932Sdonn for (tip = &t.twinit; tip < &t.codetab[0]; ++tip) 100*36932Sdonn if (*tip) { 101*36932Sdonn fputs(*tip, stdout); 102*36932Sdonn putchar('\0'); 103*36932Sdonn } 104*36932Sdonn for (tip = &t.codetab[0]; tip < &t.zzz; ++tip) 105*36932Sdonn if (*tip) { 106*36932Sdonn putchar(**tip); 107*36932Sdonn fputs(*tip + 1, stdout); 108*36932Sdonn putchar('\0'); 109*36932Sdonn } 110*36932Sdonn 111*36932Sdonn return 0; 112*36932Sdonn } 113