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/*
23 * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28/*	  All Rights Reserved  	*/
29
30
31#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
32/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
33
34#include "ctype.h"
35#include "string.h"
36#include "stdlib.h"
37#include "unistd.h"
38
39#include "lp.h"
40
41/**
42 ** isprinter() - SEE IF ARGUMENT IS A REAL PRINTER
43 **/
44
45int
46#if	defined(__STDC__)
47isprinter (
48	char *			str
49)
50#else
51isprinter (str)
52	char			*str;
53#endif
54{
55	char			*path	= 0;
56
57	int			bool;
58
59	bool = (
60		str
61	     && *str
62	     && (path = getprinterfile(str, CONFIGFILE))
63	     && Access(path, F_OK) == 0
64	);
65	if (path)
66		Free (path);
67	return (bool);
68}
69
70/**
71 ** isclass() - SEE IF ARGUMENT IS A REAL CLASS
72 **/
73
74int
75#if	defined(__STDC__)
76isclass (
77	char *			str
78)
79#else
80isclass (str)
81	char			*str;
82#endif
83{
84	char			*path	= 0;
85
86	int			bool;
87
88	bool = (
89		str
90	     && *str
91	     && (path = getclassfile(str))
92	     && Access(path, F_OK) == 0
93	);
94	if (path)
95		Free (path);
96	return (bool);
97}
98
99/**
100 ** isrequest() - SEE IF ARGUMENT LOOKS LIKE A REAL REQUEST
101 **/
102
103int
104#if	defined(__STDC__)
105isrequest (
106	char *			str
107)
108#else
109isrequest (str)
110	char			*str;
111#endif
112{
113	char			*dashp;
114
115	/*
116	 * Valid print requests have the form
117	 *
118	 *	dest-NNN
119	 *
120	 * where ``dest'' looks like a printer or class name.
121	 * An earlier version of this routine checked to see if
122	 * the ``dest'' was an EXISTING printer or class, but
123	 * that caused problems with valid requests moved from
124	 * a deleted printer or class (the request ID doesn't
125	 * change in the new LP).
126	 */
127
128	if (!str || !*str)
129		return (0);
130
131	if (!(dashp = strrchr(str, '-')))
132		return (0);
133
134	if (dashp == str)
135	    return(0);
136
137	*dashp = 0;
138	if (!syn_name(str)) {
139		*dashp = '-';
140		return (0);
141	}
142	*dashp++ = '-';
143
144	if (!isnumber(dashp))
145		return (0);
146
147	return (1);
148}
149
150int
151#if	defined(__STDC__)
152isnumber (
153	char *			s
154)
155#else
156isnumber (s)
157	char			*s;
158#endif
159{
160	register int		c;
161
162	if (!s || !*s)
163		return (0);
164	while ((c = *(s++)) != '\0')
165		if (!isdigit(c))
166			return (0);
167	return (1);
168}
169