| 1 | /* $Id: parse.c,v 1.2 2000/07/17 18:32:36 sandervl Exp $ */
|
|---|
| 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;
|
|---|
| 90 | int fAuxMute = TRUE;
|
|---|
| 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) {
|
|---|
| 190 | case '3':
|
|---|
| 191 | fInt3BeforeInit = TRUE;
|
|---|
| 192 | break;
|
|---|
| 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;
|
|---|
| 204 | break;
|
|---|
| 205 | case 'A': // Enable cd
|
|---|
| 206 | fAuxMute = FALSE;
|
|---|
| 207 | break;
|
|---|
| 208 | case 'N': // device header name
|
|---|
| 209 | if (iPort)
|
|---|
| 210 | return FALSE;
|
|---|
| 211 | if (!pszOption)
|
|---|
| 212 | return FALSE;
|
|---|
| 213 | if (!CopyDevicename(pszOption))
|
|---|
| 214 | return FALSE;
|
|---|
| 215 | break;
|
|---|
| 216 | case 'V': // Verbose option
|
|---|
| 217 | /*
|
|---|
| 218 | Rudi: why ??
|
|---|
| 219 | if (iPort)
|
|---|
| 220 | return FALSE;
|
|---|
| 221 | if (pszOption)
|
|---|
| 222 | return FALSE;
|
|---|
| 223 | */
|
|---|
| 224 | fVerbose=TRUE;
|
|---|
| 225 | break;
|
|---|
| 226 | break;
|
|---|
| 227 | default:
|
|---|
| 228 | return FALSE; // unknown parameter
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | return TRUE;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | /* Function: ParseParm
|
|---|
| 235 | Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
|
|---|
| 236 | length of this parameter, which must be at least 1
|
|---|
| 237 | Output: TRUE if the parameter was value
|
|---|
| 238 | Purpose: parses the string into three parts: the letter parameter, the port
|
|---|
| 239 | number, and the option string. Calls DoParm with these values.
|
|---|
| 240 | Notes:
|
|---|
| 241 | the following describes the format of valid parameters.
|
|---|
| 242 | 1. Parameters consist of a letter, an optional number, and an
|
|---|
| 243 | optional 'option'. The format is x[n][:option], where 'x' is the
|
|---|
| 244 | letter, 'n' is the number, and 'option' is the option.
|
|---|
| 245 | 2. Blanks are delimeters between parameters, therefore there are no
|
|---|
| 246 | blanks within a parameter.
|
|---|
| 247 | 3. The option is preceded by a colon
|
|---|
| 248 | This gives us only four possibilities:
|
|---|
| 249 | P (length == 1)
|
|---|
| 250 | P1 (length == 2)
|
|---|
| 251 | P:option (length >= 3)
|
|---|
| 252 | P1:option (length >= 4)
|
|---|
| 253 | */
|
|---|
| 254 | int ParseParm(char __far *pszParm, int iLength)
|
|---|
| 255 | {
|
|---|
| 256 | char ch,ch1=(char) toupper(*pszParm); // get letter
|
|---|
| 257 |
|
|---|
| 258 | if (iLength == 1) // only a letter?
|
|---|
| 259 | return DoParm(ch1,0,NULL);
|
|---|
| 260 |
|
|---|
| 261 | ch=pszParm[1]; // should be either 1-9 or :
|
|---|
| 262 | if (ch < '1' || (ch > '9' && ch != ':'))
|
|---|
| 263 | return FALSE;
|
|---|
| 264 |
|
|---|
| 265 | if (iLength == 2) {
|
|---|
| 266 | if (ch == ':')
|
|---|
| 267 | return FALSE;
|
|---|
| 268 | return DoParm(ch1,ch - '0',NULL);
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | if (iLength == 3) {
|
|---|
| 272 | if (ch != ':')
|
|---|
| 273 | return FALSE;
|
|---|
| 274 | return DoParm(ch1,0,pszParm+2);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | if (ch == ':')
|
|---|
| 278 | return DoParm(ch1,0,pszParm+2);
|
|---|
| 279 |
|
|---|
| 280 | return DoParm(ch1,ch - '0',pszParm+3);
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | int GetParms(char __far *pszCmdLine)
|
|---|
| 284 | {
|
|---|
| 285 | int iLength;
|
|---|
| 286 |
|
|---|
| 287 | while (*pszCmdLine != ' ') { // skip over filename
|
|---|
| 288 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
|---|
| 289 | pszCmdLine++;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | while (TRUE) {
|
|---|
| 293 | pszCmdLine=SkipWhite(pszCmdLine); // move to next param
|
|---|
| 294 | if (!pszCmdLine) return TRUE; // exit if no more
|
|---|
| 295 |
|
|---|
| 296 | for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
|
|---|
| 297 | if (pszCmdLine[iLength] == ' ') break; // of parameter
|
|---|
| 298 |
|
|---|
| 299 | if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
|
|---|
| 300 | return FALSE;
|
|---|
| 301 |
|
|---|
| 302 | while (*pszCmdLine != ' ') { // skip over parameter
|
|---|
| 303 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
|---|
| 304 | pszCmdLine++;
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 | }
|
|---|