* Copyright (c) 1991 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)map.c 5.2 (Berkeley) %G%";
int baudrate
__P((char *));
/* Baud rate conditionals for mapping. */
struct map
*next
; /* Linked list of maps. */
char *porttype
; /* Port type, or "" for any. */
char *type
; /* Terminal type to select. */
int conditional
; /* Baud rate conditionals bitmask. */
int speed
; /* Baud rate to compare against. */
* [port-type][test baudrate]:terminal-type
* The baud rate tests are: >, <, @, =, !
mapp
= malloc((u_int
)sizeof(MAP
));
if (copy
== NULL
|| mapp
== NULL
)
err("%s", strerror(errno
));
arg
= strpbrk(arg
, "><@=!:");
if (arg
== NULL
) { /* [?]term */
mapp
->type
= mapp
->porttype
;
if (arg
== mapp
->porttype
) /* [><@=! baud]:term */
termp
= mapp
->porttype
= NULL
;
for (;; ++arg
) /* Optional conditionals. */
if (mapp
->conditional
& GT
)
if (mapp
->conditional
& LT
)
case '=': /* Not documented. */
mapp
->conditional
|= NOT
;
} else { /* Optional baudrate. */
arg
= index(p
= arg
, ':');
mapp
->speed
= baudrate(p
);
if (*arg
== NULL
) /* Non-optional type. */
/* Terminate porttype, if specified. */
/* If a NOT conditional, reverse the test. */
if (mapp
->conditional
& NOT
)
mapp
->conditional
= ~mapp
->conditional
& (EQ
| GT
| LT
);
/* If user specified a port with an option flag, set it. */
badmopt
: err("illegal -m option format: %s", copy
);
(void)printf("port: %s\n", mapp
->porttype
? mapp
->porttype
: "ANY");
(void)printf("type: %s\n", mapp
->type
);
(void)printf("conditional: ");
if (mapp
->conditional
& GT
) {
if (mapp
->conditional
& EQ
) {
if (mapp
->conditional
& LT
)
(void)printf("\nspeed: %d\n", mapp
->speed
);
* Return the type of terminal to use for a port of type 'type', as specified
* by the first applicable mapping in 'map'. If no mappings apply, return
for (mapp
= maplist
; mapp
; mapp
= mapp
->next
)
if (mapp
->porttype
== NULL
|| !strcmp(mapp
->porttype
, type
)) {
switch (mapp
->conditional
) {
case 0: /* No test specified. */
match
= (ospeed
== mapp
->speed
);
match
= (ospeed
>= mapp
->speed
);
match
= (ospeed
> mapp
->speed
);
match
= (ospeed
<= mapp
->speed
);
match
= (ospeed
< mapp
->speed
);
/* No match found; return given type. */
/* The baudrate number can be preceded by a 'B', which is ignored. */
for (sp
= speeds
; sp
->string
; ++sp
)
if (!strcasecmp(rate
, sp
->string
))
err("unknown baud rate %s", rate
);