00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <string.h>
00027 #include "cr-selector.h"
00028 #include "cr-parser.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037 CRSelector*
00038 cr_selector_new (CRSimpleSel *a_simple_sel)
00039 {
00040 CRSelector *result = NULL ;
00041
00042 result = g_try_malloc (sizeof (CRSelector)) ;
00043 if (!result)
00044 {
00045 cr_utils_trace_info ("Out of memory") ;
00046 return NULL ;
00047 }
00048 memset (result, 0, sizeof (CRSelector)) ;
00049 result->simple_sel = a_simple_sel ;
00050 return result ;
00051 }
00052
00053 CRSelector *
00054 cr_selector_parse_from_buf (const guchar * a_char_buf,
00055 enum CREncoding a_enc)
00056 {
00057 CRParser * parser = NULL ;
00058
00059 g_return_val_if_fail (a_char_buf, NULL) ;
00060
00061 parser = cr_parser_new_from_buf (a_char_buf, strlen (a_char_buf),
00062 a_enc, FALSE) ;
00063 g_return_val_if_fail (parser, NULL) ;
00064
00065
00066 return NULL ;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 CRSelector*
00076 cr_selector_append (CRSelector *a_this, CRSelector *a_new)
00077 {
00078 CRSelector *cur = NULL ;
00079
00080 if (!a_this)
00081 {
00082 return a_new ;
00083 }
00084
00085
00086 for (cur = a_this ; cur && cur->next ; cur = cur->next) ;
00087
00088 cur->next = a_new ;
00089 a_new->prev = cur ;
00090
00091 return a_this ;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 CRSelector*
00101 cr_selector_prepend (CRSelector *a_this, CRSelector *a_new)
00102 {
00103 CRSelector *cur = NULL ;
00104
00105 a_new->next = a_this ;
00106 a_this->prev = a_new ;
00107
00108 for (cur = a_new ; cur && cur->prev ; cur = cur->prev) ;
00109
00110 return cur ;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119 CRSelector*
00120 cr_selector_append_simple_sel (CRSelector *a_this, CRSimpleSel *a_simple_sel)
00121 {
00122 CRSelector * selector = NULL ;
00123
00124 selector = cr_selector_new (a_simple_sel) ;
00125 g_return_val_if_fail (selector, NULL) ;
00126
00127 return cr_selector_append (a_this, selector) ;
00128 }
00129
00130
00131 guchar *
00132 cr_selector_to_string (CRSelector *a_this)
00133 {
00134 guchar *result = NULL ;
00135 GString *str_buf = NULL ;
00136
00137 str_buf = g_string_new (NULL) ;
00138 g_return_val_if_fail (str_buf, NULL) ;
00139
00140 if (a_this)
00141 {
00142 CRSelector *cur = NULL ;
00143
00144 for (cur = a_this ; cur ; cur = cur->next)
00145 {
00146 if (cur->simple_sel)
00147 {
00148 guchar *tmp_str = NULL ;
00149
00150 tmp_str = cr_simple_sel_to_string
00151 (cur->simple_sel) ;
00152
00153 if (tmp_str)
00154 {
00155 if (cur->prev)
00156 g_string_append_printf
00157 (str_buf,", ") ;
00158
00159 g_string_append_printf
00160 (str_buf, "%s",
00161 tmp_str) ;
00162
00163 g_free (tmp_str) ;
00164 tmp_str = NULL ;
00165 }
00166 }
00167 }
00168 }
00169
00170 if (str_buf)
00171 {
00172 result = str_buf->str ;
00173 g_string_free (str_buf, FALSE) ;
00174 str_buf = NULL ;
00175 }
00176
00177 return result ;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186 void
00187 cr_selector_dump (CRSelector *a_this, FILE *a_fp)
00188 {
00189 guchar *tmp_buf = NULL ;
00190
00191 if (a_this)
00192 {
00193 tmp_buf = cr_selector_to_string (a_this) ;
00194 if (tmp_buf)
00195 {
00196 fprintf (a_fp, "%s", tmp_buf) ;
00197 g_free (tmp_buf) ;
00198 tmp_buf = NULL ;
00199 }
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208 void
00209 cr_selector_ref (CRSelector *a_this)
00210 {
00211 g_return_if_fail (a_this) ;
00212
00213 a_this->ref_count ++ ;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 gboolean
00226 cr_selector_unref (CRSelector *a_this)
00227 {
00228 g_return_val_if_fail (a_this, FALSE) ;
00229
00230 if (a_this->ref_count)
00231 {
00232 a_this->ref_count -- ;
00233 }
00234
00235 if (a_this->ref_count == 0)
00236 {
00237 cr_selector_destroy (a_this) ;
00238 return TRUE ;
00239 }
00240
00241 return FALSE ;
00242 }
00243
00244
00245
00246
00247
00248 void
00249 cr_selector_destroy (CRSelector *a_this)
00250 {
00251 CRSelector *cur = NULL ;
00252
00253 g_return_if_fail (a_this) ;
00254
00255
00256
00257
00258
00259 for (cur = a_this ;cur && cur->next ; cur = cur->next)
00260 {
00261 if (cur->simple_sel)
00262 {
00263 cr_simple_sel_destroy (cur->simple_sel) ;
00264 cur->simple_sel = NULL ;
00265 }
00266 }
00267
00268 if (cur)
00269 {
00270 if (cur->simple_sel)
00271 {
00272 cr_simple_sel_destroy (cur->simple_sel) ;
00273 cur->simple_sel = NULL ;
00274 }
00275 }
00276
00277
00278 if (cur && !cur->prev)
00279 {
00280 g_free (cur) ;
00281 return ;
00282 }
00283
00284
00285 for (cur = cur->prev ; cur && cur->prev ; cur = cur->prev)
00286 {
00287 if (cur->next)
00288 {
00289 g_free (cur->next) ;
00290 cur->next = NULL ;
00291 }
00292 }
00293
00294 if (!cur)
00295 return ;
00296
00297 if (cur->next)
00298 {
00299 g_free (cur->next) ;
00300 cur->next = NULL ;
00301 }
00302
00303 g_free (cur) ;
00304 }