From patchwork Fri Sep 12 23:10:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 2829 Received: (qmail 23190 invoked by alias); 12 Sep 2014 23:10:35 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 23118 invoked by uid 89); 12 Sep 2014 23:10:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=no version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] Minor cleanup in locale.c Message-Id: <20140912231031.0A69F2C3972@topped-with-meat.com> Date: Fri, 12 Sep 2014 16:10:30 -0700 (PDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=n1GpOfe5QYQA:10 a=QpzouxlztigA:10 a=Z6MIti7PxpgA:10 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=UT9qadGrKCsrjp31dG4A:9 a=Wu4H_ODvbClGjlh_:21 a=51nkHGJbdbSFZtIB:21 a=CjuIK1q_8ugA:10 Here we had a couple of nested functions just for scope, where top-level statics are identical code. One of them had just one call, so having a function at all was just extra fluff. Also some cosmetic nits (implicit Boolean coercion, not used mixed decls when they are the tightest way to write the code). Thanks, Roland * locale/programs/locale.c (show_locale_vars): Inline local function into its sole call site. Clean up some style nits. (print_item): New function, broken out of ... (show_info): ... local function here. Clean up style nits. --- a/locale/programs/locale.c +++ b/locale/programs/locale.c @@ -792,188 +792,181 @@ print_assignment (const char *name, const char *val, bool dquote) static void show_locale_vars (void) { - size_t cat_no; - const char *lcall = getenv ("LC_ALL") ? : ""; - const char *lang = getenv ("LANG") ? : ""; - - auto void get_source (const char *name); - - void get_source (const char *name) - { - char *val = getenv (name); - - if (lcall[0] != '\0' || val == NULL) - print_assignment (name, lcall[0] ? lcall : lang[0] ? lang : "POSIX", - true); - else - print_assignment (name, val, false); - } + const char *lcall = getenv ("LC_ALL") ?: ""; + const char *lang = getenv ("LANG") ?: ""; /* LANG has to be the first value. */ print_assignment ("LANG", lang, false); /* Now all categories in an unspecified order. */ - for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no) + for (size_t cat_no = 0; cat_no < NCATEGORIES; ++cat_no) if (cat_no != LC_ALL) - get_source (category[cat_no].name); + { + const char *name = category[cat_no].name; + const char *val = getenv (name); + + if (lcall[0] != '\0' || val == NULL) + print_assignment (name, + lcall[0] != '\0' ? lcall + : lang[0] != '\0' ? lang + : "POSIX", + true); + else + print_assignment (name, val, false); + } /* The last is the LC_ALL value. */ print_assignment ("LC_ALL", lcall, false); } -/* Show the information request for NAME. */ +/* Subroutine of show_info, below. */ static void -show_info (const char *name) +print_item (struct cat_item *item) { - size_t cat_no; - - auto void print_item (struct cat_item *item); - - void print_item (struct cat_item *item) + switch (item->value_type) { - switch (item->value_type) - { - case string: - if (show_keyword_name) - printf ("%s=\"", item->name); - fputs (nl_langinfo (item->item_id) ? : "", stdout); - if (show_keyword_name) - putchar ('"'); - putchar ('\n'); - break; - case stringarray: - { - int cnt; - const char *val; - - if (show_keyword_name) - printf ("%s=\"", item->name); + case string: + if (show_keyword_name) + printf ("%s=\"", item->name); + fputs (nl_langinfo (item->item_id) ? : "", stdout); + if (show_keyword_name) + putchar ('"'); + putchar ('\n'); + break; + case stringarray: + { + const char *val; + int cnt; - for (cnt = 0; cnt < item->max - 1; ++cnt) - { - val = nl_langinfo (item->item_id + cnt); - if (val != NULL) - fputs (val, stdout); - putchar (';'); - } + if (show_keyword_name) + printf ("%s=\"", item->name); + for (cnt = 0; cnt < item->max - 1; ++cnt) + { val = nl_langinfo (item->item_id + cnt); if (val != NULL) fputs (val, stdout); - - if (show_keyword_name) - putchar ('"'); - putchar ('\n'); + putchar (';'); } - break; - case stringlist: + + val = nl_langinfo (item->item_id + cnt); + if (val != NULL) + fputs (val, stdout); + + if (show_keyword_name) + putchar ('"'); + putchar ('\n'); + } + break; + case stringlist: + { + int first = 1; + const char *val = nl_langinfo (item->item_id) ? : ""; + + if (show_keyword_name) + printf ("%s=", item->name); + + for (int cnt = 0; cnt < item->max && *val != '\0'; ++cnt) { - int first = 1; - const char *val = nl_langinfo (item->item_id) ? : ""; - int cnt; - - if (show_keyword_name) - printf ("%s=", item->name); - - for (cnt = 0; cnt < item->max && *val != '\0'; ++cnt) - { - printf ("%s%s%s%s", first ? "" : ";", - show_keyword_name ? "\"" : "", val, - show_keyword_name ? "\"" : ""); - val = strchr (val, '\0') + 1; - first = 0; - } - putchar ('\n'); + printf ("%s%s%s%s", first ? "" : ";", + show_keyword_name ? "\"" : "", val, + show_keyword_name ? "\"" : ""); + val = strchr (val, '\0') + 1; + first = 0; } - break; - case byte: - { - const char *val = nl_langinfo (item->item_id); + putchar ('\n'); + } + break; + case byte: + { + const char *val = nl_langinfo (item->item_id); - if (show_keyword_name) - printf ("%s=", item->name); + if (show_keyword_name) + printf ("%s=", item->name); - if (val != NULL) - printf ("%d", *val == '\377' ? -1 : *val); - putchar ('\n'); - } - break; - case bytearray: + if (val != NULL) + printf ("%d", *val == '\377' ? -1 : *val); + putchar ('\n'); + } + break; + case bytearray: + { + const char *val = nl_langinfo (item->item_id); + int cnt = val ? strlen (val) : 0; + + if (show_keyword_name) + printf ("%s=", item->name); + + while (cnt > 1) { - const char *val = nl_langinfo (item->item_id); - int cnt = val ? strlen (val) : 0; + printf ("%d;", *val == '\177' ? -1 : *val); + --cnt; + ++val; + } - if (show_keyword_name) - printf ("%s=", item->name); + printf ("%d\n", cnt == 0 || *val == '\177' ? -1 : *val); + } + break; + case word: + { + union { unsigned int word; char *string; } val; + val.string = nl_langinfo (item->item_id); + if (show_keyword_name) + printf ("%s=", item->name); - while (cnt > 1) - { - printf ("%d;", *val == '\177' ? -1 : *val); - --cnt; - ++val; - } + printf ("%d\n", val.word); + } + break; + case wordarray: + { + int first = 1; + union { unsigned int *wordarray; char *string; } val; - printf ("%d\n", cnt == 0 || *val == '\177' ? -1 : *val); - } - break; - case word: - { - union { unsigned int word; char *string; } val; - val.string = nl_langinfo (item->item_id); - if (show_keyword_name) - printf ("%s=", item->name); + val.string = nl_langinfo (item->item_id); + if (show_keyword_name) + printf ("%s=", item->name); - printf ("%d\n", val.word); - } - break; - case wordarray: + for (int cnt = 0; cnt < item->max; ++cnt) { - int first = 1; - union { unsigned int *wordarray; char *string; } val; - int cnt; - - val.string = nl_langinfo (item->item_id); - if (show_keyword_name) - printf ("%s=", item->name); - - for (cnt = 0; cnt < item->max; ++cnt) - { - printf ("%s%d", first ? "" : ";", val.wordarray[cnt]); - first = 0; - } - putchar ('\n'); + printf ("%s%d", first ? "" : ";", val.wordarray[cnt]); + first = 0; } - break; - case wstring: - case wstringarray: - case wstringlist: - /* We don't print wide character information since the same - information is available in a multibyte string. */ - default: - break; - - } + putchar ('\n'); + } + break; + case wstring: + case wstringarray: + case wstringlist: + /* We don't print wide character information since the same + information is available in a multibyte string. */ + default: + break; } +} - for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no) +/* Show the information request for NAME. */ +static void +show_info (const char *name) +{ + for (size_t cat_no = 0; cat_no < NCATEGORIES; ++cat_no) if (cat_no != LC_ALL) { - size_t item_no; - if (strcmp (name, category[cat_no].name) == 0) /* Print the whole category. */ { if (show_category_name != 0) puts (category[cat_no].name); - for (item_no = 0; item_no < category[cat_no].number; ++item_no) + for (size_t item_no = 0; + item_no < category[cat_no].number; + ++item_no) print_item (&category[cat_no].item_desc[item_no]); return; } - for (item_no = 0; item_no < category[cat_no].number; ++item_no) + for (size_t item_no = 0; item_no < category[cat_no].number; ++item_no) if (strcmp (name, category[cat_no].item_desc[item_no].name) == 0) { if (show_category_name != 0)