Skip to content

Commit e28cb32

Browse files
committed
txt: a new post-processor for testing neatroff
1 parent 50893f2 commit e28cb32

File tree

2 files changed

+205
-2
lines changed

2 files changed

+205
-2
lines changed

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ CFLAGS = -Wall -O2 "-DTROFFFDIR=\"$(FDIR)\""
66
LDFLAGS =
77
OBJS = post.o ps.o font.o dev.o clr.o dict.o iset.o sbuf.o
88
OBJSPDF = post.o pdf.o pdfext.o font.o dev.o clr.o dict.o iset.o sbuf.o
9+
OBJSTXT = post.o txt.o font.o dev.o clr.o dict.o iset.o sbuf.o
910

10-
all: post pdf
11+
all: post pdf txt
1112
%.o: %.c post.h
1213
$(CC) -c $(CFLAGS) $<
1314
post: $(OBJS)
1415
$(CC) -o $@ $(OBJS) $(LDFLAGS)
1516
pdf: $(OBJSPDF)
1617
$(CC) -o $@ $(OBJSPDF) $(LDFLAGS)
18+
txt: $(OBJSTXT)
19+
$(CC) -o $@ $(OBJSTXT) $(LDFLAGS)
1720
clean:
18-
rm -f *.o post pdf
21+
rm -f *.o post pdf txt

txt.c

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#include <ctype.h>
2+
#include <stdarg.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
#include "post.h"
7+
8+
static int o_f, o_s, o_m; /* font and size */
9+
static int o_h, o_v; /* current user position */
10+
static int p_wd, p_ht; /* page width and height in basic units */
11+
static int c_wdpt = 10, c_htpt = 12; /* glyph cell width and height in points */
12+
static int c_wd, c_ht; /* glyph cell width and height in basic units */
13+
static int p_cwd, p_cht; /* page dimentions in cells */
14+
static char *o_pg; /* output page buffer */
15+
16+
void outgname(int g)
17+
{
18+
}
19+
20+
void outpage(void)
21+
{
22+
o_v = 0;
23+
o_h = 0;
24+
}
25+
26+
/* calls o_flush() if necessary */
27+
void out(char *s, ...)
28+
{
29+
va_list ap;
30+
va_start(ap, s);
31+
vfprintf(stdout, s, ap);
32+
va_end(ap);
33+
}
34+
35+
void outc(char *c)
36+
{
37+
struct glyph *g = dev_glyph(c, o_f);
38+
int v = o_v / c_ht - 1;
39+
int h = o_h / c_wd;
40+
if (h >= 0 && v >= 0 && h < p_cwd && v < p_cht)
41+
o_pg[v * p_cwd + h] = g->name[0];
42+
}
43+
44+
void outh(int h)
45+
{
46+
o_h = h;
47+
}
48+
49+
void outv(int v)
50+
{
51+
o_v = v;
52+
}
53+
54+
void outrel(int h, int v)
55+
{
56+
o_h += h;
57+
o_v += v;
58+
}
59+
60+
void outfont(int f)
61+
{
62+
if (dev_font(f))
63+
o_f = f;
64+
}
65+
66+
void outmnt(int f)
67+
{
68+
}
69+
70+
void outsize(int s)
71+
{
72+
if (s > 0)
73+
o_s = s;
74+
}
75+
76+
void outcolor(int c)
77+
{
78+
o_m = c;
79+
}
80+
81+
void outrotate(int deg)
82+
{
83+
}
84+
85+
void drawmbeg(char *s)
86+
{
87+
}
88+
89+
void drawmend(char *s)
90+
{
91+
}
92+
93+
void drawbeg(void)
94+
{
95+
}
96+
97+
void drawend(int close, int fill)
98+
{
99+
}
100+
101+
void drawl(int h, int v)
102+
{
103+
outrel(h, v);
104+
}
105+
106+
void drawc(int c)
107+
{
108+
outrel(c, 0);
109+
}
110+
111+
void drawe(int h, int v)
112+
{
113+
outrel(h, 0);
114+
}
115+
116+
void drawa(int h1, int v1, int h2, int v2)
117+
{
118+
outrel(h1 + h2, v1 + v2);
119+
}
120+
121+
void draws(int h1, int v1, int h2, int v2)
122+
{
123+
outrel(h1, v1);
124+
}
125+
126+
void outeps(char *eps, int hwid, int vwid)
127+
{
128+
}
129+
130+
void outpdf(char *pdf, int hwid, int vwid)
131+
{
132+
}
133+
134+
void outlink(char *lnk, int hwid, int vwid)
135+
{
136+
}
137+
138+
void outname(int n, char (*desc)[64], int *page, int *off)
139+
{
140+
}
141+
142+
void outmark(int n, char (*desc)[256], int *page, int *off, int *level)
143+
{
144+
}
145+
146+
void outinfo(char *kwd, char *val)
147+
{
148+
}
149+
150+
void outset(char *var, char *val)
151+
{
152+
if (!strcmp(var, "cellht"))
153+
c_htpt = atoi(val);
154+
if (!strcmp(var, "cellwd"))
155+
c_wdpt = atoi(val);
156+
}
157+
158+
void docpagebeg(int n)
159+
{
160+
memset(o_pg, 0, p_cwd * p_cht);
161+
if (n > 1)
162+
out(" \n");
163+
}
164+
165+
void docpageend(int n)
166+
{
167+
int lastln = 0;
168+
int i, j;
169+
for (i = 0; i < p_cht; i++)
170+
for (j = 0; j < p_cwd; j++)
171+
if (o_pg[i * p_cwd + j])
172+
lastln = i + 1;
173+
for (i = 0; i < lastln; i++) {
174+
int lastcol = 0;
175+
for (j = 0; j < p_cwd; j++)
176+
if (o_pg[i * p_cwd + j])
177+
lastcol = j + 1;
178+
for (j = 0; j < lastcol; j++) {
179+
int c = o_pg[i * p_cwd + j];
180+
printf("%c", c ? c : ' ');
181+
}
182+
printf("\n");
183+
}
184+
}
185+
186+
void doctrailer(int pages)
187+
{
188+
free(o_pg);
189+
}
190+
191+
void docheader(char *title, int pagewidth, int pageheight, int linewidth)
192+
{
193+
p_wd = pagewidth * dev_res / 254;
194+
p_ht = pageheight * dev_res / 254;
195+
c_wd = dev_res * c_wdpt / 72;
196+
c_ht = dev_res * c_htpt / 72;
197+
p_cwd = p_wd / c_wd;
198+
p_cht = p_ht / c_ht;
199+
o_pg = malloc(p_cwd * p_cht);
200+
}

0 commit comments

Comments
 (0)