mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
fix a few minor compatibility issues.
- let eval() handle a base and number of digits, like it's advertized to. - in gnu-mode, undivert can take file names as arguments. - in gnu-mode, map can handle reversed charsets. Suggestions and okay otto@, mostly prompted by looking at the regress tests in newer gnu-m4.
This commit is contained in:
parent
424e9ac3fa
commit
e79fa6877f
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: eval.c,v 1.55 2005/03/02 10:12:15 espie Exp $ */
|
||||
/* $OpenBSD: eval.c,v 1.56 2005/05/29 18:44:36 espie Exp $ */
|
||||
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
|
||||
|
||||
/*
|
||||
@ -37,7 +37,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
|
||||
#else
|
||||
static char rcsid[] = "$OpenBSD: eval.c,v 1.55 2005/03/02 10:12:15 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: eval.c,v 1.56 2005/05/29 18:44:36 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -49,6 +49,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.55 2005/03/02 10:12:15 espie Exp $";
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -178,9 +179,27 @@ expand_builtin(const char *argv[], int argc, int td)
|
||||
* doexpr - evaluate arithmetic
|
||||
* expression
|
||||
*/
|
||||
{
|
||||
int base = 10;
|
||||
int maxdigits = 0;
|
||||
const char *errstr;
|
||||
|
||||
if (argc > 3) {
|
||||
base = strtonum(argv[3], 2, 36, &errstr);
|
||||
if (errstr) {
|
||||
errx(1, "base %s invalid", argv[3]);
|
||||
}
|
||||
}
|
||||
if (argc > 4) {
|
||||
maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr);
|
||||
if (errstr) {
|
||||
errx(1, "maxdigits %s invalid", argv[4]);
|
||||
}
|
||||
}
|
||||
if (argc > 2)
|
||||
pbnum(expr(argv[2]));
|
||||
pbnumbase(expr(argv[2]), base, maxdigits);
|
||||
break;
|
||||
}
|
||||
|
||||
case IFELTYPE:
|
||||
if (argc > 4)
|
||||
@ -866,10 +885,15 @@ doundiv(const char *argv[], int argc)
|
||||
|
||||
if (argc > 2) {
|
||||
for (ind = 2; ind < argc; ind++) {
|
||||
n = atoi(argv[ind]);
|
||||
if (n > 0 && n < maxout && outfile[n] != NULL)
|
||||
getdiv(n);
|
||||
|
||||
const char *errstr;
|
||||
n = strtonum(argv[ind], 1, INT_MAX, &errstr);
|
||||
if (errstr) {
|
||||
if (errno == EINVAL && mimic_gnu)
|
||||
getdivfile(argv[ind]);
|
||||
} else {
|
||||
if (n < maxout && outfile[n] != NULL)
|
||||
getdiv(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1011,12 +1035,23 @@ handledash(char *buffer, char *end, const char *src)
|
||||
while(*src) {
|
||||
if (src[1] == '-' && src[2]) {
|
||||
unsigned char i;
|
||||
for (i = (unsigned char)src[0];
|
||||
i <= (unsigned char)src[2]; i++) {
|
||||
*p++ = i;
|
||||
if (p == end) {
|
||||
*p = '\0';
|
||||
return buffer;
|
||||
if ((unsigned char)src[0] <= (unsigned char)src[2]) {
|
||||
for (i = (unsigned char)src[0];
|
||||
i <= (unsigned char)src[2]; i++) {
|
||||
*p++ = i;
|
||||
if (p == end) {
|
||||
*p = '\0';
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = (unsigned char)src[0];
|
||||
i >= (unsigned char)src[2]; i--) {
|
||||
*p++ = i;
|
||||
if (p == end) {
|
||||
*p = '\0';
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
src += 3;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.40 2005/03/02 10:12:15 espie Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.41 2005/05/29 18:44:36 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -55,6 +55,7 @@ extern void doprintlineno(struct input_file *);
|
||||
extern void doprintfilename(struct input_file *);
|
||||
|
||||
extern void doesyscmd(const char *);
|
||||
extern void getdivfile(const char *);
|
||||
|
||||
|
||||
/* look.c */
|
||||
@ -96,6 +97,7 @@ extern void initspaces(void);
|
||||
extern void killdiv(void);
|
||||
extern void onintr(int);
|
||||
extern void pbnum(int);
|
||||
extern void pbnumbase(int, int, int);
|
||||
extern void pbunsigned(unsigned long);
|
||||
extern void pbstr(const char *);
|
||||
extern void putback(int);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: gnum4.c,v 1.30 2005/05/21 10:33:48 espie Exp $ */
|
||||
/* $OpenBSD: gnum4.c,v 1.31 2005/05/29 18:44:36 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Marc Espie
|
||||
@ -551,3 +551,18 @@ doesyscmd(const char *cmd)
|
||||
pbstr(getstring());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
getdivfile(const char *name)
|
||||
{
|
||||
FILE *f;
|
||||
int c;
|
||||
|
||||
f = fopen(name, "r");
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
while ((c = getc(f))!= EOF)
|
||||
putc(c, active);
|
||||
(void) fclose(f);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: misc.c,v 1.30 2003/11/17 17:12:10 espie Exp $ */
|
||||
/* $OpenBSD: misc.c,v 1.31 2005/05/29 18:44:36 espie Exp $ */
|
||||
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
|
||||
|
||||
/*
|
||||
@ -37,7 +37,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
static char rcsid[] = "$OpenBSD: misc.c,v 1.30 2003/11/17 17:12:10 espie Exp $";
|
||||
static char rcsid[] = "$OpenBSD: misc.c,v 1.31 2005/05/29 18:44:36 espie Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -119,13 +119,33 @@ pbstr(const char *s)
|
||||
void
|
||||
pbnum(int n)
|
||||
{
|
||||
pbnumbase(n, 10, 0);
|
||||
}
|
||||
|
||||
void
|
||||
pbnumbase(int n, int base, int d)
|
||||
{
|
||||
static char digits[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
int num;
|
||||
int printed = 0;
|
||||
|
||||
if (base > 36)
|
||||
errx(1, "base %d > 36: not supported", base);
|
||||
|
||||
if (base < 2)
|
||||
errx(1, "bad base %d for conversion", base);
|
||||
|
||||
num = (n < 0) ? -n : n;
|
||||
do {
|
||||
putback(num % 10 + '0');
|
||||
putback(digits[num % base]);
|
||||
printed++;
|
||||
}
|
||||
while ((num /= 10) > 0);
|
||||
while ((num /= base) > 0);
|
||||
|
||||
if (n < 0)
|
||||
printed++;
|
||||
while (printed++ < d)
|
||||
putback('0');
|
||||
|
||||
if (n < 0)
|
||||
putback('-');
|
||||
|
Loading…
Reference in New Issue
Block a user