00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "string.h"
00024 #include "cr-stylesheet.h"
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 CRStyleSheet *
00037 cr_stylesheet_new (CRStatement * a_stmts)
00038 {
00039 CRStyleSheet *result;
00040
00041 result = g_try_malloc (sizeof (CRStyleSheet));
00042 if (!result) {
00043 cr_utils_trace_info ("Out of memory");
00044 return NULL;
00045 }
00046
00047 memset (result, 0, sizeof (CRStyleSheet));
00048
00049 if (a_stmts)
00050 result->statements = a_stmts;
00051
00052 return result;
00053 }
00054
00055
00056
00057
00058
00059 gchar *
00060 cr_stylesheet_to_string (CRStyleSheet const *a_this)
00061 {
00062 gchar *str = NULL;
00063 GString *stringue = NULL;
00064 CRStatement const *cur_stmt = NULL;
00065
00066 g_return_val_if_fail (a_this, NULL);
00067
00068 if (a_this->statements) {
00069 stringue = g_string_new (NULL) ;
00070 g_return_val_if_fail (stringue, NULL) ;
00071 }
00072 for (cur_stmt = a_this->statements;
00073 cur_stmt; cur_stmt = cur_stmt->next) {
00074 if (cur_stmt->prev) {
00075 g_string_append (stringue, "\n\n") ;
00076 }
00077 str = cr_statement_to_string (cur_stmt, 0) ;
00078 if (str) {
00079 g_string_append (stringue, str) ;
00080 g_free (str) ;
00081 str = NULL ;
00082 }
00083 }
00084 if (stringue) {
00085 str = stringue->str ;
00086 g_string_free (stringue, FALSE) ;
00087 stringue = NULL ;
00088 }
00089 return str ;
00090 }
00091
00092
00093
00094
00095
00096
00097 void
00098 cr_stylesheet_dump (CRStyleSheet const * a_this, FILE * a_fp)
00099 {
00100 gchar *str = NULL ;
00101
00102 g_return_if_fail (a_this);
00103
00104 str = cr_stylesheet_to_string (a_this) ;
00105 if (str) {
00106 fprintf (a_fp, "%s", str) ;
00107 g_free (str) ;
00108 str = NULL ;
00109 }
00110 }
00111
00112
00113
00114
00115
00116
00117 gint
00118 cr_stylesheet_nr_rules (CRStyleSheet const * a_this)
00119 {
00120 g_return_val_if_fail (a_this, -1);
00121
00122 return cr_statement_nr_rules (a_this->statements);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 CRStatement *
00133 cr_stylesheet_statement_get_from_list (CRStyleSheet * a_this, int itemnr)
00134 {
00135 g_return_val_if_fail (a_this, NULL);
00136
00137 return cr_statement_get_from_list (a_this->statements, itemnr);
00138 }
00139
00140 void
00141 cr_stylesheet_ref (CRStyleSheet * a_this)
00142 {
00143 g_return_if_fail (a_this);
00144
00145 a_this->ref_count++;
00146 }
00147
00148 gboolean
00149 cr_stylesheet_unref (CRStyleSheet * a_this)
00150 {
00151 g_return_val_if_fail (a_this, FALSE);
00152
00153 if (a_this->ref_count)
00154 a_this->ref_count--;
00155
00156 if (!a_this->ref_count) {
00157 cr_stylesheet_destroy (a_this);
00158 return TRUE;
00159 }
00160
00161 return FALSE;
00162 }
00163
00164
00165
00166
00167
00168 void
00169 cr_stylesheet_destroy (CRStyleSheet * a_this)
00170 {
00171 g_return_if_fail (a_this);
00172
00173 if (a_this->statements) {
00174 cr_statement_destroy (a_this->statements);
00175 a_this->statements = NULL;
00176 }
00177 g_free (a_this);
00178 }