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 CRAttrSel *
00040 cr_attr_sel_new (void)
00041 {
00042 CRAttrSel *result = NULL;
00043
00044 result = g_malloc0 (sizeof (CRAttrSel));
00045
00046 return result;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 enum CRStatus
00059 cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel)
00060 {
00061 CRAttrSel *cur_sel = NULL;
00062
00063 g_return_val_if_fail (a_this && a_attr_sel,
00064 CR_BAD_PARAM_ERROR);
00065
00066 for (cur_sel = a_this;
00067 cur_sel->next;
00068 cur_sel = cur_sel->next) ;
00069
00070 cur_sel->next = a_attr_sel;
00071 a_attr_sel->prev = cur_sel;
00072
00073 return CR_OK;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 enum CRStatus
00086 cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this,
00087 CRAttrSel * a_attr_sel)
00088 {
00089 g_return_val_if_fail (a_this && a_attr_sel,
00090 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 if (cur->prev) {
00111 g_string_append_c (str_buf, ' ');
00112 }
00113
00114 if (cur->name) {
00115 guchar *name = NULL;
00116
00117 name = g_strndup (cur->name->stryng->str,
00118 cur->name->stryng->len);
00119 if (name) {
00120 g_string_append (str_buf, name);
00121 g_free (name);
00122 name = NULL;
00123 }
00124 }
00125
00126 if (cur->value) {
00127 guchar *value = NULL;
00128
00129 value = g_strndup (cur->value->stryng->str,
00130 cur->value->stryng->len);
00131 if (value) {
00132 switch (cur->match_way) {
00133 case SET:
00134 break;
00135
00136 case EQUALS:
00137 g_string_append_c (str_buf, '=');
00138 break;
00139
00140 case INCLUDES:
00141 g_string_append (str_buf, "~=");
00142 break;
00143
00144 case DASHMATCH:
00145 g_string_append (str_buf, "|=");
00146 break;
00147
00148 default:
00149 break;
00150 }
00151
00152 g_string_append_printf
00153 (str_buf, "\"%s\"", value);
00154
00155 g_free (value);
00156 value = NULL;
00157 }
00158 }
00159 }
00160
00161 if (str_buf) {
00162 result = str_buf->str;
00163 g_string_free (str_buf, FALSE);
00164 }
00165
00166 return result;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 void
00176 cr_attr_sel_dump (CRAttrSel * a_this, FILE * a_fp)
00177 {
00178 guchar *tmp_str = NULL;
00179
00180 g_return_if_fail (a_this);
00181
00182 tmp_str = cr_attr_sel_to_string (a_this);
00183
00184 if (tmp_str) {
00185 fprintf (a_fp, "%s", tmp_str);
00186 g_free (tmp_str);
00187 tmp_str = NULL;
00188 }
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 void
00198 cr_attr_sel_destroy (CRAttrSel * a_this)
00199 {
00200 g_return_if_fail (a_this);
00201
00202 if (a_this->name) {
00203 cr_string_destroy (a_this->name);
00204 a_this->name = NULL;
00205 }
00206
00207 if (a_this->value) {
00208 cr_string_destroy (a_this->value);
00209 a_this->value = NULL;
00210 }
00211
00212 if (a_this->next) {
00213 cr_attr_sel_destroy (a_this->next);
00214 a_this->next = NULL;
00215 }
00216
00217 if (a_this) {
00218 g_free (a_this);
00219 a_this = NULL;
00220 }
00221 }