4 #define MAXLINE 3600 /* maximum input line */
6 char *version
= "version Oct 24, 1991";
8 char in
[MAXLINE
+1]; /* input buffer */
20 int main(int argc
, char *argv
[])
25 if (p
= getenv("TYPESETTER"))
27 while (argc
> 1 && argv
[1][0] == '-') {
31 if (argv
[1][2] == '\0') {
33 printf("...\teqn %s\n", version
);
40 szstack
[0] = gsize
= atoi(&argv
[1][2]);
43 deltaps
= atoi(&argv
[1][2]);
47 minsize
= atoi(&argv
[1][2]);
50 strcpy(ftstack
[0].name
,&argv
[1][2]);
56 typesetter
= &argv
[1][2];
59 fprintf(stderr
, "%s: unknown option %s\n", cmdname
, argv
[1]);
66 sprintf(buf
, "\"%s\"", typesetter
);
67 install(deftbl
, strsave(typesetter
), strsave(buf
), 0);
68 init_tbl(); /* install other keywords in tables */
70 pushsrc(File
, curfile
->fname
);
73 curfile
->fname
= strsave("-");
77 if (strcmp(*++argv
, "-") == 0)
79 else if ((curfile
->fin
= fopen(*argv
, "r")) == NULL
)
80 ERROR
"can't open file %s", *argv FATAL
;
81 curfile
->fname
= strsave(*argv
);
83 if (curfile
->fin
!= stdin
)
90 * initialize data for particular typesetter
91 * the minsize could profitably come from the
92 * troff description file /usr/lib/font/dev.../DESC.out
96 if (strcmp(s
, "202") == 0) {
99 } else if (strcmp(s
, "aps") == 0) {
102 } else if (strcmp(s
, "cat") == 0) {
105 } else if (strcmp(s
, "post") == 0) {
121 printf(".lf 1 %s\n", curfile
->fname
);
122 while ((type
= getlinex(in
)) != EOF
) {
123 if (in
[0] == '.' && in
[1] == 'E' && in
[2] == 'Q') {
124 for (i
= 11; i
< 100; i
++)
127 if (markline
) { /* turn off from last time */
128 printf(".nr MK 0\n");
136 printf(".nr MK %d\n", markline
); /* for -ms macros */
137 printf(".if %gm>\\n(.v .ne %gm\n", eqnht
, eqnht
);
138 printf(".rn %d 10\n", eqnreg
);
140 printf("\\&\\*(10\n");
143 while (putchar(input()) != '\n')
145 printf(".lf %d\n", curfile
->lineno
+1);
147 else if (type
== lefteq
)
149 else if (in
[0] == '.' && in
[1] == 'l' && in
[2] == 'f') {
150 if (sscanf(in
+3, "%d %s", &ln
, fname
) == 2) {
151 free(curfile
->fname
);
152 printf(".lf %d %s\n", curfile
->lineno
= ln
, curfile
->fname
= strsave(fname
));
154 printf(".lf %d\n", curfile
->lineno
= ln
);
161 int getlinex(char *s
)
165 while ((c
=input()) != '\n' && c
!= EOF
&& c
!= lefteq
) {
166 if (s
>= in
+MAXLINE
) {
167 ERROR
"input line too long: %.20s\n", in WARNING
;
185 printf(".nr %d \\n(.s\n", sz1
= salloc());
187 printf(".rm %d \n", ds
);
191 printf(".as %d \"%s\n", ds
, in
);
195 printf(".as %d \\*(%d\n", ds
, eqnreg
);
197 printf(".lf %d\n", curfile
->lineno
+1);
199 } while (getlinex(in
) == lefteq
);
201 printf(".as %d \"%s", ds
, in
);
203 printf("\\s\\n(%d", sz1
);
204 printf("\\*(%d\n", ds
);
205 printf(".lf %d\n", curfile
->lineno
+1);
206 if (curfile
->lineno
> n
+3)
207 fprintf(stderr
, "eqn warning: multi-line %c...%c, file %s:%d,%d\n",
208 lefteq
, righteq
, curfile
->fname
, n
, curfile
->lineno
);
216 double before
, after
;
217 extern double BeforeSub
, AfterSub
;
219 dprintf(".\tanswer <- S%d, h=%g,b=%g\n",p1
, eht
[p1
], ebase
[p1
]);
221 before
= eht
[p1
] - ebase
[p1
] - BeforeSub
; /* leave room for sub or superscript */
222 after
= ebase
[p1
] - AfterSub
;
223 if (spaceval
|| before
> 0.01 || after
> 0.01) {
224 printf(".ds %d ", p1
); /* used to be \\x'0' here: why? */
225 if (spaceval
!= NULL
)
226 printf("\\x'0-%s'", spaceval
);
227 else if (before
> 0.01)
228 printf("\\x'0-%gm'", before
);
229 printf("\\*(%d", p1
);
230 if (spaceval
== NULL
&& after
> 0.01)
231 printf("\\x'%gm'", after
);
235 printf(".ds %d %s\\*(%d\\s\\n(99\n", p1
, DPS(gsize
,gsize
), p1
);
237 if (spaceval
!= NULL
) {
251 if (szstack
[0] != 0) /* absolute gsize in effect */
252 printf(".nr 99 \\n(.s\n");
259 for (i
= 11; i
< 100; i
++)
264 ERROR
"no eqn strings left (%d)", i FATAL
;
273 void nrwid(int n1
, int p
, int n2
)
275 printf(".nr %d 0\\w'%s\\*(%d'\n", n1
, DPS(gsize
,p
), n2
); /* 0 defends against - width */
278 char *ABSPS(int dn
) /* absolute size dn in printable form \sd or \s(dd (dd >= 40) */
280 static char buf
[100], *lb
= buf
;
283 if (lb
> buf
+ sizeof(buf
) - 10)
288 if (dn
>= 10) { /* \s(dd only works in new troff */
300 char *DPS(int f
, int t
) /* delta ps (t-f) in printable form \s+d or \s-d or \s+-(dd */
302 static char buf
[100], *lb
= buf
;
306 if (lb
> buf
+ sizeof(buf
) - 10)
311 dn
= EFFPS(t
) - EFFPS(f
);
312 if (szstack
[nszstack
] != 0) /* absolute */
313 dn
= EFFPS(t
); /* should do proper \s(dd */
320 if (dn
>= 10) { /* \s+(dd only works in new troff */
331 int EFFPS(int n
) /* effective value of n */
339 double EM(double m
, int ps
) /* convert m to ems in gsize */
341 m
*= (double) EFFPS(ps
) / gsize
;
342 if (m
<= 0.001 && m
>= -0.001)
348 double REL(double m
, int ps
) /* convert m to ems in ps */
350 m
*= (double) gsize
/ EFFPS(ps
);
351 if (m
<= 0.001 && m
>= -0.001)