summaryrefslogtreecommitdiff
path: root/dviware/umddvi/lib/scanpost.c
blob: c382731e6ed9234f7106fdd2c4e099583e74f2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (c) 1987 University of Maryland Department of Computer Science.
 * All rights reserved.  Permission to copy for any purpose is hereby granted
 * so long as this copyright notice remains intact.
 */

#ifndef lint
static char rcsid[] = "$Header: scanpost.c,v 2.3 87/06/16 18:28:54 chris Exp $";
#endif

/*
 * ScanPostAmble - read a DVI postamble.
 */

#include <stdio.h>
#include "types.h"
#include "dvicodes.h"
#include "fio.h"
#include "postamble.h"

ScanPostAmble(f, headerfunc, fontfunc)
	register FILE *f;
	int (*headerfunc)();
	register int (*fontfunc)();
{
	register int n;
	register char *s;
	char name[512];

	if (FindPostAmble(f))
		GripeCannotFindPostamble();
	if (GetByte(f) != Sign8(DVI_POST))
		GripeMissingOp("POST");

	/* Read the postamble info stuff. */
	{
		struct PostAmbleInfo pai;
		register struct PostAmbleInfo *p = &pai;

		p->pai_PrevPagePointer = GetLong(f);
		p->pai_Numerator = GetLong(f);
		p->pai_Denominator = GetLong(f);
		p->pai_DVIMag = GetLong(f);
		p->pai_TallestPageHeight = GetLong(f);
		p->pai_WidestPageWidth = GetLong(f);
		p->pai_DVIStackSize = GetWord(f);
		p->pai_NumberOfPages = GetWord(f);

		(*headerfunc)(p);
	}

	/* Now read all the font definitions. */
	{
		struct PostAmbleFont paf;
		register struct PostAmbleFont *p = &paf;

		for (;;) {
			switch (UnSign8(getc(f))) {

			case DVI_FNTDEF1:
				p->paf_DVIFontIndex = UnSign8(getc(f));
				break;

			case DVI_FNTDEF2:
				p->paf_DVIFontIndex = UnSign16(GetWord(f));
				break;

			case DVI_FNTDEF3:
				p->paf_DVIFontIndex = UnSign24(Get3Byte(f));
				break;

			case DVI_FNTDEF4:
				p->paf_DVIFontIndex = GetLong(f);
				break;

			case DVI_POSTPOST:
				return;

			default:
				GripeMissingOp("POSTPOST");
				/*NOTREACHED*/
			}
			p->paf_DVIChecksum = GetLong(f);
			p->paf_DVIMag = GetLong(f);
			p->paf_DVIDesignSize = GetLong(f);
			p->paf_n1 = UnSign8(getc(f));
			p->paf_n2 = UnSign8(getc(f));
			p->paf_name = name;	/* never trust people not to
						   clobber it */
			n = p->paf_n1 + p->paf_n2;
			s = name;
			while (--n >= 0)
				*s++ = GetByte(f);
			*s = 0;
			(*fontfunc)(p);
		}
	}
}