1 | /*
|
---|
2 | * Copyright (c) 1995-2000, Index Data
|
---|
3 | * See the file LICENSE for details.
|
---|
4 | *
|
---|
5 | * $Log$
|
---|
6 | * Revision 1.1 2000/08/03 03:11:26 johnmcp
|
---|
7 | * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
|
---|
8 | *
|
---|
9 | * Revision 1.19 2000/02/29 13:44:55 adam
|
---|
10 | * Check for config.h (currently not generated).
|
---|
11 | *
|
---|
12 | * Revision 1.18 2000/01/31 13:15:21 adam
|
---|
13 | * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
|
---|
14 | * that some characters are not surrounded by spaces in resulting term.
|
---|
15 | * ILL-code updates.
|
---|
16 | *
|
---|
17 | * Revision 1.17 1999/11/30 13:47:12 adam
|
---|
18 | * Improved installation. Moved header files to include/yaz.
|
---|
19 | *
|
---|
20 | * Revision 1.16 1999/04/20 09:56:48 adam
|
---|
21 | * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
|
---|
22 | * Modified all encoders/decoders to reflect this change.
|
---|
23 | *
|
---|
24 | * Revision 1.15 1999/01/08 11:23:29 adam
|
---|
25 | * Added const modifier to some of the BER/ODR encoding routines.
|
---|
26 | *
|
---|
27 | * Revision 1.14 1998/10/13 15:58:36 adam
|
---|
28 | * Minor fix in odr_getoidbystr_nmem.
|
---|
29 | *
|
---|
30 | * Revision 1.13 1998/02/11 11:53:34 adam
|
---|
31 | * Changed code so that it compiles as C++.
|
---|
32 | *
|
---|
33 | * Revision 1.12 1997/10/31 12:20:08 adam
|
---|
34 | * Improved memory debugging for xmalloc/nmem.c. References to NMEM
|
---|
35 | * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
|
---|
36 | * Bug fix: missing fclose in data1_read_espec1.
|
---|
37 | *
|
---|
38 | */
|
---|
39 | #if HAVE_CONFIG_H
|
---|
40 | #include <config.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <stdlib.h>
|
---|
44 | #include <string.h>
|
---|
45 | #include <ctype.h>
|
---|
46 | #include <yaz/odr.h>
|
---|
47 | #include <yaz/oid.h>
|
---|
48 |
|
---|
49 | void odr_prname(ODR o, const char *name)
|
---|
50 | {
|
---|
51 | if (name)
|
---|
52 | fprintf (o->print, "%*s%s ", o->indent*4, "", name);
|
---|
53 | else
|
---|
54 | fprintf (o->print, "%*s", o->indent*4, "");
|
---|
55 | }
|
---|
56 |
|
---|
57 | int odp_more_chunks(ODR o, const unsigned char *base, int len)
|
---|
58 | {
|
---|
59 | if (!len)
|
---|
60 | return 0;
|
---|
61 | if (len < 0) /* indefinite length */
|
---|
62 | {
|
---|
63 | if (*o->bp == 0 && *(o->bp + 1) == 0)
|
---|
64 | {
|
---|
65 | o->bp += 2;
|
---|
66 | return 0;
|
---|
67 | }
|
---|
68 | else
|
---|
69 | return 1;
|
---|
70 | }
|
---|
71 | else
|
---|
72 | return o->bp - base < len;
|
---|
73 | }
|
---|
74 |
|
---|
75 | Odr_oid *odr_oiddup_nmem(NMEM nmem, Odr_oid *o)
|
---|
76 | {
|
---|
77 | Odr_oid *r;
|
---|
78 |
|
---|
79 | if (!o)
|
---|
80 | return 0;
|
---|
81 | if (!(r = (int *)nmem_malloc(nmem, (oid_oidlen(o) + 1) * sizeof(int))))
|
---|
82 | return 0;
|
---|
83 | oid_oidcpy(r, o);
|
---|
84 | return r;
|
---|
85 | }
|
---|
86 |
|
---|
87 | Odr_oid *odr_oiddup(ODR odr, Odr_oid *o)
|
---|
88 | {
|
---|
89 | return odr_oiddup_nmem (odr->mem, o);
|
---|
90 | }
|
---|
91 |
|
---|
92 | Odr_oid *odr_getoidbystr_nmem(NMEM nmem, char *str)
|
---|
93 | {
|
---|
94 | int num = 1, i = 0;
|
---|
95 | char *p = str;
|
---|
96 | Odr_oid *ret;
|
---|
97 |
|
---|
98 | if (!isdigit(*str))
|
---|
99 | return 0;
|
---|
100 | while ((p = strchr(p, '.')))
|
---|
101 | num++, p++;
|
---|
102 | ret = (int *)nmem_malloc(nmem, sizeof(*ret)*(num + 1));
|
---|
103 | p = str;
|
---|
104 | do
|
---|
105 | ret[i++] = atoi(p);
|
---|
106 | while ((p = strchr(p, '.')) && *++p);
|
---|
107 | ret[i] = -1;
|
---|
108 | return ret;
|
---|
109 | }
|
---|
110 |
|
---|
111 | Odr_oid *odr_getoidbystr(ODR o, char *str)
|
---|
112 | {
|
---|
113 | return odr_getoidbystr_nmem (o->mem, str);
|
---|
114 | }
|
---|
115 |
|
---|