/* ------------------------------------------------ Copyright 2014 AT&T Intellectual Property Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ------------------------------------------- */ #include #include #include #include #include "gsconfig.h" #include "gstypes.h" #include FILE * ifd; FILE * ofd; FILE * sfd; #define MAX_GDAT_HEADER 10000 gs_int8_t buf[2*MAXTUPLESZ]; gs_int8_t schema_buf[MAX_GDAT_HEADER]; gs_int8_t header_buf[MAX_GDAT_HEADER]; gs_retval_t read_tuple(gs_uint32_t * sz, gs_sp_t data, gs_int32_t maxlen) { gs_uint32_t nsz; static gs_uint32_t read=0; again: if (fread(&nsz,sizeof(gs_uint32_t),1,ifd)!=1) { exit(0); } read=read+sizeof(gs_uint32_t); *sz=ntohl(nsz); if ((*sz)>maxlen) { fprintf(stderr,"INTERNAL ERROR tuple to long for fixed buffer. Tuple sz %u\n", (*sz)); *sz=0; return 0; } if (*sz==0) goto again; if (fread(data,(*sz),1,ifd)!=1) { fprintf(stderr,"UNEXPECTED END OF FILE. Tried to read tuple of size %u\n", (*sz)); exit(0); } read=read+*sz; return 0; } int main(int argc, char** argv) { gs_schemahandle_t schema; gs_uint32_t rsize; gs_int8_t rbuf[2*MAXTUPLESZ]; gs_int8_t wbuf[2*MAXTUPLESZ]; gs_int32_t numberoffields; gs_int32_t verbose=0; gs_int32_t y; gs_int32_t parserversion; gs_uint32_t schemalen; gs_sp_t me; gs_int32_t ch; me=argv[0]; if (argc<2) { fprintf(stderr, "%s::usage: %s -v -x \n", me,me); exit(1); } while ((ch = getopt(argc, argv, "vx")) != -1) { switch(ch) { case 'v': verbose=1; break; case 'x': verbose=2; } } argc -= optind; if (argc < 1) { fprintf(stderr,"%s::usage: %s -v -x \n", me,me); exit(1); } argv += optind; if ((sfd=fopen(argv[0],"r"))==0) { fprintf(stderr,"%s::error:could not open schema file %s\n", me,argv[0]); exit(1); } schemalen = fread(schema_buf, 1, MAX_GDAT_HEADER, sfd); schema_buf[schemalen] = 0; schema = ftaschema_parse_string_prot(schema_buf); if (schema < 0) { fprintf(stderr,"%s::error:unable to parse schema file %s\n", me,argv[0]); exit(1); } fclose(sfd); argv++; if ((strcmp(argv[0],"-")!=0)&&(strcmp(argv[0],"stdin")!=0)) { if ((ifd=fopen(argv[0],"r"))==0) { fprintf(stderr,"%s::error:could not open input file %s\n", me,argv[0]); exit(1); } } else { ifd = stdin; } argv++; if ((ofd=fopen(argv[0],"wb"))==0) { fprintf(stderr,"%s::error:could not open output file %s\n", me,argv[0]); exit(1); } parserversion = get_schemaparser_version(); // write GDAT header sprintf(header_buf,"GDAT\nVERSION:%u\nSCHEMALENGTH:%lu\n", parserversion,schemalen+1); // need to get ASCII version of schema fwrite(header_buf,strlen(header_buf),1,ofd); fwrite(schema_buf,schemalen+1,1,ofd); ///////////////////////////////////////////// if ((numberoffields=ftaschema_tuple_len(schema))<0) { fprintf(stderr,"%s::error:could not get number of fields in schema\n", me); exit(1); } if (verbose==1) { for(y=0; y