xref: /freebsd/usr.bin/m4/expr.c (revision eccad222770297bdd2787e31cd37b906edba62c6)
1a841e1ebSBaptiste Daroussin /* $OpenBSD: expr.c,v 1.18 2010/09/07 19:58:09 marco Exp $ */
29b50d902SRodney W. Grimes /*
3a841e1ebSBaptiste Daroussin  * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
49b50d902SRodney W. Grimes  *
5a841e1ebSBaptiste Daroussin  * Permission to use, copy, modify, and distribute this software for any
6a841e1ebSBaptiste Daroussin  * purpose with or without fee is hereby granted, provided that the above
7a841e1ebSBaptiste Daroussin  * copyright notice and this permission notice appear in all copies.
89b50d902SRodney W. Grimes  *
9a841e1ebSBaptiste Daroussin  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10a841e1ebSBaptiste Daroussin  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11a841e1ebSBaptiste Daroussin  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12a841e1ebSBaptiste Daroussin  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13a841e1ebSBaptiste Daroussin  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14a841e1ebSBaptiste Daroussin  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15a841e1ebSBaptiste Daroussin  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
169b50d902SRodney W. Grimes  */
179b50d902SRodney W. Grimes #include <sys/cdefs.h>
18acc9d408SJuli Mallett __FBSDID("$FreeBSD$");
19acc9d408SJuli Mallett 
20a841e1ebSBaptiste Daroussin #include <stdint.h>
219b50d902SRodney W. Grimes #include <stdio.h>
22a841e1ebSBaptiste Daroussin #include <stddef.h>
23acc9d408SJuli Mallett #include "mdef.h"
24acc9d408SJuli Mallett #include "extern.h"
259b50d902SRodney W. Grimes 
26a841e1ebSBaptiste Daroussin int32_t end_result;
27*eccad222SEd Schouten static const char *copy_toeval;
28a841e1ebSBaptiste Daroussin int yyerror(const char *msg);
299b50d902SRodney W. Grimes 
30a841e1ebSBaptiste Daroussin extern void yy_scan_string(const char *);
31a841e1ebSBaptiste Daroussin extern int yyparse(void);
329b50d902SRodney W. Grimes 
339b50d902SRodney W. Grimes int
34a841e1ebSBaptiste Daroussin yyerror(const char *msg)
359b50d902SRodney W. Grimes {
36a841e1ebSBaptiste Daroussin 	fprintf(stderr, "m4: %s in expr %s\n", msg, copy_toeval);
37a841e1ebSBaptiste Daroussin 	return(0);
389b50d902SRodney W. Grimes }
399b50d902SRodney W. Grimes 
40a841e1ebSBaptiste Daroussin int
41a841e1ebSBaptiste Daroussin expr(const char *toeval)
429b50d902SRodney W. Grimes {
43a841e1ebSBaptiste Daroussin 	copy_toeval = toeval;
44a841e1ebSBaptiste Daroussin 	yy_scan_string(toeval);
45a841e1ebSBaptiste Daroussin 	yyparse();
46a841e1ebSBaptiste Daroussin 	return end_result;
479b50d902SRodney W. Grimes }
48