From nobody Fri Oct 08 06:11:16 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C0EB912D4571; Fri, 8 Oct 2021 06:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HQd9x32qnz3Llg; Fri, 8 Oct 2021 06:11:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA5C722080; Fri, 8 Oct 2021 06:11:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1986BG9Y007848; Fri, 8 Oct 2021 06:11:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1986BGxa007847; Fri, 8 Oct 2021 06:11:16 GMT (envelope-from git) Date: Fri, 8 Oct 2021 06:11:16 GMT Message-Id: <202110080611.1986BGxa007847@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 12f9183eb7c7 - stable/12 - loader: cstyle cleanup of console.c List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 12f9183eb7c7d4247c485c79c4657cb1fcb165d2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=12f9183eb7c7d4247c485c79c4657cb1fcb165d2 commit 12f9183eb7c7d4247c485c79c4657cb1fcb165d2 Author: Toomas Soome AuthorDate: 2020-11-14 10:56:40 +0000 Commit: Kyle Evans CommitDate: 2021-10-08 05:24:28 +0000 loader: cstyle cleanup of console.c cstyle cleanup only, no functional changes intended. (cherry picked from commit 3e9f0f1d298f7f1e535831cdf697f5884a6d07dc) --- stand/common/console.c | 360 +++++++++++++++++++++++++------------------------ 1 file changed, 187 insertions(+), 173 deletions(-) diff --git a/stand/common/console.c b/stand/common/console.c index f4ffc563889c..5b2ddfb10f69 100644 --- a/stand/common/console.c +++ b/stand/common/console.c @@ -49,97 +49,102 @@ static int twiddle_set(struct env_var *ev, int flags, const void *value); void cons_probe(void) { - int cons; - int active; - char *prefconsole; - - /* We want a callback to install the new value when this var changes. */ - env_setenv("twiddle_divisor", EV_VOLATILE, "1", twiddle_set, env_nounset); - - /* Do all console probes */ - for (cons = 0; consoles[cons] != NULL; cons++) { - consoles[cons]->c_flags = 0; - consoles[cons]->c_probe(consoles[cons]); - } - /* Now find the first working one */ - active = -1; - for (cons = 0; consoles[cons] != NULL && active == -1; cons++) { - consoles[cons]->c_flags = 0; - consoles[cons]->c_probe(consoles[cons]); - if (consoles[cons]->c_flags == (C_PRESENTIN | C_PRESENTOUT)) - active = cons; - } - /* Force a console even if all probes failed */ - if (active == -1) - active = 0; + int cons; + int active; + char *prefconsole; - /* Check to see if a console preference has already been registered */ - prefconsole = getenv("console"); - if (prefconsole != NULL) - prefconsole = strdup(prefconsole); - if (prefconsole != NULL) { - unsetenv("console"); /* we want to replace this */ - cons_change(prefconsole); - } else { - consoles[active]->c_flags |= C_ACTIVEIN | C_ACTIVEOUT; - consoles[active]->c_init(0); - prefconsole = strdup(consoles[active]->c_name); - } - - printf("Consoles: "); - for (cons = 0; consoles[cons] != NULL; cons++) - if (consoles[cons]->c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) - printf("%s ", consoles[cons]->c_desc); - printf("\n"); - - if (prefconsole != NULL) { - env_setenv("console", EV_VOLATILE, prefconsole, cons_set, + /* We want a callback to install the new value when this var changes. */ + env_setenv("twiddle_divisor", EV_VOLATILE, "1", twiddle_set, env_nounset); - free(prefconsole); - } + + /* Do all console probes */ + for (cons = 0; consoles[cons] != NULL; cons++) { + consoles[cons]->c_flags = 0; + consoles[cons]->c_probe(consoles[cons]); + } + /* Now find the first working one */ + active = -1; + for (cons = 0; consoles[cons] != NULL && active == -1; cons++) { + consoles[cons]->c_flags = 0; + consoles[cons]->c_probe(consoles[cons]); + if (consoles[cons]->c_flags == (C_PRESENTIN | C_PRESENTOUT)) + active = cons; + } + /* Force a console even if all probes failed */ + if (active == -1) + active = 0; + + /* Check to see if a console preference has already been registered */ + prefconsole = getenv("console"); + if (prefconsole != NULL) + prefconsole = strdup(prefconsole); + if (prefconsole != NULL) { + unsetenv("console"); /* we want to replace this */ + cons_change(prefconsole); + } else { + consoles[active]->c_flags |= C_ACTIVEIN | C_ACTIVEOUT; + consoles[active]->c_init(0); + prefconsole = strdup(consoles[active]->c_name); + } + + printf("Consoles: "); + for (cons = 0; consoles[cons] != NULL; cons++) + if (consoles[cons]->c_flags & (C_ACTIVEIN | C_ACTIVEOUT)) + printf("%s ", consoles[cons]->c_desc); + printf("\n"); + + if (prefconsole != NULL) { + env_setenv("console", EV_VOLATILE, prefconsole, cons_set, + env_nounset); + free(prefconsole); + } } int getchar(void) { - int cons; - int rv; - - /* Loop forever polling all active consoles */ - for(;;) - for (cons = 0; consoles[cons] != NULL; cons++) - if ((consoles[cons]->c_flags & (C_PRESENTIN | C_ACTIVEIN)) == - (C_PRESENTIN | C_ACTIVEIN) && - ((rv = consoles[cons]->c_in()) != -1)) - return(rv); + int cons; + int rv; + + /* Loop forever polling all active consoles */ + for (;;) { + for (cons = 0; consoles[cons] != NULL; cons++) { + if ((consoles[cons]->c_flags & + (C_PRESENTIN | C_ACTIVEIN)) == + (C_PRESENTIN | C_ACTIVEIN) && + ((rv = consoles[cons]->c_in()) != -1)) + return (rv); + } + } } int ischar(void) { - int cons; - - for (cons = 0; consoles[cons] != NULL; cons++) - if ((consoles[cons]->c_flags & (C_PRESENTIN | C_ACTIVEIN)) == - (C_PRESENTIN | C_ACTIVEIN) && - (consoles[cons]->c_ready() != 0)) - return(1); - return(0); + int cons; + + for (cons = 0; consoles[cons] != NULL; cons++) + if ((consoles[cons]->c_flags & (C_PRESENTIN | C_ACTIVEIN)) == + (C_PRESENTIN | C_ACTIVEIN) && + (consoles[cons]->c_ready() != 0)) + return (1); + return (0); } void putchar(int c) { - int cons; + int cons; - /* Expand newlines */ - if (c == '\n') - putchar('\r'); + /* Expand newlines */ + if (c == '\n') + putchar('\r'); - for (cons = 0; consoles[cons] != NULL; cons++) - if ((consoles[cons]->c_flags & (C_PRESENTOUT | C_ACTIVEOUT)) == - (C_PRESENTOUT | C_ACTIVEOUT)) - consoles[cons]->c_out(c); + for (cons = 0; consoles[cons] != NULL; cons++) { + if ((consoles[cons]->c_flags & (C_PRESENTOUT | C_ACTIVEOUT)) == + (C_PRESENTOUT | C_ACTIVEOUT)) + consoles[cons]->c_out(c); + } } /* @@ -148,12 +153,12 @@ putchar(int c) static int cons_find(const char *name) { - int cons; + int cons; - for (cons = 0; consoles[cons] != NULL; cons++) - if (!strcmp(consoles[cons]->c_name, name)) - return (cons); - return (-1); + for (cons = 0; consoles[cons] != NULL; cons++) + if (strcmp(consoles[cons]->c_name, name) == 0) + return (cons); + return (-1); } /* @@ -162,22 +167,23 @@ cons_find(const char *name) static int cons_set(struct env_var *ev, int flags, const void *value) { - int ret; - - if ((value == NULL) || (cons_check(value) == 0)) { - /* - * Return CMD_OK instead of CMD_ERROR to prevent forth syntax error, - * which would prevent it processing any further loader.conf entries. - */ - return (CMD_OK); - } + int ret; + + if ((value == NULL) || (cons_check(value) == 0)) { + /* + * Return CMD_OK instead of CMD_ERROR to prevent forth syntax + * error, which would prevent it processing any further + * loader.conf entries. + */ + return (CMD_OK); + } - ret = cons_change(value); - if (ret != CMD_OK) - return (ret); + ret = cons_change(value); + if (ret != CMD_OK) + return (ret); - env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); - return (CMD_OK); + env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); + return (CMD_OK); } /* @@ -186,36 +192,36 @@ cons_set(struct env_var *ev, int flags, const void *value) static int cons_check(const char *string) { - int cons, found, failed; - char *curpos, *dup, *next; - - dup = next = strdup(string); - found = failed = 0; - while (next != NULL) { - curpos = strsep(&next, " ,"); - if (*curpos != '\0') { - cons = cons_find(curpos); - if (cons == -1) { - printf("console %s is invalid!\n", curpos); - failed++; - } else { - found++; - } + int cons, found, failed; + char *curpos, *dup, *next; + + dup = next = strdup(string); + found = failed = 0; + while (next != NULL) { + curpos = strsep(&next, " ,"); + if (*curpos != '\0') { + cons = cons_find(curpos); + if (cons == -1) { + printf("console %s is invalid!\n", curpos); + failed++; + } else { + found++; + } + } } - } - free(dup); + free(dup); - if (found == 0) - printf("no valid consoles!\n"); + if (found == 0) + printf("no valid consoles!\n"); - if (found == 0 || failed != 0) { - printf("Available consoles:\n"); - for (cons = 0; consoles[cons] != NULL; cons++) - printf(" %s\n", consoles[cons]->c_name); - } + if (found == 0 || failed != 0) { + printf("Available consoles:\n"); + for (cons = 0; consoles[cons] != NULL; cons++) + printf(" %s\n", consoles[cons]->c_name); + } - return (found); + return (found); } /* @@ -224,56 +230,64 @@ cons_check(const char *string) static int cons_change(const char *string) { - int cons, active; - 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); - active = 0; - 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)) { - active++; - continue; - } - - if (active != 0) { - /* If no consoles have initialised we wouldn't see this. */ - printf("console %s failed to initialize\n", consoles[cons]->c_name); - } - } - } + int cons, active; + char *curpos, *dup, *next; - free(dup); - - if (active == 0) { - /* All requested consoles failed to initialise, try to recover. */ + /* Disable all consoles */ for (cons = 0; consoles[cons] != NULL; cons++) { - 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)) - active++; + consoles[cons]->c_flags &= ~(C_ACTIVEIN | C_ACTIVEOUT); } - if (active == 0) - return (CMD_ERROR); /* Recovery failed. */ - } + /* Enable selected consoles */ + dup = next = strdup(string); + active = 0; + 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)) { + active++; + continue; + } + + if (active != 0) { + /* + * If no consoles have initialised we + * wouldn't see this. + */ + printf("console %s failed to initialize\n", + consoles[cons]->c_name); + } + } + } + + free(dup); + + if (active == 0) { + /* + * All requested consoles failed to initialise, + * try to recover. + */ + for (cons = 0; consoles[cons] != NULL; cons++) { + 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)) + active++; + } + + if (active == 0) + return (CMD_ERROR); /* Recovery failed. */ + } - return (CMD_OK); + return (CMD_OK); } /* @@ -287,16 +301,16 @@ cons_change(const char *string) static int twiddle_set(struct env_var *ev, int flags, const void *value) { - u_long tdiv; - char * eptr; - - tdiv = strtoul(value, &eptr, 0); - if (*(const char *)value == 0 || *eptr != 0) { - printf("invalid twiddle_divisor '%s'\n", (const char *)value); - return (CMD_ERROR); - } - twiddle_divisor((u_int)tdiv); - env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); - - return(CMD_OK); + u_long tdiv; + char *eptr; + + tdiv = strtoul(value, &eptr, 0); + if (*(const char *)value == 0 || *eptr != 0) { + printf("invalid twiddle_divisor '%s'\n", (const char *)value); + return (CMD_ERROR); + } + twiddle_divisor((u_int)tdiv); + env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); + + return (CMD_OK); }