386BSD 0.1 development
[unix-history] / usr / othersrc / public / ghostscript-2.4.1 / zfilter2.c
CommitLineData
82f88cbd
WJ
1/* Copyright (C) 1991 Aladdin Enterprises. All rights reserved.
2 Distributed by Free Software Foundation, Inc.
3
4This file is part of Ghostscript.
5
6Ghostscript is distributed in the hope that it will be useful, but
7WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
8to anyone for the consequences of using it or for whether it serves any
9particular purpose or works at all, unless he says so in writing. Refer
10to the Ghostscript General Public License for full details.
11
12Everyone is granted permission to copy, modify and redistribute
13Ghostscript, but only under the conditions described in the Ghostscript
14General Public License. A copy of this license is supposed to have been
15given to you along with Ghostscript so you can know your rights and
16responsibilities. It should be in a file named COPYING. Among other
17things, the copyright notice and this notice must be preserved on all
18copies. */
19
20/* zfilter2.c */
21/* Additional filter creation for Ghostscript */
22#include "ghost.h"
23#include "errors.h"
24#include "oper.h"
25#include "alloc.h"
26#include "stream.h"
27
28/* Imported from zfilter.c */
29int filter_read(P3(os_ptr, stream_procs _ds *, stream **));
30int filter_write(P3(os_ptr, stream_procs _ds *, stream **));
31
32/* .filterASCII85Encode */
33extern stream_procs s_A85E_procs;
34int
35zA85E(os_ptr op)
36{ return filter_write(op, &s_A85E_procs, NULL);
37}
38
39/* .filterASCII85Decode */
40extern stream_procs s_A85D_procs;
41int
42zA85D(os_ptr op)
43{ return filter_read(op, &s_A85D_procs, NULL);
44}
45
46/* .filterNullEncode */
47extern stream_procs s_NullE_procs;
48int
49zNullE(os_ptr op)
50{ return filter_write(op, &s_NullE_procs, NULL);
51}
52
53/* .filterRunLengthEncode */
54#if 0 /* ****** */
55extern stream_procs s_RLE_procs;
56extern void s_RLE_init(P2(stream *, uint));
57int
58zRLE(register os_ptr op)
59{ stream *s;
60 int code;
61 check_type(*op, t_integer);
62 if ( (ulong)(op->value.intval) > max_uint )
63 return e_rangecheck;
64 code = filter_write(op - 1, &s_RLE_procs, &s);
65 if ( code < 0 ) return code;
66 s_RLE_init(s, (uint)(op->value.intval));
67 pop(1);
68 return 0;
69}
70#endif /* ****** */
71
72/* .filterRunLengthDecode */
73#if 0 /* ****** */
74extern stream_procs s_RLD_procs;
75extern void s_RLD_init(P1(stream *));
76int
77zRLD(os_ptr op)
78{ stream *s;
79 int code = filter_write(op, &s_RLD_procs, &s);
80 if ( code < 0 ) return code;
81 s_RLD_init(s);
82 return 0;
83}
84#endif /* ****** */
85
86/* .filterSubFileDecode */
87/****** Only implemented for null case (count=0, null string) ******/
88extern stream_procs s_SFD_procs;
89int
90zSFD(os_ptr op)
91{ int code;
92 check_type(op[-1], t_integer);
93 check_type(*op, t_string);
94 if ( op[-1].value.intval < 0 ) return e_rangecheck;
95 if ( op[-1].value.intval != 0 || r_size(op) != 0 )
96 return e_undefined; /* NYI */
97 code = filter_read(op - 2, &s_SFD_procs, NULL);
98 if ( code < 0 ) return code;
99 pop(2);
100 return 0;
101}
102
103/* ------ Initialization procedure ------ */
104
105op_def zfilter2_op_defs[] = {
106 {"1.filterASCII85Encode", zA85E},
107 {"1.filterASCII85Decode", zA85D},
108 {"1.filterNullEncode", zNullE},
109#if 0 /* ****** */
110 {"2.filterRunLengthEncode", zRLE},
111 {"1.filterRunLengthDecode", zRLD},
112#endif /* ****** */
113 {"1.filterSubFileDecode", zSFD},
114 op_def_end(0)
115};