Skip to content

Commit

Permalink
Start experimenting with the parser API.
Browse files Browse the repository at this point in the history
  • Loading branch information
alriddoch committed Feb 12, 2010
1 parent 4b4a671 commit d2f3380
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 26 deletions.
89 changes: 64 additions & 25 deletions libcolladadae/parser.c
Expand Up @@ -20,37 +20,76 @@

#include <libxml/parser.h>

xmlSAXHandler my_handler = {
0, /* internalSubsetSAXFunc, */
0, /* isStandaloneSAXFunc, */
0, /* hasInternalSubsetSAXFunc, */
0, /* hasExternalSubsetSAXFunc, */
0, /* resolveEntitySAXFunc, */
0, /* getEntitySAXFunc, */
0, /* entityDeclSAXFunc, */
0, /* notationDeclSAXFunc, */
0, /* attributeDeclSAXFunc, */
0, /* elementDeclSAXFunc, */
0, /* unparsedEntityDeclSAXFunc, */
0, /* setDocumentLocatorSAXFunc, */
0, /* startDocumentSAXFunc, */
0, /* endDocumentSAXFunc, */
0, /* startElementSAXFunc, */
0, /* endElementSAXFunc, */
0, /* referenceSAXFunc, */
0, /* charactersSAXFunc, */
0, /* ignorableWhitespaceSAXFunc, */
0, /* processingInstructionSAXFunc, */
0, /* commentSAXFunc, */
0, /* warningSAXFunc, */
0, /* errorSAXFunc, */
0, /* fatalErrorSAXFunc, */
#include <assert.h>

typedef struct _dae_parser_state {
libcolladadae_file * dps_file;
} dae_parser_state;

static void dae_start(dae_parser_state * state)
{
assert(state != NULL);

printf("%s\n", __func__);
state->dps_file = calloc(1, sizeof(libcolladadae_file));
}

static void dae_end(dae_parser_state * state)
{
assert(state != NULL);

printf("%s\n", __func__);
state->dps_file = calloc(1, sizeof(libcolladadae_file));
}

static void dae_start_element(dae_parser_state *ctx,
const xmlChar *name,
const xmlChar **atts)
{
printf("<%s>\n", name);
}

static void dae_end_element(dae_parser_state *ctx,
const xmlChar *name)
{
printf("</%s>\n", name);
}

static xmlSAXHandler dae_handler = {
(internalSubsetSAXFunc)0,
(isStandaloneSAXFunc)0,
(hasInternalSubsetSAXFunc)0,
(hasExternalSubsetSAXFunc)0,
(resolveEntitySAXFunc)0,
(getEntitySAXFunc)0,
(entityDeclSAXFunc)0,
(notationDeclSAXFunc)0,
(attributeDeclSAXFunc)0,
(elementDeclSAXFunc)0,
(unparsedEntityDeclSAXFunc)0,
(setDocumentLocatorSAXFunc)0,
(startDocumentSAXFunc)&dae_start,
(endDocumentSAXFunc)&dae_end,
(startElementSAXFunc)&dae_start_element,
(endElementSAXFunc)&dae_end_element,
(referenceSAXFunc)0,
(charactersSAXFunc)0,
(ignorableWhitespaceSAXFunc)0,
(processingInstructionSAXFunc)0,
(commentSAXFunc)0,
(warningSAXFunc)0,
(errorSAXFunc)0,
(fatalErrorSAXFunc)0,
};

libcolladadae_file * libcolladadae_file_load(const char * filename)
{
dae_parser_state parser_state;
xmlSAXUserParseFile(&dae_handler, &parser_state, filename);
return parser_state.dps_file;
}

void libcolladadae_free(libcolladadae_file * file)
{
free(file);
}
3 changes: 2 additions & 1 deletion libcolladadae/parser.h
Expand Up @@ -20,9 +20,10 @@
#define LIBCOLLADADAE_PARSER_H

typedef struct _libcolladadae_file {
void * place_holder;
} libcolladadae_file;

libcolladadae_file * libcolladadae_file_load(const char * filename);
void libcolladadae_free(libcolladadae_file * file);

#endif // LIBCOLLADADAE_PARSER_H
#endif /* LIBCOLLADADAE_PARSER_H */
1 change: 1 addition & 0 deletions libcolladadae/tests/dumpdae.c
Expand Up @@ -15,5 +15,6 @@ int main(int argc, char ** argv)
fprintf(stderr, "Parsing %s failed\n", argv[1]);
return 1;
}
libcolladadae_free(ret);
return 0;
}

0 comments on commit d2f3380

Please sign in to comment.