2 * $Id: dumb.trm,v 1.16 2004/04/13 17:24:16 broeker Exp $
6 /* GNUPLOT - qtopia.trm */
9 * Copyright 1991 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
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.
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,
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
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.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
45 * Michael Neuroth, 2004-05-16
46 * INTERNET: michael.neuroth@freenet.de
48 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
53 #define NO_QTOPIA_ENHANCED_SUPPORT
56 register_term(qtopia_driver)
60 TERM_PUBLIC void QTOPIA_options __PROTO((void));
61 TERM_PUBLIC void QTOPIA_init __PROTO((void));
62 TERM_PUBLIC void QTOPIA_graphics __PROTO((void));
63 TERM_PUBLIC void QTOPIA_text __PROTO((void));
64 TERM_PUBLIC void QTOPIA_reset __PROTO((void));
65 TERM_PUBLIC void QTOPIA_linetype __PROTO((int linetype));
66 TERM_PUBLIC void QTOPIA_move __PROTO((unsigned int x, unsigned int y));
67 TERM_PUBLIC void QTOPIA_point __PROTO((unsigned int x, unsigned int y,
69 TERM_PUBLIC void QTOPIA_vector __PROTO((unsigned int x, unsigned int y));
70 TERM_PUBLIC void QTOPIA_put_text __PROTO((unsigned int x, unsigned int y,
72 TERM_PUBLIC void QTOPIA_arrow __PROTO((unsigned int sx, unsigned int sy,
73 unsigned int ex, unsigned int ey,
76 #define ENHqtopia_put_text NULL
79 #define QTOPIA_XMAX 4096
80 #define QTOPIA_YMAX 4096
83 #define QTOPIA_VCHAR (QTOPIA_YMAX/25)
84 #define QTOPIA_HCHAR (QTOPIA_XMAX/40)
85 #define QTOPIA_VTIC (QTOPIA_YMAX/50)
86 #define QTOPIA_HTIC (QTOPIA_XMAX/40)
88 #define QTOPIA_VCHAR (QTOPIA_YMAX/25)
89 #define QTOPIA_HCHAR (QTOPIA_XMAX/50)
90 #define QTOPIA_VTIC (QTOPIA_YMAX/100)
91 #define QTOPIA_HTIC (QTOPIA_XMAX/150)
94 #endif /* TERM_PROTO */
98 /*#include <winsock2.h>*/
99 /* needs: ws2_32.lib */
101 #include <sys/types.h>
102 #include <sys/socket.h>
103 #include <netinet/in.h>
104 #include <arpa/inet.h>
107 #define QTOPIA_MAX_BUFFER 512
108 #define QTOPIA_MAX_DELAY_COUNT 20 /* * 100 ms = 2 s */
111 #define QTOPIA_BAD_SOCKET INVALID_SOCKET /* -1 */
112 #define QTOPIA_BAD_CONNECT SOCKET_ERROR
114 #define QTOPIA_BAD_SOCKET -1
115 #define QTOPIA_BAD_CONNECT -1
117 #define QTOPIA_PORT_NO 5050
119 static int qtopia_client_socket = QTOPIA_BAD_SOCKET;
120 static unsigned short qtopia_port_no = QTOPIA_PORT_NO;
121 static char qtopia_host_name[QTOPIA_MAX_BUFFER+1] = { "localhost" };
123 static int OpenClient __PROTO(( int test));
124 static void CloseClient();
126 static void MySleep( delay )
136 static void InitSockets()
139 WORD wVersionRequested;
143 wVersionRequested = MAKEWORD( 2, 2 );
145 err = WSAStartup( wVersionRequested, &wsaData );
149 static void ExitSockets()
156 static int CheckForQtplot( count )
159 /* test (via sockets) if qtplot is allready running */
160 if( !OpenClient( 1 ) )
162 /* give qtplot a litle bit time to start... */
163 if( count < QTOPIA_MAX_DELAY_COUNT )
168 system( "start qtplot" );
176 return CheckForQtplot( count+1 );
191 static int OpenClient( test )
195 struct sockaddr_in address;
198 /* Create a socket for the client. */
200 qtopia_client_socket = socket(AF_INET, SOCK_STREAM, 0);
202 if( qtopia_client_socket != QTOPIA_BAD_SOCKET )
204 /* Name the socket, as agreed with the server. */
206 address.sin_family = AF_INET;
207 address.sin_addr.s_addr = inet_addr(/*qtopia_host_name*/"127.0.0.1"); /* localhost */
208 address.sin_port = htons(qtopia_port_no);
209 len = sizeof(address);
211 /* Now connect our socket to the server's socket. */
213 result = connect(qtopia_client_socket, (struct sockaddr *)&address, len);
215 if( result == QTOPIA_BAD_SOCKET )
217 /* mark this socket as bad */
219 close( qtopia_client_socket );
221 qtopia_client_socket = QTOPIA_BAD_SOCKET;
225 fprintf( gpoutfile, "error connecting to server !\n" );
227 return 0; /* something went wrong */
234 fprintf( gpoutfile, "error creating socket !\n" );
236 return 0; /* something went wrong */
239 return 1; /* everything ist ok ! */
242 static void CloseClient()
244 close( qtopia_client_socket );
247 static int IsClientOk()
249 return qtopia_client_socket != QTOPIA_BAD_SOCKET;
252 static void SendDataToSocket( sLine )
259 send_count = send( qtopia_client_socket, sLine, strlen( sLine ), 0 );
261 if( send_count <= 0 )
263 fprintf( gpoutfile, "error writing to socket str=%s!\n", sLine );
268 fprintf( gpoutfile, "wrote %d bytes\n", send_count );
275 /*fprintf( gpoutfile, sLine );*/
279 /* ************************************************** */
281 enum QTOPIA_id { QTOPIA_PORT, QTOPIA_HOST, QTOPIA_OTHER };
283 static struct gen_table QTOPIA_opts[] =
285 { "po$rt", QTOPIA_PORT },
286 { "ho$st", QTOPIA_HOST },
287 { NULL, QTOPIA_OTHER }
293 /* this is not for the qtopia terminal ! */
294 /*SendDataToSocket( "qtd options\n" );*/
299 while (!END_OF_COMMAND)
301 switch(lookup_table(&QTOPIA_opts[0],c_token))
306 int_error(c_token, "expecting port number");
307 qtopia_port_no = (int) real(const_express(&a));
312 int_error(c_token, "expecting host name");
313 if (isstring(c_token))
314 quote_str( qtopia_host_name, c_token, sizeof(qtopia_host_name) );
316 copy_str( qtopia_host_name, c_token, sizeof(qtopia_host_name) );
325 sprintf(term_options, "host=%s port=%d",qtopia_host_name,qtopia_port_no);
332 /* initialize lib (if necassary) */
337 SendDataToSocket( "qtd init\n" );
344 SendDataToSocket( "qtd graphics\n" );
350 SendDataToSocket( "qtd text\n" );
357 SendDataToSocket( "qtd reset\n" );
359 /* give the qtplot a litle bit time to shutdown */
368 QTOPIA_linetype(linetype)
371 char sBuffer[QTOPIA_MAX_BUFFER];
373 sprintf( sBuffer, "qtd linetype type=%d\n",linetype );
375 SendDataToSocket( sBuffer );
383 char sBuffer[QTOPIA_MAX_BUFFER];
385 sprintf( sBuffer, "qtd move x=%d y=%d\n",x,y );
387 SendDataToSocket( sBuffer );
392 QTOPIA_point(x, y, point)
396 char sBuffer[QTOPIA_MAX_BUFFER];
398 sprintf( sBuffer, "qtd point x=%d y=%d point=%d\n",x,y,point );
400 SendDataToSocket( sBuffer );
405 QTOPIA_vector(_x, _y)
408 char sBuffer[QTOPIA_MAX_BUFFER];
410 sprintf( sBuffer, "qtd vector x=%d y=%d\n",_x,_y );
412 SendDataToSocket( sBuffer );
417 QTOPIA_put_text(x, y, str)
421 char sBuffer[QTOPIA_MAX_BUFFER];
423 sprintf( sBuffer, "qtd put_text x=%d y=%d str=%s\n",x,y,str );
425 SendDataToSocket( sBuffer );
428 /* not suported yet ! */
430 QTOPIA_arrow(sx, sy, ex, ey, head)
431 unsigned int sx, sy, ex, ey;
432 int head; /* ignored */
434 char sBuffer[QTOPIA_MAX_BUFFER];
436 sprintf( sBuffer, "qtd arrow sx=%d sy=%d ex=%d ey=%d head=%d\n",sx,sy,ex,ey,head );
438 SendDataToSocket( sBuffer );
442 #endif /* TERM_BODY */
445 TERM_TABLE_START(qtopia_driver)
446 "qtopia", "qtopia or Qt",
447 QTOPIA_XMAX, QTOPIA_YMAX, QTOPIA_VCHAR, QTOPIA_HCHAR,
448 QTOPIA_VTIC, QTOPIA_HTIC, QTOPIA_options, QTOPIA_init, QTOPIA_reset,
449 QTOPIA_text, null_scale, QTOPIA_graphics, QTOPIA_move, QTOPIA_vector,
450 QTOPIA_linetype, QTOPIA_put_text, null_text_angle,
451 null_justify_text, QTOPIA_point, /*QTOPIA_arrow*/0, set_font_null,
454 NULL, NULL, NULL, NULL
456 , NULL, NULL, NULL, NULL, NULL
459 , NULL, NULL, NULL, NULL
461 TERM_TABLE_END(qtopia_driver)
464 #define LAST_TERM qtopia_driver
466 #endif /* TERM_TABLE */
471 "?commands set terminal qtopia",
472 "?set terminal qtopia",
477 " The `qtopia` terminal driver has no additional options.",
480 " set terminal qtopia",
483 #endif /* TERM_HELP */