Annotation of researchv10no/cmd/basic/bas/plot.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include "typedef.h"
                      3: #include "basic.h"
                      4: 
                      5: #define MAXPLOT        32      /* number of bytes in plot buffer */
                      6: #define SFLAG          035
                      7: #define EFLAG          0377
                      8: #define CLEAR          030
                      9: #define UP             0
                     10: #define DOWN           1
                     11: 
                     12: #define LIMIT          1024.   /* Screen limit */
                     13: #define XMAX           280
                     14: #define YMAX           192
                     15: #define XSCALE         (LIMIT/XMAX)
                     16: #define YSCALE         (LIMIT/YMAX)
                     17: 
                     18: static struct plotinfo {
                     19:        int             p_des;          /* plot file descriptor */
                     20:        char            *p_file;        /* the plot file name */
                     21:        char            p_buff[MAXPLOT];        /* the plot buffer */
                     22:        int             p_pen;          /* current pen position */
                     23:        char            *p_ptr;         /* plot buffer pointer */
                     24:        int             p_x;            /* current x position */
                     25:        int             p_y;            /* current y position */
                     26:        }       p;
                     27: 
                     28: 
                     29: /*
                     30:  * pltini --- initialize the plot structure
                     31:  */
                     32: 
                     33: pltini(file)
                     34: char   *file;
                     35: {
                     36:        if (p.p_des > 0)
                     37:                pltcls();       /* close it if open */
                     38:        if (file == NULL)
                     39:                file = p.p_file;
                     40:        if (file == NULL)
                     41:                file = "!plot";
                     42:        if (file[0] == '!')
                     43:                p.p_des = pipeout("/bin/sh", "sh", "-c", &file[1], 0);
                     44:        else
                     45:                p.p_des = creat(file, 0666);
                     46:        if (p.p_des < 0)
                     47:                err("cannot open %s for plotting", file);
                     48:        p.p_ptr = p.p_buff;
                     49:        p.p_pen = UP;
                     50:        p.p_file = file;
                     51: }
                     52: 
                     53: 
                     54: /*
                     55:  * pltcls --- close the plot file
                     56:  */
                     57: 
                     58: pltcls()
                     59: {
                     60: 
                     61:        if (p.p_des > 0) {
                     62:                penup();
                     63:                pltflush();
                     64:                close(p.p_des);
                     65:                }
                     66:        p.p_des = 0;
                     67: }
                     68: 
                     69: 
                     70: /*
                     71:  * pltflush --- flush the plot buffer
                     72:  */
                     73: 
                     74: pltflush()
                     75: {
                     76:        register int    l;
                     77: 
                     78:        l = p.p_ptr - p.p_buff;
                     79:        if (l)
                     80:                if (write(p.p_des, p.p_buff, l) < 0)
                     81:                        err("write error during plotting");
                     82:        p.p_ptr = p.p_buff;
                     83: }
                     84: 
                     85: 
                     86: /*
                     87:  * plot --- move the pen to the specified coordinates
                     88:  */
                     89: 
                     90: plot(x, y)
                     91: {
                     92:        register int    ix, iy;
                     93: 
                     94:        if (tflg)
                     95:                fprintf(stderr, "plot %d %d\n", x, y);
                     96:        if (x < 0 || x >= XMAX)
                     97:                err("invalid x co-ordinate %d", x);
                     98:        if (y < 0 || y >= YMAX)
                     99:                err("invalid y co-ordinate %d", y);
                    100:        if (p.p_pen == DOWN) {
                    101:                ix = x * XSCALE;
                    102:                iy = (YMAX - y) * YSCALE;
                    103:                plotc((ix >> 6) & 077);
                    104:                plotc(ix & 077);
                    105:                plotc((iy >> 6) & 077);
                    106:                plotc(iy & 077);
                    107:                }
                    108:        p.p_x = x;
                    109:        p.p_y = y;
                    110: }
                    111: 
                    112: 
                    113: /*
                    114:  * plotc --- enter a character into the plot buffer
                    115:  */
                    116: 
                    117: plotc(ch)
                    118: {
                    119: 
                    120:        *p.p_ptr++ = ch;
                    121:        if (p.p_ptr >= &p.p_buff[MAXPLOT])
                    122:                pltflush();
                    123: }
                    124: 
                    125: 
                    126: /*
                    127:  * penup --- raise the pen
                    128:  */
                    129: 
                    130: penup()
                    131: {
                    132: 
                    133:        if (p.p_pen == DOWN)
                    134:                plotc(EFLAG);
                    135:        p.p_pen = UP;
                    136:        pltflush();
                    137: }
                    138: 
                    139: 
                    140: /*
                    141:  * pendn --- lower the pen
                    142:  */
                    143: 
                    144: pendn()
                    145: {
                    146: 
                    147:        if (p.p_pen == UP) {
                    148:                plotc(SFLAG);
                    149:                p.p_pen = DOWN;
                    150:                plot(p.p_x, p.p_y);
                    151:                }
                    152: }
                    153: 
                    154: 
                    155: /*
                    156:  * erase --- erase the plot display
                    157:  */
                    158: 
                    159: erase()
                    160: {
                    161: 
                    162:        penup();
                    163:        plotc(CLEAR);
                    164:        plotc(EFLAG);
                    165:        pltflush();
                    166: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.