1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
<!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>KLone: emb.c Source File</title>
<link href="kl.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<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="dirs.html">Directories</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></div>
<div class="nav">
<a class="el" href="dir_000000.html">src</a> / <a class="el" href="dir_000008.html">libemb</a></div>
<h1>emb.c</h1><a href="emb_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment"> * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com></span>
00003 <span class="comment"> * All rights reserved.</span>
00004 <span class="comment"> *</span>
00005 <span class="comment"> * This file is part of KLone, and as such it is subject to the license stated</span>
00006 <span class="comment"> * in the LICENSE file which you have received as part of this distribution.</span>
00007 <span class="comment"> *</span>
00008 <span class="comment"> * $Id: emb.c,v 1.14 2006/04/22 13:14:46 tat Exp $</span>
00009 <span class="comment"> */</span>
00010
00011 <span class="preprocessor">#include <<a class="code" href="emb_8h.html">klone/emb.h</a>></span>
00012 <span class="preprocessor">#include <<a class="code" href="io_8h.html">klone/io.h</a>></span>
00013 <span class="preprocessor">#include <<a class="code" href="codecs_8h.html">klone/codecs.h</a>></span>
00014 <span class="preprocessor">#include <u/libu.h></span>
00015
00016 <span class="comment">/* these are klone-site autogen functions */</span>
00017 <span class="keywordtype">void</span> <a class="code" href="emb_8c.html#a3">register_pages</a>(<span class="keywordtype">void</span>);
00018 <span class="keywordtype">void</span> <a class="code" href="emb_8c.html#a4">unregister_pages</a>(<span class="keywordtype">void</span>);
00019
00020 <span class="keyword">static</span> <span class="keyword">struct </span>emblist_s list; <span class="comment">/* list of emb resources */</span>
00021 <span class="keyword">static</span> size_t nres; <span class="comment">/* num of emb resources */</span>
00022 <span class="keyword">static</span> <span class="keywordtype">int</span> init = 0;
00023
<a name="l00024"></a><a class="code" href="emb_8h.html#a6">00024</a> <span class="keywordtype">int</span> <a class="code" href="emb_8c.html#a5">emb_init</a>(<span class="keywordtype">void</span>)
00025 {
00026 <span class="keywordflow">if</span>(init++ == 0)
00027 {
00028 LIST_INIT(&list); <span class="comment">/* init resource list */</span>
00029
00030 <span class="comment">/* call autogen external function (cannot be called more then once!) */</span>
00031 dbg(<span class="stringliteral">"registering embedded resources"</span>);
00032 <a class="code" href="emb_8c.html#a3">register_pages</a>();
00033 }
00034
00035 <span class="keywordflow">return</span> 0;
00036 }
00037
<a name="l00038"></a><a class="code" href="emb_8h.html#a7">00038</a> <span class="keywordtype">int</span> <a class="code" href="emb_8c.html#a6">emb_term</a>(<span class="keywordtype">void</span>)
00039 {
00040 dbg_err_if(init == 0);
00041
00042 <a class="code" href="emb_8c.html#a4">unregister_pages</a>();
00043
00044 <span class="keywordflow">return</span> 0;
00045 err:
00046 <span class="keywordflow">return</span> ~0;
00047 }
00048
<a name="l00049"></a><a class="code" href="emb_8h.html#a8">00049</a> <span class="keywordtype">int</span> <a class="code" href="emb_8h.html#a8">emb_register</a>(<a class="code" href="structembres__s.html">embres_t</a> *res)
00050 {
00051 dbg_err_if(init == 0 || res == NULL);
00052
00053 <span class="keywordflow">if</span>(res-><a class="code" href="structembres__s.html#o1">type</a> == ET_FILE)
00054 dbg(<span class="stringliteral">"registering %s (%s)"</span>, res-><a class="code" href="structembres__s.html#o0">filename</a>,
00055 ((<a class="code" href="structembfile__s.html">embfile_t</a>*)res)->comp ? <span class="stringliteral">"compressed"</span> : <span class="stringliteral">"uncompressed"</span>);
00056 <span class="keywordflow">else</span>
00057 dbg(<span class="stringliteral">"registering %s"</span>, res->filename);
00058
00059 LIST_INSERT_HEAD(&list, res, np);
00060 nres++;
00061
00062 <span class="keywordflow">return</span> 0;
00063 err:
00064 <span class="keywordflow">return</span> ~0;
00065 }
00066
<a name="l00067"></a><a class="code" href="emb_8h.html#a9">00067</a> <span class="keywordtype">int</span> <a class="code" href="emb_8h.html#a9">emb_unregister</a>(<a class="code" href="structembres__s.html">embres_t</a> *res)
00068 {
00069 dbg_err_if(init == 0 || res == NULL);
00070
00071 LIST_REMOVE(res, np);
00072 nres--;
00073
00074 <span class="keywordflow">return</span> 0;
00075 err:
00076 <span class="keywordflow">return</span> ~0;
00077 }
00078
<a name="l00079"></a><a class="code" href="emb_8h.html#a10">00079</a> <span class="keywordtype">int</span> <a class="code" href="emb_8h.html#a10">emb_lookup</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename, <a class="code" href="structembres__s.html">embres_t</a> **pr)
00080 {
00081 <a class="code" href="structembres__s.html">embres_t</a> *res;
00082
00083 dbg_err_if (init == 0);
00084 dbg_err_if (filename == NULL || !strlen(filename));
00085 dbg_err_if (pr == NULL);
00086
00087 LIST_FOREACH(res, &list, np)
00088 {
00089 <span class="keywordflow">if</span>(strcmp(filename, res-><a class="code" href="structembres__s.html#o0">filename</a>))
00090 <span class="keywordflow">continue</span>;
00091
00092 <span class="comment">/* save found resource pointer */</span>
00093 *pr = res;
00094
00095 <span class="keywordflow">return</span> 0; <span class="comment">/* found */</span>
00096 }
00097
00098 err:
00099 <span class="comment">/* not found */</span>
00100 <span class="keywordflow">return</span> ~0;
00101 }
00102
<a name="l00103"></a><a class="code" href="emb_8h.html#a11">00103</a> <span class="keywordtype">int</span> <a class="code" href="emb_8c.html#a10">emb_count</a>(<span class="keywordtype">void</span>)
00104 {
00105 dbg_err_if (init == 0);
00106
00107 <span class="keywordflow">return</span> nres;
00108 err:
00109 <span class="keywordflow">return</span> -1;
00110 }
00111
<a name="l00112"></a><a class="code" href="emb_8h.html#a12">00112</a> <span class="keywordtype">int</span> <a class="code" href="emb_8h.html#a12">emb_getn</a>(size_t n, <a class="code" href="structembres__s.html">embres_t</a> **pr)
00113 {
00114 <a class="code" href="structembres__s.html">embres_t</a> *res = NULL;
00115
00116 dbg_err_if (init == 0);
00117 dbg_err_if (n >= nres);
00118 dbg_err_if (pr == NULL);
00119
00120 LIST_FOREACH(res, &list, np)
00121 {
00122 <span class="keywordflow">if</span>(n-- == 0)
00123 <span class="keywordflow">break</span>;
00124 }
00125
00126 *pr = res;
00127
00128 <span class="keywordflow">return</span> 0;
00129 err:
00130 <span class="keywordflow">return</span> ~0;
00131 }
00132
<a name="l00133"></a><a class="code" href="emb_8h.html#a13">00133</a> <span class="keywordtype">int</span> <a class="code" href="emb_8h.html#a13">emb_open</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *file, <a class="code" href="structio__s.html">io_t</a> **pio)
00134 {
00135 <a class="code" href="structembfile__s.html">embfile_t</a> *e = NULL;
00136 <a class="code" href="structcodec__s.html">codec_t</a> *gzip = NULL;
00137 <a class="code" href="structio__s.html">io_t</a> *io;
00138
00139 dbg_return_if (pio == NULL, ~0);
00140 dbg_return_if (file == NULL, ~0);
00141
00142 dbg_err_if(<a class="code" href="emb_8h.html#a10">emb_lookup</a>(file, (<a class="code" href="structembres__s.html">embres_t</a>**)&e) || e->res.<a class="code" href="structembres__s.html#o1">type</a> != <a class="code" href="emb_8h.html#a14a3">ET_FILE</a>);
00143
00144 dbg_err_if(<a class="code" href="io_8h.html#a6">io_mem_create</a>((<span class="keywordtype">char</span>*)e->data, e->size, 0, &io));
00145
00146 <span class="preprocessor">#ifdef HAVE_LIBZ</span>
00147 <span class="preprocessor"></span> <span class="keywordflow">if</span>(e->comp)
00148 {
00149 dbg_err_if(<a class="code" href="group__codec__t.html#ga7">codec_gzip_create</a>(<a class="code" href="cgzip_8h.html#a3a1">GZIP_UNCOMPRESS</a>, &gzip));
00150 dbg_err_if(<a class="code" href="group__io__t.html#ga23">io_codec_add_tail</a>(io, (<a class="code" href="structcodec__s.html">codec_t</a>*)gzip));
00151 gzip = NULL;
00152 }
00153 <span class="preprocessor">#endif</span>
00154 <span class="preprocessor"></span>
00155 *pio = io;
00156
00157 <span class="keywordflow">return</span> 0;
00158 err:
00159 <span class="keywordflow">if</span>(gzip)
00160 <a class="code" href="group__codec__t.html#ga3">codec_free</a>(gzip);
00161 <span class="keywordflow">return</span> ~0;
00162 }
00163
</pre></div><hr>
<div>
<div style="text-align:left">
<a href="http://www.koanlogic.com/kl/cont/gb/html/products.html">←Products</a>
</div>
<div style="text-align:center;">
© 2005-2006 - <a href="http://www.koanlogic.com">KoanLogic S.r.l.</a> - All rights reserved
</div>
</div>
</body>
</html>
|