YAZ 5.35.1
oid_util.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
5
11#if HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15#include <stdlib.h>
16#include <string.h>
17
18#include <yaz/yaz-iconv.h>
19#include <yaz/snprintf.h>
20#include <yaz/oid_util.h>
21
22void oid_oidcpy(Odr_oid *t, const Odr_oid *s)
23{
24 while ((*(t++) = *(s++)) > -1);
25}
26
27void oid_oidcat(Odr_oid *t, const Odr_oid *s)
28{
29 while (*t > -1)
30 t++;
31 while ((*(t++) = *(s++)) > -1);
32}
33
34int oid_oidcmp(const Odr_oid *o1, const Odr_oid *o2)
35{
36 while (*o1 == *o2 && *o1 > -1)
37 {
38 o1++;
39 o2++;
40 }
41 if (*o1 == *o2)
42 return 0;
43 else if (*o1 > *o2)
44 return 1;
45 else
46 return -1;
47}
48
49int oid_oidlen(const Odr_oid *o)
50{
51 int len = 0;
52
53 while (*(o++) >= 0)
54 len++;
55 return len;
56}
57
58
59char *oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
60{
61 char tmpbuf[20];
62 int i;
63
64 oidbuf[0] = '\0';
65 for (i = 0; oid[i] != -1 && i < OID_SIZE; i++)
66 {
67 yaz_snprintf(tmpbuf, sizeof(tmpbuf)-1, "%d", oid[i]);
68 if (i > 0)
69 strcat(oidbuf, ".");
70 strcat(oidbuf, tmpbuf);
71 }
72 return oidbuf;
73}
74
75int oid_dotstring_to_oid(const char *name, Odr_oid *oid)
76{
77 int i = 0;
78 int val = 0;
79 while (yaz_isdigit (*name))
80 {
81 val = val*10 + (*name - '0');
82 name++;
83 if (*name == '.')
84 {
85 if (i < OID_SIZE-1)
86 oid[i++] = val;
87 val = 0;
88 name++;
89 }
90 }
91 if (i == 0)
92 return -1;
93 oid[i] = val;
94 oid[i+1] = -1;
95 return 0;
96}
97
98/*
99 * Local variables:
100 * c-basic-offset: 4
101 * c-file-style: "Stroustrup"
102 * indent-tabs-mode: nil
103 * End:
104 * vim: shiftwidth=4 tabstop=8 expandtab
105 */
106
char * name
Definition initopt.c:18
int oid_dotstring_to_oid(const char *name, Odr_oid *oid)
converts dot string to OID
Definition oid_util.c:75
void oid_oidcat(Odr_oid *t, const Odr_oid *s)
appends to OID
Definition oid_util.c:27
char * oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
converts OID to string (dot notation)
Definition oid_util.c:59
void oid_oidcpy(Odr_oid *t, const Odr_oid *s)
copies OID
Definition oid_util.c:22
int oid_oidcmp(const Odr_oid *o1, const Odr_oid *o2)
compares OIDs
Definition oid_util.c:34
int oid_oidlen(const Odr_oid *o)
returns length of OIDs
Definition oid_util.c:49
Header for OID basic functions.
short Odr_oid
Definition oid_util.h:42
#define OID_SIZE
Definition oid_util.h:39
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Definition snprintf.c:31
Header for config file reading utilities.
Header for YAZ iconv interface.
#define yaz_isdigit(x)
Definition yaz-iconv.h:86