1 #ifndef lint
RCSid()2 static char *RCSid() { return RCSid("$Id: wgnuplib.c,v 1.12 2016/07/21 09:07:44 markisch 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 <tchar.h>
47 #include <wchar.h>
48 #include "wgnuplib.h"
49 #include "wresourc.h"
50 #include "wcommon.h"
51
52 HINSTANCE hdllInstance;
53 LPWSTR szParentClass = L"wgnuplot_parent";
54 LPWSTR szTextClass = L"wgnuplot_text";
55 LPWSTR szToolbarClass = L"wgnuplot_toolbar";
56 LPWSTR szSeparatorClass = L"wgnuplot_separator";
57 LPWSTR szPauseClass = L"wgnuplot_pause";
58 LPTSTR szGraphClass = TEXT("wgnuplot_graph");
59
60 /* Window ID */
61 struct WID {
62 BOOL used;
63 HWND hwnd;
64 void * ptr;
65 };
66 struct WID *widptr = NULL;
67 unsigned int nwid = 0;
68 HLOCAL hwid = 0;
69
70 void *
LocalAllocPtr(UINT flags,UINT size)71 LocalAllocPtr(UINT flags, UINT size)
72 {
73 HLOCAL hlocal;
74 hlocal = LocalAlloc(flags, size+1);
75 return (char *)LocalLock(hlocal);
76 }
77
78 void *
LocalReAllocPtr(void * ptr,UINT flags,UINT size)79 LocalReAllocPtr(void * ptr, UINT flags, UINT size)
80 {
81 HLOCAL hlocal;
82 hlocal = LocalHandle(ptr);
83 LocalUnlock(hlocal);
84 hlocal = LocalReAlloc(hlocal, size+1, flags);
85 return (char *)LocalLock(hlocal);
86 }
87
88 void
LocalFreePtr(void * ptr)89 LocalFreePtr(void *ptr)
90 {
91 HLOCAL hlocal;
92 hlocal = LocalHandle(ptr);
93 LocalUnlock(hlocal);
94 LocalFree(hlocal);
95 return;
96 }
97
98
99 /* ascii to int */
100 /* returns:
101 * A pointer to character past int if successful,
102 * otherwise NULL on failure.
103 * convert int is stored at pval.
104 */
105 LPTSTR
GetInt(LPTSTR str,LPINT pval)106 GetInt(LPTSTR str, LPINT pval)
107 {
108 int val = 0;
109 BOOL negative = FALSE;
110 BOOL success = FALSE;
111 TCHAR ch;
112
113 if (!str)
114 return NULL;
115 while (((ch = *str) != 0) && isspace(ch))
116 str++;
117
118 if (ch == '-') {
119 negative = TRUE;
120 str++;
121 }
122 while (((ch = *str) != 0) && isdigit(ch)) {
123 success = TRUE;
124 val = val * 10 + (ch - '0');
125 str++;
126 }
127
128 if (success) {
129 if (negative)
130 val = -val;
131 *pval = val;
132 return str;
133 }
134 return NULL;
135 }
136
137