Annotation of src/readcfg.c, revision 1.1.1.1

1.1       root        1: //**
                      2: //** READCFG.C - Utilities to read and write the CONTROLS.CFG file.
                      3: //**
                      4: //** 02/20/96  Les Bird
                      5: //**
                      6: 
                      7: #include <stdio.h>
                      8: #include <stdlib.h>
                      9: #include <string.h>
                     10: #include <dos.h>
                     11: #include <io.h>
                     12: #include <ctype.h>
                     13: #include <sys\types.h>
                     14: #include "sos.h"
                     15: #include "profile.h"
                     16: 
                     17: #include "whdcntrl.h"
                     18: 
                     19: char controlConfigFile[_MAX_PATH];
                     20: 
                     21: static
                     22: char tempBuf[256];
                     23: 
                     24: char *controlAction[MAXACTIONS+1]={
                     25:      "MOVE FORWARD ",
                     26:      "MOVE BACKWARD",
                     27:      "TURN LEFT    ",
                     28:      "TURN RIGHT   ",
                     29:      "RUN MODE     ",
                     30:      "STRAFE MODE  ",
                     31:      "USE WEAPON   ",
                     32:      "OPEN/CLOSE   ",
                     33:      "JUMP         ",
                     34:      "CROUCH       ",
                     35:      "LOOK UP      ",
                     36:      "LOOK DOWN    ",
                     37:      "LOOK CENTER  ",
                     38:      "STRAFE LEFT  ",
                     39:      "STRAFE RIGHT ",
                     40:      "USE POTION   ",
                     41:      "CAST SPELL   ",
                     42:      "FLY UP       ",
                     43:      "FLY DOWN     ",
                     44:      "USE SHIELD   ",
                     45:      NULL
                     46: };
                     47: 
                     48: #ifdef CON_MOUSE
                     49: char *mouseControlLabel[MAXMOUSEBUTTONS]={
                     50:      "LEFT BUTTON  ",
                     51:      "MIDDLE BUTTON",
                     52:      "RIGHT BUTTON "
                     53: };
                     54: #endif
                     55: 
                     56: #ifdef CON_JOYSTICK
                     57: char *joystickControlLabel[MAXJOYSTICKBUTTONS]={
                     58:      "BUTTON 1",
                     59:      "BUTTON 2",
                     60:      "BUTTON 3",
                     61:      "BUTTON 4"
                     62: };
                     63: #endif
                     64: 
                     65: #ifdef CON_AVENGER
                     66: char *avengerControlLabel[MAXAVENGERBUTTONS]={
                     67:      "BUTTON A",
                     68:      "BUTTON B",
                     69:      "BUTTON C",
                     70:      "BUTTON D",
                     71:      "BUTTON E",
                     72:      "BUTTON F"
                     73: };
                     74: #endif
                     75: 
                     76: #ifdef CON_GAMEPAD
                     77: char *gamepadControlLabel[MAXGAMEPADBUTTONS]={
                     78:      "BUTTON A",
                     79:      "BUTTON B",
                     80:      "BUTTON C",
                     81:      "BUTTON D"
                     82: };
                     83: #endif
                     84: 
                     85: #ifdef CON_WINGMAN
                     86: char *wingmanControlLabel[MAXWINGMANBUTTONS]={
                     87:      "BUTTON 1",
                     88:      "BUTTON 2",
                     89:      "BUTTON 3",
                     90:      "BUTTON 4"
                     91: };
                     92: #endif
                     93: 
                     94: #ifdef CON_VFX1
                     95: char *VFX1ControlLabel[MAXVFX1BUTTONS]={
                     96:      "TOP BUTTON   ",
                     97:      "MIDDLE BUTTON",
                     98:      "BOTTOM BUTTON"
                     99: };
                    100: #endif
                    101: 
                    102: //** Supported video modes
                    103: char *videoModeList[NUMVIDEOMODES]={
                    104:      "MCGA 320 X 200",
                    105:      "SUPERVGA 640 X 480"
                    106: };
                    107: 
                    108: signed
                    109: char configKeyboard[MAXACTIONS];
                    110: 
                    111: #ifdef CON_MOUSE
                    112: signed
                    113: char configMouse[MAXMOUSEBUTTONS];
                    114: #endif
                    115: #ifdef CON_JOYSTICK
                    116: signed
                    117: char configJoystick[MAXJOYSTICKBUTTONS];
                    118: #endif
                    119: #ifdef CON_AVENGER
                    120: signed
                    121: char configAvenger[MAXAVENGERBUTTONS];
                    122: #endif
                    123: #ifdef CON_GAMEPAD
                    124: signed
                    125: char configGamepad[MAXGAMEPADBUTTONS];
                    126: #endif
                    127: #ifdef CON_WINGMAN
                    128: signed
                    129: char configWingman[MAXWINGMANBUTTONS];
                    130: #endif
                    131: #ifdef CON_VFX1
                    132: signed
                    133: char configVFX1[MAXVFX1BUTTONS];
                    134: #endif
                    135: 
                    136: signed
                    137: char videoModeOption;
                    138: 
                    139: void
                    140: readKeyboardConfig(_INI_INSTANCE *sInstance)
                    141: {
                    142:      int  i,j;
                    143: 
                    144:      for (i=0 ; i < MAXACTIONS ; i++) {
                    145:           configKeyboard[i]=-1;
                    146:      }
                    147:      if (!hmiINILocateSection(sInstance,"KEYBOARD")) {
                    148:           return;
                    149:      }
                    150:      for (i=0 ; i < MAXACTIONS ; i++) {
                    151:           if (hmiINIGetItemString(sInstance,controlAction[i],tempBuf,16)) {
                    152:                sscanf(tempBuf,"%x",&j);
                    153:                configKeyboard[i]=(signed char)j;
                    154:           }
                    155:      }
                    156: }
                    157: 
                    158: void
                    159: writeKeyboardConfig(_INI_INSTANCE *sInstance)
                    160: {
                    161:      int  i;
                    162: 
                    163:      if (!hmiINILocateSection(sInstance,"KEYBOARD")) {
                    164:           hmiINIAddSection(sInstance,"KEYBOARD");
                    165:      }
                    166:      for (i=0 ; i < MAXACTIONS ; i++) {
                    167:           if (!hmiINILocateItem(sInstance,controlAction[i])) {
                    168:                hmiINIAddItemDecimal(sInstance,controlAction[i],
                    169:                                     (WORD)configKeyboard[i],
                    170:                                     strlen(controlAction[i])+4,16);
                    171:           }
                    172:           else {
                    173:                hmiINIWriteDecimal(sInstance,(WORD)configKeyboard[i]);
                    174:           }
                    175:      }
                    176: }
                    177: 
                    178: #ifdef CON_MOUSE
                    179: void
                    180: readMouseConfig(_INI_INSTANCE *sInstance)
                    181: {
                    182:      int  i,j;
                    183: 
                    184:      for (i=0 ; i < MAXMOUSEBUTTONS ; i++) {
                    185:           configMouse[i]=-1;
                    186:      }
                    187:      if (!hmiINILocateSection(sInstance,"MOUSE")) {
                    188:           return;
                    189:      }
                    190:      for (i=0 ; i < MAXMOUSEBUTTONS ; i++) {
                    191:           if (hmiINIGetItemString(sInstance,mouseControlLabel[i],tempBuf,16)) {
                    192:                sscanf(tempBuf,"%x",&j);
                    193:                configMouse[i]=(signed char)j;
                    194:           }
                    195:      }
                    196: }
                    197: 
                    198: void
                    199: writeMouseConfig(_INI_INSTANCE *sInstance)
                    200: {
                    201:      int  i;
                    202: 
                    203:      if (!hmiINILocateSection(sInstance,"MOUSE")) {
                    204:           hmiINIAddSection(sInstance,"MOUSE");
                    205:      }
                    206:      for (i=0 ; i < MAXMOUSEBUTTONS ; i++) {
                    207:           if (!hmiINILocateItem(sInstance,mouseControlLabel[i])) {
                    208:                hmiINIAddItemDecimal(sInstance,mouseControlLabel[i],
                    209:                                     (WORD)configMouse[i],
                    210:                                     strlen(mouseControlLabel[i])+4,16);
                    211:           }
                    212:           else {
                    213:                hmiINIWriteDecimal(sInstance,(WORD)configMouse[i]);
                    214:           }
                    215:      }
                    216: }
                    217: #endif
                    218: 
                    219: #ifdef CON_JOYSTICK
                    220: void
                    221: readJoystickConfig(_INI_INSTANCE *sInstance)
                    222: {
                    223:      int  i,j;
                    224: 
                    225:      for (i=0 ; i < MAXJOYSTICKBUTTONS ; i++) {
                    226:           configJoystick[i]=-1;
                    227:      }
                    228:      if (!hmiINILocateSection(sInstance,"JOYSTICK")) {
                    229:           return;
                    230:      }
                    231:      for (i=0 ; i < MAXJOYSTICKBUTTONS ; i++) {
                    232:           if (hmiINIGetItemString(sInstance,joystickControlLabel[i],
                    233:                                   tempBuf,16)) {
                    234:                sscanf(tempBuf,"%x",&j);
                    235:                configJoystick[i]=(signed char)j;
                    236:           }
                    237:      }
                    238: }
                    239: 
                    240: void
                    241: writeJoystickConfig(_INI_INSTANCE *sInstance)
                    242: {
                    243:      int  i;
                    244: 
                    245:      if (!hmiINILocateSection(sInstance,"JOYSTICK")) {
                    246:           hmiINIAddSection(sInstance,"JOYSTICK");
                    247:      }
                    248:      for (i=0 ; i < MAXJOYSTICKBUTTONS ; i++) {
                    249:           if (!hmiINILocateItem(sInstance,joystickControlLabel[i])) {
                    250:                hmiINIAddItemDecimal(sInstance,joystickControlLabel[i],
                    251:                                     (WORD)configJoystick[i],
                    252:                                     strlen(joystickControlLabel[i])+4,16);
                    253:           }
                    254:           else {
                    255:                hmiINIWriteDecimal(sInstance,(WORD)configJoystick[i]);
                    256:           }
                    257:      }
                    258: }
                    259: #endif
                    260: 
                    261: #ifdef CON_AVENGER
                    262: void
                    263: readAvengerConfig(_INI_INSTANCE *sInstance)
                    264: {
                    265:      int  i,j;
                    266: 
                    267:      for (i=0 ; i < MAXAVENGERBUTTONS ; i++) {
                    268:           configAvenger[i]=-1;
                    269:      }
                    270:      if (!hmiINILocateSection(sInstance,"AVENGER")) {
                    271:           return;
                    272:      }
                    273:      for (i=0 ; i < MAXAVENGERBUTTONS ; i++) {
                    274:           if (hmiINIGetItemString(sInstance,avengerControlLabel[i],
                    275:                                   tempBuf,16)) {
                    276:                sscanf(tempBuf,"%x",&j);
                    277:                configAvenger[i]=(signed char)j;
                    278:           }
                    279:      }
                    280: }
                    281: 
                    282: void
                    283: writeAvengerConfig(_INI_INSTANCE *sInstance)
                    284: {
                    285:      int  i;
                    286: 
                    287:      if (!hmiINILocateSection(sInstance,"AVENGER")) {
                    288:           hmiINIAddSection(sInstance,"AVENGER");
                    289:      }
                    290:      for (i=0 ; i < MAXAVENGERBUTTONS ; i++) {
                    291:           if (!hmiINILocateItem(sInstance,avengerControlLabel[i])) {
                    292:                hmiINIAddItemDecimal(sInstance,avengerControlLabel[i],
                    293:                                     (WORD)configAvenger[i],
                    294:                                     strlen(avengerControlLabel[i])+4,16);
                    295:           }
                    296:           else {
                    297:                hmiINIWriteDecimal(sInstance,(WORD)configAvenger[i]);
                    298:           }
                    299:      }
                    300: }
                    301: #endif
                    302: 
                    303: #ifdef CON_GAMEPAD
                    304: void
                    305: readGamepadConfig(_INI_INSTANCE *sInstance)
                    306: {
                    307:      int  i,j;
                    308: 
                    309:      for (i=0 ; i < MAXGAMEPADBUTTONS ; i++) {
                    310:           configGamepad[i]=-1;
                    311:      }
                    312:      if (!hmiINILocateSection(sInstance,"GAMEPAD")) {
                    313:           return;
                    314:      }
                    315:      for (i=0 ; i < MAXGAMEPADBUTTONS ; i++) {
                    316:           if (hmiINIGetItemString(sInstance,gamepadControlLabel[i],
                    317:                                   tempBuf,16)) {
                    318:                sscanf(tempBuf,"%x",&j);
                    319:                configGamepad[i]=(signed char)j;
                    320:           }
                    321:      }
                    322: }
                    323: 
                    324: void
                    325: writeGamepadConfig(_INI_INSTANCE *sInstance)
                    326: {
                    327:      int  i;
                    328: 
                    329:      if (!hmiINILocateSection(sInstance,"GAMEPAD")) {
                    330:           hmiINIAddSection(sInstance,"GAMEPAD");
                    331:      }
                    332:      for (i=0 ; i < MAXGAMEPADBUTTONS ; i++) {
                    333:           if (!hmiINILocateItem(sInstance,gamepadControlLabel[i])) {
                    334:                hmiINIAddItemDecimal(sInstance,gamepadControlLabel[i],
                    335:                                     (WORD)configGamepad[i],
                    336:                                     strlen(gamepadControlLabel[i])+4,16);
                    337:           }
                    338:           else {
                    339:                hmiINIWriteDecimal(sInstance,(WORD)configGamepad[i]);
                    340:           }
                    341:      }
                    342: }
                    343: #endif
                    344: 
                    345: #ifdef CON_WINGMAN
                    346: void
                    347: readWingmanConfig(_INI_INSTANCE *sInstance)
                    348: {
                    349:      int  i,j;
                    350: 
                    351:      for (i=0 ; i < MAXWINGMANBUTTONS ; i++) {
                    352:           configWingman[i]=-1;
                    353:      }
                    354:      if (!hmiINILocateSection(sInstance,"WINGMAN")) {
                    355:           return;
                    356:      }
                    357:      for (i=0 ; i < MAXWINGMANBUTTONS ; i++) {
                    358:           if (hmiINIGetItemString(sInstance,wingmanControlLabel[i],
                    359:                                   tempBuf,16)) {
                    360:                sscanf(tempBuf,"%x",&j);
                    361:                configWingman[i]=(signed char)j;
                    362:           }
                    363:      }
                    364: }
                    365: 
                    366: void
                    367: writeWingmanConfig(_INI_INSTANCE *sInstance)
                    368: {
                    369:      int  i;
                    370: 
                    371:      if (!hmiINILocateSection(sInstance,"WINGMAN")) {
                    372:           hmiINIAddSection(sInstance,"WINGMAN");
                    373:      }
                    374:      for (i=0 ; i < MAXWINGMANBUTTONS ; i++) {
                    375:           if (!hmiINILocateItem(sInstance,wingmanControlLabel[i])) {
                    376:                hmiINIAddItemDecimal(sInstance,wingmanControlLabel[i],
                    377:                                     (WORD)configWingman[i],
                    378:                                     strlen(wingmanControlLabel[i])+4,16);
                    379:           }
                    380:           else {
                    381:                hmiINIWriteDecimal(sInstance,(WORD)configWingman[i]);
                    382:           }
                    383:      }
                    384: }
                    385: #endif
                    386: 
                    387: #ifdef CON_VFX1
                    388: void
                    389: readVFX1Config(_INI_INSTANCE *sInstance)
                    390: {
                    391:      int  i,j;
                    392: 
                    393:      for (i=0 ; i < MAXVFX1BUTTONS ; i++) {
                    394:           configVFX1[i]=-1;
                    395:      }
                    396:      if (!hmiINILocateSection(sInstance,"VFX1")) {
                    397:           return;
                    398:      }
                    399:      for (i=0 ; i < MAXVFX1BUTTONS ; i++) {
                    400:           if (hmiINIGetItemString(sInstance,VFX1ControlLabel[i],
                    401:                                   tempBuf,16)) {
                    402:                sscanf(tempBuf,"%x",&j);
                    403:                configVFX1[i]=(signed char)j;
                    404:           }
                    405:      }
                    406: }
                    407: 
                    408: void
                    409: writeVFX1Config(_INI_INSTANCE *sInstance)
                    410: {
                    411:      int  i;
                    412: 
                    413:      if (!hmiINILocateSection(sInstance,"VFX1")) {
                    414:           hmiINIAddSection(sInstance,"VFX1");
                    415:      }
                    416:      for (i=0 ; i < MAXVFX1BUTTONS ; i++) {
                    417:           if (!hmiINILocateItem(sInstance,VFX1ControlLabel[i])) {
                    418:                hmiINIAddItemDecimal(sInstance,VFX1ControlLabel[i],
                    419:                                     (WORD)configVFX1[i],
                    420:                                     strlen(VFX1ControlLabel[i])+4,16);
                    421:           }
                    422:           else {
                    423:                hmiINIWriteDecimal(sInstance,(WORD)configVFX1[i]);
                    424:           }
                    425:      }
                    426: }
                    427: #endif
                    428: 
                    429: void
                    430: readVideoMode(_INI_INSTANCE *sInstance)
                    431: {
                    432:      int  i;
                    433: 
                    434:      videoModeOption=0;
                    435:      if (!hmiINILocateSection(sInstance,"VIDEO")) {
                    436:           return;
                    437:      }
                    438:      if (hmiINILocateItem(sInstance,"Resolution")) {
                    439:           if (hmiINIGetString(sInstance,tempBuf,40)) {
                    440:                for (i=0 ; i < NUMVIDEOMODES ; i++) {
                    441:                     if (stricmp(videoModeList[i],tempBuf) == 0) {
                    442:                          videoModeOption=i;
                    443:                          return;
                    444:                     }
                    445:                }
                    446:           }
                    447:      }
                    448: }
                    449: 
                    450: void
                    451: writeVideoMode(_INI_INSTANCE *sInstance)
                    452: {
                    453:      if (!hmiINILocateSection(sInstance,"VIDEO")) {
                    454:           hmiINIAddSection(sInstance,"VIDEO");
                    455:      }
                    456:      if (!hmiINILocateItem(sInstance,"Resolution")) {
                    457:           hmiINIAddItemString(sInstance,"Resolution",
                    458:                               videoModeList[videoModeOption],_SETUP_JUSTIFY);
                    459:      }
                    460:      else {
                    461:           hmiINIWriteString(sInstance,videoModeList[videoModeOption]);
                    462:      }
                    463: }
                    464: 
                    465: void
                    466: readControlConfigs(void)
                    467: {
                    468:      _INI_INSTANCE sInstance;
                    469: 
                    470:      strcpy(controlConfigFile,"CONTROLS.CFG");
                    471:      if (!hmiINIOpen(&sInstance,controlConfigFile)) {
                    472:           return;
                    473:      }
                    474:      readKeyboardConfig(&sInstance);
                    475: #ifdef CON_MOUSE
                    476:      readMouseConfig(&sInstance);
                    477: #endif
                    478: #ifdef CON_JOYSTICK
                    479:      readJoystickConfig(&sInstance);
                    480: #endif
                    481: #ifdef CON_AVENGER
                    482:      readAvengerConfig(&sInstance);
                    483: #endif
                    484: #ifdef CON_GAMEPAD
                    485:      readGamepadConfig(&sInstance);
                    486: #endif
                    487: #ifdef CON_WINGMAN
                    488:      readWingmanConfig(&sInstance);
                    489: #endif
                    490: #ifdef CON_VFX1
                    491:      readVFX1Config(&sInstance);
                    492: #endif
                    493:      readVideoMode(&sInstance);
                    494:      hmiINIClose(&sInstance);
                    495: }
                    496: 
                    497: void
                    498: writeControlConfigs(void)
                    499: {
                    500:      WORD hFile;
                    501:      _INI_INSTANCE sInstance;
                    502: 
                    503:      if (!hmiINIOpen(&sInstance,controlConfigFile)) {
                    504:           if ((hFile=creat(controlConfigFile,S_IREAD|S_IWRITE)) == -1) {
                    505:                return;
                    506:           }
                    507:           close(hFile);
                    508:           if (!hmiINIOpen(&sInstance,controlConfigFile)) {
                    509:                return;
                    510:           }
                    511:      }
                    512:      writeKeyboardConfig(&sInstance);
                    513: #ifdef CON_MOUSE
                    514:      writeMouseConfig(&sInstance);
                    515: #endif
                    516: #ifdef CON_JOYSTICK
                    517:      writeJoystickConfig(&sInstance);
                    518: #endif
                    519: #ifdef CON_AVENGER
                    520:      writeAvengerConfig(&sInstance);
                    521: #endif
                    522: #ifdef CON_GAMEPAD
                    523:      writeGamepadConfig(&sInstance);
                    524: #endif
                    525: #ifdef CON_WINGMAN
                    526:      writeWingmanConfig(&sInstance);
                    527: #endif
                    528: #ifdef CON_VFX1
                    529:      writeVFX1Config(&sInstance);
                    530: #endif
                    531:      writeVideoMode(&sInstance);
                    532:      hmiINIClose(&sInstance);
                    533: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.