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
|
---|
25 | extern "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 | #define COMM_DEBUG
|
---|
42 |
|
---|
43 | // True if the /V parameter was specified
|
---|
44 | int fVerbose = FALSE;
|
---|
45 | int fDebug = FALSE;
|
---|
46 | int ForceCard = CARD_NONE;
|
---|
47 |
|
---|
48 | extern "C" short int midi_port;
|
---|
49 |
|
---|
50 | #ifdef COMM_DEBUG
|
---|
51 | extern "C" short int MAGIC_COMM_PORT;
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | //*****************************************************************************
|
---|
55 | //*****************************************************************************
|
---|
56 | int toupper(int c)
|
---|
57 | {
|
---|
58 | return (unsigned) c - 'a' <= 'z' - 'a' ? c - ('a' - 'A') : c;
|
---|
59 | }
|
---|
60 | //*****************************************************************************
|
---|
61 | //*****************************************************************************
|
---|
62 | CHAR 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 |
|
---|
79 | USHORT 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 | //*****************************************************************************
|
---|
103 | int 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 | //*****************************************************************************
|
---|
114 | char 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 | //*****************************************************************************
|
---|
124 | void 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 | //*****************************************************************************
|
---|
209 | int DoParm(char cParm, char FAR48 *pszOption)
|
---|
210 | {
|
---|
211 | switch (cParm) {
|
---|
212 | case 'V': // Verbose option
|
---|
213 | fVerbose = TRUE;
|
---|
214 | break;
|
---|
215 | case 'D':
|
---|
216 | fDebug = TRUE;
|
---|
217 | break;
|
---|
218 | case 'C':
|
---|
219 | CheckCardName(pszOption);
|
---|
220 | break;
|
---|
221 | #if 1
|
---|
222 | case 'M':
|
---|
223 | midi_port = 0x300;
|
---|
224 | //sz2us(pszOption, 16);
|
---|
225 | break;
|
---|
226 | #endif
|
---|
227 | #ifdef COMM_DEBUG
|
---|
228 | case 'P':
|
---|
229 | if(*pszOption == '0') {
|
---|
230 | MAGIC_COMM_PORT = 0x000;
|
---|
231 | }
|
---|
232 | else
|
---|
233 | if(*pszOption == '1') {
|
---|
234 | MAGIC_COMM_PORT = 0x3f8;
|
---|
235 | }
|
---|
236 | else
|
---|
237 | if(*pszOption == '2') {
|
---|
238 | MAGIC_COMM_PORT = 0x2f8;
|
---|
239 | }
|
---|
240 | break;
|
---|
241 | #endif
|
---|
242 |
|
---|
243 | default:
|
---|
244 | return FALSE; // unknown parameter
|
---|
245 | }
|
---|
246 | return TRUE;
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* Function: ParseParm
|
---|
250 | Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
|
---|
251 | length of this parameter, which must be at least 1
|
---|
252 | Output: TRUE if the parameter was value
|
---|
253 | Purpose: parses the string into three parts: the letter parameter, the port
|
---|
254 | number, and the option string. Calls DoParm with these values.
|
---|
255 | Notes:
|
---|
256 | the following describes the format of valid parameters.
|
---|
257 | 1. Parameters consist of a letter, an optional number, and an
|
---|
258 | optional 'option'. The format is x[n][:option], where 'x' is the
|
---|
259 | letter, 'n' is the number, and 'option' is the option.
|
---|
260 | 2. Blanks are delimeters between parameters, therefore there are no
|
---|
261 | blanks within a parameter.
|
---|
262 | 3. The option is preceded by a colon
|
---|
263 | This gives us only four possibilities:
|
---|
264 | P (length == 1)
|
---|
265 | P1 (length == 2)
|
---|
266 | P:option (length >= 3)
|
---|
267 | P1:option (length >= 4)
|
---|
268 | */
|
---|
269 | int ParseParm(char FAR48 *pszParm, int iLength)
|
---|
270 | {
|
---|
271 | char ch,ch1=(char) toupper(*pszParm); // get letter
|
---|
272 |
|
---|
273 | if (iLength == 1) // only a letter?
|
---|
274 | return DoParm(ch1,NULL);
|
---|
275 |
|
---|
276 | ch=pszParm[1]; // should be either 1-9 or :
|
---|
277 | if (ch < '1' || (ch > '9' && ch != ':'))
|
---|
278 | return FALSE;
|
---|
279 |
|
---|
280 | if (iLength == 3) {
|
---|
281 | if (ch != ':')
|
---|
282 | return FALSE;
|
---|
283 | return DoParm(ch1,pszParm+2);
|
---|
284 | }
|
---|
285 |
|
---|
286 | if (ch == ':')
|
---|
287 | return DoParm(ch1,pszParm+2);
|
---|
288 |
|
---|
289 | return DoParm(ch1, pszParm+3);
|
---|
290 | }
|
---|
291 | //*****************************************************************************
|
---|
292 | //*****************************************************************************
|
---|
293 | int GetParms(char FAR48 *pszCmdLine)
|
---|
294 | {
|
---|
295 | int iLength;
|
---|
296 |
|
---|
297 | while (*pszCmdLine != ' ') { // skip over filename
|
---|
298 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
---|
299 | pszCmdLine++;
|
---|
300 | }
|
---|
301 |
|
---|
302 | while (TRUE) {
|
---|
303 | pszCmdLine=SkipWhite(pszCmdLine); // move to next param
|
---|
304 | if (!pszCmdLine) return TRUE; // exit if no more
|
---|
305 |
|
---|
306 | for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
|
---|
307 | if (pszCmdLine[iLength] == ' ') break; // of parameter
|
---|
308 |
|
---|
309 | if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
|
---|
310 | return FALSE;
|
---|
311 |
|
---|
312 | while (*pszCmdLine != ' ') { // skip over parameter
|
---|
313 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
---|
314 | pszCmdLine++;
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 | //*****************************************************************************
|
---|
319 | //*****************************************************************************
|
---|
320 |
|
---|