diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2012-04-12 17:00:12 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2012-04-12 17:00:12 +0000 |
commit | 9fcb2f01c668956044de8fbda3588daa44668125 (patch) | |
tree | 4ea33725b56a7a84d45b477bcdaf9b5975a9eff6 /usr.bin/m4 | |
parent | b62a38f7a63f839572d350e11cddb5eb541227a7 (diff) |
new m4 -g stuff:
- expr(`4**3')
- include(`hey I am not there') keeps going.
work with Baptiste Daroussin, who had the idea but didn't nail all details
right.
okay otto@, miod@
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/m4/eval.c | 11 | ||||
-rw-r--r-- | usr.bin/m4/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/m4/main.c | 6 | ||||
-rw-r--r-- | usr.bin/m4/parser.y | 5 | ||||
-rw-r--r-- | usr.bin/m4/tokenizer.l | 3 |
6 files changed, 23 insertions, 11 deletions
diff --git a/usr.bin/m4/Makefile b/usr.bin/m4/Makefile index fbaf9183805..16e1b6560e0 100644 --- a/usr.bin/m4/Makefile +++ b/usr.bin/m4/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.11 2004/05/12 21:17:03 espie Exp $ +# $OpenBSD: Makefile,v 1.12 2012/04/12 17:00:11 espie Exp $ # -DEXTENDED # if you want the paste & spaste macros. @@ -8,8 +8,8 @@ CFLAGS+=-DEXTENDED -I. CDIAGFLAGS=-W -Wall -Wstrict-prototypes -pedantic \ -Wno-unused -Wno-char-subscripts -Wno-sign-compare -LDADD= -ly -ll -DPADD= ${LIBY} ${LIBL} +LDADD= -ly -ll -lm +DPADD= ${LIBY} ${LIBL} ${LIBM} SRCS= eval.c expr.c look.c main.c misc.c gnum4.c trace.c tokenizer.l parser.y MAN= m4.1 diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 4bcfbf28589..c76801adec0 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.69 2011/03/24 11:23:08 espie Exp $ */ +/* $OpenBSD: eval.c,v 1.70 2012/04/12 17:00:11 espie Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /* @@ -264,8 +264,13 @@ expand_builtin(const char *argv[], int argc, int td) case INCLTYPE: if (argc > 2) if (!doincl(argv[2])) - err(1, "%s at line %lu: include(%s)", - CURRENT_NAME, CURRENT_LINE, argv[2]); + if (mimic_gnu) { + warn("%s at line %lu: include(%s)", + CURRENT_NAME, CURRENT_LINE, argv[2]); + exit_code = 1; + } else + err(1, "%s at line %lu: include(%s)", + CURRENT_NAME, CURRENT_LINE, argv[2]); break; case SINCTYPE: diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index a988cffcb27..ef59ad7aee4 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.51 2011/09/27 07:24:02 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.52 2012/04/12 17:00:11 espie Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -86,6 +86,7 @@ extern ndptr macro_getbuiltin(const char *); /* main.c */ extern void outputstr(const char *); extern void do_emit_synchline(void); +extern int exit_code; #define emit_synchline() do { if (synch_lines) do_emit_synchline(); } while(0) /* misc.c */ diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 851ff374b89..4c5af0ad0cc 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.80 2011/09/27 07:24:02 espie Exp $ */ +/* $OpenBSD: main.c,v 1.81 2012/04/12 17:00:11 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -165,6 +165,8 @@ static void enlarge_stack(void); int main(int, char *[]); +int exit_code = 0; + int main(int argc, char *argv[]) { @@ -283,7 +285,7 @@ main(int argc, char *argv[]) (void) fclose(outfile[0]); } - return 0; + return exit_code; } /* diff --git a/usr.bin/m4/parser.y b/usr.bin/m4/parser.y index 2c63ae92d4c..5b46d261a9a 100644 --- a/usr.bin/m4/parser.y +++ b/usr.bin/m4/parser.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: parser.y,v 1.6 2008/08/21 21:00:14 espie Exp $ */ +/* $OpenBSD: parser.y,v 1.7 2012/04/12 17:00:11 espie Exp $ */ /* * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org> * @@ -15,6 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <math.h> #include <stdint.h> #define YYSTYPE int32_t extern int32_t end_result; @@ -33,6 +34,7 @@ extern int yyerror(const char *); %left LSHIFT RSHIFT %left '+' '-' %left '*' '/' '%' +%right EXPONENT %right UMINUS UPLUS '!' '~' %% @@ -41,6 +43,7 @@ top : expr { end_result = $1; } ; expr : expr '+' expr { $$ = $1 + $3; } | expr '-' expr { $$ = $1 - $3; } + | expr EXPONENT expr { $$ = pow($1, $3); } | expr '*' expr { $$ = $1 * $3; } | expr '/' expr { if ($3 == 0) { diff --git a/usr.bin/m4/tokenizer.l b/usr.bin/m4/tokenizer.l index 7da63086add..4adabd7e98f 100644 --- a/usr.bin/m4/tokenizer.l +++ b/usr.bin/m4/tokenizer.l @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: tokenizer.l,v 1.7 2010/03/22 20:40:44 espie Exp $ */ +/* $OpenBSD: tokenizer.l,v 1.8 2012/04/12 17:00:11 espie Exp $ */ /* * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org> * @@ -53,6 +53,7 @@ radix 0[rR][0-9]+:[0-9a-zA-Z]+ "!=" { return(NE); } "&&" { return(LAND); } "||" { return(LOR); } +"**" { if (mimic_gnu) { return (EXPONENT); } } . { return yytext[0]; } %% |