1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 int max_x=1024, max_y=780;
6 extern float f_fx, f_fy;
7 #define SX(x) (int)(f_fx*(float)(x))
8 
9 int linbw[]={0,2,4,3,1};
10 int lincol[]={0,1,2,3,4};
11 char linchar[]={96,'a','b','c','d','e','f','g'};
12 int *linarr;
13 int nlinarr=5;
14 
15 float fxscal, fyscal, fxoff, fyoff;
16 
openpl()17 openpl()
18 {
19 	printf("\033\014\n");
20 	printf("\035");		/* send ESC FF GS */
21 	linarr = linbw;
22 	linetype(0);
23 	}
24 
linetype(type)25 linetype(type)
26 	int type;
27 {
28 	printf("\033%c",linchar[type]);
29 	}
30 
clsline()31 clsline() {}
32 
closepl()33 closepl()
34 {
35 	move(0,0);
36 	putchar('\r');
37 	}
38 
space(x0,y0,x1,y1)39 space(x0,y0,x1,y1)
40 	int x0, x1, y0, y1;
41 {
42 	fxoff = (float)x0;
43 	fyoff = (float)y0;
44 	fxscal = (float)(max_x)/(float)(x1-x0);
45 	fyscal = (float)(max_y)/(float)(y1-y0);
46 	}
47 
move(x,y)48 move(x,y)
49 	int x, y;
50 {
51 	int xx, yy;
52 	xx = (int)(((float)(x)-fxoff)*fxscal);
53 	yy = (int)(((float)(y)-fyoff)*fyscal);
54 	fputc(0x1d,stdout);
55 	fputc(((yy&0x3e0)>>5)+0x20,stdout);
56 	fputc((yy&0x1f)+0x60,stdout);
57 	fputc(((xx&0x3e0)>>5)+0x20,stdout);
58 	fputc((xx&0x1f)+0x40,stdout);
59 	}
60 
cont(x,y)61 cont(x,y)
62 	int x, y;
63 {
64 	int xx, yy;
65 	xx = (int)(((float)(x)-fxoff)*fxscal);
66 	yy = (int)(((float)(y)-fyoff)*fyscal);
67 	fputc(((yy&0x3e0)>>5)+0x20,stdout);
68 	fputc((yy&0x1f)+0x60,stdout);
69 	fputc(((xx&0x3e0)>>5)+0x20,stdout);
70 	fputc((xx&0x1f)+0x40,stdout);
71 	}
72 
drawstr(str)73 drawstr(str)
74 	char *str;
75 {
76  	fputc(0x1f,stdout);
77 	fputs(str,stdout);
78 	fputc(0x1d,stdout);
79 	}
80 
81 int tarr[] = {10,20,50,100,200,500,1000,2000,5000};
82 int ntarr = sizeof(tarr);
xaxis(int n,char * title)83 xaxis(int n, char *title)
84 {
85   int i, jm, tick;
86   int js;
87   char numstr[20];
88 
89   tick = -20;
90 
91   for (i=0; i<ntarr; i++) if ((jm = n/tarr[i])<21) goto found;
92   jm = n/5000l; i=ntarr-1;
93  found:	js = tarr[i];
94 
95   for (i=1; i<=jm; i++) {
96     move(SX(i*js),0);
97     cont(SX(i*js),tick);
98   }
99 
100   sprintf(numstr,"%d",js);
101   move(SX(js)-20,tick-40);
102   drawstr(numstr);
103   sprintf(numstr,"%d",jm*js);
104   move(SX(jm*js)-20,tick-40);
105   drawstr(numstr);
106   i = tick-60;
107   move(SX(n/2)-strlen(title)*8,i);
108   drawstr(title);
109 }
110