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

Last change on this file since 588 was 588, checked in by David Azarewicz, 9 years ago

Build system cleanup

File size: 9.0 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;
46
47extern short int midi_port;
48
49#ifdef COMM_DEBUG
50extern short int MAGIC_COMM_PORT;
51#endif
52
53//*****************************************************************************
54//*****************************************************************************
55int toupper(int c)
56{
57 return (unsigned) c - 'a' <= 'z' - 'a' ? c - ('a' - 'A') : c;
58}
59//*****************************************************************************
60//*****************************************************************************
61CHAR FAR48 *mymemchr(CHAR FAR48 *strP, CHAR c, USHORT size)
62{
63 USHORT i;
64 // search for the character - return position if found
65 i = 0;
66 while (i <= size - 1) {
67 if (*strP == c)
68 return (strP);
69 strP++;
70 i++;
71 }
72 // character not found - return null
73 return ((CHAR FAR48 *) 0);
74}
75//*****************************************************************************
76//*****************************************************************************
77
78USHORT sz2us(char FAR48 *sz, int base)
79{
80 static char digits[] = "0123456789ABCDEF";
81
82 USHORT us=0;
83 // char *pc;
84 CHAR FAR48 *pc;
85
86 // skip leading spaces
87 while (*sz == ' ') sz++;
88
89 // skip leading zeros
90 while (*sz == '0') sz++;
91
92 // accumulate digits - return error if unexpected character encountered
93 for (;;sz++) {
94 pc = (CHAR FAR48 *) mymemchr(digits, toupper(*sz), base);
95 if (!pc)
96 return us;
97 us = (us * base) + (pc - digits);
98 }
99}
100//*****************************************************************************
101//*****************************************************************************
102int IsWhitespace(char ch)
103{
104 if ( ch > '9' && ch < 'A')
105 return TRUE;
106 if ( ch < '0' || ch > 'Z')
107 return TRUE;
108
109 return FALSE;
110}
111//*****************************************************************************
112//*****************************************************************************
113char FAR48 *SkipWhite(char FAR48 *psz)
114{
115 while (*psz) {
116 if (!IsWhitespace((char) toupper(*psz))) return psz;
117 psz++;
118 }
119 return NULL;
120}
121//*****************************************************************************
122//*****************************************************************************
123void CheckCardName(char FAR48 *psz)
124{
125 char name[CARD_MAX_LEN+1];
126 int i;
127
128 for (i=0; i<CARD_MAX_LEN; i++) {
129 name[i] = toupper(psz[i]);
130 if(name[i] == ' ') {
131 name[i] = 0;
132 break;
133 }
134 }
135 name[CARD_MAX_LEN] = 0;
136
137 if(!strcmp(name, CARD_STRING_SBLIVE)) {
138 ForceCard = CARD_SBLIVE;
139 }
140 else
141 if(!strcmp(name, CARD_STRING_ALS4000)) {
142 ForceCard = CARD_ALS4000;
143 }
144 else
145 if(!strcmp(name, CARD_STRING_CMEDIA)) {
146 ForceCard = CARD_CMEDIA;
147 }
148 else
149 if(!strcmp(name, CARD_STRING_CS4281)) {
150 ForceCard = CARD_CS4281;
151 }
152 else
153 if(!strcmp(name, CARD_STRING_ICH)) {
154 ForceCard = CARD_ICH;
155 }
156 else
157 if(!strcmp(name, CARD_STRING_CS46XX)) {
158 ForceCard = CARD_CS46XX;
159 }
160 else
161 if(!strcmp(name, CARD_STRING_VIA82XX)) {
162 ForceCard = CARD_VIA82XX;
163 }
164 else
165 if(!strcmp(name, CARD_STRING_ESS1938)) {
166 ForceCard = CARD_ESS1938;
167 }
168 else
169 if(!strcmp(name, CARD_STRING_VORTEX)) {
170 ForceCard = CARD_VORTEX;
171 }
172 else
173 if(!strcmp(name, CARD_STRING_ENSONIQ)) {
174 ForceCard = CARD_ENSONIQ;
175 }
176 else
177 if(!strcmp(name, CARD_STRING_TRIDENT)) {
178 ForceCard = CARD_TRIDENT;
179 }
180 else
181 if(!strcmp(name, CARD_STRING_NEOMAGIC)) {
182 ForceCard = CARD_NEOMAGIC;
183 }
184 else
185 if(!strcmp(name, CARD_STRING_FM801)) {
186 ForceCard = CARD_FM801;
187 }
188 else
189 if(!strcmp(name, CARD_STRING_ATIIXP)) {
190 ForceCard = CARD_ATIIXP;
191 }
192 else
193 if(!strcmp(name, CARD_STRING_AUDIGYLS)) {
194 ForceCard = CARD_AUDIGYLS;
195 }
196 else
197 if(!strcmp(name, CARD_STRING_BT87X)) {
198 ForceCard = CARD_BT87X;
199 }
200 else
201 if(!strcmp(name, CARD_STRING_AZX)) {
202 ForceCard = CARD_AZX;
203 }
204
205}
206//*****************************************************************************
207//*****************************************************************************
208int DoParm(char cParm, char FAR48 *pszOption)
209{
210 switch (cParm) {
211 case 'V': // Verbose option
212 fVerbose = TRUE;
213 break;
214 case 'D':
215 fDebug = TRUE;
216 break;
217 case 'C':
218 CheckCardName(pszOption);
219 break;
220#if 1
221 case 'M':
222 midi_port = 0x300;
223 //sz2us(pszOption, 16);
224 break;
225#endif
226#ifdef COMM_DEBUG
227 case 'P':
228 if(*pszOption == '0') {
229 MAGIC_COMM_PORT = 0x000;
230 }
231 else
232 if(*pszOption == '1') {
233 MAGIC_COMM_PORT = 0x3f8;
234 }
235 else
236 if(*pszOption == '2') {
237 MAGIC_COMM_PORT = 0x2f8;
238 }
239 break;
240#endif
241
242 default:
243 return FALSE; // unknown parameter
244 }
245 return TRUE;
246}
247
248/* Function: ParseParm
249 Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
250 length of this parameter, which must be at least 1
251 Output: TRUE if the parameter was value
252 Purpose: parses the string into three parts: the letter parameter, the port
253 number, and the option string. Calls DoParm with these values.
254 Notes:
255 the following describes the format of valid parameters.
256 1. Parameters consist of a letter, an optional number, and an
257 optional 'option'. The format is x[n][:option], where 'x' is the
258 letter, 'n' is the number, and 'option' is the option.
259 2. Blanks are delimeters between parameters, therefore there are no
260 blanks within a parameter.
261 3. The option is preceded by a colon
262 This gives us only four possibilities:
263 P (length == 1)
264 P1 (length == 2)
265 P:option (length >= 3)
266 P1:option (length >= 4)
267*/
268int ParseParm(char FAR48 *pszParm, int iLength)
269{
270 char ch,ch1=(char) toupper(*pszParm); // get letter
271
272 if (iLength == 1) // only a letter?
273 return DoParm(ch1,NULL);
274
275 ch=pszParm[1]; // should be either 1-9 or :
276 if (ch < '1' || (ch > '9' && ch != ':'))
277 return FALSE;
278
279 if (iLength == 3) {
280 if (ch != ':')
281 return FALSE;
282 return DoParm(ch1,pszParm+2);
283 }
284
285 if (ch == ':')
286 return DoParm(ch1,pszParm+2);
287
288 return DoParm(ch1, pszParm+3);
289}
290//*****************************************************************************
291//*****************************************************************************
292int GetParms(char FAR48 *pszCmdLine)
293{
294 int iLength;
295
296 while (*pszCmdLine != ' ') { // skip over filename
297 if (!*pszCmdLine) return TRUE; // no params? then just exit
298 pszCmdLine++;
299 }
300
301 while (TRUE) {
302 pszCmdLine=SkipWhite(pszCmdLine); // move to next param
303 if (!pszCmdLine) return TRUE; // exit if no more
304
305 for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
306 if (pszCmdLine[iLength] == ' ') break; // of parameter
307
308 if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
309 return FALSE;
310
311 while (*pszCmdLine != ' ') { // skip over parameter
312 if (!*pszCmdLine) return TRUE; // no params? then just exit
313 pszCmdLine++;
314 }
315 }
316}
317//*****************************************************************************
318//*****************************************************************************
319
Note: See TracBrowser for help on using the repository browser.