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 #include "cr-additional-sel.h"
00026 #include "string.h"
00027
00028
00029
00030
00031
00032 CRAdditionalSel *
00033 cr_additional_sel_new (void)
00034 {
00035 CRAdditionalSel *result = NULL;
00036
00037 result = g_try_malloc (sizeof (CRAdditionalSel));
00038
00039 if (result == NULL) {
00040 cr_utils_trace_debug ("Out of memory");
00041 return NULL;
00042 }
00043
00044 memset (result, 0, sizeof (CRAdditionalSel));
00045
00046 return result;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 CRAdditionalSel *
00056 cr_additional_sel_new_with_type (enum AddSelectorType a_sel_type)
00057 {
00058 CRAdditionalSel *result = NULL;
00059
00060 result = cr_additional_sel_new ();
00061
00062 g_return_val_if_fail (result, NULL);
00063
00064 result->type = a_sel_type;
00065
00066 return result;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 void
00078 cr_additional_sel_set_class_name (CRAdditionalSel * a_this,
00079 CRString * a_class_name)
00080 {
00081 g_return_if_fail (a_this && a_this->type == CLASS_ADD_SELECTOR);
00082
00083 if (a_this->content.class_name) {
00084 cr_string_destroy (a_this->content.class_name);
00085 }
00086
00087 a_this->content.class_name = a_class_name;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097 void
00098 cr_additional_sel_set_id_name (CRAdditionalSel * a_this, CRString * a_id)
00099 {
00100 g_return_if_fail (a_this && a_this->type == ID_ADD_SELECTOR);
00101
00102 if (a_this->content.id_name) {
00103 cr_string_destroy (a_this->content.id_name);
00104 }
00105
00106 a_this->content.id_name = a_id;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 void
00117 cr_additional_sel_set_pseudo (CRAdditionalSel * a_this, CRPseudo * a_pseudo)
00118 {
00119 g_return_if_fail (a_this
00120 && a_this->type == PSEUDO_CLASS_ADD_SELECTOR);
00121
00122 if (a_this->content.pseudo) {
00123 cr_pseudo_destroy (a_this->content.pseudo);
00124 }
00125
00126 a_this->content.pseudo = a_pseudo;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136 void
00137 cr_additional_sel_set_attr_sel (CRAdditionalSel * a_this, CRAttrSel * a_sel)
00138 {
00139 g_return_if_fail (a_this && a_this->type == ATTRIBUTE_ADD_SELECTOR);
00140
00141 if (a_this->content.attr_sel) {
00142 cr_attr_sel_destroy (a_this->content.attr_sel);
00143 }
00144
00145 a_this->content.attr_sel = a_sel;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 CRAdditionalSel *
00157 cr_additional_sel_append (CRAdditionalSel * a_this, CRAdditionalSel * a_sel)
00158 {
00159 CRAdditionalSel *cur_sel = NULL;
00160
00161 g_return_val_if_fail (a_sel, NULL);
00162
00163 if (a_this == NULL) {
00164 return a_sel;
00165 }
00166
00167 if (a_sel == NULL)
00168 return NULL;
00169
00170 for (cur_sel = a_this;
00171 cur_sel && cur_sel->next; cur_sel = cur_sel->next) ;
00172
00173 g_return_val_if_fail (cur_sel != NULL, NULL);
00174
00175 cur_sel->next = a_sel;
00176 a_sel->prev = cur_sel;
00177
00178 return a_this;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 CRAdditionalSel *
00190 cr_additional_sel_prepend (CRAdditionalSel * a_this, CRAdditionalSel * a_sel)
00191 {
00192 g_return_val_if_fail (a_sel, NULL);
00193
00194 if (a_this == NULL) {
00195 return a_sel;
00196 }
00197
00198 a_sel->next = a_this;
00199 a_this->prev = a_sel;
00200
00201 return a_sel;
00202 }
00203
00204 guchar *
00205 cr_additional_sel_to_string (CRAdditionalSel * a_this)
00206 {
00207 guchar *result = NULL;
00208 GString *str_buf = NULL;
00209 CRAdditionalSel *cur = NULL;
00210
00211 g_return_val_if_fail (a_this, NULL);
00212
00213 str_buf = g_string_new (NULL);
00214
00215 for (cur = a_this; cur; cur = cur->next) {
00216 switch (cur->type) {
00217 case CLASS_ADD_SELECTOR:
00218 {
00219 guchar *name = NULL;
00220
00221 if (cur->content.class_name) {
00222 name = g_strndup
00223 (cur->content.class_name->stryng->str,
00224 cur->content.class_name->stryng->len);
00225
00226 if (name) {
00227 g_string_append_printf
00228 (str_buf, ".%s",
00229 name);
00230 g_free (name);
00231 name = NULL;
00232 }
00233 }
00234 }
00235 break;
00236
00237 case ID_ADD_SELECTOR:
00238 {
00239 guchar *name = NULL;
00240
00241 if (cur->content.class_name) {
00242 name = g_strndup
00243 (cur->content.id_name->stryng->str,
00244 cur->content.id_name->stryng->len);
00245
00246 if (name) {
00247 g_string_append_printf
00248 (str_buf, "#%s",
00249 name);
00250 g_free (name);
00251 name = NULL;
00252 }
00253 }
00254 }
00255
00256 break;
00257
00258 case PSEUDO_CLASS_ADD_SELECTOR:
00259 {
00260 if (cur->content.pseudo) {
00261 guchar *tmp_str = NULL;
00262
00263 tmp_str = cr_pseudo_to_string
00264 (cur->content.pseudo);
00265 if (tmp_str) {
00266 g_string_append_printf
00267 (str_buf, ":%s",
00268 tmp_str);
00269 g_free (tmp_str);
00270 tmp_str = NULL;
00271 }
00272 }
00273 }
00274 break;
00275
00276 case ATTRIBUTE_ADD_SELECTOR:
00277 if (cur->content.attr_sel) {
00278 guchar *tmp_str = NULL;
00279
00280 g_string_append_c (str_buf, '[');
00281 tmp_str = cr_attr_sel_to_string
00282 (cur->content.attr_sel);
00283 if (tmp_str) {
00284 g_string_append_printf
00285 (str_buf, "%s]", tmp_str);
00286 g_free (tmp_str);
00287 tmp_str = NULL;
00288 }
00289 }
00290 break;
00291
00292 default:
00293 break;
00294 }
00295 }
00296
00297 if (str_buf) {
00298 result = str_buf->str;
00299 g_string_free (str_buf, FALSE);
00300 str_buf = NULL;
00301 }
00302
00303 return result;
00304 }
00305
00306 guchar *
00307 cr_additional_sel_one_to_string (CRAdditionalSel *a_this)
00308 {
00309 guchar *result = NULL;
00310 GString *str_buf = NULL;
00311
00312 g_return_val_if_fail (a_this, NULL) ;
00313
00314 str_buf = g_string_new (NULL) ;
00315
00316 switch (a_this->type) {
00317 case CLASS_ADD_SELECTOR:
00318 {
00319 guchar *name = NULL;
00320
00321 if (a_this->content.class_name) {
00322 name = g_strndup
00323 (a_this->content.class_name->stryng->str,
00324 a_this->content.class_name->stryng->len);
00325
00326 if (name) {
00327 g_string_append_printf
00328 (str_buf, ".%s",
00329 name);
00330 g_free (name);
00331 name = NULL;
00332 }
00333 }
00334 }
00335 break;
00336
00337 case ID_ADD_SELECTOR:
00338 {
00339 guchar *name = NULL;
00340
00341 if (a_this->content.class_name) {
00342 name = g_strndup
00343 (a_this->content.id_name->stryng->str,
00344 a_this->content.id_name->stryng->len);
00345
00346 if (name) {
00347 g_string_append_printf
00348 (str_buf, "#%s",
00349 name);
00350 g_free (name);
00351 name = NULL;
00352 }
00353 }
00354 }
00355
00356 break;
00357
00358 case PSEUDO_CLASS_ADD_SELECTOR:
00359 {
00360 if (a_this->content.pseudo) {
00361 guchar *tmp_str = NULL;
00362
00363 tmp_str = cr_pseudo_to_string
00364 (a_this->content.pseudo);
00365 if (tmp_str) {
00366 g_string_append_printf
00367 (str_buf, ":%s",
00368 tmp_str);
00369 g_free (tmp_str);
00370 tmp_str = NULL;
00371 }
00372 }
00373 }
00374 break;
00375
00376 case ATTRIBUTE_ADD_SELECTOR:
00377 if (a_this->content.attr_sel) {
00378 guchar *tmp_str = NULL;
00379
00380 g_string_append_printf (str_buf, "[");
00381 tmp_str = cr_attr_sel_to_string
00382 (a_this->content.attr_sel);
00383 if (tmp_str) {
00384 g_string_append_printf
00385 (str_buf, "%s]", tmp_str);
00386 g_free (tmp_str);
00387 tmp_str = NULL;
00388 }
00389 }
00390 break;
00391
00392 default:
00393 break;
00394 }
00395
00396 if (str_buf) {
00397 result = str_buf->str;
00398 g_string_free (str_buf, FALSE);
00399 str_buf = NULL;
00400 }
00401
00402 return result;
00403 }
00404
00405
00406
00407
00408
00409
00410
00411 void
00412 cr_additional_sel_dump (CRAdditionalSel * a_this, FILE * a_fp)
00413 {
00414 guchar *tmp_str = NULL;
00415
00416 g_return_if_fail (a_fp);
00417
00418 if (a_this) {
00419 tmp_str = cr_additional_sel_to_string (a_this);
00420 if (tmp_str) {
00421 fprintf (a_fp, "%s", tmp_str);
00422 g_free (tmp_str);
00423 tmp_str = NULL;
00424 }
00425 }
00426 }
00427
00428
00429
00430
00431
00432
00433 void
00434 cr_additional_sel_destroy (CRAdditionalSel * a_this)
00435 {
00436 g_return_if_fail (a_this);
00437
00438 switch (a_this->type) {
00439 case CLASS_ADD_SELECTOR:
00440 cr_string_destroy (a_this->content.class_name);
00441 a_this->content.class_name = NULL;
00442 break;
00443
00444 case PSEUDO_CLASS_ADD_SELECTOR:
00445 cr_pseudo_destroy (a_this->content.pseudo);
00446 a_this->content.pseudo = NULL;
00447 break;
00448
00449 case ID_ADD_SELECTOR:
00450 cr_string_destroy (a_this->content.id_name);
00451 a_this->content.id_name = NULL;
00452 break;
00453
00454 case ATTRIBUTE_ADD_SELECTOR:
00455 cr_attr_sel_destroy (a_this->content.attr_sel);
00456 a_this->content.attr_sel = NULL;
00457 break;
00458
00459 default:
00460 break;
00461 }
00462
00463 if (a_this->next) {
00464 cr_additional_sel_destroy (a_this->next);
00465 }
00466
00467 g_free (a_this);
00468 }