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