File: dumb.trm

package info (click to toggle)
gnuplot 3.5beta6.340-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,792 kB
  • ctags: 4,205
  • sloc: ansic: 41,878; asm: 539; makefile: 498; objc: 379; csh: 297; sh: 277; pascal: 194; perl: 138; lisp: 88
file content (371 lines) | stat: -rw-r--r-- 8,910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
 * $Id: dumb.trm,v 1.22 1997/04/10 02:34:11 drd Exp $
 *
 */

/* GNUPLOT - dumb.trm */
/*
 * Copyright (C) 1991, 1992
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the modified code.  Modifications are to be distributed
 * as patches to released version.
 *
 * This software  is provided "as is" without express or implied warranty.
 *
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *   DUMB terminals
 *
 * AUTHORS
 *   Francois Pinard, 91-04-03
 *           INTERNET: pinard@iro.umontreal.ca
 *
 * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
 *
 */
#ifndef GOT_DRIVER_H
#include "driver.h"
#endif

#ifdef TERM_REGISTER
register_term(dumb_driver)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void DUMB_options __PROTO((void));
TERM_PUBLIC void DUMB_init __PROTO((void));
TERM_PUBLIC void DUMB_graphics __PROTO((void));
TERM_PUBLIC void DUMB_text __PROTO((void));
TERM_PUBLIC void DUMB_reset __PROTO((void));
TERM_PUBLIC void DUMB_linetype __PROTO((int linetype));
TERM_PUBLIC void DUMB_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void DUMB_point __PROTO((unsigned int x, unsigned int y, int point));
TERM_PUBLIC void DUMB_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void DUMB_put_text __PROTO((unsigned int x, unsigned int y, char *str));
TERM_PUBLIC void DUMB_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head));

#define DUMB_XMAX 79
#define DUMB_YMAX 24

#endif /* TERM_PROTO */

#ifdef TERM_BODY

#define DUMB_AXIS_CONST '\1'
#define DUMB_BORDER_CONST '\2'

static char *dumb_matrix = NULL;      /* matrix of characters */
static char *dumb_priority = NULL;    /* matrix of priority at each position */
static char dumb_pen;                 /* current character used to draw */
static int dumb_x;                    /* current X position */
static int dumb_y;                    /* current Y position */
static int dumb_xmax = DUMB_XMAX;
static int dumb_ymax = DUMB_YMAX;
static int dumb_feed = 1;

#define DUMB_PIXEL(x,y) dumb_matrix[dumb_xmax*(y)+(x)]

static void dumb_set_pixel __PROTO((int x, int y, int v, int p));


static void dumb_set_pixel(x,y,v,p)
int x,y,v,p;
{
  if ( (unsigned) x <= dumb_xmax &&  /* ie x>=0 && x<=dumb_xmax */
       (unsigned) y <= dumb_ymax &&
       p > dumb_priority[dumb_xmax*y+x])
    {
      dumb_matrix[dumb_xmax*y+x] = v;
      dumb_priority[dumb_xmax*y+x] = p;
    }
}


TERM_PUBLIC void DUMB_options()
{
  int x,y;
  struct value a;

  if (almost_equals(c_token, "f$eed"))
	++c_token, dumb_feed = 1;
  else if (almost_equals(c_token, "nof$eed"))
   ++c_token, dumb_feed = 0;
	
  if (!END_OF_COMMAND) {
    x = (int) real(const_express(&a));
    if (!END_OF_COMMAND) {
      y = (int) real(const_express(&a));
      dumb_xmax = term->xmax = x;
      dumb_ymax = term->ymax = y;
    }
  }

  sprintf(term_options, "%sfeed %d %d", dumb_feed ? "" : "no",dumb_xmax,dumb_ymax);
}


TERM_PUBLIC void DUMB_init()
{
  if (dumb_matrix)
    free(dumb_matrix);

  dumb_matrix = gp_alloc ((unsigned long)dumb_xmax * dumb_ymax * 2, "dumb terminal");

  dumb_priority = dumb_matrix + dumb_xmax * dumb_ymax;
}


TERM_PUBLIC void DUMB_graphics ()
{
  int i;
  char *pm = dumb_matrix, *pp = dumb_priority;

  for ( i = dumb_xmax * dumb_ymax; i > 0; i-- ) {
    *pm++ = ' ';
    *pp++ = 0;
  }
}


TERM_PUBLIC void DUMB_text ()
{
  int x, y, l;

  putc ('\f', outfile);
  for (y = dumb_ymax - 1; y >= 0; y--)
    {
      for (l = dumb_xmax; l > 0 && DUMB_PIXEL (l - 1, y) == ' '; l--)
       ;
      for (x = 0; x < l; x++)
       putc (DUMB_PIXEL (x, y), outfile);
      if (dumb_feed || y>0) putc('\n', outfile);
    }
  fflush (outfile);
}


TERM_PUBLIC void DUMB_reset()
{
  free (dumb_matrix);
  dumb_matrix = NULL;
}


TERM_PUBLIC void DUMB_linetype(linetype)
int linetype;
{
  static char pen_type[7] = {'*', '#', '$', '%', '@', '&', '='};

  if (linetype == -2)
    dumb_pen = DUMB_BORDER_CONST;
  else if (linetype == -1)
    dumb_pen = DUMB_AXIS_CONST;
  else
    {
      linetype = linetype % 7;
      dumb_pen = pen_type[linetype];
    }
}


TERM_PUBLIC void DUMB_move(x, y)
unsigned int x, y;
{
  dumb_x = x;
  dumb_y = y;
}


TERM_PUBLIC void DUMB_point(x,y,point)
unsigned int x,y;
int point;
{
  dumb_set_pixel (x, y, point == -1 ? '.' : point % 26 + 'A', 4);
}


TERM_PUBLIC void DUMB_vector(_x,_y)
unsigned int _x,_y;
{
  int x=_x;	/* we need signed int, since unsigned-signed=unsigned and */
  int y=_y;	/* abs and cast to double wouldn't work */
  char pen, pen1;
  int priority;
  int delta;

  if (ABS (y - dumb_y) > ABS (x - dumb_x))
    {
      switch (dumb_pen)
       {
       case DUMB_AXIS_CONST:
         pen = ':';
         pen1 = '+';
         priority = 1;
         break;

       case DUMB_BORDER_CONST:
         pen = '|';
         pen1 = '+';
         priority = 2;
         break;

       default:
         pen = dumb_pen;
         pen1 = dumb_pen;
         priority = 3;
         break;
       }
      dumb_set_pixel (dumb_x, dumb_y, pen1, priority);
      for (delta = 1; delta < ABS (y - dumb_y); delta++)
       dumb_set_pixel (dumb_x
                       + (int) ((double) (x - dumb_x) * delta / ABS(y - dumb_y)
                                + 0.5),
                       dumb_y + delta * sign (y - dumb_y),
                       pen, priority);
      dumb_set_pixel (x, y, pen1, priority);
    }
  else if (ABS (x - dumb_x) > ABS (y - dumb_y))
    {
      switch (dumb_pen)
       {
       case DUMB_AXIS_CONST:
         pen = '.';
         pen1 = '+';
         priority = 1;
         break;

       case DUMB_BORDER_CONST:
         pen = '-';
         pen1 = '+';
         priority = 2;
         break;

       default:
         pen = dumb_pen;
         pen1 = dumb_pen;
         priority = 3;
         break;
       }
      dumb_set_pixel (dumb_x, dumb_y, pen1, priority);
      for (delta = 1; delta < ABS (x - dumb_x); delta++)
       dumb_set_pixel (dumb_x + delta * sign (x - dumb_x),
                       dumb_y +
                       (int) ((double) (y - dumb_y) * delta / ABS(x - dumb_x)
                              + 0.5),
                       pen, priority);
      dumb_set_pixel (x, y, pen1, priority);
    }
  else
    {
      switch (dumb_pen)
       {
       case DUMB_AXIS_CONST:	/* zero length axis */
         pen = '+';
         priority = 1;
         break;

       case DUMB_BORDER_CONST:	/* zero length border */
         pen = '+';
         priority = 2;
         break;

       default:
         pen = dumb_pen;
         priority = 3;
         break;
       }
      for (delta = 0; delta <= ABS (x - dumb_x); delta++)
	dumb_set_pixel (dumb_x + delta * sign (x - dumb_x),
			dumb_y + delta * sign (y - dumb_y),
			pen, priority);
    }
  dumb_x = x;
  dumb_y = y;
}


TERM_PUBLIC void DUMB_put_text(x,y,str)
unsigned int x, y;
char *str;
{
  int length;

  length = strlen(str);
  if (x + length > dumb_xmax)
    x = GPMAX(0, dumb_xmax - length);

  for (; x < dumb_xmax && *str; x++, str++)
    dumb_set_pixel (x, y, *str, 5);
}


TERM_PUBLIC void DUMB_arrow (sx,sy,ex,ey,head)
unsigned int sx,sy,ex,ey;
int head; /* ignored */
{
  char saved_pen;
  char saved_x;
  char saved_y;

  saved_pen = dumb_pen;
  saved_x = dumb_x;
  saved_y = dumb_y;

  dumb_pen = '>';
  dumb_x = sx;
  dumb_y = sy;
  DUMB_vector (ex,ey);

  dumb_pen = saved_pen;
  dumb_x = saved_x;
  dumb_y = saved_y;
}
#endif /* TERM_BODY */

#ifdef TERM_TABLE
TERM_TABLE_START(dumb_driver)
         "dumb", "printer or glass dumb terminal",
         DUMB_XMAX, DUMB_YMAX, 1, 1,
         1, 1, DUMB_options, DUMB_init, DUMB_reset,
         DUMB_text, null_scale, DUMB_graphics, DUMB_move, DUMB_vector,
         DUMB_linetype, DUMB_put_text, null_text_angle,
         null_justify_text, DUMB_point, DUMB_arrow, set_font_null,
			0, /* pointsize */
			TERM_CAN_MULTIPLOT
TERM_TABLE_END(dumb_driver)

#undef LAST_TERM
#define LAST_TERM dumb_driver

#endif /* TERM_TABLE */

#ifdef TERM_HELP
START_HELP(dumb)
"1 dumb",
"?set terminal dumb",
"?set term dumb",
"?terminal dumb",
"?term dumb",
"?dumb",
" The `dumb` terminal driver has an optional size specification and trailing",
" linefeed control.",
"",
" Syntax:",
"       set terminal dumb {[no]feed} {<xsize> <ysize>}",
"",
" where <xsize> and <ysize> set the size of the dumb terminals. Default is",
" 79 by 24. The last newline is printed only if `feed` is enabled.",
"",
" Examples:",
"       set term dumb nofeed",
"       set term dumb 79 49 # VGA screen---why would anyone do that?"
END_HELP(dumb)
#endif