1 /* $NetBSD: map.c,v 1.10 2003/08/07 11:16:48 agc Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)map.c 8.1 (Berkeley) 6/9/93";
37 __RCSID("$NetBSD: map.c,v 1.10 2003/08/07 11:16:48 agc Exp $");
40 #include <sys/types.h>
48 int baudrate
__P((char *));
50 /* Baud rate conditionals for mapping. */
59 struct map
*next
; /* Linked list of maps. */
60 const char *porttype
; /* Port type, or "" for any. */
61 const char *type
; /* Terminal type to select. */
62 int conditional
; /* Baud rate conditionals bitmask. */
63 int speed
; /* Baud rate to compare against. */
70 * [port-type][test baudrate]:terminal-type
71 * The baud rate tests are: >, <, @, =, !
74 add_mapping(port
, arg
)
79 char *copy
, *p
, *termp
;
82 mapp
= malloc((u_int
)sizeof(MAP
));
83 if (copy
== NULL
|| mapp
== NULL
)
94 mapp
->conditional
= 0;
96 arg
= strpbrk(arg
, "><@=!:");
98 if (arg
== NULL
) { /* [?]term */
99 mapp
->type
= mapp
->porttype
;
100 mapp
->porttype
= NULL
;
104 if (arg
== mapp
->porttype
) /* [><@=! baud]:term */
105 mapp
->porttype
= termp
= NULL
;
109 for (;; ++arg
) /* Optional conditionals. */
112 if (mapp
->conditional
& GT
)
114 mapp
->conditional
|= LT
;
117 if (mapp
->conditional
& LT
)
119 mapp
->conditional
|= GT
;
122 case '=': /* Not documented. */
123 mapp
->conditional
|= EQ
;
126 mapp
->conditional
|= NOT
;
132 next
: if (*arg
== ':') {
133 if (mapp
->conditional
)
136 } else { /* Optional baudrate. */
137 arg
= strchr(p
= arg
, ':');
141 mapp
->speed
= baudrate(p
);
144 if (*arg
== '\0') /* Non-optional type. */
149 /* Terminate porttype, if specified. */
153 /* If a NOT conditional, reverse the test. */
154 if (mapp
->conditional
& NOT
)
155 mapp
->conditional
= ~mapp
->conditional
& (EQ
| GT
| LT
);
157 /* If user specified a port with an option flag, set it. */
160 badmopt
: errx(1, "illegal -m option format: %s", copy
);
161 mapp
->porttype
= port
;
165 (void)printf("port: %s\n", mapp
->porttype
? mapp
->porttype
: "ANY");
166 (void)printf("type: %s\n", mapp
->type
);
167 (void)printf("conditional: ");
169 if (mapp
->conditional
& GT
) {
173 if (mapp
->conditional
& EQ
) {
174 (void)printf("%sEQ", p
);
177 if (mapp
->conditional
& LT
)
178 (void)printf("%sLT", p
);
179 (void)printf("\nspeed: %d\n", mapp
->speed
);
185 * Return the type of terminal to use for a port of type 'type', as specified
186 * by the first applicable mapping in 'map'. If no mappings apply, return
197 for (mapp
= maplist
; mapp
; mapp
= mapp
->next
)
198 if (mapp
->porttype
== NULL
|| !strcmp(mapp
->porttype
, type
)) {
199 switch (mapp
->conditional
) {
200 case 0: /* No test specified. */
204 match
= (ospeed
== mapp
->speed
);
207 match
= (ospeed
>= mapp
->speed
);
210 match
= (ospeed
> mapp
->speed
);
213 match
= (ospeed
<= mapp
->speed
);
216 match
= (ospeed
< mapp
->speed
);
222 /* No match found; return given type. */
231 /* The baudrate number can be preceded by a 'B', which is ignored. */