libcmml  0.9.1
cmml-parse.c

Reading from a CMML file

libcmml provides a convenient callback based framework for reading CMML files. After opening a CMML file for reading, you can attach various callbacks relevant to the parts of the file you are interested in, including the stream element, head element, and clip elements. Then, as bytes are read, libcmml will call your callbacks as appropriate.

The functions that need to be called and the respective data structures are defined in cmml.h.

The general sequence of API calls is the following:

This procedure is illustrated in cmml-parse.c, which prints the title attribute of a CMML tag :

#include <stdio.h>
#include <cmml.h>
#define BUFSIZE 100000
static int
read_head (CMML * cmml, const CMML_Head * head, void * user_data) {
puts(head->title);
return 0;
}
int main(int argc, char *argv[])
{
char *filename = NULL;
FILE * cmml_file;
CMML * doc;
long n = 0;
if (argc != 2) {
fprintf (stderr, "Usage: %s <CMMLfile>\n", argv[0]);
exit (1);
}
filename = argv[1];
cmml_file = fopen(filename, "r");
doc = cmml_new(cmml_file);
/* alternatively use:
* doc = cmml_open(filename);
*/
cmml_set_read_callbacks (doc, NULL, read_head, NULL, NULL);
while (((n = cmml_read (doc, BUFSIZE)) > 0));
cmml_file = cmml_destroy(doc);
fclose(cmml_file);
/* alternatively use:
* cmml_close(doc);
*/
exit(0);
}
int main(int argc, char *argv[])
Definition: cmml-validate.c:212
#define BUFSIZE
Definition: cmml-validate.c:79
static int read_head(CMML *cmml, const CMML_Head *head, void *user_data)
Definition: cmml-validate.c:161
FILE * cmml_destroy(CMML *cmml)
void CMML
Definition: cmml.h:50
CMML * cmml_new(FILE *file)
long cmml_read(CMML *cmml, long n)
int cmml_set_read_callbacks(CMML *cmml, CMMLReadStream read_stream, CMMLReadHead read_head, CMMLReadClip read_clip, void *user_data)
Definition: cmml.h:223
char * title
Definition: cmml.h:228