static Viewer * mk_new_viewer(QSP_ARG_DECL int viewer_type) { const char *s; char name[256]; int dx,dy; Viewer *vp; s=NAMEOF("viewer name"); strcpy(name,s); dx=(int)HOW_MANY("width"); dy=(int)HOW_MANY("height"); if( viewer_name_in_use(QSP_ARG name) ) return NO_VIEWER; if( dx <= 0 || dy <= 0 ){ WARN("viewer sizes must be positive"); return NO_VIEWER; } vp = viewer_init(QSP_ARG name,dx,dy,viewer_type); if( vp == NO_VIEWER ) return NO_VIEWER; #ifdef HAVE_X11 default_cmap(QSP_ARG VW_DPYABLE(vp) ); #endif /* HAVE_X11 */ #ifndef BUILD_FOR_IOS /* default state is to be shown, * but in IOS we can only see one at a time, so * we leave them on the bottom until we ask. */ show_viewer(QSP_ARG vp); #endif /* ! BUILD_FOR_IOS */ select_viewer(QSP_ARG vp); return vp; }
static void x_play_movie(QSP_ARG_DECL Movie *mvip) { Data_Obj *dp; Viewer *vp; dp = (Data_Obj *)mvip->mvi_data; /* longlist(dp); */ vp = vwr_of(QSP_ARG MOVIE_VIEWER_NAME); mk_win: if( vp == NO_VIEWER ){ vp = viewer_init(QSP_ARG MOVIE_VIEWER_NAME,OBJ_COLS(dp),OBJ_ROWS(dp),0); if( vp == NO_VIEWER ){ WARN("couldn't create viewer"); return; } default_cmap(QSP_ARG VW_DPYABLE(vp) ); show_viewer(QSP_ARG vp); /* default state is to be shown */ select_viewer(QSP_ARG vp); } else { if( vp->vw_width != OBJ_COLS(dp) || vp->vw_height != OBJ_ROWS(dp) ){ sprintf(ERROR_STRING, "Resizing movie viewer for movie %s", OBJ_NAME(dp)); advise(ERROR_STRING); delete_viewer(QSP_ARG vp); vp=NO_VIEWER; goto mk_win; } } /* load_viewer got rewritten, no longer show all frames!? */ old_load_viewer(QSP_ARG vp,dp); }
int main(int argc, char** argv) { // save argv, argc for initialization of GLUT char** orig_argv = argv; int orig_argc = argc; bool configured = false; bool graphics = true; char* port = "5000"; --argc; progname = *argv++; while (argc > 0 && (argv[0][0] == '-')) { switch (argv[0][1]) { case 'c': if (configured) help(); configFile = argv[1]; argc--; argv++; configured = true; break; case 'p': port = argv[1]; argc--; argv++; break; case 'i': stopwhenidle = atoi(argv[1]); argc--; argv++; break; case 'd': debug = true; break; case 't': graphics = false; testfile = argv[1]; argc--; argv++; break; case 'n': graphics = false; break; case 'D': vmUseThreads = false; break; case 'r': if (configured) help(); configCount = 0; configured = true; break; case 'R': if (configured) help(); configCount = atoi(argv[1]); argc--; argv++; configured = true; break; default: help(); } argc--; argv++; } if (debug) fprintf(stdout, "initial configuration\n"); // start timer initTimeKeeping(); // vm initialization vmInit(port); fprintf(stderr, "Listening on %s\n", port); if (vmUseThreads) msg2vm(NULL, CMD_MODE_ND, 0); // create blocklist and initialize mutex initBlockList(); // see if we are running a test if (testfile) configured = configtest(testfile); if (!configured) { help(); } else { if (configFile != NULL) readConfig(configFile); else randomConfig(configCount); } if (graphics) { // initialize viewer viewer_init(orig_argc, orig_argv); // GL loop indefinitely event_loop(); } else { fprintf(stderr, "Running without graphics\n"); int idle = 0; while (1) { Block *block; sleep(1); int changes = 0; ForEachBlock(block) { if (block->msgTargetsDelta > 0) changes++; } if (changes == 0) { idle++; if ((stopwhenidle > 0) && (idle > stopwhenidle)) { printf("All Done\n"); msg2vm(NULL, STOP, 0); } continue; } idle = 0; fprintf(stderr, "\n---- %d\n", changes); // something changed ForEachBlock(block) { if (block->msgTargetsDelta > 0) { block->msgTargets += block->msgTargetsDelta; block->msgTargetsDelta = 0; showBlock(stderr, block); } if (checkTest(0)) { msg2vm(NULL, STOP, 0); } } fprintf(stderr, "\n"); } } // we are all done return 0; }
/* * main */ int main(int argc, char *argv[]) { struct stat sb; BOOL result; int rv = 1; int ch; int i, drvmax; progname = argv[0]; toolkit_initialize(); toolkit_arginit(&argc, &argv); while ((ch = getopt_long(argc, argv, "c:C:t:vh", longopts, NULL)) != -1) { switch (ch) { case 'c': if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) { fprintf(stderr, "Can't access %s.\n", optarg); exit(1); } milstr_ncpy(modulefile, optarg, sizeof(modulefile)); /* resume/statsave dir */ file_cpyname(statpath, modulefile, sizeof(statpath)); file_cutname(statpath); break; case 'C': if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) { fprintf(stderr, "Can't access %s.\n", optarg); exit(1); } milstr_ncpy(timidity_cfgfile_path, optarg, sizeof(timidity_cfgfile_path)); break; case 't': if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) { fprintf(stderr, "Can't access %s.\n", optarg); exit(1); } milstr_ncpy(fontfilename, optarg, sizeof(fontfilename)); break; case 'v': verbose = 1; break; case 'h': case '?': default: usage(); break; } } argc -= optind; argv += optind; if (modulefile[0] == '\0') { char *env = getenv("HOME"); if (env) { /* base dir */ snprintf(modulefile, sizeof(modulefile), "%s/.np2", env); if (stat(modulefile, &sb) < 0) { if (mkdir(modulefile, 0700) < 0) { perror(modulefile); exit(1); } } else if (!S_ISDIR(sb.st_mode)) { fprintf(stderr, "%s isn't directory.\n", modulefile); exit(1); } /* font file */ snprintf(np2cfg.fontfile, sizeof(np2cfg.fontfile), "%s/font.bmp", modulefile); /* resume/statsave dir */ file_cpyname(statpath, modulefile, sizeof(statpath)); file_catname(statpath, "/sav/", sizeof(statpath)); if (stat(statpath, &sb) < 0) { if (mkdir(statpath, 0700) < 0) { perror(statpath); exit(1); } } else if (!S_ISDIR(sb.st_mode)) { fprintf(stderr, "%s isn't directory.\n", statpath); exit(1); } /* config file */ milstr_ncat(modulefile, "/np2rc", sizeof(modulefile)); if ((stat(modulefile, &sb) >= 0) && !S_ISREG(sb.st_mode)) { fprintf(stderr, "%s isn't regular file.\n", modulefile); } } } if (timidity_cfgfile_path[0] == '\0') { file_cpyname(timidity_cfgfile_path, modulefile, sizeof(timidity_cfgfile_path)); file_cutname(timidity_cfgfile_path); file_catname(timidity_cfgfile_path, "timidity.cfg", sizeof(timidity_cfgfile_path)); } dosio_init(); file_setcd(modulefile); initload(); toolwin_readini(); kdispwin_readini(); skbdwin_readini(); rand_setseed((SINT32)time(NULL)); #if defined(GCC_CPU_ARCH_IA32) mmxflag = havemmx() ? 0 : MMXFLAG_NOTSUPPORT; mmxflag += np2oscfg.disablemmx ? MMXFLAG_DISABLE : 0; #endif TRACEINIT(); if (fontmng_init() != SUCCESS) goto fontmng_failure; kdispwin_initialize(); viewer_init(); skbdwin_initialize(); toolkit_widget_create(); scrnmng_initialize(); kbdmng_init(); inputmng_init(); keystat_initialize(); scrnmode = 0; if (np2cfg.RASTER) { scrnmode |= SCRNMODE_HIGHCOLOR; } if (sysmenu_create() != SUCCESS) goto sysmenu_failure; if (scrnmng_create(scrnmode) != SUCCESS) goto scrnmng_failure; if (soundmng_initialize() == SUCCESS) { result = soundmng_pcmload(SOUND_PCMSEEK, file_getcd("fddseek.wav")); if (!result) { result = soundmng_pcmload(SOUND_PCMSEEK, SYSRESPATH "/fddseek.wav"); } if (result) { soundmng_pcmvolume(SOUND_PCMSEEK, np2cfg.MOTORVOL); } result = soundmng_pcmload(SOUND_PCMSEEK1, file_getcd("fddseek1.wav")); if (!result) { result = soundmng_pcmload(SOUND_PCMSEEK1, SYSRESPATH "/fddseek1.wav"); } if (result) { soundmng_pcmvolume(SOUND_PCMSEEK1, np2cfg.MOTORVOL); } } joymng_initialize(); mousemng_initialize(); if (np2oscfg.MOUSE_SW) { mouse_running(MOUSE_ON); } commng_initialize(); sysmng_initialize(); taskmng_initialize(); pccore_init(); S98_init(); toolkit_widget_show(); scrndraw_redraw(); pccore_reset(); if (!(scrnmode & SCRNMODE_FULLSCREEN)) { if (np2oscfg.toolwin) { toolwin_create(); } if (np2oscfg.keydisp) { kdispwin_create(); } if (np2oscfg.softkbd) { skbdwin_create(); } } #if !defined(CPUCORE_IA32) if (np2oscfg.resume) { flagload(np2resumeext, "Resume", FALSE); } #endif sysmng_workclockreset(); drvmax = (argc < 4) ? argc : 4; for (i = 0; i < drvmax; i++) { diskdrv_readyfdd(i, argv[i], 0); } setup_signal(SIGINT, sighandler); setup_signal(SIGTERM, sighandler); toolkit_widget_mainloop(); rv = 0; kdispwin_destroy(); toolwin_destroy(); skbdwin_destroy(); pccore_cfgupdate(); mouse_running(MOUSE_OFF); joymng_deinitialize(); S98_trash(); #if !defined(CPUCORE_IA32) if (np2oscfg.resume) { flagsave(np2resumeext); } else { flagdelete(np2resumeext); } #endif pccore_term(); debugwin_destroy(); soundmng_deinitialize(); scrnmng_destroy(); scrnmng_failure: sysmenu_destroy(); sysmenu_failure: fontmng_terminate(); fontmng_failure: if (sys_updates & (SYS_UPDATECFG|SYS_UPDATEOSCFG)) { initsave(); toolwin_writeini(); kdispwin_writeini(); skbdwin_writeini(); } skbdwin_deinitialize(); TRACETERM(); dosio_term(); viewer_term(); toolkit_terminate(); return rv; }
int main(int argc, char *argv[]) { int opt_follow = 0; int opt_command = 0; char *opt_title = NULL; char *logfile = NULL; int i; /* Get command arguments */ for (i = 1; i < argc; i++) { char *args = argv[i]; if ( args[0] == '-' ) { if ( strncmp(args, "-f", 2) == 0 ) { if ( args[2] != '\0' ) opt_follow = atoi(args+2); if ( opt_follow <= 0 ) opt_follow = DEFAULT_TIMEOUT; } else if ( strncmp(args, "-c", 2) == 0 ) { opt_command = 1; } else if ( strncmp(args, "-t", 2) == 0 ) { char *s = args + 2; if ( *s == '\0' ) { s = argv[++i]; if ( s == NULL ) usage(); } opt_title = strskip_spaces(s); } else { usage(); } } else { if ( logfile == NULL ) logfile = args; else usage(); } } /* GTK gears initialization */ gtk_init(&argc, &argv); /* The viewer */ viewer = viewer_init(opt_title); viewer_destroyed(viewer, shutdown, NULL); viewer_load(viewer, logfile); /* Setup remote command pipe if any */ if ( opt_command ) { command_id = gdk_input_add(fileno(stdin), GDK_INPUT_READ, (GdkInputFunction) command_handler, (gpointer) viewer); } /* Setup handling of automatic follow */ if ( opt_follow ) { timeout_tag = g_timeout_add(opt_follow * 1000, (GSourceFunc) follow, NULL); } /* Processing loop */ gtk_main(); return 0; }