Parsing a data file
To parse a data file, a bindrv reader context has to be allocated with a call to bindrv_newreader. This initialisation routine requires a callback function that is used for inputing data from some stream (e.g. use the C function fread to read from a file opened with the function fopen). The reader procedure has then to enter a loop calling first bindrv_nexttoken to get the type of the next token to read and then, depending on this data type, use the function suitable to read and decode this token. For instance if the function returns BINDRV_TYP_REAL, a real has to be read and the function bindrv_getreal can be used to get its value. If the file structure is known in advance, the data can be input with a sequence of calls to the decoding functions. For instance the data file of the example of the preceding section could be input with the following code:
int a,c; char *l; if(bindrv_getctrl(bctx,&c)==0 && (c==1)) { while(bindrv_getint(bctx,&a)==0) printf("got: %d\n",a); if(bindrv_getctrl(bctx,&c)!=0 || (c!=2)) exit(1); } if(bindrv_getctrl(bctx,&c)==0 && (c==4)) { while(bindrv_getstring(bctx,&l)==0) { printf("got: %s\n",l); free(l); } if(bindrv_getctrl(bctx,&c)!=0 || (c!=2)) exit(2); } if(bindrv_getctrl(bctx,&c)!=0 || (c!=3)) exit(3);
As shown above, the application is in charge of releasing string buffers returned by bindrv_getstring: this routine allocates the returned memory block using the C function malloc. The application may replace this default memory allocator by calling function bindrv_setalloc.
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.