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