2 Iso2709 record management
7 Revision 1.3 1995/02/10 17:05:18 adam
8 New function iso2709_display to display MARC records in a
9 line-by-line format. The iso2709_cvt function no longer
10 prints the record to stderr.
12 * Revision 1.2 1995/02/10 16:50:32 adam
13 * Indicator field moved to 'struct iso2709_dir' from 'struct
15 * Function iso2709_rm implemented - to delete a MARC record.
17 * Revision 1.1.1.1 1995/02/09 17:27:11 adam
18 * Initial version of email gateway under CVS control.
30 static int atoin (const char *buf, int n)
36 val = val*10 + (*buf - '0');
42 static void strncpyx (char *d, const char *s, int n)
44 while (--n >= 0 && *s)
45 if (*s != ISO2709_IDFS)
59 char *iso2709_read (FILE *inf)
65 if (fread (length_str, 1, 5, inf) != 5)
67 size = atoin (length_str, 5);
70 if (!(buf = malloc (size+1)))
72 if (fread (buf+5, 1, size-5, inf) != (size-5))
77 memcpy (buf, length_str, 5);
82 Iso2709Rec iso2709_cvt (const char *buf)
84 struct iso2709_dir **dpp, *dp;
88 if (!(p = malloc (sizeof(*p))))
91 /* deal with record label (24 characters) */
92 p->record_length = atoin (buf, 5);
93 strncpyx (p->record_status, buf+5, 1);
94 strncpyx (p->implementation_codes, buf+6, 4);
95 p->indicator_length = atoin (buf+10, 1);
96 p->identifier_length = atoin (buf+11, 1);
97 p->base_address = atoin (buf+12, 4);
98 strncpyx (p->user_systems, buf+17, 3);
100 p->length_data_entry = atoin (buf+20, 1);
101 p->length_starting = atoin (buf+21, 1);
102 p->length_implementation = atoin (buf+22, 1);
103 strncpyx (p->future_use, buf+23, 1);
105 /* deal with directory */
108 while (buf[pos] != ISO2709_FS)
110 *dpp = malloc (sizeof(**dpp));
112 strncpyx ((*dpp)->tag, buf+pos, 3);
114 (*dpp)->length = atoin (buf+pos, p->length_data_entry);
115 pos += p->length_data_entry;
116 (*dpp)->offset = atoin (buf+pos, p->length_starting);
117 pos += p->length_starting + p->length_implementation;
122 /* deal with datafields */
123 for (dp = p->directory; dp; dp = dp->next)
126 struct iso2709_field **fpp;
127 int dpos = pos+dp->offset;
131 *fpp = malloc (sizeof(**fpp));
133 if (p->indicator_length && memcmp (dp->tag, "00", 2))
135 dp->indicator = malloc (p->indicator_length+1);
136 strncpyx (dp->indicator, buf+dpos, p->indicator_length);
137 dpos += p->indicator_length;
140 dp->indicator = NULL;
142 if (memcmp (dp->tag, "00", 2))
149 if (p->identifier_length && !tag00)
151 (*fpp)->identifier = malloc (p->identifier_length+1);
152 strncpyx ((*fpp)->identifier, buf+dpos+1,
153 p->identifier_length-1);
154 dpos += p->identifier_length;
157 (*fpp)->identifier = NULL;
160 while (buf[dpos_n] != ISO2709_FS && buf[dpos_n] != ISO2709_IDFS)
163 (*fpp)->data = malloc (dpos_n - dpos + 1);
164 strncpyx ((*fpp)->data, buf+dpos, dpos_n - dpos);
167 if (buf[dpos] == ISO2709_FS)
171 *fpp = malloc (sizeof(**fpp));
178 void iso2709_rm (Iso2709Rec rec)
180 struct iso2709_dir *dir, *dir1;
182 for (dir = rec->directory; dir; dir = dir1)
184 struct iso2709_field *field, *field1;
186 for (field = dir->fields; field; field = field1)
188 free (field->identifier);
190 field1 = field->next;
193 free (dir->indicator);