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 CRAttrSel *
00044 cr_attr_sel_new (void)
00045 {
00046 CRAttrSel *result = NULL;
00047
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, CR_BAD_PARAM_ERROR);
00068
00069 for (cur_sel = a_this; cur_sel->next; cur_sel = cur_sel->next) ;
00070
00071 cur_sel->next = a_attr_sel;
00072 a_attr_sel->prev = cur_sel;
00073
00074 return CR_OK;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 enum CRStatus
00087 cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel)
00088 {
00089 g_return_val_if_fail (a_this && a_attr_sel, CR_BAD_PARAM_ERROR);
00090
00091 a_attr_sel->next = a_this;
00092 a_this->prev = a_attr_sel;
00093
00094 return CR_OK;
00095 }
00096
00097 guchar *
00098 cr_attr_sel_to_string (CRAttrSel * a_this)
00099 {
00100 CRAttrSel *cur = NULL;
00101 guchar *result = NULL;
00102 GString *str_buf = NULL;
00103
00104 g_return_val_if_fail (a_this, NULL);
00105
00106 str_buf = g_string_new (NULL);
00107
00108 for (cur = a_this; cur; cur = cur->next) {
00109 if (cur->prev) {
00110 g_string_append_printf (str_buf, " ");
00111 }
00112
00113 if (cur->name) {
00114 guchar *name = NULL;
00115
00116 name = g_strndup (cur->name->str, cur->name->len);
00117 if (name) {
00118 g_string_append_printf (str_buf, "%s", name);
00119 g_free (name);
00120 name = NULL;
00121 }
00122 }
00123
00124 if (cur->value) {
00125 guchar *value = NULL;
00126
00127 value = g_strndup (cur->value->str, cur->value->len);
00128 if (value) {
00129 switch (cur->match_way) {
00130 case SET:
00131 break;
00132
00133 case EQUALS:
00134 g_string_append_printf (str_buf, "=");
00135 break;
00136
00137 case INCLUDES:
00138 g_string_append_printf
00139 (str_buf, "~=");
00140 break;
00141
00142 case DASHMATCH:
00143 g_string_append_printf
00144 (str_buf, "|=");
00145 break;
00146
00147 default:
00148 break;
00149 }
00150
00151 g_string_append_printf
00152 (str_buf, "\"%s\"", value);
00153
00154 g_free (value);
00155 value = NULL;
00156 }
00157 }
00158 }
00159
00160 if (str_buf) {
00161 result = str_buf->str;
00162 g_string_free (str_buf, FALSE);
00163 }
00164
00165 return result;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 void
00175 cr_attr_sel_dump (CRAttrSel * a_this, FILE * a_fp)
00176 {
00177 guchar *tmp_str = NULL;
00178
00179 g_return_if_fail (a_this);
00180
00181 tmp_str = cr_attr_sel_to_string (a_this);
00182
00183 if (tmp_str) {
00184 fprintf (a_fp, "%s", tmp_str);
00185 g_free (tmp_str);
00186 tmp_str = NULL;
00187 }
00188 }
00189
00190
00191
00192
00193
00194
00195
00196 void
00197 cr_attr_sel_destroy (CRAttrSel * a_this)
00198 {
00199 g_return_if_fail (a_this);
00200
00201 if (a_this->name) {
00202 g_string_free (a_this->name, TRUE);
00203 a_this->name = NULL;
00204 }
00205
00206 if (a_this->value) {
00207 g_string_free (a_this->value, TRUE);
00208 a_this->value = NULL;
00209 }
00210
00211 if (a_this->next) {
00212 cr_attr_sel_destroy (a_this->next);
00213 a_this->next = NULL;
00214 }
00215
00216 if (a_this) {
00217 g_free (a_this);
00218 a_this = NULL;
00219 }
00220 }