shocking@nswitgould.OZ (Stephen Hocking cc) (09/23/87)
Sometime ago, I posted a request for information on the above. I was swamped with help which was much appreciated, thanks guys and am now steaming along OK. Quite a few people offered to send me source to the programs that they had written, or had floating about from other people, and one person sent it without prompting. To all those people who sent requests for help when I got it, I've mailed a copy of the program to you. Share & Enjoy. Once again, thanks to all those people who helped. Stephen -- "Lay orf Arfur, 'e doesnt know wot 'es saying" UUCP.net: {ukc,uunet}!munnari!nswitgould.oz!shocking ACS.net: shocking@nswitgould.oz
shocking@nswitgould.OZ (Stephen Hocking cc) (10/01/87)
This message contains the shar file of the the programs to do all this stuff. Owing to the constant stream of requests for it after the initial burst, and the fact that mailers around the world have been choking on the size of the file when I've tried to send it to individuals, I've decided to post it here. Kre & Rich Salz will probably ream my bum for not posting it via *.sources, but that's the price of a quick & dirty fix :-). Share & Enjoy. #! /bin/sh # This is a shell archive. Remove anything before the "#! /bin/sh" line, # then unpack it by saving it in a file and typing "sh file." # # Wrapped by Roger March,,,,obiwan,open (roger) at obiwan on Fri Sep 18 10:38:39 1987 # # unpacks with default permissions # # Contents : nrofftab/README nrofftab/charlist nrofftab/elbat.c # nrofftab/tabXXX.c nrofftab/table.c nrofftab/table.doc nrofftab/term.5 # nrofftab/term.h nrofftab/Makefile # if `test ! -d nrofftab` then mkdir nrofftab echo "mkdir nrofftab" fi if `test ! -s nrofftab/README` then echo "x - nrofftab/README" cat > nrofftab/README << '@\Rogue\Monster\' There are two programs in this package. "table", written by Bruce Townsend with help from Ian Darwin, prepares an nroff driver table from a source file. "elbat", written by Matt Crawford and modified for USG UNIX by Bruce Townsend, is the inverse operation - it decompiles an nroff driver table, producing a source file. The Makefile should not need modification other than to add new names of terminal drivers, of the form "tabXXX" where "XXX" is a mnemonic for a terminal, e.g. tab450 for a Diablo 450 in 10-pitch mode. These names are added to the TABFILES definition in the Makefile. The format for Berkeley tab files is different and thus this package will not work on Berkely systems without substantial hacking. You may want to change CFLAGS, LDFLAGS, etc. to your taste or de-bugging preference. To compile the elbat program, type "make elbat". To de-compile a file, type "elbat /usr/lib/term/tabXXX > tabXXX.c" To compile a tabXXX file (say tab450), type "make tab450". Of course, you need the tab450.c source before you do this. Do NOT FORGET to include the tabXXX name in the TABFILES definition in the Makefile first. Be VERY CAREFULL with "make install" (try "make -n install first). Read the table.doc file and the term.5 man page for more info. I have updated the term.5 man page to reflect this program. IF YOU HAVE PROBLEMS... It is quite possible that some or all of the integers stored in the tabfile are long, not int. On our machine, long = int = 32 bits, so I do not know which is appropriate. Read the table.doc file for more info. Acknowledgements: Ian Darwin tested out the first (very buggy) version of this utility, and suggested many useful changes, including the introduction of the Makefile. Matt Crawford wrote the elbat program originally for Berkeley systems. -Bruce Townsend Voice Processing Applications, Bell-Northern Research, Ottawa, Ontario. Mail path: {utzoo, utcs, bnr-di, bnr-mtl}!bnr-vpa!bruce @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/README" fi if `test ! -s nrofftab/charlist` then echo "x - nrofftab/charlist" cat > nrofftab/charlist << '@\Rogue\Monster\' TABLE OF NROFF CHARACTER INPUT NAMES IN THE ORDER THEY APPEAR IN THE codetab[] TABLE (see term(5)) _______________ Name Number (Octal) _______________ <sp> 000 ! 001 " 002 # 003 $ 004 % 005 & 006 ' 007 ( 010 ) 011 * 012 + 013 , 014 - 015 . 016 / 017 0 020 1 021 2 022 3 023 4 024 5 025 6 026 7 027 8 030 9 031 : 032 ; 033 < 034 = 035 > 036 ? 037 @ 040 A 041 B 042 C 043 D 044 E 045 F 046 G 047 H 050 I 051 J 052 K 053 L 054 M 055 N 056 O 057 P 060 Q 061 R 062 S 063 T 064 U 065 V 066 W 067 X 070 Y 071 Z 072 [ 073 \ 074 ] 075 ^ 076 _ 077 ` 100 a 101 b 102 c 103 d 104 e 105 f 106 g 107 h 110 i 111 j 112 k 113 l 114 m 115 n 116 o 117 p 120 q 121 r 122 s 123 t 124 u 125 v 126 w 127 x 130 y 131 z 132 { 133 | 134 } 135 ~ 136 \| 137 \(hy 140 \(bu 141 \(sq 142 \(em 143 \(ru 144 \(14 145 \(12 146 \(34 147 \- 150 \(fi 151 \(fl 152 \(ff 153 \(Fi 154 \(Fl 155 \(de 156 \(dg 157 \(sc 160 \(fm 161 \(aa 162 \(ga 163 \(ul 164 \(sl 165 \^ 166 \<sp> 167 \(*a 170 \(*b 171 \(*g 172 \(*d 173 \(*e 174 \(*z 175 \(*y 176 \(*h 177 \(*i 200 \(*k 201 \(*l 202 \(*m 203 \(*n 204 \(*c 205 \(*o 206 \(*p 207 \(*r 210 \(*s 211 \(*t 212 \(*u 213 \(*f 214 \(*x 215 \(*q 216 \(*w 217 \(*G 220 \(*D 221 \(*H 222 \(*L 223 \(*C 224 \(*P 225 \(*S 226 \(*T 227 \(*U 230 \(*F 231 \(*Q 232 \(*W 233 \(sr 234 \(ts 235 \(rn 236 \(>= 237 \(<= 240 \(== 241 \(mi 242 \(~= 243 \(ap 244 \(!= 245 \(-> 246 \(<- 247 \(ua 250 \(da 251 \(eq 252 \(mu 253 \(di 254 \(+- 255 \(cu 256 \(ca 257 \(sb 260 \(sp 261 \(ib 262 \(ip 263 \(if 264 \(pd 265 \(gr 266 \(no 267 \(is 270 \(pt 271 \(es 272 \(mo 273 \(pl 274 \(rg 275 \(co 276 \(br 277 \(ct 300 \(dd 301 \(rh 302 \(lh 303 \(** 304 \(bs 305 \(or 306 \(ci 307 \(lt 310 \(lb 311 \(rt 312 \(rb 313 \(lk 314 \(rk 315 \(bv 316 \(lf 317 \(rf 320 \(lc 321 \(rc 322 @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/charlist" fi if `test ! -s nrofftab/elbat.c` then echo "x - nrofftab/elbat.c" cat > nrofftab/elbat.c << '@\Rogue\Monster\' /* elbat: a program to de-compile nroff drive tables so they can ** be fiddled with. ** ** usage: elbat tabXXX > tabXXX.c ** ** Matt Crawford, University of Chicago, 10 May 1984 ** ihnp4!oddjob!matt crawford@anl-mcs.arpa ** ** Modified by: Bruce Townsend, Bell Northern-Research, March 6 1985 ** - Changed for USG UNIX systems. ** */ #include <stdio.h> #include <ctype.h> #include <fcntl.h> #include "term.h" void loadtab(), vprint(); char *codelabel[] = { "space", "!", "\"", "#", "$", "%", "&", "' close", "(", ")", "*", "+", ",", "- hyphen", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_ dash", "` open", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "narrow sp", "hyphen", "bullet", "square", "3/4 em", "rule", "1/4", "1/2", "3/4", "minus", "fi", "fl", "ff", "ffi", "ffl", "degree", "dagger", "section", "foot mark", "acute accent", "grave accent", "underrule", "slash (longer)", "half narrow space", "unpaddable space", "alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega", "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Tau", "Upsilon", "Phi", "Psi", "Omega", "square root", "terminal sigma", "root en", ">=", "<=", "identically equal", "equation minus", "approx =", "approximates", "not equal", "right arrow", "left arrow", "up arrow", "down arrow", "eqn equals", "multiply", "divide", "plus-minus", "cup (union)", "cap (intersection)", "subset of", "superset of", "improper subset", " improper superset", "infinity", "pt deriv", "gradient", "not", "integral", "proportional to", "empty set", "member of", "equation plus", "registration mk", "copyright mk", "box rule", "cent sign", "dbl dagger", "right hand", "left hand", "math * ", "bell system sign", "or (was star)", "circle", "left top of big curly", "left bottom of big curly", "right top of big curly", "right bottom of big curly", "left center of big curly", "right center of big curly", "bold vertical rule", "left bottom of big bracket", "right bottom of big bracket", "left top of big bracket", "right top of big bracket", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", /* No idea what these are */ }; struct t t; struct t_stor t_stor; main(argc, argv) char **argv; { register int c; register char **endptr = &t.zzz; register FILE *twfp; char labelbuf[64]; if (argc != 2) { fprintf (stderr, "Usage: elbat tabXXX > tabXXX.c\n"); exit(1); } loadtab(argv[1]); if ( (twfp = fopen("term.h", "r")) == NULL ) { perror("term.h"); exit(1); } while ( (c = getc(twfp)) != EOF && c != /*{*/ '}') putc(c, stdout); fclose(twfp); printf(/*{*/ "} t = {\n" /*}*/); /* Stupid emacs! */ printf("/*bset */\t\t0%o,\n", t.bset); printf("/*breset */\t\t0%o,\n", t.breset); #define intshow(memb) \ printf("/*%-8s*/\t\t%d,\n", "memb", t.memb) intshow(Hor); intshow(Vert); intshow(Newline); intshow(Char); intshow(Em); intshow(Halfline); intshow(Adj); #define show(memb) \ printf("/*%-8s*/\t\t\"", "memb");\ vprint(t.memb);\ printf("\",\n") show(twinit); show(twrest); show(twnl); show(hlr); show(hlf); show(flr); show(bdon); show(bdoff); show(iton); show(itoff); show(ploton); show(plotoff); show(up); show(down); show(right); show(left); while ( **--endptr == '\0' ) ; for ( c = 0; c < 256-32 /* Not all 256-32 chars are in use */ && &t.codetab[c] <= endptr; c++ ) { sprintf(labelbuf, "/* %s */", codelabel[c]); printf("%-20s\t\"", labelbuf); if ( t.codetab[c][0] ) vprint(t.codetab[c]); else if ( t.codetab[c][1] ) { printf("\\000"); vprint(t.codetab[c]+1); } else printf("\\000\\0"); printf("\",\n"); } printf(/*{*/ "};\n"); exit(0); } void vprint(str) register char *str; { while ( str && *str ) { char c[5]; if ( isascii(*str) && isprint(*str) && *str != '\\' && *str != '"' ) { c[0] = *str; c[1] = '\0'; } else switch ( *str ) { case '\\': case '"': c[0] = '\\'; c[1] = *str; c[2] = '\0'; break; case '\b': strcpy(c, "\\b"); break; case '\t': strcpy(c, "\\t"); break; case '\n': strcpy(c, "\\n"); break; case '\r': strcpy(c, "\\r"); break; default: sprintf(c, "\\%03.3o", (int)*str & 0377); break; } fputs(c, stdout); str++; } } void loadtab( tname ) char *tname; { register int tfd; int c_size, *ip; register char **pp, *mptr; extern char *malloc(); if( (tfd=open(tname, O_RDONLY)) < 0 ) { perror( tname ); exit(1); } read(tfd, &c_size, sizeof(int)); read(tfd, &t_stor, sizeof(t_stor)); mptr = malloc (c_size); read(tfd, mptr, c_size); t.bset = t_stor.bset; t.breset = t_stor.breset; t.Hor = t_stor.Hor; t.Vert = t_stor.Vert; t.Newline = t_stor.Newline; t.Char = t_stor.Char; t.Em = t_stor.Em; t.Halfline = t_stor.Halfline; t.Adj = t_stor.Adj; ip = &t_stor.twinit; for ( pp = &t.twinit; pp < &t.zzz;) *pp++ = mptr + *ip++; } @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/elbat.c" fi if `test ! -s nrofftab/tabXXX.c` then echo "x - nrofftab/tabXXX.c" cat > nrofftab/tabXXX.c << '@\Rogue\Monster\' /* This is an example of a source file for an nroff driver table. * It is a very stripped down version of a Diablo 450 in 10 pitch. * The integer settings (bset - Adj) are correct for this terminal * but only ascii charcters and some simple special charcters are * included. Therefore, it is not intended as a source for a useful * driver table, but rather as a starting point so that you can * hack up your own. */ #include <termio.h> /* Req'd only for bset, breset */ #define INCH 240 struct { int bset; int breset; int Hor; int Vert; int Newline; int Char; int Em; int Halfline; int Adj; char *twinit; char *twrest; char *twnl; char *hlr; char *hlf; char *flr; char *bdon; char *bdoff; char *iton; char *itoff; char *ploton; char *plotoff; char *up; char *down; char *right; char *left; char *codetab[256-32]; char *zzz; } t = { /*bset */ 0, /*breset */ ONLCR | OCRNL | ONLRET, /*Hor */ INCH / 60, /*Vert */ INCH / 48, /*Newline */ INCH / 6, /*Char */ INCH / 10, /*Em */ INCH / 10, /*Halfline*/ INCH / 12, /*Adj */ INCH / 10, /*twinit */ "", /*twrest */ "", /*twnl */ "", /*hlr */ "", /*hlf */ "", /*flr */ "", /*bdon */ "", /*bdoff */ "", /*iton */ "", /*itoff */ "", /*ploton */ "", /*plotoff */ "", /*up */ "", /*down */ "", /*right */ "", /*left */ "", /* space */ "\001 ", /* ! */ "\001!", /* " */ "\001\"", /* # */ "\001#", /* $ */ "\001$", /* % */ "\001%", /* & */ "\001&", /* ' close */ "\001'", /* ( */ "\001(", /* ) */ "\001)", /* * */ "\001*", /* + */ "\001+", /* , */ "\001,", /* - hyphen */ "\001-", /* . */ "\001.", /* / */ "\001/", /* 0 */ "\2010", /* 1 */ "\2011", /* 2 */ "\2012", /* 3 */ "\2013", /* 4 */ "\2014", /* 5 */ "\2015", /* 6 */ "\2016", /* 7 */ "\2017", /* 8 */ "\2018", /* 9 */ "\2019", /* : */ "\001:", /* ; */ "\001;", /* < */ "\001<", /* = */ "\001=", /* > */ "\001>", /* ? */ "\001?", /* @ */ "\001@", /* A */ "\201A", /* B */ "\201B", /* C */ "\201C", /* D */ "\201D", /* E */ "\201E", /* F */ "\201F", /* G */ "\201G", /* H */ "\201H", /* I */ "\201I", /* J */ "\201J", /* K */ "\201K", /* L */ "\201L", /* M */ "\201M", /* N */ "\201N", /* O */ "\201O", /* P */ "\201P", /* Q */ "\201Q", /* R */ "\201R", /* S */ "\201S", /* T */ "\201T", /* U */ "\201U", /* V */ "\201V", /* W */ "\201W", /* X */ "\201X", /* Y */ "\201Y", /* Z */ "\201Z", /* [ */ "\001[", /* \ */ "\001\\", /* ] */ "\001]", /* ^ */ "\001^", /* _ dash */ "\001_", /* ` open */ "\001`", /* a */ "\201a", /* b */ "\201b", /* c */ "\201c", /* d */ "\201d", /* e */ "\201e", /* f */ "\201f", /* g */ "\201g", /* h */ "\201h", /* i */ "\201i", /* j */ "\201j", /* k */ "\201k", /* l */ "\201l", /* m */ "\201m", /* n */ "\201n", /* o */ "\201o", /* p */ "\201p", /* q */ "\201q", /* r */ "\201r", /* s */ "\201s", /* t */ "\201t", /* u */ "\201u", /* v */ "\201v", /* w */ "\201w", /* x */ "\201x", /* y */ "\201y", /* z */ "\201z", /* { */ "\001{", /* | */ "\001|", /* } */ "\001}", /* ~ */ "\001~", /* narrow sp */ "\000\0", /* hyphen */ "\001-", /* bullet */ "\000\0", /* square */ "\000\0", /* 3/4 em */ "\001-", /* rule */ "\001_", /* 1/4 */ "\0031/4", /* 1/2 */ "\0031/2", /* 3/4 */ "\0033/4", /* minus */ "\001-", /* fi */ "\202fi", /* fl */ "\202fl", /* ff */ "\202ff", /* ffi */ "\203ffi", /* ffl */ "\203ffl", /* degree */ "\000\0", /* dagger */ "\000\0", /* section */ "\000\0", /* foot mark */ "\000\0", /* acute accent */ "\000\0", /* grave accent */ "\000\0", /* underrule */ "\001_", /* slash (longer) */ "\001/", /* half narrow space */ "\000\0", /* unpaddable space */ "\001 ", /* alpha */ "\000\0", /* beta */ "\000\0", /* gamma */ "\000\0", /* epsilon */ "\000\0", /* zeta */ "\000\0", /* eta */ "\000\0", /* theta */ "\000\0", /* iota */ "\000\0", /* kappa */ "\000\0", /* lambda */ "\000\0", /* mu */ "\000\0", /* nu */ "\000\0", /* xi */ "\000\0", /* omicron */ "\000\0", /* pi */ "\000\0", /* rho */ "\000\0", /* sigma */ "\000\0", /* tau */ "\000\0", /* upsilon */ "\000\0", /* phi */ "\000\0", /* chi */ "\000\0", /* psi */ "\000\0", /* omega */ "\000\0", /* Gamma */ "\000\0", /* Delta */ "\000\0", /* Theta */ "\000\0", /* Lambda */ "\000\0", /* Xi */ "\000\0", /* Pi */ "\000\0", /* Sigma */ "\000\0", /* Tau */ "\000\0", /* Upsilon */ "\000\0", /* Phi */ "\000\0", /* Psi */ "\000\0", /* Omega */ "\000\0", /* square root */ "\000\0", /* terminal sigma */ "\000\0", /* root en */ "\000\0", /* >= */ "\000\0", /* <= */ "\000\0", /* identically equal */ "\000\0", /* equation minus */ "\000\0", /* approx = */ "\000\0", /* approximates */ "\000\0", /* not equal */ "\000\0", /* right arrow */ "\000\0", /* left arrow */ "\000\0", /* up arrow */ "\000\0", /* down arrow */ "\000\0", /* eqn equals */ "\000\0", /* multiply */ "\000\0", /* divide */ "\000\0", /* plus-minus */ "\000\0", /* cup (union) */ "\000\0", /* cap (intersection) */ "\000\0", /* subset of */ "\000\0", /* superset of */ "\000\0", /* improper subset */ "\000\0", /* improper superset */ "\000\0", /* infinity */ "\000\0", /* pt deriv */ "\000\0", /* gradient */ "\000\0", /* not */ "\000\0", /* integral */ "\000\0", /* proportional to */ "\000\0", /* empty set */ "\000\0", /* member of */ "\000\0", /* equation plus */ "\001+", /* registration mk */ "\000\0", /* copyright mk */ "\000\0", /* box rule */ "\001|", /* cent sign */ "\000\0", /* dbl dagger */ "\000\0", /* right hand */ "\000\0", /* left hand */ "\000\0", /* math * */ "\001*", /* bell system sign */ "\000\0", /* or (was star) */ "\001|", /* circle */ "\000\0", /* left top of big curly */ "\001|", /* left bottom of big curly */ "\001|", /* right top of big curly */ "\001|", /* right bottom of big curly */ "\001|", /* left center of big curly */ "\001|", /* right center of big curly */ "\001|", /* bold vertical rule */ "\001|", /* left bottom of big bracket */ "\001|", /* right bottom of big bracket */ "\001|", /* left top of big bracket */ "\001|", /* right top of big bracket */ "\001|", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", /* ??? */ "\000\0", }; @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/tabXXX.c" fi if `test ! -s nrofftab/table.c` then echo "x - nrofftab/table.c" cat > nrofftab/table.c << '@\Rogue\Monster\' /* * * TABLE - A PROGRAM TO PREPARE NROFF DRIVER TABLES * copyright (c) 1985 by Bruce Townsend and Bell-Northern Research. * Permission hereby granted to use, distribute, modify, or copy * except for profit, providing this disclaimer is included. * * The contributions of Ian Darwin (the Makefile, cleaning up the * code, etc) are gratefully acknowledged. * * Version 1.2 - * * The program has been substantially modified from version 1.1 * The major bug in version 1.1 was that zero-width characters * were not handled properly. This has been fixed. * * Please send bug reports to Bruce Townsend (utcs!bnr-vpa!bruce) * * Usage: * 1) Build a file tabXXX.c, where XXX is some reasonable * acronym for the terminal or printer you want to drive * (peruse existing names to see what's reasonable!). * Make this file by hacking up one of the existing * table entries. * 2) If the amount of char data that the structure * references is very large, you may want to redefine * C_SIZE * 3) check to see whether <sgtty.h> or <termio.h> should * be #included in the tabXXX.c file. One of these include * files may be necessary to provide settings for t.bset, * t.breset. This is instead of the previous tendency to code * octal magic numbers in these fields. * 4) Enter your new table into the Makefile; just add the * name "tabXXX" to the TABFILES definition. * 5) Type "make tabXXX" where tabXXX is the same name * you chose before. * 6) Locate the tabfile in the proper place (on our system * the directory is /usr/lib/term * * */ #define C_SIZE 10000 /* The maximum amount of character data allowed in the initialized structure t - increase if necessary */ #include <stdio.h> #include "term.h" /* This file contains the definition of the the structures t and t_stor */ /************* DO NOT ALTER ANYTHING AFTER THIS POINT ***************/ extern struct t t; struct t_stor t_stor; char c_data[C_SIZE]; char *c_pointer[256]; int c_length[256]; char *c_end = c_data; int n_strings, c_size; main (argc, argv) int argc; char *argv[]; { FILE *table; int i, j, i_len, j_len; char *tail, *start, *char_pointer, *strcpy(); if (argc != 2) { /* Need a file name argument */ fprintf (stderr, "Usage: table \"file\"\n"); exit (1); } /* Open the file */ if ((table = fopen (argv[1], "w")) == NULL) { fprintf (stderr, "File %s not opened for writing\n", argv[1]); exit (1); } /* Copy the integer values from the initialized structure to the storage structure */ t_stor.bset = t.bset; t_stor.breset = t.breset; t_stor.Hor = t.Hor; t_stor.Vert = t.Vert; t_stor.Newline = t.Newline; t_stor.Char = t.Char; t_stor.Em = t.Em; t_stor.Halfline = t.Halfline; t_stor.Adj = t.Adj; /* Add the character strings into a character array */ addstring (t.twinit); addstring (t.twrest); addstring (t.twnl); addstring (t.hlr); addstring (t.hlf); addstring (t.flr); addstring (t.bdon); addstring (t.bdoff); addstring (t.iton); addstring (t.itoff); addstring (t.ploton); addstring (t.plotoff); addstring (t.up); addstring (t.down); addstring (t.right); addstring (t.left); for (i = 0; i < 256 - 32; i++) addchar (t.codetab[i]); /* eliminate strings which are tails of other strings */ for (i = 0; i < n_strings; i++) { if (! c_pointer[i]) continue; /* String cleared out */ i_len = c_length[i]; for (j = 0; j < n_strings; j++) { if (i == j || ! c_pointer[j]) continue; j_len = c_length[j]; if (i_len <= j_len) { /* string i could be tail of string j */ tail = c_pointer[j] + j_len - i_len; if (! char_comp (c_pointer[i], tail, i_len)) { c_pointer[i] = 0; break; } } } } /* Compress the c_data array */ char_pointer = c_data; for (i = j = 0; i < n_strings; i++) { if (! (start = c_pointer[i])) continue; c_pointer[j] = char_pointer; c_length[j++] = c_length[i]; for (i_len = c_length[i]; i_len--;) *char_pointer++ = *start++; *char_pointer++ = 0; } n_strings = j; c_size = char_pointer - c_data; /* Now find each string in this table and provide an index to it */ t_stor.twinit = findstring (t.twinit); t_stor.twrest = findstring (t.twrest); t_stor.twnl = findstring (t.twnl); t_stor.hlr = findstring (t.hlr); t_stor.hlf = findstring (t.hlf); t_stor.flr = findstring (t.flr); t_stor.bdon = findstring (t.bdon); t_stor.bdoff = findstring (t.bdoff); t_stor.iton = findstring (t.iton); t_stor.itoff = findstring (t.itoff); t_stor.ploton = findstring (t.ploton); t_stor.plotoff = findstring (t.plotoff); t_stor.up = findstring (t.up); t_stor.down = findstring (t.down); t_stor.right = findstring (t.right); t_stor.left = findstring (t.left); for (i = 0; i < 256 - 32; i++) { t_stor.codetab[i] = findchar (t.codetab[i]); } t_stor.zzz = 0; /* Write the character storage block size */ if (fwrite (&c_size, sizeof (c_size), 1, table) != 1) write_err (); if (fwrite (&t_stor, sizeof (t_stor), 1, table) != 1) write_err (); if (fwrite (c_data, sizeof (*c_data), c_size, table) != c_size) write_err (); if (fclose (table)) { fprintf (stderr, "File %s not closed properly\n", argv[1]); exit (1); } } addstring (string) char *string; { c_pointer[n_strings] = c_end; c_end += (c_length[n_strings] = strlen (string)) + 1; if (c_end >= c_data + C_SIZE) { fprintf (stderr, "Table size too small, increase it!\n"); exit(1); } strcpy (c_pointer[n_strings++], string); } addchar (string) char *string; { c_pointer[n_strings] = c_end; c_end += (c_length[n_strings] = strlen (string + 2) + 2) + 1; if (c_end >= c_data + C_SIZE) { fprintf (stderr, "Table size too small, increase it!\n"); exit(1); } *c_pointer[n_strings] = *string++; /* Copy in first two bytes */ *(c_pointer[n_strings]+1) = *string++; strcpy (c_pointer[n_strings++] + 2, string); /* Copy the rest */ } char_comp (str1, str2, len) char *str1, *str2; int len; { while (len--) { if (*str1++ != *str2++) return (1); } return (0); } findstring (string) char *string; { int c_len, s_len, i; for (i = 0; i < n_strings; i++) { if ((c_len = c_length[i]) >= (s_len = strlen (string))) { if (!char_comp (string, c_pointer[i] + c_len - s_len, s_len)) return (c_pointer[i] + c_len - s_len - c_data); } } fprintf (stderr, "Serious bug! string not found in table\n"); exit(1); /* NOTREACHED */ } findchar (string) char *string; { int c_len, s_len, i; for (i = 0; i < n_strings; i++) { if ((c_len = c_length[i]) >= (s_len = strlen (string+2) + 2)) { if (!char_comp (string, c_pointer[i] + c_len - s_len, s_len)) return (c_pointer[i] + c_len - s_len - c_data); } } fprintf (stderr, "Serious bug! character not found in table\n"); exit(1); /* NOTREACHED */ } write_err () { fprintf (stderr, "Write to file failed\n"); exit (1); } @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/table.c" fi if `test ! -s nrofftab/table.doc` then echo "x - nrofftab/table.doc" cat > nrofftab/table.doc << '@\Rogue\Monster\' DOCUMENTATION OF NROFF TAB FILE UTILITY -Bruce Townsend, Bell-Northern Research, March 1985 (utcs!bnr-vpa!bruce) This file contains some documentation for the table program. This program makes printer and terminal driver tables suitable for nroff. The development of this program was motivated by the lack of any other means to prepare custom nroff driver tables, for those systems which do not have the original source that prepared the driver tables (usually found in /usr/lib/term). The format for the tables imbodied in this program was deduced from a "term" manual page, and by examining the contents of several existing tab files. Therefore, this program is not definitive in any sense, but is intended as a help for those who (like myself) do not have access to any formal tools that make these tab files. Also it is possible that this program will require modification for systems where the size of an integer is not 32 bits. The system that this program was developed on is an HP9000 (System III) and the data sizes are: long 32 int 32 short 16 char 8 As I have not had access to different machines, I do not know whether certain data in the tab file is of int or long type, since that type is the same on our machine. I have assumed int type. If your luck is really bad, I suppose it is possible that the format of the tab file is different across various implementations. The format of the tab file is: Type Name Size on HP9000 Description ---- ---- -------------- ----------- int c_size 4 bytes - The amount of character data in bytes that follows the t_stor structure. In fact the size of the file in bytes should be: c_size + sizeof (c_size) + sizeof (t_stor) (On our machine: c_size + 1004) struct { 1000 bytes - This is the storage for the "t" int bset; structure with one change. All the elements int breset; of the t structure which were pointers to int Hor; strings are now integer indexes to one int Vert; large character array. int Newline; int Char; int Em; int Halfline; int Adj; int twinit; int twrest; int twnl; int hlr; int hlf; int flr; int bdon; int bdoff; int iton; int itoff; int ploton; int plotoff; int up; int down; int right; int left; int codetab[256-32]; int zzz; } t_stor; char array[c_size] (variable size)- This is the storage for the strings pointed to by the indexes. How to Use the Table Program ---------------------------- Examine the "term" manual page which explains the purpose of each of the items in the "t" structure. Make a copy of the tabXXX.c program and edit it, replacing XXX with a suitable mnemonic. Initialize the t structure to the integer or character string values that are necessary for the terminal or printer in question. You have a high degree of flexibility here, and variable-width characters, overstrike combinations, etc are easy to implement. The only catch here is determining which index of the t.codetab[] array corresponds to which nroff printable character. This information is not in the manual page. After some experimentation, I have made a table which list the characters I know about. The table has some holes in it, but is as complete as I can make it. If anyone has additions or corrections, please let me know. The table is found in the file charlist. Also, the comments in tabXXX.c should help. WARNING: ALL CHARACTER STRINGS IN THE codetab[] array MUST be at least two characters in size, not counting the null terminator. The typical definition for a zero-width string which prints nothing is "\000\0" and NOT "". THIS IS VERY IMPORTANT, because it is necessary to allow the first byte of these strings to be zero in the case of zero-width strings that do print something. E.G. the string "\000^\b" is a zero-width "hat" character. If the amount of char data is very large, you may need to increase the definition of C_SIZE in table.c. It is now set at 10000 characters. The table.c program will burp out a message to this effect if necessary. The t.bset and t.breset flags will need definitions from either <termio.h> or <sgtty.h>. Include whichever is appropriate for your system in tabXXX.c. After the tabXXX.c file has been edited, place it in the same directory as table.c and the Makefile, and compile the table with: make tabXXX This will compile and run a program which will in turn make the tab file. Move the tabfile to its destination directory (likely /usr/term/tab). Run nroff as: nroff -TXXX ... (for example): nroff -T630P ... Debugging is not easy. You can use the supplied program which takes a tab file (tabXXX) and makes a source file (tabXXX.c). The program is called elbat (reverse of table) Do this by: elbat tabXXX > tabXXX.c and compare to your original tabXXX.c Do this for tab files that you have already to check that the format is the same on your system as on mine. The Table Program ----------------- As mentioned before, this program is not to be considered a definitive one. It works for HP9000's as far as I can tell. However, it does have the feature of compressing the supplied character data as much as possible. If one string is the tail of another (e.g. the strings abcdef and def), than only the largest string is stored. The smaller is indexed into the middle of the larger. Repeated strings (including the null string) are only stored once. It should generate a tabfile very close to the size of the distributed tables. Check by using elbat on a distributed table, compile using the table utility, and compare the sizes. The character data will almost certainly be stored in a different order than in the distributed table, so "cmp -l" will find most bytes different. However, the nroff results using the two files should be identical. The program has not been extensively tested. There may be bugs or misinformation. Let me know of any problems. If the tab files produced by this program do not work at all on your system, then it may be that the data types for c_size, and t_stor.whatever are incorrect. (Long instead of int?) You can get an indication by looking at the first word (int or long?) of an existing tab file. This is the amount of char data stored in the file. Subtract it from the size of the file in bytes. The result will be the size of the t_stor structure plus the size of the c_size variable. The t_stor structure has 250 elements in it. If each is 4 bytes, as on our system, and the c_size variable is 4 bytes also, then the result of the previous subtraction should be 1004. If the sizeof(int) on your system is 16 bits, then the difference should be 502. If it is not, then perhaps the types (some or all) of c_size, and the elements in t_stor should be changed to reflect this. Good luck! I can be reached at: utcs!bnr-vpa!bruce (UUCP) or (613) 726 - 3008 (Phone) (Ottawa, Canada) @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/table.doc" fi if `test ! -s nrofftab/term.5` then echo "x - nrofftab/term.5" cat > nrofftab/term.5 << '@\Rogue\Monster\' .TH TERM 5 .SH NAME term \- terminal driving tables for nroff .SH DESCRIPTION .IR Nroff (1) uses driving tables to customize its output for various types of output devices, such as printing terminals, special word-processing terminals (such as Diablo, Qume, or NEC Spinwriter mechanisms), or special output filter programs. These driving tables are written as C programs, compiled, and installed in \f3/usr/lib/term/tab\f2name\fP , where .I name\^ is the name for that terminal type as given in .IR term (7). The structure of the tables is as follows: .PP .nf .ta 5m 10m 15m 20m 25m 30m 35m 40m 45m 50m 55m 60m #define INCH 240 struct { int bset; int breset; int Hor; int Vert; int Newline; int Char; int Em; int Halfline; int Adj; char *twinit; char *twrest; char *twnl; char *hlr; char *hlf; char *flr; char *bdon; char *bdoff; char *iton; char *itoff; char *ploton; char *plotoff; char *up; char *down; char *right; char *left; char *codetab[256\-32]; char *zzz; } t; .fi .DT .PP The meanings of the various fields are as follows: .TP 10 .I bset\^ bits to set in the .I c_oflag\^ field of the .I termio\^ structure (see .IR tty (4)) before output. .TP 10 .I breset\^ bits to reset in the .I c_oflag\^ field of the .I termio\^ structure before output. .TP 10 .I Hor\^ horizontal resolution in fractions of an inch. .TP 10 .I Vert\^ vertical resolution in fractions of an inch. .TP 10 .I Newline\^ space moved by a newline (linefeed) character in fractions of an inch. .TP 10 .I Char\^ quantum of character sizes, in fractions of an inch. (i.e., a character is a multiple of Char units wide) .TP 10 .I Em\^ size of an em in fractions of an inch. .TP 10 .I Halfline\^ space moved by a half-linefeed (or half-reverse-linefeed) character in fractions of an inch. .TP 10 .I Adj\^ quantum of white space, in fractions of an inch. (i.e., white spaces are a multiple of Adj units wide) .IP Note: if this is less than the size of the space character (in units of Char; see below for how the sizes of characters are defined), .I nroff\^ will output fractional spaces using plot mode. Also, if the .B \-e switch to .I nroff\^ is used, Adj is set equal to Hor by .IR nroff . .TP 10 .I twinit\^ set of characters used to initialize the terminal in a mode suitable for .IR nroff . .TP 10 .I twrest\^ set of characters used to restore the terminal to normal mode. .TP 10 .I twnl\^ set of characters used to move down one line. .TP 10 .I hlr\^ set of characters used to move up one-half line. .TP 10 .I hlf\^ set of characters used to move down one-half line. .TP 10 .I flr\^ set of characters used to move up one line. .TP 10 .I bdon\^ set of characters used to turn on hardware boldface mode, if any. .I Nroff\^ assumes that boldface mode is reset automatically by the .I twnl\^ string, because many letter-quality printers reset the boldface mode when they receive a carriage return; the .I twnl\^ string should include whatever characters are necessary to reset the boldface mode. .TP 10 .I bdoff\^ set of characters used to turn off hardware boldface mode, if any. .TP 10 .I iton\^ set of characters used to turn on hardware italics mode, if any. .TP 10 .I itoff\^ set of characters used to turn off hardware italics mode, if any. .TP 10 .I ploton\^ set of characters used to turn on hardware plot mode (for Diablo type mechanisms), if any. .TP 10 .I plotoff\^ set of characters used to turn off hardware plot mode (for Diablo type mechanisms), if any. .TP 10 .I up\^ set of characters used to move up one resolution unit (Vert) in plot mode, if any. .TP 10 .I down\^ set of characters used to move down one resolution unit (Vert) in plot mode, if any. .TP 10 .I right\^ set of characters used to move right one resolution unit (Hor) in plot mode, if any. .TP 10 .I left\^ set of characters used to move left one resolution unit (Hor) in plot mode, if any. .TP 10 .I codetab\^ definition of characters needed to print an .I nroff\^ character on the terminal. The first byte is the number of character units (Char) needed to hold the character; i.e., ``\\001'' is one unit wide, ``\\002'' is two units wide, etc. The high-order bit (0200) is on if the character is to be underlined in underline mode (.ul). The rest of the bytes are the characters used to produce the character in question. If the character has the sign (0200) bit on, it is a code to move the terminal in plot mode. It is encoded as: .RS .IP "0100 bit on" 15 vertical motion. .IP "0100 bit off" 15 horizontal motion. .IP "040 bit on" 15 negative (up or left) motion. .IP "040 bit off" 15 positive (down or right) motion. .IP "037 bits" 15 number of such motions to make. .RE .TP 10 .I zzz\^ a zero terminator at the end. .PP All quantities which are in units of fractions of an inch should be expressed as .RI INCH* num / denom , where .I num\^ and .I denom\^ are respectively the numerator and denominator of the fraction; i.e., 1/48 of an inch would be written as ``INCH/48''. .PP If any sequence of characters does not pertain to the output device, that sequence should be given as a null string. .PP If you have source license: .br The source code for the terminal .I name\^ is in .BI /usr/src/cmd/text/roff.d/terms.d/tab name .c. When a new terminal type is added, the file .I maketerms.c\^ should be updated to `#include' the source to that driving table; note that the various terminal types are grouped into ``parts'' labelled .BR PART1 , .BR PART2 , and .BR PART3 . If necessary, more parts can be added. Other changes necessary to .I maketerms.c\^ are left as an exercise to the reader. The makefile .I terms.mk\^ in that directory should then be updated. .PP If you do not have source license, but have Bruce Townsend's .I table\^ utility: .br The source code for the terminal .I name\^ is in a file called .BI tab name .c. When a new terminal type is added, the file .I Makefile\^ in the same directory should be updated. Just add the name .BI tab name to the definition of .BR TABFILES . Then type .BI "make tab" name. Store the result in .B /usr/lib/term. .SH FILES /usr/lib/term/tab\f2name\fP driving tables .br tab\f2name\fP.c source for driving tables .SH SEE ALSO troff(1), term(7) @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/term.5" fi if `test ! -s nrofftab/term.h` then echo "x - nrofftab/term.h" cat > nrofftab/term.h << '@\Rogue\Monster\' #ifndef INCH #define INCH 240 #endif struct t { int bset; int breset; int Hor; int Vert; int Newline; int Char; int Em; int Halfline; int Adj; char *twinit; char *twrest; char *twnl; char *hlr; char *hlf; char *flr; char *bdon; char *bdoff; char *iton; char *itoff; char *ploton; char *plotoff; char *up; char *down; char *right; char *left; char *codetab[256-32]; char *zzz; }; struct t_stor { /* This structure will be stored in the tab file */ int bset; int breset; int Hor; int Vert; int Newline; int Char; int Em; int Halfline; int Adj; int twinit; int twrest; int twnl; int hlr; int hlf; int flr; int bdon; int bdoff; int iton; int itoff; int ploton; int plotoff; int up; int down; int right; int left; int codetab[256-32]; int zzz; }; @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/term.h" fi if `test ! -s nrofftab/Makefile` then echo "x - nrofftab/Makefile" cat > nrofftab/Makefile << '@\Rogue\Monster\' # Makefile for table.c, method of producing a single terminal # table for nroff under USG UNIX. # Makefile written by Bruce Townsend (utcs!bnr-vpa!bruce) # and Ian Darwin (utcs!darwin!ian) # March 6, 1985. TABFILES = tabXXX DESTDIR = /usr/lib/term LINTTAB = tabXXX DEFS = CFLAGS = $(DEFS) -O LDFLAGS = -s LFLAGS = $(DEFS) $(TABFILES): dummy_file $(MAKE) -$(MAKEFLAGS) table.o $@.o cc $(LDFLAGS) table.o $@.o ./a.out $@ # This dummy_file should never exist, it is a kludge to get Make to # always execute cc. dummy_file: @rm -f dummy_file all: $(TABFILES) install: $(TABFILES) mv $(TABFILES) $(DESTDIR) lint: table.c lint $(LFLAGS) table.c $(LINTTAB).c elbat: elbat.o cc $(LDFLAGS) elbat.o -o elbat clean: rm -f a.out tab*.o elbat.o @\Rogue\Monster\ else echo "shar: Will not over write nrofftab/Makefile" fi # to concatenate archives, remove anything after this line exit 0 -- "Lay orf Arfur, 'e doesnt know wot 'es saying" UUCP.net: {ukc,uunet}!munnari!nswitgould.oz!shocking ACS.net: shocking@nswitgould.oz
irf@kuling.UUCP (Stellan Bergman) (10/01/87)
Until we got our latest release of HP-UX (5.21) I was nroffing merrily with a nroff table I wrote myself for the Laserjet+ emulating closely what I would have got had I only had troff. The HP-UX table was (almost) identical to all other 7-bit tables published in many places (e.g. in "troff TYPESETTING FOR UNIX(TM) SYSTEMS", Appendix C, by S.L Emerson and K. Paulsell, Prentice-Hall, 1987, ISBN 0-13-930959-4 025). Now, with the new release, HP has (finally!) introduced 8 bit nroff making it possible to typeset in other languages than English (e.g. Swedish, which has three more vowels than English ...) the nroff table format has changed. nroff -Tlas, where my old tablas table should be used gives error messages "Floating exceptions" and then bombs out. Is there anoone out there who knows how the new 8 bit tables should be written. I would appreciate answer through any means (Ordinary mail, e-mail, here ...) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Bo Thide, Swedish Institute of Space Physics, S-755 90 Uppsala, Sweden UUCP: ....enea!kuling!irfu!bt ___________________________________________________
bruce@bnr-vpa.UUCP (10/07/87)
In article <500@kuling.UUCP> irf@kuling.UUCP (Stellan Bergman) writes: > >Until we got our latest release of HP-UX (5.21) I was nroffing merrily with >a nroff table I wrote myself... >... Now, with the new release, >HP has (finally!) introduced 8 bit nroff making it possible to typeset >in other languages than English (e.g. Swedish, which has three more vowels >than English ...) the nroff table format has changed. nroff -Tlas, where >my old tablas table should be used gives error messages "Floating exceptions" >and then bombs out. > >Is there anoone out there who knows how the new 8 bit tables should be written. >I would appreciate answer through any means (Ordinary mail, e-mail, here ...) > As author of the "table" utility that compiles nroff driver tables for USG systems that was distributed to the net some time ago, I have been made aware of the problem that HP-UX (5.2) introduces. I received a message from someone at HP who is responsible for maintaining nroff, and he revealed that difference in the new format is merely the inclusion of a new integer element in the structures t and t_stor, called Kchar. It is inserted immediately following the Char element, and apparently refers to the width of Kanji characters. As I do not yet have this HP-UX release, I am unable to test this, but I hope to within a week or two. For those of you who can't wait, and want to hack the table program, try simply modifying the structures to include this new element. Also, anywhere there appears a "Char" in table.c, elbat.c, or term.h, copy that line and substitute Kchar for Char. Good luck. Apparently, the value of t.Kchar is generally twice that of t.Char, but I do not yet know how that is used. Coincidently, I was in the process of preparing a new version of the table utility (version 2.0), and I will send it to comp.sources.unix when it is ready. It will include provision for this new format for those systems that use it (is HP-UX the only one?). The new version fixes a few problems with both table and elbat, provides a much better Makefile, and a proper man page. I have more closely examined the driver table format, at least those that are supplied with my machine, and have rewritten table.c so that the operation: elbat tabfile > tabfile.c (de-compile) ; table tabfile.c (compile) is an identity operation (at least on my machine for the tabfiles supplied with HP-UX). The previous version (1.2) re-compiled the tabfiles into a different (but I thought equivalent) form; it may be that systems that encountered problems with the use of tabfiles prepared by table may benefit from the new version. regards, Bruce Townsend (bnr-vpa!bruce) -- Bruce Townsend (bnr-vpa!bruce) Phone: (613) 726-3008 Bell-Northern Research Usenet: {utzoo, utcs}!bnr-vpa!bruce P.O. Box 3511, Station C, Ottawa, Ontario, Canada, K1Y 4H7