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