2 * FML interpreter. Europagate, 1995
5 * Revision 1.4 1995/02/23 08:32:05 adam
8 * Revision 1.2 1995/02/10 16:52:08 adam
9 * Indicator field moved in MARC structure. The FML list representation
10 * of a MARC record has changed.
12 * Revision 1.1 1995/02/10 15:50:56 adam
13 * MARC interface implemented. Minor bugs fixed. fmltest can
14 * be used to format single MARC records. New function '\list'
29 struct fml_node *marc_to_fml (Fml fml, Iso2709Rec rec)
31 struct fml_node *ptr_0 = NULL, *ptr_1;
32 struct iso2709_dir *dir;
34 for (dir = rec->directory; dir; dir=dir->next)
38 ptr = fml_node_alloc (fml);
48 struct iso2709_field *fields = dir->fields;
50 ptr = fml_node_alloc (fml);
51 ptr->p[0] = fml_atom_alloc (fml, fields->data);
54 while ((fields = fields->next))
56 ptr = ptr->p[0] = fml_node_alloc (fml);
57 ptr->p[0] = fml_atom_alloc (fml, fields->data);
66 static void add_string (const char *str, char **buf, int *max, int *size)
68 if (*size + strlen(str) >= *max)
71 int nsize = *size + strlen(str) + 2048;
73 nbuf = malloc (nsize);
83 strcpy (*buf + *size, str);
87 char *marc_to_str (Fml fml, Iso2709Rec rec)
89 struct iso2709_dir *dir;
90 static char *buf = NULL;
94 add_string ("{", &buf, &max, &size);
95 for (dir = rec->directory; dir; dir=dir->next)
97 struct iso2709_field *fields;
99 add_string ("{\'", &buf, &max, &size);
100 add_string (dir->tag, &buf, &max, &size);
101 add_string ("\'",&buf, &max, &size);
104 add_string ("\'", &buf, &max, &size);
105 add_string (dir->indicator, &buf, &max, &size);
106 add_string ("\'", &buf, &max, &size);
109 add_string ("{}", &buf, &max, &size);
110 add_string ("{", &buf, &max, &size);
111 for (fields = dir->fields; fields; fields=fields->next)
113 add_string ("{", &buf, &max, &size);
114 if (fields->identifier)
116 add_string ("\'", &buf, &max, &size);
117 add_string (fields->identifier, &buf, &max, &size);
118 add_string ("\'", &buf, &max, &size);
121 add_string ("{}", &buf, &max, &size);
122 add_string (" \'", &buf, &max, &size);
123 add_string (fields->data, &buf, &max, &size);
124 add_string ("\'}", &buf, &max, &size);
126 add_string ("}}\n", &buf, &max, &size);
128 add_string ("}", &buf, &max, &size);