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