Annotation of 43BSDReno/usr.bin/roff/nroff_term/mktab.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.