[142] | 1 | /* $Id: parse.c 191 2001-09-28 12:10:07Z 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
|
---|
| 29 | extern "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.
|
---|
| 44 | USHORT ausCL_BaseIO[NUM_DEVICES] =
|
---|
| 45 | { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };
|
---|
| 46 |
|
---|
| 47 | // The IRQ levels specified on the command line
|
---|
| 48 | USHORT ausCL_IRQ[NUM_DEVICES] =
|
---|
| 49 | { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };
|
---|
| 50 |
|
---|
| 51 | // The DMA Channels specified on the command line
|
---|
| 52 | USHORT ausCL_DMA[NUM_DEVICES] =
|
---|
| 53 | { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };
|
---|
| 54 |
|
---|
| 55 | // The device header name specified on the command line
|
---|
| 56 | char szCL_DevName[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
|
---|
| 57 |
|
---|
| 58 | // The DSP Ucode file name specified on the command line
|
---|
| 59 | char szCL_DSPUcodeName[SIZE_CONFIG_LINE] = {' '};
|
---|
| 60 |
|
---|
| 61 | // The size of the heap, in bytes
|
---|
| 62 | USHORT usCL_HeapSize = 0;
|
---|
| 63 |
|
---|
| 64 | // TRUE if /P and /I parameters were specified on the command line
|
---|
| 65 | int fParamsSpecified = FALSE;
|
---|
| 66 |
|
---|
| 67 | // True if the /V parameter was specified
|
---|
| 68 | int fVerbose = FALSE; //###
|
---|
| 69 |
|
---|
| 70 | // True if the hardware initialization errors should be ignore (/O:QUIETINIT)
|
---|
| 71 | int fQuietInit = FALSE;
|
---|
| 72 |
|
---|
| 73 | // The value of the /R parameter
|
---|
| 74 | int iCL_Resolution=2;
|
---|
| 75 |
|
---|
| 76 | // (### No:) declared in strategy.c
|
---|
| 77 | // True if /O:LONGNAMES specified
|
---|
| 78 | int 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
|
---|
| 82 | int fFMforMIDI = FALSE;
|
---|
| 83 |
|
---|
| 84 | // ### True if we should to an INT3() on 1st entry to driver.
|
---|
| 85 | int fInt3BeforeInit;
|
---|
| 86 |
|
---|
| 87 | int fMicMute = TRUE;
|
---|
| 88 | int fLineMute = TRUE;
|
---|
| 89 | int fCDMute = TRUE;
|
---|
[191] | 90 | int fAuxMute = TRUE;
|
---|
[142] | 91 |
|
---|
| 92 | CHAR *memchr(CHAR *strP, CHAR c, USHORT size)
|
---|
| 93 | /* ###!! BLOCK COPY from AD1848, need figure out how memchr() resolves. */
|
---|
| 94 | // This function searches a string for a particular character and returns
|
---|
| 95 | // a pointer to the character in the string.
|
---|
| 96 | // The parameter 'strP' is a pointer to a string of characters. The
|
---|
| 97 | // parameter 'c' is the character to evaluate. The parameter 'size' is the
|
---|
| 98 | // size of the string.
|
---|
| 99 | // The function returns a pointer to the character in the string if found.
|
---|
| 100 | // Otherwise, the value null is returned.
|
---|
| 101 | {
|
---|
| 102 | USHORT i;
|
---|
| 103 |
|
---|
| 104 | // search for the character - return position if found
|
---|
| 105 | i = 0;
|
---|
| 106 | while (i <= size - 1) {
|
---|
| 107 | if (*strP == c)
|
---|
| 108 | return (strP);
|
---|
| 109 | strP++;
|
---|
| 110 | i++;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | // character not found - return null
|
---|
| 114 | return ((CHAR *) 0);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | USHORT sz2us(char __far *sz, int base)
|
---|
| 119 | {
|
---|
| 120 | static char digits[] = "0123456789ABCDEF";
|
---|
| 121 |
|
---|
| 122 | USHORT us=0;
|
---|
| 123 | char *pc;
|
---|
| 124 |
|
---|
| 125 | // skip leading spaces
|
---|
| 126 | while (*sz == ' ') sz++;
|
---|
| 127 |
|
---|
| 128 | // skip leading zeros
|
---|
| 129 | while (*sz == '0') sz++;
|
---|
| 130 |
|
---|
| 131 | // accumulate digits - return error if unexpected character encountered
|
---|
| 132 | for (;;sz++) {
|
---|
| 133 | pc = (char *) memchr(digits, toupper(*sz), base);
|
---|
| 134 | if (!pc)
|
---|
| 135 | return us;
|
---|
| 136 | us = (us * base) + (pc - digits);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | int IsWhitespace(char ch)
|
---|
| 141 | {
|
---|
| 142 | if ( ch > '9' && ch < 'A')
|
---|
| 143 | return TRUE;
|
---|
| 144 | if ( ch < '0' || ch > 'Z')
|
---|
| 145 | return TRUE;
|
---|
| 146 |
|
---|
| 147 | return FALSE;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | char __far *SkipWhite(char __far *psz)
|
---|
| 151 | {
|
---|
| 152 | while (*psz) {
|
---|
| 153 | if (!IsWhitespace((char) toupper(*psz))) return psz;
|
---|
| 154 | psz++;
|
---|
| 155 | }
|
---|
| 156 | return NULL;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | int CopyDevicename(char __far *psz)
|
---|
| 160 | {
|
---|
| 161 | int i,j;
|
---|
| 162 | char ch;
|
---|
| 163 |
|
---|
| 164 | // first, check if the filename is valid
|
---|
| 165 | for (i=0; i<9; i++) {
|
---|
| 166 | ch=(char) toupper(psz[i]);
|
---|
| 167 | if (!ch || ch == ' ')
|
---|
| 168 | break;
|
---|
| 169 | if (i==8) // too long?
|
---|
| 170 | return FALSE;
|
---|
| 171 | if ( ch > '9' && ch < 'A')
|
---|
| 172 | return FALSE;
|
---|
| 173 | if ( (ch != '$' && ch < '0') || ch > 'Z')
|
---|
| 174 | return FALSE;
|
---|
| 175 | }
|
---|
| 176 | if (!i) return FALSE; // zero-length name?
|
---|
| 177 |
|
---|
| 178 | for (j=0; j<i; j++)
|
---|
| 179 | szCL_DevName[j]=(char) toupper(psz[j]);
|
---|
| 180 |
|
---|
| 181 | for (;j<8;j++)
|
---|
| 182 | szCL_DevName[j]=' ';
|
---|
| 183 |
|
---|
| 184 | return TRUE;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | int DoParm(char cParm, int iPort, char __far *pszOption)
|
---|
| 188 | {
|
---|
| 189 | switch (cParm) {
|
---|
[152] | 190 | case '3':
|
---|
| 191 | fInt3BeforeInit = TRUE;
|
---|
| 192 | break;
|
---|
[142] | 193 | case 'J': // which MIDI. MPU by default, if /J then FMSYNTH
|
---|
| 194 | fFMforMIDI = TRUE;
|
---|
| 195 | break;
|
---|
| 196 | case 'M': // Enable mic
|
---|
| 197 | fMicMute = FALSE;
|
---|
| 198 | break;
|
---|
| 199 | case 'L': // Enable line
|
---|
| 200 | fLineMute = FALSE;
|
---|
| 201 | break;
|
---|
| 202 | case 'C': // Enable cd
|
---|
| 203 | fCDMute = FALSE;
|
---|
[191] | 204 | break;
|
---|
| 205 | case 'A': // Enable cd
|
---|
| 206 | fAuxMute = FALSE;
|
---|
| 207 | break;
|
---|
[142] | 208 | case 'N': // device header name
|
---|
[191] | 209 | if (iPort)
|
---|
| 210 | return FALSE;
|
---|
| 211 | if (!pszOption)
|
---|
| 212 | return FALSE;
|
---|
[142] | 213 | if (!CopyDevicename(pszOption))
|
---|
| 214 | return FALSE;
|
---|
| 215 | break;
|
---|
| 216 | case 'V': // Verbose option
|
---|
| 217 | if (iPort)
|
---|
| 218 | return FALSE;
|
---|
| 219 | if (pszOption)
|
---|
| 220 | return FALSE;
|
---|
| 221 | fVerbose=TRUE;
|
---|
| 222 | break;
|
---|
| 223 | break;
|
---|
| 224 | default:
|
---|
| 225 | return FALSE; // unknown parameter
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | return TRUE;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | /* Function: ParseParm
|
---|
| 232 | Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
|
---|
| 233 | length of this parameter, which must be at least 1
|
---|
| 234 | Output: TRUE if the parameter was value
|
---|
| 235 | Purpose: parses the string into three parts: the letter parameter, the port
|
---|
| 236 | number, and the option string. Calls DoParm with these values.
|
---|
| 237 | Notes:
|
---|
| 238 | the following describes the format of valid parameters.
|
---|
| 239 | 1. Parameters consist of a letter, an optional number, and an
|
---|
| 240 | optional 'option'. The format is x[n][:option], where 'x' is the
|
---|
| 241 | letter, 'n' is the number, and 'option' is the option.
|
---|
| 242 | 2. Blanks are delimeters between parameters, therefore there are no
|
---|
| 243 | blanks within a parameter.
|
---|
| 244 | 3. The option is preceded by a colon
|
---|
| 245 | This gives us only four possibilities:
|
---|
| 246 | P (length == 1)
|
---|
| 247 | P1 (length == 2)
|
---|
| 248 | P:option (length >= 3)
|
---|
| 249 | P1:option (length >= 4)
|
---|
| 250 | */
|
---|
| 251 | int ParseParm(char __far *pszParm, int iLength)
|
---|
| 252 | {
|
---|
| 253 | char ch,ch1=(char) toupper(*pszParm); // get letter
|
---|
| 254 |
|
---|
| 255 | if (iLength == 1) // only a letter?
|
---|
| 256 | return DoParm(ch1,0,NULL);
|
---|
| 257 |
|
---|
| 258 | ch=pszParm[1]; // should be either 1-9 or :
|
---|
| 259 | if (ch < '1' || (ch > '9' && ch != ':'))
|
---|
| 260 | return FALSE;
|
---|
| 261 |
|
---|
| 262 | if (iLength == 2) {
|
---|
| 263 | if (ch == ':')
|
---|
| 264 | return FALSE;
|
---|
| 265 | return DoParm(ch1,ch - '0',NULL);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | if (iLength == 3) {
|
---|
| 269 | if (ch != ':')
|
---|
| 270 | return FALSE;
|
---|
| 271 | return DoParm(ch1,0,pszParm+2);
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | if (ch == ':')
|
---|
| 275 | return DoParm(ch1,0,pszParm+2);
|
---|
| 276 |
|
---|
| 277 | return DoParm(ch1,ch - '0',pszParm+3);
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | int GetParms(char __far *pszCmdLine)
|
---|
| 281 | {
|
---|
| 282 | int iLength;
|
---|
| 283 |
|
---|
| 284 | while (*pszCmdLine != ' ') { // skip over filename
|
---|
| 285 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
---|
| 286 | pszCmdLine++;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | while (TRUE) {
|
---|
| 290 | pszCmdLine=SkipWhite(pszCmdLine); // move to next param
|
---|
| 291 | if (!pszCmdLine) return TRUE; // exit if no more
|
---|
| 292 |
|
---|
| 293 | for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
|
---|
| 294 | if (pszCmdLine[iLength] == ' ') break; // of parameter
|
---|
| 295 |
|
---|
| 296 | if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
|
---|
| 297 | return FALSE;
|
---|
| 298 |
|
---|
| 299 | while (*pszCmdLine != ' ') { // skip over parameter
|
---|
| 300 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
---|
| 301 | pszCmdLine++;
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 | }
|
---|