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