int US_CheckParm(const char *parm, const char **strings) { // Strip any non-alphabetic characters from 'parm' while (*parm) { if (isalpha(*(parm))) break; parm++; } // For every string in 'strings' for (int i = 0; strings[i]; ++i) { if (strings[i][0] == '\0') continue; if (!CK_Cross_strcasecmp(parm, strings[i])) return i; } return -1; }
int main(int argc, char *argv[]) { // Send the cmd-line args to the User Manager. us_argc = argc; us_argv = (const char **) argv; // Default to the first episode with all files present. // If no episodes are found, we default to Keen 4, in order // to show the file not found messages. ck_currentEpisode = &ck4_episode; for (int i = 0; ck_episodes[i]; ++i) { if (ck_episodes[i]->isPresent()) { ck_currentEpisode = ck_episodes[i]; break; } } bool isFullScreen = false; bool isAspectCorrected = true; #ifdef CK_ENABLE_PLAYLOOP_DUMPER const char *dumperFilename = NULL; #endif for (int i = 1; i < argc; ++i) { if (!CK_Cross_strcasecmp(argv[i], "/EPISODE")) { // A bit of stuff from the usual demo loop if (argc >= i+1) { if (!strcmp(argv[i+1], "4")) ck_currentEpisode = &ck4_episode; else if (!strcmp(argv[i+1], "5")) ck_currentEpisode = &ck5_episode; else if (!strcmp(argv[i+1], "6")) ck_currentEpisode = &ck6_episode; else Quit("Unsupported episode!"); } } else if (!CK_Cross_strcasecmp(argv[i], "/FULLSCREEN")) { isFullScreen = true; } else if (!CK_Cross_strcasecmp(argv[i], "/FILLED")) { isAspectCorrected = false; } #ifdef CK_ENABLE_PLAYLOOP_DUMPER else if (!CK_Cross_strcasecmp(argv[i], "/DUMPFILE")) { if (i < argc+1) dumperFilename = argv[++i]; // Yes, we increment i twice } #endif } #ifdef CK_ENABLE_PLAYLOOP_DUMPER extern FILE *ck_dumperFile; if (dumperFilename != NULL) { ck_dumperFile = fopen(dumperFilename, "wb"); if (ck_dumperFile == NULL) { fprintf(stderr, "Couldn't open dumper file for writing.\n"); return 1; } printf("Writing to dump file %s\n", dumperFilename); } #endif VL_SetParams(isFullScreen, isAspectCorrected); ck_currentEpisode->defineConstants(); CK_InitGame(); for (int i = 1; i < argc; ++i) { if (!CK_Cross_strcasecmp(argv[i], "/DEMOFILE")) { // A bit of stuff from the usual demo loop ck_gameState.levelState = 0; CK_PlayDemoFile(argv[i + 1]); Quit(0); } } if (us_noWait || us_tedLevel) ck_debugActive = true; // Draw the ANSI "Press Key When Ready Screen" here CK_DemoLoop(); CK_ShutdownID(); #ifdef CK_ENABLE_PLAYLOOP_DUMPER if (ck_dumperFile) fclose(ck_dumperFile); #endif }