void startup_common(const char *name, int playmode) { /* (re)init all global data */ init_data(); init_tutorial(); init_timeout(); init_shop_selection(); reset_food(); /* zero out victual and tin */ reset_steal(); reset_dig_status(); reset_encumber_msg(); reset_occupations(); /* create mutable copies of object and artifact liss */ init_objlist(); init_artilist(); reset_rndmonst(NON_PM); free_dungeon(); /* clean up stray dungeon data */ program_state.game_running = 0; initoptions(); dlb_init(); /* must be before newgame() */ /* * Initialization of the boundaries of the mazes * Both boundaries have to be even. */ x_maze_max = COLNO-1; if (x_maze_max % 2) x_maze_max--; y_maze_max = ROWNO-1; if (y_maze_max % 2) y_maze_max--; /* * Initialize the vision system. This must be before mklev() on a * new game or before a level restore on a saved game. */ vision_init(); if (playmode == MODE_TUTORIAL) flags.tutorial = TRUE; if (playmode == MODE_EXPLORE) discover = TRUE; else if (playmode == MODE_WIZARD) wizard = TRUE; if (name && name[0]) { strncpy(plname, name, PL_NSIZ); plname[PL_NSIZ-1] = '\0'; } if (wizard) strcpy(plname, "巫师"); cls(); initrack(); }
argoptions ParseCommandLine(int argc, const char *argv[]) { argoptions opt; initoptions(&opt); bool nobounding = false; bool nodisp = false; string filename; utility::parse_cli_arguments(argc,argv, utility::cli_argument_pack() .positional_arg(filename,"dataset", "Model file") .positional_arg(opt.boundthresh,"boundthresh","bounding threshold value") .arg(nodisp,"no-display-updating","disable run-time display updating") .arg(nobounding,"no-bounding","disable bounding technique") .arg(silent_mode,"silent","no output except elapsed time") ); strcpy(opt.filename, filename.c_str()); opt.displaymode = nodisp ? RT_DISPLAY_DISABLED : RT_DISPLAY_ENABLED; opt.boundmode = nobounding ? RT_BOUNDING_DISABLED : RT_BOUNDING_ENABLED; return opt; }
jboolean nhjni_run() { windowprocs = _nhjni_proxy_procs; _nhjni_proxy_init(); int fd = create_levelfile(0, (char *)0); if (fd < 0) { raw_print("Cannot create lock file"); } else { hackpid = 1; write(fd, (genericptr_t) &hackpid, sizeof(hackpid)); close(fd); } iflags.news = TRUE; int argc=1; char *argv[]={"nethack",NULL}; initoptions(); init_nhwindows(&argc,argv); dlb_init(); vision_init(); display_gamewindows(); if ((fd = restore_saved_game()) >= 0) { const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); pline("Restoring save file..."); mark_synch(); /* flush output */ if(!dorecover(fd)) goto not_recovered; check_special_room(FALSE); //wd_message(); if (discover || wizard) { if(yn("Do you want to keep the save file?") == 'n') (void) delete_savefile(); else { (void) chmod(fq_save,FCMASK); /* back to readable */ compress(fq_save); } } flags.move = 0; } else { not_recovered: player_selection(); newgame(); flags.move = 0; set_wear(); (void) pickup(1); } moveloop(); return JNI_TRUE; }
int getargs(int argc, char **argv, argoptions * opt) { int i, rc, unknowncnt; if (opt == NULL) return -1; initoptions(opt); if (argc < 2) { // printusage(argv); Ok to not have params - default model #ifndef DEFAULT_MODELFILE return -1; #else return 0; #endif//DEFAULT_MODELFILE } i = 1; unknowncnt = 0; while (i < argc) { if (argv[i][0] == '-' || argv[i][0] == '+') { rc = getparm(argc, argv, i, opt); if (rc != -1) { i += rc; } else { printusage(argv); return -1; } } else { unknowncnt++; if (unknowncnt > 1) { fprintf(stderr, "Too many model file names found!\n"); printusage(argv); return -1; } else { strcpy(opt->filename, argv[i]); opt->foundfilename = 1; i++; } } } if (opt->foundfilename == -1) { fprintf(stderr, "Missing model file name!\n"); printusage(argv); return -1; } return 0; }
void* example_main(void *filename) { try { LOG_INFO("initoptions"); argoptions opt; initoptions(&opt); strcpy(opt.filename, (char*) filename); LOG_INFO("initoptions done"); LOG_INFO("CreateScene"); if ((CreateScene(opt) != 0)) return NULL; LOG_INFO("CreateScene done"); LOG_INFO("tachyon video"); tachyon_video tachyon; LOG_INFO("tachyon video init_console"); tachyon.init_console(); LOG_INFO("tachyon video init_window"); tachyon.init_window(global_xsize, global_ysize); LOG_INFO("tachyon video init_window done"); if( !tachyon.running ) return NULL; LOG_INFO("tachyon video done"); video = &tachyon; //Exit from the while via GUI "Exit" menu. for(;;) { LOG_INFO("main_loop() start"); elapsedTime = 0; startTime=time(NULL); isCancelled=false; if (video)video->running = true; memset(g_pImg, 0, 4 * global_xsize * global_ysize); tachyon.main_loop(); elapsedTime = (long)(time(NULL)-startTime); video->running=false; //The timer to restart drawing then it is complete. int timer=5; do{ sleep(1); }while( ( isPaused || !isCancelled && (timer--)>0 ) ); LOG_INFO("main_loop() done"); } return NULL; } catch (std::exception& e) { LOG_ERROR("An error occurred. Error text is %s", e.what()); return NULL; } }
Sint parsemaxmatoptions(MMcallinfo *mmcallinfo,int argc, char *argv[]) { OptionDescription options[NUMOFOPTIONS]; // store the options Sint optval; // neg. return val. if error, otherwise option number Uint argnum; // pointer to argv signed long readint; // temporary integer to read value from string char leastlengthtext[128+1]; initoptions(&options[0],(Uint) NUMOFOPTIONS); ADDOPTION(OPTMUM,"-mum", "compute maximal matches that are unique in both sequences"); ADDOPTION(OPTMUMREF,"-mumreference", "compute maximal matches that are unique in the reference-\n" "sequence but not necessarily in the query-sequence (default)"); ADDOPTION(OPTMUMCAND,"-mumcand", "same as -mumreference"); ADDOPTION(OPTMAXMATCH,"-maxmatch", "compute all maximal matches regardless of their uniqueness"); ADDOPTION(OPTMATCHNUCLEOTIDESONLY,"-n", "match only the characters a, c, g, or t\n" "they can be in upper or in lower case"); makeleastlengthtext(&leastlengthtext[0]); ADDOPTION(OPTLEASTLENGTH,"-l",&leastlengthtext[0]); ADDOPTION(OPTCOMPUTEBOTHDIRECTIONS,"-b", "compute forward and reverse complement matches"); ADDOPTION(OPTONLYREVERSECOMPLEMENT,"-r", "only compute reverse complement matches"); ADDOPTION(OPTSHOWSTRING,"-s", "show the matching substrings"); ADDOPTION(OPTSHOWREVERSEPOSITIONS,"-c", "report the query-position of a reverse complement match\n" "relative to the original query sequence"); ADDOPTION(OPTFOURCOLUMN,"-F", "force 4 column output format regardless of the number of\n" "reference sequence inputs"); ADDOPTION(OPTSHOWSEQUENCELENGTHS,"-L", "show the length of the query sequences on the header line"); ADDOPTION(OPTCHUNKS,"-C","number of chunks to split query sequence"); ADDOPTION(OPTPREFIXLENGTH,"-P","length of prefix for Direct Access Table"); ADDOPTION(OPTH,"-h", "show possible options"); ADDOPTION(OPTHELP,"-help", "show possible options"); mmcallinfo->showstring = false; mmcallinfo->reversecomplement = false; mmcallinfo->forward = true; mmcallinfo->showreversepositions = false; mmcallinfo->fourcolumn = false; mmcallinfo->showsequencelengths = false; mmcallinfo->matchnucleotidesonly = false; mmcallinfo->cmum = false; mmcallinfo->cmumcand = false; mmcallinfo->cmaxmatch = false; mmcallinfo->minmatchlength = (Uint) DEFAULTMINUNIQUEMATCHLEN; mmcallinfo->chunks = (Uint) DEFAULTCHUNK; if(argc == 1) { showusage(argv[0],&options[0],(Uint) NUMOFOPTIONS); return 1; } for(argnum = UintConst(1); argnum < (Uint) argc && argv[argnum][0] == '-'; argnum++) { optval = procoption(options,(Uint) NUMOFOPTIONS,argv[argnum]); if(optval < 0) { return -1; } switch(optval) { case OPTSHOWSTRING: mmcallinfo->showstring = true; break; case OPTCOMPUTEBOTHDIRECTIONS: mmcallinfo->reversecomplement = true; break; case OPTSHOWREVERSEPOSITIONS: mmcallinfo->showreversepositions = true; break; case OPTLEASTLENGTH: // additionally check the length parameter argnum++; if(argnum > (Uint) (argc-2)) { ERROR1("missing argument for option %s", options[OPTLEASTLENGTH].optname); return -2; } if(sscanf(argv[argnum],"%ld",&readint) != 1 || readint <= 0) { ERROR2("argument %s for option %s is not a positive integer", argv[argnum],options[OPTLEASTLENGTH].optname); return -3; } mmcallinfo->minmatchlength = (Uint) readint; break; case OPTFOURCOLUMN: mmcallinfo->fourcolumn = true; break; case OPTSHOWSEQUENCELENGTHS: mmcallinfo->showsequencelengths = true; break; case OPTMATCHNUCLEOTIDESONLY: mmcallinfo->matchnucleotidesonly = true; break; case OPTONLYREVERSECOMPLEMENT: mmcallinfo->forward = false; mmcallinfo->reversecomplement = true; break; case OPTMAXMATCH: mmcallinfo->cmaxmatch = true; break; case OPTMUMREF: case OPTMUMCAND: mmcallinfo->cmumcand = true; break; case OPTMUM: mmcallinfo->cmum = true; break; case OPTCHUNKS: argnum++; if(argnum > (Uint) (argc-2)) { ERROR1("missing argument for option %s", options[OPTCHUNKS].optname); return -2; } if(sscanf(argv[argnum],"%ld",&readint) != 1 || readint <= 0) { ERROR2("argument %s for option %s is not a positive integer", argv[argnum],options[OPTCHUNKS].optname); return -3; } mmcallinfo->chunks = (Uint) readint; break; case OPTPREFIXLENGTH: argnum++; if(argnum > (Uint) (argc-2)) { ERROR1("missing argument for option %s", options[OPTPREFIXLENGTH].optname); return -2; } if(sscanf(argv[argnum],"%ld",&readint) != 1 || readint <= 0) { ERROR2("argument %s for option %s is not a positive integer", argv[argnum],options[OPTPREFIXLENGTH].optname); return -3; } mmcallinfo->prefix = (Uint) readint; break; case OPTH: case OPTHELP: showusage(argv[0],&options[0],(Uint) NUMOFOPTIONS); return 1; } } if(argnum > (Uint) (argc-2)) { ERROR0("missing file arguments"); return -4; } if(safestringcopy(&mmcallinfo->program[0],argv[0],PATH_MAX) != 0) { return -5; } if(safestringcopy(&mmcallinfo->subjectfile[0],argv[argnum],PATH_MAX) != 0) { return -6; } for(argnum++, mmcallinfo->numofqueryfiles = 0; argnum < (Uint) argc; mmcallinfo->numofqueryfiles++, argnum++) { if(mmcallinfo->numofqueryfiles >= (Uint) MAXNUMOFQUERYFILES) { ERROR1("too many query files, maximal number is %d", (int) MAXNUMOFQUERYFILES); return -7; } if(safestringcopy(&mmcallinfo->queryfilelist [mmcallinfo->numofqueryfiles][0], argv[argnum],PATH_MAX) != 0) { return -8; } } /* verify that mum options are not interchanged */ OPTIONEXCLUDE(OPTMUM,OPTMUMCAND); OPTIONEXCLUDE(OPTMUM,OPTMUMREF); OPTIONEXCLUDE(OPTMUM,OPTMAXMATCH); OPTIONEXCLUDE(OPTMUMCAND,OPTMAXMATCH); OPTIONEXCLUDE(OPTMUMREF,OPTMAXMATCH); if ( mmcallinfo->cmaxmatch ) { mmcallinfo->cmum = false; mmcallinfo->cmumcand = false; } else if ( mmcallinfo->cmum ) { } else /* default to cmumcand */ { mmcallinfo->cmumcand = true; } /* verify that the options -b and -r are not used at the same time */ OPTIONEXCLUDE(OPTCOMPUTEBOTHDIRECTIONS,OPTONLYREVERSECOMPLEMENT); /* verify that -c is only used in combination with either -b or -r */ OPTIONIMPLYEITHER2(OPTSHOWREVERSEPOSITIONS, OPTCOMPUTEBOTHDIRECTIONS,OPTONLYREVERSECOMPLEMENT); return 0; }
int main(int argc, char *argv[]) { int fd; #ifdef CHDIR char *dir; #endif hname = argv[0]; hackpid = getpid(); #ifdef CHDIR /* otherwise no chdir() */ /* * See if we must change directory to the playground. * (Perhaps hack runs suid and playground is inaccessible * for the player.) * The environment variable HACKDIR is overridden by a * -d command line option (must be the first option given) */ dir = getenv("HACKDIR"); if (argc > 1 && !strncmp(argv[1], "-d", 2)) { argc--; argv++; dir = argv[0] + 2; if (*dir == '=' || *dir == ':') dir++; if (!*dir && argc > 1) { argc--; argv++; dir = argv[0]; } if (!*dir) error("Flag -d must be followed by a directory name."); } #endif /* * Who am i? Algorithm: 1. Use name as specified in HACKOPTIONS * 2. Use $USER or $LOGNAME (if 1. fails) * 3. Use getlogin() (if 2. fails) * The resulting name is overridden by command line options. * If everything fails, or if the resulting name is some generic * account like "games", "play", "player", "hack" then eventually * we'll ask him. * Note that we trust him here; it is possible to play under * somebody else's name. */ { char *s; initoptions(); if (!*plname && (s = getenv("USER"))) strncpy(plname, s, sizeof(plname) - 1); if (!*plname && (s = getenv("LOGNAME"))) strncpy(plname, s, sizeof(plname) - 1); if (!*plname && (s = getlogin())) strncpy(plname, s, sizeof(plname) - 1); } /* * Now we know the directory containing 'record' and * may do a prscore(). */ if (argc > 1 && !strncmp(argv[1], "-s", 2)) { #ifdef CHDIR chdirx(dir, 0); #endif prscore(argc, argv); exit(0); } /* * It seems he really wants to play. * Remember tty modes, to be restored on exit. */ gettty(); setbuf(stdout, obuf); umask(007); setrandom(); startup(); cls(); u.uhp = 1; /* prevent RIP on early quits */ u.ux = FAR; /* prevent nscr() */ signal(SIGHUP, hangup); /* * Find the creation date of this game, * so as to avoid restoring outdated savefiles. */ gethdate(hname); /* * We cannot do chdir earlier, otherwise gethdate will fail. */ #ifdef CHDIR chdirx(dir, 1); #endif /* * Process options. */ while (argc > 1 && argv[1][0] == '-') { argv++; argc--; switch (argv[0][1]) { #ifdef WIZARD case 'D': wizard = TRUE; break; #endif #ifdef NEWS case 'n': flags.nonews = TRUE; break; #endif case 'u': if (argv[0][2]) strncpy(plname, argv[0] + 2, sizeof(plname) - 1); else if (argc > 1) { argc--; argv++; strncpy(plname, argv[0], sizeof(plname) - 1); } else printf("Player name expected after -u\n"); break; default: /* allow -T for Tourist, etc. */ strncpy(pl_character, argv[0] + 1, sizeof(pl_character) - 1); } } if (argc > 1) locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS if (!locknum || locknum > MAX_NR_OF_PLAYERS) locknum = MAX_NR_OF_PLAYERS; #endif #ifdef DEF_PAGER if (!(catmore = getenv("HACKPAGER")) && !(catmore = getenv("PAGER"))) catmore = DEF_PAGER; #endif #ifdef MAIL getmailstatus(); #endif #ifdef WIZARD if (wizard) strcpy(plname, "wizard"); else #endif if (!*plname || !strncmp(plname, "player", 4) || !strncmp(plname, "games", 4)) askname(); plnamesuffix(); /* strip suffix from name; calls askname() */ /* again if suffix was whole name */ /* accepts any suffix */ #ifdef WIZARD if (!wizard) { #endif /* * check for multiple games under the same name * (if !locknum) or check max nr of players (otherwise) */ signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); if (!locknum) strcpy(lock, plname); getlock(); /* sets lock if locknum != 0 */ #ifdef WIZARD } else { char *sfoo; strcpy(lock, plname); if ((sfoo = getenv("MAGIC"))) while (*sfoo) { switch (*sfoo++) { case 'n': srandom(*sfoo++); break; } } if ((sfoo = getenv("GENOCIDED")) != NULL) { if (*sfoo == '!') { struct permonst *pm = mons; char *gp = genocided; while (pm < mons + CMNUM + 2) { if (!strchr(sfoo, pm->mlet)) *gp++ = pm->mlet; pm++; } *gp = 0; } else strncpy(genocided, sfoo, sizeof(genocided) - 1); strcpy(fut_geno, genocided); } } #endif setftty(); sprintf(SAVEF, "save/%d%s", getuid(), plname); regularize(SAVEF + 5); /* avoid . or / in name */ if ((fd = open(SAVEF, O_RDONLY)) >= 0 && (uptodate(fd) || unlink(SAVEF) == 666)) { signal(SIGINT, done1); pline("Restoring old save file..."); fflush(stdout); if (!dorecover(fd)) goto not_recovered; pline("Hello %s, welcome to %s!", plname, gamename); flags.move = 0; } else { not_recovered: fobj = fcobj = invent = 0; fmon = fallen_down = 0; ftrap = 0; fgold = 0; flags.ident = 1; init_objects(); u_init(); signal(SIGINT, done1); mklev(); u.ux = xupstair; u.uy = yupstair; inshop(); setsee(); flags.botlx = 1; makedog(); { struct monst *mtmp; if ((mtmp = m_at(u.ux, u.uy)) != NULL) mnexto(mtmp); /* riv05!a3 */ } seemons(); #ifdef NEWS if (flags.nonews || !readnews()) /* after reading news we did docrt() already */ #endif docrt(); /* give welcome message before pickup messages */ pline("Hello %s, welcome to %s!", plname, gamename); pickup(1); read_engr_at(u.ux, u.uy); flags.move = 1; } flags.moonphase = phase_of_the_moon(); if (flags.moonphase == FULL_MOON) { pline("You are lucky! Full moon tonight."); u.uluck++; } else if (flags.moonphase == NEW_MOON) pline("Be careful! New moon tonight."); initrack(); for (;;) { if (flags.move) { /* actual time passed */ settrack(); if (moves % 2 == 0 || (!(Fast & ~INTRINSIC) && (!Fast || rn2(3)))) { movemon(); if (!rn2(70)) makemon(NULL, 0, 0); } if (Glib) glibr(); p_timeout(); ++moves; if (flags.time) flags.botl = 1; if (u.uhp < 1) { pline("You die..."); done("died"); } if (u.uhp * 10 < u.uhpmax && moves - wailmsg > 50) { wailmsg = moves; if (u.uhp == 1) pline("You hear the wailing of the Banshee..."); else pline("You hear the howling of the CwnAnnwn..."); } if (u.uhp < u.uhpmax) { if (u.ulevel > 9) { if (Regeneration || !(moves % 3)) { flags.botl = 1; u.uhp += rnd((int)u.ulevel - 9); if (u.uhp > u.uhpmax) u.uhp = u.uhpmax; } } else if (Regeneration || (!(moves % (22 - u.ulevel * 2)))) { flags.botl = 1; u.uhp++; } } if (Teleportation && !rn2(85)) tele(); if (Searching && multi >= 0) dosearch(); gethungry(); invault(); amulet(); } if (multi < 0) { if (!++multi) { pline("%s", nomovemsg ? nomovemsg : "You can move again."); nomovemsg = 0; if (afternmv) (*afternmv)(); afternmv = NULL; } } find_ac(); #ifndef QUEST if (!flags.mv || Blind) #endif { seeobjs(); seemons(); nscr(); } if (flags.botl || flags.botlx) bot(); flags.move = 1; if (multi >= 0 && occupation) { if (monster_nearby()) stop_occupation(); else if ((*occupation)() == 0) occupation = NULL; continue; } if (multi > 0) { #ifdef QUEST if (flags.run >= 4) finddir(); #endif lookaround(); if (!multi) { /* lookaround may clear multi */ flags.move = 0; continue; } if (flags.mv) { if (multi < COLNO && !--multi) flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } } else if (multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack(NULL); } if (multi && multi % 7 == 0) fflush(stdout); } }