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