Exemple #1
0
/* arguments are:
 * 1. callback function for stdio and for notification of
 *   sync_output, output_page and resize events
 * 2. window handle, used as parent.  Use NULL if you have no window.
 * 3. argc
 * 4. argv
 */
int GSDLLEXPORT GSDLLAPI
gsdll_init_with_encoding(GSDLL_CALLBACK callback, HWND hwnd, int argc, char * argv[], int encoding)
{
    int code;

    if ((code = gsapi_new_instance(&pgs_minst, (void *)1)) < 0)
        return -1;

    gsapi_set_stdio(pgs_minst,
        gsdll_old_stdin, gsdll_old_stdout, gsdll_old_stderr);
    gsapi_set_poll(pgs_minst, gsdll_old_poll);
    /* ignore hwnd */

/* rest of MacGSView compatibilty hack */
#ifdef __MACOS__
        hwndtext=hwnd;
#endif

/****** SINGLE-INSTANCE HACK ******/
    pgsdll_callback = callback;
/****** SINGLE-INSTANCE HACK ******/

    code = gsapi_set_arg_encoding(pgs_minst, encoding);
    if (code >= 0)
        code = gsapi_init_with_args(pgs_minst, argc, argv);
    if (code == e_Quit) {
        gsapi_exit(pgs_minst);
        return GSDLL_INIT_QUIT;
    }
    return code;
}
Exemple #2
0
/* 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);
}
Exemple #3
0
GSDLLEXPORT int GSDLLAPI
gsapi_init_with_argsA(void *lib, int argc, char **argv)
{
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    int code;
    gs_arg_get_codepoint *old;
    if (lib == NULL)
        return gs_error_Fatal;

    old = gs_main_inst_get_arg_decode(get_minst_from_memory(ctx->memory));
    code = gsapi_set_arg_encoding(lib, GS_ARG_ENCODING_LOCAL);
    if (code != 0)
        return code;
    code = gsapi_init_with_args(lib, 2*argc, (char **)argv);
    gs_main_inst_arg_decode(get_minst_from_memory(ctx->memory), old);
    return code;
}
Exemple #4
0
GSDLLEXPORT int GSDLLAPI
gsapi_run_fileA(void *lib, const char *file_name,
        int user_errors, int *pexit_code)
{
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    int code;
    gs_arg_get_codepoint *old;
    if (lib == NULL)
        return gs_error_Fatal;

    old = gs_main_inst_get_arg_decode(get_minst_from_memory(ctx->memory));
    code = gsapi_set_arg_encoding(lib, GS_ARG_ENCODING_LOCAL);
    if (code != 0)
        return code;
    code = gsapi_run_file(lib, (const char *)file_name, user_errors, pexit_code);
    gs_main_inst_arg_decode(get_minst_from_memory(ctx->memory), old);
    return code;
}
Exemple #5
0
GSDLLEXPORT int GSDLLAPI
gsapi_init_with_argsW(void *lib, int argc, wchar_t **argv)
{
#ifdef GS_NO_UTF8
    /* Cannot call the W entrypoints in a GS_NO_UTF8 build */
    return gs_error_Fatal;
#else
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    int code;
    gs_arg_get_codepoint *old;
    if (lib == NULL)
        return gs_error_Fatal;

    old = gs_main_inst_get_arg_decode(get_minst_from_memory(ctx->memory));
    code = gsapi_set_arg_encoding(lib, GS_ARG_ENCODING_UTF16LE);
    if (code != 0)
        return code;
    code = gsapi_init_with_args(lib, 2*argc, (char **)argv);
    gs_main_inst_arg_decode(get_minst_from_memory(ctx->memory), old);
    return code;
#endif
}
Exemple #6
0
GSDLLEXPORT int GSDLLAPI
gsapi_run_fileW(void *lib, const wchar_t *file_name,
        int user_errors, int *pexit_code)
{
#ifdef GS_NO_UTF8
    /* Cannot call the W entrypoints in a GS_NO_UTF8 build */
    return gs_error_Fatal;
#else
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    int code;
    gs_arg_get_codepoint *old;
    if (lib == NULL)
        return gs_error_Fatal;

    old = gs_main_inst_get_arg_decode(get_minst_from_memory(ctx->memory));
    code = gsapi_set_arg_encoding(lib, GS_ARG_ENCODING_UTF16LE);
    if (code != 0)
        return code;
    code = gsapi_run_file(lib, (const char *)file_name, user_errors, pexit_code);
    gs_main_inst_arg_decode(get_minst_from_memory(ctx->memory), old);
    return code;
#endif
}