* vsort - Sort troff output for versatec to reduce amount of reverse leading
int skipfirst
= 1; /* skip the first leading so start at top of page */
int cpsize
= 02; /* Funny sizes */
int pagelength
= 144 * 11; /* in Leading units */
int pagemod
; /* horizontal page number (for versatec) */
#define MODOFF 3672 /* 432 * 8.5 */
int esc
, lead
, back
, verd
, mcase
, railmag
;
int pstart
= 0; /* Means a startline is pending */
int oback
, omcase
, orailmag
, ocol
, orow
;
char nocutmarks
= 0; /* Remove lines that seem to be cut marks. */
#define iscutmark(ch) (ch == 023 || ch == 040 || ch == 061)
while (argc
> 1 && argv
[1][0] == '-') {
float f
= 144 * atof(argv
[1] + 2);
if((in
=fopen(argv
[0], "r")) == NULL
)
while((c
= getch()) != -1) {
if(c
& 0200) /* escape (left/right) */
if((c
& 0377) < 0100) /* Purely for efficiency */
linesflush(); /* Omit trailing leading. */
verd
= 0; back
= 0; mcase
= 0;
if(loadfont(railmag
, cpsize
) < 0)
putc(0100, out
); /* Dont stuff it guys */
case 0101: /* lower rail */
case 0102: /* upper rail */
case 0103: /* upper mag */
case 0104: /* lower mag */
case 0105: /* lower case */
case 0106: /* upper case */
case 0107: /* escape forward */
case 0110: /* escape backwards */
case 0112: /* lead forward */
case 0113: /* undefined */
case 0114: /* lead backward */
case 0115: /* undefined */
if((c
& 0340) == 0140) /* leading */
if (wide
&& row
< 0 && pagemod
) {
if((c
& 0360) == 0120) /* size change */
col
+= stupidadj(c
& 017, cpsize
);
loadfont(railmag
, c
& 017);
} /* End of while loop reading chars. */
linesflush(); /* don't put out trailing leading. */
fprintf(stderr
, stderr
, "vsort: %s\n", s
);
cline
.start
.psize
= cpsize
;
cline
.start
.mcase
= mcase
;
cline
.start
.railmag
= railmag
;
register struct line
*linep
;
if((allp
= calloc(sizeof *linep
,1)) == ((char *)-1))
linep
= (struct line
*)allp
;
linep
->end
.psize
= cpsize
;
linep
->end
.mcase
= mcase
;
linep
->end
.railmag
= railmag
;
linep
->start
.col
= cline
.start
.col
;
linep
->start
.psize
= cline
.start
.psize
;
linep
->start
.mcase
= cline
.start
.mcase
;
linep
->start
.back
= cline
.start
.back
;
linep
->start
.verd
= cline
.start
.verd
;
linep
->start
.railmag
= cline
.start
.railmag
;
if((allp
= calloc(cline
.len
,1)) == ((char *)-1))
for(i
= 0; i
< cline
.len
; i
++)
register struct line
*linep
;
register struct line
*clp
;
if((clp
= tail
) == NULL
) {
linep
->lastp
= linep
->nextp
= NULL
;
while(clp
!= NULL
&& clp
->row
> linep
->row
)
if(clp
== NULL
) /* goes at head of list */ {
linep
->nextp
= clp
->nextp
;
clp
->nextp
->lastp
= linep
;
if(cline
.len
> TBUFLEN
) {
allflush() /* Flush all lines, then put out trailing leading. */
register struct line
*linep
;
if ((linep
= head
) == NULL
)
/* Heuristic: if cut marks are present, they are on lines whose
* row numbers are <= 24 or >= pagelength-4.
* Cut marks are formed from 023's, 040's, or 061's.
* There are 2 or 4 of them on a line, and no other characters
* are present. cutmark(...) checks this.
* Cutmark lines are removed if nocutmarks is true.
* Three leading units are removed, too, to compensate for
* varian output not being exactly 1584 leading units long.
&& (linep
->row
<= 24 || linep
->row
>= pagelength
-4)
if(linep
->start
.railmag
!= orailmag
)
ptrail(linep
->start
.railmag
);
if(linep
->start
.psize
!= opsize
)
ptsize(linep
->start
.psize
);
if(linep
->start
.mcase
!= omcase
)
if(linep
->row
> orow
) /* lead forward */
ptlead(linep
->row
- orow
);
if(linep
->start
.col
!= ocol
)
ptesc(linep
->start
.col
-ocol
);
if(linep
->start
.back
!= oback
)
for(i
= 0; i
< linep
->len
; i
++) {
if (!iscutmark(*cp
)) /* iscutmark is a macro. */
for(i
= 0; i
< linep
->len
; i
++)
orailmag
= linep
->end
.railmag
;
opsize
= linep
->end
.psize
;
omcase
= linep
->end
.mcase
;
register struct line
*linep
;
register int dashcount
= 0;
register int firstdash
= 0;
for (i
= 0; i
< linep
->len
; i
++) {
ch
= linep
->codep
[i
] & 0377;
/* Must have 2 or 4 dashes on a line. */
return (dashcount
== 4 || dashcount
== 2);
if((rlmg
& 01) != (orailmag
& 01))
putc((rlmg
& 01) ? 0102:0101, out
); /* rail */
if((rlmg
& 02) != (orailmag
& 02))
putc((rlmg
& 02) ? 0103:0104, out
); /* mag */
putc(oback
? 0107:0110, out
);
putc(0120 | (size
& 017), out
);
ptesc(-stupidadj(size
, opsize
));
register struct point_sizes
*psp
;
register struct point_sizes
*lpsp
;
while(psp
->real_code
!= 0) {
if((psp
->stupid_code
& 017) == code
)
while(lpsp
->real_code
!= 0) {
if((lpsp
->stupid_code
& 017) == lcode
)
if(!(lpsp
->stupid_code
& 0200) && (psp
->stupid_code
& 0200))
if((lpsp
->stupid_code
& 0200) && !(psp
->stupid_code
& 0200))
putc(omcase
? 0105:0106, out
);
if((escc
< 0 && !oback
) || (escc
>= 0 && oback
))
putc(0200 | ((~escc
) & 0177), out
);
putc(0140 | ((~leadd
) & 037), out
);
register struct line
*linep
;
fprintf(stderr
, "row: %d\n", linep
->row
);
fprintf(stderr
, "start.col: %o ", linep
->start
.col
& 0377);
fprintf(stderr
, ".psize: %o ", linep
->start
.psize
);
fprintf(stderr
, ".railmag: %o ", linep
->start
.railmag
);
fprintf(stderr
, ".verd: %o ", linep
->start
.verd
);
fprintf(stderr
, ".back: %o ", linep
->start
.back
);
fprintf(stderr
, ".mcase: %o\n", linep
->start
.mcase
);
fprintf(stderr
, " end.col: %o ", linep
->end
.col
);
fprintf(stderr
, ".psize: %o ", linep
->end
.psize
);
fprintf(stderr
, ".railmag: %o ", linep
->end
.railmag
);
fprintf(stderr
, ".verd: %o ", linep
->end
.verd
);
fprintf(stderr
, ".back: %o ", linep
->end
.back
);
fprintf(stderr
, ".mcase: %o\n", linep
->end
.mcase
);
fprintf(stderr
, "len: %d\t", linep
->len
);
fprintf(stderr
, "codep: ");
for (i
= 0; i
< linep
->len
; i
++)
fprintf(stderr
, "%o ", linep
->codep
[i
] & 0377);