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 <stdio.h>
00028 #include "cr-attr-sel.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 CRAttrSel *
00045 cr_attr_sel_new (void)
00046 {
00047 CRAttrSel *result = NULL ;
00048 result = g_malloc0 (sizeof (CRAttrSel)) ;
00049
00050 return result ;
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 enum CRStatus
00063 cr_attr_sel_append_attr_sel (CRAttrSel *a_this, CRAttrSel *a_attr_sel)
00064 {
00065 CRAttrSel * cur_sel = NULL ;
00066
00067 g_return_val_if_fail (a_this && a_attr_sel,
00068 CR_BAD_PARAM_ERROR) ;
00069
00070 for (cur_sel = a_this ; cur_sel->next ; cur_sel = cur_sel->next) ;
00071
00072 cur_sel->next = a_attr_sel ;
00073 a_attr_sel->prev = cur_sel ;
00074
00075 return CR_OK ;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 enum CRStatus
00088 cr_attr_sel_prepend_attr_sel (CRAttrSel *a_this, CRAttrSel *a_attr_sel)
00089 {
00090 g_return_val_if_fail (a_this && a_attr_sel, CR_BAD_PARAM_ERROR);
00091
00092 a_attr_sel->next = a_this ;
00093 a_this->prev = a_attr_sel ;
00094
00095 return CR_OK ;
00096 }
00097
00098 guchar *
00099 cr_attr_sel_to_string (CRAttrSel *a_this)
00100 {
00101 CRAttrSel *cur = NULL ;
00102 guchar * result = NULL ;
00103 GString *str_buf = NULL ;
00104
00105 g_return_val_if_fail (a_this, NULL) ;
00106
00107 str_buf = g_string_new (NULL) ;
00108
00109 for (cur = a_this ; cur ; cur = cur->next)
00110 {
00111 if (cur->prev)
00112 {
00113 g_string_append_printf (str_buf," ") ;
00114 }
00115
00116 if (cur->name)
00117 {
00118 guchar *name = NULL ;
00119
00120 name = g_strndup (cur->name->str,
00121 cur->name->len) ;
00122 if (name)
00123 {
00124 g_string_append_printf (str_buf,
00125 "%s", name) ;
00126 g_free (name) ;
00127 name = NULL ;
00128 }
00129 }
00130
00131 if (cur->value)
00132 {
00133 guchar *value = NULL ;
00134
00135 value = g_strndup (cur->value->str,
00136 cur->value->len) ;
00137 if (value)
00138 {
00139 switch (cur->match_way)
00140 {
00141 case SET:
00142 break ;
00143
00144 case EQUALS:
00145 g_string_append_printf
00146 (str_buf,"=") ;
00147 break ;
00148
00149 case INCLUDES:
00150 g_string_append_printf
00151 (str_buf,"~=") ;
00152 break ;
00153
00154 case DASHMATCH:
00155 g_string_append_printf
00156 (str_buf,"|=") ;
00157 break ;
00158
00159 default:
00160 break ;
00161 }
00162
00163 g_string_append_printf
00164 (str_buf,"\"%s\"",value) ;
00165
00166 g_free (value) ;
00167 value = NULL ;
00168 }
00169 }
00170 }
00171
00172 if (str_buf)
00173 {
00174 result = str_buf->str ;
00175 g_string_free (str_buf, FALSE) ;
00176 }
00177
00178 return result ;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187 void
00188 cr_attr_sel_dump (CRAttrSel *a_this, FILE *a_fp)
00189 {
00190 guchar * tmp_str = NULL ;
00191
00192 g_return_if_fail (a_this) ;
00193
00194 tmp_str = cr_attr_sel_to_string (a_this) ;
00195
00196 if (tmp_str)
00197 {
00198 fprintf (a_fp, "%s", tmp_str) ;
00199 g_free (tmp_str) ;
00200 tmp_str = NULL ;
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 void
00212 cr_attr_sel_destroy (CRAttrSel *a_this)
00213 {
00214 g_return_if_fail (a_this) ;
00215
00216 if (a_this->name)
00217 {
00218 g_string_free (a_this->name, TRUE) ;
00219 a_this->name = NULL ;
00220 }
00221
00222 if (a_this->value)
00223 {
00224 g_string_free (a_this->value, TRUE) ;
00225 a_this->value = NULL ;
00226 }
00227
00228 if (a_this->next)
00229 {
00230 cr_attr_sel_destroy (a_this->next) ;
00231 a_this->next = NULL ;
00232 }
00233
00234 if (a_this)
00235 {
00236 g_free (a_this) ;
00237 a_this = NULL ;
00238 }
00239 }