-/* $OpenBSD: eval.c,v 1.25 2000/03/11 15:54:43 espie Exp $ */
+/* $OpenBSD: eval.c,v 1.26 2000/03/18 01:06:55 espie Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
#if 0
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$OpenBSD: eval.c,v 1.25 2000/03/11 15:54:43 espie Exp $";
+static char rcsid[] = "$OpenBSD: eval.c,v 1.26 2000/03/18 01:06:55 espie Exp $";
#endif
#endif /* not lint */
static void doundiv __P((const char *[], int));
static void dosub __P((const char *[], int));
static void map __P((char *, const char *, const char *, const char *));
+static const char *handledash __P((char *, char *, const char *));
/*
* eval - evaluate built-in macros.
* argc - number of elements in argv.
const char *argv[];
int argc;
{
+ /* In gnu-m4 mode, having two empty arguments means no quotes at
+ * all. */
+ if (mimic_gnu) {
+ if (argc > 3 && !*argv[2] && !*argv[3]) {
+ lquote[0] = EOS;
+ rquote[0] = EOS;
+ return;
+ }
+ }
if (argc > 2) {
if (*argv[2])
strlcpy(lquote, argv[2], sizeof(lquote));
{
const char *tmp;
unsigned char sch, dch;
+ static char frombis[257];
+ static char tobis[257];
static unsigned char mapvec[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
};
if (*src) {
+ if (mimic_gnu) {
+ /*
+ * expand character ranges on the fly
+ */
+ from = handledash(frombis, frombis + 256, from);
+ to = handledash(tobis, tobis + 256, to);
+ }
tmp = from;
/*
* create a mapping between "from" and
}
*dest = '\0';
}
+
+
+/*
+ * handledash:
+ * use buffer to copy the src string, expanding character ranges
+ * on the way.
+ */
+static const char *
+handledash(buffer, end, src)
+ char *buffer;
+ char *end;
+ const char *src;
+{
+ char *p;
+
+ p = buffer;
+ 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;
+ }
+ }
+ src += 3;
+ } else
+ *p++ = *src++;
+ if (p == end)
+ break;
+ }
+ *p = '\0';
+ return buffer;
+}
+
-.\" @(#) $OpenBSD: m4.1,v 1.11 2000/03/11 15:54:44 espie Exp $
+.\" @(#) $OpenBSD: m4.1,v 1.12 2000/03/18 01:06:55 espie Exp $
.\"
.\"
.Dd January 26, 1993
.Nd macro language processor
.Sh SYNOPSIS
.Nm m4
+.Op Fl g
.Oo
.Fl D Ns Ar name Ns Op Ar =value
.Oc
.Ic changequote
built-in macro.
.Pp
-Some built-ins don't make any sense without arguments, and hence are not
+Most built-ins don't make any sense without arguments, and hence are not
recognized as special when not followed by an open parenthesis.
.Pp
The options are as follows:
Add directory
.Ar dirname
to the include path.
+.It Fl g
+Activate GNU-m4 compatibility mode. In this mode, changequote with
+two empty parameters deactivates quotes, translit handles simple character
+ranges (e.g., a-z) and regular expressions mimic emacs behavior.
.Sh SYNTAX
.Nm m4
provides the following built-in macros.
-/* $OpenBSD: main.c,v 1.31 2000/03/11 15:54:44 espie Exp $ */
+/* $OpenBSD: main.c,v 1.32 2000/03/18 01:06:56 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.31 2000/03/11 15:54:44 espie Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.32 2000/03/18 01:06:56 espie Exp $";
#endif
#endif /* not lint */
initkwds();
initspaces();
- while ((c = getopt(argc, argv, "tD:U:o:I:")) != -1)
+ while ((c = getopt(argc, argv, "gtD:U:o:I:")) != -1)
switch(c) {
case 'D': /* define something..*/
case 'U': /* undefine... */
remhash(optarg, TOP);
break;
+ case 'g':
+ mimic_gnu = 1;
+ break;
case 'o': /* specific output */
case '?':
usage();