1/*********************************************************************
2 *   Copyright 2009, UCAR/Unidata
3 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
4 *********************************************************************/
5/* $Id: dump.c,v 1.3 2010/05/24 19:59:57 dmh Exp $ */
6/* $Header: /upc/share/CVS/netcdf-3/ncgen/dump.c,v 1.3 2010/05/24 19:59:57 dmh Exp $ */
7
8#include "includes.h"
9#include "dump.h"
10
11#define DEBUGSRC
12
13/* Forward */
14static void dumpdataprim(NCConstant*,Bytebuffer*);
15
16char*
17indentstr(int n)
18{
19    static char indentline[1024];
20    memset(indentline,' ',n+1);
21    indentline[n+1] = '\0';
22    return indentline;
23}
24
25
26void
27dumpconstant(NCConstantcon, char* tag)
28{
29    Bytebufferbuf = bbNew();
30    Datalistdl = builddatalist(1);
31    dlappend(dl,con);
32    bufdump(dl,buf);
33    fprintf(stderr,"%s: %s\n",tag,bbContents(buf));
34    bbFree(buf);
35}
36
37void
38dumpdatalist(Datalistlist, char* tag)
39{
40    Bytebufferbuf = bbNew();
41    bufdump(list,buf);
42    fprintf(stderr,"%s: %s\n",tag,bbContents(buf));
43    bbFree(buf);
44}
45
46void
47bufdump(DatalistlistBytebufferbuf)
48{
49    int i;
50    NCConstantdp;
51    unsigned int count;
52
53    if(list == NULL) {
54 bbCat(buf,"NULL");
55 return;
56    }
57
58    count = list->length;
59    for(dp=list->data,i=0;i<count;i++,dp++) {
60       switch (dp->nctype) {
61        case NC_COMPOUND:
62     bbCat(buf,"{");
63     bufdump(dp->value.compoundv,buf);
64     bbCat(buf,"}");
65            break;
66        case NC_ARRAY:
67     bbCat(buf,"[");
68     bufdump(dp->value.compoundv,buf);
69     bbCat(buf,"]");
70            break;
71        case NC_VLEN:
72     bbCat(buf,"{*");
73     bufdump(dp->value.compoundv,buf);
74     bbCat(buf,"}");
75            break;
76 default:
77     if(isprimplus(dp->nctype) || dp->nctype == NC_FILLVALUE) {
78                bbCat(buf," ");
79                dumpdataprim(dp,buf);
80     } else {
81           char tmp[64];
82         sprintf(tmp,"?%d? ",dp->nctype);
83            bbCat(buf,tmp);
84            } break;
85 }
86    }
87}
88
89
90static void
91dumpdataprim(NCConstantciBytebufferbuf)
92{
93    char tmp[64];
94    ASSERT(isprimplus(ci->nctype) || ci->nctype == NC_FILLVALUE);
95    switch (ci->nctype) {
96    case NC_CHAR: {
97 bbCat(buf,"'");
98 escapifychar(ci->value.charv,tmp,'\'');
99 bbCat(buf,tmp);
100 bbCat(buf,"'");
101 } break;
102    case NC_BYTE:
103 sprintf(tmp,"%hhd",ci->value.int8v);
104 bbCat(buf,tmp);
105 break;
106    case NC_SHORT:
107 sprintf(tmp,"%hd",ci->value.int16v);
108 bbCat(buf,tmp);
109 break;
110    case NC_INT:
111 sprintf(tmp,"%d",ci->value.int32v);
112 bbCat(buf,tmp);
113 break;
114    case NC_FLOAT:
115 sprintf(tmp,"%g",ci->value.floatv);
116 bbCat(buf,tmp);
117 break;
118    case NC_DOUBLE:
119 sprintf(tmp,"%lg",ci->value.doublev);
120 bbCat(buf,tmp);
121 break;
122    case NC_UBYTE:
123 sprintf(tmp,"%hhu",ci->value.int8v);
124 bbCat(buf,tmp);
125 break;
126    case NC_USHORT:
127 sprintf(tmp,"%hu",ci->value.uint16v);
128 bbCat(buf,tmp);
129 break;
130    case NC_UINT:
131 sprintf(tmp,"%u",ci->value.uint32v);
132 bbCat(buf,tmp);
133 break;
134    case NC_INT64:
135 sprintf(tmp,"%lld",ci->value.int64v);
136 bbCat(buf,tmp);
137 break;
138    case NC_UINT64:
139 sprintf(tmp,"%llu",ci->value.uint64v);
140 bbCat(buf,tmp);
141 break;
142    case NC_ECONST:
143 sprintf(tmp,"%s",ci->value.enumv->fqn);
144 bbCat(buf,tmp);
145 break;
146    case NC_STRING:
147 bbCat(buf,"\"");
148 bbCat(buf,ci->value.stringv.stringv);
149 bbCat(buf,"\"");
150 break;
151    case NC_OPAQUE:
152 bbCat(buf,"0x");
153 bbCat(buf,ci->value.opaquev.stringv);
154 break;
155    case NC_FILLVALUE:
156 bbCat(buf,"_");
157 break;
158    default: PANIC1("dumpdataprim: bad type code:%d",ci->nctype);
159    }
160}
161
162void
163dumpgroup(Symbolg)
164{
165    if(debug <= 1) return;
166    fdebug("group %s {\n",(g==NULL?"null":g->name));
167    if(g != NULL && g->subnodes != NULL) {
168 int i;
169 for(i=0;i<listlength(g->subnodes);i++) {
170     Symbolsym = (Symbol*)listget(g->subnodes,i);
171     char* tname;
172     if(sym->objectclass == NC_PRIM
173        || sym->objectclass == NC_TYPE) {
174 tname = nctypename(sym->subclass);
175     } else
176 tname = nctypename(sym->objectclass);
177     fdebug("    %3d:  %s\t%s\t%s\n",
178 i,
179 sym->name,
180 tname,
181 (sym->ref.is_ref?"ref":"")
182 );
183 }
184    }
185    fdebug("}\n");
186}
187
188void
189dumpconstant1(NCConstantcon)
190{
191    switch (con->nctype) {
192    case NC_COMPOUND: {
193 Datalistdl = con->value.compoundv;
194 Bytebufferbuf = bbNew();
195 bufdump(dl,buf);
196/* fprintf(stderr,"(0x%lx){",(unsigned long)dl);*/
197 fprintf(stderr,"{%s}",bbDup(buf));
198 bbFree(buf);
199 } break;
200    case NC_STRING:
201 if(con->value.stringv.len > 0 && con->value.stringv.stringv != NULL)
202     fprintf(stderr,"\"%s\"",con->value.stringv.stringv);
203 else
204     fprintf(stderr,"\"\"");
205 break;
206    case NC_OPAQUE:
207 if(con->value.opaquev.len > 0 && con->value.opaquev.stringv != NULL)
208     fprintf(stderr,"0x%s",con->value.opaquev.stringv);
209 else
210     fprintf(stderr,"0x--");
211 break;
212    case NC_ECONST:
213 fprintf(stderr,"%s",(con->value.enumv==NULL?"?":con->value.enumv->name));
214 break;
215    case NC_FILLVALUE:
216 fprintf(stderr,"_");
217 break;
218    case NC_CHAR:
219 fprintf(stderr,"'%c'",con->value.charv);
220 break;
221    case NC_BYTE:
222 fprintf(stderr,"%hhd",con->value.int8v);
223 break;
224    case NC_UBYTE:
225 fprintf(stderr,"%hhu",con->value.uint8v);
226 break;
227    case NC_SHORT:
228 fprintf(stderr,"%hd",con->value.int16v);
229 break;
230    case NC_USHORT:
231 fprintf(stderr,"%hu",con->value.uint16v);
232 break;
233    case NC_INT:
234 fprintf(stderr,"%d",con->value.int32v);
235 break;
236    case NC_UINT:
237 fprintf(stderr,"%u",con->value.uint32v);
238 break;
239    case NC_INT64:
240 fprintf(stderr,"%lld",con->value.int64v);
241 break;
242    case NC_UINT64:
243 fprintf(stderr,"%llu",con->value.uint64v);
244 break;
245    case NC_FLOAT:
246 fprintf(stderr,"%g",con->value.floatv);
247 break;
248    case NC_DOUBLE:
249 fprintf(stderr,"%g",con->value.doublev);
250 break;
251    default:
252 fprintf(stderr,"<unknown>");
253 break;
254    }
255    fflush(stderr);
256}
257
258#define MAXELEM 8
259#define MAXDEPTH 4
260
261void
262dumpsrc0(Datasrcsrc,char* tag)
263{
264    int icountindexdepth;
265    depth = MAXDEPTH;
266    count = src->length;
267    index = src->index;
268    if(count > MAXELEMcount = MAXELEM;
269    if(index > countindex = count;
270    fprintf(stderr,"%s:: ",(tag?tag:""));
271    do {
272        fprintf(stderr,"[%d/%d]",src->index,src->length);
273 for(i=0;i<index;i++) {
274     fprintf(stderr," ");
275     dumpconstant1(&src->data[i]);
276 }
277 fprintf(stderr,"^");
278 for(i=index;i<count;i++) {
279     fprintf(stderr," ");
280     dumpconstant1(&src->data[i]);
281 }
282        if(count < src->length) fprintf(stderr,"...");
283 fprintf(stderr," | ");
284        src = src->prev;
285    } while(src != NULL && depth > 0);
286    if(src != NULL) fprintf(stderr,"---");
287    fprintf(stderr,"\n");
288    fflush(stderr);
289}
290
291void
292dumpsrc(Datasrcsrc,char* tag)
293{
294#ifndef DEBUGSRC
295    if(debug == 0) return;
296#endif
297    dumpsrc0(src,tag);
298}


HyperKWIC - Version 7.20DA executed at 11:37 on 27 Oct 2017 | Polyhedron Solutions - INTERNAL USE | COMMERCIAL (Any O/S) SN 4AKIed