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