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 :
00001 00031 #include <stdio.h> 00032 00033 #include <cmml.h> 00034 00045 #define BUFSIZE 100000 00046 00047 00058 static int 00059 read_head (CMML * cmml, const CMML_Head * head, void * user_data) { 00060 puts(head->title); 00061 return 0; 00062 } 00063 00070 int main(int argc, char *argv[]) 00071 { 00072 char *filename = NULL; 00073 FILE * cmml_file; 00074 CMML * doc; 00075 long n = 0; 00076 00077 if (argc != 2) { 00078 fprintf (stderr, "Usage: %s <CMMLfile>\n", argv[0]); 00079 exit (1); 00080 } 00081 filename = argv[1]; 00082 00083 cmml_file = fopen(filename, "r"); 00084 doc = cmml_new(cmml_file); 00085 00086 /* alternatively use: 00087 * doc = cmml_open(filename); 00088 */ 00089 00090 cmml_set_read_callbacks (doc, NULL, read_head, NULL, NULL); 00091 00092 while (((n = cmml_read (doc, BUFSIZE)) > 0)); 00093 00094 cmml_file = cmml_destroy(doc); 00095 fclose(cmml_file); 00096 00097 /* alternatively use: 00098 * cmml_close(doc); 00099 */ 00100 00101 exit(0); 00102 }