1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ 2 3 /* 4 * This file is part of The Croco Library 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of version 2.1 of the GNU Lesser General Public 8 * License as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 * USA 19 * 20 * Author: Dodji Seketeli 21 * Look at file COPYRIGHTS for copyright information 22 */ 23 24 #ifndef __CR_DEFS_H__ 25 #define __CR_DEFS_H__ 26 27 #include <stdio.h> 28 #include <glib.h> 29 /* 30 * We're disabling this #include for Inkscape: see comment in libcroco.h. 31 //#include "libcroco-config.h" 32 */ 33 34 G_BEGIN_DECLS 35 36 /** 37 *@file 38 *The Croco library basic types definitions 39 *And global definitions. 40 */ 41 42 /** 43 *The status type returned 44 *by the methods of the croco library. 45 */ 46 enum CRStatus { 47 CR_OK, 48 CR_BAD_PARAM_ERROR, 49 CR_INSTANCIATION_FAILED_ERROR, 50 CR_UNKNOWN_TYPE_ERROR, 51 CR_UNKNOWN_PROP_ERROR, 52 CR_UNKNOWN_PROP_VAL_ERROR, 53 CR_UNEXPECTED_POSITION_SCHEME, 54 CR_START_OF_INPUT_ERROR, 55 CR_END_OF_INPUT_ERROR, 56 CR_OUTPUT_TOO_SHORT_ERROR, 57 CR_INPUT_TOO_SHORT_ERROR, 58 CR_OUT_OF_BOUNDS_ERROR, 59 CR_EMPTY_PARSER_INPUT_ERROR, 60 CR_ENCODING_ERROR, 61 CR_ENCODING_NOT_FOUND_ERROR, 62 CR_PARSING_ERROR, 63 CR_SYNTAX_ERROR, 64 CR_NO_ROOT_NODE_ERROR, 65 CR_NO_TOKEN, 66 CR_OUT_OF_MEMORY_ERROR, 67 CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR, 68 CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR, 69 CR_ERROR, 70 CR_FILE_NOT_FOUND_ERROR, 71 CR_VALUE_NOT_FOUND_ERROR 72 } ; 73 74 /** 75 *Values used by 76 *cr_input_seek_position() ; 77 */ 78 enum CRSeekPos { 79 CR_SEEK_CUR, 80 CR_SEEK_BEGIN, 81 CR_SEEK_END 82 } ; 83 84 /** 85 *Encoding values. 86 */ 87 enum CREncoding 88 { 89 CR_UCS_4 = 1/*Must be not NULL*/, 90 CR_UCS_1, 91 CR_ISO_8859_1, 92 CR_ASCII, 93 CR_UTF_8, 94 CR_UTF_16, 95 CR_AUTO/*should be the last one*/ 96 } ; 97 98 99 100 101 #define CROCO_LOG_DOMAIN "LIBCROCO" 102 103 #ifdef __GNUC__ 104 #define cr_utils_trace(a_log_level, a_msg) \ 105 g_log (CROCO_LOG_DOMAIN, \ 106 G_LOG_LEVEL_CRITICAL, \ 107 "file %s: line %d (%s): %s\n", \ 108 __FILE__, \ 109 __LINE__, \ 110 __PRETTY_FUNCTION__, \ 111 a_msg) 112 #else /*__GNUC__*/ 113 114 #define cr_utils_trace(a_log_level, a_msg) \ 115 g_log (CROCO_LOG_DOMAIN, \ 116 G_LOG_LEVEL_CRITICAL, \ 117 "file %s: line %d: %s\n", \ 118 __FILE__, \ 119 __LINE__, \ 120 a_msg) 121 #endif 122 123 /** 124 *Traces an info message. 125 *The file, line and enclosing function 126 *of the message will be automatically 127 *added to the message. 128 *@param a_msg the msg to trace. 129 */ 130 #define cr_utils_trace_info(a_msg) \ 131 cr_utils_trace (G_LOG_LEVEL_INFO, a_msg) 132 133 /** 134 *Trace a debug message. 135 *The file, line and enclosing function 136 *of the message will be automatically 137 *added to the message. 138 *@param a_msg the msg to trace. 139 */ 140 #define cr_utils_trace_debug(a_msg) \ 141 cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ; 142 143 144 /**************************** 145 *Encoding transformations and 146 *encoding helpers 147 ****************************/ 148 149 enum CRStatus 150 cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len, 151 guint32 *a_out, gulong *a_consumed) ; 152 153 enum CRStatus 154 cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len, 155 guchar *a_out, gulong *a_out_len) ; 156 157 enum CRStatus 158 cr_utils_utf8_to_ucs1 (const guchar * a_in, gulong * a_in_len, 159 guchar *a_out, gulong *a_out_len) ; 160 161 enum CRStatus 162 cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len, 163 guchar *a_out, gulong *a_out_len) ; 164 165 enum CRStatus 166 cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start, 167 const guchar *a_in_end, 168 gulong *a_len) ; 169 enum CRStatus 170 cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start, 171 const guchar *a_in_end, 172 gulong *a_len) ; 173 enum CRStatus 174 cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start, 175 const guchar *a_in_end, 176 gulong *a_len) ; 177 enum CRStatus 178 cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start, 179 const guint32 *a_in_end, 180 gulong *a_len) ; 181 182 enum CRStatus 183 cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start, 184 gulong *a_in_len, 185 guchar **a_out, 186 gulong *a_len) ; 187 188 enum CRStatus 189 cr_utils_utf8_str_to_ucs1 (const guchar * a_in_start, 190 gulong * a_in_len, 191 guchar **a_out, 192 gulong *a_out_len) ; 193 194 enum CRStatus 195 cr_utils_utf8_to_ucs4 (const guchar * a_in, 196 gulong * a_in_len, 197 guint32 *a_out, gulong *a_out_len) ; 198 199 enum CRStatus 200 cr_utils_ucs4_str_to_utf8 (const guint32 *a_in, 201 gulong *a_in_len, 202 guchar **a_out, gulong *a_out_len) ; 203 204 enum CRStatus 205 cr_utils_utf8_str_to_ucs4 (const guchar * a_in, 206 gulong *a_in_len, 207 guint32 **a_out, 208 gulong *a_out_len) ; 209 210 211 /***************************************** 212 *CSS basic types identification utilities 213 *****************************************/ 214 215 gboolean 216 cr_utils_is_newline (guint32 a_char) ; 217 218 gboolean 219 cr_utils_is_white_space (guint32 a_char) ; 220 221 gboolean 222 cr_utils_is_nonascii (guint32 a_char) ; 223 224 gboolean 225 cr_utils_is_hexa_char (guint32 a_char) ; 226 227 228 /********************************** 229 *Miscellaneous utility functions 230 ***********************************/ 231 232 void 233 cr_utils_dump_n_chars (guchar a_char, 234 FILE *a_fp, 235 glong a_nb) ; 236 237 void 238 cr_utils_dump_n_chars2 (guchar a_char, 239 GString *a_string, 240 glong a_nb) ; 241 GList * 242 cr_utils_dup_glist_of_string (GList const *a_list) ; 243 244 GList * 245 cr_utils_dup_glist_of_cr_string (GList const * a_list_of_strings) ; 246 247 G_END_DECLS 248 249 #endif /*__CR_DEFS_H__*/ 250