1 /* GNUPLOT - win/wgnuplib.c */
2 /*[
3  * Copyright 1992, 1993, 1998, 2004   Russell Lang
4  *
5  * Permission to use, copy, and distribute this software and its
6  * documentation for any purpose with or without fee is hereby granted,
7  * provided that the above copyright notice appear in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation.
10  *
11  * Permission to modify the software is granted, but not the right to
12  * distribute the complete modified source code.  Modifications are to
13  * be distributed as patches to the released version.  Permission to
14  * distribute binaries produced by compiling modified sources is granted,
15  * provided you
16  *   1. distribute the corresponding source modifications from the
17  *    released version in the form of a patch file along with the binaries,
18  *   2. add special version identification to distinguish your version
19  *    in addition to the base release version number,
20  *   3. provide your name and address as the primary contact for the
21  *    support of your modified version, and
22  *   4. retain our contact information in regard to use of the base
23  *    software.
24  * Permission to distribute the released version of the source code along
25  * with corresponding source modifications in the form of a patch file is
26  * granted with same provisions 2 through 4 for binary distributions.
27  *
28  * This software is provided "as is" without express or implied warranty
29  * to the extent permitted by applicable law.
30 ]*/
31 
32 /*
33  * AUTHORS
34  *
35  *   Russell Lang
36  */
37 
38 #define STRICT
39 #include <ctype.h>
40 #include <windows.h>
41 #include <windowsx.h>
42 #include <tchar.h>
43 #include <wchar.h>
44 #include "wgnuplib.h"
45 #include "wresourc.h"
46 #include "wcommon.h"
47 
48 HINSTANCE hdllInstance;
49 LPWSTR szParentClass = L"wgnuplot_parent";
50 LPWSTR szTextClass = L"wgnuplot_text";
51 LPWSTR szToolbarClass = L"wgnuplot_toolbar";
52 LPWSTR szSeparatorClass = L"wgnuplot_separator";
53 LPWSTR szPauseClass = L"wgnuplot_pause";
54 
55 /* Window ID */
56 struct WID {
57 	BOOL    used;
58 	HWND    hwnd;
59 	void  * ptr;
60 };
61 struct WID *widptr = NULL;
62 unsigned int nwid = 0;
63 HLOCAL hwid = 0;
64 
65 void *
LocalAllocPtr(UINT flags,UINT size)66 LocalAllocPtr(UINT flags, UINT size)
67 {
68 HLOCAL hlocal;
69 	hlocal = LocalAlloc(flags, size+1);
70 	return (char *)LocalLock(hlocal);
71 }
72 
73 void *
LocalReAllocPtr(void * ptr,UINT flags,UINT size)74 LocalReAllocPtr(void * ptr, UINT flags, UINT size)
75 {
76 HLOCAL hlocal;
77 	hlocal = LocalHandle(ptr);
78 	LocalUnlock(hlocal);
79 	hlocal = LocalReAlloc(hlocal, size+1, flags);
80 	return (char *)LocalLock(hlocal);
81 }
82 
83 void
LocalFreePtr(void * ptr)84 LocalFreePtr(void *ptr)
85 {
86 HLOCAL hlocal;
87 	hlocal = LocalHandle(ptr);
88 	LocalUnlock(hlocal);
89 	LocalFree(hlocal);
90 	return;
91 }
92 
93 
94 /* ascii to int */
95 /* returns:
96  *  A pointer to character past int if successful,
97  *  otherwise NULL on failure.
98  *  convert int is stored at pval.
99  */
100 LPTSTR
GetInt(LPTSTR str,LPINT pval)101 GetInt(LPTSTR str, LPINT pval)
102 {
103     int val = 0;
104     BOOL negative = FALSE;
105     BOOL success = FALSE;
106     TCHAR ch;
107 
108     if (!str)
109 	return NULL;
110     while (((ch = *str) != 0) && isspace(ch))
111 	str++;
112 
113     if (ch == '-') {
114 	negative = TRUE;
115 	str++;
116     }
117     while (((ch = *str) != 0) && isdigit(ch)) {
118 	success = TRUE;
119 	val = val * 10 + (ch - '0');
120 	str++;
121     }
122 
123     if (success) {
124 	if (negative)
125 	    val = -val;
126 	*pval = val;
127 	return str;
128     }
129     return NULL;
130 }
131 
132