|
Creates a new XaintParser into memory.
Example:
This example contains all XaintParser functions.
#include <stdio.h>
#include <xaint.h>
static void
request( XaintParser *parser)
{
FILE *f;
char buffer[50];
size_t bytesRead;
f = (FILE*) XaintParser_getUserData(parser);
bytesRead = fread(buffer, 1, sizeof(buffer), f);
XaintParser_feedData(parser, buffer, bytesRead);
}
static void
event( XaintParser *parser, XaintChar *data, XaintType type)
{
printf( "(%d) Event [%s] type: '%c'\n", parser, data, type);
}
int main()
{
FILE *f;
XaintParser *parser;
f = fopen( "note.xnt", "rb");
if (!f)
{
printf( "ERROR: could not open file.\n");
return 1;
}
parser = XaintParser_new();
XaintParser_setUserData(parser, f);
XaintParser_setDataRequest(parser, request);
XaintParser_setEvent(parser, event);
printf( "Parsing file\n");
printf( "\tUserData: (%d)\n", XaintParser_getUserData(parser));
printf( "\tDataRequest: (%d)\n", XaintParser_getDataRequest(parser));
printf( "\tEvent: (%d)\n", XaintParser_getEvent(parser));
printf( "\n");
if (! XaintParser_parse(parser))
{
printf( "error: #%d, (col %d, row %d)\n",
XaintParser_getLastError(parser),
XaintParser_getColNum(parser),
XaintParser_getRowNum(parser));
return 1;
}
printf( "\nFinished\n");
fclose(f);
XaintParser_delete(parser);
return 0;
}
|