int main(int argc, char *argv[]) { int exit_status = 0; gs_main_instance *minst = gs_main_alloc_instance(gs_malloc_init(NULL)); int code = gs_main_init_with_args(minst, argc, argv); #ifdef RUN_STRINGS { /* Run a list of strings (for testing). */ const char **pstr = run_strings; for (; *pstr; ++pstr) { int exit_code; ref error_object; int code; fprintf(stdout, "{%s} =>\n", *pstr); fflush(stdout); code = gs_main_run_string(minst, *pstr, 0, &exit_code, &error_object); zflush(osp); fprintf(stdout, " => code = %d\n", code); fflush(stdout); if (code < 0) { gs_to_exit(1); return 1; } } } #endif if (code >= 0) code = gs_main_run_start(minst); 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; } gs_to_exit_with_code(minst->heap, exit_status, code); switch (exit_status) { case 0: exit_status = exit_OK; break; case 1: exit_status = exit_FAILED; break; } return exit_status; }
/* Initialise the interpreter */ GSDLLEXPORT int GSDLLAPI gsapi_init_with_args(void *lib, int argc, char **argv) { gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib; if (lib == NULL) return e_Fatal; return gs_main_init_with_args(get_minst_from_memory(ctx->memory), argc, argv); }
/* Do per-instance interpreter allocation/init. No device is set yet */ static int /* ret 0 ok, else -ve error code */ ps_impl_allocate_interp_instance( pl_interp_instance_t **instance, /* RETURNS instance struct */ pl_interp_t *interp, /* dummy interpreter */ gs_memory_t *mem /* allocator to allocate instance from */ ) { #ifdef DEBUG_WITH_EXPERIMENTAL_GSOPTIONS_FILE # define MAX_ARGS 40 #else # define MAX_ARGS /* unspecified */ #endif int code = 0, exit_code; const char *argv[MAX_ARGS] = { "", "-dNOPAUSE", #ifndef DEBUG "-dQUIET", #else "-dOSTACKPRINT", // NB: debuggging postscript Needs to be removed. "-dESTACKPRINT", // NB: debuggging postscript Needs to be removed. #endif #if UFST_BRIDGE==1 "-dJOBSERVER", "-sUFST_PlugIn=" UFSTFONTDIR "mtfonts/pcl45/mt3/plug__xi.fco", "-sFCOfontfile=" UFSTFONTDIR "mtfonts/pclps2/mt3/pclp2_xj.fco", "-sFCOfontfile2=" UFSTFONTDIR "mtfonts/pcl45/mt3/wd____xh.fco", "-sFAPIfontmap=FCOfontmap-PCLPS2", "-sFAPIconfig=FAPIconfig-FCO", #endif 0 }; #ifndef DEBUG int argc = 9; #else int argc = 10; #endif #ifdef DEBUG_WITH_EXPERIMENTAL_GSOPTIONS_FILE char argbuf[1024]; #endif # undef MAX_ARGS ps_interp_instance_t *psi /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/ = (ps_interp_instance_t *) gs_alloc_bytes( mem, sizeof(ps_interp_instance_t), "ps_allocate_interp_instance(ps_interp_instance_t)" ); #if UFST_BRIDGE!=1 argc -= 6; #endif /* If allocation error, deallocate & return */ if (!psi) { return gs_error_VMerror; } /* Initialize for pl_main_universe_dnit/pl_deallocate_interp_instance in case of gs_main_init_with_args returns with error code. */ psi->pl.interp = interp; /* Setup pointer to mem used by PostScript */ psi->plmemory = mem; psi->minst = gs_main_alloc_instance(mem->non_gc_memory); #ifdef DEBUG_WITH_EXPERIMENTAL_GSOPTIONS_FILE { /* Fetch more GS arguments (debug purposes only). Pulling debugging arguments from a file allows easy additions of postscript arguments to a debug system, it is not recommended for production systems since some options will conflict with commandline arguments in unpleasant ways. */ FILE *f = fopen("gsoptions", "rb"); /* Sorry we handle the current directory only. Assuming it always fails with no crash in a real embedded system. */ if (f != NULL) { int i; int l = fread(argbuf, 1, sizeof(argbuf) - 1, f); if (l >= sizeof(argbuf) - 1) errprintf("The gsoptions file is too big. Truncated to the buffer length %d.\n", l - 1); if (l > 0) { argbuf[l] = 0; if (argbuf[0] && argbuf[0] != '\r' && argbuf[0] != '\n') /* Silently skip empty lines. */ argv[argc++] = argbuf; for (i = 0; i < l; i++) if (argbuf[i] == '\r' || argbuf[i] == '\n') { argbuf[i] = 0; if (argbuf[i + 1] == 0 || argbuf[i + 1] == '\r' || argbuf[i + 1] == '\n') continue; /* Silently skip empty lines. */ if (argc >= count_of(argv)) { errprintf("The gsoptions file contains too many options. " "Truncated to the buffer length %d.\n", argc); break; } argv[argc++] = argbuf + i + 1; } } fclose(f); } } #endif *instance = (pl_interp_instance_t *)psi; code = gs_main_init_with_args(psi->minst, argc, (char**)argv); if (code<0) return code; /* General init of PS interp instance */ if ((code = gs_main_run_string_begin(psi->minst, 0, &exit_code, &psi->minst->error_object)) < 0) return exit_code; { gs_state *pgs = psi->minst->i_ctx_p->pgs; gsicc_init_iccmanager(pgs); } /* inialize fresh job to false so that we can check for a pdf file next job. */ psi->fresh_job = true; /* default is a postscript stream */ psi->pdf_stream = false; /* Return success */ return 0; }