1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: multitos.trm,v 1.15 2006/07/21 02:35:47 sfeam Exp $
5 /* GNUPLOT - multitos.trm */
8 * Copyright 1994, 1998, 2004
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.
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,
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
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.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
38 * This file is included by ../term.c.
40 * This terminal driver supports:
41 * mtos : ATARI Systems MiNT/MULTITOS/MAGIC with external client
44 * Dirk Stadler (email: dirk_stadler@n.maus.de, dirk@lstm.uni-erlangen.de)
46 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
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, const 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);
72 /* default to ST high resolution */
78 #define MTOS_VTIC MTOS_HTIC
80 #define GOT_MTOS_PROTO
81 #endif /* TERM_PROTO */
83 #ifndef TERM_PROTO_ONLY
100 extern const char *user_gnuplotpath;
102 int MTOS_pause(char *str);
103 static void MTOS_quit(void);
104 void MTOS_open_pipe(void);
105 static void write_pid(void);
106 static void init_exit(void);
108 /* commands for GPCLIENT */
109 #define SET_GRAPHICS 'G'
112 #define SET_ANGLE 'A'
113 #define SET_JUSTIFY 'J'
114 #define SET_POINTMODE 'D'
124 /* for creating pipes */
125 #define PIPE1 "u:\\pipe\\GPLT%d"
126 #define PIPE2 "u:\\pipe\\gpclient.tmp"
128 #define SIZE ((unsigned)sizeof(short))
130 /* default name for client */
131 #define GPCLIENT1 "gpclient.prg"
132 #define GPCLIENT2 "gpclient"
137 /* some global variables */
138 static char MTOS_mode = 0;
139 static int handle = -1;
145 term_options[0] = NUL;
152 char *file, cmd[MAXPATHLEN+1];
153 char const *const ext[] = { "prg", "app", NULL };
157 if ((aesid = appl_init()) < 0)
158 int_error(NO_CARET, "APPL_INIT failed !");
160 file = findfile(GPCLIENT2, user_gnuplotpath, ext);
162 safe_strncpy(cmd, GPCLIENT1, sizeof(cmd));
163 else if (file && !strchr(file, '\\') && !strchr(file, '/'))
164 safe_strncpy(cmd, file, sizeof(cmd));
168 int_error(NO_CARET, "Cannot find GPCLIENT !");
170 sprintf(&pipe[1], PIPE1, aesid);
172 if ((handle = open(&pipe[1], O_RDWR | O_CREAT)) < 0) {
173 if ((handle = (int) Fcreate(&pipe[1], 0)) < 0)
174 int_error(NO_CARET, "Cannot open PIPE to GPCLIENT !");
176 pipe[0] = (char) (strlen(&pipe[1]) + 1);
178 if (!shel_write(1, 1, 100, cmd, pipe)) {
181 int_error(NO_CARET, "Cannot spawn GPCLIENT !");
186 menu_register(aesid, " Terminal: mtos");
194 buff = (short) GR_RESET;
195 write(handle, &buff, SIZE);
203 buff = (short) SET_TEXT;
204 if (MTOS_mode != SET_TEXT)
205 write(handle, &buff, SIZE);
206 MTOS_mode = SET_TEXT;
214 buff = (short) SET_GRAPHICS;
215 write(handle, &buff, SIZE);
216 MTOS_mode = SET_GRAPHICS;
220 MTOS_move(unsigned int x, unsigned int y)
222 short x_1, y_1, buff;
226 buff = (short) GR_MOVE;
227 write(handle, &buff, SIZE);
228 write(handle, &x_1, SIZE);
229 write(handle, &y_1, SIZE);
233 MTOS_vector(unsigned int x, unsigned int y)
235 short x_1, y_1, buff;
239 buff = (short) GR_DRAW;
240 write(handle, &buff, SIZE);
241 write(handle, &x_1, SIZE);
242 write(handle, &y_1, SIZE);
246 MTOS_linetype(int lt)
251 buff = (short) SET_LINE;
252 write(handle, &buff, SIZE);
253 write(handle, <_1, SIZE);
257 MTOS_text_angle(int ang)
261 ta_1 = (short) (ang ? 1 : 0);
262 buff = (short) SET_ANGLE;
263 write(handle, &buff, SIZE);
264 write(handle, &ta_1, SIZE);
269 MTOS_put_text(unsigned int x, unsigned int y, const char *str)
271 short x_1, y_1, len, buff;
275 len = (short) strlen(str) + 1;
276 buff = (short) GR_TEXT;
277 write(handle, &buff, SIZE);
278 write(handle, &x_1, SIZE);
279 write(handle, &y_1, SIZE);
280 write(handle, &len, SIZE);
281 write(handle, str, (unsigned) len);
285 MTOS_justify_text(enum JUSTIFY mode)
289 j_mode = (short) mode;
290 buff = (short) SET_JUSTIFY;
291 write(handle, &buff, SIZE);
292 write(handle, &j_mode, SIZE);
297 MTOS_point(unsigned int x, unsigned int y, int number)
301 buff = (short) SET_POINTMODE;
303 write(handle, &buff, SIZE);
304 write(handle, &mode, SIZE);
305 do_point(x, y, number);
307 write(handle, &buff, SIZE);
308 write(handle, &mode, SIZE);
312 MTOS_pause(char *str)
316 len = (short) strlen(str) + 1;
317 buff = (short) PAUSE;
318 write(handle, &buff, SIZE);
319 write(handle, &len, SIZE);
320 write(handle, str, (unsigned) len);
321 read(handle, &len, SIZE);
334 write(handle, &buff, SIZE);
346 if ((handle = open(PIPE2, O_RDWR)) < 0)
348 read(handle, &len, SIZE);
350 read(handle, pipe, (unsigned) len);
352 if ((handle = open(pipe, O_RDWR)) < 0) {
354 "\n\n\33p Can't open Pipe: (%s) Error: (%s) !\33q\n\n",
355 pipe,sys_errlist[errno]);
367 short buff, mypid, gpclpid;
369 mypid = (short) getpid();
371 while (write(handle, &buff, SIZE) <= 0)
372 Fselect(100, 0L, 0L, 0L);
373 while (read(handle, &gpclpid, SIZE) <= 0)
374 Fselect(100, 0L, 0L, 0L);
375 write(handle, &mypid, SIZE);
387 #endif /* TERM_BODY */
391 TERM_TABLE_START(mtos_driver)
392 "mtos", "Atari MiNT/MULTITOS/Magic Terminal",
393 MTOS_XMAX, MTOS_YMAX, MTOS_VCHAR, MTOS_HCHAR,
394 MTOS_VTIC, MTOS_HTIC, MTOS_options, MTOS_init, MTOS_reset,
395 MTOS_text, null_scale, MTOS_graphics, MTOS_move, MTOS_vector,
396 MTOS_linetype, MTOS_put_text, MTOS_text_angle,
397 MTOS_justify_text, MTOS_point, do_arrow, set_font_null,
398 0, TERM_CAN_MULTIPLOT, 0, 0
399 TERM_TABLE_END(mtos_driver)
402 #define LAST_TERM mtos_driver
404 #endif /* TERM_TABLE */
406 #endif /* TERM_PROTO_ONLY */
411 "?commands set terminal mtos",
412 "?set terminal mtos",
417 " The `mtos` terminal has no options. It sends data via a pipe to an external",
418 " program called GPCLIENT. It runs under MULTITOS, Magic 3.x, MagicMAC. and",
419 " MiNT. If you cannot find GPCLIENT, than mail to dirk@lstm.uni-erlangen.de."
421 #endif /* TERM_HELP */