示例#1
0
/*
 * Activate all of the consoles listed in *string and disable all the others.
 */
static void
cons_change(const char *string)
{
    int		cons;
    char	*curpos, *dup, *next;

    /* Disable all consoles */
    for (cons = 0; consoles[cons] != NULL; cons++) {
	consoles[cons]->c_flags &= ~(C_ACTIVEIN | C_ACTIVEOUT);
    }

    /* Enable selected consoles */
    dup = next = strdup(string);
    while (next != NULL) {
	curpos = strsep(&next, " ,");
	if (*curpos == '\0')
		continue;
	cons = cons_find(curpos);
	if (cons >= 0) {
	    consoles[cons]->c_flags |= C_ACTIVEIN | C_ACTIVEOUT;
	    consoles[cons]->c_init(0);
	    if ((consoles[cons]->c_flags & (C_PRESENTIN | C_PRESENTOUT)) !=
		(C_PRESENTIN | C_PRESENTOUT))
		printf("console %s failed to initialize\n",
		    consoles[cons]->c_name);
	}
    }

    free(dup);
}
/*
 * Select a console.
 *
 * XXX Note that the console system design allows for some extension
 *     here (eg. multiple consoles, input/output only, etc.)
 */
static int
cons_set(struct env_var *ev, int flags, void *value)
{
    int		cons, active;

    if ((value == NULL) || ((active = cons_find(value)) == -1)) {
	if (value != NULL) 
	    printf("no such console '%s'\n", (char *)value);
	printf("Available consoles:\n");
	for (cons = 0; consoles[cons] != NULL; cons++)
	    printf("    %s\n", consoles[cons]->c_name);
	return(CMD_ERROR);
    }

    /* disable all current consoles */
    for (cons = 0; consoles[cons] != NULL; cons++)
	consoles[cons]->c_flags &= ~(C_ACTIVEIN | C_ACTIVEOUT);
    
    /* enable selected console */
    consoles[active]->c_flags |= C_ACTIVEIN | C_ACTIVEOUT;
    consoles[active]->c_init(0);

    env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
    return(CMD_OK);
}
示例#3
0
/*
 * Check that all of the consoles listed in *string are valid consoles
 */
static int
cons_check(const char *string)
{
    int		cons;
    char	*curpos, *dup, *next;

    dup = next = strdup(string);
    cons = -1;
    while (next != NULL) {
	curpos = strsep(&next, " ,");
	if (*curpos != '\0') {
	    cons = cons_find(curpos);
	    if (cons == -1)
		break;
	}
    }

    free(dup);
    return (cons);
}