Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / modules / plugin / tools / tester / common / strconv.cpp
blob79725ad370a14ca65d5098d19190155b664ff9e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "xp.h"
40 #include "profile.h"
41 #include "strconv.h"
43 static char szDefaultString[] = PROFILE_DEFAULT_STRING;
45 static BOOL isTrueNumericValue(LPSTR szString)
47 char szPrefix[] = PROFILE_NUMERIC_PREFIX;
48 return (strncmp(szString, szPrefix, strlen(szPrefix)) == 0);
51 static LPSTR convertStringToLPSTR(LPSTR szString)
53 if(szString == NULL)
54 return NULL;
56 if(isTrueNumericValue(szString))
58 char szPrefix[] = PROFILE_NUMERIC_PREFIX;
59 return (LPSTR)atol(szString + strlen(szPrefix));
61 else
62 return szString;
65 DWORD convertStringToLPSTR1(DWORD * pdw1)
67 if(pdw1 == NULL)
68 return 0L;
70 DWORD dwRet = (isTrueNumericValue((LPSTR)(*pdw1)) ? (fTNV1) : 0);
72 *pdw1 = (DWORD)convertStringToLPSTR((LPSTR)(*pdw1));
74 return dwRet;
77 DWORD convertStringToLPSTR2(DWORD * pdw1, DWORD * pdw2)
79 if((pdw1 == NULL) || (pdw2 == NULL))
80 return 0L;
82 DWORD dwRet = (isTrueNumericValue((LPSTR)(*pdw1)) ? (fTNV1) : 0)
83 | (isTrueNumericValue((LPSTR)(*pdw2)) ? (fTNV2) : 0);
85 *pdw1 = (DWORD)convertStringToLPSTR((LPSTR)(*pdw1));
86 *pdw2 = (DWORD)convertStringToLPSTR((LPSTR)(*pdw2));
88 return dwRet;
91 DWORD convertStringToLPSTR3(DWORD * pdw1, DWORD * pdw2, DWORD * pdw3)
93 if((pdw1 == NULL) || (pdw2 == NULL) || (pdw3 == NULL))
94 return 0L;
96 DWORD dwRet = (isTrueNumericValue((LPSTR)(*pdw1)) ? (fTNV1) : 0)
97 | (isTrueNumericValue((LPSTR)(*pdw2)) ? (fTNV2) : 0)
98 | (isTrueNumericValue((LPSTR)(*pdw3)) ? (fTNV3) : 0);
100 *pdw1 = (DWORD)convertStringToLPSTR((LPSTR)(*pdw1));
101 *pdw2 = (DWORD)convertStringToLPSTR((LPSTR)(*pdw2));
102 *pdw3 = (DWORD)convertStringToLPSTR((LPSTR)(*pdw3));
104 return dwRet;
107 // converts numeric value represented by string to DWORD
108 static DWORD convertStringToDWORD(LPSTR szString)
110 if(szString == NULL)
111 return 0L;
113 if(strcmp(szString, szDefaultString) == 0)
114 return DEFAULT_DWARG_VALUE;
115 else
116 return (DWORD)atol(szString);
119 void convertStringToDWORD1(DWORD * pdw1)
121 if(pdw1 == NULL)
122 return;
123 *pdw1 = convertStringToDWORD((LPSTR)(*pdw1));
126 void convertStringToDWORD2(DWORD * pdw1, DWORD * pdw2)
128 if((pdw1 == NULL) || (pdw2 == NULL))
129 return;
130 *pdw1 = convertStringToDWORD((LPSTR)(*pdw1));
131 *pdw2 = convertStringToDWORD((LPSTR)(*pdw2));
134 void convertStringToDWORD3(DWORD * pdw1, DWORD * pdw2, DWORD * pdw3)
136 if((pdw1 == NULL) || (pdw2 == NULL) || (pdw3 == NULL))
137 return;
138 *pdw1 = convertStringToDWORD((LPSTR)(*pdw1));
139 *pdw2 = convertStringToDWORD((LPSTR)(*pdw2));
140 *pdw3 = convertStringToDWORD((LPSTR)(*pdw3));
143 void convertStringToDWORD4(DWORD * pdw1, DWORD * pdw2, DWORD * pdw3, DWORD * pdw4)
145 if((pdw1 == NULL) || (pdw2 == NULL) || (pdw3 == NULL) || (pdw4 == NULL))
146 return;
148 *pdw1 = convertStringToDWORD((LPSTR)(*pdw1));
149 *pdw2 = convertStringToDWORD((LPSTR)(*pdw2));
150 *pdw3 = convertStringToDWORD((LPSTR)(*pdw3));
151 *pdw4 = convertStringToDWORD((LPSTR)(*pdw4));
154 static NPBool convertStringToBOOL(LPSTR szString)
156 if(szString == NULL)
157 return (NPBool)NULL;
159 if(isTrueNumericValue(szString))
161 char szPrefix[] = PROFILE_NUMERIC_PREFIX;
162 return (NPBool)atol(szString + strlen(szPrefix));
164 else
166 NPBool npb = (stricmp(szString, "TRUE") == 0) ? TRUE : FALSE;
167 return npb;
171 DWORD convertStringToBOOL1(DWORD * pdw1)
173 if(pdw1 == NULL)
174 return 0L;
176 DWORD dwRet = (isTrueNumericValue((LPSTR)(*pdw1)) ? (fTNV1) : 0);
178 *pdw1 = (DWORD)convertStringToBOOL((LPSTR)(*pdw1));
180 return dwRet;
183 static NPReason convertStringToNPReason(LPSTR szString)
185 if(szString == NULL)
186 return NPRES_DONE;
188 if(isTrueNumericValue(szString))
190 char szPrefix[] = PROFILE_NUMERIC_PREFIX;
191 return (NPReason)atol(szString + strlen(szPrefix));
193 else
195 if(stricmp(ENTRY_NPRES_DONE, szString) == 0)
196 return NPRES_DONE;
197 else if(stricmp(ENTRY_NPRES_NETWORK_ERR, szString) == 0)
198 return NPRES_NETWORK_ERR;
199 else if(stricmp(ENTRY_NPRES_USER_BREAK, szString) == 0)
200 return NPRES_USER_BREAK;
201 else
202 return NPRES_DONE;
206 DWORD convertStringToNPReason1(DWORD * pdw1)
208 if(pdw1 == NULL)
209 return 0L;
211 *pdw1 = (DWORD)convertStringToNPReason((LPSTR)(*pdw1));
213 return 0L;
216 static NPNVariable convertStringToNPNVariable(LPSTR szString)
218 if(szString == NULL)
219 return (NPNVariable)0;
221 if(isTrueNumericValue(szString))
223 char szPrefix[] = PROFILE_NUMERIC_PREFIX;
224 return (NPNVariable)atol(szString + strlen(szPrefix));
226 else
228 if(stricmp(ENTRY_NPNVXDISPLAY, szString) == 0)
229 return NPNVxDisplay;
230 else if(stricmp(ENTRY_NPNVXTAPPCONTEXT, szString) == 0)
231 return NPNVxtAppContext;
232 else if(stricmp(ENTRY_NPNVNETSCAPEWINDOW, szString) == 0)
233 return NPNVnetscapeWindow;
234 else if(stricmp(ENTRY_NPNVJAVASCRIPTENABLEDBOOL, szString) == 0)
235 return NPNVjavascriptEnabledBool;
236 else if(stricmp(ENTRY_NPNVASDENABLEDBOOL, szString) == 0)
237 return NPNVasdEnabledBool;
238 else if(stricmp(ENTRY_NPNVISOFFLINEBOOL, szString) == 0)
239 return NPNVisOfflineBool;
240 else
241 return (NPNVariable)0;
245 DWORD convertStringToNPNVariable1(DWORD * pdw1)
247 if(pdw1 == NULL)
248 return 0L;
250 DWORD dwRet = (isTrueNumericValue((LPSTR)(*pdw1)) ? (fTNV1) : 0);
252 *pdw1 = (DWORD)convertStringToNPNVariable((LPSTR)(*pdw1));
254 return dwRet;
257 static NPPVariable convertStringToNPPVariable(LPSTR szString)
259 if(szString == NULL)
260 return (NPPVariable)0;
262 if(isTrueNumericValue(szString))
264 char szPrefix[] = PROFILE_NUMERIC_PREFIX;
265 return (NPPVariable)atol(szString + strlen(szPrefix));
267 else
269 if(stricmp(ENTRY_NPPVPLUGINNAMESTRING, szString) == 0)
270 return NPPVpluginNameString;
271 else if(stricmp(ENTRY_NPPVPLUGINDESCRIPTIONSTRING, szString) == 0)
272 return NPPVpluginDescriptionString;
273 else if(stricmp(ENTRY_NPPVPLUGINWINDOWBOOL, szString) == 0)
274 return NPPVpluginWindowBool;
275 else if(stricmp(ENTRY_NPPVPLUGINTRANSPARENTBOOL, szString) == 0)
276 return NPPVpluginTransparentBool;
277 else if(stricmp(ENTRY_NPPVPLUGINKEEPLIBRARYINMEMORY, szString) == 0)
278 return NPPVpluginKeepLibraryInMemory;
279 else if(stricmp(ENTRY_NPPVPLUGINWINDOWSIZE, szString) == 0)
280 return NPPVpluginWindowSize;
281 else
282 return (NPPVariable)0;
286 DWORD convertStringToNPPVariable1(DWORD * pdw1)
288 if(pdw1 == NULL)
289 return 0L;
291 DWORD dwRet = (isTrueNumericValue((LPSTR)(*pdw1)) ? (fTNV1) : 0);
293 *pdw1 = (DWORD)convertStringToNPPVariable((LPSTR)(*pdw1));
295 return dwRet;
298 NPByteRange * convertStringToNPByteRangeList(LPSTR szString)
300 NPByteRange **brNextFromPrev, *brList = 0;
301 if(szString) {
302 int offset = -1, len = -1;
303 char *p = szString;
304 while (EOF != sscanf((const char*)p, "%d-%d", &offset, &len)) {
305 if (offset == -1 || len == -1)
306 break;
307 NPByteRange *brCurr = new NPByteRange;
308 brCurr->offset = offset;
309 brCurr->length = len;
310 brCurr->next = 0;
311 if (!brList)
312 brList = brCurr;
313 else
314 *brNextFromPrev = brCurr;
316 brNextFromPrev = &brCurr->next;
318 if (!(p = strchr(p, ',')))
319 break;
320 while(*(++p) == ' '); // cut off white spaces
323 return brList;