11 double margin = MARGIN; /* extra space around edges */
12 extern double frame_ht, frame_wid, ticklen;
13 extern int just, sizeop, tick_dir;
14 extern double sizexpr, lab_up, lab_rt;
16 char graphname[50] = "Graph";
17 char graphpos[200] = "";
19 void print(void) /* arrange final output */
24 double dx, dy, xfac, yfac;
28 fclose(tfd); /* end the temp file */
32 if ((p=lookup("margin",0)) != NULL)
34 if (frame_ht < 0) /* wasn't set explicitly, so use default */
35 frame_ht = getvar(lookup("frameht", 0));
37 frame_wid = getvar(lookup("framewid", 0));
39 for (p = objlist; p; p = p->next) {
40 dprintf("print: name = <%s>, type = %d\n", p->name, p->type);
41 if (p->type == NAME) {
45 fprintf(tfd, "\t# %s %g .. %g, %g .. %g\n",
46 p->name, pt.x, pt1.x, pt.y, pt1.y);
49 ERROR "can't take log of x coord %g", pt.x FATAL;
55 ERROR "can't take log of y coord %g", pt.y FATAL;
59 if (!(p->coord & XFLAG)) {
64 if (!(p->coord & YFLAG)) {
69 if (autoticks && strcmp(p->name, dflt_coord) == 0) {
73 p->pt.x = pow(10.0, pt.x);
74 p->pt1.x = pow(10.0, pt1.x);
77 p->pt.y = pow(10.0, pt.y);
78 p->pt1.y = pow(10.0, pt1.y);
84 xfac = dx > 0 ? frame_wid/dx : frame_wid/2;
85 yfac = dy > 0 ? frame_ht/dy : frame_ht/2;
87 fprintf(tfd, "define xy_%s @ ", p->name);
89 fprintf(tfd, "\t(($1)-(%g))*%g", pt.x, xfac);
91 fprintf(tfd, "\t%g", xfac);
93 fprintf(tfd, ", (($2)-(%g))*%g @\n", pt.y, yfac);
95 fprintf(tfd, ", %g @\n", yfac);
96 fprintf(tfd, "define x_%s @ ", p->name);
98 fprintf(tfd, "\t(($1)-(%g))*%g @\n", pt.x, xfac);
100 fprintf(tfd, "\t%g @\n", xfac);
101 fprintf(tfd, "define y_%s @ ", p->name);
103 fprintf(tfd, "\t(($1)-(%g))*%g @\n", pt.y, yfac);
105 fprintf(tfd, "\t%g @\n", yfac);
110 if (codegen && autoticks && dfp)
113 if ((fd = fopen(tempfile, "r")) != NULL) {
114 while ((c = getc(fd)) != EOF)
121 void endstat(void) /* clean up after each statement */
125 lab_up = lab_rt = 0.0;
134 void graph(char *s) /* graph statement */
140 fprintf(stdout, "%s: [\n", graphname);
141 print(); /* pump out previous graph */
142 fprintf(stdout, "\n] %s\n", graphpos);
146 dprintf("into graph with <%s>\n", s);
149 while ((c = *s) == ' ' || c == '\t')
152 ERROR "no name on graph statement" WARNING;
153 if (!isupper((uchar)s[0]))
154 ERROR "graph name %s must be capitalized", s WARNING;
155 for (p=graphname; (c = *s) != ' ' && c != '\t' && c != '\0'; )
159 dprintf("graphname = <%s>, graphpos = <%s>\n", graphname, graphpos);
164 void setup(void) /* done at each .G1 */
166 static int firstG1 = 0;
170 frame_ht = frame_wid = -1; /* reset in frame() */
171 ticklen = getvar(lookup("ticklen", 0));
174 codegen = synerr = 0;
175 strcpy(graphname, "Graph");
176 strcpy(graphpos, "");
179 void do_first(void) /* done at first .G1: definitions, etc. */
182 extern char *lib_defines;
183 static char buf[100], buf1[100]; /* static because pbstr uses them */
186 snprintf(buf, sizeof buf, "define pid /%d/\n", getpid());
189 if ((fp = fopen(lib_defines, "r")) != NULL) {
190 snprintf(buf1, sizeof buf, "copy \"%s\"\n", lib_defines);
194 fprintf(stderr, "grap warning: can't open %s\n", lib_defines);
199 void reset(void) /* done at each "graph ..." statement */
201 Obj *p, *np, *deflist;
202 extern int tlist, toffside, autodir;
204 curr_coord = dflt_coord;
206 autoticks = LEFT|BOT;
208 tside = tlist = toffside = 0;
212 for (p = objlist; p; p = np) {
214 if (p->type == DEFNAME || p->type == VARNAME) {
231 if ((tfd = fopen(tempfile, "w")) == NULL) {
232 fprintf(stderr, "grap: can't open %s\n", tempfile);