1 1.21 kre /* $NetBSD: expr.c,v 1.21 2019/03/26 23:31:45 kre Exp $ */ 2 1.19 christos /* $OpenBSD: expr.c,v 1.17 2006/01/20 23:10:19 espie Exp $ */ 3 1.5 glass /* 4 1.19 christos * Copyright (c) 2004 Marc Espie <espie (at) cvs.openbsd.org> 5 1.5 glass * 6 1.19 christos * Permission to use, copy, modify, and distribute this software for any 7 1.19 christos * purpose with or without fee is hereby granted, provided that the above 8 1.19 christos * copyright notice and this permission notice appear in all copies. 9 1.19 christos * 10 1.19 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 1.19 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 1.19 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 1.19 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 1.19 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 1.19 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 1.19 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 1.5 glass */ 18 1.16 jmc #if HAVE_NBTOOL_CONFIG_H 19 1.16 jmc #include "nbtool_config.h" 20 1.16 jmc #endif 21 1.8 lukem #include <sys/cdefs.h> 22 1.21 kre __RCSID("$NetBSD: expr.c,v 1.21 2019/03/26 23:31:45 kre Exp $"); 23 1.19 christos #include <stdint.h> 24 1.19 christos #include <stdio.h> 25 1.12 tv #include <stddef.h> 26 1.8 lukem #include "mdef.h" 27 1.8 lukem #include "extern.h" 28 1.8 lukem 29 1.19 christos int32_t end_result; 30 1.19 christos const char *copy_toeval; 31 1.5 glass 32 1.19 christos extern void yy_scan_string(const char *); 33 1.19 christos extern int yyparse(void); 34 1.19 christos extern int yyerror(const char *); 35 1.5 glass 36 1.5 glass int 37 1.19 christos yyerror(const char *msg) 38 1.5 glass { 39 1.21 kre fprintf(stderr, "m4:%s:%lu: %s in expr %s\n", infile[ilevel].name, 40 1.20 christos infile[ilevel].lineno, msg, copy_toeval); 41 1.19 christos return(0); 42 1.5 glass } 43 1.2 glass 44 1.19 christos int 45 1.19 christos expr(const char *toeval) 46 1.5 glass { 47 1.19 christos copy_toeval = toeval; 48 1.19 christos yy_scan_string(toeval); 49 1.19 christos yyparse(); 50 1.19 christos return end_result; 51 1.5 glass } 52