source: GPL/branches/uniaud32-next/drv32/parse.c

Last change on this file was 677, checked in by Paul Smedley, 4 years ago

More code cleanups from AlexT from #os2russian

File size: 9.2 KB
Line 
1/* $Id: parse.c,v 1.3 2003/08/08 15:09:03 vladest Exp $ */
2
3/*
4 * Config.sys parameter parsing
5 *
6 * (C) 2000-2002 InnoTek Systemberatung GmbH
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * USA.
22 */
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27#define INCL_NOPMAPI
28#define INCL_DOSMISC
29#include <os2.h>
30#ifdef __cplusplus
31}
32#endif
33
34#include <devtype.h>
35#include <string.h>
36#include "parse.h" // NUM_DEVICES
37
38#define COMM_DEBUG
39
40// True if the /V parameter was specified
41int fVerbose = FALSE;
42int fDebug = FALSE;
43//int ForceCard = CARD_NONE;
44int iAdapterNumber = -1;
45
46extern short int midi_port;
47
48#ifdef COMM_DEBUG
49extern short int MAGIC_COMM_PORT;
50#endif
51
52//*****************************************************************************
53//*****************************************************************************
54int toupper(int c)
55{
56 return (unsigned) c - 'a' <= 'z' - 'a' ? c - ('a' - 'A') : c;
57}
58//*****************************************************************************
59//*****************************************************************************
60CHAR FAR48 *mymemchr(CHAR FAR48 *strP, CHAR c, USHORT size)
61{
62 USHORT i;
63 // search for the character - return position if found
64 i = 0;
65 while (i <= size - 1) {
66 if (*strP == c)
67 return (strP);
68 strP++;
69 i++;
70 }
71 // character not found - return null
72 return ((CHAR FAR48 *) 0);
73}
74//*****************************************************************************
75//*****************************************************************************
76
77USHORT sz2us(char FAR48 *sz, int base)
78{
79 static char digits[] = "0123456789ABCDEF";
80
81 USHORT us=0;
82 // char *pc;
83 CHAR FAR48 *pc;
84
85 // skip leading spaces
86 while (*sz == ' ') sz++;
87
88 // skip leading zeros
89 while (*sz == '0') sz++;
90
91 // accumulate digits - return error if unexpected character encountered
92 for (;;sz++) {
93 pc = (CHAR FAR48 *) mymemchr(digits, toupper(*sz), base);
94 if (!pc)
95 return us;
96 us = (us * base) + (pc - digits);
97 }
98}
99//*****************************************************************************
100//*****************************************************************************
101int IsWhitespace(char ch)
102{
103 if ( ch > '9' && ch < 'A')
104 return TRUE;
105 if ( ch < '0' || ch > 'Z')
106 return TRUE;
107
108 return FALSE;
109}
110//*****************************************************************************
111//*****************************************************************************
112char FAR48 *SkipWhite(char FAR48 *psz)
113{
114 while (*psz) {
115 if (!IsWhitespace((char) toupper(*psz))) return psz;
116 psz++;
117 }
118 return NULL;
119}
120//*****************************************************************************
121
122#if 0
123//*****************************************************************************
124void CheckCardName(char FAR48 *psz)
125{
126 char name[CARD_MAX_LEN+1];
127 int i;
128
129 for (i=0; i<CARD_MAX_LEN; i++) {
130 name[i] = toupper(psz[i]);
131 if(name[i] == ' ') {
132 name[i] = 0;
133 break;
134 }
135 }
136 name[CARD_MAX_LEN] = 0;
137
138 if(!strcmp(name, CARD_STRING_SBLIVE)) {
139 ForceCard = CARD_SBLIVE;
140 }
141 else
142 if(!strcmp(name, CARD_STRING_ALS4000)) {
143 ForceCard = CARD_ALS4000;
144 }
145 else
146 if(!strcmp(name, CARD_STRING_CMEDIA)) {
147 ForceCard = CARD_CMEDIA;
148 }
149 else
150 if(!strcmp(name, CARD_STRING_CS4281)) {
151 ForceCard = CARD_CS4281;
152 }
153 else
154 if(!strcmp(name, CARD_STRING_ICH)) {
155 ForceCard = CARD_ICH;
156 }
157 else
158 if(!strcmp(name, CARD_STRING_CS46XX)) {
159 ForceCard = CARD_CS46XX;
160 }
161 else
162 if(!strcmp(name, CARD_STRING_VIA82XX)) {
163 ForceCard = CARD_VIA82XX;
164 }
165 else
166 if(!strcmp(name, CARD_STRING_ESS1938)) {
167 ForceCard = CARD_ESS1938;
168 }
169 else
170 if(!strcmp(name, CARD_STRING_VORTEX)) {
171 ForceCard = CARD_VORTEX;
172 }
173 else
174 if(!strcmp(name, CARD_STRING_ENSONIQ)) {
175 ForceCard = CARD_ENSONIQ;
176 }
177 else
178 if(!strcmp(name, CARD_STRING_TRIDENT)) {
179 ForceCard = CARD_TRIDENT;
180 }
181 else
182 if(!strcmp(name, CARD_STRING_NEOMAGIC)) {
183 ForceCard = CARD_NEOMAGIC;
184 }
185 else
186 if(!strcmp(name, CARD_STRING_FM801)) {
187 ForceCard = CARD_FM801;
188 }
189 else
190 if(!strcmp(name, CARD_STRING_ATIIXP)) {
191 ForceCard = CARD_ATIIXP;
192 }
193 else
194 if(!strcmp(name, CARD_STRING_AUDIGYLS)) {
195 ForceCard = CARD_AUDIGYLS;
196 }
197 else
198 if(!strcmp(name, CARD_STRING_BT87X)) {
199 ForceCard = CARD_BT87X;
200 }
201 else
202 if(!strcmp(name, CARD_STRING_AZX)) {
203 ForceCard = CARD_AZX;
204 }
205
206}
207//*****************************************************************************
208#endif
209
210//*****************************************************************************
211int DoParm(char cParm, char FAR48 *pszOption)
212{
213 switch (cParm) {
214 case 'A':
215 iAdapterNumber = *pszOption & 0x07;
216 break;
217 case 'V': // Verbose option
218 fVerbose = TRUE;
219 break;
220 case 'D':
221 fDebug = TRUE;
222 break;
223 //case 'C':
224 //CheckCardName(pszOption);
225 //break;
226#if 1
227 case 'M':
228 midi_port = 0x300;
229 //sz2us(pszOption, 16);
230 break;
231#endif
232#ifdef COMM_DEBUG
233 case 'P':
234 if(*pszOption == '0') {
235 MAGIC_COMM_PORT = 0x000;
236 }
237 else
238 if(*pszOption == '1') {
239 MAGIC_COMM_PORT = 0x3f8;
240 }
241 else
242 if(*pszOption == '2') {
243 MAGIC_COMM_PORT = 0x2f8;
244 }
245 if(*pszOption == '4') {
246 MAGIC_COMM_PORT = 0x4000;
247 }
248 break;
249#endif
250
251 default:
252 return FALSE; // unknown parameter
253 }
254 return TRUE;
255}
256
257/* Function: ParseParm
258 Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
259 length of this parameter, which must be at least 1
260 Output: TRUE if the parameter was value
261 Purpose: parses the string into three parts: the letter parameter, the port
262 number, and the option string. Calls DoParm with these values.
263 Notes:
264 the following describes the format of valid parameters.
265 1. Parameters consist of a letter, an optional number, and an
266 optional 'option'. The format is x[n][:option], where 'x' is the
267 letter, 'n' is the number, and 'option' is the option.
268 2. Blanks are delimeters between parameters, therefore there are no
269 blanks within a parameter.
270 3. The option is preceded by a colon
271 This gives us only four possibilities:
272 P (length == 1)
273 P1 (length == 2)
274 P:option (length >= 3)
275 P1:option (length >= 4)
276*/
277int ParseParm(char FAR48 *pszParm, int iLength)
278{
279 char ch,ch1=(char) toupper(*pszParm); // get letter
280
281 if (iLength == 1) // only a letter?
282 return DoParm(ch1,NULL);
283
284 ch=pszParm[1]; // should be either 1-9 or :
285 if (ch < '1' || (ch > '9' && ch != ':'))
286 return FALSE;
287
288 if (iLength == 3) {
289 if (ch != ':')
290 return FALSE;
291 return DoParm(ch1,pszParm+2);
292 }
293
294 if (ch == ':')
295 return DoParm(ch1,pszParm+2);
296
297 return DoParm(ch1, pszParm+3);
298}
299//*****************************************************************************
300//*****************************************************************************
301int GetParms(char FAR48 *pszCmdLine)
302{
303 int iLength;
304
305 while (*pszCmdLine != ' ') { // skip over filename
306 if (!*pszCmdLine) return TRUE; // no params? then just exit
307 pszCmdLine++;
308 }
309
310 while (TRUE) {
311 pszCmdLine=SkipWhite(pszCmdLine); // move to next param
312 if (!pszCmdLine) return TRUE; // exit if no more
313
314 for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
315 if (pszCmdLine[iLength] == ' ') break; // of parameter
316
317 if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
318 return FALSE;
319
320 while (*pszCmdLine != ' ') { // skip over parameter
321 if (!*pszCmdLine) return TRUE; // no params? then just exit
322 pszCmdLine++;
323 }
324 }
325}
326//*****************************************************************************
327//*****************************************************************************
328
Note: See TracBrowser for help on using the repository browser.