125284Sjaap #ifndef lint
2*25285Sjaap static char sccsid[] = "@(#)dumpdev.c 1.2 (CWI) 85/10/24";
325284Sjaap #endif lint
425284Sjaap
525284Sjaap /*
625284Sjaap * inverse of makethev, dump de information of the (binary) device information
725284Sjaap * will also dump the font info of standard (default) mounted fonts.
825284Sjaap *
925284Sjaap * Usage:
1025284Sjaap * dumpdev [flags] device
1125284Sjaap *
1225284Sjaap * flags:
1325284Sjaap * -f name; take info from dir name instead of default dir
1425284Sjaap * -Tdevice; device for wich the dump is made;
1525284Sjaap * -D; dump only the device info, not the font info
1625284Sjaap * -F F1 F2 ...; dump only the named fonts info
1725284Sjaap * -d; give extra debug info on error output
1825284Sjaap *
1925284Sjaap * Author: jaap akkerhuis, Mathematisch Centrum, Oc 1982
2025284Sjaap *
2125284Sjaap */
2225284Sjaap
2325284Sjaap # include "../dev.h"
2425284Sjaap # include <stdio.h>
2525284Sjaap
2625284Sjaap # define BMASK 0377
2725284Sjaap # define FATAL 1
2825284Sjaap
2925284Sjaap struct dev dev;
3025284Sjaap struct Font font;
3125284Sjaap
32*25285Sjaap char *fontdir = "/usr/local/lib/ditroff/font";
3325284Sjaap char *devname = "har"; /* devicename */
3425284Sjaap
3525284Sjaap int nfonts;
3625284Sjaap int nsizes;
3725284Sjaap int nchtab;
3825284Sjaap
3925284Sjaap # define NSIZE 100 /* maximum number of sizes */
4025284Sjaap
4125284Sjaap # define NCH 256 /* maximum number of characters with funny names */
4225284Sjaap
4325284Sjaap # define FSIZE 200 /* size of physical font */
4425284Sjaap
4525284Sjaap # define NFONT 10 /* Maximum number of default fonts */
4625284Sjaap
4725284Sjaap int dbg;
4825284Sjaap int Dflag;
4925284Sjaap int Fflag;
5025284Sjaap
main(argc,argv)5125284Sjaap main(argc, argv)
5225284Sjaap int argc; char *argv[];
5325284Sjaap { FILE *fp;
5425284Sjaap
5525284Sjaap while (argc > 1 && argv[1][0] == '-') {
5625284Sjaap switch (argv[1][1]) {
5725284Sjaap case 'f':
5825284Sjaap fontdir = argv[2];
5925284Sjaap argv++;
6025284Sjaap argc--;
6125284Sjaap break;
6225284Sjaap case 'd':
6325284Sjaap dbg ++;
6425284Sjaap break;
6525284Sjaap case 'T':
6625284Sjaap devname = &argv[1][2];
6725284Sjaap break;
6825284Sjaap case 'D':
6925284Sjaap Dflag++;
7025284Sjaap break;
7125284Sjaap case 'F':
7225284Sjaap Fflag++;
7325284Sjaap break;
7425284Sjaap default:
7525284Sjaap fprintf( stderr, "Unknown option %c\n", argv[1][1]);
7625284Sjaap break;
7725284Sjaap }
7825284Sjaap argv++;
7925284Sjaap argc--;
8025284Sjaap }
8125284Sjaap
8225284Sjaap if(devname == NULL)
8325284Sjaap error(FATAL,"No device specified");
8425284Sjaap
8525284Sjaap getdesc();
8625284Sjaap
8725284Sjaap if(Dflag)
8825284Sjaap exit(0);
8925284Sjaap
9025284Sjaap if( Fflag)
9125284Sjaap while ( argc > 1) {
9225284Sjaap getfont( argv[1] );
9325284Sjaap argv++;
9425284Sjaap argc--;
9525284Sjaap }
9625284Sjaap }
9725284Sjaap
error(f,s,a1,a2,a3,a4,a5,a6,a7)9825284Sjaap error(f, s, a1, a2, a3, a4, a5, a6, a7) {
9925284Sjaap fprintf(stderr, "dumpdev: ");
10025284Sjaap fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
10125284Sjaap fprintf(stderr, "\n");
10225284Sjaap if (f)
10325284Sjaap exit(1);
10425284Sjaap }
10525284Sjaap
10625284Sjaap /*
10725284Sjaap * structure of a device file.
10825284Sjaap *
10925284Sjaap * the first part consists of the structure dev.
11025284Sjaap *
11125284Sjaap * Notes: dev.filesize contains the size of the file minus the strcture dev
11225284Sjaap * dev.nchtab contains the nimber of funny charnames +1
11325284Sjaap *
11425284Sjaap * then follows a list of sizes (shorts), ended with a zero.
11525284Sjaap *
11625284Sjaap * then follows a table of dev.nchtab pointers ( shorts ),
11725284Sjaap * these will point to the strings with all the funnynames.
11825284Sjaap * this is called chtab.
11925284Sjaap *
12025284Sjaap * after this is the table of funny names (chname) which is dev.lnchname
12125284Sjaap * bytes big.
12225284Sjaap *
12325284Sjaap * So up uo here the device charactistics are read.
12425284Sjaap *
12525284Sjaap * Then follows the default mounted font info, dev.nfont times (max NFONT).
12625284Sjaap *
12725284Sjaap * first the font structure.
12825284Sjaap *
12925284Sjaap * font.nwfonts is the amount of widths of the font, so it will be used
13025284Sjaap * as the amount of characters in the font as well.
13125284Sjaap *
13225284Sjaap * so now will follow:
13325284Sjaap * the widthtable (font.nwfonts bytes) containg the widths info
13425284Sjaap * the kerntable (font.nwfonts bytes) containing the de- & ascender info
13525284Sjaap * the codetable (font.nwfonts bytes) containing the codes for the chars
13625284Sjaap * the fitable (dev.nchtab+128-32 bytes) containing indexes to the
13725284Sjaap * previous three tables.
13825284Sjaap *
13925284Sjaap * if font.fonttab == 1
14025284Sjaap * will also follow the fcodetable (font.nwfonts (sizeof(short))
14125284Sjaap * containing the physical font numbers ( see also the comment
14225284Sjaap * added by jna in makedev.c)
14325284Sjaap *
14425284Sjaap * for info about the use of this tables, see the comment at dumpfont.
14525284Sjaap *
14625284Sjaap */
14725284Sjaap
14825284Sjaap char *chname;
14925284Sjaap short *chtab;
15025284Sjaap
getdesc()15125284Sjaap getdesc()
15225284Sjaap {
15325284Sjaap char *malloc(), *filebase, *p;
15425284Sjaap struct Font *fontbase[NFONT];
15525284Sjaap short *pstab, *p1;
15625284Sjaap int i, fin, nw;
15725284Sjaap char temp[60];
15825284Sjaap
15925284Sjaap sprintf(temp, "%s/dev%s/DESC.out", fontdir, devname);
16025284Sjaap
16125284Sjaap if((fin = open(temp, 0)) < 0)
16225284Sjaap error(FATAL, "can't open DESC.out for %s\n", temp);
16325284Sjaap
16425284Sjaap printf("# Dump of device %s (%s)\n", devname, temp);
16525284Sjaap
16625284Sjaap if((read(fin, &dev, sizeof(struct dev))) != sizeof(struct dev))
16725284Sjaap error(FATAL, "read error reading devstruct %s", temp);
16825284Sjaap nfonts = dev.nfonts;
16925284Sjaap nsizes = dev.nsizes;
17025284Sjaap nchtab = dev.nchtab;
17125284Sjaap if(nfonts > NFONT)
17225284Sjaap error(!FATAL,"More (%d) fonts then possible (%d)",
17325284Sjaap nfonts, NFONT);
17425284Sjaap if(nsizes > NSIZE)
17525284Sjaap error(!FATAL,"More (%d) sizes then possible (%d)",
17625284Sjaap nsizes, NSIZE);
17725284Sjaap if(nchtab > NCH)
17825284Sjaap error(!FATAL,"More (%d) names then possible (%d)",
17925284Sjaap nchtab, NCH);
18025284Sjaap if(dbg) {
18125284Sjaap fprintf(stderr,
18225284Sjaap "filesize %d, default fonts %d, sizes %d, funny names %d lchname %d\n",
18325284Sjaap dev.filesize, dev.nfonts, dev.nsizes, dev.nchtab, dev.lchname);
18425284Sjaap fprintf(stderr,
18525284Sjaap "sizescale %d, paperwidth %d, paperlenght %d, spare1 %d, spare2 %d\n",
18625284Sjaap dev.sizescale, dev.paperwidth, dev.paperlength, dev.spare1,
18725284Sjaap dev.spare2);
18825284Sjaap }
18925284Sjaap
19025284Sjaap printf("res %d\nhor %d\nvert %d\nunitwidth %d\n",
19125284Sjaap dev.res, dev.hor, dev.vert, dev.unitwidth);
19225284Sjaap if( dev.sizescale)
19325284Sjaap printf("sizescale %d\n", dev.sizescale);
19425284Sjaap if(dev.paperwidth)
19525284Sjaap printf("paperwidth %d\n", dev.paperwidth);
19625284Sjaap if(dev.paperlength)
19725284Sjaap printf("paperlength %d\n", dev.paperlength);
19825284Sjaap if(dev.spare1)
19925284Sjaap printf("spare1 %d\n", dev.spare1);
20025284Sjaap if(dev.spare2)
20125284Sjaap printf("spare2 %d\n", dev.spare2);
20225284Sjaap
20325284Sjaap filebase = malloc(dev.filesize); /* enough room for whole file */
20425284Sjaap if((read(fin, filebase, dev.filesize)) != dev.filesize) /* all at once */
20525284Sjaap error(FATAL, "read error reading fontinfo %s", temp);
20625284Sjaap pstab = (short *) filebase;
20725284Sjaap
20825284Sjaap printf("sizes ");
20925284Sjaap i = 0;
21025284Sjaap for( p1 = pstab; *p1; p1++) {
21125284Sjaap i++;
21225284Sjaap printf("%d ",*p1);
21325284Sjaap }
21425284Sjaap printf("\n");
21525284Sjaap if ( i != nsizes)
21625284Sjaap error(!FATAL, "%s sizes (%d) then expected (%d)\n",
21725284Sjaap i > nsizes ? "More" : "Less", i, nsizes);
21825284Sjaap
21925284Sjaap chtab = pstab + nsizes + 1; /* table of indexes in chname */
22025284Sjaap chname = (char *) (chtab + dev.nchtab); /* start of name table */
22125284Sjaap p = chname + dev.lchname; /* beginning of first font */
22225284Sjaap
22325284Sjaap for ( i = 0; i < nfonts; i++) { /* pickup the font names */
22425284Sjaap fontbase[i] = (struct Font *) p;
22525284Sjaap nw = *p & BMASK; /* first thing is width count */
22625284Sjaap p += sizeof(struct Font);
22725284Sjaap p += 3 * nw + dev.nchtab + 128 - 32;
22825284Sjaap if(fontbase[i]->fonttab == 1)
22925284Sjaap p += nw * sizeof( short );
23025284Sjaap }
23125284Sjaap printf("fonts %d", nfonts);
23225284Sjaap for ( i = 0; i < nfonts; i++)
23325284Sjaap printf(" %s",fontbase[i]->namefont);
23425284Sjaap printf("\n");
23525284Sjaap
23625284Sjaap if(dbg) {
23725284Sjaap fprintf(stderr, "Indexes:");
23825284Sjaap p1 = chtab;
23925284Sjaap i = 0;
24025284Sjaap for( p1 = chtab; p1 < chtab + dev.nchtab - 1; p1++) {
24125284Sjaap i++;
24225284Sjaap fprintf(stderr, " %d", *p1);
24325284Sjaap if( i == 16) {
24425284Sjaap fprintf(stderr,"\n");
24525284Sjaap i = 0;
24625284Sjaap }
24725284Sjaap }
24825284Sjaap if( i != 0)
24925284Sjaap fprintf(stderr, "\n");
25025284Sjaap }
25125284Sjaap
25225284Sjaap printf("charset\n");
25325284Sjaap i = 0;
25425284Sjaap for( p1 = chtab; p1 < chtab + dev.nchtab -1; p1++) {
25525284Sjaap int i2;
25625284Sjaap i++;
25725284Sjaap printf(" %s", chname + *p1);
25825284Sjaap if( i == 16 || (i2 == 0 & i == 4)) {
25925284Sjaap printf("\n");
26025284Sjaap i = 0;
26125284Sjaap if( i2 == 0)
26225284Sjaap i2++;
26325284Sjaap }
26425284Sjaap }
26525284Sjaap if( i != 0)
26625284Sjaap printf("\n");
26725284Sjaap
26825284Sjaap if( !Dflag)
26925284Sjaap if ( !Fflag)
27025284Sjaap for( i = 0; i < nfonts ; i++ )
27125284Sjaap dumpfont( fontbase[i]);
27225284Sjaap close( fin );
27325284Sjaap }
27425284Sjaap
27525284Sjaap /*
27625284Sjaap * How to use the tables
27725284Sjaap *
27825284Sjaap * the fitable (font index table) contains indexes to the information about
27925284Sjaap * all the characters of a device that can be printed.
28025284Sjaap * The device is supposed to have all (128-32) printable ascii chars.
28125284Sjaap * We rely on thus idea
28225284Sjaap * There are also an unknown numer (den.nchtab -1) funny chars.
28325284Sjaap * So this make it clear why fitab is device dependent and not font dependent.
28425284Sjaap *
28525284Sjaap * For ascii characters you get your information by:
28625284Sjaap * fitab[inputchar-32] will have the index in the tables,
28725284Sjaap * if the index is 0, the char doesn't exist on this font
28825284Sjaap * so f.i. codetab[fitab[inputchar-32]] will give you the
28925284Sjaap * outputcode.
29025284Sjaap *
29125284Sjaap * For funny chars:
29225284Sjaap * Compare the string of the funny char with strings in nchname table
29325284Sjaap * if the nth string are the same, you can find the index by
29425284Sjaap * fitab[n + 128-32]
29525284Sjaap * if the index is 0, the char doesn't exist on this font
29625284Sjaap * and the kerning info f.i. by
29725284Sjaap * kerntab[fitab[n + 128-32]]
29825284Sjaap * if font.fonttab == 1
29925284Sjaap * There will also be a font code table, this is found by
30025284Sjaap * the same ways.
30125284Sjaap * if n >= dev.nchtab, the funny name was illegal.
30225284Sjaap *
30325284Sjaap * Note:
30425284Sjaap * Width[0] contains the spacesize, set by or the spacesize command
30525284Sjaap * while constructing the font file, or the default spacesize.
30625284Sjaap *
30725284Sjaap */
30825284Sjaap
30925284Sjaap dumpfont( font )
31025284Sjaap struct Font *font;
31125284Sjaap { char *p;
31225284Sjaap int nw;
31325284Sjaap int i, c;
31425284Sjaap char *kerntab, *fitab, *widthtab, *codetab;
31525284Sjaap short *fcode;
31625284Sjaap
31725284Sjaap p = (char *) font;
31825284Sjaap
31925284Sjaap nw = *p & BMASK;
32025284Sjaap
32125284Sjaap p += sizeof(struct Font);
32225284Sjaap
32325284Sjaap widthtab = p;
32425284Sjaap p += nw;
32525284Sjaap kerntab = p;
32625284Sjaap p += nw;
32725284Sjaap codetab = p;
32825284Sjaap p += nw;
32925284Sjaap fitab = p;
33025284Sjaap if( font->fonttab == 1) { /* the fcode tab is here */
33125284Sjaap p += nchtab + 128 -32;
33225284Sjaap fcode = (short *) p;
33325284Sjaap }
33425284Sjaap
33525284Sjaap printf("# Fontinfo for %s\n", devname);
33625284Sjaap printf("name %s\n", font->namefont);
33725284Sjaap printf("internalname %s\n", font->intname);
33825284Sjaap if( font->specfont )
33925284Sjaap printf("special\n");
34025284Sjaap mklig( font->ligfont );
34125284Sjaap if( font->fonttab )
34225284Sjaap printf("fonttab\n");
34325284Sjaap if( font->slant )
34425284Sjaap printf("slant %d\n", font-> slant);
34525284Sjaap if( *widthtab ) /* widthtab[0] contains the spacewidth */
34625284Sjaap printf( "spacewidth %d\n", *widthtab & BMASK);
34725284Sjaap
34825284Sjaap /* now print the contents of this font */
34925284Sjaap
35025284Sjaap /* first the ascii chars */
35125284Sjaap for( c = 0; c < 128 - 32; c++) {
35225284Sjaap i = fitab[c];
35325284Sjaap if( i ) {
35425284Sjaap printf("%c\t%d\t%o\t0%o",
35525284Sjaap (c + 32) & BMASK, widthtab[i] & BMASK,
35625284Sjaap kerntab[i] & BMASK, codetab[i] & BMASK);
35725284Sjaap if(font->fonttab == 1)
35825284Sjaap printf("\t%d\n", fcode[i]);
35925284Sjaap else
36025284Sjaap printf("\n");
36125284Sjaap }
36225284Sjaap }
36325284Sjaap
36425284Sjaap /* and now the special ones */
36525284Sjaap for( c = 0; c < nchtab; c++) {
36625284Sjaap i = (unsigned char)fitab[c + 128 - 32];
36725284Sjaap if(i) {
36825284Sjaap printf("%s\t%d\t%o\t0%o",
36925284Sjaap &chname[chtab[c]], widthtab[i] & BMASK,
37025284Sjaap kerntab[i] & BMASK, codetab[i] & BMASK);
37125284Sjaap if(font->fonttab == 1)
37225284Sjaap printf("\t%d\n", fcode[i]);
37325284Sjaap else
37425284Sjaap printf("\n");
37525284Sjaap }
37625284Sjaap }
37725284Sjaap }
37825284Sjaap
37925284Sjaap
mklig(c)38025284Sjaap mklig( c )
38125284Sjaap char c;
38225284Sjaap {
38325284Sjaap if( !c )
38425284Sjaap return;
38525284Sjaap
38625284Sjaap printf("ligatures");
38725284Sjaap
38825284Sjaap if( c & LFF)
38925284Sjaap printf(" ff");
39025284Sjaap if( c & LFI)
39125284Sjaap printf(" fi");
39225284Sjaap if( c & LFL)
39325284Sjaap printf(" fl");
39425284Sjaap if( c & LFFI)
39525284Sjaap printf(" ffi");
39625284Sjaap if( c & LFFL)
39725284Sjaap printf(" ffl");
39825284Sjaap printf(" 0\n");
39925284Sjaap }
40025284Sjaap
getfont(fname)40125284Sjaap getfont( fname )
40225284Sjaap char *fname;
40325284Sjaap { char *malloc(), *p;
40425284Sjaap int fin, size;
40525284Sjaap char temp[60];
40625284Sjaap
40725284Sjaap sprintf(temp,"%s/dev%s/%s.out", fontdir, devname, fname);
40825284Sjaap
40925284Sjaap if((fin = open(temp, 0)) < 0)
41025284Sjaap error(FATAL, "can't open %s\n", temp);
41125284Sjaap
41225284Sjaap printf("# Dump of font %s (%s)\n", fname, temp);
41325284Sjaap
41425284Sjaap size = lseek(fin, 0L, 2); /*get size of file*/
41525284Sjaap if(dbg)
41625284Sjaap fprintf(stderr, "Size of font %s: %d\n", temp, size);
41725284Sjaap
41825284Sjaap lseek(fin, 0L, 0);
41925284Sjaap
42025284Sjaap p = malloc( size);
42125284Sjaap
42225284Sjaap if((read(fin, p, size)) != size )
42325284Sjaap error(FATAL, "read error at %s\n", temp);
42425284Sjaap
42525284Sjaap dumpfont(p);
42625284Sjaap free( p );
42725284Sjaap close (fin);
42825284Sjaap }
429