xref: /illumos-gate/usr/src/cmd/lp/lib/lp/syntax.c (revision 3db86aab)
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.5	*/
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
33 
34 #include "ctype.h"
35 #include "string.h"
36 
37 #include "lp.h"
38 
39 int
40 #if	defined(__STDC__)
41 syn_name (
42 	char *			str
43 )
44 #else
45 syn_name (str)
46 	char			*str;
47 #endif
48 {
49 	register char		*p;
50 
51 	if (!str || !*str)
52 	  	return(0);
53 
54 	if (strlen(str) > (size_t) 14)
55 		return (0);
56 
57 	for (p = str; *p; p++)
58 		if (!isalnum(*p) && *p != '_' && *p != '-')
59 			return (0);
60 
61 	return (1);
62 }
63 
64 int
65 #if	defined(__STDC__)
66 syn_type (
67 	char *			str
68 )
69 #else
70 syn_type (str)
71 	char			*str;
72 #endif
73 {
74 	register char		*p;
75 
76 	if (!str)
77 		return(0);
78 
79 	if (strlen(str) > (size_t) 14)
80 		return (0);
81 
82 	for (p = str; *p; p++)
83 		if (!isalnum(*p) && *p != '-')
84 			return (0);
85 
86 	return (1);
87 }
88 
89 int
90 #if	defined(__STDC__)
91 syn_text (
92 	char *			str
93 )
94 #else
95 syn_text (str)
96 	char			*str;
97 #endif
98 {
99 	register char		*p;
100 
101 	if (!str)
102 		return(0);
103 
104 	for (p = str; *p; p++)
105 		if (!isgraph(*p) && *p != '\t' && *p != ' ')
106 			return (0);
107 
108 	return (1);
109 }
110 
111 int
112 #if	defined(__STDC__)
113 syn_comment (
114 	char *			str
115 )
116 #else
117 syn_comment (str)
118 	char			*str;
119 #endif
120 {
121 	register char		*p;
122 
123 	if (!str)
124 		return(0);
125 
126 	for (p = str; *p; p++)
127 		if (!isgraph(*p) && *p != '\t' && *p != ' ' && *p != '\n')
128 			return (0);
129 
130 	return (1);
131 }
132 
133 int
134 #if	defined(__STDC__)
135 syn_machine_name (
136 	char *			str
137 )
138 #else
139 syn_machine_name (str)
140 	char			*str;
141 #endif
142 {
143 	if (!str)
144 		return(0);
145 
146 	if (strlen(str) > (size_t) 8)
147 		return (0);
148 
149 	return (1);
150 }
151 
152 int
153 #if	defined(__STDC__)
154 syn_option (
155 	char *			str
156 )
157 #else
158 syn_option (str)
159 	char			*str;
160 #endif
161 {
162 	register char		*p;
163 
164 	if (!str)
165 		return(0);
166 
167 	for (p = str; *p; p++)
168 		if (!isprint(*p))
169 			return (0);
170 
171 	return (1);
172 }
173