1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
2 
3 /* libcroco - Library for parsing and applying CSS
4  * Copyright (C) 2006-2019 Free Software Foundation, Inc.
5  *
6  * This file is not part of the GNU gettext program, but is used with
7  * GNU gettext.
8  *
9  * The original copyright notice is as follows:
10  */
11 
12 /*
13  * This file is part of The Croco Library
14  *
15  * Copyright (C) 2003-2004 Dodji Seketeli.  All Rights Reserved.
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of version 2.1 of the GNU Lesser General Public
19  * License as published by the Free Software Foundation.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29  * USA
30  *
31  * Author: Dodji Seketeli
32  */
33 
34 #include <stdio.h>
35 #include <glib.h>
36 #include "cr-utils.h"
37 #include "cr-rgb.h"
38 #include "cr-num.h"
39 #include "cr-string.h"
40 
41 #ifndef __CR_TERM_H__
42 #define __CR_TERM_H__
43 
44 G_BEGIN_DECLS
45 
46 /**
47  *@file
48  *Declaration of the #CRTem class.
49  */
50 
51 enum CRTermType
52 {
53         TERM_NO_TYPE = 0,
54         TERM_NUMBER,
55         TERM_FUNCTION,
56         TERM_STRING,
57         TERM_IDENT,
58         TERM_URI,
59         TERM_RGB,
60         TERM_UNICODERANGE,
61         TERM_HASH
62 } ;
63 
64 
65 enum UnaryOperator
66 {
67         NO_UNARY_UOP = 0,
68         PLUS_UOP,
69         MINUS_UOP,
70         EMPTY_UNARY_UOP
71 } ;
72 
73 enum Operator
74 {
75         NO_OP = 0,
76         DIVIDE,
77         COMMA
78 } ;
79 
80 struct _CRTerm ;
81 typedef struct _CRTerm CRTerm ;
82 
83 /**
84  *An abstraction of a css2 term as
85  *defined in the CSS2 spec in appendix D.1:
86  *term ::=
87  *[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S*
88  *| ANGLE S* | TIME S* | FREQ S* | function ]
89  * | STRING S* | IDENT S* | URI S* | RGB S*
90  *| UNICODERANGE S* | hexcolor
91  */
92 struct _CRTerm
93 {
94         /**
95          *The type of the term.
96          */
97         enum CRTermType type ;
98 
99         /**
100          *The unary operator associated to
101          *the current term.
102          */
103         enum UnaryOperator unary_op ;
104 
105         /**
106          *The operator associated to the current term.
107          */
108         enum Operator the_operator ;
109 
110 
111         /**
112          *The content of the term.
113          *Depending of the type of the term,
114          *this holds either a number, a percentage ...
115          */
116         union
117         {
118                 CRNum *num ;
119                 CRString * str ;
120                 CRRgb * rgb ;
121         } content ;
122 
123         /**
124          *If the term is of type UNICODERANGE,
125          *this field holds the upper bound of the range.
126          *if the term is of type FUNCTION, this holds
127          *an instance of CRTerm that represents
128          * the expression which is the argument of the function.
129          */
130         union
131         {
132                 CRTerm *func_param ;
133         } ext_content ;
134 
135         /**
136          *A spare pointer, just in case.
137          *Can be used by the application.
138          */
139         gpointer app_data ;
140 
141         glong ref_count ;
142 
143         /**
144          *A pointer to the next term,
145          *just in case this term is part of
146          *an expression.
147          */
148         CRTerm *next ;
149 
150         /**
151          *A pointer to the previous
152          *term.
153          */
154         CRTerm *prev ;
155         CRParsingLocation location ;
156 } ;
157 
158 CRTerm * cr_term_parse_expression_from_buf (const guchar *a_buf,
159                                             enum CREncoding a_encoding) ;
160 CRTerm * cr_term_new (void) ;
161 
162 enum CRStatus cr_term_set_number (CRTerm *a_this, CRNum *a_num) ;
163 
164 enum CRStatus cr_term_set_function (CRTerm *a_this,
165                                     CRString *a_func_name,
166                                     CRTerm *a_func_param) ;
167 
168 enum CRStatus cr_term_set_string (CRTerm *a_this, CRString *a_str) ;
169 
170 enum CRStatus cr_term_set_ident (CRTerm *a_this, CRString *a_str) ;
171 
172 enum CRStatus cr_term_set_uri (CRTerm *a_this, CRString *a_str) ;
173 
174 enum CRStatus cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) ;
175 
176 enum CRStatus cr_term_set_hash (CRTerm *a_this, CRString *a_str) ;
177 
178 CRTerm * cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) ;
179 
180 CRTerm * cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) ;
181 
182 guchar * cr_term_to_string (CRTerm const *a_this) ;
183 
184 guchar * cr_term_one_to_string (CRTerm const * a_this) ;
185 
186 void cr_term_dump (CRTerm const *a_this, FILE *a_fp) ;
187 
188 int cr_term_nr_values (CRTerm const *a_this) ;
189 
190 CRTerm * cr_term_get_from_list (CRTerm *a_this, int itemnr) ;
191 
192 void cr_term_ref (CRTerm *a_this) ;
193 
194 gboolean cr_term_unref (CRTerm *a_this) ;
195 
196 void cr_term_destroy (CRTerm * a_term) ;
197 
198 G_END_DECLS
199 
200 #endif /*__CR_TERM_H__*/
201