2347ef353aa1c882ec7e4c527b1a9bb2e47860c9
[yaz-moved-to-github.git] / odr / odr.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr.c,v $
7  * Revision 1.1  1995-03-07 09:23:15  quinn
8  * Installing top-level API and documentation.
9  *
10  *
11  */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include <odr.h>
17
18 char *odr_errlist[] =
19 {
20     "No (unknown) error",
21     "Memoy allocation failed",
22     "System error",
23     "No space in buffer",
24     "Required data element missing",
25     "Unexpected tag",
26     "Other error"
27 };
28
29 void odr_perror(ODR o, char *message)
30 {
31     fprintf(stderr, "%s: %s\n", message, odr_errlist[o->error]);
32 }
33
34 void odr_setprint(ODR o, FILE *file)
35 {
36     o->print = file;
37 }
38
39 ODR odr_createmem(int direction)
40 {
41     struct odr *r;
42
43     if (!(r = malloc(sizeof(*r))))
44         return 0;
45     r->direction = direction;
46     r->print = stdout;
47     r->buf = 0;
48     r->buflen = 0;
49     odr_reset(r);
50     return r;
51 }
52
53 void odr_reset(ODR o)
54 {
55     o->error = ONONE;
56     o->bp = 0;
57     o->left = o->buflen;
58     o->t_class = -1;
59     o->t_tag = -1;
60     o->indent = 0;
61     o->stackp = 0;
62 }
63     
64 void odr_destroy(ODR o)
65 {
66     free(o);
67 }