[BACK]Return to dumb.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/dumb.trm, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2:  * $Id: dumb.trm,v 1.24 1998/04/14 00:17:37 drd Exp $
                      3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - dumb.trm */
                      7:
                      8: /*[
                      9:  * Copyright 1991 - 1993, 1998   Thomas Williams, Colin Kelley
                     10:  *
                     11:  * Permission to use, copy, and distribute this software and its
                     12:  * documentation for any purpose with or without fee is hereby granted,
                     13:  * provided that the above copyright notice appear in all copies and
                     14:  * that both that copyright notice and this permission notice appear
                     15:  * in supporting documentation.
                     16:  *
                     17:  * Permission to modify the software is granted, but not the right to
                     18:  * distribute the complete modified source code.  Modifications are to
                     19:  * be distributed as patches to the released version.  Permission to
                     20:  * distribute binaries produced by compiling modified sources is granted,
                     21:  * provided you
                     22:  *   1. distribute the corresponding source modifications from the
                     23:  *    released version in the form of a patch file along with the binaries,
                     24:  *   2. add special version identification to distinguish your version
                     25:  *    in addition to the base release version number,
                     26:  *   3. provide your name and address as the primary contact for the
                     27:  *    support of your modified version, and
                     28:  *   4. retain our contact information in regard to use of the base
                     29:  *    software.
                     30:  * Permission to distribute the released version of the source code along
                     31:  * with corresponding source modifications in the form of a patch file is
                     32:  * granted with same provisions 2 through 4 for binary distributions.
                     33:  *
                     34:  * This software is provided "as is" without express or implied warranty
                     35:  * to the extent permitted by applicable law.
                     36: ]*/
                     37:
                     38: /*
                     39:  * This file is included by ../term.c.
                     40:  *
                     41:  * This terminal driver supports:
                     42:  *   DUMB terminals
                     43:  *
                     44:  * AUTHORS
                     45:  *   Francois Pinard, 91-04-03
                     46:  *           INTERNET: pinard@iro.umontreal.ca
                     47:  *
                     48:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
                     49:  *
                     50:  */
                     51: #include "driver.h"
                     52:
                     53: #ifdef TERM_REGISTER
                     54: register_term(dumb_driver)
                     55: #endif
                     56:
                     57: #ifdef TERM_PROTO
                     58: TERM_PUBLIC void DUMB_options __PROTO((void));
                     59: TERM_PUBLIC void DUMB_init __PROTO((void));
                     60: TERM_PUBLIC void DUMB_graphics __PROTO((void));
                     61: TERM_PUBLIC void DUMB_text __PROTO((void));
                     62: TERM_PUBLIC void DUMB_reset __PROTO((void));
                     63: TERM_PUBLIC void DUMB_linetype __PROTO((int linetype));
                     64: TERM_PUBLIC void DUMB_move __PROTO((unsigned int x, unsigned int y));
                     65: TERM_PUBLIC void DUMB_point __PROTO((unsigned int x, unsigned int y,
                     66:                                     int point));
                     67: TERM_PUBLIC void DUMB_vector __PROTO((unsigned int x, unsigned int y));
                     68: TERM_PUBLIC void DUMB_put_text __PROTO((unsigned int x, unsigned int y,
                     69:                                        char *str));
                     70: TERM_PUBLIC void DUMB_arrow __PROTO((unsigned int sx, unsigned int sy,
                     71:                                     unsigned int ex, unsigned int ey,
                     72:                                     int head));
                     73:
                     74: #define DUMB_XMAX 79
                     75: #define DUMB_YMAX 24
                     76:
                     77: #endif /* TERM_PROTO */
                     78:
                     79: #ifdef TERM_BODY
                     80:
                     81: #define DUMB_AXIS_CONST '\1'
                     82: #define DUMB_BORDER_CONST '\2'
                     83:
                     84: /* matrix of characters */
                     85: static char *dumb_matrix = NULL;
                     86: /* matrix of priority at each position */
                     87: static char *dumb_priority = NULL;
                     88: /* current character used to draw */
                     89: static char dumb_pen;
                     90: /* current X position */
                     91: static int dumb_x;
                     92: /* current Y position */
                     93: static int dumb_y;
                     94: static int dumb_xmax = DUMB_XMAX;
                     95: static int dumb_ymax = DUMB_YMAX;
                     96: static int dumb_feed = 1;
                     97:
                     98: #define DUMB_PIXEL(x,y) dumb_matrix[dumb_xmax*(y)+(x)]
                     99:
                    100: static void dumb_set_pixel __PROTO((int x, int y, int v, int p));
                    101:
                    102:
                    103: static void dumb_set_pixel(x, y, v, p)
                    104: int x, y, v, p;
                    105: {
                    106:     if ((unsigned) x <= dumb_xmax &&   /* ie x>=0 && x<=dumb_xmax */
                    107:        (unsigned) y <= dumb_ymax &&
                    108:        p > dumb_priority[dumb_xmax * y + x]) {
                    109:        dumb_matrix[dumb_xmax * y + x] = v;
                    110:        dumb_priority[dumb_xmax * y + x] = p;
                    111:     }
                    112: }
                    113:
                    114:
                    115: TERM_PUBLIC void DUMB_options()
                    116: {
                    117:     int x, y;
                    118:     struct value a;
                    119:
                    120:     if (almost_equals(c_token, "f$eed"))
                    121:        ++c_token, dumb_feed = 1;
                    122:     else if (almost_equals(c_token, "nof$eed"))
                    123:        ++c_token, dumb_feed = 0;
                    124:
                    125:     if (!END_OF_COMMAND) {
                    126:        x = (int) real(const_express(&a));
                    127:        if (!END_OF_COMMAND) {
                    128:            y = (int) real(const_express(&a));
                    129:            dumb_xmax = term->xmax = x;
                    130:            dumb_ymax = term->ymax = y;
                    131:        }
                    132:     }
                    133:     sprintf(term_options, "%sfeed %d %d",
                    134:            dumb_feed ? "" : "no", dumb_xmax, dumb_ymax);
                    135: }
                    136:
                    137:
                    138: TERM_PUBLIC void DUMB_init()
                    139: {
                    140:     if (dumb_matrix)
                    141:        free(dumb_matrix);
                    142:
                    143:     dumb_matrix = gp_alloc((unsigned long) dumb_xmax * dumb_ymax * 2, "dumb terminal");
                    144:
                    145:     dumb_priority = dumb_matrix + dumb_xmax * dumb_ymax;
                    146: }
                    147:
                    148:
                    149: TERM_PUBLIC void DUMB_graphics()
                    150: {
                    151:     int i;
                    152:     char *pm = dumb_matrix, *pp = dumb_priority;
                    153:
                    154:     for (i = dumb_xmax * dumb_ymax; i > 0; i--) {
                    155:        *pm++ = ' ';
                    156:        *pp++ = 0;
                    157:     }
                    158: }
                    159:
                    160:
                    161: TERM_PUBLIC void DUMB_text()
                    162: {
                    163:     int x, y, l;
                    164:
                    165:     putc('\f', gpoutfile);
                    166:     for (y = dumb_ymax - 1; y >= 0; y--) {
                    167:        for (l = dumb_xmax; l > 0 && DUMB_PIXEL(l - 1, y) == ' '; l--);
                    168:        for (x = 0; x < l; x++)
                    169:            putc(DUMB_PIXEL(x, y), gpoutfile);
                    170:        if (dumb_feed || y > 0)
                    171:            putc('\n', gpoutfile);
                    172:     }
                    173:     fflush(gpoutfile);
                    174: }
                    175:
                    176:
                    177: TERM_PUBLIC void DUMB_reset()
                    178: {
                    179:     free(dumb_matrix);
                    180:     dumb_matrix = NULL;
                    181: }
                    182:
                    183:
                    184: TERM_PUBLIC void DUMB_linetype(linetype)
                    185: int linetype;
                    186: {
                    187:     static char pen_type[7] = { '*', '#', '$', '%', '@', '&', '=' };
                    188:
                    189:     if (linetype == -2)
                    190:        dumb_pen = DUMB_BORDER_CONST;
                    191:     else if (linetype == -1)
                    192:        dumb_pen = DUMB_AXIS_CONST;
                    193:     else {
                    194:        linetype = linetype % 7;
                    195:        dumb_pen = pen_type[linetype];
                    196:     }
                    197: }
                    198:
                    199:
                    200: TERM_PUBLIC void DUMB_move(x, y)
                    201: unsigned int x, y;
                    202: {
                    203:     dumb_x = x;
                    204:     dumb_y = y;
                    205: }
                    206:
                    207:
                    208: TERM_PUBLIC void DUMB_point(x, y, point)
                    209: unsigned int x, y;
                    210: int point;
                    211: {
                    212:     dumb_set_pixel(x, y, point == -1 ? '.' : point % 26 + 'A', 4);
                    213: }
                    214:
                    215:
                    216: TERM_PUBLIC void DUMB_vector(_x, _y)
                    217: unsigned int _x, _y;
                    218: {
                    219:     int x = _x;                        /* we need signed int, since
                    220:                                 * unsigned-signed=unsigned and */
                    221:     int y = _y;                        /* abs and cast to double wouldn't work */
                    222:     char pen, pen1;
                    223:     int priority;
                    224:     int delta;
                    225:
                    226:     if (ABS(y - dumb_y) > ABS(x - dumb_x)) {
                    227:        switch (dumb_pen) {
                    228:        case DUMB_AXIS_CONST:
                    229:            pen = ':';
                    230:            pen1 = '+';
                    231:            priority = 1;
                    232:            break;
                    233:
                    234:        case DUMB_BORDER_CONST:
                    235:            pen = '|';
                    236:            pen1 = '+';
                    237:            priority = 2;
                    238:            break;
                    239:
                    240:        default:
                    241:            pen = dumb_pen;
                    242:            pen1 = dumb_pen;
                    243:            priority = 3;
                    244:            break;
                    245:        }
                    246:        dumb_set_pixel(dumb_x, dumb_y, pen1, priority);
                    247:        for (delta = 1; delta < ABS(y - dumb_y); delta++) {
                    248:            dumb_set_pixel(dumb_x  + (int) ((double) (x - dumb_x) *
                    249:                                            delta / ABS(y - dumb_y) + 0.5),
                    250:                           dumb_y + delta * sign(y - dumb_y), pen, priority);
                    251:        }
                    252:        dumb_set_pixel(x, y, pen1, priority);
                    253:     } else if (ABS(x - dumb_x) > ABS(y - dumb_y)) {
                    254:        switch (dumb_pen) {
                    255:        case DUMB_AXIS_CONST:
                    256:            pen = '.';
                    257:            pen1 = '+';
                    258:            priority = 1;
                    259:            break;
                    260:
                    261:        case DUMB_BORDER_CONST:
                    262:            pen = '-';
                    263:            pen1 = '+';
                    264:            priority = 2;
                    265:            break;
                    266:
                    267:        default:
                    268:            pen = dumb_pen;
                    269:            pen1 = dumb_pen;
                    270:            priority = 3;
                    271:            break;
                    272:        }
                    273:        dumb_set_pixel(dumb_x, dumb_y, pen1, priority);
                    274:        for (delta = 1; delta < ABS(x - dumb_x); delta++)
                    275:            dumb_set_pixel(dumb_x + delta * sign(x - dumb_x),
                    276:                           dumb_y +
                    277:                           (int) ((double) (y - dumb_y) * delta / ABS(x - dumb_x)
                    278:                                  + 0.5),
                    279:                           pen, priority);
                    280:        dumb_set_pixel(x, y, pen1, priority);
                    281:     } else {
                    282:        switch (dumb_pen) {
                    283:        case DUMB_AXIS_CONST:   /* zero length axis */
                    284:            pen = '+';
                    285:            priority = 1;
                    286:            break;
                    287:
                    288:        case DUMB_BORDER_CONST: /* zero length border */
                    289:            pen = '+';
                    290:            priority = 2;
                    291:            break;
                    292:
                    293:        default:
                    294:            pen = dumb_pen;
                    295:            priority = 3;
                    296:            break;
                    297:        }
                    298:        for (delta = 0; delta <= ABS(x - dumb_x); delta++)
                    299:            dumb_set_pixel(dumb_x + delta * sign(x - dumb_x),
                    300:                           dumb_y + delta * sign(y - dumb_y),
                    301:                           pen, priority);
                    302:     }
                    303:     dumb_x = x;
                    304:     dumb_y = y;
                    305: }
                    306:
                    307:
                    308: TERM_PUBLIC void DUMB_put_text(x, y, str)
                    309: unsigned int x, y;
                    310: char *str;
                    311: {
                    312:     int length;
                    313:
                    314:     length = strlen(str);
                    315:     if (x + length > dumb_xmax)
                    316:        x = GPMAX(0, dumb_xmax - length);
                    317:
                    318:     for (; x < dumb_xmax && *str; x++, str++)
                    319:        dumb_set_pixel(x, y, *str, 5);
                    320: }
                    321:
                    322:
                    323: TERM_PUBLIC void DUMB_arrow(sx, sy, ex, ey, head)
                    324: unsigned int sx, sy, ex, ey;
                    325: int head;                      /* ignored */
                    326: {
                    327:     char saved_pen;
                    328:     char saved_x;
                    329:     char saved_y;
                    330:
                    331:     saved_pen = dumb_pen;
                    332:     saved_x = dumb_x;
                    333:     saved_y = dumb_y;
                    334:
                    335:     dumb_pen = '>';
                    336:     dumb_x = sx;
                    337:     dumb_y = sy;
                    338:     DUMB_vector(ex, ey);
                    339:
                    340:     dumb_pen = saved_pen;
                    341:     dumb_x = saved_x;
                    342:     dumb_y = saved_y;
                    343: }
                    344:
                    345: #endif /* TERM_BODY */
                    346:
                    347: #ifdef TERM_TABLE
                    348: TERM_TABLE_START(dumb_driver)
                    349:     "dumb", "printer or glass dumb terminal",
                    350:     DUMB_XMAX, DUMB_YMAX, 1, 1,
                    351:     1, 1, DUMB_options, DUMB_init, DUMB_reset,
                    352:     DUMB_text, null_scale, DUMB_graphics, DUMB_move, DUMB_vector,
                    353:     DUMB_linetype, DUMB_put_text, null_text_angle,
                    354:     null_justify_text, DUMB_point, DUMB_arrow, set_font_null,
                    355:     0,                         /* pointsize */
                    356:     TERM_CAN_MULTIPLOT
                    357: TERM_TABLE_END(dumb_driver)
                    358:
                    359: #undef LAST_TERM
                    360: #define LAST_TERM dumb_driver
                    361:
                    362: #endif /* TERM_TABLE */
                    363:
                    364: #ifdef TERM_HELP
                    365: START_HELP(dumb)
                    366: "1 dumb",
                    367: "?commands set terminal dumb",
                    368: "?set terminal dumb",
                    369: "?set term dumb",
                    370: "?terminal dumb",
                    371: "?term dumb",
                    372: "?dumb",
                    373: " The `dumb` terminal driver has an optional size specification and trailing",
                    374: " linefeed control.",
                    375: "",
                    376: " Syntax:",
                    377: "       set terminal dumb {[no]feed} {<xsize> <ysize>}",
                    378: "",
                    379: " where <xsize> and <ysize> set the size of the dumb terminals. Default is",
                    380: " 79 by 24. The last newline is printed only if `feed` is enabled.",
                    381: "",
                    382: " Examples:",
                    383: "       set term dumb nofeed",
                    384: "       set term dumb 79 49 # VGA screen---why would anyone do that?"
                    385: END_HELP(dumb)
                    386: #endif /* TERM_HELP */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>