[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5494-gdd7bd
From: |
Arnold Robbins |
Subject: |
[SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5494-gdd7bd9eb |
Date: |
Tue, 9 Jul 2024 13:58:55 -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 dd7bd9eb8b92426bd6134935a20361211f1de3c2 (commit)
via e7028c03c5ff4dbe05cb83d02706f4752622f600 (commit)
from 7b9e9bca203c92acaa6b3cd107764be319994038 (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=dd7bd9eb8b92426bd6134935a20361211f1de3c2
commit dd7bd9eb8b92426bd6134935a20361211f1de3c2
Author: Arnold D. Robbins <arnold@skeeve.com>
Date: Tue Jul 9 20:58:41 2024 +0300
More fixes in printf.
diff --git a/printf.c b/printf.c
index 162403dd..d134e91c 100644
--- a/printf.c
+++ b/printf.c
@@ -2469,13 +2469,30 @@ format_signed_integer(NODE *arg, struct flags *flags)
// The next step is deal with the rest of the printf flags.
// add more output digits to match the precision
- if (flags->have_prec && val_len < flags->precision) {
+ if (flags->have_prec && flags->precision == 0 && is_zero(arg)) {
+ int fw = flags->field_width;
+ char *cp;
+
+ free((void *) number_value);
+
+ if (flags->field_width == 0)
+ return strdup("");
+
+ emalloc(buf1, char *, flags->field_width + 1,
"format_signed_integer");
+ for (cp = buf1; fw > 0; fw--)
+ *cp++ = ' ';
+ *cp = '\0';
+
+ return buf1;
+ } else if (flags->have_prec && val_len < flags->precision) {
char *cp;
+ char *buf2;
const char *src;
int prec = flags->precision;
+ int count = flags->precision + flags->field_width + 1 +
(flags->plus || flags->space);
+ int fw = flags->field_width;
- emalloc(buf1, char *, flags->precision + 1 + (flags->plus ||
flags->space),
- "format_signed_integer");
+ emalloc(buf1, char *, count, "format_signed_integer");
cp = buf1;
src = number_value;
if (number_value[0] == '-') {
@@ -2493,6 +2510,20 @@ format_signed_integer(NODE *arg, struct flags *flags)
strcpy(cp, src);
free((void *) number_value);
+ val_len = strlen(buf1);
+
+ if (fw > val_len) {
+ emalloc(buf2, char *, count, "format_signed_integer");
+ cp = buf2;
+ for (; fw > val_len; fw--)
+ *cp++ = fill[0];
+ strcpy(cp, buf1);
+ free((void *) buf1);
+
+ buf1 = buf2;
+ }
+
+ return buf1;
} else if (flags->field_width > val_len) {
char *cp;
const char *src;
@@ -2564,6 +2595,15 @@ format_signed_integer(NODE *arg, struct flags *flags)
reverse(buf1);
}
+ free((void *) number_value);
+ } else if (flags->plus || flags->space) {
+ emalloc(buf1, char *, val_len + 2, "format_signed_integer");
+ if (flags->plus) {
+ sprintf(buf1, "+%s", number_value);
+ } else {
+ sprintf(buf1, " %s", number_value);
+ }
+
free((void *) number_value);
} else
buf1 = (char *) number_value;
@@ -2613,12 +2653,15 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
*cp++ = '0';
strcpy(cp, src);
- } else if (flags->precision == 0 && flags->base == 8) {
+ free((void *) number_value);
+ } else if (flags->have_prec && flags->precision == 0 &&
flags->base == 8
+ && number_value[0] != '0') {
emalloc(buf1, char *, val_len + 2,
"format_unsigned_integer");
sprintf(buf1, "0%s", number_value);
- }
+ free((void *) number_value);
+ } else
+ buf1 = (char *) number_value;
- free((void *) number_value);
val_len = strlen(buf1);
} else if (flags->field_width > val_len) { // pad the field if necessary
// when there's a precision, field width padding with zeros is
not done.
@@ -2635,7 +2678,7 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
fill[0] = '0';
if (flags->alt) {
- if (flags->base == 16) {
+ if (flags->base == 16 && ! is_zero(arg)) {
if (fill[0] == '0') {
*cp++ = '0';
*cp++ = flags->format;
@@ -2680,22 +2723,23 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
buf1 = buf2;
val_len = strlen(buf1);
}
- } else if (flags->alt) {
+ } else 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, buf1);
+ sprintf(buf2, "0%c%s", flags->format, number_value);
} else if (flags->base == 8) {
if (number_value[0] != '0')
- sprintf(buf2, "0%s", buf1);
+ sprintf(buf2, "0%s", number_value);
else
- strcpy(buf2, buf1);
+ strcpy(buf2, number_value);
}
- free((void *) buf1);
+ free((void *) number_value);
buf1 = buf2;
val_len = strlen(buf1);
- }
+ } else
+ buf1 = (char *) number_value;
return buf1;
}
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=e7028c03c5ff4dbe05cb83d02706f4752622f600
commit e7028c03c5ff4dbe05cb83d02706f4752622f600
Author: Arnold D. Robbins <arnold@skeeve.com>
Date: Tue Jul 9 20:17:32 2024 +0300
More printf fixes. Checkpoint commit.
diff --git a/ChangeLog b/ChangeLog
index 226ec04e..f1484301 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-07-09 Arnold D. Robbins <arnold@skeeve.com>
+
+ * printf.c: Signed printing I think is working. Unsigned is better.
+ Checkpoint commit.
+
2024-07-07 Arnold D. Robbins <arnold@skeeve.com>
* printf.c: Signed and unsigned integer printing mostly working now.
diff --git a/printf.c b/printf.c
index 939741b7..162403dd 100644
--- a/printf.c
+++ b/printf.c
@@ -1448,9 +1448,17 @@ check_pos:
goto out;
}
} else {
- // FIXME
- msg(_("fatal: `$' not permitted after period in
format"));
- goto out;
+ argnum = prec;
+ prec = 0;
+ used_dollar = true;
+ if (argnum <= 0) {
+ msg(_("fatal: argument index with `$'
must be > 0"));
+ goto out;
+ }
+ if (argnum >= num_args) {
+ msg(_("fatal: argument index %ld
greater than total number of supplied arguments"), argnum);
+ goto out;
+ }
}
goto retry;
@@ -2493,33 +2501,67 @@ format_signed_integer(NODE *arg, struct flags *flags)
emalloc(buf1, char *, flags->field_width + 1 + (flags->plus ||
flags->space),
"format_signed_integer");
- cp = buf1;
- src = number_value;
- if (number_value[0] == '-') {
- *cp++ = '-';
- src++;
- fw--;
- val_len--;
- } else if (flags->plus) {
- *cp++ = '+';
- fw--;
- } else if (flags->space) {
- *cp++ = ' ';
- fw--;
- }
-
if (compute_zero_flag(flags))
fill[0] = '0';
+ cp = buf1;
+ src = number_value;
+
if (flags->left_just) {
+ if (number_value[0] == '-') {
+ *cp++ = '-';
+ src++;
+ fw--;
+ val_len--;
+ } else if (flags->plus) {
+ *cp++ = '+';
+ fw--;
+ } else if (flags->space) {
+ *cp++ = ' ';
+ fw--;
+ }
strcpy(cp, src);
cp += val_len;
for (; fw > val_len; fw--)
*cp++ = fill[0];
+ *cp = '\0';
} else {
- for (; fw > val_len; fw--)
- *cp++ = fill[0];
- strcpy(cp, src);
+ strcpy(buf1, number_value);
+ reverse(buf1);
+ bool negative = (buf1[val_len - 1] == '-');
+ cp = buf1 + val_len;
+
+ if (negative) {
+ *cp = '\0'; // remove minus temporarily
+ val_len--;
+ }
+
+ if (fill[0] == '0') {
+ // leave room for the extra character
+ int stop = val_len + (negative || flags->plus
|| flags->space);
+
+ for (; fw > stop; fw--)
+ *cp++ = fill[0];
+ }
+
+ if (negative) {
+ *cp++ = '-';
+ fw--;
+ } else if (flags->plus) {
+ *cp++ = '+';
+ fw--;
+ } else if (flags->space) {
+ *cp++ = ' ';
+ fw--;
+ }
+
+ if (fill[0] == ' ') {
+ for (; fw > val_len; fw--)
+ *cp++ = fill[0];
+ }
+ *cp = '\0';
+
+ reverse(buf1);
}
free((void *) number_value);
@@ -2555,33 +2597,91 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
// The next step is deal with the rest of the printf flags.
// Add more output digits to match the precision
- if (flags->have_prec && val_len < flags->precision) {
+ if (flags->have_prec) {
+ if (val_len < flags->precision) {
+ char *cp;
+ const char *src;
+ int prec = flags->precision;
+
+ // plus and space flags are only for signed conversions
+ emalloc(buf1, char *, flags->precision + 1,
+ "format_unsigned_integer");
+ cp = buf1;
+ src = number_value;
+
+ for (; prec > val_len; prec--)
+ *cp++ = '0';
+
+ strcpy(cp, src);
+ } else if (flags->precision == 0 && flags->base == 8) {
+ emalloc(buf1, char *, val_len + 2,
"format_unsigned_integer");
+ sprintf(buf1, "0%s", number_value);
+ }
+
+ free((void *) number_value);
+ val_len = strlen(buf1);
+ } else if (flags->field_width > val_len) { // pad the field if necessary
+ // when there's a precision, field width padding with zeros is
not done.
char *cp;
const char *src;
- int prec = flags->precision;
+ int fw = flags->field_width;
+
+ emalloc(buf1, char *, flags->field_width + 3,
"format_unsigned_integer");
- // plus and space flags are only for signed conversions
- emalloc(buf1, char *, flags->precision + 1,
- "format_unsigned_integer");
cp = buf1;
src = number_value;
- if (number_value[0] == '-') {
- *cp++ = '-';
- src++;
- val_len--;
- }
- for (; prec > val_len; prec--)
- *cp++ = '0';
+ if (compute_zero_flag(flags))
+ fill[0] = '0';
+
+ if (flags->alt) {
+ if (flags->base == 16) {
+ if (fill[0] == '0') {
+ *cp++ = '0';
+ *cp++ = flags->format;
+ fw -= 2;
+ for (; fw > val_len; fw--)
+ *cp++ = fill[0];
+ } else {
+ for (; fw > val_len; fw--)
+ *cp++ = fill[0];
+ fw -= 2;
+ *cp++ = '0';
+ *cp++ = flags->format;
+ }
+ } else if (flags->base == 8 && src[0] != '0') {
+ *cp++ = '0';
+ }
+
+ strcpy(cp, src);
+ free((void *) number_value);
+ } else
+ buf1 = (char *) number_value;
- strcpy(cp, src);
- free((void *) number_value);
val_len = strlen(buf1);
- } else
- buf1 = (char *) number_value;
- // handle the alt flag
- if (flags->alt) {
+ if (val_len < fw) {
+ emalloc(buf2, char *, flags->field_width + 1,
"format_unsigned_integer");
+ cp = buf2;
+
+ if (flags->left_just) {
+ strcpy(cp, buf1);
+ cp += val_len;
+ fw -= val_len;
+ for (; fw > 0; fw--)
+ *cp++ = fill[0];
+ } else {
+ for (; fw > val_len; fw--)
+ *cp++ = fill[0];
+ strcpy(cp, buf1);
+ }
+
+ free((void *) buf1);
+ buf1 = buf2;
+ val_len = strlen(buf1);
+ }
+ } else if (flags->alt) {
+ // handle the alt flag
emalloc(buf2, char *, val_len + 3, "format_unsigned_integer");
if (flags->base == 16) {
@@ -2597,36 +2697,6 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
val_len = strlen(buf1);
}
- // pad the field if necessary
- if (flags->field_width > val_len) {
- char *cp;
- const char *src;
- int fw = flags->field_width;
-
- emalloc(buf2, char *, flags->field_width + 1,
"format_unsigned_integer");
-
- cp = buf2;
- src = buf1;
-
- if (compute_zero_flag(flags) && ! flags->alt)
- fill[0] = '0';
-
- if (flags->left_just) {
- strcpy(cp, src);
- cp += val_len;
- for (; fw > val_len; fw--)
- *cp++ = fill[0];
- } else {
- for (; fw > val_len; fw--)
- *cp++ = fill[0];
- strcpy(cp, src);
- }
-
- free((void *) buf1);
- buf1 = buf2;
- val_len = strlen(buf1);
- }
-
return buf1;
}
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 5 ++
printf.c | 268 ++++++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 196 insertions(+), 77 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5494-gdd7bd9eb,
Arnold Robbins <=