home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / quickplot / part2 / read_stream.c < prev   
Encoding:
C/C++ Source or Header  |  1986-11-30  |  3.2 KB  |  156 lines

  1. /* :set tabstops=4                                                    */
  2. static char *RCSid = "$Header: read_stream.c,v 1.1 86/04/20 16:16:49 sysad Exp $";
  3.  
  4. /*
  5.  * $Log:    read_stream.c,v $
  6.  * Revision 1.1  86/04/20  16:16:49  sysad
  7.  * Initial distribution version
  8.  * 
  9.  * 
  10.  */
  11.  
  12.  
  13. /* It is the intent of the author that this software may be distributed
  14.  * and used freely, without restriction.  If you make improvements or
  15.  * enhancements, I would appreciate a copy.
  16.  *
  17.  * Duane H. Hesser    Teltone Corporation
  18.  * ....uw-beaver!tikal!sysad
  19.  * ....uw-beaver!tikal!dhh
  20.  */
  21.  
  22. #include "defs.h"
  23. #include "extern.h"
  24.  
  25. read_stream(source)
  26. struct inbuf *source;
  27. {
  28.     char c;
  29.     char string[256],ebuf[64];
  30.     int len,got;
  31.     short x0,y0,x1,y1,r;
  32.     char getbyte();
  33.     short getshort();
  34.  
  35.     got = 0;
  36. #ifdef QUICKPLOT
  37.     linemask = plotchar;
  38. #endif
  39.     while((c = getbyte(source)) && !eof(source))
  40.     {
  41.         ++got;
  42.         switch(c)
  43.         {
  44.             case 'm':
  45.                 curx = getshort(source);
  46.                 cury = getshort(source);
  47.                 move(curx,cury);
  48.                 break;
  49.             
  50.             case 'n':
  51.                 curx = getshort(source);
  52.                 cury = getshort(source);
  53.                 cont(curx,cury);
  54.                 break;
  55.             
  56.             case 'p':
  57.                 curx = getshort(source);
  58.                 cury = getshort(source);
  59.                 move(curx,cury);
  60.                 point(curxdot,curydot);
  61.                 break;
  62.             
  63.             case 'l':
  64.                 x1 = getshort(source);
  65.                 y1 = getshort(source);
  66.                 curx = getshort(source);
  67.                 cury = getshort(source);
  68.                 line(x1,y1,curx,cury);
  69.                 break;
  70.             
  71.             case 't':
  72.                 len = getstr(source,string);
  73.                 label(string,len);
  74.                 break;
  75.             
  76.             case 'a':
  77.                 curx = getshort(source);
  78.                 cury = getshort(source);
  79.                 x0 = getshort(source);
  80.                 y0 = getshort(source);
  81.                 x1 = getshort(source);
  82.                 y1 = getshort(source);
  83.                 arc(curx,cury,x0,y0,x1,y1);
  84.                 /* The manual doesn't specify this, but it seems
  85.                  * the most reasonable thing to do.
  86.                  */
  87.                 move(curx,cury);
  88.                 break;
  89.             
  90.             case 'c':
  91.                 x1 = getshort(source);
  92.                 y1 = getshort(source);
  93.                 r = getshort(source);
  94.                 circle(x1,y1,r);
  95.                 /* (x1,y1) becomes current point                    */
  96.                 break;
  97.             
  98.             case 'e':
  99.                 return(-got); /* negative got triggers erase        */
  100.                 break;
  101.             break;
  102.             
  103.             case 'f':
  104.                 --got;
  105.                 len = getstr(source,string);
  106.                 if(!len) break;
  107.  
  108. #ifdef DEBUG
  109.                 if(debug & 1) printf("linemask=%s",string);
  110. #endif
  111. #ifdef QUICKPLOT
  112.                 if(strcmp(string,"solid") == 0)
  113.                     linemask = plotchar;
  114.                 else if(strcmp(string,"dotted") == 0)
  115.                     linemask = '2';
  116.                 else if(strcmp(string,"shortdashed") == 0)
  117.                     linemask = '3';
  118.                 else if(strcmp(string,"longdashed") == 0)
  119.                     linemask = '4';
  120.                 else if(strcmp(string,"dotdashed") == 0)
  121.                     linemask = '5';
  122.                 break;
  123. #else
  124.                 if(strcmp(string,"solid") == 0)
  125.                     linemask = SOLID;
  126.                 else if(strcmp(string,"dotted") == 0)
  127.                     linemask = DOTTED;
  128.                 else if(strcmp(string,"shortdashed") == 0)
  129.                     linemask = SHORTDASHED;
  130.                 else if(strcmp(string,"longdashed") == 0)
  131.                     linemask = LONGDASHED;
  132.                 else if(strcmp(string,"dotdashed") == 0)
  133.                     linemask = DOTDASHED;
  134.                 break;
  135. #endif QUICKPLOT
  136.             
  137.             case 's':
  138.                 --got;
  139.                 x0 = getshort(source);
  140.                 y0 = getshort(source);
  141.                 x1 = getshort(source);
  142.                 y1 = getshort(source);
  143.                 space(x0,y0,x1,y1);
  144.                 break;
  145.             default:
  146.                 --got;
  147.                 sprintf(ebuf,"bad input data: cmd (0%o)\n",c);
  148.                 write(2,ebuf,strlen(ebuf));
  149.                 break;
  150.         }
  151.     }
  152.     /* return the number of commands decoded                        */
  153.     return(--got > 0 ? got : 0);
  154. }
  155.  
  156.