From: Adam Dickmeiss Date: Fri, 10 Feb 1995 18:15:51 +0000 (+0000) Subject: FML function 'strcmp' implemented. This function can be used to X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=3d645ef1f92e9cbacce6d9b9e7cfe739c8fe6b39;p=egate.git FML function 'strcmp' implemented. This function can be used to test for existence of MARC fields. --- diff --git a/fml/Makefile b/fml/Makefile index 995fad0..87c77d8 100644 --- a/fml/Makefile +++ b/fml/Makefile @@ -1,6 +1,6 @@ # FML interpreter. Europagate, 1995 # -# $Id: Makefile,v 1.5 1995/02/10 17:21:44 adam Exp $ +# $Id: Makefile,v 1.6 1995/02/10 18:15:51 adam Exp $ SHELL=/bin/sh INCLUDE=-I../include -I. @@ -9,7 +9,7 @@ CFLAGS=-g -Wall -pedantic DEFS=$(INCLUDE) LIB=fml.a PO = fmltoken.o fmlmem.o fml.o fmlsym.o fmlrel.o fmlarit.o fmllist.o \ -fmlcall.o fmlcalls.o fmlmarc.o +fmlcall.o fmlcalls.o fmlmarc.o fmlstr.o CPP=cc -E CC=gcc diff --git a/fml/fml.c b/fml/fml.c index d5f5af3..371d2b4 100644 --- a/fml/fml.c +++ b/fml/fml.c @@ -2,7 +2,11 @@ * FML interpreter. Europagate, 1995 * * $Log: fml.c,v $ - * Revision 1.7 1995/02/10 15:50:54 adam + * Revision 1.8 1995/02/10 18:15:52 adam + * FML function 'strcmp' implemented. This function can be used to + * test for existence of MARC fields. + * + * Revision 1.7 1995/02/10 15:50:54 adam * MARC interface implemented. Minor bugs fixed. fmltest can * be used to format single MARC records. New function '\list' * implemented. @@ -126,6 +130,7 @@ Fml fml_open (void) fml_list_init (fml); fml_arit_init (fml); fml_rel_init (fml); + fml_str_init (fml); sym_info = fml_sym_add (fml->sym_tab, "s"); sym_info->kind = FML_CPREFIX; diff --git a/fml/fmlmem.c b/fml/fmlmem.c index ce82b69..7e78ac8 100644 --- a/fml/fmlmem.c +++ b/fml/fmlmem.c @@ -2,7 +2,11 @@ * FML interpreter. Europagate, 1995 * * $Log: fmlmem.c,v $ - * Revision 1.5 1995/02/09 14:37:18 adam + * Revision 1.6 1995/02/10 18:15:52 adam + * FML function 'strcmp' implemented. This function can be used to + * test for existence of MARC fields. + * + * Revision 1.5 1995/02/09 14:37:18 adam * Removed .depend from cvs. Removed function fml_mk_list. * * Revision 1.4 1995/02/09 14:33:37 adam @@ -130,6 +134,24 @@ struct fml_atom *fml_atom_alloc (Fml fml, char *str) return a0; } +int fml_atom_cmp (Fml fml, struct fml_atom *a1, struct fml_atom *a2) +{ + while (a1 && a2) + { + int n; + n = strncmp (a1->buf, a2->buf, FML_ATOM_BUF); + if (n) + return n; + a1 = a1->next; + a2 = a2->next; + } + if (!a1 && !a2) + return 0; + if (a1) + return 1; + return -1; +} + int fml_atom_str (struct fml_atom *a, char *str) { int len = 0; diff --git a/fml/fmlp.h b/fml/fmlp.h index 9a4244e..99a2038 100644 --- a/fml/fmlp.h +++ b/fml/fmlp.h @@ -2,7 +2,11 @@ * FML interpreter. Europagate, 1995 * * $Log: fmlp.h,v $ - * Revision 1.7 1995/02/10 15:50:56 adam + * Revision 1.8 1995/02/10 18:15:52 adam + * FML function 'strcmp' implemented. This function can be used to + * test for existence of MARC fields. + * + * Revision 1.7 1995/02/10 15:50:56 adam * MARC interface implemented. Minor bugs fixed. fmltest can * be used to format single MARC records. New function '\list' * implemented. @@ -62,6 +66,7 @@ int fml_atom_val (struct fml_atom *a); void fml_node_delete (Fml fml, struct fml_node *fn); struct fml_node *fml_node_copy (Fml fml, struct fml_node *fn); struct fml_node *fml_mk_node_val (Fml fml, int val); +int fml_atom_cmp (Fml fml, struct fml_atom *a1, struct fml_atom *a2); struct token { int kind; @@ -119,6 +124,7 @@ void fml_node_stat (Fml fml); void fml_rel_init (Fml fml); void fml_arit_init (Fml fml); void fml_list_init (Fml fml); +void fml_str_init (Fml fml); void fml_lr_values (Fml fml, struct fml_node *l, int *left_val, struct fml_node *r, int *right_val); void fml_cmd_lex (struct fml_node **np, struct token *tp); diff --git a/fml/fmlstr.c b/fml/fmlstr.c new file mode 100644 index 0000000..440dabb --- /dev/null +++ b/fml/fmlstr.c @@ -0,0 +1,50 @@ +/* + * FML interpreter. Europagate, 1995 + * + * $Log: fmlstr.c,v $ + * Revision 1.1 1995/02/10 18:15:53 adam + * FML function 'strcmp' implemented. This function can be used to + * test for existence of MARC fields. + * + */ + +#include +#include +#include + +#include "fmlp.h" + +static struct fml_node *fml_exec_strcmp (Fml fml, struct fml_node **lp, + struct token *tp) +{ + char *arg; + struct fml_node *fn = NULL, *fn1, *fn2; + int n; + + fml_cmd_lex (lp, tp); + + fn1 = fml_expr_term (fml, lp, tp); + fn2 = fml_expr_term (fml, lp, tp); + if (!fn1->is_atom && !fn2->is_atom) + fn = NULL; + n = fml_atom_cmp (fml, fn1->p[0], fn2->p[0]); + if (n == 0) + arg = "0"; + else if (n > 0) + arg = "1"; + else + arg = "-1"; + fn = fml_node_alloc (fml); + fn->is_atom = 1; + fn->p[0] = fml_atom_alloc (fml, arg); + return fn; +} + +void fml_str_init (Fml fml) +{ + struct fml_sym_info *sym_info; + + sym_info = fml_sym_add (fml->sym_tab, "strcmp"); + sym_info->kind = FML_CPREFIX; + sym_info->prefix = fml_exec_strcmp; +} diff --git a/fml/fmltoken.c b/fml/fmltoken.c index fc4d189..fb34f14 100644 --- a/fml/fmltoken.c +++ b/fml/fmltoken.c @@ -2,7 +2,11 @@ * FML interpreter. Europagate, 1995 * * $Log: fmltoken.c,v $ - * Revision 1.3 1995/02/10 15:50:57 adam + * Revision 1.4 1995/02/10 18:15:53 adam + * FML function 'strcmp' implemented. This function can be used to + * test for existence of MARC fields. + * + * Revision 1.3 1995/02/10 15:50:57 adam * MARC interface implemented. Minor bugs fixed. fmltest can * be used to format single MARC records. New function '\list' * implemented. @@ -42,6 +46,11 @@ struct fml_node *fml_tokenize (Fml fml) fml_pr_list (p); printf ("\n"); } + if (look_char != fml->eof_mark) + { + fprintf (stderr, "Ill formed parantheses"); + exit (1); + } return p; } @@ -157,6 +166,24 @@ static void lexer (Fml fml) while (look_char != fml->eof_mark && look_char != '\'') { lex_buf[off++] = look_char; + if (look_char == '\\') + { + look_char = (*fml->read_func)(); + switch (look_char) + { + case 'n': + lex_buf[off-1] = '\n'; + break; + case 't': + lex_buf[off-1] = '\n'; + break; + case '\'': + lex_buf[off-1] = '\''; + break; + default: + lex_buf[off-1] = look_char; + } + } look_char = (*fml->read_func)(); } lex_buf[off] = '\0'; diff --git a/fml/marc.fml b/fml/marc.fml index 524efe6..f180e68 100644 --- a/fml/marc.fml +++ b/fml/marc.fml @@ -1,5 +1,5 @@ # Fml scripts to display MARC records -# $Id: marc.fml,v 1.2 1995/02/10 16:52:08 adam Exp $ +# $Id: marc.fml,v 1.3 1995/02/10 18:15:53 adam Exp $ \func f0 rec { \foreach line {\rec} { \line \index 1 \ @@ -13,4 +13,23 @@ \n } } +\func mline prefix suffix lin tag subfield { + \if {{\strcmp {\line \index 1} \tag}\eq 0} { + \foreach field {\lin \index 3} { + \if {{\strcmp {\field \index 1} \subfield}\eq 0} { + \prefix + \field \index 2 + \suffix + } + } + } +} + +\func f1 rec { + \foreach line {\rec} { + \mline 'Title: ' '\n' \line 245 a + \mline 'Author: ' {} \line 100 a + \mline ', ' '\n' \line 100 h + } +}