Changed header.
[egate.git] / fml / fmlstr.c
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmlstr.c,v $
5  * Revision 1.3  1995/02/23 08:32:06  adam
6  * Changed header.
7  *
8  * Revision 1.1  1995/02/10  18:15:53  adam
9  * FML function 'strcmp' implemented. This function can be used to
10  * test for existence of MARC fields.
11  *
12  */
13
14 #include <assert.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17
18 #include "fmlp.h"
19
20 static struct fml_node *fml_exec_strcmp (Fml fml, struct fml_node **lp, 
21                                          struct token *tp)
22 {
23     char *arg;
24     struct fml_node *fn = NULL, *fn1, *fn2;
25     int n;
26
27     fml_cmd_lex (lp, tp);
28
29     fn1 = fml_expr_term (fml, lp, tp);
30     fn2 = fml_expr_term (fml, lp, tp);
31     if (!fn1->is_atom && !fn2->is_atom)
32         fn = NULL;
33     n = fml_atom_cmp (fml, fn1->p[0], fn2->p[0]);
34     if (n == 0)
35         arg = "0";
36     else if (n > 0)
37         arg = "1";
38     else 
39         arg = "-1";
40     fn = fml_node_alloc (fml);
41     fn->is_atom = 1;
42     fn->p[0] = fml_atom_alloc (fml, arg);
43     return fn;
44 }
45
46 void fml_str_init (Fml fml)
47 {
48     struct fml_sym_info *sym_info;
49
50     sym_info = fml_sym_add (fml->sym_tab, "strcmp");
51     sym_info->kind = FML_CPREFIX;
52     sym_info->prefix = fml_exec_strcmp;
53 }