cmml-write.c

Writing a CMML file

Although libcmml was created mainly for the purpose of parsing existing CMML files, it also provides rudimentary support for creating CMML files. This basically consists in providing the data structures for the different tags and API functions to print those tags. There is no validation or sequence checking available for the writing side.

The general sequence of API calls is the following:

This procedure is illustrated in cmml-write.c:

00001 /* Copyright (C) 2003 CSIRO Australia
00002 
00003    Redistribution and use in source and binary forms, with or without
00004    modification, are permitted provided that the following conditions
00005    are met:
00006    
00007    - Redistributions of source code must retain the above copyright
00008    notice, this list of conditions and the following disclaimer.
00009    
00010    - Redistributions in binary form must reproduce the above copyright
00011    notice, this list of conditions and the following disclaimer in the
00012    documentation and/or other materials provided with the distribution.
00013    
00014    - Neither the name of the CSIRO nor the names of its
00015    contributors may be used to endorse or promote products derived from
00016    this software without specific prior written permission.
00017    
00018    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00021    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00022    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00025    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00026    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 */
00030 
00031 #include <stdio.h>
00032 #include <string.h>
00033 
00034 #include <cmml.h>
00035 
00045 #define BUFSIZE 100000
00046 
00050 int main(int argc, char *argv[])
00051 {
00052   CMML_Preamble * pre = NULL;
00053   CMML_Head * head = NULL;
00054   CMML_Clip * clip = NULL;
00055   CMML_Time * start = NULL, * end = NULL;
00056   char buf[BUFSIZE];
00057 
00058   /* write preamble */
00059   pre = cmml_preamble_new("UTF-8", NULL, NULL, NULL, NULL);
00060   cmml_preamble_snprint (buf, BUFSIZE, pre);
00061   puts(buf);
00062   cmml_preamble_destroy(pre);
00063 
00064   /* write head */
00065   head = cmml_head_new();
00066   head->title = strdup("This is a test file");
00067   cmml_head_snprint (buf, BUFSIZE, head);
00068   puts(buf);
00069   cmml_head_destroy(head);
00070 
00071   /* write a clip for the interval 0.6 to 3.5 seconds */
00072   cmml_npt_snprint (buf, BUFSIZE, 0.6);
00073   start = cmml_time_new (buf);
00074 
00075   cmml_npt_snprint (buf, BUFSIZE, 3.5);
00076   end = cmml_time_new (buf);
00077 
00078   clip = cmml_clip_new(start, end);
00079   clip->anchor_href = strdup("http://www.annodex.net/");
00080   clip->anchor_text = strdup("hyperlink to annodex.net");
00081   clip->desc_text = strdup("This is a clip");
00082   cmml_clip_snprint (buf, BUFSIZE, clip);
00083   puts (buf);
00084   cmml_clip_destroy(clip);
00085 
00086   printf ("</cmml>\n");
00087 
00088   exit(0);
00089 }

Generated on Wed Oct 4 19:48:52 2006 for libcmml by  doxygen 1.4.7