cr-utils.h

Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00018  * USA
00019  *
00020  * Author: Dodji Seketeli
00021  * Look at file COPYRIGHTS for copyright information
00022  */
00023 
00024 #ifndef __CR_DEFS_H__
00025 #define __CR_DEFS_H__
00026 
00027 #include <stdio.h>
00028 #include <glib.h>
00029 #include "libcroco-config.h"
00030 
00031 G_BEGIN_DECLS
00032 
00033 /**
00034  *@file
00035  *The Croco library basic types definitions
00036  *And global definitions.
00037  */
00038 
00039 /**
00040  *The status type returned
00041  *by the methods of the croco library.
00042  */
00043 enum CRStatus {
00044         CR_OK,
00045         CR_BAD_PARAM_ERROR,
00046         CR_INSTANCIATION_FAILED_ERROR,
00047         CR_UNKNOWN_TYPE_ERROR,
00048         CR_UNKNOWN_PROP_ERROR,
00049         CR_UNKNOWN_PROP_VAL_ERROR,
00050         CR_UNEXPECTED_POSITION_SCHEME,
00051         CR_START_OF_INPUT_ERROR,
00052         CR_END_OF_INPUT_ERROR,
00053         CR_OUTPUT_TOO_SHORT_ERROR,
00054         CR_INPUT_TOO_SHORT_ERROR,
00055         CR_OUT_OF_BOUNDS_ERROR,
00056         CR_EMPTY_PARSER_INPUT_ERROR,
00057         CR_ENCODING_ERROR,
00058         CR_ENCODING_NOT_FOUND_ERROR,
00059         CR_PARSING_ERROR,
00060         CR_SYNTAX_ERROR,
00061         CR_NO_ROOT_NODE_ERROR,
00062         CR_NO_TOKEN,
00063         CR_OUT_OF_MEMORY_ERROR,
00064         CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR,
00065         CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR,
00066         CR_ERROR,
00067         CR_FILE_NOT_FOUND_ERROR,
00068         CR_VALUE_NOT_FOUND_ERROR
00069 } ;
00070 
00071 /**
00072  *Values used by
00073  *cr_input_seek_position() ;
00074  */
00075 enum CRSeekPos {
00076         CR_SEEK_CUR,
00077         CR_SEEK_BEGIN,
00078         CR_SEEK_END
00079 } ;
00080 
00081 /**
00082  *Encoding values.
00083  */
00084 enum CREncoding 
00085 {
00086         CR_UCS_4 = 1/*Must be not NULL*/,
00087         CR_UCS_1,
00088         CR_ISO_8859_1,
00089         CR_ASCII,
00090         CR_UTF_8,
00091         CR_UTF_16,
00092         CR_AUTO/*should be the last one*/
00093 } ;
00094 
00095 
00096 
00097 
00098 #define CROCO_LOG_DOMAIN "LIBCROCO"
00099 
00100 #ifdef __GNUC__
00101 #define cr_utils_trace(a_log_level, a_msg) \
00102 g_log (CROCO_LOG_DOMAIN, \
00103        G_LOG_LEVEL_CRITICAL, \
00104        "file %s: line %d (%s): %s\n", \
00105        __FILE__, \
00106        __LINE__, \
00107        __PRETTY_FUNCTION__, \
00108         a_msg)
00109 #else /*__GNUC__*/
00110 
00111 #define cr_utils_trace(a_log_level, a_msg) \
00112 g_log (CROCO_LOG_DOMAIN, \
00113        G_LOG_LEVEL_CRITICAL, \
00114        "file %s: line %d: %s\n", \
00115        __FILE__, \
00116        __LINE__, \
00117        a_msg)
00118 #endif
00119 
00120 /**
00121  *Traces an info message.
00122  *The file, line and enclosing function
00123  *of the message will be automatically 
00124  *added to the message.
00125  *@param a_msg the msg to trace.
00126  */
00127 #define cr_utils_trace_info(a_msg) \
00128 cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
00129 
00130 /**
00131  *Trace a debug message.
00132  *The file, line and enclosing function
00133  *of the message will be automatically
00134  *added to the message.
00135  *@param a_msg the msg to trace.
00136  */
00137 #define cr_utils_trace_debug(a_msg) \
00138 cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
00139 
00140 
00141 /****************************
00142  *Encoding transformations and
00143  *encoding helpers
00144  ****************************/
00145 
00146 enum CRStatus
00147 cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len,
00148                                   guint32 *a_out, gulong *a_consumed) ;
00149 
00150 enum CRStatus
00151 cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len,
00152                        guchar *a_out, gulong *a_out_len) ;
00153 
00154 enum CRStatus
00155 cr_utils_utf8_to_ucs1 (const guchar * a_in, gulong * a_in_len,
00156                        guchar *a_out, gulong *a_out_len) ;
00157 
00158 enum CRStatus
00159 cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len,
00160                        guchar *a_out, gulong *a_out_len) ;
00161 
00162 enum CRStatus
00163 cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start,
00164                                const guchar *a_in_end,
00165                                gulong *a_len) ;
00166 enum CRStatus
00167 cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start, 
00168                                const guchar *a_in_end,
00169                                gulong *a_len) ;
00170 enum CRStatus
00171 cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start,
00172                                const guchar *a_in_end,
00173                                gulong *a_len) ;
00174 enum CRStatus
00175 cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start, 
00176                                const guint32 *a_in_end,
00177                                gulong *a_len) ;
00178 
00179 enum CRStatus
00180 cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start, 
00181                            gulong *a_in_len,
00182                            guchar **a_out, 
00183                            gulong *a_len) ;
00184 
00185 enum CRStatus
00186 cr_utils_utf8_str_to_ucs1 (const guchar * a_in_start, 
00187                            gulong * a_in_len,
00188                            guchar **a_out, 
00189                            gulong *a_out_len) ;
00190 
00191 enum CRStatus
00192 cr_utils_utf8_to_ucs4 (const guchar * a_in, 
00193                        gulong * a_in_len,
00194                        guint32 *a_out, gulong *a_out_len) ;
00195 
00196 enum CRStatus
00197 cr_utils_ucs4_str_to_utf8 (const guint32 *a_in, 
00198                            gulong *a_in_len,
00199                            guchar **a_out, gulong *a_out_len) ;
00200 
00201 enum CRStatus
00202 cr_utils_utf8_str_to_ucs4 (const guchar * a_in, 
00203                            gulong *a_in_len,
00204                            guint32 **a_out, 
00205                            gulong *a_out_len) ;
00206 
00207 
00208 /*****************************************
00209  *CSS basic types identification utilities
00210  *****************************************/
00211 
00212 gboolean
00213 cr_utils_is_newline (guint32 a_char) ;
00214 
00215 gboolean
00216 cr_utils_is_white_space (guint32 a_char) ;
00217 
00218 gboolean
00219 cr_utils_is_nonascii (guint32 a_char) ;
00220 
00221 gboolean
00222 cr_utils_is_hexa_char (guint32 a_char) ;
00223 
00224 
00225 /**********************************
00226  *Miscellaneous utility functions
00227  ***********************************/
00228 
00229 void
00230 cr_utils_dump_n_chars (guchar a_char, 
00231                        FILE *a_fp, 
00232                        glong a_nb) ;
00233 
00234 void
00235 cr_utils_dump_n_chars2 (guchar a_char, 
00236                         GString *a_string,
00237                         glong a_nb) ;
00238 gdouble
00239 cr_utils_n_to_0_dot_n (glong a_n, glong decimal_places) ;
00240 
00241 GList *
00242 cr_utils_dup_glist_of_string (GList *a_list) ;
00243 
00244 GList *
00245 cr_utils_dup_glist_of_cr_string (GList * a_list_of_strings) ;
00246 
00247 G_END_DECLS
00248 
00249 #endif /*__CR_DEFS_H__*/

Generated on Thu Mar 9 19:19:09 2006 for Libcroco by  doxygen 1.4.6