xref: /illumos-gate/usr/src/cmd/lp/include/filters.h (revision 2a8bcb4e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
32 
33 /**
34  ** The disk copy of the filter table:
35  **/
36 
37 /*
38  * There are 9 fields in the filter table (the first one is ignored).
39  */
40 #define	FL_MAX	9
41 # define FL_IGN		0
42 # define FL_PTYPS	1
43 # define FL_PRTRS	2
44 # define FL_ITYPS	3
45 # define FL_NAME	4
46 # define FL_OTYPS	5
47 # define FL_TYPE	6
48 # define FL_CMD		7
49 # define FL_TMPS	8
50 
51 /*
52  * Various strings.
53  */
54 #define FL_SEP		":"
55 #define FL_END		"\n"
56 #define	FL_FAST		"fast"
57 #define	FL_SLOW		"slow"
58 
59 /**
60  ** The internal copy of a filter as seen by the rest of the world:
61  **/
62 
63 typedef enum FILTERTYPE {
64 	fl_none,
65 	fl_fast,
66 	fl_slow,
67 	fl_both
68 }			FILTERTYPE;
69 
70 /*
71  * A (char **) list is an array of string pointers (char *) with
72  * a null pointer after the last item.
73  */
74 typedef struct FILTER {
75 	char *		name;		/* name of filter (redundant) */
76 	char *		command;	/* shell command (full path) */
77 	FILTERTYPE	type;		/* type of filter (fast/slow) */
78 	char **		printer_types;	/* list of valid printer types */
79 	char **		printers;	/* list of valid printers */
80 	char **		input_types;	/* list of valid input types */
81 	char **		output_types;	/* list of valid output types */
82 	char **		templates;	/* list of option templates */
83 }			FILTER;
84 
85 /**
86  ** The internal copy of a filter as seen by the filter routines:
87  **/
88 
89 /*
90  * To speed up processing the filter table, FL_MAX_GUESS slots
91  * will be preallocated for the internal copy. If filter tables
92  * are expected to be substantially larger than this, bump it up.
93  */
94 #define FL_MAX_GUESS	10
95 
96 typedef struct TYPE {
97 	char *			name;
98 	unsigned short		info;	/* 1 iff "name" is in Terminfo */
99 }			TYPE;
100 
101 #define	PATT_STAR	"*"
102 
103 typedef struct TEMPLATE {
104 	char *			keyword;
105 	char *			pattern;
106 	char *			re;
107 	char *			result;
108 	int			nbra;
109 }			TEMPLATE;
110 
111 /*
112  * A (TYPE *) list is an array of content-types (TYPE) with a null
113  * "name" element. A (TEMPLATE *) list is an array of templates (TEMPLATE)
114  * with a null "keyword" element.
115  */
116 typedef struct _FILTER {
117 	struct _FILTER *	next;		/* for linking several */
118 	char *			name;
119 	char *			command;
120 	char **			printers;
121 	TYPE *			printer_types;
122 	TYPE *			input_types;	/* all possible choices */
123 	TYPE *			output_types;	/* all possible choices */
124 	TYPE *			inputp;		/* the one to be used */
125 	TYPE *			outputp;	/* the one to be used */
126 	TEMPLATE *		templates;
127 	FILTERTYPE		type;
128 	unsigned char		mark,
129 				level;
130 }			_FILTER;
131 
132 #define	FL_CLEAR	0x00
133 #define	FL_SKIP		0x01
134 #define	FL_LEFT		0x02
135 #define	FL_RIGHT	0x04
136 
137 #define PARM_INPUT	"INPUT"
138 #define PARM_OUTPUT	"OUTPUT"
139 #define PARM_TERM	"TERM"
140 #define PARM_PRINTER	"PRINTER"
141 
142 #define NPARM_SPEC	8
143 # define PARM_CPI	"CPI"
144 # define PARM_LPI	"LPI"
145 # define PARM_LENGTH	"LENGTH"
146 # define PARM_WIDTH	"WIDTH"
147 # define PARM_PAGES	"PAGES"
148 # define PARM_CHARSET	"CHARSET"
149 # define PARM_FORM	"FORM"
150 # define PARM_COPIES	"COPIES"
151 
152 #define PARM_MODES	"MODES"
153 
154 #define FPARM_CPI	0x0001
155 #define FPARM_LPI	0x0002
156 #define FPARM_LENGTH	0x0004
157 #define FPARM_WIDTH	0x0008
158 #define FPARM_PAGES	0x0010
159 #define FPARM_CHARSET	0x0020
160 #define FPARM_FORM	0x0040
161 #define FPARM_COPIES	0x0080
162 #define FPARM_MODES	0x0100
163 
164 /**
165  ** Various routines.
166  **/
167 
168 /*
169  * Null terminated list (filters[i].name == NULL).
170  */
171 extern _FILTER		*filters;
172 
173 extern size_t		nfilters;
174 
175 #if	defined(__STDC__)
176 
177 FILTER *	getfilter ( char * );
178 
179 _FILTER *	search_filter ( char * );
180 
181 FILTERTYPE	insfilter ( char ** , char * , char * , char * , char * , char ** , unsigned short * );
182 FILTERTYPE	s_to_filtertype ( char * );
183 
184 TEMPLATE	s_to_template ( char * );
185 
186 TEMPLATE *	sl_to_templatel ( char ** );
187 
188 TYPE		s_to_type ( char * );
189 
190 TYPE *		sl_to_typel ( char ** );
191 
192 char *		template_to_s ( TEMPLATE );
193 char *		type_to_s ( TYPE );
194 
195 char **		templatel_to_sl ( TEMPLATE * );
196 char **		typel_to_sl ( TYPE * );
197 
198 int		open_filtertable ( char * , char * );
199 
200 int		get_and_load ( void );
201 int		putfilter ( char * , FILTER * );
202 int		delfilter ( char * );
203 int		loadfilters ( char * );
204 int		dumpfilters( char * );
205 
206 void		freetempl ( TEMPLATE * );
207 void		freefilter ( FILTER * );
208 void		free_filter ( _FILTER * );
209 void		trash_filters ( void );
210 void		close_filtertable ( FILE * );
211 
212 #else
213 
214 extern FILTER		*getfilter();
215 
216 extern _FILTER		*search_filter();
217 
218 extern FILTERTYPE	insfilter(),
219 			s_to_filtertype();
220 
221 extern TYPE		s_to_type(),
222 			*sl_to_typel();
223 
224 extern TEMPLATE		s_to_template(),
225 			*sl_to_templatel();
226 
227 #if	defined(BUFSIZ)
228 extern FILE		*open_filtertable();
229 #endif
230 
231 extern char		**typel_to_sl(),
232 			**templatel_to_sl(),
233 			*getfilterfile();
234 
235 extern int		putfilter(),
236 			delfilter(),
237 			loadfilters(),
238 			get_and_load();
239 
240 extern void		freefilter(),
241 			free_filter(),
242 			freetempl(),
243 			trash_filters(),
244 			close_filtertable();
245 
246 #endif
247