Exemplo n.º 1
0
Arquivo: gs.c Projeto: 99years/plan9
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;
}
Exemplo n.º 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);
}
Exemplo n.º 3
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 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;
}
Exemplo n.º 4
0
/* 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;
}