From patchwork Thu Mar 17 19:28:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 52067 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 73F2C384781A for ; Thu, 17 Mar 2022 19:33:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73F2C384781A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1647545620; bh=X7HALskp9ATMR8mxKGcpdH/6iTvpDeXeVrR7FuXJapw=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kVvpaB9m1Fk53lm4uAl9AqPag6kjo9t/F9YYv/5jNkutzQC5t2smMYR9aM5B1JoxI ldfprGdI0htzJcUXLVjqfSMQkEuXnrOqBjqnYrrgBkWqckdI+mbLHM4vB33RhUZaP4 5w41KoMuX8m8DZ9i8kffClz2b9R03qqw2Dz/7KNQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D43B03865474 for ; Thu, 17 Mar 2022 19:29:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D43B03865474 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-664-tJZL_McBOA-tDQp11hsj4g-1; Thu, 17 Mar 2022 15:29:00 -0400 X-MC-Unique: tJZL_McBOA-tDQp11hsj4g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E8998002BF for ; Thu, 17 Mar 2022 19:29:00 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6EEAB1402642 for ; Thu, 17 Mar 2022 19:28:59 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing In-Reply-To: References: X-From-Line: c3452ce7f9301b9b12e97bf35f5d8eaff0e0c39e Mon Sep 17 00:00:00 2001 Message-Id: Date: Thu, 17 Mar 2022 20:28:57 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" form_character and form_string processing a sufficiently similar that the logic can be shared. Reviewed-by: Adhemerval Zanella --- stdio-common/vfprintf-process-arg.c | 130 +++++++++------------------- 1 file changed, 43 insertions(+), 87 deletions(-) diff --git a/stdio-common/vfprintf-process-arg.c b/stdio-common/vfprintf-process-arg.c index a28afce7de..4fe369e111 100644 --- a/stdio-common/vfprintf-process-arg.c +++ b/stdio-common/vfprintf-process-arg.c @@ -335,29 +335,20 @@ LABEL (form_strerror): goto LABEL (print_string); } -#ifdef COMPILE_WPRINTF LABEL (form_character): /* Character. */ if (is_long) goto LABEL (form_wcharacter); --width; /* Account for the character itself. */ if (!left) - PAD (L' '); + PAD (L_(' ')); +#ifdef COMPILE_WPRINTF outchar (__btowc ((unsigned char) process_arg_int ())); /* Promoted. */ +#else + outchar ((unsigned char) process_arg_int ()); /* Promoted. */ +#endif if (left) - PAD (L' '); - break; - -LABEL (form_wcharacter): - { - /* Wide character. */ - --width; - if (!left) - PAD (L' '); - outchar (process_arg_wchar_t ()); - if (left) - PAD (L' '); - } + PAD (L_(' ')); break; LABEL (form_string): @@ -366,8 +357,11 @@ LABEL (form_string): /* The string argument could in fact be `char *' or `wchar_t *'. But this should not make a difference here. */ +#ifdef COMPILE_WPRINTF string = (CHAR_T *) process_arg_wstring (); - +#else + string = (CHAR_T *) process_arg_string (); +#endif /* Entry point for printing other strings. */ LABEL (print_string): @@ -387,21 +381,39 @@ LABEL (form_string): } else if (!is_long && spec != L_('S')) { +#ifdef COMPILE_WPRINTF done = outstring_converted_wide_string (s, (const char *) string, prec, width, left, done); if (done < 0) goto all_done; /* The padding has already been written. */ break; +#else + if (prec != -1) + /* Search for the end of the string, but don't search past + the length (in bytes) specified by the precision. */ + len = __strnlen (string, prec); + else + len = strlen (string); +#endif } else { +#ifdef COMPILE_WPRINTF if (prec != -1) /* Search for the end of the string, but don't search past the length specified by the precision. */ len = __wcsnlen (string, prec); else len = __wcslen (string); +#else + done = outstring_converted_wide_string + (s, (const wchar_t *) string, prec, width, left, done); + if (done < 0) + goto all_done; + /* The padding has already been written. */ + break; +#endif } if ((width -= len) < 0) @@ -411,25 +423,27 @@ LABEL (form_string): } if (!left) - PAD (L' '); + PAD (L_(' ')); outstring (string, len); if (left) - PAD (L' '); + PAD (L_(' ')); } break; -#else /* !COMPILE_WPRINTF */ -LABEL (form_character): - /* Character. */ - if (is_long) - goto LABEL (form_wcharacter); - --width; /* Account for the character itself. */ - if (!left) - PAD (' '); - outchar ((unsigned char) process_arg_int ()); /* Promoted. */ - if (left) - PAD (' '); + +#ifdef COMPILE_WPRINTF +LABEL (form_wcharacter): + { + /* Wide character. */ + --width; + if (!left) + PAD (L' '); + outchar (process_arg_wchar_t ()); + if (left) + PAD (L' '); + } break; +#else /* !COMPILE_WPRINTF */ LABEL (form_wcharacter): { /* Wide character. */ @@ -453,63 +467,5 @@ LABEL (form_wcharacter): PAD (' '); } break; - -LABEL (form_string): - { - size_t len; - - /* The string argument could in fact be `char *' or `wchar_t *'. - But this should not make a difference here. */ - string = (char *) process_arg_string (); - - /* Entry point for printing other strings. */ - LABEL (print_string): - - if (string == NULL) - { - /* Write "(null)" if there's space. */ - if (prec == -1 || prec >= (int) sizeof (null) - 1) - { - string = (char *) null; - len = sizeof (null) - 1; - } - else - { - string = (char *) ""; - len = 0; - } - } - else if (!is_long && spec != L_('S')) - { - if (prec != -1) - /* Search for the end of the string, but don't search past - the length (in bytes) specified by the precision. */ - len = __strnlen (string, prec); - else - len = strlen (string); - } - else - { - done = outstring_converted_wide_string - (s, (const wchar_t *) string, prec, width, left, done); - if (done < 0) - goto all_done; - /* The padding has already been written. */ - break; - } - - if ((width -= len) < 0) - { - outstring (string, len); - break; - } - - if (!left) - PAD (' '); - outstring (string, len); - if (left) - PAD (' '); - } - break; #endif /* !COMPILE_WPRINTF */ }