pickfilter.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1996 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2.1.5 */
/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
#include "string.h"
#include "limits.h"
#include "lpsched.h"
#include "validate.h"
/*
* Transform consecutive "LP_SEP" characters to a single comma and n-1 LP_SEP;
*
* BUT we'll leave LP_SEP inside single quotes alone!
*
* This is to allow the following case (and the like) to work correctly:
* prtitle='standard input'
*/
void
transform_WS_to_SEP(char *cp)
{ char *p;
int inside_quote = 0;
int done_one_already = 0;
for (p = cp; *p != '\0'; p++) {
if (*p == '\'') {
continue;
}
if (inside_quote)
continue;
if (*p == ' ') {
if (!done_one_already) {
*p = ',';
done_one_already = 1;
} else {
/* multiple LP_WS into one LP_SEP */
}
} else {
done_one_already = 0;
}
}
}
/**
** pickfilter() - SEE IF WE CAN FIND A FILTER FOR THIS REQUEST
**/
int
{
register char ** pp;
register char ** pl;
char * pipes[2] = { 0 , 0 };
char * cp;
char * output_type;
char ** modes = 0;
char ** parms = 0;
char ** valid_printer_types;
char ** p_cpi = 0;
char ** p_lpi = 0;
char ** p_pwid = 0;
char ** p_plen = 0;
int got_cpi = 0;
int got_lpi = 0;
int got_plen = 0;
int got_pwid = 0;
int must_have_filter= 0;
unsigned long chk;
/* fix for bugid 1097387 */
output_type = (char *) NULL;
/*
* The bulk of the code below is building a parameter list "parms"
* to send to "insfilter()".
*/
}
);
/*
* characteristics (aka ``stuff'') that will be used for
* this job. The printer defaults are questionable.
* Take this opportunity to also save the ``stuff'' in
* the request structure.
*/
/*
* If a form is involved, pick up its page size and print
* spacing requirements.
*/
if (pfs) {
got_cpi = 1;
}
got_lpi = 1;
}
*pp++ = PARM_LENGTH;
got_plen = 1;
}
*pp++ = PARM_WIDTH;
got_pwid = 1;
}
/*
* If no form is involved, pick up whatever page size and print
* spacing requirements were given by the user.
*/
} else {
if (o_cpi) {
got_cpi = 1;
}
if (o_lpi) {
got_lpi = 1;
}
if (o_length) {
*pp++ = PARM_LENGTH;
got_plen = 1;
}
if (o_width) {
*pp++ = PARM_WIDTH;
got_pwid = 1;
}
}
/*
* Pick up whatever page size and print spacing requirements
* haven't been specified yet from the printer defaults.
*
* for at least one type of the printer at hand, but not
* necessarily all types. Once we pick a type that works
* The code that does that assumes that we do the following last,
* then the later code will have to be changed, too.
*/
}
}
*pp++ = PARM_LENGTH;
}
*pp++ = PARM_WIDTH;
}
/*
* Pick up the number of pages, character set (the form's
* or the user's), the form name, the number of copies,
* and the modes.
*/
*pp++ = PARM_PAGES;
must_have_filter = 1;
}
*pp++ = PARM_CHARSET;
*pp++ = PARM_CHARSET;
}
}
*pp++ = PARM_COPIES;
}
if (modes) {
*pp++ = PARM_MODES;
}
must_have_filter = 1;
}
*pp = 0; /* null terminated list! */
/*
* If the printer type(s) are not ``unknown'', then include
* them as possible ``output'' type(s) to match
* with the user's input type (directly, or through a filter).
*/
else {
valid_printer_types = 0;
must_have_filter = 0;
}
pc->output_type = 0;
/*
* If we don't really need a filter and the types match,
* then that's good enough. Some ``broadly defined''
* filters might match our needs, but if the printer
* can do what we need, then why pull in a filter?
* Besides, Section 3.40 in the requirements imply
* that we don't use a filter if the printer can handle
* the file.
*/
if (!must_have_filter ) {
if (
)
) {
} else if (
)
) {
/*
* (1) There is one printer type, might even
* be ``unknown'';
* (2) There are several printer types, but that
* means only one input type, ``simple'',
* which any of the printer types can handle.
*/
}
}
/*
* Don't try using a filter if the user doesn't want
* a filter to be used! He or she would rather see an
* error message than (heaven forbid!) a filter being
* used.
*/
/*
* For each printer type, and each input type the printer
* accepts, see if we have a filter that matches the
* request to the printer. Each time we try, save the
* output type we use in case of success; we just might
* need that value later....
*/
for (
pl++
)
(output_type = *pl),
*pl,
);
for (
pl++
)
/*
* Don't waste time with check we've already made.
*/
if ((must_have_filter == 1) ||
)
/*
* Either we have one (or less) printer
* types and many input types, or we have
* one input type, ``simple''; regardless,
* using the first printer type is OK.
*/
(output_type = *pl),
*(pc->printer_types),
);
}
/*
* If we were successful, check that the printer type
* (We know that ALL the printer's types can handle the stuff
* the user gave or the stuff in the form.)
* Each printer's default that doesn't pass muster gets dropped.
* This may mean re-instantiating the filter(s) (if any).
*/
#define NZ(X) ((X)? *(X) : (char *)0)
chk = chkprinter(
(char *)0
);
if (chk) {
register char ** _pp;
char * hole = "";
/*
* Remove the offending printer defaults from the
* (non-null!) holes in the parameter list.
*/
/*
* If there are filters, we have to re-instantiate
* them. (Can't check "ret" here, because it may
* be misleading.)
*/
/*
* First, close up the gaps we punched in
* the parameter list.
*/
*_pp = 0;
/*
* Re-instantiate the filter(s). This
* CAN'T fail, because it is not mandatory
*/
);
}
}
}
/*
* Save the filters, if any. Note: although "ret" can be
* misleading, i.e. set to "fl_both" when there really aren't
* any filters, the declaration of "pipes" ensured they'd be
* zero if not set.
*/
/*
* stuff, to make life easier above.
*/
if (parms)
if (modes)
}