diff options
Diffstat (limited to 'psi/psapi.c')
-rw-r--r-- | psi/psapi.c | 144 |
1 files changed, 77 insertions, 67 deletions
diff --git a/psi/psapi.c b/psi/psapi.c index b3300815..c74934a8 100644 --- a/psi/psapi.c +++ b/psi/psapi.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2019 Artifex Software, Inc. +/* Copyright (C) 2001-2020 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -37,6 +37,7 @@ #include "store.h" #include "iname.h" #include "interp.h" +#include "gxgstate.h" #ifndef GS_THREADSAFE /* Number of threads to allow per process. Unless GS_THREADSAFE is defined @@ -98,16 +99,15 @@ psapi_new_instance(gs_lib_ctx_t **pinstance, return gs_error_Fatal; } mem->gs_lib_ctx->top_of_system = (void*) minst; - mem->gs_lib_ctx->core->caller_handle = caller_handle; + mem->gs_lib_ctx->core->default_caller_handle = caller_handle; mem->gs_lib_ctx->core->custom_color_callback = NULL; #ifdef METRO - mem->gs_lib_ctx->core->stdin_fn = metro_stdin; - mem->gs_lib_ctx->core->stdout_fn = metro_stdout; - mem->gs_lib_ctx->core->stderr_fn = metro_stderr; -#else - mem->gs_lib_ctx->core->stdin_fn = NULL; - mem->gs_lib_ctx->core->stdout_fn = NULL; - mem->gs_lib_ctx->core->stderr_fn = NULL; + if (mem->gs_lib_ctx->core->stdin_fn == NULL) + mem->gs_lib_ctx->core->stdin_fn = metro_stdin; + if (mem->gs_lib_ctx->core->stdout_fn == NULL) + mem->gs_lib_ctx->core->stdout_fn = metro_stdout; + if (mem->gs_lib_ctx->core->stderr_fn == NULL) + mem->gs_lib_ctx->core->stderr_fn = metro_stderr; #endif mem->gs_lib_ctx->core->poll_fn = NULL; @@ -139,13 +139,21 @@ psapi_delete_instance(gs_lib_ctx_t *ctx) mem = (gs_memory_t *)(ctx->memory); minst = get_minst_from_memory(ctx->memory); - ctx->core->caller_handle = NULL; + ctx->core->default_caller_handle = NULL; ctx->core->stdin_fn = NULL; ctx->core->stdout_fn = NULL; ctx->core->stderr_fn = NULL; ctx->core->poll_fn = NULL; minst->display = NULL; + if (minst->param_list) { + gs_c_param_list_release(minst->param_list); + gs_free_object(minst->heap, minst->param_list, "psapi_delete_instance"); + } + + gs_c_param_list_release(&minst->enum_params); + gs_free_object(minst->heap, minst->enum_keybuf, "psapi_delete_instance"); + gs_free_object(mem, minst, "init_main_instance"); /* Release the memory (frees up everything) */ @@ -291,58 +299,32 @@ psapi_init_with_args2(gs_lib_ctx_t *ctx) } int +psapi_set_device_param(gs_lib_ctx_t *ctx, + gs_param_list *plist) +{ + gs_main_instance *minst = get_minst_from_memory(ctx->memory); + + return gs_putdeviceparams(minst->i_ctx_p->pgs->device, plist); +} + +int +psapi_get_device_params(gs_lib_ctx_t *ctx, + gs_param_list *plist) +{ + gs_main_instance *minst = get_minst_from_memory(ctx->memory); + + if (minst->i_ctx_p->pgs->device == NULL) + return 0; + return gs_getdeviceparams(minst->i_ctx_p->pgs->device, plist); +} + +int psapi_set_param(gs_lib_ctx_t *ctx, - psapi_sptype type, - const char *param, - const void *val) + gs_param_list *plist) { gs_main_instance *minst = get_minst_from_memory(ctx->memory); - ref value; - int code = 0; - i_ctx_t *i_ctx_p = minst->i_ctx_p; - uint space = icurrent_space; - - ialloc_set_space(idmemory, avm_system); - switch (type) { - case psapi_spt_null: - make_null(&value); - break; - case psapi_spt_bool: - if (val) - make_true(&value); - else - make_false(&value); - break; - case psapi_spt_int: - make_int(&value, *(int *)val); - break; - case psapi_spt_float: - make_real(&value, *(float *)val); - break; - case psapi_spt_string: - if (val == NULL) - make_empty_string(&value, a_readonly); - else { - size_t len = strlen(val); - byte *body = ialloc_string(len, "-s"); - - if (body == NULL) - return gs_error_Fatal; - memcpy(body, val, len); - make_const_string(&value, a_readonly | avm_system, len, body); - } - break; - case psapi_spt_name: - code = name_ref(ctx->memory, val, strlen(val), &value, 1); - break; - default: - break; - } - ialloc_set_space(idmemory, space); - /* Enter the name in systemdict. */ - i_initial_enter_name_copy(minst->i_ctx_p, param, &value); - return code; + return gs_main_set_language_param(minst, plist); } int @@ -365,12 +347,23 @@ psapi_run_string_begin(gs_lib_ctx_t *ctx, int user_errors, int *pexit_code) { + gs_main_instance *minst; + int code; + if (ctx == NULL) return gs_error_Fatal; + minst = get_minst_from_memory(ctx->memory); + + if (minst->mid_run_string == 1) + return -1; + minst->mid_run_string = 1; + + code = gs_main_run_string_begin(minst, user_errors, pexit_code, + &(minst->error_object)); + if (code < 0) + minst->mid_run_string = 0; - return gs_main_run_string_begin(get_minst_from_memory(ctx->memory), - user_errors, pexit_code, - &(get_minst_from_memory(ctx->memory)->error_object)); + return code; } int @@ -380,12 +373,20 @@ psapi_run_string_continue(gs_lib_ctx_t *ctx, int user_errors, int *pexit_code) { + gs_main_instance *minst; + int code; + if (ctx == NULL) return gs_error_Fatal; + minst = get_minst_from_memory(ctx->memory); - return gs_main_run_string_continue(get_minst_from_memory(ctx->memory), - str, length, user_errors, pexit_code, - &(get_minst_from_memory(ctx->memory)->error_object)); + code = gs_main_run_string_continue(minst, str, length, user_errors, + pexit_code, + &(minst->error_object)); + if (code < 0) + minst->mid_run_string = 0; + + return code; } uint @@ -402,12 +403,18 @@ psapi_run_string_end(gs_lib_ctx_t *ctx, int user_errors, int *pexit_code) { + int code; + gs_main_instance *minst; + if (ctx == NULL) return gs_error_Fatal; + minst = get_minst_from_memory(ctx->memory); + + code = gs_main_run_string_end(minst, user_errors, pexit_code, + &(minst->error_object)); - return gs_main_run_string_end(get_minst_from_memory(ctx->memory), - user_errors, pexit_code, - &(get_minst_from_memory(ctx->memory)->error_object)); + minst->mid_run_string = 0; + return code; } int @@ -454,6 +461,9 @@ psapi_run_file(gs_lib_ctx_t *ctx, return gs_error_Fatal; minst = get_minst_from_memory(ctx->memory); + if (minst->mid_run_string == 1) + return -1; + /* Convert the file_name to utf8 */ if (minst->get_codepoint) { len = 1; |