|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T p
Length: 6267 (0x187b)
Types: TextFile
Names: »pageloop«
└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
└─⟦af5ba6c8e⟧ »unix3.0/DVIWARE.tar.Z«
└─⟦ca79c7339⟧
└─⟦this⟧ »DVIware/laser-setters/mctex/dvi/pageloop«
/*
* Copyright (c) 1987, 1989 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.
*/
/*
* Sample device driver page loop.
* Here are the functions you must write.
* The particular lines to change are indicated with `:::'.
*/
char *DVIFileName; /* name of input DVI file */
/*
* Do some sort of device-dependent fiddling with fonts
* as they are read from the DVI file.
*/
struct font *
DefineFont(name, dvimag, dvidsz)
char *name;
i32 dvimag, dvidsz;
{
struct font *f;
char *path;
::: f = GetFont(name, dvimag, dvidsz, PrintEngine, &path);
if (f == NULL) {
GripeCannotGetFont(name, dvimag, dvidsz, PrintEngine, path);
return (NULL);
}
::: f->f_un.f_int = NextFontNumber++;
return (f);
}
/*
* Start a new page (interpreter found a DVI_BOP).
*/
void
BeginPage()
{
::: (void) printf("start new page\n");
::: dev_hh = dev_vv = somewhere;
}
/*
* End the page (interpreter found a DVI_EOP).
*/
EndPage()
{
::: (void) printf("end the page\n");
}
/*
* Perform a \special.
* This version ignores all, with a warning.
*/
void
DoSpecial(len)
i32 len;
{
error(0, 0, "warning: ignoring \\special");
(void) fseek(stdin, (long)len, 1);
}
/*
* Set a rule at dvi_hh, dvi_vv.
*/
void
SetRule(h, w)
i32 h, w;
{
::: DRAW A RULE, height h, width w AT dvi_hh,dvi_vv
}
/*
* Check the range of a character, to be sure the device can handle it.
* Called for DVI_SET and DVI_PUT opcodes only.
*/
int
CheckChar(c)
i32 c;
{
if ((ui32)c > 127) {
error(0, 0, "Warning: character code %ld too big for XXX",
(long)c);
return (1);
}
return (0);
}
/*
* Main page loop. This reads one page of the DVI file.
* Returns 1 for EOP and 0 for end of last page (POST).
*/
int
PageLoop()
{
static struct font NoFont; /* font with zero pspace, etc */
register int c;
register i32 p;
register struct font *f = &NoFont;
register FILE *fp = ds.ds_fp;
::: LOCAL VARIABLE DECLARATIONS
int doingpage = 0, advance;
::: if (ReversePages)
if (ds.ds_prevpage == -1)
return (0); /* `the first shall be last' */
else
(void) fseek(fp, ds.ds_prevpage, 0);
/*
* This would be a `for (;;)', but that makes the function
* crawl off the right of the screen.
*
* We handle ordinary characters early, as they are the
* most common opcodes in DVI files, and doing so makes the
* loop run faster.
*/
loop:
c = fgetbyte(fp);
if (DVI_IsChar(c)) {
register struct glyph *g;
p = c;
advance = 1;
do_char:
g = GLYPH(f, p);
if (!GVALID(g)) {
GripeBadGlyph(p, f);
goto loop;
}
if ((g->g_flags & GF_SEEN) == 0) {
g->g_pixwidth = fromSP(g->g_tfmwidth);
g->g_flags |= GF_SEEN;
::: LOAD GLYPH (p,f,g) INTO DEVICE IF NECESSARY
}
::: SET DEVICE POSITION (to dvi_hh, dvi_vv) IF NECESSARY
::: SET DEVICE FONT (e.g., to f->f_un.f_int) IF NECESSARY
::: PUT CHARACTER p IN FONT f
::: ADJUST NOTION OF DEVICE POSITION IF NECESSARY
if (advance) {
dvi_h += g->g_tfmwidth;
dvi_hh += g->g_pixwidth;
p = fromSP(dvi_h);
FIXDRIFT(dvi_hh, p);
}
goto loop;
}
if (c == EOF) /* unexpected end of DVI file */
GripeUnexpectedDVIEOF();
/*
* Gather up a parameter, if known.
*/
switch (DVI_OpLen(c)) {
case DPL_NONE:
break;
case DPL_SGN1:
p = fgetbyte(fp);
p = Sign8(p);
break;
case DPL_SGN2:
fGetWord(fp, p);
p = Sign16(p);
break;
case DPL_SGN3:
fGet3Byte(fp, p);
p = Sign24(p);
break;
case DPL_SGN4:
fGetLong(fp, p);
break;
case DPL_UNS1:
p = fgetbyte(fp);
p = UnSign8(p);
break;
case DPL_UNS2:
fGetWord(fp, p);
p = UnSign16(p);
break;
case DPL_UNS3:
fGet3Byte(fp, p);
p = UnSign24(p);
break;
default:
panic("DVI_OpLen(%d) = %d", c, DVI_OpLen(c));
/* NOTREACHED */
}
/*
* Now switch on the type.
*/
switch (DVI_DT(c)) {
case DT_SET:
advance = 1;
::: if (CheckChar(p)) ...delete this if all characters OK
::: goto loop;
goto do_char;
case DT_PUT:
advance = 0;
::: if (CheckChar(p))
::: goto loop;
goto do_char;
case DT_SETRULE:
DVIRule(SetRule, 1);
goto loop;
case DT_PUTRULE:
DVIRule(SetRule, 0);
goto loop;
case DT_NOP:
goto loop;
case DT_BOP:
if (doingpage)
GripeUnexpectedOp("BOP (already in page)");
DVIBeginPage(BeginPage);
doingpage = 1;
goto loop;
case DT_EOP:
if (!doingpage)
GripeUnexpectedOp("EOP (no BOP)");
EndPage();
return (1);
case DT_PUSH:
*ds.ds_sp++ = ds.ds_cur;
goto loop;
case DT_POP:
ds.ds_cur = *--ds.ds_sp;
goto loop;
case DT_W0:
p = dvi_w;
goto right;
case DT_W:
dvi_w = p;
goto right;
case DT_X0:
p = dvi_x;
goto right;
case DT_X:
dvi_x = p;
goto right;
case DT_RIGHT:
right:
dvi_h += p;
if (F_SMALLH(f, p)) {
dvi_hh += fromSP(p);
p = fromSP(dvi_h);
FIXDRIFT(dvi_hh, p);
} else
dvi_hh = fromSP(dvi_h);
goto loop;
case DT_Y0:
p = dvi_y;
goto down;
case DT_Y:
dvi_y = p;
goto down;
case DT_Z0:
p = dvi_z;
goto down;
case DT_Z:
dvi_z = p;
goto down;
case DT_DOWN:
down:
dvi_v += p;
if (F_SMALLV(f, p)) {
dvi_vv += fromSP(p);
p = fromSP(dvi_v);
FIXDRIFT(dvi_vv, p);
} else
dvi_vv = fromSP(dvi_v);
goto loop;
case DT_FNTNUM:
f = DVIFindFont((i32)(c - DVI_FNTNUM0));
goto loop;
case DT_FNT:
f = DVIFindFont(p);
goto loop;
case DT_XXX:
DoSpecial(p);
goto loop;
case DT_FNTDEF:
SkipFontDef(fp);
goto loop;
case DT_PRE:
GripeUnexpectedOp("PRE");
/* NOTREACHED */
case DT_POST:
if (doingpage) {
GripeUnexpectedOp("POST (no EOP)");
/* NOTREACHED */
}
return (0);
case DT_POSTPOST:
GripeUnexpectedOp("POSTPOST");
/* NOTREACHED */
case DT_UNDEF:
GripeUndefinedOp(c);
/* NOTREACHED */
default:
panic("DVI_DT(%d) = %d", c, DVI_DT(c));
/* NOTREACHED */
}
/* NOTREACHED */
}
main(argc, argv)
int argc;
char **argv;
{
::: DECLARATIONS
ProgName = *argv;
ds.ds_usermag = 1000;
::: ds.ds_maxdrift = 3;
::: ReversePages = 0;
DVIFileName = "`stdin'";
::: PARSE OPTIONS
::: OPEN INPUT FILE
::: DVISetState(stdin, DefineFont, dpi, xoff, yoff);
::: SET INITIAL DEVICE STATE
while (PageLoop())
/* void */;
::: FINISH DEVICE OUTPUT
::: exit(0);
}