2 static char RCSid[]="$Id: gnupmdrv.c,v 1.6 2005/07/28 07:46:06 mikulik Exp $" ;
5 /****************************************************************************
9 Outboard PM driver for GNUPLOT 3.x
13 This file contains the startup procedures for gnupmdrv
15 ****************************************************************************/
17 /* PM driver for GNUPLOT */
20 * Copyright 1992, 1993, 1998, 2004 Roger Fearick
22 * Permission to use, copy, and distribute this software and its
23 * documentation for any purpose with or without fee is hereby granted,
24 * provided that the above copyright notice appear in all copies and
25 * that both that copyright notice and this permission notice appear
26 * in supporting documentation.
28 * Permission to modify the software is granted, but not the right to
29 * distribute the complete modified source code. Modifications are to
30 * be distributed as patches to the released version. Permission to
31 * distribute binaries produced by compiling modified sources is granted,
33 * 1. distribute the corresponding source modifications from the
34 * released version in the form of a patch file along with the binaries,
35 * 2. add special version identification to distinguish your version
36 * in addition to the base release version number,
37 * 3. provide your name and address as the primary contact for the
38 * support of your modified version, and
39 * 4. retain our contact information in regard to use of the base
41 * Permission to distribute the released version of the source code along
42 * with corresponding source modifications in the form of a patch file is
43 * granted with same provisions 2 through 4 for binary distributions.
45 * This software is provided "as is" without express or implied warranty
46 * to the extent permitted by applicable law.
53 * Gnuplot driver for OS/2: Roger Fearick
59 #define INCL_SPLDOSPRINT
60 #define INCL_DOSMEMMGR
61 #define INCL_DOSPROCESS
62 #define INCL_DOSFILEMGR
70 /*==== g l o b a l d a t a ================================================*/
74 #define IPCDEFAULT "gnuplot"
78 #ifdef PM_KEEP_OLD_ENHANCED_TEXT
82 /*==== l o c a l d a t a ==================================================*/
84 /* class names for window registration */
86 static char szTitle[256] = "Gnuplot" ;
88 /*==== f u n c t i o n s =====================================================*/
90 BOOL QueryIni( HAB ) ;
91 int main( int, char** ) ;
92 static HWND InitHelp( HAB, HWND ) ;
94 /*==== c o d e ===============================================================*/
96 int main ( int argc, char **argv )
98 ** args: argv[1] : name to be used for IPC (pipes/semaphores) with gnuplot
100 ** Standard PM initialisation:
101 ** -- set up message processing loop
102 ** -- register all window classes
103 ** -- start up main window
104 ** -- subclass main window for help and dde message trapping to frame window
105 ** -- init help system
106 ** -- check command line and open any filename found there
110 static ULONG flFrameFlags = (FCF_ACCELTABLE|FCF_STANDARD);//&(~FCF_TASKLIST) ;
111 static ULONG flClientFlags = WS_VISIBLE ;
114 PFNWP pfnOldFrameWndProc ;
119 * A subtile problem is fixed here:
120 * upon the first initialization of this driver (i.e. we're here in main())
121 * it may inherit handles of files opened (temporarily) by gnuplot itself!
122 * We close them here.
126 if( argc <= 1 ) strcpy( szIPCName, IPCDEFAULT ) ;
129 strcpy( szIPCName, argv[1] ) ;
130 for ( i=2; i<argc; i++ ) {
131 while( *argv[i] != '\0' ) {
132 if( *argv[i] == '-' ) {
138 #ifdef PM_KEEP_OLD_ENHANCED_TEXT
151 else if ( *argv[i] == '"' ) {
154 while( *argv[i] != '"' ) {
165 /* get path from argv[0] to track down program files */
166 strcpy( szIniFile, argv[0] ) ;
167 while( (p=strchr(szIniFile,'/'))!=NULL ) *p = '\\' ;
168 p = strrchr(szIniFile,'\\') ;
169 if(p==NULL) p = strrchr(szIniFile,':') ;
170 if(p==NULL) p = szIniFile ;
175 hab = WinInitialize( 0 ) ;
176 hmq = WinCreateMsgQueue( hab, 50 ) ;
178 // get defaults from gnupmdrv.ini
180 bPos = QueryIni( hab ) ;
182 // register window and child window classes
184 if( ! WinRegisterClass( hab, /* Exit if can't register */
186 (PFNWP)DisplayClientWndProc,
191 // create main window
193 hwndFrame = WinCreateStdWindow (
204 if ( ! hwndFrame ) return 0 ;
206 // subclass window for help & DDE trapping
208 pfnOldFrameWndProc = WinSubclassWindow( hwndFrame, (PFNWP)NewFrameWndProc ) ;
209 WinSetWindowULong( hwndFrame, QWL_USER, (ULONG) pfnOldFrameWndProc ) ;
211 // init the help manager
213 hwndHelp = InitHelp( hab, hwndFrame ) ;
215 // set window title and make it active
218 char text[256] = APP_NAME;
219 strcat( text, " [" ) ;
220 strcat( text, szTitle ) ;
221 strcat( text, "]" ) ;
222 WinSetWindowText( hwndFrame, text ) ;
224 // process window messages
226 while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
227 WinDispatchMsg (hab, &qmsg) ;
231 WinDestroyHelpInstance( hwndHelp ) ;
232 WinDestroyWindow (hwndFrame) ;
233 WinDestroyMsgQueue (hmq) ;
239 static HWND InitHelp( HAB hab, HWND hwnd )
241 ** initialise the help system
244 static HELPINIT helpinit = { sizeof(HELPINIT),
247 (PHELPTABLE)MAKELONG(1, 0xFFFF),
256 /* should be bigger or dynamic */
257 static char helppath[256] ;
259 _execname(helppath, sizeof(helppath));
260 _fnslashify(helppath);
261 p=strrchr(helppath, '/');
264 strcat( helppath, "/" ) ;
265 strcat( helppath, helpinit.pszHelpLibraryName ) ;
266 helpinit.pszHelpLibraryName = helppath ;
268 hwndHelp = WinCreateHelpInstance( hab, &helpinit ) ;
269 WinAssociateHelpInstance( hwndHelp, hwnd ) ;
273 MRESULT EXPENTRY NewFrameWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
275 ** Subclasses top-level frame window to trap help & dde messages
278 PFNWP pfnOldFrameWndProc ;
280 pfnOldFrameWndProc = (PFNWP) WinQueryWindowULong( hwnd, QWL_USER ) ;
285 case HM_QUERY_KEYS_HELP:
286 return (MRESULT) IDH_KEYS ;
288 return (*pfnOldFrameWndProc)(hwnd, msg, mp1, mp2) ;
292 MRESULT EXPENTRY About( HWND hDlg, ULONG message, MPARAM mp1, MPARAM mp2)
294 ** 'About' box dialog function
297 return WinDefDlgProc( hDlg, message, mp1, mp2 ) ;