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 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */ 34 35 /** 36 ** The disk copy of the filter table: 37 **/ 38 39 /* 40 * There are 9 fields in the filter table (the first one is ignored). 41 */ 42 #define FL_MAX 9 43 # define FL_IGN 0 44 # define FL_PTYPS 1 45 # define FL_PRTRS 2 46 # define FL_ITYPS 3 47 # define FL_NAME 4 48 # define FL_OTYPS 5 49 # define FL_TYPE 6 50 # define FL_CMD 7 51 # define FL_TMPS 8 52 53 /* 54 * Various strings. 55 */ 56 #define FL_SEP ":" 57 #define FL_END "\n" 58 #define FL_FAST "fast" 59 #define FL_SLOW "slow" 60 61 /** 62 ** The internal copy of a filter as seen by the rest of the world: 63 **/ 64 65 typedef enum FILTERTYPE { 66 fl_none, 67 fl_fast, 68 fl_slow, 69 fl_both 70 } FILTERTYPE; 71 72 /* 73 * A (char **) list is an array of string pointers (char *) with 74 * a null pointer after the last item. 75 */ 76 typedef struct FILTER { 77 char * name; /* name of filter (redundant) */ 78 char * command; /* shell command (full path) */ 79 FILTERTYPE type; /* type of filter (fast/slow) */ 80 char ** printer_types; /* list of valid printer types */ 81 char ** printers; /* list of valid printers */ 82 char ** input_types; /* list of valid input types */ 83 char ** output_types; /* list of valid output types */ 84 char ** templates; /* list of option templates */ 85 } FILTER; 86 87 /** 88 ** The internal copy of a filter as seen by the filter routines: 89 **/ 90 91 /* 92 * To speed up processing the filter table, FL_MAX_GUESS slots 93 * will be preallocated for the internal copy. If filter tables 94 * are expected to be substantially larger than this, bump it up. 95 */ 96 #define FL_MAX_GUESS 10 97 98 typedef struct TYPE { 99 char * name; 100 unsigned short info; /* 1 iff "name" is in Terminfo */ 101 } TYPE; 102 103 #define PATT_STAR "*" 104 105 typedef struct TEMPLATE { 106 char * keyword; 107 char * pattern; 108 char * re; 109 char * result; 110 int nbra; 111 } TEMPLATE; 112 113 /* 114 * A (TYPE *) list is an array of content-types (TYPE) with a null 115 * "name" element. A (TEMPLATE *) list is an array of templates (TEMPLATE) 116 * with a null "keyword" element. 117 */ 118 typedef struct _FILTER { 119 struct _FILTER * next; /* for linking several */ 120 char * name; 121 char * command; 122 char ** printers; 123 TYPE * printer_types; 124 TYPE * input_types; /* all possible choices */ 125 TYPE * output_types; /* all possible choices */ 126 TYPE * inputp; /* the one to be used */ 127 TYPE * outputp; /* the one to be used */ 128 TEMPLATE * templates; 129 FILTERTYPE type; 130 unsigned char mark, 131 level; 132 } _FILTER; 133 134 #define FL_CLEAR 0x00 135 #define FL_SKIP 0x01 136 #define FL_LEFT 0x02 137 #define FL_RIGHT 0x04 138 139 #define PARM_INPUT "INPUT" 140 #define PARM_OUTPUT "OUTPUT" 141 #define PARM_TERM "TERM" 142 #define PARM_PRINTER "PRINTER" 143 144 #define NPARM_SPEC 8 145 # define PARM_CPI "CPI" 146 # define PARM_LPI "LPI" 147 # define PARM_LENGTH "LENGTH" 148 # define PARM_WIDTH "WIDTH" 149 # define PARM_PAGES "PAGES" 150 # define PARM_CHARSET "CHARSET" 151 # define PARM_FORM "FORM" 152 # define PARM_COPIES "COPIES" 153 154 #define PARM_MODES "MODES" 155 156 #define FPARM_CPI 0x0001 157 #define FPARM_LPI 0x0002 158 #define FPARM_LENGTH 0x0004 159 #define FPARM_WIDTH 0x0008 160 #define FPARM_PAGES 0x0010 161 #define FPARM_CHARSET 0x0020 162 #define FPARM_FORM 0x0040 163 #define FPARM_COPIES 0x0080 164 #define FPARM_MODES 0x0100 165 166 /** 167 ** Various routines. 168 **/ 169 170 /* 171 * Null terminated list (filters[i].name == NULL). 172 */ 173 extern _FILTER *filters; 174 175 extern size_t nfilters; 176 177 #if defined(__STDC__) 178 179 FILTER * getfilter ( char * ); 180 181 _FILTER * search_filter ( char * ); 182 183 FILTERTYPE insfilter ( char ** , char * , char * , char * , char * , char ** , unsigned short * ); 184 FILTERTYPE s_to_filtertype ( char * ); 185 186 TEMPLATE s_to_template ( char * ); 187 188 TEMPLATE * sl_to_templatel ( char ** ); 189 190 TYPE s_to_type ( char * ); 191 192 TYPE * sl_to_typel ( char ** ); 193 194 char * template_to_s ( TEMPLATE ); 195 char * type_to_s ( TYPE ); 196 197 char ** templatel_to_sl ( TEMPLATE * ); 198 char ** typel_to_sl ( TYPE * ); 199 200 int open_filtertable ( char * , char * ); 201 202 int get_and_load ( void ); 203 int putfilter ( char * , FILTER * ); 204 int delfilter ( char * ); 205 int loadfilters ( char * ); 206 int dumpfilters( char * ); 207 208 void freetempl ( TEMPLATE * ); 209 void freefilter ( FILTER * ); 210 void free_filter ( _FILTER * ); 211 void trash_filters ( void ); 212 void close_filtertable ( FILE * ); 213 214 #else 215 216 extern FILTER *getfilter(); 217 218 extern _FILTER *search_filter(); 219 220 extern FILTERTYPE insfilter(), 221 s_to_filtertype(); 222 223 extern TYPE s_to_type(), 224 *sl_to_typel(); 225 226 extern TEMPLATE s_to_template(), 227 *sl_to_templatel(); 228 229 #if defined(BUFSIZ) 230 extern FILE *open_filtertable(); 231 #endif 232 233 extern char **typel_to_sl(), 234 **templatel_to_sl(), 235 *getfilterfile(); 236 237 extern int putfilter(), 238 delfilter(), 239 loadfilters(), 240 get_and_load(); 241 242 extern void freefilter(), 243 free_filter(), 244 freetempl(), 245 trash_filters(), 246 close_filtertable(); 247 248 #endif 249