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 #ifndef __CR_DEFS_H__
35 #define __CR_DEFS_H__
36
37 #include <stdio.h>
38 #include <glib.h>
39 #include "libcroco-config.h"
40
41 G_BEGIN_DECLS
42
43 /**
44 *@file
45 *The Croco library basic types definitions
46 *And global definitions.
47 */
48
49 /**
50 *The status type returned
51 *by the methods of the croco library.
52 */
53 enum CRStatus {
54 CR_OK,
55 CR_BAD_PARAM_ERROR,
56 CR_INSTANCIATION_FAILED_ERROR,
57 CR_UNKNOWN_TYPE_ERROR,
58 CR_UNKNOWN_PROP_ERROR,
59 CR_UNKNOWN_PROP_VAL_ERROR,
60 CR_UNEXPECTED_POSITION_SCHEME,
61 CR_START_OF_INPUT_ERROR,
62 CR_END_OF_INPUT_ERROR,
63 CR_OUTPUT_TOO_SHORT_ERROR,
64 CR_INPUT_TOO_SHORT_ERROR,
65 CR_OUT_OF_BOUNDS_ERROR,
66 CR_EMPTY_PARSER_INPUT_ERROR,
67 CR_ENCODING_ERROR,
68 CR_ENCODING_NOT_FOUND_ERROR,
69 CR_PARSING_ERROR,
70 CR_SYNTAX_ERROR,
71 CR_NO_ROOT_NODE_ERROR,
72 CR_NO_TOKEN,
73 CR_OUT_OF_MEMORY_ERROR,
74 CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR,
75 CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR,
76 CR_ERROR,
77 CR_FILE_NOT_FOUND_ERROR,
78 CR_VALUE_NOT_FOUND_ERROR
79 } ;
80
81 /**
82 *Values used by
83 *cr_input_seek_position() ;
84 */
85 enum CRSeekPos {
86 CR_SEEK_CUR,
87 CR_SEEK_BEGIN,
88 CR_SEEK_END
89 } ;
90
91 /**
92 *Encoding values.
93 */
94 enum CREncoding
95 {
96 CR_UCS_4 = 1/*Must be not NULL*/,
97 CR_UCS_1,
98 CR_ISO_8859_1,
99 CR_ASCII,
100 CR_UTF_8,
101 CR_UTF_16,
102 CR_AUTO/*should be the last one*/
103 } ;
104
105
106
107
108 #define CROCO_LOG_DOMAIN "LIBCROCO"
109
110 #ifdef __GNUC__
111 #define cr_utils_trace(a_log_level, a_msg) \
112 g_log (CROCO_LOG_DOMAIN, \
113 G_LOG_LEVEL_CRITICAL, \
114 "file %s: line %d (%s): %s\n", \
115 __FILE__, \
116 __LINE__, \
117 __PRETTY_FUNCTION__, \
118 a_msg)
119 #else /*__GNUC__*/
120
121 #define cr_utils_trace(a_log_level, a_msg) \
122 g_log (CROCO_LOG_DOMAIN, \
123 G_LOG_LEVEL_CRITICAL, \
124 "file %s: line %d: %s\n", \
125 __FILE__, \
126 __LINE__, \
127 a_msg)
128 #endif
129
130 /**
131 *Traces an info message.
132 *The file, line and enclosing function
133 *of the message will be automatically
134 *added to the message.
135 *@param a_msg the msg to trace.
136 */
137 #define cr_utils_trace_info(a_msg) \
138 cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
139
140 /**
141 *Trace a debug message.
142 *The file, line and enclosing function
143 *of the message will be automatically
144 *added to the message.
145 *@param a_msg the msg to trace.
146 */
147 #define cr_utils_trace_debug(a_msg) \
148 cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
149
150
151 /****************************
152 *Encoding transformations and
153 *encoding helpers
154 ****************************/
155
156 enum CRStatus
157 cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len,
158 guint32 *a_out, gulong *a_consumed) ;
159
160 enum CRStatus
161 cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len,
162 guchar *a_out, gulong *a_out_len) ;
163
164 enum CRStatus
165 cr_utils_utf8_to_ucs1 (const guchar * a_in, gulong * a_in_len,
166 guchar *a_out, gulong *a_out_len) ;
167
168 enum CRStatus
169 cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len,
170 guchar *a_out, gulong *a_out_len) ;
171
172 enum CRStatus
173 cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start,
174 const guchar *a_in_end,
175 gulong *a_len) ;
176 enum CRStatus
177 cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start,
178 const guchar *a_in_end,
179 gulong *a_len) ;
180 enum CRStatus
181 cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start,
182 const guchar *a_in_end,
183 gulong *a_len) ;
184 enum CRStatus
185 cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start,
186 const guint32 *a_in_end,
187 gulong *a_len) ;
188
189 enum CRStatus
190 cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start,
191 gulong *a_in_len,
192 guchar **a_out,
193 gulong *a_len) ;
194
195 enum CRStatus
196 cr_utils_utf8_str_to_ucs1 (const guchar * a_in_start,
197 gulong * a_in_len,
198 guchar **a_out,
199 gulong *a_out_len) ;
200
201 enum CRStatus
202 cr_utils_utf8_to_ucs4 (const guchar * a_in,
203 gulong * a_in_len,
204 guint32 *a_out, gulong *a_out_len) ;
205
206 enum CRStatus
207 cr_utils_ucs4_str_to_utf8 (const guint32 *a_in,
208 gulong *a_in_len,
209 guchar **a_out, gulong *a_out_len) ;
210
211 enum CRStatus
212 cr_utils_utf8_str_to_ucs4 (const guchar * a_in,
213 gulong *a_in_len,
214 guint32 **a_out,
215 gulong *a_out_len) ;
216
217
218 /*****************************************
219 *CSS basic types identification utilities
220 *****************************************/
221
222 gboolean
223 cr_utils_is_newline (guint32 a_char) ;
224
225 gboolean
226 cr_utils_is_white_space (guint32 a_char) ;
227
228 gboolean
229 cr_utils_is_nonascii (guint32 a_char) ;
230
231 gboolean
232 cr_utils_is_hexa_char (guint32 a_char) ;
233
234
235 /**********************************
236 *Miscellaneous utility functions
237 ***********************************/
238
239 void
240 cr_utils_dump_n_chars (guchar a_char,
241 FILE *a_fp,
242 glong a_nb) ;
243
244 void
245 cr_utils_dump_n_chars2 (guchar a_char,
246 GString *a_string,
247 glong a_nb) ;
248 GList *
249 cr_utils_dup_glist_of_string (GList const *a_list) ;
250
251 GList *
252 cr_utils_dup_glist_of_cr_string (GList const * a_list_of_strings) ;
253
254 G_END_DECLS
255
256 #endif /*__CR_DEFS_H__*/