Beispiel #1
0
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;
}
Beispiel #2
0
int
display_set_callback(gs_main_instance *minst, display_callback *callback)
{
    i_ctx_t *i_ctx_p;
    bool was_open;
    int code;
    int exit_code = 0;
    os_ptr op;
    gx_device *dev;
    gx_device_display *ddev;

    /* If display device exists, copy prototype if needed and return
     *  device true
     * If it doesn't exist, return
     *  false
     */
    const char getdisplay[] =
      "devicedict /display known dup { /display finddevice exch } if";
    code = gs_main_run_string(minst, getdisplay, 0, &exit_code,
        &minst->error_object);
    if (code < 0)
       return code;

    i_ctx_p = minst->i_ctx_p;	/* run_string may change i_ctx_p if GC */
    op = osp;
    check_type(*op, t_boolean);
    if (op->value.boolval) {
        /* display device was included in Ghostscript so we need
         * to set the callback structure pointer within it.
         * If the device is already open, close it before
         * setting callback, then reopen it.
         */
        check_read_type(op[-1], t_device);
        dev = op[-1].value.pdevice;

        was_open = dev->is_open;
        if (was_open) {
            code = gs_closedevice(dev);
            if (code < 0)
                return_error(code);
        }

        ddev = (gx_device_display *) dev;
        ddev->callback = callback;

        if (was_open) {
            code = gs_opendevice(dev);
            if (code < 0) {
                dprintf("**** Unable to open the display device, quitting.\n");
                return_error(code);
            }
        }
        pop(1);	/* device */
    }
    pop(1);	/* boolean */
    return 0;
}