gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5503-gfd33a


From: Arnold Robbins
Subject: [SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5503-gfd33a7cd
Date: Sat, 13 Jul 2024 15:21:54 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, stable/printf-rework has been updated
       via  fd33a7cd1eb2c5372e30d5e79a3164cd2fdc133e (commit)
      from  8f14d054736a4d1b5daee636dbfebac923ba7fdf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=fd33a7cd1eb2c5372e30d5e79a3164cd2fdc133e

commit fd33a7cd1eb2c5372e30d5e79a3164cd2fdc133e
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Sat Jul 13 22:21:40 2024 +0300

    More printf progress.

diff --git a/ChangeLog b/ChangeLog
index 105ab551..a4470554 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-07-13         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * printf.c: Continued progress against the printf-corners test.
+
 2024-07-11         Arnold D. Robbins     <arnold@skeeve.com>
 
        * printf.c: Signed and unsigned integer printing and float printing
diff --git a/printf.c b/printf.c
index d8a4dba2..800d9651 100644
--- a/printf.c
+++ b/printf.c
@@ -1576,6 +1576,9 @@ check_pos:
                                break;
                        magic_posix_flag = true;
                        goto retry;
+               case 'C':               // POSIX 2024 extension, undocumented 
for now
+                       cs1 = 'c';
+                       // FALL THROUGH
                case 'c':
                        need_format = false;
                        parse_next_arg();
@@ -1655,6 +1658,9 @@ out0:
                                }
                        }
                        goto pr_tail;
+               case 'S':               // POSIX 2024 extension, undocumented 
for now
+                       cs1 = 's';
+                       // FALL THROUGH
                case 's':
                        need_format = false;
                        parse_next_arg();
@@ -2489,8 +2495,14 @@ format_signed_integer(NODE *arg, struct flags *flags)
 
                free((void *) number_value);
 
-               if (flags->field_width == 0)
-                       return strdup("");
+               if (flags->field_width == 0) {
+                       if (flags->plus)
+                               return estrdup("+", 1);
+                       else if (flags->space)
+                               return estrdup(" ", 1);
+                       else
+                               return estrdup("", 1);
+               }
 
                emalloc(buf1, char *, flags->field_width + 1, 
"format_signed_integer");
                for (cp = buf1; fw > 0; fw--)
@@ -2652,6 +2664,11 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
 
        // Add more output digits to match the precision
        if (flags->have_prec) {
+               if (flags->precision == 0 && is_zero(arg) && flags->field_width 
== 0 && ! flags->alt) {
+                       free((void *) number_value);
+                       return estrdup("", 1);
+               }
+
                if (val_len < flags->precision) {
                        char *cp;
                        const char *src;
@@ -2668,7 +2685,7 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
 
                        strcpy(cp, src);
                        free((void *) number_value);
-               } else if (flags->have_prec && flags->precision == 0) {
+               } else if (flags->have_prec) {
                        if (flags->base == 8) {
                                if (number_value[0] != '0') {
                                        emalloc(buf1, char *, val_len + 2, 
"format_unsigned_integer");
@@ -2678,7 +2695,7 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
                                        buf1 = (char *) number_value;
                        } else {
                                free((void *) number_value);
-                               buf1 = strdup("");
+                               buf1 = estrdup("", 1);
                        }
                } else
                        buf1 = (char *) number_value;
@@ -2719,6 +2736,7 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
 
                        strcpy(cp, src);
                        free((void *) number_value);
+                       flags->alt = false;
                } else
                        buf1 = (char *) number_value;
 
@@ -2745,23 +2763,25 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
                        buf1 = buf2;
                        val_len = strlen(buf1);
                }
-       } else if (flags->alt && ! is_zero(arg)) {
+       } else
+               buf1 = (char *) number_value;
+
+       if (flags->alt && ! is_zero(arg)) {
                // handle the alt flag
                emalloc(buf2, char *, val_len + 3, "format_unsigned_integer");
 
                if (flags->base == 16) {
-                       sprintf(buf2, "0%c%s", flags->format, number_value);
+                       sprintf(buf2, "0%c%s", flags->format, buf1);
                } else if (flags->base == 8) {
-                       if (number_value[0] != '0')
-                               sprintf(buf2, "0%s", number_value);
+                       if (buf1[0] != '0')
+                               sprintf(buf2, "0%s", buf1);
                        else
-                               strcpy(buf2, number_value);
+                               strcpy(buf2, buf1);
                }
-               free((void *) number_value);
+               free((void *) buf1);
                buf1 = buf2;
                val_len = strlen(buf1);
-       } else
-               buf1 = (char *) number_value;
+       }
 
        return buf1;
 }
@@ -2821,7 +2841,7 @@ format_out_of_range(NODE *arg, struct flags *flags)
                return buf;
        }
 
-       return strdup(nan_inf_val);
+       return estrdup(nan_inf_val, strlen(nan_inf_val));
 }
 
 /* compute_zero_flag --- return true if we want to fill with zeros */
@@ -2905,9 +2925,9 @@ mpf1:
                                tmpval = uval = (uintmax_t) mpfr_get_sj(mf, 
ROUND_MODE);
                                if (! flags->alt && flags->have_prec && 
flags->precision == 0 && tmpval == 0) {
                                        if (flags->base == 8)
-                                               return strdup("0");
+                                               return estrdup("0", 1);
                                        else
-                                               return strdup("");      /* 
printf("%.0x", 0) is no characters */
+                                               return estrdup("", 1);  /* 
printf("%.0x", 0) is no characters */
                                }
                                goto fmt0;
                        }
@@ -3044,8 +3064,8 @@ adjust_flags(struct flags *flags)
 
        if (flags->base != 10) {
                flags->quote = false;
-               flags->plus = false;
-               flags->space = false;
+//             flags->plus = false;
+//             flags->space = false;
        }
 
        if (flags->plus)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog |  4 ++++
 printf.c  | 54 +++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 41 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]