]>
git.saurik.com Git - apple/libc.git/blob - gen/getttyent.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1989, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 #include "xlocale_private.h"
71 register struct ttyent
*t
;
74 while (t
= getttyent())
75 if (!strcmp(tty
, t
->ty_name
))
81 static char *skip(), *value();
86 static struct ttyent tty
;
89 #define MAXLINELENGTH 1024
90 static char *line
= NULL
;
91 locale_t loc
= __current_locale();
94 line
= malloc(MAXLINELENGTH
);
99 if (!tf
&& !setttyent())
102 if (!fgets(p
= line
, MAXLINELENGTH
, tf
))
104 /* skip lines that are too big */
105 if (!index(p
, '\n')) {
106 while ((c
= getc(tf
)) != '\n' && c
!= EOF
)
110 while (isspace_l(*p
, loc
))
119 if (!*(tty
.ty_getty
= p
))
120 tty
.ty_getty
= tty
.ty_type
= NULL
;
123 if (!*(tty
.ty_type
= p
))
129 tty
.ty_window
= NULL
;
130 tty
.ty_onerror
= NULL
;
131 tty
.ty_onoption
= NULL
;
133 #define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace_l(p[sizeof(e) - 1], loc)
134 #define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
135 for (; *p
; p
= skip(p
)) {
137 tty
.ty_status
&= ~TTY_ON
;
138 else if (scmp(_TTYS_ON
))
139 tty
.ty_status
|= TTY_ON
;
140 else if (scmp(_TTYS_SECURE
))
141 tty
.ty_status
|= TTY_SECURE
;
142 else if (vcmp(_TTYS_WINDOW
))
143 tty
.ty_window
= value(p
);
144 else if (vcmp(_TTYS_ONERROR
))
145 tty
.ty_onerror
= value(p
);
146 else if (vcmp(_TTYS_ONOPTION
))
147 tty
.ty_onoption
= value(p
);
152 if (zapchar
== '#' || *p
== '#')
153 while ((c
= *++p
) == ' ' || c
== '\t')
158 if (p
= index(p
, '\n'))
166 * Skip over the current field, removing quotes, and return a pointer to
176 for (q
= 0, t
= p
; (c
= *p
) != '\0'; p
++) {
178 q
^= QUOTED
; /* obscure, but nice */
181 if (q
== QUOTED
&& *p
== '\\' && *(p
+1) == '"')
191 if (c
== '\t' || c
== ' ' || c
== '\n') {
194 while ((c
= *p
) == '\t' || c
== ' ' || c
== '\n')
208 return ((p
= index(p
, '=')) ? ++p
: NULL
);
218 } else if (tf
= fopen(_PATH_TTYS
, "r"))
229 rval
= !(fclose(tf
) == EOF
);