int main(int argc, char *argv[]) { int exit_status; int code = 1, code1; void *instance; int exit_code; /* run Ghostscript */ if ((code = gsapi_new_instance(&instance, NULL)) == 0) { gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr); code = gsapi_init_with_args(instance, argc, argv); if (code == 0) code = gsapi_run_string(instance, start_string, 0, &exit_code); code1 = gsapi_exit(instance); if (code == 0 || code == e_Quit) code = code1; if (code == e_Quit) code = 0; /* user executed 'quit' */ gsapi_delete_instance(instance); } exit_status = 0; switch (code) { case 0: case e_Info: case e_Quit: break; case e_Fatal: exit_status = 1; break; default: exit_status = 255; } return exit_status; }
void main(void) { int code; int exit_code; int argc; char **argv; char dformat[64], ddevice[32]; SInt32 response; /* Initialize operating environment */ #if TARGET_API_MAC_CARBON MoreMasterPointers(224); #else MoreMasters(); #endif InitCursor(); FlushEvents(everyEvent,0); if (AEInstallEventHandler(kCoreEventClass,kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler), 0L,false) != noErr) ExitToShell(); gActionFunctionScrollUPP = NewControlActionUPP(&actionFunctionScroll); Gestalt(gestaltMenuMgrAttr,&response); if(response & gestaltMenuMgrAquaLayoutMask) gRunningOnX = true; /* Initialize SIOUX */ SIOUXSettings.initializeTB = false; SIOUXSettings.standalone = false; SIOUXSettings.asktosaveonclose = false; SIOUXSettings.sleep = GetCaretTime(); SIOUXSettings.userwindowtitle = "\pGhostscript"; /* Get arguments from user */ argc = ccommand(&argv); /* Show command line window */ if (InstallConsole(0)) ExitToShell(); /* Part of fudge to make SIOUX accept characters without becoming modal */ SelectWindow(SIOUXTextWindow->window); PostEvent(keyDown, 0x4c00); // Enter ReadCharsFromConsole(dformat, 0x7FFF); clrscr(); /* Add in the display format as the first command line argument */ if (argc >= MAX_ARGS - 1) { printf("Too many command line arguments\n"); return; } memmove(&argv[3], &argv[1], (argc-1) * sizeof(char**)); argc += 2; argv[1] = ddevice; argv[2] = dformat; gs_sprintf(ddevice, "-sDEVICE=display"); gs_sprintf(dformat, "-dDisplayFormat=%d", display_format); /* Run Ghostscript */ if (gsapi_new_instance(&instance, NULL) < 0) { printf("Can't create Ghostscript instance\n"); return; } #ifdef DEBUG visual_tracer_init(); set_visual_tracer(&visual_tracer); #endif gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr); gsapi_set_poll(instance, gsdll_poll); gsapi_set_display_callback(instance, &display); code = gsapi_init_with_args(instance, argc, argv); if (code == 0) code = gsapi_run_string(instance, start_string, 0, &exit_code); else { printf("Failed to initialize. Error %d.\n", code); fflush(stdout); } code = gsapi_exit(instance); if (code != 0) { printf("Failed to terminate. Error %d.\n", code); fflush(stdout); } gsapi_delete_instance(instance); #ifdef DEBUG visual_tracer_close(); #endif /* Ghostscript has finished - let user see output before quitting */ WriteCharsToConsole("\r[Finished - hit any key to quit]", 33); fflush(stdout); /* Process events until a key is hit or user quits from menu */ while(!gDone) { EventRecord eventStructure; if(WaitNextEvent(everyEvent,&eventStructure,SIOUXSettings.sleep,NULL)) { if (eventStructure.what == keyDown) gDone = true; doEvents(&eventStructure); } else SIOUXHandleOneEvent(&eventStructure); } }