예제 #1
0
파일: ziodev2.c 프로젝트: hackqiang/gs
/* <mark> <name> <value> ... <iodevice> .putdevparams */
static int
zputdevparams(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gx_io_device *iodev;
    stack_param_list list;
    gs_param_list *const plist = (gs_param_list *) & list;
    int code;
    password system_params_password;

    check_read_type(*op, t_string);
    iodev = gs_findiodevice(imemory, op->value.bytes, r_size(op));
    if (iodev == 0)
        return_error(e_undefined);
    code = stack_param_list_read(&list, &o_stack, 1, NULL, false, iimemory);
    if (code < 0)
        return code;
    code = dict_read_password(&system_params_password, systemdict,
                              "SystemParamsPassword");
    if (code < 0)
        return code;
    code = param_check_password(plist, &system_params_password);
    if (code != 0) {
        iparam_list_release(&list);
        return_error(code < 0 ? code : e_invalidaccess);
    }
    code = gs_putdevparams(iodev, plist);
    iparam_list_release(&list);
    if (code < 0)
        return code;
    ref_stack_pop(&o_stack, list.count * 2 + 2);
    return 0;
}
예제 #2
0
/* Patch stdin/out/err to use our windows. */
static void
mac_std_init(void)
{
    /* If stdxxx is the console, replace the 'open' routines, */
    /* which haven't gotten called yet. */

//    if (gp_file_is_console(gs_stdin))
        gs_findiodevice((const byte *)"%stdin", 6)->procs.open_device =
            mac_stdin_open;

//    if (gp_file_is_console(gs_stdout))
        gs_findiodevice((const byte *)"%stdout", 7)->procs.open_device =
            mac_stdout_open;

//    if (gp_file_is_console(gs_stderr))
        gs_findiodevice((const byte *)"%stderr", 7)->procs.open_device =
            mac_stderr_open;
}
예제 #3
0
/* This is the public routine for getting the stderr stream. */
int
zget_stderr(i_ctx_t *i_ctx_p, stream ** ps)
{
    stream *s;
    gx_io_device *iodev;
    int code;

    if (file_is_valid(s, &ref_stderr)) {
	*ps = s;
	return 0;
    }
    iodev = gs_findiodevice((const byte *)"%stderr", 7);
    iodev->state = i_ctx_p;
    code = (*iodev->procs.open_device)(iodev, "w", ps, imemory_system);
    iodev->state = NULL;
    return min(code, 0);
}
예제 #4
0
파일: ziodev2.c 프로젝트: hackqiang/gs
/* <iodevice> .getdevparams <mark> <name> <value> ... */
static int
zgetdevparams(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gx_io_device *iodev;
    stack_param_list list;
    gs_param_list *const plist = (gs_param_list *) & list;
    int code;
    ref *pmark;

    check_read_type(*op, t_string);
    iodev = gs_findiodevice(imemory, op->value.bytes, r_size(op));
    if (iodev == 0)
        return_error(e_undefined);
    stack_param_list_write(&list, &o_stack, NULL, iimemory);
    if ((code = gs_getdevparams(iodev, plist)) < 0) {
        ref_stack_pop(&o_stack, list.count * 2);
        return code;
    }
    pmark = ref_stack_index(&o_stack, list.count * 2);
    make_mark(pmark);
    return 0;
}
/* are equivalent; both return name==NULL. */
int
parse_file_name(const ref *op, parsed_file_name *pfn)
{   const byte *pname;
    uint len, dlen;
    const byte *pdelim;
    gx_io_device *iodev;

    check_read_type(*op, t_string);
    len = r_size(op);
    pname = op->value.const_bytes;
    if ( len == 0 )
        return_error(e_undefinedfilename);
    if ( pname[0] != '%' )	/* no device */
    {   pfn->iodev = NULL;
        pfn->fname = (const char *)pname;
        pfn->len = len;
        return 0;
    }
    pdelim = (const byte *)memchr(pname + 1, '%', len - 1);
    if ( pdelim == NULL )	/* %device */
        dlen = len;
    else if ( pdelim[1] == 0 ) /* %device% */
    {   pdelim = NULL;
        dlen = len;
    }
    else
    {   dlen = pdelim - pname;
        pdelim++, len--;
    }
    iodev = gs_findiodevice(pname, dlen);
    if ( iodev == 0 )
        return_error(e_undefinedfilename);
    pfn->iodev = iodev;
    pfn->fname = (const char *)pdelim;
    pfn->len = len - dlen;
    return 0;
}
예제 #6
0
/* are equivalent; both return name==NULL. */
int
gs_parse_file_name(gs_parsed_file_name_t * pfn, const char *pname,
                   uint len)
{
    uint dlen;
    const char *pdelim;
    gx_io_device *iodev;

    if (len == 0)
	return_error(gs_error_undefinedfilename); /* null name not allowed */
    if (pname[0] != '%') {	/* no device */
	pfn->memory = 0;
	pfn->iodev = NULL;
	pfn->fname = pname;
	pfn->len = len;
	return 0;
    }
    pdelim = memchr(pname + 1, '%', len - 1);
    if (pdelim == NULL)		/* %device */
	dlen = len;
    else if (pdelim[1] == 0) {	/* %device% */
	pdelim = NULL;
	dlen = len;
    } else {
	dlen = pdelim - pname;
	pdelim++, len--;
    }
    iodev = gs_findiodevice((const byte *)pname, dlen);
    if (iodev == 0)
	return_error(gs_error_undefinedfilename);
    pfn->memory = 0;
    pfn->iodev = iodev;
    pfn->fname = pdelim;
    pfn->len = len - dlen;
    return 0;
}
예제 #7
0
/* <name_string> <access_string> file <file> */
int				/* exported for zsysvm.c */
zfile(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    char file_access[4];
    gs_parsed_file_name_t pname;
    int code = parse_file_access_string(op, file_access);
    stream *s;

    if (code < 0)
	return code;
    code = parse_file_name(op - 1, &pname, i_ctx_p->LockFilePermissions);
    if (code < 0)
	return code;
	/*
	 * HACK: temporarily patch the current context pointer into the
	 * state pointer for stdio-related devices.  See ziodev.c for
	 * more information.
	 */
    if (pname.iodev && pname.iodev->dtype == iodev_dtype_stdio) {
	bool statement = (strcmp(pname.iodev->dname, "%statementedit%") == 0);
	bool lineedit = (strcmp(pname.iodev->dname, "%lineedit%") == 0);
	if (pname.fname)
	    return_error(e_invalidfileaccess);
	if (statement || lineedit) {
	    /* These need special code to support callouts */
	    gx_io_device *indev = gs_findiodevice((const byte *)"%stdin", 6);
	    stream *ins;
	    if (strcmp(file_access, "r"))
		return_error(e_invalidfileaccess);
	    indev->state = i_ctx_p;
	    code = (indev->procs.open_device)(indev, file_access, &ins, imemory);
	    indev->state = 0;
	    if (code < 0)
		return code;
	    check_ostack(2);
	    push(2);
	    make_stream_file(op - 3, ins, file_access);
	    make_bool(op-2, statement);
	    make_int(op-1, 0);
	    make_string(op, icurrent_space, 0, NULL);
	    return zfilelineedit(i_ctx_p);
	}
	pname.iodev->state = i_ctx_p;
	code = (*pname.iodev->procs.open_device)(pname.iodev,
						 file_access, &s, imemory);
	pname.iodev->state = NULL;
    } else {
	if (pname.iodev == NULL)
	    pname.iodev = iodev_default;
	code = zopen_file(i_ctx_p, &pname, file_access, &s, imemory);
    }
    if (code < 0)
	return code;
    code = ssetfilename(s, op[-1].value.const_bytes, r_size(op - 1));
    if (code < 0) {
	sclose(s);
	return_error(e_VMerror);
    }
    make_stream_file(op - 1, s, file_access);
    pop(1);
    return code;
}