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