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