YAZ  5.23.1
grs1disp.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  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 
17 #include <yaz/proto.h>
18 #include <yaz/oid_db.h>
19 
20 static void display_variant(WRBUF w, Z_Variant *v, int level)
21 {
22  int i;
23 
24  for (i = 0; i < v->num_triples; i++)
25  {
26  wrbuf_printf(w, "%*sclass=" ODR_INT_PRINTF ",type=" ODR_INT_PRINTF,
27  level * 4, "", *v->triples[i]->zclass,
28  *v->triples[i]->type);
30  wrbuf_printf(w, ",value=%s\n",
32  else
33  wrbuf_printf(w, "\n");
34  }
35 }
36 
37 static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
38 {
39  int i;
40 
41  if (!r)
42  {
43  return;
44  }
45  for (i = 0; i < r->num_elements; i++)
46  {
47  Z_TaggedElement *t;
48 
49  wrbuf_printf(w, "%*s", level * 4, "");
50  t = r->elements[i];
51  wrbuf_printf(w, "(");
52  if (t->tagType)
53  wrbuf_printf(w, ODR_INT_PRINTF ",", *t->tagType);
54  else
55  wrbuf_printf(w, "?,");
58  else
59  wrbuf_printf(w, "%s) ", t->tagValue->u.string);
61  {
62  if (!t->content->u.subtree)
63  printf (" (no subtree)\n");
64  else
65  {
66  wrbuf_printf(w, "\n");
67  display_grs1(w, t->content->u.subtree, level+1);
68  }
69  }
70  else if (t->content->which == Z_ElementData_string)
71  {
72  wrbuf_puts(w, t->content->u.string);
73  wrbuf_puts(w, "\n");
74  }
75  else if (t->content->which == Z_ElementData_numeric)
76  {
78  }
79  else if (t->content->which == Z_ElementData_oid)
80  {
81  Odr_oid *ip = t->content->u.oid;
82 
83  if (ip)
84  {
85  char oid_name_str[OID_STR_MAX];
86  oid_class oclass;
87  const char *oid_name
88  = yaz_oid_to_string_buf(ip, &oclass, oid_name_str);
89 
90  if (oid_name)
91  wrbuf_printf(w, "OID: %s\n", oid_name);
92  }
93  }
95  wrbuf_printf(w, "[No data requested]\n");
97  wrbuf_printf(w, "[Element empty]\n");
99  wrbuf_printf(w, "[Element not there]\n");
100  else if (t->content->which == Z_ElementData_date)
101  wrbuf_printf(w, "Date: %s\n", t->content->u.date);
102  else if (t->content->which == Z_ElementData_ext)
103  {
104  printf ("External\n");
105  /* we cannot print externals here. Srry */
106  }
107  else
108  wrbuf_printf(w, "? type = %d\n",t->content->which);
109  if (t->appliedVariant)
110  display_variant(w, t->appliedVariant, level+1);
111  if (t->metaData && t->metaData->supportedVariants)
112  {
113  int c;
114 
115  wrbuf_printf(w, "%*s---- variant list\n", (level+1)*4, "");
116  for (c = 0; c < t->metaData->num_supportedVariants; c++)
117  {
118  wrbuf_printf(w, "%*svariant #%d\n", (level+1)*4, "", c);
119  display_variant(w, t->metaData->supportedVariants[c], level+2);
120  }
121  }
122  }
123 }
124 
126 {
127  display_grs1(wrbuf, r, 0);
128 }
129 
130 /*
131  * Local variables:
132  * c-basic-offset: 4
133  * c-file-style: "Stroustrup"
134  * indent-tabs-mode: nil
135  * End:
136  * vim: shiftwidth=4 tabstop=8 expandtab
137  */
138 
int which
Definition: z-grs.h:69
Z_StringOrNumeric * tagValue
Definition: z-grs.h:61
Odr_int * type
Definition: z-grs.h:150
Odr_int * tagType
Definition: z-grs.h:60
Odr_int * numeric
Definition: z-core.h:1322
Odr_int * zclass
Definition: z-grs.h:149
Z_InternationalString * internationalString
Definition: z-grs.h:154
const char * yaz_oid_to_string_buf(const Odr_oid *oid, oid_class *oclass, char *buf)
maps any OID to string (named or dot-notation)
Definition: oid_db.c:99
void wrbuf_puts(WRBUF b, const char *buf)
appends C-string to WRBUF
Definition: wrbuf.c:89
Z_ElementData * content
Definition: z-grs.h:63
short Odr_oid
Definition: oid_util.h:42
string buffer
Definition: wrbuf.h:42
#define Z_ElementData_subtree
Definition: z-grs.h:96
char * date
Definition: z-grs.h:73
static void display_variant(WRBUF w, Z_Variant *v, int level)
Definition: grs1disp.c:20
void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags)
Performs "pretty" display of GRS-1 record to WRBUF.
Definition: grs1disp.c:125
Header for OID database.
#define Z_StringOrNumeric_numeric
Definition: z-core.h:1324
#define Z_ElementData_ext
Definition: z-grs.h:87
#define Z_ElementData_date
Definition: z-grs.h:86
static void display_grs1(WRBUF w, Z_GenericRecord *r, int level)
Definition: grs1disp.c:37
#define Z_Triple_internationalString
Definition: z-grs.h:162
Z_GenericRecord * subtree
Definition: z-grs.h:83
void wrbuf_printf(WRBUF b, const char *fmt,...)
writes printf result to WRBUF
Definition: wrbuf.c:178
Z_Triple ** triples
Definition: z-grs.h:175
Z_ElementMetaData * metaData
Definition: z-grs.h:64
Z_InternationalString * string
Definition: z-grs.h:75
Header for Z39.50 Protocol.
#define OID_STR_MAX
Definition: oid_util.h:40
#define Z_ElementData_oid
Definition: z-grs.h:90
#define ODR_INT_PRINTF
Definition: odr.h:49
int num_triples
Definition: z-grs.h:174
#define Z_ElementData_noDataRequested
Definition: z-grs.h:94
Z_Variant ** supportedVariants
Definition: z-grs.h:107
oid_class
Definition: oid_db.h:45
#define Z_ElementData_elementEmpty
Definition: z-grs.h:93
union Z_Triple::@105 value
union Z_ElementData::@104 u
Z_InternationalString * string
Definition: z-core.h:1321
union Z_StringOrNumeric::@75 u
#define Z_ElementData_numeric
Definition: z-grs.h:85
int num_supportedVariants
Definition: z-grs.h:106
#define Z_ElementData_elementNotThere
Definition: z-grs.h:92
Z_Variant * appliedVariant
Definition: z-grs.h:65
#define Z_ElementData_string
Definition: z-grs.h:88
Z_TaggedElement ** elements
Definition: z-grs.h:56
int which
Definition: z-grs.h:151
int num_elements
Definition: z-grs.h:55
Odr_int * numeric
Definition: z-grs.h:72
Odr_oid * oid
Definition: z-grs.h:77