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