summaryrefslogtreecommitdiff
path: root/gs/src/ziodev2.c
blob: 7819fe87b0b1b2273479b0cf7bf29e9849324100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Copyright (C) 1993, 1994, 1996 Aladdin Enterprises.  All rights reserved.
  
  This file is part of Aladdin Ghostscript.
  
  Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  or distributor accepts any responsibility for the consequences of using it,
  or for whether it serves any particular purpose or works at all, unless he
  or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  License (the "License") for full details.
  
  Every copy of Aladdin Ghostscript must include a copy of the License,
  normally in a plain ASCII text file named PUBLIC.  The License grants you
  the right to copy, modify and redistribute Aladdin Ghostscript, but only
  under certain conditions described in the License.  Among other things, the
  License requires that the copyright notice and this notice be preserved on
  all copies.
*/

/* ziodev2.c */
/* (Level 2) IODevice operators */
#include "string_.h"
#include "ghost.h"
#include "gp.h"
#include "errors.h"
#include "oper.h"
#include "stream.h"
#include "gxiodev.h"
#include "files.h"				/* for file_open_stream */
#include "iparam.h"
#include "iutil2.h"
#include "store.h"

/* ------ %null% ------ */

/* This represents the null output file. */
private iodev_proc_open_device(null_open);
gx_io_device gs_iodev_null =
  { "%null%", "FileSystem",
     { iodev_no_init, null_open, iodev_no_open_file,
       iodev_os_fopen, iodev_os_fclose,
       iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
       iodev_no_enumerate_files, NULL, NULL,
       iodev_no_get_params, iodev_no_put_params
     }
  };

private int
null_open(gx_io_device *iodev, const char *access, stream **ps,
  gs_memory_t *mem)
{	if ( !streq1(access, 'w') )
		return_error(e_invalidfileaccess);
	return file_open_stream(gp_null_file_name,
				strlen(gp_null_file_name),
				access, 256 /* arbitrary */, ps,
				iodev->procs.fopen);
}

/* ------ %ram% ------ */

/* This is an IODevice with no interesting parameters for the moment. */
gx_io_device gs_iodev_ram =
  { "%ram%", "Special",
     { iodev_no_init, iodev_no_open_device, iodev_no_open_file,
       iodev_no_fopen, iodev_no_fclose,
       iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
       iodev_no_enumerate_files, NULL, NULL,
       iodev_no_get_params, iodev_no_put_params
     }
  };

/* ------ Operators ------ */

/* <iodevice> .getdevparams <mark> <name> <value> ... */
private int
zgetdevparams(os_ptr op)
{
	gx_io_device *iodev;
	stack_param_list list;
	int code;
	ref *pmark;

	check_read_type(*op, t_string);
	iodev = gs_findiodevice(op->value.bytes, r_size(op));
	if ( iodev == 0 )
	  return_error(e_undefinedfilename);
	stack_param_list_write(&list, &o_stack, NULL);
#define plist ((gs_param_list *)&list)

	code = gs_getdevparams(iodev, plist);
	if (code < 0)
	{	ref_stack_pop(&o_stack, list.count * 2);
		return code;
	}
#undef plist
	pmark = ref_stack_index(&o_stack, list.count * 2);
	make_mark(pmark);
	return 0;
}

/* <mark> <name> <value> ... <iodevice> .putdevparams */
private int
zputdevparams(os_ptr op)
{	gx_io_device *iodev;
	stack_param_list list;
	int code;
	check_read_type(*op, t_string);
	iodev = gs_findiodevice(op->value.bytes, r_size(op));
	if ( iodev == 0 )
	  return_error(e_undefinedfilename);
	code = stack_param_list_read(&list, &o_stack, 1, NULL, false);
	if ( code < 0 )
	  return code;
#define plist ((gs_param_list *)&list)
	code = param_check_password(plist, &SystemParamsPassword);
	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;
#undef plist
	ref_stack_pop(&o_stack, list.count * 2 + 2);
	return 0;
}

/* ------ Initialization procedure ------ */

BEGIN_OP_DEFS(ziodev2_l2_op_defs) {
		op_def_begin_level2(),
	{"1.getdevparams", zgetdevparams},
	{"2.putdevparams", zputdevparams},
END_OP_DEFS(0) }