cr-utils.h 6.4 KB

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