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