2 * Iso2709 record management
7 * Revision 1.2 1995/03/30 14:22:19 adam
8 * More work on new MARC anchor functions.
10 * Revision 1.1 1995/03/28 16:07:07 adam
11 * New function: iso2709_out. This function is the reverse of iso2709_cvt.
23 static void memint (char *p, int val, int len)
31 sprintf (buf, "%08d", val);
32 memcpy (p, buf+8-len, len);
36 int iso2709_out (Iso2709Rec p, char **buf, int bsize)
38 struct iso2709_field *field;
39 struct iso2709_dir *dir;
41 int base_address = 25;
45 for (dir = p->directory; dir; dir = dir->next)
47 len += 4 + p->length_data_entry + p->length_starting
48 + p->length_implementation;
49 base_address += 3 + p->length_data_entry + p->length_starting
50 + p->length_implementation;
52 len += p->indicator_length;
53 for (field = dir->fields; field; field = field->next)
55 if (*field->identifier)
56 len += p->identifier_length;
57 len += strlen (field->data);
75 memcpy (op+5, p->record_status, 1);
76 memcpy (op+6, p->implementation_codes, 4);
77 memint (op+10, p->indicator_length, 1);
78 memint (op+11, p->identifier_length, 1);
79 memint (op+12, base_address, 5);
80 memcpy (op+17, p->user_systems, 3);
81 memint (op+20, p->length_data_entry, 1);
82 memint (op+21, p->length_starting, 1);
83 memint (op+22, p->length_implementation, 1);
84 memcpy (op+23, p->future_use, 1);
87 data_p = base_address;
89 for (dir = p->directory; dir; dir = dir->next)
94 memcpy (op + data_p, dir->indicator, p->indicator_length);
95 data_p += p->indicator_length;
97 for (field = dir->fields; field; field = field->next)
99 if (*field->identifier)
101 op[data_p] = ISO2709_IDFS;
102 memcpy (op + data_p+1, field->identifier,
103 p->identifier_length-1);
104 data_p += p->identifier_length;
106 memcpy (op + data_p, field->data, strlen(field->data));
107 data_p += strlen(field->data);
109 op[data_p++] = ISO2709_FS;
111 memcpy (op + entry_p, dir->tag, 3);
113 memint (op + entry_p, data_p - data_0, p->length_data_entry);
114 entry_p += p->length_data_entry;
115 memint (op + entry_p, data_0 - base_address, p->length_starting);
116 entry_p += p->length_starting;
117 entry_p += p->length_implementation;
119 op[entry_p++] = ISO2709_FS;
120 assert (entry_p == base_address);
121 op[data_p++] = ISO2709_RS;
122 assert (data_p == len);