mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
add limited support for format builtin in gnu-m4 mode, because I'm fed
up of patching it away in various autoconf derivatives. okay miod@
This commit is contained in:
parent
fd5fa2e695
commit
09d1584fde
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.22 2005/09/06 15:33:21 espie Exp $
|
||||
# $OpenBSD: Makefile,v 1.23 2006/03/20 20:27:45 espie Exp $
|
||||
|
||||
FIBOMAX=25
|
||||
M4=m4
|
||||
@ -10,7 +10,8 @@ REGRESS_TARGETS= test-ff_after_dnl test-m4wrap test-m4wrap2 \
|
||||
test-m4wrap3 test-gm4wrap3 test-fibo \
|
||||
test-patterns trip test-strangequotes test-redef test-quotes \
|
||||
test-weird test-args test-esyscmd test-eval test-gnupatterns \
|
||||
test-gnupatterns2 test-comments test-synch1 test-synch1bis
|
||||
test-gnupatterns2 test-comments test-synch1 test-synch1bis \
|
||||
test-gnuformat
|
||||
|
||||
test-ff_after_dnl: ff_after_dnl.m4
|
||||
${M4} ff_after_dnl.m4 | diff - ${.CURDIR}/ff_after_dnl.out
|
||||
@ -39,6 +40,9 @@ test-gnupatterns:
|
||||
test-gnupatterns2:
|
||||
${M4} -g ${.CURDIR}/gnupatterns2.m4 | diff - ${.CURDIR}/gnupatterns2.out
|
||||
|
||||
test-gnuformat:
|
||||
${M4} -g ${.CURDIR}/gnuformat.m4 | diff - ${.CURDIR}/gnuformat.out
|
||||
|
||||
fibo.out:
|
||||
perl ${.CURDIR}/fibo.pl ${FIBOMAX} >$@
|
||||
|
||||
|
1
regress/usr.bin/m4/gnuformat.m4
Normal file
1
regress/usr.bin/m4/gnuformat.m4
Normal file
@ -0,0 +1 @@
|
||||
format(`a%15sa%%b%-15sbc%3scd%-3sd', `string', `pouet', `toolong', `toolong2')
|
1
regress/usr.bin/m4/gnuformat.out
Normal file
1
regress/usr.bin/m4/gnuformat.out
Normal file
@ -0,0 +1 @@
|
||||
a stringa%bpouet bctoolongcdtoolong2d
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: eval.c,v 1.60 2006/03/20 10:55:19 espie Exp $ */
|
||||
/* $OpenBSD: eval.c,v 1.61 2006/03/20 20:27:45 espie Exp $ */
|
||||
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
|
||||
|
||||
/*
|
||||
@ -283,6 +283,12 @@ expand_builtin(const char *argv[], int argc, int td)
|
||||
if (argc > 2)
|
||||
(void) dopaste(argv[2]);
|
||||
break;
|
||||
case FORMATTYPE:
|
||||
if (mimic_gnu)
|
||||
doformat(argv, argc);
|
||||
else
|
||||
m4errx(1, "format builtin is only available in gnu-m4 mode.");
|
||||
break;
|
||||
#endif
|
||||
case CHNQTYPE:
|
||||
dochq(argv, ac);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.44 2006/03/20 10:55:19 espie Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.45 2006/03/20 20:27:45 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -55,7 +55,8 @@ extern void doprintlineno(struct input_file *);
|
||||
extern void doprintfilename(struct input_file *);
|
||||
|
||||
extern void doesyscmd(const char *);
|
||||
extern void getdivfile(const char *);
|
||||
extern void getdivfile(const char *);
|
||||
extern void doformat(const char *[], int);
|
||||
|
||||
|
||||
/* look.c */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: gnum4.c,v 1.32 2006/03/20 10:55:19 espie Exp $ */
|
||||
/* $OpenBSD: gnum4.c,v 1.33 2006/03/20 20:27:45 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Marc Espie
|
||||
@ -502,6 +502,52 @@ doregexp(const char *argv[], int argc)
|
||||
regfree(&re);
|
||||
}
|
||||
|
||||
void
|
||||
doformat(const char *argv[], int argc)
|
||||
{
|
||||
const char *format = argv[2];
|
||||
int pos = 3;
|
||||
while (*format != 0) {
|
||||
if (*format != '%') {
|
||||
addchar(*format++);
|
||||
} else {
|
||||
format++;
|
||||
if (*format == '%' || *format == 0) {
|
||||
addchar('%');
|
||||
if (*format == '%')
|
||||
format++;
|
||||
} else {
|
||||
int left_padded = 0;
|
||||
unsigned long width;
|
||||
size_t l;
|
||||
|
||||
if (*format == '-') {
|
||||
left_padded = 1;
|
||||
format++;
|
||||
}
|
||||
width = strtoul(format, &format, 10);
|
||||
if (*format != 's') {
|
||||
m4errx(1, "Unsupported format specification: %s.", argv[2]);
|
||||
}
|
||||
format++;
|
||||
if (pos >= argc)
|
||||
m4errx(1, "Format with too many values.");
|
||||
l = strlen(argv[pos]);
|
||||
if (!left_padded) {
|
||||
while (l < width--)
|
||||
addchar(' ');
|
||||
}
|
||||
addchars(argv[pos++], l);
|
||||
if (left_padded) {
|
||||
while (l < width--)
|
||||
addchar(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pbstr(getstring());
|
||||
}
|
||||
|
||||
void
|
||||
doesyscmd(const char *cmd)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" @(#) $OpenBSD: m4.1,v 1.43 2005/09/30 20:34:26 jaredy Exp $
|
||||
.\" @(#) $OpenBSD: m4.1,v 1.44 2006/03/20 20:27:45 espie Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -251,6 +251,16 @@ specifies the minimum number of digits in the result.
|
||||
.It Fn expr expr
|
||||
This is an alias for
|
||||
.Ic eval .
|
||||
.It Fn format formatstring arg1 ...
|
||||
Returns
|
||||
.Fa formatstring
|
||||
with escape sequences substituted with
|
||||
.Fa arg1
|
||||
and following arguments, in a way similar to
|
||||
.Xr printf 3 .
|
||||
This built-in is only available in GNU-m4 compatibility mode, and the
|
||||
left-padding flag, an optional field width and the %s data type
|
||||
are the only supported parameters.
|
||||
.It Fn ifdef name yes no
|
||||
If the macro named by the first argument is defined then return the second
|
||||
argument, otherwise the third.
|
||||
@ -439,6 +449,7 @@ For portability, one should not use the macros
|
||||
.Ic builtin ,
|
||||
.Ic esycmd ,
|
||||
.Ic expr ,
|
||||
.Ic format ,
|
||||
.Ic indir ,
|
||||
.Ic paste ,
|
||||
.Ic patsubst ,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.70 2006/03/20 10:55:19 espie Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.71 2006/03/20 20:27:45 espie Exp $ */
|
||||
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
|
||||
|
||||
/*-
|
||||
@ -111,6 +111,7 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
|
||||
{ "esyscmd", ESYSCMDTYPE},
|
||||
{ "__file__", FILENAMETYPE | NOARGS},
|
||||
{ "__line__", LINETYPE | NOARGS},
|
||||
{ "format", FORMATTYPE},
|
||||
#endif
|
||||
{ "popdef", POPDTYPE },
|
||||
{ "pushdef", PUSDTYPE },
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: mdef.h,v 1.28 2003/06/30 22:13:33 espie Exp $ */
|
||||
/* $OpenBSD: mdef.h,v 1.29 2006/03/20 20:27:45 espie Exp $ */
|
||||
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
|
||||
|
||||
/*
|
||||
@ -84,6 +84,7 @@
|
||||
#define ESYSCMDTYPE 41
|
||||
#define TRACEONTYPE 42
|
||||
#define TRACEOFFTYPE 43
|
||||
#define FORMATTYPE 44
|
||||
|
||||
#define BUILTIN_MARKER "__builtin_"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user