source: GPL/branches/uniaud32-2.1.x/drv32/parse.c@ 594

Last change on this file since 594 was 594, checked in by David Azarewicz, 8 years ago

Code cleanup.
Hack for tick.

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 <devhelp.h>
35#include <devtype.h>
36#include <unicard.h>
37#include "parse.h" // NUM_DEVICES
38#include <string.h>
39
40#define COMM_DEBUG
41
42// True if the /V parameter was specified
43int fVerbose = FALSE;
44int fDebug = FALSE;
45int ForceCard = CARD_NONE;
46int iAdapterNumber = 0;
47
48extern short int midi_port;
49
50#ifdef COMM_DEBUG
51extern short int MAGIC_COMM_PORT;
52#endif
53
54//*****************************************************************************
55//*****************************************************************************
56int toupper(int c)
57{
58 return (unsigned) c - 'a' <= 'z' - 'a' ? c - ('a' - 'A') : c;
59}
60//*****************************************************************************
61//*****************************************************************************
62CHAR FAR48 *mymemchr(CHAR FAR48 *strP, CHAR c, USHORT size)
63{
64 USHORT i;
65 // search for the character - return position if found
66 i = 0;
67 while (i <= size - 1) {
68 if (*strP == c)
69 return (strP);
70 strP++;
71 i++;
72 }
73 // character not found - return null
74 return ((CHAR FAR48 *) 0);
75}
76//*****************************************************************************
77//*****************************************************************************
78
79USHORT sz2us(char FAR48 *sz, int base)
80{
81 static char digits[] = "0123456789ABCDEF";
82
83 USHORT us=0;
84 // char *pc;
85 CHAR FAR48 *pc;
86
87 // skip leading spaces
88 while (*sz == ' ') sz++;
89
90 // skip leading zeros
91 while (*sz == '0') sz++;
92
93 // accumulate digits - return error if unexpected character encountered
94 for (;;sz++) {
95 pc = (CHAR FAR48 *) mymemchr(digits, toupper(*sz), base);
96 if (!pc)
97 return us;
98 us = (us * base) + (pc - digits);
99 }
100}
101//*****************************************************************************
102//*****************************************************************************
103int IsWhitespace(char ch)
104{
105 if ( ch > '9' && ch < 'A')
106 return TRUE;
107 if ( ch < '0' || ch > 'Z')
108 return TRUE;
109
110 return FALSE;
111}
112//*****************************************************************************
113//*****************************************************************************
114char FAR48 *SkipWhite(char FAR48 *psz)
115{
116 while (*psz) {
117 if (!IsWhitespace((char) toupper(*psz))) return psz;
118 psz++;
119 }
120 return NULL;
121}
122//*****************************************************************************
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//*****************************************************************************
209int DoParm(char cParm, char FAR48 *pszOption)
210{
211 switch (cParm) {
212 case 'A':
213 iAdapterNumber = *pszOption & 0x07;
214 break;
215 case 'V': // Verbose option
216 fVerbose = TRUE;
217 break;
218 case 'D':
219 fDebug = TRUE;
220 break;
221 case 'C':
222 CheckCardName(pszOption);
223 break;
224#if 1
225 case 'M':
226 midi_port = 0x300;
227 //sz2us(pszOption, 16);
228 break;
229#endif
230#ifdef COMM_DEBUG
231 case 'P':
232 if(*pszOption == '0') {
233 MAGIC_COMM_PORT = 0x000;
234 }
235 else
236 if(*pszOption == '1') {
237 MAGIC_COMM_PORT = 0x3f8;
238 }
239 else
240 if(*pszOption == '2') {
241 MAGIC_COMM_PORT = 0x2f8;
242 }
243 if(*pszOption == '4') {
244 MAGIC_COMM_PORT = 0x4000;
245 }
246 break;
247#endif
248
249 default:
250 return FALSE; // unknown parameter
251 }
252 return TRUE;
253}
254
255/* Function: ParseParm
256 Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
257 length of this parameter, which must be at least 1
258 Output: TRUE if the parameter was value
259 Purpose: parses the string into three parts: the letter parameter, the port
260 number, and the option string. Calls DoParm with these values.
261 Notes:
262 the following describes the format of valid parameters.
263 1. Parameters consist of a letter, an optional number, and an
264 optional 'option'. The format is x[n][:option], where 'x' is the
265 letter, 'n' is the number, and 'option' is the option.
266 2. Blanks are delimeters between parameters, therefore there are no
267 blanks within a parameter.
268 3. The option is preceded by a colon
269 This gives us only four possibilities:
270 P (length == 1)
271 P1 (length == 2)
272 P:option (length >= 3)
273 P1:option (length >= 4)
274*/
275int ParseParm(char FAR48 *pszParm, int iLength)
276{
277 char ch,ch1=(char) toupper(*pszParm); // get letter
278
279 if (iLength == 1) // only a letter?
280 return DoParm(ch1,NULL);
281
282 ch=pszParm[1]; // should be either 1-9 or :
283 if (ch < '1' || (ch > '9' && ch != ':'))
284 return FALSE;
285
286 if (iLength == 3) {
287 if (ch != ':')
288 return FALSE;
289 return DoParm(ch1,pszParm+2);
290 }
291
292 if (ch == ':')
293 return DoParm(ch1,pszParm+2);
294
295 return DoParm(ch1, pszParm+3);
296}
297//*****************************************************************************
298//*****************************************************************************
299int GetParms(char FAR48 *pszCmdLine)
300{
301 int iLength;
302
303 while (*pszCmdLine != ' ') { // skip over filename
304 if (!*pszCmdLine) return TRUE; // no params? then just exit
305 pszCmdLine++;
306 }
307
308 while (TRUE) {
309 pszCmdLine=SkipWhite(pszCmdLine); // move to next param
310 if (!pszCmdLine) return TRUE; // exit if no more
311
312 for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
313 if (pszCmdLine[iLength] == ' ') break; // of parameter
314
315 if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
316 return FALSE;
317
318 while (*pszCmdLine != ' ') { // skip over parameter
319 if (!*pszCmdLine) return TRUE; // no params? then just exit
320 pszCmdLine++;
321 }
322 }
323}
324//*****************************************************************************
325//*****************************************************************************
326
Note: See TracBrowser for help on using the repository browser.