1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
18 #include <schemaparser.h>
24 gs_retval_t read_tuple(gs_uint32_t * sz, gs_sp_t data, gs_int32_t maxlen) {
26 static gs_uint32_t read=0;
28 if (fread(&nsz,sizeof(gs_uint32_t),1,ifd)!=1) {
32 read=read+sizeof(gs_uint32_t);
35 fprintf(stderr,"INTERNAL ERROR tuple to long for fixed buffer. Tuple sz %u\n",
40 if (*sz==0) goto again;
41 if (fread(data,(*sz),1,ifd)!=1) {
42 fprintf(stderr,"UNEXPECTED END OF FILE. Tryed to read tuple of size %u\n",
50 int main(int argc, char** argv) {
52 gs_schemahandle_t schema;
54 gs_uint32_t rstreamid;
56 gs_int8_t rbuf[2*MAXTUPLESZ];
58 gs_int32_t numberoffields;
60 gs_int32_t truncate=-1;
62 gs_int32_t parserversion;
63 gs_uint32_t schemalen;
67 gs_uint32_t scramble =0;
68 gs_uint32_t schema_only =0;
70 /* initialize host library and the sgroup */
76 "%s::usage: %s -v -x -t <int> -s <int> <uncompressed_file_name>\n",
81 while ((ch = getopt(argc, argv, "ps:t:vx")) != -1) {
93 truncate=atoi(optarg);
96 sscanf(optarg,"%u",&scramble);
101 fprintf(stderr,"%s::usage: %s -v -x -t <int> <uncompressed_file_name>\n",
107 if ((strcmp(argv[0],"-")!=0)&&(strcmp(argv[0],"stdin")!=0)) {
108 if ((ifd=fopen(argv[0],"r"))==0) {
109 fprintf(stderr,"%s::error:could not open input file %s\n",
117 if (fscanf(ifd,"GDAT\nVERSION:%u\nSCHEMALENGTH:%u\n",&parserversion,&schemalen)!=2) {
118 fprintf(stderr,"%s::error:unknown file type for file %s\n",
123 if (schemaparser_accepts_version(parserversion)!=1) {
124 fprintf(stderr,"%s::error: wrong parser version %u for file %s\n",
125 me,parserversion,argv[0]);
129 if ((asciischema=malloc(schemalen))==0) {
130 fprintf(stderr,"%s::error: could not allocate schema buffer of sz %u "
132 me,schemalen,argv[0]);
136 if (fread(asciischema,schemalen,1,ifd)!=1) {
137 fprintf(stderr,"%s::error: could not read schema buffer of sz %u "
139 me,schemalen,argv[0]);
142 if (schema_only==1) {
143 fprintf(stdout,"%s\n",asciischema);
146 fprintf(stderr,"%s\n",asciischema);
148 if ((schema=ftaschema_parse_string(asciischema))<0) {
149 fprintf(stderr,"%s::error: could not parse schema "
155 if ((numberoffields=ftaschema_tuple_len(schema))<0) {
156 fprintf(stderr,"%s::error:could not get number of fields in schema\n",
161 for(y=0; y<numberoffields;y++) {
162 printf("%s",ftaschema_field_name(schema,y));
163 if (y<numberoffields-1) printf("|");
167 while(read_tuple(&rsize,rbuf,2*MAXTUPLESZ)==0) {
168 if ((!rsize) || (schema_only==1))
170 for(y=0; y<numberoffields;y++) {
171 struct access_result ar;
173 printf("%s->",ftaschema_field_name(schema,y));
174 ar=ftaschema_get_field_by_index(schema,y,rbuf,rsize);
175 switch (ar.field_data_type) {
180 printf("%u",ar.r.ui);
184 ar.r.ui=gscpbswap32(ar.r.ui^scramble);
186 printf("%u.%u.%u.%u",ar.r.ui>>24&0xff,
195 for(x=0;x<4;x++) { if (ar.r.ip6.v[x]==0) zc++;}
198 unsigned char * a = (unsigned char *) &(ar.r.ip6.v[0]);
200 y=((unsigned)a[2*x])<<8|((unsigned) a[2*x+1]);
202 if (x<7) printf(":");
210 printf("%u",ar.r.ui);
229 printf("%lld",ar.r.l);
248 src=(gs_sp_t)ar.r.vs.offset;
249 if ((truncate>=0) && (ar.r.vs.length>truncate)) {
250 ar.r.vs.length=truncate;
252 if ((ar.r.vs.length>0) && (src[ar.r.vs.length-1]==0)) {
253 ar.r.vs.length = ar.r.vs.length-1;
255 for(x=0;x<ar.r.vs.length;x++) {
257 if (((c<='~') && (c>=' '))&&(c!='|')) {
260 printf("(0x%x)",(gs_uint8_t)c);
268 if (y<numberoffields-1) printf("|");
271 if (verbose!=0) fflush(stdout);