Initial release of Maemo 5 port of gnuplot
[gnuplot] / src / win / wgnuplib.c
1 #ifndef lint
2 static char *RCSid() { return RCSid("$Id: wgnuplib.c,v 1.6 2004/07/01 17:10:10 broeker Exp $"); }
3 #endif
4
5 /* GNUPLOT - win/wgnuplib.c */
6 /*[
7  * Copyright 1992, 1993, 1998, 2004   Russell Lang
8  *
9  * Permission to use, copy, and distribute this software and its
10  * documentation for any purpose with or without fee is hereby granted,
11  * provided that the above copyright notice appear in all copies and
12  * that both that copyright notice and this permission notice appear
13  * in supporting documentation.
14  *
15  * Permission to modify the software is granted, but not the right to
16  * distribute the complete modified source code.  Modifications are to
17  * be distributed as patches to the released version.  Permission to
18  * distribute binaries produced by compiling modified sources is granted,
19  * provided you
20  *   1. distribute the corresponding source modifications from the
21  *    released version in the form of a patch file along with the binaries,
22  *   2. add special version identification to distinguish your version
23  *    in addition to the base release version number,
24  *   3. provide your name and address as the primary contact for the
25  *    support of your modified version, and
26  *   4. retain our contact information in regard to use of the base
27  *    software.
28  * Permission to distribute the released version of the source code along
29  * with corresponding source modifications in the form of a patch file is
30  * granted with same provisions 2 through 4 for binary distributions.
31  *
32  * This software is provided "as is" without express or implied warranty
33  * to the extent permitted by applicable law.
34 ]*/
35
36 /*
37  * AUTHORS
38  *
39  *   Russell Lang
40  */
41
42 #define STRICT
43 #include <ctype.h>
44 #include <windows.h>
45 #include <windowsx.h>
46 #include "wgnuplib.h"
47 #include "wresourc.h"
48 #include "wcommon.h"
49
50 HINSTANCE hdllInstance;
51 LPSTR szParentClass = "wgnuplot_parent";
52 LPSTR szTextClass = "wgnuplot_text";
53 LPSTR szPauseClass = "wgnuplot_pause";
54 LPSTR szGraphClass = "wgnuplot_graph";
55
56 /* Window ID */
57 struct WID {
58         BOOL       used;
59         HWND       hwnd;
60         void FAR * ptr;
61 };
62 struct WID *widptr = NULL;
63 unsigned int nwid = 0;
64 HLOCAL hwid = 0;
65
66 #ifdef __DLL__
67 int WDPROC
68 LibMain(HINSTANCE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
69 {
70         hdllInstance = hInstance;
71         return 1;
72 }
73
74 int WDPROC
75 WEP(int nParam)
76 {
77         return 1;
78 }
79
80 BOOL WDPROC
81 CheckWGNUPLOTVersion(LPSTR str)
82 {
83 char mess[256];
84 LPSTR version;
85         version = WGNUPLOTVERSION;
86         if (lstrcmp(str,version)) {
87                 wsprintf(mess,"Incorrect DLL version\nExpected version   %s\nThis is version   %s",str,version);
88                 MessageBox(NULL, mess , "WGNUPLOT.DLL", MB_OK | MB_ICONSTOP | MB_TASKMODAL);
89                 return TRUE;
90         }
91         return FALSE;   /* Correct version */
92 }
93 #endif /* __DLL__ */
94
95 void NEAR *
96 LocalAllocPtr(UINT flags, UINT size)
97 {
98 HLOCAL hlocal;
99         hlocal = LocalAlloc(flags, size+1);
100         return (char *)LocalLock(hlocal);
101 }
102
103 void NEAR *
104 LocalReAllocPtr(void NEAR * ptr, UINT flags, UINT size)
105 {
106 HLOCAL hlocal;
107         hlocal = LocalHandle(ptr);
108         LocalUnlock(hlocal);
109         hlocal = LocalReAlloc(hlocal, size+1, flags);
110         return (char *)LocalLock(hlocal);
111 }
112
113 void
114 LocalFreePtr(void NEAR *ptr)
115 {
116 HLOCAL hlocal;
117         hlocal = LocalHandle(ptr);
118         LocalUnlock(hlocal);
119         LocalFree(hlocal);
120         return;
121 }
122
123
124 /* ascii to int */
125 /* returns:
126  *  A pointer to character past int if successful,
127  *  otherwise NULL on failure.
128  *  convert int is stored at pval.
129  */
130 LPSTR
131 GetInt(LPSTR str, LPINT pval)
132 {
133     int val = 0;
134     BOOL negative = FALSE;
135     BOOL success = FALSE;
136     unsigned char ch;
137
138     if (!str)
139         return NULL;
140     while ( (ch = *str)!=0 && isspace(ch) )
141         str++;
142
143     if (ch == '-') {
144         negative = TRUE;
145         str++;
146     }
147     while ( (ch = *str)!=0 && isdigit(ch) ) {
148         success = TRUE;
149         val = val * 10 + (ch - '0');
150         str++;
151     }
152
153     if (success) {
154         if (negative)
155             val = -val;
156         *pval = val;
157         return str;
158     }
159     return NULL;
160 }
161