From nobody Tue Sep 12 16:42:53 2023 X-Original-To: dev-commits-src-main@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 4RlTsT49m1z4st8q; Tue, 12 Sep 2023 16:42:53 +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 4RlTsT3ldHz3bVT; Tue, 12 Sep 2023 16:42:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694536973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hia0R+yCAMGGe0aJ+1W+OHUFCX/4NqNb14NpKKvcwUQ=; b=T1pw8OAl0M9l6kDD31PJknAuskCOIw7BNXOCd37JrQvUqQJsi4zPEm0hIMXXEzmNJsKJ2J ocV8Lz0wrUbv3SFK3rotXAMw/Ea7dSUiKdPjCkOKsp1uWroSrdvLsMIhulJ12EPkwCIrSX g2FMbq8wppWdHEYnReUlFnAd3ohYY6qqz7N5hw7KaVNbABjewekTd5sKpCHpZXuf8HuPn6 PlVh6z3P8jfpuJDvVsBgzhFqEG/G5RHsRv3vmnHKghGewOWjOSTkuVuGSsN0mYRcyX2LHe uDEY3wwQkVGYcs7aBxwKQpVxSyHUN9k95hvA0yM9wtVwhfX0bn0xSL/YRO6mBw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694536973; a=rsa-sha256; cv=none; b=LLKJSXh5NX9exZuyuXr9FwkI6yYhjSeR9PVKnpnLitHgCmBepo/SkKoF7I13LekON4ByE5 7nvGULZm5a2meyrUEjhNKLyU5exr/WyCqw24MfEEKQ3e2oCzrB+GnzsaeubDIHZOHXJ6gu eD7O4Kdm64oOvnXQUzlxsQc9uY726VwwURMOVGKH0YPE6DrBxOBIF/EvTBPRqOHFgLuJpT gNMdVs0efihjbWBqNwcnr3cOKe0pFzKlnqT8o7EGL5sHuOJBsZBgNOS7lbx2bJIX+SBYs8 KeOYTCnc2diDoOwNISBZW6f5sDYTjkWM8qz+lSZ1aC4i621UVCEFeFEVQBLvjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694536973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hia0R+yCAMGGe0aJ+1W+OHUFCX/4NqNb14NpKKvcwUQ=; b=h0ik/uA0+NrAtpjxgEaNndOprfhM2tMmJfVwsYywl5Z3Mci7M5MaIlSZ/ROaDhvq17F0c5 VNWg/LCXzm2/8eEfH3uXfNkevnCu+QN8PiUWeq06GD0oW7RgBuAuDD+IsPqUOog3yR2jo1 BLDopQ8okkRoBTpj9hD63cawa5UwsEDHvbvSoZsiraUK3t7+nYbUhSClbYe92aB3M2h0fr M4f6HqgQ79lCLi1p4zISrac/jjkJ0ayeZOBITfWVnONVnsEVqUPCZ+0aC6v5Xyl7TQFBp6 bGuHOoZo0nzKnLPAe0ksL0A4m0TDJTfJv8z4sRUUnLeXG76Em+e85+Qwtdir9A== 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 4RlTsT2pT3zfjb; Tue, 12 Sep 2023 16:42:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38CGgrwX070359; Tue, 12 Sep 2023 16:42:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38CGgrtg070356; Tue, 12 Sep 2023 16:42:53 GMT (envelope-from git) Date: Tue, 12 Sep 2023 16:42:53 GMT Message-Id: <202309121642.38CGgrtg070356@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 63b6e661d25c - main - sh: reindent a for loop in parser.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 63b6e661d25c67b4ab9b7743bf1c68e3876ddc1e Auto-Submitted: auto-generated The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=63b6e661d25c67b4ab9b7743bf1c68e3876ddc1e commit 63b6e661d25c67b4ab9b7743bf1c68e3876ddc1e Author: Piotr Pawel Stefaniak AuthorDate: 2023-01-01 19:22:28 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2023-09-12 16:36:32 +0000 sh: reindent a for loop in parser.c Reduce indentation level before a commit that will add new code here. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D37926 --- bin/sh/parser.c | 242 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 123 insertions(+), 119 deletions(-) diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 044233da5d73..121c367c601c 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -2054,135 +2054,139 @@ getprompt(void *unused __unused) /* * Format prompt string. */ - for (i = 0; (i < PROMPTLEN - 1) && (*fmt != '\0'); i++, fmt++) - if (*fmt == '\\') - switch (*++fmt) { + for (i = 0; (i < PROMPTLEN - 1) && (*fmt != '\0'); i++, fmt++) { + if (*fmt != '\\') { + ps[i] = *fmt; + continue; + } - /* - * Non-printing sequence begin and end. - */ - case '[': - case ']': - ps[i] = '\001'; - break; + switch (*++fmt) { - /* - * Literal \ and some ASCII characters: - * \a BEL - * \e ESC - * \r CR - */ - case '\\': - case 'a': - case 'e': - case 'r': - if (*fmt == 'a') - ps[i] = '\007'; - else if (*fmt == 'e') - ps[i] = '\033'; - else if (*fmt == 'r') - ps[i] = '\r'; - else - ps[i] = '\\'; - break; + /* + * Non-printing sequence begin and end. + */ + case '[': + case ']': + ps[i] = '\001'; + break; - /* - * CRLF sequence - */ - case 'n': - if (i < PROMPTLEN - 3) { - ps[i++] = '\r'; - ps[i] = '\n'; - } - break; + /* + * Literal \ and some ASCII characters: + * \a BEL + * \e ESC + * \r CR + */ + case '\\': + case 'a': + case 'e': + case 'r': + if (*fmt == 'a') + ps[i] = '\007'; + else if (*fmt == 'e') + ps[i] = '\033'; + else if (*fmt == 'r') + ps[i] = '\r'; + else + ps[i] = '\\'; + break; - /* - * Hostname. - * - * \h specifies just the local hostname, - * \H specifies fully-qualified hostname. - */ - case 'h': - case 'H': - ps[i] = '\0'; - gethostname(&ps[i], PROMPTLEN - i - 1); - ps[PROMPTLEN - 1] = '\0'; - /* Skip to end of hostname. */ - trim = (*fmt == 'h') ? '.' : '\0'; - while ((ps[i] != '\0') && (ps[i] != trim)) - i++; - --i; - break; + /* + * CRLF sequence + */ + case 'n': + if (i < PROMPTLEN - 3) { + ps[i++] = '\r'; + ps[i] = '\n'; + } + break; - /* - * User name. - */ - case 'u': - ps[i] = '\0'; - getusername(&ps[i], PROMPTLEN - i); - /* Skip to end of username. */ - while (ps[i + 1] != '\0') - i++; - break; + /* + * Hostname. + * + * \h specifies just the local hostname, + * \H specifies fully-qualified hostname. + */ + case 'h': + case 'H': + ps[i] = '\0'; + gethostname(&ps[i], PROMPTLEN - i - 1); + ps[PROMPTLEN - 1] = '\0'; + /* Skip to end of hostname. */ + trim = (*fmt == 'h') ? '.' : '\0'; + while ((ps[i] != '\0') && (ps[i] != trim)) + i++; + --i; + break; - /* - * Working directory. - * - * \W specifies just the final component, - * \w specifies the entire path. - */ - case 'W': - case 'w': - pwd = lookupvar("PWD"); - if (pwd == NULL || *pwd == '\0') - pwd = "?"; - if (*fmt == 'W' && - *pwd == '/' && pwd[1] != '\0') - strlcpy(&ps[i], strrchr(pwd, '/') + 1, + /* + * User name. + */ + case 'u': + ps[i] = '\0'; + getusername(&ps[i], PROMPTLEN - i); + /* Skip to end of username. */ + while (ps[i + 1] != '\0') + i++; + break; + + /* + * Working directory. + * + * \W specifies just the final component, + * \w specifies the entire path. + */ + case 'W': + case 'w': + pwd = lookupvar("PWD"); + if (pwd == NULL || *pwd == '\0') + pwd = "?"; + if (*fmt == 'W' && + *pwd == '/' && pwd[1] != '\0') + strlcpy(&ps[i], strrchr(pwd, '/') + 1, + PROMPTLEN - i); + else { + home = lookupvar("HOME"); + if (home != NULL) + homelen = strlen(home); + if (home != NULL && + strcmp(home, "/") != 0 && + strncmp(pwd, home, homelen) == 0 && + (pwd[homelen] == '/' || + pwd[homelen] == '\0')) { + strlcpy(&ps[i], "~", PROMPTLEN - i); - else { - home = lookupvar("HOME"); - if (home != NULL) - homelen = strlen(home); - if (home != NULL && - strcmp(home, "/") != 0 && - strncmp(pwd, home, homelen) == 0 && - (pwd[homelen] == '/' || - pwd[homelen] == '\0')) { - strlcpy(&ps[i], "~", - PROMPTLEN - i); - strlcpy(&ps[i + 1], - pwd + homelen, - PROMPTLEN - i - 1); - } else { - strlcpy(&ps[i], pwd, PROMPTLEN - i); - } + strlcpy(&ps[i + 1], + pwd + homelen, + PROMPTLEN - i - 1); + } else { + strlcpy(&ps[i], pwd, PROMPTLEN - i); } - /* Skip to end of path. */ - while (ps[i + 1] != '\0') - i++; - break; + } + /* Skip to end of path. */ + while (ps[i + 1] != '\0') + i++; + break; - /* - * Superuser status. - * - * '$' for normal users, '#' for root. - */ - case '$': - ps[i] = (geteuid() != 0) ? '$' : '#'; - break; + /* + * Superuser status. + * + * '$' for normal users, '#' for root. + */ + case '$': + ps[i] = (geteuid() != 0) ? '$' : '#'; + break; - /* - * Emit unrecognized formats verbatim. - */ - default: - ps[i] = '\\'; - if (i < PROMPTLEN - 2) - ps[++i] = *fmt; - break; - } - else - ps[i] = *fmt; + /* + * Emit unrecognized formats verbatim. + */ + default: + ps[i] = '\\'; + if (i < PROMPTLEN - 2) + ps[++i] = *fmt; + break; + } + + } ps[i] = '\0'; return (ps); }