source: sbliveos2/trunk/drv16/parse.c@ 153

Last change on this file since 153 was 152, checked in by sandervl, 25 years ago

misc updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: parse.c 152 2000-07-17 18:37:33Z sandervl $ */
2
3/* SCCSID = %W% %E% */
4/****************************************************************************
5 * *
6 * Copyright (c) IBM Corporation 1994 - 1997. *
7 * *
8 * The following IBM OS/2 source code is provided to you solely for the *
9 * the purpose of assisting you in your development of OS/2 device drivers. *
10 * You may use this code in accordance with the IBM License Agreement *
11 * provided in the IBM Device Driver Source Kit for OS/2. *
12 * *
13 ****************************************************************************/
14/**@internal %W%
15 * Parses DEVICE= command line parameters, stuffs values into global vbls.
16 * @version %I%
17 * @context
18 * Unless otherwise noted, all interfaces are Ring-3, 16-bit,
19 * Init-time kernel stack.
20 * @notes
21 * @history
22 * 13-Nov-96 Timur Tabi
23 */
24
25
26#pragma code_seg ("_inittext");
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31#define INCL_NOPMAPI
32#define INCL_DOSMISC
33#include <os2.h>
34#ifdef __cplusplus
35}
36#endif
37
38#include "parse.h" // NUM_DEVICES
39#include "runtime.h" // runtime prototypes
40#include <include.h>
41
42
43// The base I/O ports specified on the command line.
44USHORT ausCL_BaseIO[NUM_DEVICES] =
45{ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };
46
47// The IRQ levels specified on the command line
48USHORT ausCL_IRQ[NUM_DEVICES] =
49{ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };
50
51// The DMA Channels specified on the command line
52USHORT ausCL_DMA[NUM_DEVICES] =
53{ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };
54
55// The device header name specified on the command line
56char szCL_DevName[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
57
58// The DSP Ucode file name specified on the command line
59char szCL_DSPUcodeName[SIZE_CONFIG_LINE] = {' '};
60
61// The size of the heap, in bytes
62USHORT usCL_HeapSize = 0;
63
64// TRUE if /P and /I parameters were specified on the command line
65int fParamsSpecified = FALSE;
66
67// True if the /V parameter was specified
68int fVerbose = FALSE; //###
69
70// True if the hardware initialization errors should be ignore (/O:QUIETINIT)
71int fQuietInit = FALSE;
72
73// The value of the /R parameter
74int iCL_Resolution=2;
75
76// (### No:) declared in strategy.c
77// True if /O:LONGNAMES specified
78int fLongNames; //###
79
80// switch set at init time based on config sys parm that tells us which
81// midi to use FM Synth or MPU401
82int fFMforMIDI = FALSE;
83
84// ### True if we should to an INT3() on 1st entry to driver.
85int fInt3BeforeInit;
86
87int fMicMute = TRUE;
88int fLineMute = TRUE;
89int fCDMute = TRUE;
90
91CHAR *memchr(CHAR *strP, CHAR c, USHORT size)
92/* ###!! BLOCK COPY from AD1848, need figure out how memchr() resolves. */
93// This function searches a string for a particular character and returns
94// a pointer to the character in the string.
95// The parameter 'strP' is a pointer to a string of characters. The
96// parameter 'c' is the character to evaluate. The parameter 'size' is the
97// size of the string.
98// The function returns a pointer to the character in the string if found.
99// Otherwise, the value null is returned.
100{
101 USHORT i;
102
103 // search for the character - return position if found
104 i = 0;
105 while (i <= size - 1) {
106 if (*strP == c)
107 return (strP);
108 strP++;
109 i++;
110 }
111
112 // character not found - return null
113 return ((CHAR *) 0);
114}
115
116
117USHORT sz2us(char __far *sz, int base)
118{
119 static char digits[] = "0123456789ABCDEF";
120
121 USHORT us=0;
122 char *pc;
123
124// skip leading spaces
125 while (*sz == ' ') sz++;
126
127// skip leading zeros
128 while (*sz == '0') sz++;
129
130// accumulate digits - return error if unexpected character encountered
131 for (;;sz++) {
132 pc = (char *) memchr(digits, toupper(*sz), base);
133 if (!pc)
134 return us;
135 us = (us * base) + (pc - digits);
136 }
137}
138
139int IsWhitespace(char ch)
140{
141 if ( ch > '9' && ch < 'A')
142 return TRUE;
143 if ( ch < '0' || ch > 'Z')
144 return TRUE;
145
146 return FALSE;
147}
148
149char __far *SkipWhite(char __far *psz)
150{
151 while (*psz) {
152 if (!IsWhitespace((char) toupper(*psz))) return psz;
153 psz++;
154 }
155 return NULL;
156}
157
158int CopyDevicename(char __far *psz)
159{
160 int i,j;
161 char ch;
162
163// first, check if the filename is valid
164 for (i=0; i<9; i++) {
165 ch=(char) toupper(psz[i]);
166 if (!ch || ch == ' ')
167 break;
168 if (i==8) // too long?
169 return FALSE;
170 if ( ch > '9' && ch < 'A')
171 return FALSE;
172 if ( (ch != '$' && ch < '0') || ch > 'Z')
173 return FALSE;
174 }
175 if (!i) return FALSE; // zero-length name?
176
177 for (j=0; j<i; j++)
178 szCL_DevName[j]=(char) toupper(psz[j]);
179
180 for (;j<8;j++)
181 szCL_DevName[j]=' ';
182
183 return TRUE;
184}
185
186int DoParm(char cParm, int iPort, char __far *pszOption)
187{
188 USHORT us;
189
190 switch (cParm) {
191 case '3':
192 fInt3BeforeInit = TRUE;
193 break;
194 case 'J': // which MIDI. MPU by default, if /J then FMSYNTH
195 fFMforMIDI = TRUE;
196 break;
197 case 'M': // Enable mic
198 fMicMute = FALSE;
199 break;
200 case 'L': // Enable line
201 fLineMute = FALSE;
202 break;
203 case 'C': // Enable cd
204 fCDMute = FALSE;
205 break;
206 case 'N': // device header name
207 if (iPort)
208 return FALSE;
209 if (!pszOption)
210 return FALSE;
211 if (!CopyDevicename(pszOption))
212 return FALSE;
213 break;
214 case 'V': // Verbose option
215 if (iPort)
216 return FALSE;
217 if (pszOption)
218 return FALSE;
219 fVerbose=TRUE;
220 break;
221 break;
222 default:
223 return FALSE; // unknown parameter
224 }
225
226 return TRUE;
227}
228
229/* Function: ParseParm
230 Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
231 length of this parameter, which must be at least 1
232 Output: TRUE if the parameter was value
233 Purpose: parses the string into three parts: the letter parameter, the port
234 number, and the option string. Calls DoParm with these values.
235 Notes:
236 the following describes the format of valid parameters.
237 1. Parameters consist of a letter, an optional number, and an
238 optional 'option'. The format is x[n][:option], where 'x' is the
239 letter, 'n' is the number, and 'option' is the option.
240 2. Blanks are delimeters between parameters, therefore there are no
241 blanks within a parameter.
242 3. The option is preceded by a colon
243 This gives us only four possibilities:
244 P (length == 1)
245 P1 (length == 2)
246 P:option (length >= 3)
247 P1:option (length >= 4)
248*/
249int ParseParm(char __far *pszParm, int iLength)
250{
251 char ch,ch1=(char) toupper(*pszParm); // get letter
252
253 if (iLength == 1) // only a letter?
254 return DoParm(ch1,0,NULL);
255
256 ch=pszParm[1]; // should be either 1-9 or :
257 if (ch < '1' || (ch > '9' && ch != ':'))
258 return FALSE;
259
260 if (iLength == 2) {
261 if (ch == ':')
262 return FALSE;
263 return DoParm(ch1,ch - '0',NULL);
264 }
265
266 if (iLength == 3) {
267 if (ch != ':')
268 return FALSE;
269 return DoParm(ch1,0,pszParm+2);
270 }
271
272 if (ch == ':')
273 return DoParm(ch1,0,pszParm+2);
274
275 return DoParm(ch1,ch - '0',pszParm+3);
276}
277
278int GetParms(char __far *pszCmdLine)
279{
280 int iLength;
281
282 while (*pszCmdLine != ' ') { // skip over filename
283 if (!*pszCmdLine) return TRUE; // no params? then just exit
284 pszCmdLine++;
285 }
286
287 while (TRUE) {
288 pszCmdLine=SkipWhite(pszCmdLine); // move to next param
289 if (!pszCmdLine) return TRUE; // exit if no more
290
291 for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
292 if (pszCmdLine[iLength] == ' ') break; // of parameter
293
294 if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
295 return FALSE;
296
297 while (*pszCmdLine != ' ') { // skip over parameter
298 if (!*pszCmdLine) return TRUE; // no params? then just exit
299 pszCmdLine++;
300 }
301 }
302}
Note: See TracBrowser for help on using the repository browser.