<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>libcmml: Example Documentation</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.3.4 --> <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="examples.html">Examples</a></div> <h1>cmml-uri-file.c</h1><b>Parse a CMML file given through a file uri (optionally with a fragment offset)</b><p> This example program demonstrates how a CMML file that is given through a file uri and optionally contains a fragment offset can be interpreted. The example can be extended to other schemes such as http and to cover uri queries, too.<p> The procedure is illustrated in cmml-uri-file.c, which opens a file given through a file uri, and optionally seeks to an offset given the uri fragment specifier. It then prints out the descriptions of all the following clips: <div class="fragment"><pre> <span class="preprocessor">#include <stdio.h></span> <span class="preprocessor">#include <<a class="code" href="cmml_8h.html">cmml.h</a>></span> <span class="preprocessor">#include <string.h></span> <span class="preprocessor">#define BUFSIZE 100000</span> <span class="preprocessor"></span> <span class="keyword">typedef</span> <span class="keyword">struct </span>{ <span class="keywordtype">char</span> *scheme; <span class="keywordtype">char</span> *authority; <span class="keywordtype">char</span> *path; <span class="keywordtype">char</span> *querystr; <span class="keywordtype">char</span> *fragstr; } URI; <span class="keyword">static</span> URI * parse_file_uri (<span class="keyword">const</span> <span class="keywordtype">char</span> *uri_string) { <span class="keyword">const</span> <span class="keywordtype">char</span> *location; <span class="keyword">const</span> <span class="keywordtype">char</span> *locbegin; <span class="keywordtype">int</span> length; URI *result; locbegin = uri_string; result = (URI*) calloc(<span class="keyword">sizeof</span>(URI), <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>)); <span class="comment">/* ignore file:// and authority parts to get path */</span> location = strstr (locbegin, <span class="stringliteral">"://"</span>); locbegin = location+3; length = strlen(locbegin); location = strchr(locbegin, <span class="charliteral">'#'</span>); <span class="comment">/* XXX: ignore queries for the moment */</span> <span class="keywordflow">if</span> (location != NULL) length = location - locbegin; result->path = (<span class="keywordtype">char</span>*) calloc (length+1, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>)); result->path = strncpy(result->path, locbegin, length); result->path[length] = <span class="charliteral">'\0'</span>; <span class="keywordflow">if</span> (location != NULL) { <span class="comment">/* fragment given */</span> length = strlen(location); result->fragstr = NULL; result->fragstr = (<span class="keywordtype">char</span>*) calloc (length, <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>)); result->fragstr = strncpy(result->fragstr, location+1, length); } <span class="keywordflow">else</span> { result->fragstr = NULL; } <span class="keywordflow">return</span> result; } <span class="keyword">static</span> <span class="keywordtype">int</span> <a name="a35"></a><a class="code" href="cmml-validate_8c.html#a5">read_clip</a> (<a class="code" href="cmml_8h.html#a0">CMML</a> * cmml, <span class="keyword">const</span> <a name="_a36"></a><a class="code" href="structCMML__Clip.html">CMML_Clip</a> * clip, <span class="keywordtype">void</span> * user_data) { puts(clip-><a name="a37"></a><a class="code" href="structCMML__Clip.html#o28">desc_text</a>); <span class="keywordflow">return</span> 0; } <span class="keywordtype">int</span> <a name="a38"></a><a class="code" href="cmml-validate_8c.html#a6">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) { <span class="keywordtype">char</span> *uri_string = NULL; URI * uri; <a class="code" href="cmml_8h.html#a0">CMML</a> * doc; <span class="keywordtype">long</span> n = 0; <span class="keywordflow">if</span> (argc < 2) { fprintf (stderr, <span class="stringliteral">"Usage: %s <file://filename#fragment>\n"</span>, argv[0]); exit (1); } uri_string = argv[1]; uri = parse_file_uri(uri_string); doc = <a name="a39"></a><a class="code" href="cmml_8h.html#a37">cmml_open</a>(uri->path); <span class="comment">/* if fragment given, forward to that */</span> <span class="keywordflow">if</span> (uri->fragstr != NULL) <a name="a40"></a><a class="code" href="cmml_8h.html#a55">cmml_skip_to_offset</a>(doc, uri->fragstr); <a name="a41"></a><a class="code" href="cmml_8h.html#a41">cmml_set_read_callbacks</a> (doc, NULL, NULL, read_clip, NULL); <span class="keywordflow">while</span> (((n = <a name="a42"></a><a class="code" href="cmml_8h.html#a42">cmml_read</a> (doc, BUFSIZE)) > 0)); <a name="a43"></a><a class="code" href="cmml_8h.html#a40">cmml_close</a>(doc); exit(0); } </pre></div> <hr size="1"><address style="align: right;"><small>Generated on Thu Jan 26 12:26:56 2006 for libcmml by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.4 </small></address> </body> </html>