/* Create a new instance of Ghostscript. * First instance per process call with *pinstance == NULL * next instance in a proces call with *pinstance == copy of valid_instance pointer * *pinstance is set to a new instance pointer. */ GSDLLEXPORT int GSDLLAPI gsapi_new_instance(void **pinstance, void *caller_handle) { gs_memory_t *mem = NULL; gs_main_instance *minst = NULL; if (pinstance == NULL) return gs_error_Fatal; #ifndef GS_THREADSAFE /* limited to 1 instance, till it works :) */ if ( gsapi_instance_counter >= gsapi_instance_max ) return gs_error_Fatal; ++gsapi_instance_counter; #endif if (*pinstance == NULL) /* first instance in this process */ mem = gs_malloc_init(); else { /* nothing different for second thread initialization * seperate memory, ids, only stdio is process shared. */ mem = gs_malloc_init(); } if (mem == NULL) return gs_error_Fatal; minst = gs_main_alloc_instance(mem); if (minst == NULL) { gs_malloc_release(mem); return gs_error_Fatal; } mem->gs_lib_ctx->top_of_system = (void*) minst; mem->gs_lib_ctx->caller_handle = caller_handle; mem->gs_lib_ctx->custom_color_callback = NULL; #ifdef METRO mem->gs_lib_ctx->stdin_fn = metro_stdin; mem->gs_lib_ctx->stdout_fn = metro_stdout; mem->gs_lib_ctx->stderr_fn = metro_stderr; #else mem->gs_lib_ctx->stdin_fn = NULL; mem->gs_lib_ctx->stdout_fn = NULL; mem->gs_lib_ctx->stderr_fn = NULL; #endif mem->gs_lib_ctx->poll_fn = NULL; *pinstance = (void*)(mem->gs_lib_ctx); return gsapi_set_arg_encoding(*pinstance, GS_ARG_ENCODING_LOCAL); }
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; }
gs_memory_t * gs_lib_init0(FILE * debug_out) { gs_memory_t *mem; mem = (gs_memory_t *) gs_malloc_init(); /* Reset debugging flags */ memset(gs_debug, 0, 128); gs_log_errors = 0; return mem; }
gs_memory_t * gs_lib_init0(FILE * debug_out) { /* Reset debugging flags */ #ifdef PACIFY_VALGRIND VALGRIND_HG_DISABLE_CHECKING(gs_debug, 128); #endif memset(gs_debug, 0, 128); gs_log_errors = 0; return (gs_memory_t *) gs_malloc_init(); }
/* Create a new instance of Ghostscript. * First instance per process call with *pinstance == NULL * next instance in a proces call with *pinstance == copy of valid_instance pointer * *pinstance is set to a new instance pointer. */ GSDLLEXPORT int GSDLLAPI gsapi_new_instance(void **pinstance, void *caller_handle) { gs_memory_t *mem = NULL; gs_main_instance *minst = NULL; if (pinstance == NULL) return e_Fatal; /* limited to 1 instance, till it works :) */ if ( gsapi_instance_counter >= gsapi_instance_max ) return e_Fatal; ++gsapi_instance_counter; if (*pinstance == NULL) /* first instance in this process */ mem = gs_malloc_init(NULL); else { /* nothing different for second thread initialization * seperate memory, ids, only stdio is process shared. */ mem = gs_malloc_init(NULL); } minst = gs_main_alloc_instance(mem); mem->gs_lib_ctx->top_of_system = (void*) minst; mem->gs_lib_ctx->caller_handle = caller_handle; mem->gs_lib_ctx->custom_color_callback = NULL; mem->gs_lib_ctx->stdin_fn = NULL; mem->gs_lib_ctx->stdout_fn = NULL; mem->gs_lib_ctx->stderr_fn = NULL; mem->gs_lib_ctx->poll_fn = NULL; *pinstance = (void*)(mem->gs_lib_ctx); return 0; }
int main(int argc, const char *argv[]) { char achar = '0'; gs_memory_t *mem; gs_state *pgs; const gx_device *const *list; gx_device *dev; gx_device_bbox *bbdev; int code; gp_init(); mem = gs_malloc_init(); gs_lib_init1(mem); if (argc < 2 || (achar = argv[1][0]) < '1' || achar > '0' + countof(tests) - 1 ) { lprintf1("Usage: gslib 1..%c\n", '0' + (char)countof(tests) - 1); gs_abort(mem); } gs_debug['@'] = 1; gs_debug['?'] = 1; /*gs_debug['B'] = 1; *//****** PATCH ******/ /*gs_debug['L'] = 1; *//****** PATCH ******/ /* * gs_iodev_init must be called after the rest of the inits, for * obscure reasons that really should be documented! */ gs_iodev_init(mem); /****** WRONG ******/ gs_lib_device_list(&list, NULL); gs_copydevice(&dev, list[0], mem); check_device_separable(dev); gx_device_fill_in_procs(dev); bbdev = gs_alloc_struct_immovable(mem, gx_device_bbox, &st_device_bbox, "bbox"); gx_device_bbox_init(bbdev, dev, mem); code = dev_proc(dev, get_profile)(dev, &bbdev->icc_struct); rc_increment(bbdev->icc_struct); /* Print out the device name just to test the gsparam.c API. */ { gs_c_param_list list; gs_param_string nstr; gs_c_param_list_write(&list, mem); code = gs_getdeviceparams(dev, (gs_param_list *) & list); if (code < 0) { lprintf1("getdeviceparams failed! code = %d\n", code); gs_abort(mem); } gs_c_param_list_read(&list); code = param_read_string((gs_param_list *) & list, "Name", &nstr); if (code < 0) { lprintf1("reading Name failed! code = %d\n", code); gs_abort(mem); } dputs("Device name = "); debug_print_string(nstr.data, nstr.size); dputs("\n"); gs_c_param_list_release(&list); } /* * If this is a device that takes an OutputFile, set the OutputFile * to "-" in the copy. */ { gs_c_param_list list; gs_param_string nstr; gs_c_param_list_write(&list, mem); param_string_from_string(nstr, "-"); code = param_write_string((gs_param_list *)&list, "OutputFile", &nstr); if (code < 0) { lprintf1("writing OutputFile failed! code = %d\n", code); gs_abort(mem); } gs_c_param_list_read(&list); code = gs_putdeviceparams(dev, (gs_param_list *)&list); gs_c_param_list_release(&list); if (code < 0 && code != gs_error_undefined) { lprintf1("putdeviceparams failed! code = %d\n", code); gs_abort(mem); } } dev = (gx_device *) bbdev; pgs = gs_state_alloc(mem); gs_setdevice_no_erase(pgs, dev); /* can't erase yet */ { gs_point dpi; gs_screen_halftone ht; gs_dtransform(pgs, 72.0, 72.0, &dpi); ht.frequency = min(fabs(dpi.x), fabs(dpi.y)) / 16.001; ht.angle = 0; ht.spot_function = odsf; gs_setscreen(pgs, &ht); } /* gsave and grestore (among other places) assume that */ /* there are at least 2 gstates on the graphics stack. */ /* Ensure that now. */ gs_gsave(pgs); gs_erasepage(pgs); code = (*tests[achar - '1']) (pgs, mem); gs_output_page(pgs, 1, 1); { gs_rect bbox; gx_device_bbox_bbox(bbdev, &bbox); dprintf4("Bounding box: [%g %g %g %g]\n", bbox.p.x, bbox.p.y, bbox.q.x, bbox.q.y); } if (code) dprintf1("**** Test returned code = %d.\n", code); dputs("Done. Press <enter> to exit."); fgetc(mem->gs_lib_ctx->fstdin); gs_lib_finit(0, 0, mem); return 0; #undef mem }