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

Last change on this file since 498 was 484, checked in by David Azarewicz, 15 years ago

Fix for recording hang

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