loadfilters.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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
#include "stdio.h"
#include "string.h"
#include "errno.h"
#include "stdlib.h"
#include "unistd.h"
#include "lp.h"
#include "filters.h"
static int getfields (int, char *[], char *, int, int, char *);
static int fs_cmp(const void *, const void *);
/**
** loadfilters() - READ FILTERS FROM FILTER TABLE INTO INTERNAL STRUCTURE
**/
int
loadfilters(char *file)
{
int fd;
if (filters) {
trash_filters ();
} else
return (-1);
/*
* Preallocate space for the internal filter table.
* Our guess is the number of filters previously read in,
* if any have been read in before (see above).
*/
if (!filters) {
return (-1);
}
for (
pf++
) {
char **list;
/*
* Allocate more space if needed.
*/
);
if (!filters) {
return (-1);
}
}
/*
* Note the use of "" instead of LP_WS. The
* "sl_to_templatel()" routine will take care
* of stripping leading blanks. Stripping trailing
* blanks would be nice but shouldn't matter.
*/
/* quote reason #3 (in "getlist()") */
/* quote reason #4 (in "s_to_template()") */
}
if (errno != 0) {
int save_errno = errno;
free_filter (pf);
errno = save_errno;
return (-1);
}
/*
* If we have more space allocated than we need,
* return the extra.
*/
);
if (!filters) {
return (-1);
}
}
/*
* Sort the filters, putting ``fast'' filters before
* ``slow'' filters. This preps the list for "insfilter()"
* so that it can easily pick fast filters over otherwise
* equivalent slow filters. This sorting is done every
* time we read in the table; one might think that if
* "putfilter()" would insert in the correct order then
* the table, when written out to disk, would be sorted
* already--removing the need to sort it here. We don't
* take that approach, because (1) sorting it isn't that
* expensive and (2) someone might tamper with the table
* file.
*/
return (0);
}
/**
** getfields() - PARSE NON-COMMENT LINE FROM FILE INTO FIELDS
**/
static int
{
register char *p,
*q;
register int n = 0;
errno = 0;
if (*p && *p != '#') {
switch (eMode) {
case CHECK_LEAD_DBL_QUOTE: /* check for leading double quote */
if (*p == '"') {
p++;
break;
}
/* drop through to NORMAL_PARSING case */
case NORMAL_PARSING: /* default legacy editing */
if (*p == '\\') {
if (
/* quote reason #1 */ p[1] == '\\'
)
p++;
*q++ = *p++;
*q++ = 0;
p++;
if (n < max) {
fields[n++] = q;
}
} else
*q++ = *p++;
break;
case LITERAL_READ: /* read literally until another double quote */
if (*p == '\\' && p[1] == '"') { /* embedded double quote */
p++;
*q++ = *p++;
} else if (*p == '"') { /* end of literal read */
p++;
} else {
*q++ = *p++; /* capture as is */
}
break;
}
}
*q = 0;
while (n < max)
fields[n++] = "";
return (n);
}
}
return (-1);
}
/**
** fs_cmp() - COMPARE TWO FILTERS BY "FILTERTYPE"
**/
static int
{
return (0);
return (-1);
else
return (1);
}