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