2 * FML interpreter. Europagate, 1995
5 * Revision 1.1 1995/02/10 15:50:56 adam
6 * MARC interface implemented. Minor bugs fixed. fmltest can
7 * be used to format single MARC records. New function '\list'
21 struct fml_node *marc_to_fml (Fml fml, Iso2709Rec rec)
23 struct fml_node *ptr_0 = NULL, *ptr_1;
24 struct iso2709_dir *dir;
26 for (dir = rec->directory; dir; dir=dir->next)
30 ptr = fml_node_alloc (fml);
40 struct iso2709_field *fields = dir->fields;
42 ptr = fml_node_alloc (fml);
43 ptr->p[0] = fml_atom_alloc (fml, fields->data);
46 while ((fields = fields->next))
48 ptr = ptr->p[0] = fml_node_alloc (fml);
49 ptr->p[0] = fml_atom_alloc (fml, fields->data);
58 static void add_string (const char *str, char **buf, int *max, int *size)
60 if (*size + strlen(str) >= *max)
63 int nsize = *size + strlen(str) + 2048;
65 nbuf = malloc (nsize);
75 strcpy (*buf + *size, str);
79 char *marc_to_str (Fml fml, Iso2709Rec rec)
81 struct iso2709_dir *dir;
82 static char *buf = NULL;
86 add_string ("{", &buf, &max, &size);
87 for (dir = rec->directory; dir; dir=dir->next)
89 struct iso2709_field *fields;
91 add_string ("{", &buf, &max, &size);
92 add_string (dir->tag, &buf, &max, &size);
93 add_string ("{", &buf, &max, &size);
95 for (fields = dir->fields; fields; fields=fields->next)
97 add_string ("{", &buf, &max, &size);
99 if (fields->indicator)
101 add_string ("\'", &buf, &max, &size);
102 add_string (fields->indicator, &buf, &max, &size);
103 add_string ("\'", &buf, &max, &size);
106 add_string ("{}", &buf, &max, &size);
107 add_string (" ", &buf, &max, &size);
108 if (fields->identifier)
110 add_string ("\'", &buf, &max, &size);
111 add_string (fields->identifier, &buf, &max, &size);
112 add_string ("\'", &buf, &max, &size);
115 add_string ("{}", &buf, &max, &size);
116 add_string (" ", &buf, &max, &size);
117 add_string ("\'", &buf, &max, &size);
118 add_string (fields->data, &buf, &max, &size);
119 add_string ("\'", &buf, &max, &size);
120 add_string ("}", &buf, &max, &size);
122 add_string ("}}\n", &buf, &max, &size);
124 add_string ("}", &buf, &max, &size);