Sat Jun 27 19:18:58 2020 UTC ()
eval: Make radix optional even if minimum result width is specified.
This is what GNU m4 does too.


(uwe)
diff -r1.27 -r1.28 src/usr.bin/m4/eval.c

cvs diff -r1.27 -r1.28 src/usr.bin/m4/eval.c (expand / switch to unified diff)

--- src/usr.bin/m4/eval.c 2018/07/30 22:58:09 1.27
+++ src/usr.bin/m4/eval.c 2020/06/27 19:18:58 1.28
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1/* $OpenBSD: eval.c,v 1.66 2008/08/21 21:01:47 espie Exp $ */ 1/* $OpenBSD: eval.c,v 1.66 2008/08/21 21:01:47 espie Exp $ */
2/* $NetBSD: eval.c,v 1.27 2018/07/30 22:58:09 kre Exp $ */ 2/* $NetBSD: eval.c,v 1.28 2020/06/27 19:18:58 uwe Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1989, 1993 5 * Copyright (c) 1989, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * Ozan Yigit at York University. 9 * Ozan Yigit at York University.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE. 33 * SUCH DAMAGE.
34 */ 34 */
35 35
36/* 36/*
37 * eval.c 37 * eval.c
38 * Facility: m4 macro processor 38 * Facility: m4 macro processor
39 * by: oz 39 * by: oz
40 */ 40 */
41#if HAVE_NBTOOL_CONFIG_H 41#if HAVE_NBTOOL_CONFIG_H
42#include "nbtool_config.h" 42#include "nbtool_config.h"
43#endif 43#endif
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45__RCSID("$NetBSD: eval.c,v 1.27 2018/07/30 22:58:09 kre Exp $"); 45__RCSID("$NetBSD: eval.c,v 1.28 2020/06/27 19:18:58 uwe Exp $");
46 46
47#include <sys/types.h> 47#include <sys/types.h>
48#include <ctype.h> 48#include <ctype.h>
49#include <err.h> 49#include <err.h>
50#include <errno.h> 50#include <errno.h>
51#include <limits.h> 51#include <limits.h>
52#include <unistd.h> 52#include <unistd.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <stddef.h> 55#include <stddef.h>
56#include <stdint.h> 56#include <stdint.h>
57#include <string.h> 57#include <string.h>
58#include <inttypes.h> 58#include <inttypes.h>
@@ -174,27 +174,27 @@ expand_builtin(const char *argv[], int a @@ -174,27 +174,27 @@ expand_builtin(const char *argv[], int a
174 dotrace(argv, argc, 0); 174 dotrace(argv, argc, 0);
175 break; 175 break;
176 176
177 case EXPRTYPE: 177 case EXPRTYPE:
178 /* 178 /*
179 * doexpr - evaluate arithmetic 179 * doexpr - evaluate arithmetic
180 * expression 180 * expression
181 */ 181 */
182 { 182 {
183 int base = 10; 183 int base = 10;
184 int maxdigits = 0; 184 int maxdigits = 0;
185 int e; 185 int e;
186 186
187 if (argc > 3) { 187 if (argc > 3 && *argv[3] != '\0') {
188 base = strtoi(argv[3], NULL, 0, 2, 36, &e); 188 base = strtoi(argv[3], NULL, 0, 2, 36, &e);
189 if (e) { 189 if (e) {
190 m4errx(1, "expr: base %s invalid.", argv[3]); 190 m4errx(1, "expr: base %s invalid.", argv[3]);
191 } 191 }
192 } 192 }
193 if (argc > 4) { 193 if (argc > 4) {
194 maxdigits = strtoi(argv[4], NULL, 0, 0, INT_MAX, &e); 194 maxdigits = strtoi(argv[4], NULL, 0, 0, INT_MAX, &e);
195 if (e) { 195 if (e) {
196 m4errx(1, "expr: maxdigits %s invalid.", argv[4]); 196 m4errx(1, "expr: maxdigits %s invalid.", argv[4]);
197 } 197 }
198 } 198 }
199 if (argc > 2) 199 if (argc > 2)
200 pbnumbase(expr(argv[2]), base, maxdigits); 200 pbnumbase(expr(argv[2]), base, maxdigits);