Annotation of OpenXM_contrib/gnuplot/term/multitos.trm, Revision 1.1.1.2
1.1 maekawa 1: /*
1.1.1.2 ! maekawa 2: * $Id: multitos.trm,v 1.6 1998/12/14 18:40:36 lhecking Exp $
1.1 maekawa 3: */
4:
5: /* GNUPLOT - multitos.trm */
6:
7: /*[
8: * Copyright 1994, 1998
9: *
10: * Permission to use, copy, and distribute this software and its
11: * documentation for any purpose with or without fee is hereby granted,
12: * provided that the above copyright notice appear in all copies and
13: * that both that copyright notice and this permission notice appear
14: * in supporting documentation.
15: *
16: * Permission to modify the software is granted, but not the right to
17: * distribute the complete modified source code. Modifications are to
18: * be distributed as patches to the released version. Permission to
19: * distribute binaries produced by compiling modified sources is granted,
20: * provided you
21: * 1. distribute the corresponding source modifications from the
22: * released version in the form of a patch file along with the binaries,
23: * 2. add special version identification to distinguish your version
24: * in addition to the base release version number,
25: * 3. provide your name and address as the primary contact for the
26: * support of your modified version, and
27: * 4. retain our contact information in regard to use of the base
28: * software.
29: * Permission to distribute the released version of the source code along
30: * with corresponding source modifications in the form of a patch file is
31: * granted with same provisions 2 through 4 for binary distributions.
32: *
33: * This software is provided "as is" without express or implied warranty
34: * to the extent permitted by applicable law.
35: ]*/
36:
37: /*
38: * This file is included by ../term.c.
39: *
40: * This terminal driver supports:
41: * mtos : ATARI Systems MiNT/MULTITOS/MAGIC with external client
42: *
43: * AUTHOR
44: * Dirk Stadler (email: dirk_stadler@n.maus.de, dirk@lstm.uni-erlangen.de)
45: *
46: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
47: *
48: */
49:
50: #include "driver.h"
51:
52: #ifdef TERM_REGISTER
53: register_term(mtos)
54: #endif
55:
56: #ifdef TERM_PROTO
57:
58: /* function-prototypes */
59: TERM_PUBLIC void MTOS_options(void);
60: TERM_PUBLIC void MTOS_init(void);
61: TERM_PUBLIC void MTOS_reset(void);
62: TERM_PUBLIC void MTOS_graphics(void);
63: TERM_PUBLIC void MTOS_text(void);
64: TERM_PUBLIC void MTOS_move(unsigned int x, unsigned int y);
65: TERM_PUBLIC void MTOS_vector(unsigned int x, unsigned int y);
66: TERM_PUBLIC void MTOS_linetype(int lt);
67: TERM_PUBLIC int MTOS_text_angle(int ang);
68: TERM_PUBLIC void MTOS_put_text(unsigned int x, unsigned int y, char *str);
69: TERM_PUBLIC int MTOS_justify_text(enum JUSTIFY mode);
70: TERM_PUBLIC void MTOS_point(unsigned int x, unsigned int y, int number);
71:
72: /* default to ST high resolution */
73: #define MTOS_XMAX 640
74: #define MTOS_YMAX 400
75: #define MTOS_VCHAR 18
76: #define MTOS_HCHAR 12
77: #define MTOS_HTIC 5
78: #define MTOS_VTIC MTOS_HTIC
79:
80: #define GOT_MTOS_PROTO
81: #endif /* TERM_PROTO */
82:
83: #ifndef TERM_PROTO_ONLY
84: #ifdef TERM_BODY
85:
86: #include <unistd.h>
87: #include <fcntl.h>
88: #include <param.h>
89: #include <process.h>
90: #include <signal.h>
91: #include <support.h>
92: #include <sys/stat.h>
93: #include <time.h>
94: #include <errno.h>
95: #include <aesbind.h>
96: #include <osbind.h>
97: #include <mintbind.h>
98:
99: int MTOS_pause(char *str);
100: static void MTOS_quit(void);
101: void MTOS_open_pipe(void);
102: static void write_pid(void);
103: static void init_exit(void);
104:
105: /* commands for GPCLIENT */
106: #define SET_GRAPHICS 'G'
107: #define SET_TEXT 'E'
108: #define SET_LINE 'L'
109: #define SET_ANGLE 'A'
110: #define SET_JUSTIFY 'J'
111: #define SET_POINTMODE 'D'
112: #define GR_MOVE 'M'
113: #define GR_DRAW 'V'
114: #define GR_RESET 'R'
115: #define GR_TEXT 'T'
116:
117: #define PAUSE 'P'
118: #define PID 'I'
119: #define QUIT 'Q'
120:
121: /* for creating pipes */
122: #define PIPE1 "u:\\pipe\\GPLT%d"
123: #define PIPE2 "u:\\pipe\\gpclient.tmp"
124: #define NAMESIZE 25
125: #define SIZE ((unsigned)sizeof(short))
126:
127: /* default name for client */
128: #define GPCLIENT1 "gpclient.prg"
129: #define GPCLIENT2 "gpclient"
130:
131: /* environment */
132: #define MYENV "GNUPLOTPATH"
133: #define PATH "PATH"
134:
135: /* some global variables */
136: static char MTOS_mode = 0;
137: static int handle = -1;
138: static int pid = -1;
139:
140: TERM_PUBLIC void MTOS_options()
141: {
142: term_options[0] = NUL;
143: }
144:
145: TERM_PUBLIC void MTOS_init()
146: {
147: char pipe[NAMESIZE];
148: char *file, cmd[MAXPATHLEN+1];
149: char const *const ext[] = { "prg", "app", NULL };
150:
151: if (handle < 0) {
152: if (aesid < 0) {
153: if ((aesid = appl_init()) < 0)
154: int_error("APPL_INIT failed !", NO_CARET);
155: }
156: file = findfile(GPCLIENT2, getenv(MYENV), ext);
157: if (!file)
158: safe_strncpy(cmd, GPCLIENT1, sizeof(cmd));
159: else if (file && !strchr(file, '\\') && !strchr(file, '/'))
160: safe_strncpy(cmd, file, sizeof(cmd));
161: else
162: unx2dos(file, cmd);
163: if (!shel_find(cmd))
164: int_error("Cannot find GPCLIENT !", NO_CARET);
165:
166: sprintf(&pipe[1], PIPE1, aesid);
167:
168: if ((handle = open(&pipe[1], O_RDWR | O_CREAT)) < 0) {
169: if ((handle = (int) Fcreate(&pipe[1], 0)) < 0)
170: int_error("Cannot open PIPE to GPCLIENT !", NO_CARET);
171: }
172: pipe[0] = (char) (strlen(&pipe[1]) + 1);
173:
174: if (!shel_write(1, 1, 100, cmd, pipe)) {
175: close(handle);
176: handle = -1;
177: int_error("Cannot spawn GPCLIENT !", NO_CARET);
178: }
179: init_exit();
180: }
181: if (aesid > -1)
182: menu_register(aesid, " Terminal: mtos");
183: }
184:
185: TERM_PUBLIC void MTOS_reset()
186: {
187: short buff;
188:
189: buff = (short) GR_RESET;
190: write(handle, &buff, SIZE);
191: }
192:
193: TERM_PUBLIC void MTOS_text()
194: {
195: short buff;
196:
197: buff = (short) SET_TEXT;
198: if (MTOS_mode != SET_TEXT)
199: write(handle, &buff, SIZE);
200: MTOS_mode = SET_TEXT;
201: }
202:
203: TERM_PUBLIC void MTOS_graphics()
204: {
205: short buff;
206:
207: buff = (short) SET_GRAPHICS;
208: write(handle, &buff, SIZE);
209: MTOS_mode = SET_GRAPHICS;
210: }
211:
212: TERM_PUBLIC void MTOS_move(unsigned int x, unsigned int y)
213: {
214: short x_1, y_1, buff;
215:
216: x_1 = (short) x;
217: y_1 = (short) y;
218: buff = (short) GR_MOVE;
219: write(handle, &buff, SIZE);
220: write(handle, &x_1, SIZE);
221: write(handle, &y_1, SIZE);
222: }
223:
224: TERM_PUBLIC void MTOS_vector(unsigned int x, unsigned int y)
225: {
226: short x_1, y_1, buff;
227:
228: x_1 = (short) x;
229: y_1 = (short) y;
230: buff = (short) GR_DRAW;
231: write(handle, &buff, SIZE);
232: write(handle, &x_1, SIZE);
233: write(handle, &y_1, SIZE);
234: }
235:
236: TERM_PUBLIC void MTOS_linetype(int lt)
237: {
238: short lt_1, buff;
239:
240: lt_1 = (short) lt;
241: buff = (short) SET_LINE;
242: write(handle, &buff, SIZE);
243: write(handle, <_1, SIZE);
244: }
245:
246: TERM_PUBLIC int MTOS_text_angle(int ang)
247: {
248: short ta_1, buff;
249:
250: ta_1 = (short) ang;
251: buff = (short) SET_ANGLE;
252: write(handle, &buff, SIZE);
253: write(handle, &ta_1, SIZE);
254: return (TRUE);
255: }
256:
257: TERM_PUBLIC void MTOS_put_text(unsigned int x, unsigned int y, char *str)
258: {
259: short x_1, y_1, len, buff;
260:
261: x_1 = (short) x;
262: y_1 = (short) y;
263: len = (short) strlen(str) + 1;
264: buff = (short) GR_TEXT;
265: write(handle, &buff, SIZE);
266: write(handle, &x_1, SIZE);
267: write(handle, &y_1, SIZE);
268: write(handle, &len, SIZE);
269: write(handle, str, (unsigned) len);
270: }
271:
272: TERM_PUBLIC int MTOS_justify_text(enum JUSTIFY mode)
273: {
274: short j_mode, buff;
275:
276: j_mode = (short) mode;
277: buff = (short) SET_JUSTIFY;
278: write(handle, &buff, SIZE);
279: write(handle, &j_mode, SIZE);
280: return (TRUE);
281: }
282:
283: TERM_PUBLIC void MTOS_point(unsigned int x, unsigned int y, int number)
284: {
285: short mode, buff;
286:
287: buff = (short) SET_POINTMODE;
288: mode = 1;
289: write(handle, &buff, SIZE);
290: write(handle, &mode, SIZE);
291: do_point(x, y, number);
292: mode = 0;
293: write(handle, &buff, SIZE);
294: write(handle, &mode, SIZE);
295: }
296:
297: int MTOS_pause(char *str)
298: {
299: short len, buff;
300:
301: len = (short) strlen(str) + 1;
302: buff = (short) PAUSE;
303: write(handle, &buff, SIZE);
304: write(handle, &len, SIZE);
305: write(handle, str, (unsigned) len);
306: read(handle, &len, SIZE);
307: return ((int) len);
308: }
309:
310: static void MTOS_quit()
311: {
312: short buff;
313:
314: if (pid > -1)
315: kill(pid, SIGTERM);
316: if (handle > -1) {
317: buff = (short) QUIT;
318: write(handle, &buff, SIZE);
319: close(handle);
320: }
321: }
322:
323: void MTOS_open_pipe()
324: {
325: char pipe[NAMESIZE];
326: short len;
327:
328: if (handle < 0) {
329: if ((handle = open(PIPE2, O_RDWR)) < 0)
330: return;
331: read(handle, &len, SIZE);
332: if (len > 0) {
333: read(handle, pipe, (unsigned) len);
334: close(handle);
335: if ((handle = open(pipe, O_RDWR)) < 0) {
336: fprintf(stderr, "\n\n\33p Can't open Pipe: (%s) Error: (%s) !\33q\n\n", pipe,sys_errlist[errno]);
337: fflush(stderr);
338: return;
339: }
340: }
341: init_exit();
342: }
343: }
344:
345: static void write_pid()
346: {
347: short buff, mypid, gpclpid;
348:
349: mypid = (short) getpid();
350: buff = (short) PID;
351: while (write(handle, &buff, SIZE) <= 0)
352: Fselect(100, 0L, 0L, 0L);
353: while (read(handle, &gpclpid, SIZE) <= 0)
354: Fselect(100, 0L, 0L, 0L);
355: write(handle, &mypid, SIZE);
356: pid = (int) gpclpid;
357: }
358:
359: static void init_exit()
360: {
361: Cconout(7);
362: write_pid();
363: atexit(MTOS_quit);
364: }
365:
366: #endif /* TERM_BODY */
367:
368: #ifdef TERM_TABLE
369:
370: TERM_TABLE_START(mtos_driver)
371: "mtos", "Atari MiNT/MULTITOS/Magic Terminal",
372: MTOS_XMAX, MTOS_YMAX, MTOS_VCHAR, MTOS_HCHAR,
373: MTOS_VTIC, MTOS_HTIC, MTOS_options, MTOS_init, MTOS_reset,
374: MTOS_text, null_scale, MTOS_graphics, MTOS_move, MTOS_vector,
375: MTOS_linetype, MTOS_put_text, MTOS_text_angle,
376: MTOS_justify_text, MTOS_point, do_arrow, set_font_null,
377: 0, TERM_CAN_MULTIPLOT, 0, 0
378: TERM_TABLE_END(mtos_driver)
379:
380: #undef LAST_TERM
381: #define LAST_TERM mtos_driver
382:
383: #endif /* TERM_TABLE */
384:
385: #endif /* TERM_PROTO_ONLY */
386:
387: #ifdef TERM_HELP
388: START_HELP(mtos)
389: "1 mtos",
390: "?commands set terminal mtos",
391: "?set terminal mtos",
392: "?set term mtos",
393: "?terminal mtos",
394: "?term mtos",
395: "?mtos",
396: " The `mtos` terminal has no options. It sends data via a pipe to an external",
397: " program called GPCLIENT. It runs under MULTITOS, Magic 3.x, MagicMAC. and",
398: " MiNT. If you cannot find GPCLIENT, than mail to dirk@lstm.uni-erlangen.de."
399: END_HELP(mtos)
400: #endif /* TERM_HELP */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>