First implementation of iso2709_a_insert.
* Europagate, 1994-1995.
*
* $Log: iso2709.c,v $
- * Revision 1.12 1995/03/29 16:08:56 adam
+ * Revision 1.13 1995/03/30 07:33:32 adam
+ * New 2709 function: iso2709_mk.
+ * First implementation of iso2709_a_insert.
+ *
+ * Revision 1.12 1995/03/29 16:08:56 adam
* Better error recovery when using bad records.
*
* Revision 1.11 1995/03/28 16:07:07 adam
return buf;
}
+Iso2709Rec iso2709_mk (void)
+{
+ Iso2709Rec p;
+
+ if (!(p = malloc (sizeof(*p))))
+ return NULL;
+
+ p->record_length = 0;
+ strncpyx (p->record_status, " ", 1);
+ strncpyx (p->implementation_codes, " ", 4);
+ p->indicator_length = 2;
+ p->identifier_length = 2;
+ p->base_address = 0;
+ strncpyx (p->user_systems, " ", 3);
+ p->length_data_entry = 4;
+ p->length_starting = 5;
+ p->length_implementation = 0;
+ strncpyx (p->future_use, " ", 1);
+
+ p->directory = NULL;
+ return p;
+}
Iso2709Rec iso2709_cvt (const char *buf)
{
* Europagate, 1995.
*
* $Log: iso2709a.c,v $
- * Revision 1.1 1995/03/29 11:44:29 adam
+ * Revision 1.2 1995/03/30 07:33:35 adam
+ * New 2709 function: iso2709_mk.
+ * First implementation of iso2709_a_insert.
+ *
+ * Revision 1.1 1995/03/29 11:44:29 adam
* New functions: iso2709_a_.. for record manipulation.
*
*/
anchor->d0 = &rec->directory;
if (*anchor->d0)
anchor->f0 = &(*anchor->d0)->fields;
+ else
+ anchor->f0 = NULL;
return anchor;
}
return 0;
}
-int iso2709_a_insert (Iso2709Anchor anchor,
+int iso2709_a_insert (Iso2709Anchor a,
const char *tag, const char *indicator,
const char *identifier, const char *data)
{
- return 0;
+ struct iso2709_field *field;
+
+ assert (data);
+ assert (tag);
+ assert (a->d0);
+ if (! *a->d0 || strcmp (tag, (*a->d0)->tag))
+ {
+ struct iso2709_dir *dir;
+
+ if (!(dir = malloc (sizeof(*dir))))
+ return 0;
+ strcpy (dir->tag, tag);
+ if (indicator)
+ {
+ if (!(dir->indicator = malloc (strlen(indicator)+1)))
+ return 0;
+ strcpy (dir->indicator, indicator);
+ }
+ else
+ dir->indicator = NULL;
+ dir->next = *a->d0;
+ *a->d0 = dir;
+ dir->fields = NULL;
+ a->f0 = &dir->fields;
+ }
+ if (!(field = malloc (sizeof(*field))))
+ return 0;
+ if (identifier)
+ {
+ if (!(field->identifier = malloc (strlen (identifier)+1)))
+ return 0;
+ strcpy (field->identifier, identifier);
+ }
+ else
+ field->identifier = NULL;
+ if (!(field->data = malloc (strlen (data)+1)))
+ return 0;
+ strcpy (field->data, data);
+ field->next = *a->f0;
+ *a->f0 = field;
+ a->f0 = &field->next;
+ return 1;
}
-
* Europagate, 1994-1995.
*
* $Log: iso2709dump.c,v $
- * Revision 1.7 1995/03/28 16:07:07 adam
+ * Revision 1.8 1995/03/30 07:33:37 adam
+ * New 2709 function: iso2709_mk.
+ * First implementation of iso2709_a_insert.
+ *
+ * Revision 1.7 1995/03/28 16:07:07 adam
* New function: iso2709_out. This function is the reverse of iso2709_cvt.
*
* Revision 1.6 1995/03/27 12:52:18 adam
static char *prog;
+static Iso2709Rec copy_rec (Iso2709Rec rec_in)
+{
+ Iso2709Rec rec_out;
+ Iso2709Anchor a_in, a_out;
+ char *tag, *indicator, *identifier, *data;
+
+ rec_out = iso2709_mk();
+
+ a_in = iso2709_a_mk (rec_in);
+ a_out = iso2709_a_mk (rec_out);
+
+ do {
+ if (!iso2709_a_info_field (a_in, &tag, &indicator, &identifier, &data))
+ break;
+ printf ("[%s %s %s]", tag, indicator ? indicator : "",
+ identifier ? identifier : "");
+#if 1
+ iso2709_a_insert (a_out, tag, indicator, identifier, data);
+#endif
+ } while (iso2709_a_next (a_in));
+ iso2709_a_rm (a_in);
+ iso2709_a_rm (a_out);
+ return rec_out;
+}
+
int main (int argc, char **argv)
{
char *buf;
- Iso2709Rec rec;
int no = 0;
int start_pos = 0;
int end_pos = 99999;
char *output_file = NULL;
char *input_file = NULL;
+ char *filter = NULL;
int verbose = 0;
int quiet = 0;
FILE *outf = NULL;
case 'q':
quiet = 1;
break;
+ case 'f':
+ if (argv[0][2])
+ filter = argv[0]+2;
+ else if (argc > 0)
+ {
+ --argc;
+ filter = *++argv;
+ }
+ else
+ {
+ fprintf (stderr, "%s: missing filter\n", prog);
+ exit (1);
+ }
+ break;
default:
fprintf (stderr, "%s: unknown option %s; use -h for help\n",
prog, *argv);
{
char *obuf;
int olen;
+ Iso2709Rec rec_input;
+ Iso2709Rec rec_output;
- rec = iso2709_cvt (buf);
+ rec_input = iso2709_cvt (buf);
if (!quiet)
printf ("------- %d --------\n", no);
- if (!rec)
+ if (!rec_input)
{
if (!quiet)
printf ("Bad record\n");
fprintf (stderr, "%s: bad record at position %d\n", prog, no);
break;
}
- olen = iso2709_out (rec, &obuf, 0);
+ olen = iso2709_out (rec_input, &obuf, 0);
+ rec_output = copy_rec (rec_input);
if (!quiet)
- iso2709_display (rec, stdout);
+ {
+ iso2709_display (rec_input, stdout);
+ }
if (outf && fwrite (obuf, 1, olen, outf) != olen)
{
fprintf (stderr, "%s: write fail of %s: %s\n",
exit (1);
}
free (obuf);
- iso2709_rm (rec);
+ iso2709_rm (rec_input);
}
free (buf);
no++;