| 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 <unicard.h>
|
|---|
| 37 | #include "parse.h" // NUM_DEVICES
|
|---|
| 38 | #include <string.h>
|
|---|
| 39 |
|
|---|
| 40 | #define COMM_DEBUG
|
|---|
| 41 |
|
|---|
| 42 | // True if the /V parameter was specified
|
|---|
| 43 | int fVerbose = FALSE;
|
|---|
| 44 | int fDebug = FALSE;
|
|---|
| 45 | //int ForceCard = CARD_NONE;
|
|---|
| 46 | int iAdapterNumber = -1;
|
|---|
| 47 |
|
|---|
| 48 | extern short int midi_port;
|
|---|
| 49 |
|
|---|
| 50 | #ifdef COMM_DEBUG
|
|---|
| 51 | extern 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 | #if 0
|
|---|
| 125 | //*****************************************************************************
|
|---|
| 126 | void CheckCardName(char FAR48 *psz)
|
|---|
| 127 | {
|
|---|
| 128 | char name[CARD_MAX_LEN+1];
|
|---|
| 129 | int i;
|
|---|
| 130 |
|
|---|
| 131 | for (i=0; i<CARD_MAX_LEN; i++) {
|
|---|
| 132 | name[i] = toupper(psz[i]);
|
|---|
| 133 | if(name[i] == ' ') {
|
|---|
| 134 | name[i] = 0;
|
|---|
| 135 | break;
|
|---|
| 136 | }
|
|---|
| 137 | }
|
|---|
| 138 | name[CARD_MAX_LEN] = 0;
|
|---|
| 139 |
|
|---|
| 140 | if(!strcmp(name, CARD_STRING_SBLIVE)) {
|
|---|
| 141 | ForceCard = CARD_SBLIVE;
|
|---|
| 142 | }
|
|---|
| 143 | else
|
|---|
| 144 | if(!strcmp(name, CARD_STRING_ALS4000)) {
|
|---|
| 145 | ForceCard = CARD_ALS4000;
|
|---|
| 146 | }
|
|---|
| 147 | else
|
|---|
| 148 | if(!strcmp(name, CARD_STRING_CMEDIA)) {
|
|---|
| 149 | ForceCard = CARD_CMEDIA;
|
|---|
| 150 | }
|
|---|
| 151 | else
|
|---|
| 152 | if(!strcmp(name, CARD_STRING_CS4281)) {
|
|---|
| 153 | ForceCard = CARD_CS4281;
|
|---|
| 154 | }
|
|---|
| 155 | else
|
|---|
| 156 | if(!strcmp(name, CARD_STRING_ICH)) {
|
|---|
| 157 | ForceCard = CARD_ICH;
|
|---|
| 158 | }
|
|---|
| 159 | else
|
|---|
| 160 | if(!strcmp(name, CARD_STRING_CS46XX)) {
|
|---|
| 161 | ForceCard = CARD_CS46XX;
|
|---|
| 162 | }
|
|---|
| 163 | else
|
|---|
| 164 | if(!strcmp(name, CARD_STRING_VIA82XX)) {
|
|---|
| 165 | ForceCard = CARD_VIA82XX;
|
|---|
| 166 | }
|
|---|
| 167 | else
|
|---|
| 168 | if(!strcmp(name, CARD_STRING_ESS1938)) {
|
|---|
| 169 | ForceCard = CARD_ESS1938;
|
|---|
| 170 | }
|
|---|
| 171 | else
|
|---|
| 172 | if(!strcmp(name, CARD_STRING_VORTEX)) {
|
|---|
| 173 | ForceCard = CARD_VORTEX;
|
|---|
| 174 | }
|
|---|
| 175 | else
|
|---|
| 176 | if(!strcmp(name, CARD_STRING_ENSONIQ)) {
|
|---|
| 177 | ForceCard = CARD_ENSONIQ;
|
|---|
| 178 | }
|
|---|
| 179 | else
|
|---|
| 180 | if(!strcmp(name, CARD_STRING_TRIDENT)) {
|
|---|
| 181 | ForceCard = CARD_TRIDENT;
|
|---|
| 182 | }
|
|---|
| 183 | else
|
|---|
| 184 | if(!strcmp(name, CARD_STRING_NEOMAGIC)) {
|
|---|
| 185 | ForceCard = CARD_NEOMAGIC;
|
|---|
| 186 | }
|
|---|
| 187 | else
|
|---|
| 188 | if(!strcmp(name, CARD_STRING_FM801)) {
|
|---|
| 189 | ForceCard = CARD_FM801;
|
|---|
| 190 | }
|
|---|
| 191 | else
|
|---|
| 192 | if(!strcmp(name, CARD_STRING_ATIIXP)) {
|
|---|
| 193 | ForceCard = CARD_ATIIXP;
|
|---|
| 194 | }
|
|---|
| 195 | else
|
|---|
| 196 | if(!strcmp(name, CARD_STRING_AUDIGYLS)) {
|
|---|
| 197 | ForceCard = CARD_AUDIGYLS;
|
|---|
| 198 | }
|
|---|
| 199 | else
|
|---|
| 200 | if(!strcmp(name, CARD_STRING_BT87X)) {
|
|---|
| 201 | ForceCard = CARD_BT87X;
|
|---|
| 202 | }
|
|---|
| 203 | else
|
|---|
| 204 | if(!strcmp(name, CARD_STRING_AZX)) {
|
|---|
| 205 | ForceCard = CARD_AZX;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | }
|
|---|
| 209 | //*****************************************************************************
|
|---|
| 210 | #endif
|
|---|
| 211 |
|
|---|
| 212 | //*****************************************************************************
|
|---|
| 213 | int DoParm(char cParm, char FAR48 *pszOption)
|
|---|
| 214 | {
|
|---|
| 215 | switch (cParm) {
|
|---|
| 216 | case 'A':
|
|---|
| 217 | iAdapterNumber = *pszOption & 0x07;
|
|---|
| 218 | break;
|
|---|
| 219 | case 'V': // Verbose option
|
|---|
| 220 | fVerbose = TRUE;
|
|---|
| 221 | break;
|
|---|
| 222 | case 'D':
|
|---|
| 223 | fDebug = TRUE;
|
|---|
| 224 | break;
|
|---|
| 225 | //case 'C':
|
|---|
| 226 | //CheckCardName(pszOption);
|
|---|
| 227 | //break;
|
|---|
| 228 | #if 1
|
|---|
| 229 | case 'M':
|
|---|
| 230 | midi_port = 0x300;
|
|---|
| 231 | //sz2us(pszOption, 16);
|
|---|
| 232 | break;
|
|---|
| 233 | #endif
|
|---|
| 234 | #ifdef COMM_DEBUG
|
|---|
| 235 | case 'P':
|
|---|
| 236 | if(*pszOption == '0') {
|
|---|
| 237 | MAGIC_COMM_PORT = 0x000;
|
|---|
| 238 | }
|
|---|
| 239 | else
|
|---|
| 240 | if(*pszOption == '1') {
|
|---|
| 241 | MAGIC_COMM_PORT = 0x3f8;
|
|---|
| 242 | }
|
|---|
| 243 | else
|
|---|
| 244 | if(*pszOption == '2') {
|
|---|
| 245 | MAGIC_COMM_PORT = 0x2f8;
|
|---|
| 246 | }
|
|---|
| 247 | if(*pszOption == '4') {
|
|---|
| 248 | MAGIC_COMM_PORT = 0x4000;
|
|---|
| 249 | }
|
|---|
| 250 | break;
|
|---|
| 251 | #endif
|
|---|
| 252 |
|
|---|
| 253 | default:
|
|---|
| 254 | return FALSE; // unknown parameter
|
|---|
| 255 | }
|
|---|
| 256 | return TRUE;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | /* Function: ParseParm
|
|---|
| 260 | Input: pointer to the letter of the parameter (e.g. the 'P' in 'P1:330').
|
|---|
| 261 | length of this parameter, which must be at least 1
|
|---|
| 262 | Output: TRUE if the parameter was value
|
|---|
| 263 | Purpose: parses the string into three parts: the letter parameter, the port
|
|---|
| 264 | number, and the option string. Calls DoParm with these values.
|
|---|
| 265 | Notes:
|
|---|
| 266 | the following describes the format of valid parameters.
|
|---|
| 267 | 1. Parameters consist of a letter, an optional number, and an
|
|---|
| 268 | optional 'option'. The format is x[n][:option], where 'x' is the
|
|---|
| 269 | letter, 'n' is the number, and 'option' is the option.
|
|---|
| 270 | 2. Blanks are delimeters between parameters, therefore there are no
|
|---|
| 271 | blanks within a parameter.
|
|---|
| 272 | 3. The option is preceded by a colon
|
|---|
| 273 | This gives us only four possibilities:
|
|---|
| 274 | P (length == 1)
|
|---|
| 275 | P1 (length == 2)
|
|---|
| 276 | P:option (length >= 3)
|
|---|
| 277 | P1:option (length >= 4)
|
|---|
| 278 | */
|
|---|
| 279 | int ParseParm(char FAR48 *pszParm, int iLength)
|
|---|
| 280 | {
|
|---|
| 281 | char ch,ch1=(char) toupper(*pszParm); // get letter
|
|---|
| 282 |
|
|---|
| 283 | if (iLength == 1) // only a letter?
|
|---|
| 284 | return DoParm(ch1,NULL);
|
|---|
| 285 |
|
|---|
| 286 | ch=pszParm[1]; // should be either 1-9 or :
|
|---|
| 287 | if (ch < '1' || (ch > '9' && ch != ':'))
|
|---|
| 288 | return FALSE;
|
|---|
| 289 |
|
|---|
| 290 | if (iLength == 3) {
|
|---|
| 291 | if (ch != ':')
|
|---|
| 292 | return FALSE;
|
|---|
| 293 | return DoParm(ch1,pszParm+2);
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | if (ch == ':')
|
|---|
| 297 | return DoParm(ch1,pszParm+2);
|
|---|
| 298 |
|
|---|
| 299 | return DoParm(ch1, pszParm+3);
|
|---|
| 300 | }
|
|---|
| 301 | //*****************************************************************************
|
|---|
| 302 | //*****************************************************************************
|
|---|
| 303 | int GetParms(char FAR48 *pszCmdLine)
|
|---|
| 304 | {
|
|---|
| 305 | int iLength;
|
|---|
| 306 |
|
|---|
| 307 | while (*pszCmdLine != ' ') { // skip over filename
|
|---|
| 308 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
|---|
| 309 | pszCmdLine++;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | while (TRUE) {
|
|---|
| 313 | pszCmdLine=SkipWhite(pszCmdLine); // move to next param
|
|---|
| 314 | if (!pszCmdLine) return TRUE; // exit if no more
|
|---|
| 315 |
|
|---|
| 316 | for (iLength=0; pszCmdLine[iLength]; iLength++) // calculate length
|
|---|
| 317 | if (pszCmdLine[iLength] == ' ') break; // of parameter
|
|---|
| 318 |
|
|---|
| 319 | if (!ParseParm(pszCmdLine,iLength)) // found parameter, so parse it
|
|---|
| 320 | return FALSE;
|
|---|
| 321 |
|
|---|
| 322 | while (*pszCmdLine != ' ') { // skip over parameter
|
|---|
| 323 | if (!*pszCmdLine) return TRUE; // no params? then just exit
|
|---|
| 324 | pszCmdLine++;
|
|---|
| 325 | }
|
|---|
| 326 | }
|
|---|
| 327 | }
|
|---|
| 328 | //*****************************************************************************
|
|---|
| 329 | //*****************************************************************************
|
|---|
| 330 |
|
|---|