Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

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  * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020  * USA
00021  */
00022 
00023 #ifndef __CR_DEFS_H__
00024 #define __CR_DEFS_H__
00025 
00026 #include "libcroco-config.h"
00027 #include <stdio.h>
00028 #include <glib.h>
00029 
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_ERROR
00064 } ;
00065 
00066 /**
00067  *Values used by
00068  *cr_input_seek_position() ;
00069  */
00070 enum CRSeekPos {
00071         CR_SEEK_CUR,
00072         CR_SEEK_BEGIN,
00073         CR_SEEK_END
00074 } ;
00075 
00076 /**
00077  *Encoding values.
00078  */
00079 enum CREncoding 
00080 {
00081         CR_UCS_4 = 1/*Must be not NULL*/,
00082         CR_UCS_1,
00083         CR_ISO_8859_1,
00084         CR_ASCII,
00085         CR_UTF_8,
00086         CR_UTF_16,
00087         CR_AUTO/*should be the last one*/
00088 } ;
00089 
00090 
00091 
00092 
00093 #define CROCO_LOG_DOMAIN "LIBCROCO"
00094 
00095 #ifdef __GNUC__
00096 #define cr_utils_trace(a_log_level, a_msg) \
00097 g_log (CROCO_LOG_DOMAIN, \
00098        G_LOG_LEVEL_CRITICAL, \
00099        "file %s: line %d (%s): %s\n", \
00100        __FILE__, \
00101        __LINE__, \
00102        __PRETTY_FUNCTION__, \
00103         a_msg)
00104 #else /*__GNUC__*/
00105 
00106 #define cr_utils_trace(a_log_level, a_msg) \
00107 g_log (CROCO_LOG_DOMAIN, \
00108        G_LOG_LEVEL_CRITICAL, \
00109        "file %s: line %d: %s\n", \
00110        __FILE__, \
00111        __LINE__, \
00112        a_msg)
00113 #endif
00114 
00115 /**
00116  *Traces an info message.
00117  *The file, line and enclosing function
00118  *of the message will be automatically 
00119  *added to the message.
00120  *@param a_msg the msg to trace.
00121  */
00122 #define cr_utils_trace_info(a_msg) \
00123 cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
00124 
00125 /**
00126  *Trace a debug message.
00127  *The file, line and enclosing function
00128  *of the message will be automatically
00129  *added to the message.
00130  *@param a_msg the msg to trace.
00131  */
00132 #define cr_utils_trace_debug(a_msg) \
00133 cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
00134 
00135 
00136 /****************************
00137  *Encoding transformations and
00138  *encoding helpers
00139  ****************************/
00140 
00141 enum CRStatus
00142 cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len,
00143                                   guint32 *a_out, gulong *a_consumed) ;
00144 
00145 enum CRStatus
00146 cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len,
00147                        guchar *a_out, gulong *a_out_len) ;
00148 
00149 enum CRStatus
00150 cr_utils_utf8_to_ucs1 (const guchar * a_in, gulong * a_in_len,
00151                        guchar *a_out, gulong *a_out_len) ;
00152 
00153 enum CRStatus
00154 cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len,
00155                        guchar *a_out, gulong *a_out_len) ;
00156 
00157 enum CRStatus
00158 cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start,
00159                                const guchar *a_in_end,
00160                                gulong *a_len) ;
00161 enum CRStatus
00162 cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start, 
00163                                const guchar *a_in_end,
00164                                gulong *a_len) ;
00165 enum CRStatus
00166 cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start,
00167                                const guchar *a_in_end,
00168                                gulong *a_len) ;
00169 enum CRStatus
00170 cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start, 
00171                                const guint32 *a_in_end,
00172                                gulong *a_len) ;
00173 
00174 enum CRStatus
00175 cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start, 
00176                            gulong *a_in_len,
00177                            guchar **a_out, 
00178                            gulong *a_len) ;
00179 
00180 enum CRStatus
00181 cr_utils_utf8_str_to_ucs1 (const guchar * a_in_start, 
00182                            gulong * a_in_len,
00183                            guchar **a_out, 
00184                            gulong *a_out_len) ;
00185 
00186 enum CRStatus
00187 cr_utils_utf8_to_ucs4 (const guchar * a_in, 
00188                        gulong * a_in_len,
00189                        guint32 *a_out, gulong *a_out_len) ;
00190 
00191 enum CRStatus
00192 cr_utils_ucs4_str_to_utf8 (const guint32 *a_in, 
00193                            gulong *a_in_len,
00194                            guchar **a_out, gulong *a_out_len) ;
00195 
00196 enum CRStatus
00197 cr_utils_utf8_str_to_ucs4 (const guchar * a_in, 
00198                            gulong *a_in_len,
00199                            guint32 **a_out, 
00200                            gulong *a_out_len) ;
00201 
00202 
00203 /*****************************************
00204  *CSS basic types identification utilities
00205  *****************************************/
00206 
00207 gboolean
00208 cr_utils_is_newline (guint32 a_char) ;
00209 
00210 gboolean
00211 cr_utils_is_white_space (guint32 a_char) ;
00212 
00213 gboolean
00214 cr_utils_is_nonascii (guint32 a_char) ;
00215 
00216 gboolean
00217 cr_utils_is_hexa_char (guint32 a_char) ;
00218 
00219 
00220 /**********************************
00221  *Miscellaneous utility functions
00222  ***********************************/
00223 
00224 void
00225 cr_utils_dump_n_chars (guchar a_char, 
00226                        FILE *a_fp, 
00227                        glong a_nb) ;
00228 
00229 void
00230 cr_utils_dump_n_chars2 (guchar a_char, 
00231                         GString *a_string,
00232                         glong a_nb) ;
00233 gdouble
00234 cr_utils_n_to_0_dot_n (glong a_n) ;
00235 
00236 GList *
00237 cr_dup_glist_of_string (GList *a_list) ;
00238 
00239 G_END_DECLS
00240 
00241 #endif /*__CR_DEFS_H__*/

Generated on Wed Oct 1 01:36:49 2003 for Libcroco by doxygen 1.3.3