Blob


1 #include <string.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 #ifndef PI
6 #define PI 3.1415926535897932384626433832795028841971693993751
7 #endif
9 #define MAXWID 8.5 /* default limits max picture to 8.5 x 11; */
10 #define MAXHT 11 /* change to taste without peril */
12 #define dprintf if(dbg)printf
14 extern char errbuf[200];
15 #define ERROR sprintf(errbuf,
16 #define FATAL ), yyerror(errbuf), exit(1)
17 #define WARNING ), yyerror(errbuf)
19 #define DEFAULT 0
21 #define HEAD1 1
22 #define HEAD2 2
23 #define HEAD12 (HEAD1+HEAD2)
24 #define INVIS 4
25 #define CW_ARC 8 /* clockwise arc */
26 #define DOTBIT 16 /* line styles */
27 #define DASHBIT 32
28 #define FILLBIT 64 /* gray-fill on boxes, etc. */
30 #define CENTER 01 /* text attributes */
31 #define LJUST 02
32 #define RJUST 04
33 #define ABOVE 010
34 #define BELOW 020
35 #define SPREAD 040
37 #define SCALE 1.0 /* default scale: units/inch */
38 #define WID 0.75 /* default width for boxes and ellipses */
39 #define WID2 0.375
40 #define HT 0.5 /* default height and line length */
41 #define HT2 (HT/2)
42 #define HT5 (HT/5)
43 #define HT10 (HT/10)
45 /* these have to be like so, so that we can write */
46 /* things like R & V, etc. */
47 #define H 0
48 #define V 1
49 #define R_DIR 0
50 #define U_DIR 1
51 #define L_DIR 2
52 #define D_DIR 3
53 #define ishor(n) (((n) & V) == 0)
54 #define isvert(n) (((n) & V) != 0)
55 #define isright(n) ((n) == R_DIR)
56 #define isleft(n) ((n) == L_DIR)
57 #define isdown(n) ((n) == D_DIR)
58 #define isup(n) ((n) == U_DIR)
60 typedef float ofloat; /* for o_val[] in obj; could be double */
62 typedef struct obj { /* stores various things in variable length */
63 int o_type;
64 int o_count; /* number of things */
65 int o_nobj; /* index in objlist */
66 int o_mode; /* hor or vert */
67 float o_x; /* coord of "center" */
68 float o_y;
69 int o_nt1; /* 1st index in text[] for this object */
70 int o_nt2; /* 2nd; difference is #text strings */
71 int o_attr; /* HEAD, CW, INVIS, etc., go here */
72 int o_size; /* linesize */
73 int o_nhead; /* arrowhead style */
74 struct symtab *o_symtab; /* symtab for [...] */
75 float o_ddval; /* value of dot/dash expression */
76 float o_fillval; /* gray scale value */
77 ofloat o_val[1]; /* actually this will be > 1 in general */
78 /* type is not always FLOAT!!!! */
79 } obj;
81 typedef union { /* the yacc stack type */
82 int i;
83 char *p;
84 obj *o;
85 double f;
86 struct symtab *st;
87 } YYSTYPE;
89 extern YYSTYPE yylval, yyval;
91 struct symtab {
92 char *s_name;
93 int s_type;
94 YYSTYPE s_val;
95 struct symtab *s_next;
96 };
98 typedef struct { /* attribute of an object */
99 int a_type;
100 int a_sub;
101 YYSTYPE a_val;
102 } Attr;
104 typedef struct {
105 int t_type; /* CENTER, LJUST, etc. */
106 char t_op; /* optional sign for size changes */
107 char t_size; /* size, abs or rel */
108 char *t_val;
109 } Text;
111 #define String 01
112 #define Macro 02
113 #define File 04
114 #define Char 010
115 #define Thru 020
116 #define Free 040
118 typedef struct { /* input source */
119 int type; /* Macro, String, File */
120 char *sp; /* if String or Macro */
121 } Src;
123 extern Src src[], *srcp; /* input source stack */
125 typedef struct {
126 FILE *fin;
127 char *fname;
128 int lineno;
129 } Infile;
131 extern Infile infile[], *curfile;
133 #define MAXARGS 20
134 typedef struct { /* argument stack */
135 char *argstk[MAXARGS]; /* pointers to args */
136 char *argval; /* points to space containing args */
137 } Arg;
139 extern int dbg;
140 extern obj **objlist;
141 extern int nobj, nobjlist;
142 extern Attr *attr;
143 extern int nattr, nattrlist;
144 extern Text *text;
145 extern int ntextlist;
146 extern int ntext;
147 extern int ntext1;
148 extern double curx, cury;
149 extern int hvmode;
150 extern int codegen;
151 extern int PEseen;
152 extern double deltx, delty;
153 extern int lineno;
154 extern int synerr;
156 extern double xmin, ymin, xmax, ymax;
158 struct pushstack {
159 double p_x;
160 double p_y;
161 int p_hvmode;
162 double p_xmin;
163 double p_ymin;
164 double p_xmax;
165 double p_ymax;
166 struct symtab *p_symtab;
167 };
168 extern struct pushstack stack[];
169 extern int nstack;
170 extern int cw;
173 #define Log10(x) errcheck(log10(x), "log")
174 #define Exp(x) errcheck(exp(x), "exp")
175 #define Sqrt(x) errcheck(sqrt(x), "sqrt")
178 char* addnewline(char *p) /* add newline to end of p */;
179 obj* addpos(obj *p, obj *q);
180 void addtattr(int sub) /* add text attrib to existing item */;
181 void arc(double xc, double yc, double x0, double y0, double x1, double y1) /* draw arc with center xc,yc */;
182 void arc_extreme(double x0, double y0, double x1, double y1, double xc, double yc);
183 obj* arcgen(int type) /* handles circular and (eventually) elliptical arcs */;
184 void arrow(double x0, double y0, double x1, double y1, double w, double h, double ang, int nhead) /* draw arrow (without shaft) */ /* head wid w, len h, rotated ang */ /* and drawn with nhead lines */;
185 int baldelim(int c, char *s) /* replace c by balancing entry in s */;
186 void blockadj(obj *p) /* adjust coords in block starting at p */;
187 obj* blockgen(obj *p, obj *q) /* handles [...] */;
188 obj* boxgen(void);
189 void checkscale(char *s) /* if s is "scale", adjust default variables */;
190 obj* circgen(int type);
191 void copy(void) /* begin input from file, etc. */;
192 void copydef(struct symtab *p) /* remember macro symtab ptr */;
193 void copyfile(char *s) /* remember file to start reading from */;
194 struct symtab* copythru(char *s) /* collect the macro name or body for thru */;
195 void copyuntil(char *s) /* string that terminates a thru */;
196 int curdir(void) /* convert current dir (hvmode) to RIGHT, LEFT, etc. */;
197 void definition(char *s) /* collect definition for s and install */ /* definitions picked up lexically */;
198 char* delimstr(char *s) /* get body of X ... X */ /* message if too big */;
199 void do_thru(void) /* read one line, make into a macro expansion */;
200 void dodef(struct symtab *stp) /* collect args and switch input to defn */;
201 void dot(void);
202 void dotbox(double x0, double y0, double x1, double y1, int ddtype, double ddval) /* dotted or dashed box */;
203 void dotext(obj *p) /* print text strings of p in proper vertical spacing */;
204 void dotline(double x0, double y0, double x1, double y1, int ddtype, double ddval);
205 void dotline(double x0, double y0, double x1, double y1, int ddtype, double ddval) /* dotted line */;
206 void ellipse(double x, double y, double r1, double r2);
207 void endfor(void) /* end one iteration of for loop */;
208 void eprint(void) /* try to print context around error */;
209 double errcheck(double x, char *s);
210 void exprsave(double f);
211 void extreme(double x, double y) /* record max and min x and y values */;
212 void fillend(void);
213 void fillstart(double v) /* only choose black, light grey (.75), or white, for now */;
214 obj* fixpos(obj *p, double x, double y);
215 void forloop(char *, double, double, int, double, char *) /* set up a for loop */;
216 void fpecatch(int arg);
217 void freedef(char *s) /* free definition for string s */;
218 void freesymtab(struct symtab *p) /* free space used by symtab at p */;
219 int getarg(char *p) /* pick up single argument, store in p, return length */;
220 YYSTYPE getblk(obj *p, char *s) /* find union type for s in p */;
221 double getblkvar(obj *p, char *s) /* find variable s2 in block p */;
222 obj* getblock(obj *p, char *s) /* find variable s in block p */;
223 double getcomp(obj *p, int t) /* return component of a position */;
224 void getdata(void);
225 obj* getfirst(int n, int t) /* find n-th occurrence of type t */;
226 double getfval(char *s) /* return float value of variable s */;
227 obj* gethere(void) /* make a place for curx,cury */;
228 obj* getlast(int n, int t) /* find n-th previous occurrence of type t */;
229 obj* getpos(obj *p, int corner) /* find position of point */;
230 YYSTYPE getvar(char *s) /* return value of variable s (usually pointer) */;
231 char * grow(char *ptr, char *name, int num, int size) /* make array bigger */;
232 char* ifstat(double expr, char *thenpart, char *elsepart);
233 int input(void);
234 void label(char *s, int t, int nh) /* text s of type t nh half-lines up */;
235 obj* leftthing(int c) /* called for {... or [... */ /* really ought to be separate functions */;
236 obj* linegen(int type);
237 struct symtab* lookup(char *s) /* find s in symtab */;
238 int main(int argc, char **argv);
239 void makeattr(int type, int sub, YYSTYPE val) /* add attribute type and val */;
240 obj* makebetween(double f, obj *p1, obj* p2) /* make position between p1 and p2 */;
241 void makefattr(int type, int sub, double f) /* double attr */;
242 void makeiattr(int type, int i) /* int attr */;
243 obj* makenode(int type, int n);
244 void makeoattr(int type, obj *o) /* obj* attr */;
245 obj* makepos(double x, double y) /* make a position cell */;
246 void maketattr(int sub, char *p) /* text attribute: takes two */;
247 struct symtab* makevar(char *s, int t, YYSTYPE v) /* make variable named s in table */ /* assumes s is static or from tostring */;
248 void makevattr(char *p) /* varname attribute */;
249 obj* movegen(void);
250 int nextchar(void);
251 void nextfor(void) /* do one iteration of a for loop */;
252 void pbstr(char *s);
253 void popsrc(void) /* restore an old one */;
254 void print(void);
255 void printexpr(double f) /* print expression for debugging */;
256 void printlf(int line, char *name);
257 void printpos(obj *p) /* print position for debugging */;
258 void pushsrc(int type, char *ptr) /* new input source */;
259 int quadrant(double x, double y);
260 void reset(void);
261 void resetvar(void) /* reset variables listed */;
262 obj* rightthing(obj *p, int c) /* called for ... ] or ... } */;
263 void savetext(int t, char *s) /* record text elements for current object */;
264 void setdefaults(void) /* set default sizes for variables like boxht */;
265 int setdir(int n) /* set direction (hvmode) from LEFT, RIGHT, etc. */;
266 void setfval(char *s, double f) /* set variable s to f */;
267 void shell_exec(void) /* do it */;
268 void shell_init(void) /* set up to interpret a shell command */;
269 void shell_text(char *s) /* add string to command being collected */;
270 void space(double x0, double y0, double x1, double y1) /* set limits of page */;
271 void spline(double x, double y, double/*sic*/ n, float *p, int dashed, double ddval);
272 char* sprintgen(char *fmt);
273 obj* subpos(obj *p, obj *q);
274 obj* textgen(void);
275 char* tostring(char *s);
276 void troff(char *s);
277 obj* troffgen(char *s) /* save away a string of troff commands */;
278 void undefine(char *s) /* undefine macro */;
279 int unput(int c);
280 int whatpos(obj *p, int corner, double *px, double *py) /* what is the position (no side effect) */;
281 void yyerror(char *s);
282 int yyparse(void);
284 #include "tex.h"