1 /* Copyright (C) 1989, 1995, 1996, 1999 Aladdin Enterprises. All rights reserved. 2 3 This file is part of AFPL Ghostscript. 4 5 AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or 6 distributor accepts any responsibility for the consequences of using it, or 7 for whether it serves any particular purpose or works at all, unless he or 8 she says so in writing. Refer to the Aladdin Free Public License (the 9 "License") for full details. 10 11 Every copy of AFPL Ghostscript must include a copy of the License, normally 12 in a plain ASCII text file named PUBLIC. The License grants you the right 13 to copy, modify and redistribute AFPL Ghostscript, but only under certain 14 conditions described in the License. Among other things, the License 15 requires that the copyright notice and this notice be preserved on all 16 copies. 17 */ 18 19 /*$Id: gs.c,v 1.6 2001/04/08 08:43:24 ghostgum Exp $ */ 20 /* 'main' program for Ghostscript */ 21 #include "ghost.h" 22 #include "imain.h" 23 #include "imainarg.h" 24 #include "iapi.h" 25 #include "iminst.h" 26 #include "errors.h" 27 28 /* Define an optional array of strings for testing. */ 29 /*#define RUN_STRINGS */ 30 #ifdef RUN_STRINGS 31 private const char *run_strings[] = 32 { 33 "2 vmreclaim /SAVE save def 2 vmreclaim", 34 "(saved\n) print flush", 35 "SAVE restore (restored\n) print flush 2 vmreclaim", 36 "(done\n) print flush quit", 37 0 38 }; 39 40 #endif 41 42 int 43 main(int argc, char *argv[]) 44 { 45 int exit_status = 0; 46 gs_main_instance *minst = gs_main_instance_default(); 47 int code = gs_main_init_with_args(minst, argc, argv); 48 49 #ifdef RUN_STRINGS 50 { /* Run a list of strings (for testing). */ 51 const char **pstr = run_strings; 52 53 for (; *pstr; ++pstr) { 54 int exit_code; 55 ref error_object; 56 int code; 57 58 fprintf(stdout, "{%s} =>\n", *pstr); 59 fflush(stdout); 60 code = gs_main_run_string(minst, *pstr, 0, 61 &exit_code, &error_object); 62 zflush(osp); 63 fprintf(stdout, " => code = %d\n", code); 64 fflush(stdout); 65 if (code < 0) { 66 gs_exit(1); 67 return 1; 68 } 69 } 70 } 71 #endif 72 73 if (code >= 0) 74 code = gs_main_run_start(minst); 75 76 exit_status = 0; 77 switch (code) { 78 case 0: 79 case e_Info: 80 case e_Quit: 81 break; 82 case e_Fatal: 83 exit_status = 1; 84 break; 85 default: 86 exit_status = 255; 87 } 88 89 gs_exit_with_code(exit_status, code); 90 91 return exit_status; 92 } 93