date and time created 83/11/11 14:54:02 by ralph
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 12 Nov 1983 06:54:02 +0000 (22:54 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 12 Nov 1983 06:54:02 +0000 (22:54 -0800)
SCCS-vsn: usr.bin/plot/crtdriver.c 4.1

usr/src/usr.bin/plot/crtdriver.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/plot/crtdriver.c b/usr/src/usr.bin/plot/crtdriver.c
new file mode 100644 (file)
index 0000000..ec86bac
--- /dev/null
@@ -0,0 +1,138 @@
+#ifndef lint
+static char sccsid[] = "@(#)crtdriver.c        4.1 (Berkeley) %G%";
+#endif
+
+/*
+This driver is used with crtplot.c.
+It is essentially the same driver as the one in /usr/src/cmd/plot.
+Unfortunately, the curses library has some of the same names as does
+as the functions that the driver calls.  These have been changed.
+
+Also, one of the commands has been removed since they don't make sense
+for crt's.
+*/
+
+
+#include <stdio.h>
+
+float deltx;
+float delty;
+
+main(argc,argv)  char **argv; {
+       int std=1;
+       FILE *fin;
+
+       while(argc-- > 1) {
+               if(*argv[1] == '-')
+                       switch(argv[1][1]) {
+                               case 'l':
+                                       deltx = atoi(&argv[1][2]) - 1;
+                                       break;
+                               case 'w':
+                                       delty = atoi(&argv[1][2]) - 1;
+                                       break;
+                               }
+
+               else {
+                       std = 0;
+                       if ((fin = fopen(argv[1], "r")) == NULL) {
+                               fprintf(stderr, "can't open %s\n", argv[1]);
+                               exit(1);
+                               }
+                       fplt(fin);
+                       }
+               argv++;
+               }
+       if (std)
+               fplt( stdin );
+       exit(0);
+       }
+
+
+fplt(fin)  FILE *fin; {
+       int c;
+       char s[256];
+       int xi,yi,x0,y0,x1,y1,r/*,dx,n,i*/;
+       /*int pat[256];*/
+
+       openpl();
+       while((c=getc(fin)) != EOF){
+               switch(c){
+               case 'm':
+                       xi = getsi(fin);
+                       yi = getsi(fin);
+                       plot_move(xi,yi);
+                       break;
+               case 'l':
+                       x0 = getsi(fin);
+                       y0 = getsi(fin);
+                       x1 = getsi(fin);
+                       y1 = getsi(fin);
+                       line(x0,y0,x1,y1);
+                       break;
+               case 't':
+                       gets(s,fin);
+                       label(s);
+                       break;
+               case 'e':
+                       plot_erase();
+                       break;
+               case 'p':
+                       xi = getsi(fin);
+                       yi = getsi(fin);
+                       point(xi,yi);
+                       break;
+               case 'n':
+                       xi = getsi(fin);
+                       yi = getsi(fin);
+                       cont(xi,yi);
+                       break;
+               case 's':
+                       x0 = getsi(fin);
+                       y0 = getsi(fin);
+                       x1 = getsi(fin);
+                       y1 = getsi(fin);
+                       space(x0,y0,x1,y1);
+                       break;
+               case 'a':
+                       xi = getsi(fin);
+                       yi = getsi(fin);
+                       x0 = getsi(fin);
+                       y0 = getsi(fin);
+                       x1 = getsi(fin);
+                       y1 = getsi(fin);
+                       arc(xi,yi,x0,y0,x1,y1);
+                       break;
+               case 'c':
+                       xi = getsi(fin);
+                       yi = getsi(fin);
+                       r = getsi(fin);
+                       circle(xi,yi,r);
+                       break;
+               case 'f':
+                       gets(s,fin);
+                       linemod(s);
+                       break;
+               default:
+                       fprintf(stderr, "Unknown command %c (%o)\n", c, c);
+                       break;
+                       }
+               }
+       closepl();
+       }
+getsi(fin)  FILE *fin; {       /* get an integer stored in 2 ascii bytes. */
+       short a, b;
+       if((b = getc(fin)) == EOF)
+               return(EOF);
+       if((a = getc(fin)) == EOF)
+               return(EOF);
+       a = a<<8;
+       return(a|b);
+}
+gets(s,fin)  char *s;  FILE *fin; {
+       for( ; *s = getc(fin); s++)
+               if(*s == '\n')
+                       break;
+       *s = '\0';
+       return;
+}