1/*********************************************************************
2 *   Copyright 2009, UCAR/Unidata
3 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
4 *********************************************************************/
5
6#include "includes.h"
7#include "nc_iter.h"
8
9#ifdef ENABLE_JAVA
10
11#include <math.h>
12
13static int j_uid = 0;
14
15static int
16j_charconstant(GeneratorgeneratorSymbolsymBytebuffercodebuf, ...)
17{
18    /* Escapes and quoting will be handled in genc_write */
19    /* Just transfer charbuf to codebuf */
20    Bytebuffercharbuf;
21    va_list ap;
22    vastart(ap,codebuf);
23    charbuf = va_arg(apBytebuffer*);
24    va_end(ap);
25    bbNull(charbuf);
26    bbCatbuf(codebuf,charbuf);
27    return 1;
28}
29
30static int
31j_constant(GeneratorgeneratorSymbolsymNCConstantconBytebufferbuf,...)
32{
33    Bytebuffercodetmp = bbNew();
34    char* special = NULL;
35
36    switch (con->nctype) {
37    case NC_CHAR:
38 if(con->value.charv == '\'')
39     bbprintf(codetmp,"'\\''");
40 else
41     bbprintf(codetmp,"'%c'",con->value.charv);
42 break;
43    case NC_BYTE:
44 bbprintf(codetmp,"%hhd",con->value.int8v);
45 break;
46    case NC_SHORT:
47 bbprintf(codetmp,"%hd",con->value.int16v);
48 break;
49    case NC_INT:
50 bbprintf(codetmp,"%d",con->value.int32v);
51 break;
52    case NC_FLOAT:
53 /* Special case for nan */
54 if(isnan(con->value.floatv))
55     bbprintf(codetmp,"Float.NaN");
56 else
57     bbprintf(codetmp,"%f",con->value.floatv);
58 break;
59    case NC_DOUBLE:
60 /* Special case for nan */
61 if(isnan(con->value.doublev))
62     bbprintf(codetmp,"Double.NaN");
63 else
64     bbprintf(codetmp,"%lf",con->value.doublev);
65 break;
66    case NC_UBYTE:
67        bbprintf(codetmp,"%hhu",con->value.uint8v);
68 break;
69    case NC_USHORT:
70 bbprintf(codetmp,"%hu",con->value.uint16v);
71 break;
72    case NC_UINT:
73 bbprintf(codetmp,"%uU",con->value.uint32v);
74 break;
75    case NC_INT64:
76 bbprintf(codetmp,"%lldLL",con->value.int64v);
77 break;
78    case NC_UINT64:
79 bbprintf(codetmp,"%lluLLU",con->value.uint64v);
80 break;
81    case NC_STRING: { /* handle separately */
82 char* escaped = escapify(con->value.stringv.stringv,
83  '"',con->value.stringv.len);
84 special = poolalloc(1+2+strlen(escaped));
85 strcpy(special,"\"");
86 strcat(special,escaped);
87 strcat(special,"\"");
88 } break;
89
90    default: PANIC1("ncstype: bad type code: %d",con->nctype);
91
92    }
93    if(special == NULL)
94        bbCatbuf(buf,codetmp);
95    else
96 bbCat(buf,special);
97    bbFree(codetmp);
98    return 1;
99}
100
101static int
102j_listbegin(GeneratorgeneratorSymbolsym, void* liststateListClass lc, size_t sizeBytebuffercodebuf, int* uidp, ...)
103{
104    if(uidp) *uidp = ++j_uid;
105    switch (lc) {
106    case LISTATTR:
107    case LISTDATA:
108 break;
109    case LISTFIELDARRAY:
110    case LISTVLEN:
111    case LISTCOMPOUND:
112 break;
113    }
114    return 1;
115}
116
117static int
118j_list(GeneratorgeneratorSymbolsym, void* liststateListClass lc, int uid, size_t countBytebuffercodebuf, ...)
119{
120    switch (lc) {
121    case LISTATTR:
122        if(count > 0) bbCat(codebuf,", ");
123 break;
124    case LISTDATA:
125        bbCat(codebuf," ");
126 break;
127    case LISTVLEN:
128    case LISTCOMPOUND:
129    case LISTFIELDARRAY:
130 break;
131    }
132    return 1;
133}
134
135static int
136j_listend(GeneratorgeneratorSymbolsym, void* liststateListClass lc, int uid, size_t countBytebufferbuf, ...)
137{
138    return 1;
139}
140
141static int
142j_vlendecl(GeneratorgeneratorSymboltsymBytebuffercodebuf, int uid, size_t count, ...)
143{
144    return 1;
145}
146
147static int
148j_vlenstring(GeneratorgeneratorSymbolsymBytebuffervlenmem, int* uidp, size_t* countp,...)
149{
150    if(uidp) *uidp = ++j_uid;
151    if(countp) *countp = 0;
152    return 1;
153}
154
155
156/* Define the single static bin data generator  */
157static Generator j_generator_singleton = {
158    NULL,
159    j_charconstant,
160    j_constant,
161    j_listbegin,
162    j_list,
163    j_listend,
164    j_vlendecl,
165    j_vlenstring
166};
167Generatorj_generator = &j_generator_singleton;
168
169#endif /*ENABLE_JAVA*/


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