| 1 | /* GLIB - Library of useful routines for C programming |
| 2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU Library General Public |
| 14 | * License along with this library; if not, write to the |
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | * Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * Modified by the GLib Team and others 1997-1999. See the AUTHORS |
| 21 | * file for a list of people on the GLib Team. See the ChangeLog |
| 22 | * files for a list of changes. These files are distributed with |
| 23 | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
| 24 | * Modified: Steve Ratcliffe May 1999. File exists so that pmidi |
| 25 | * is not dependant on glib. |
| 26 | */ |
| 27 | |
| 28 | #ifndef __G_LIB_H__ |
| 29 | #define __G_LIB_H__ |
| 30 | |
| 31 | |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
| 34 | |
| 35 | /* system specific config file glibconfig.h provides definitions for |
| 36 | * the extrema of many of the standard types. These are: |
| 37 | * |
| 38 | * G_MINSHORT, G_MAXSHORT |
| 39 | * G_MININT, G_MAXINT |
| 40 | * G_MINLONG, G_MAXLONG |
| 41 | * G_MINFLOAT, G_MAXFLOAT |
| 42 | * G_MINDOUBLE, G_MAXDOUBLE |
| 43 | * |
| 44 | * It also provides the following typedefs: |
| 45 | * |
| 46 | * gint8, guint8 |
| 47 | * gint16, guint16 |
| 48 | * gint32, guint32 |
| 49 | * gint64, guint64 |
| 50 | * |
| 51 | * It defines the G_BYTE_ORDER symbol to one of G_*_ENDIAN (see later in |
| 52 | * this file). |
| 53 | * |
| 54 | * And it provides a way to store and retrieve a `gint' in/from a `gpointer'. |
| 55 | * This is useful to pass an integer instead of a pointer to a callback. |
| 56 | * |
| 57 | * GINT_TO_POINTER(i), GUINT_TO_POINTER(i) |
| 58 | * GPOINTER_TO_INT(p), GPOINTER_TO_UINT(p) |
| 59 | * |
| 60 | * Finally, it provide the following wrappers to STDC functions: |
| 61 | * |
| 62 | * g_ATEXIT |
| 63 | * To register hooks which are executed on exit(). |
| 64 | * Usually a wrapper for STDC atexit. |
| 65 | * |
| 66 | * void *g_memmove(void *dest, const void *src, guint count); |
| 67 | * A wrapper for STDC memmove, or an implementation, if memmove doesn't |
| 68 | * exist. The prototype looks like the above, give or take a const, |
| 69 | * or size_t. |
| 70 | */ |
| 71 | |
| 72 | typedef signed char gint8; |
| 73 | typedef unsigned char guint8; |
| 74 | typedef signed short gint16; |
| 75 | typedef unsigned short guint16; |
| 76 | typedef signed int gint32; |
| 77 | typedef unsigned int guint32; |
| 78 | |
| 79 | /* include varargs functions for assertment macros |
| 80 | */ |
| 81 | #include <stdarg.h> |
| 82 | |
| 83 | /* optionally feature DMALLOC memory allocation debugger |
| 84 | */ |
| 85 | #ifdef USE_DMALLOC |
| 86 | #include "dmalloc.h" |
| 87 | #endif |
| 88 | |
| 89 | |
| 90 | #ifdef NATIVE_WIN32 |
| 91 | |
| 92 | /* On native Win32, directory separator is the backslash, and search path |
| 93 | * separator is the semicolon. |
| 94 | */ |
| 95 | #define G_DIR_SEPARATOR '\\' |
| 96 | #define G_DIR_SEPARATOR_S "\\" |
| 97 | #define G_SEARCHPATH_SEPARATOR ';' |
| 98 | #define G_SEARCHPATH_SEPARATOR_S ";" |
| 99 | |
| 100 | #else /* !NATIVE_WIN32 */ |
| 101 | |
| 102 | /* Unix */ |
| 103 | |
| 104 | #define G_DIR_SEPARATOR '/' |
| 105 | #define G_DIR_SEPARATOR_S "/" |
| 106 | #define G_SEARCHPATH_SEPARATOR ':' |
| 107 | #define G_SEARCHPATH_SEPARATOR_S ":" |
| 108 | |
| 109 | #endif /* !NATIVE_WIN32 */ |
| 110 | |
| 111 | #ifdef __cplusplus |
| 112 | extern "C" { |
| 113 | #endif /* __cplusplus */ |
| 114 | |
| 115 | |
| 116 | /* Provide definitions for some commonly used macros. |
| 117 | * Some of them are only provided if they haven't already |
| 118 | * been defined. It is assumed that if they are already |
| 119 | * defined then the current definition is correct. |
| 120 | */ |
| 121 | #ifndef NULL |
| 122 | #define NULL ((void*) 0) |
| 123 | #endif |
| 124 | |
| 125 | #ifndef FALSE |
| 126 | #define FALSE (0) |
| 127 | #endif |
| 128 | |
| 129 | #ifndef TRUE |
| 130 | #define TRUE (!FALSE) |
| 131 | #endif |
| 132 | |
| 133 | #undef MAX |
| 134 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
| 135 | |
| 136 | #undef MIN |
| 137 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
| 138 | |
| 139 | #undef ABS |
| 140 | #define ABS(a) (((a) < 0) ? -(a) : (a)) |
| 141 | |
| 142 | #undef CLAMP |
| 143 | #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) |
| 144 | |
| 145 | |
| 146 | /* Define G_VA_COPY() to do the right thing for copying va_list variables. |
| 147 | * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy. |
| 148 | */ |
| 149 | #if !defined (G_VA_COPY) |
| 150 | # if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) |
| 151 | # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2)) |
| 152 | # elif defined (G_VA_COPY_AS_ARRAY) |
| 153 | # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list)) |
| 154 | # else /* va_list is a pointer */ |
| 155 | # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2)) |
| 156 | # endif /* va_list is a pointer */ |
| 157 | #endif /* !G_VA_COPY */ |
| 158 | |
| 159 | |
| 160 | /* Provide convenience macros for handling structure |
| 161 | * fields through their offsets. |
| 162 | */ |
| 163 | #define G_STRUCT_OFFSET(struct_type, member) \ |
| 164 | ((gulong) ((gchar*) &((struct_type*) 0)->member)) |
| 165 | #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \ |
| 166 | ((gpointer) ((gchar*) (struct_p) + (gulong) (struct_offset))) |
| 167 | #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \ |
| 168 | (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset))) |
| 169 | |
| 170 | |
| 171 | /* inlining hassle. for compilers that don't allow the `inline' keyword, |
| 172 | * mostly because of strict ANSI C compliance or dumbness, we try to fall |
| 173 | * back to either `__inline__' or `__inline'. |
| 174 | * we define G_CAN_INLINE, if the compiler seems to be actually |
| 175 | * *capable* to do function inlining, in which case inline function bodys |
| 176 | * do make sense. we also define G_INLINE_FUNC to properly export the |
| 177 | * function prototypes if no inlining can be performed. |
| 178 | * we special case most of the stuff, so inline functions can have a normal |
| 179 | * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1. |
| 180 | */ |
| 181 | #ifndef G_INLINE_FUNC |
| 182 | # define G_CAN_INLINE 1 |
| 183 | #endif |
| 184 | #ifdef G_HAVE_INLINE |
| 185 | # if defined (__GNUC__) && defined (__STRICT_ANSI__) |
| 186 | # undef inline |
| 187 | # define inline __inline__ |
| 188 | # endif |
| 189 | #else /* !G_HAVE_INLINE */ |
| 190 | # undef inline |
| 191 | # if defined (G_HAVE___INLINE__) |
| 192 | # define inline __inline__ |
| 193 | # else /* !inline && !__inline__ */ |
| 194 | # if defined (G_HAVE___INLINE) |
| 195 | # define inline __inline |
| 196 | # else /* !inline && !__inline__ && !__inline */ |
| 197 | # define inline /* don't inline, then */ |
| 198 | # ifndef G_INLINE_FUNC |
| 199 | # undef G_CAN_INLINE |
| 200 | # endif |
| 201 | # endif |
| 202 | # endif |
| 203 | #endif |
| 204 | #ifndef G_INLINE_FUNC |
| 205 | # ifdef __GNUC__ |
| 206 | # ifdef __OPTIMIZE__ |
| 207 | # define G_INLINE_FUNC extern inline |
| 208 | # else |
| 209 | # undef G_CAN_INLINE |
| 210 | # define G_INLINE_FUNC extern |
| 211 | # endif |
| 212 | # else /* !__GNUC__ */ |
| 213 | # ifdef G_CAN_INLINE |
| 214 | # define G_INLINE_FUNC static inline |
| 215 | # else |
| 216 | # define G_INLINE_FUNC extern |
| 217 | # endif |
| 218 | # endif /* !__GNUC__ */ |
| 219 | #endif /* !G_INLINE_FUNC */ |
| 220 | |
| 221 | |
| 222 | /* Provide simple macro statement wrappers (adapted from Perl): |
| 223 | * G_STMT_START { statements; } G_STMT_END; |
| 224 | * can be used as a single statement, as in |
| 225 | * if (x) G_STMT_START { ... } G_STMT_END; else ... |
| 226 | * |
| 227 | * For gcc we will wrap the statements within `({' and `})' braces. |
| 228 | * For SunOS they will be wrapped within `if (1)' and `else (void) 0', |
| 229 | * and otherwise within `do' and `while (0)'. |
| 230 | */ |
| 231 | #if !(defined (G_STMT_START) && defined (G_STMT_END)) |
| 232 | # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) |
| 233 | # define G_STMT_START (void)( |
| 234 | # define G_STMT_END ) |
| 235 | # else |
| 236 | # if (defined (sun) || defined (__sun__)) |
| 237 | # define G_STMT_START if (1) |
| 238 | # define G_STMT_END else (void)0 |
| 239 | # else |
| 240 | # define G_STMT_START do |
| 241 | # define G_STMT_END while (0) |
| 242 | # endif |
| 243 | # endif |
| 244 | #endif |
| 245 | |
| 246 | |
| 247 | /* Provide macros to feature the GCC function attribute. |
| 248 | */ |
| 249 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) |
| 250 | #define G_GNUC_PRINTF( format_idx, arg_idx ) \ |
| 251 | __attribute__((format (printf, format_idx, arg_idx))) |
| 252 | #define G_GNUC_SCANF( format_idx, arg_idx ) \ |
| 253 | __attribute__((format (scanf, format_idx, arg_idx))) |
| 254 | #define G_GNUC_FORMAT( arg_idx ) \ |
| 255 | __attribute__((format_arg (arg_idx))) |
| 256 | #define G_GNUC_NORETURN \ |
| 257 | __attribute__((noreturn)) |
| 258 | #define G_GNUC_CONST \ |
| 259 | __attribute__((const)) |
| 260 | #define G_GNUC_UNUSED \ |
| 261 | __attribute__((unused)) |
| 262 | #else /* !__GNUC__ */ |
| 263 | #define G_GNUC_PRINTF( format_idx, arg_idx ) |
| 264 | #define G_GNUC_SCANF( format_idx, arg_idx ) |
| 265 | #define G_GNUC_FORMAT( arg_idx ) |
| 266 | #define G_GNUC_NORETURN |
| 267 | #define G_GNUC_CONST |
| 268 | #define G_GNUC_UNUSED |
| 269 | #endif /* !__GNUC__ */ |
| 270 | |
| 271 | |
| 272 | /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with |
| 273 | * macros, so we can refer to them as strings unconditionally. |
| 274 | */ |
| 275 | #ifdef __GNUC__ |
| 276 | #define G_GNUC_FUNCTION __FUNCTION__ |
| 277 | #define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__ |
| 278 | #else /* !__GNUC__ */ |
| 279 | #define G_GNUC_FUNCTION "" |
| 280 | #define G_GNUC_PRETTY_FUNCTION "" |
| 281 | #endif /* !__GNUC__ */ |
| 282 | |
| 283 | /* we try to provide a usefull equivalent for ATEXIT if it is |
| 284 | * not defined, but use is actually abandoned. people should |
| 285 | * use g_atexit() instead. |
| 286 | */ |
| 287 | #ifndef ATEXIT |
| 288 | # define ATEXIT(proc) g_ATEXIT(proc) |
| 289 | #else |
| 290 | # define G_NATIVE_ATEXIT |
| 291 | #endif /* ATEXIT */ |
| 292 | |
| 293 | /* Hacker macro to place breakpoints for elected machines. |
| 294 | * Actual use is strongly deprecated of course ;) |
| 295 | */ |
| 296 | #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 |
| 297 | #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END |
| 298 | #elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2 |
| 299 | #define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END |
| 300 | #else /* !__i386__ && !__alpha__ */ |
| 301 | #define G_BREAKPOINT() |
| 302 | #endif /* __i386__ */ |
| 303 | |
| 304 | |
| 305 | /* Provide macros for easily allocating memory. The macros |
| 306 | * will cast the allocated memory to the specified type |
| 307 | * in order to avoid compiler warnings. (Makes the code neater). |
| 308 | */ |
| 309 | |
| 310 | # define g_new(type, count) \ |
| 311 | ((type *) malloc ((unsigned) sizeof (type) * (count))) |
| 312 | # define g_new0(type, count) \ |
| 313 | ((type *) calloc ((unsigned) sizeof (type) * (count), 1)) |
| 314 | # define g_renew(type, mem, count) \ |
| 315 | ((type *) realloc (mem, (unsigned) sizeof (type) * (count))) |
| 316 | |
| 317 | #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \ |
| 318 | g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \ |
| 319 | sizeof (type), \ |
| 320 | sizeof (type) * (pre_alloc), \ |
| 321 | (alloc_type)) \ |
| 322 | ) |
| 323 | #define g_chunk_new(type, chunk) ( \ |
| 324 | (type *) g_mem_chunk_alloc (chunk) \ |
| 325 | ) |
| 326 | #define g_chunk_new0(type, chunk) ( \ |
| 327 | (type *) g_mem_chunk_alloc0 (chunk) \ |
| 328 | ) |
| 329 | #define g_chunk_free(mem, mem_chunk) G_STMT_START { \ |
| 330 | g_mem_chunk_free ((mem_chunk), (mem)); \ |
| 331 | } G_STMT_END |
| 332 | |
| 333 | |
| 334 | #define g_string(x) #x |
| 335 | |
| 336 | |
| 337 | /* Provide macros for error handling. The "assert" macros will |
| 338 | * exit on failure. The "return" macros will exit the current |
| 339 | * function. Two different definitions are given for the macros |
| 340 | * if G_DISABLE_ASSERT is not defined, in order to support gcc's |
| 341 | * __PRETTY_FUNCTION__ capability. |
| 342 | */ |
| 343 | |
| 344 | #ifdef G_DISABLE_ASSERT |
| 345 | |
| 346 | #define g_assert(expr) |
| 347 | #define g_assert_not_reached() |
| 348 | |
| 349 | #else /* !G_DISABLE_ASSERT */ |
| 350 | |
| 351 | #ifdef __GNUC__ |
| 352 | |
| 353 | #define g_assert(expr) G_STMT_START{ \ |
| 354 | if (!(expr)) \ |
| 355 | g_log (G_LOG_DOMAIN, \ |
| 356 | G_LOG_LEVEL_ERROR, \ |
| 357 | "file %s: line %d (%s): assertion failed: (%s)", \ |
| 358 | __FILE__, \ |
| 359 | __LINE__, \ |
| 360 | __PRETTY_FUNCTION__, \ |
| 361 | #expr); }G_STMT_END |
| 362 | |
| 363 | #define g_assert_not_reached() G_STMT_START{ \ |
| 364 | g_log (G_LOG_DOMAIN, \ |
| 365 | G_LOG_LEVEL_ERROR, \ |
| 366 | "file %s: line %d (%s): should not be reached", \ |
| 367 | __FILE__, \ |
| 368 | __LINE__, \ |
| 369 | __PRETTY_FUNCTION__); }G_STMT_END |
| 370 | |
| 371 | #else /* !__GNUC__ */ |
| 372 | |
| 373 | #define g_assert(expr) G_STMT_START{ \ |
| 374 | if (!(expr)) \ |
| 375 | g_log (G_LOG_DOMAIN, \ |
| 376 | G_LOG_LEVEL_ERROR, \ |
| 377 | "file %s: line %d: assertion failed: (%s)", \ |
| 378 | __FILE__, \ |
| 379 | __LINE__, \ |
| 380 | #expr); }G_STMT_END |
| 381 | |
| 382 | #define g_assert_not_reached() G_STMT_START{ \ |
| 383 | g_log (G_LOG_DOMAIN, \ |
| 384 | G_LOG_LEVEL_ERROR, \ |
| 385 | "file %s: line %d: should not be reached", \ |
| 386 | __FILE__, \ |
| 387 | __LINE__); }G_STMT_END |
| 388 | |
| 389 | #endif /* __GNUC__ */ |
| 390 | |
| 391 | #endif /* !G_DISABLE_ASSERT */ |
| 392 | |
| 393 | |
| 394 | #ifdef G_DISABLE_CHECKS |
| 395 | |
| 396 | #define g_return_if_fail(expr) |
| 397 | #define g_return_val_if_fail(expr,val) |
| 398 | |
| 399 | #else /* !G_DISABLE_CHECKS */ |
| 400 | |
| 401 | #ifdef __GNUC__ |
| 402 | |
| 403 | #define g_return_if_fail(expr) G_STMT_START{ \ |
| 404 | if (!(expr)) \ |
| 405 | { \ |
| 406 | g_log (G_LOG_DOMAIN, \ |
| 407 | G_LOG_LEVEL_CRITICAL, \ |
| 408 | "file %s: line %d (%s): assertion `%s' failed.", \ |
| 409 | __FILE__, \ |
| 410 | __LINE__, \ |
| 411 | __PRETTY_FUNCTION__, \ |
| 412 | #expr); \ |
| 413 | return; \ |
| 414 | }; }G_STMT_END |
| 415 | |
| 416 | #define g_return_val_if_fail(expr,val) G_STMT_START{ \ |
| 417 | if (!(expr)) \ |
| 418 | { \ |
| 419 | g_log (G_LOG_DOMAIN, \ |
| 420 | G_LOG_LEVEL_CRITICAL, \ |
| 421 | "file %s: line %d (%s): assertion `%s' failed.", \ |
| 422 | __FILE__, \ |
| 423 | __LINE__, \ |
| 424 | __PRETTY_FUNCTION__, \ |
| 425 | #expr); \ |
| 426 | return val; \ |
| 427 | }; }G_STMT_END |
| 428 | |
| 429 | #else /* !__GNUC__ */ |
| 430 | |
| 431 | #define g_return_if_fail(expr) G_STMT_START{ \ |
| 432 | if (!(expr)) \ |
| 433 | { \ |
| 434 | g_log (G_LOG_DOMAIN, \ |
| 435 | G_LOG_LEVEL_CRITICAL, \ |
| 436 | "file %s: line %d: assertion `%s' failed.", \ |
| 437 | __FILE__, \ |
| 438 | __LINE__, \ |
| 439 | #expr); \ |
| 440 | return; \ |
| 441 | }; }G_STMT_END |
| 442 | |
| 443 | #define g_return_val_if_fail(expr, val) G_STMT_START{ \ |
| 444 | if (!(expr)) \ |
| 445 | { \ |
| 446 | g_log (G_LOG_DOMAIN, \ |
| 447 | G_LOG_LEVEL_CRITICAL, \ |
| 448 | "file %s: line %d: assertion `%s' failed.", \ |
| 449 | __FILE__, \ |
| 450 | __LINE__, \ |
| 451 | #expr); \ |
| 452 | return val; \ |
| 453 | }; }G_STMT_END |
| 454 | |
| 455 | #endif /* !__GNUC__ */ |
| 456 | |
| 457 | #endif /* !G_DISABLE_CHECKS */ |
| 458 | |
| 459 | |
| 460 | /* Provide type definitions for commonly used types. |
| 461 | * These are useful because a "gint8" can be adjusted |
| 462 | * to be 1 byte (8 bits) on all platforms. Similarly and |
| 463 | * more importantly, "gint32" can be adjusted to be |
| 464 | * 4 bytes (32 bits) on all platforms. |
| 465 | */ |
| 466 | |
| 467 | typedef char gchar; |
| 468 | typedef short gshort; |
| 469 | typedef long glong; |
| 470 | typedef int gint; |
| 471 | typedef gint gboolean; |
| 472 | |
| 473 | typedef unsigned char guchar; |
| 474 | typedef unsigned short gushort; |
| 475 | typedef unsigned long gulong; |
| 476 | typedef unsigned int guint; |
| 477 | |
| 478 | typedef float gfloat; |
| 479 | typedef double gdouble; |
| 480 | |
| 481 | /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms. |
| 482 | * Since gldouble isn't used anywhere, just disable it for now */ |
| 483 | |
| 484 | #if 0 |
| 485 | #ifdef HAVE_LONG_DOUBLE |
| 486 | typedef long double gldouble; |
| 487 | #else /* HAVE_LONG_DOUBLE */ |
| 488 | typedef double gldouble; |
| 489 | #endif /* HAVE_LONG_DOUBLE */ |
| 490 | #endif /* 0 */ |
| 491 | |
| 492 | typedef void* gpointer; |
| 493 | typedef const void *gconstpointer; |
| 494 | |
| 495 | |
| 496 | typedef gint32 gssize; |
| 497 | typedef guint32 gsize; |
| 498 | typedef guint32 GQuark; |
| 499 | typedef gint32 GTime; |
| 500 | |
| 501 | |
| 502 | /* Portable endian checks and conversions |
| 503 | * |
| 504 | * glibconfig.h defines G_BYTE_ORDER which expands to one of |
| 505 | * the below macros. |
| 506 | */ |
| 507 | #define G_LITTLE_ENDIAN 1234 |
| 508 | #define G_BIG_ENDIAN 4321 |
| 509 | #define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */ |
| 510 | |
| 511 | |
| 512 | /* Basic bit swapping functions |
| 513 | */ |
| 514 | #define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \ |
| 515 | (((guint16) (val) & (guint16) 0x00ffU) << 8) | \ |
| 516 | (((guint16) (val) & (guint16) 0xff00U) >> 8))) |
| 517 | #define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \ |
| 518 | (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \ |
| 519 | (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \ |
| 520 | (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \ |
| 521 | (((guint32) (val) & (guint32) 0xff000000U) >> 24))) |
| 522 | |
| 523 | /* Intel specific stuff for speed |
| 524 | */ |
| 525 | #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 |
| 526 | # define GUINT16_SWAP_LE_BE_X86(val) \ |
| 527 | (__extension__ \ |
| 528 | ({ register guint16 __v; \ |
| 529 | if (__builtin_constant_p (val)) \ |
| 530 | __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \ |
| 531 | else \ |
| 532 | __asm__ __const__ ("rorw $8, %w0" \ |
| 533 | : "=r" (__v) \ |
| 534 | : "0" ((guint16) (val))); \ |
| 535 | __v; })) |
| 536 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val)) |
| 537 | # if !defined(__i486__) && !defined(__i586__) \ |
| 538 | && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__) |
| 539 | # define GUINT32_SWAP_LE_BE_X86(val) \ |
| 540 | (__extension__ \ |
| 541 | ({ register guint32 __v; \ |
| 542 | if (__builtin_constant_p (val)) \ |
| 543 | __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ |
| 544 | else \ |
| 545 | __asm__ __const__ ("rorw $8, %w0\n\t" \ |
| 546 | "rorl $16, %0\n\t" \ |
| 547 | "rorw $8, %w0" \ |
| 548 | : "=r" (__v) \ |
| 549 | : "0" ((guint32) (val))); \ |
| 550 | __v; })) |
| 551 | # else /* 486 and higher has bswap */ |
| 552 | # define GUINT32_SWAP_LE_BE_X86(val) \ |
| 553 | (__extension__ \ |
| 554 | ({ register guint32 __v; \ |
| 555 | if (__builtin_constant_p (val)) \ |
| 556 | __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ |
| 557 | else \ |
| 558 | __asm__ __const__ ("bswap %0" \ |
| 559 | : "=r" (__v) \ |
| 560 | : "0" ((guint32) (val))); \ |
| 561 | __v; })) |
| 562 | # endif /* processor specific 32-bit stuff */ |
| 563 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val)) |
| 564 | #else /* !__i386__ */ |
| 565 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) |
| 566 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) |
| 567 | #endif /* __i386__ */ |
| 568 | |
| 569 | #ifdef G_HAVE_GINT64 |
| 570 | # define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ |
| 571 | (((guint64) (val) & \ |
| 572 | (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) | \ |
| 573 | (((guint64) (val) & \ |
| 574 | (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) | \ |
| 575 | (((guint64) (val) & \ |
| 576 | (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) | \ |
| 577 | (((guint64) (val) & \ |
| 578 | (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) << 8) | \ |
| 579 | (((guint64) (val) & \ |
| 580 | (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >> 8) | \ |
| 581 | (((guint64) (val) & \ |
| 582 | (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \ |
| 583 | (((guint64) (val) & \ |
| 584 | (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) | \ |
| 585 | (((guint64) (val) & \ |
| 586 | (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56))) |
| 587 | # if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 |
| 588 | # define GUINT64_SWAP_LE_BE_X86(val) \ |
| 589 | (__extension__ \ |
| 590 | ({ union { guint64 __ll; \ |
| 591 | guint32 __l[2]; } __r; \ |
| 592 | if (__builtin_constant_p (val)) \ |
| 593 | __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val); \ |
| 594 | else \ |
| 595 | { \ |
| 596 | union { guint64 __ll; \ |
| 597 | guint32 __l[2]; } __w; \ |
| 598 | __w.__ll = ((guint64) val); \ |
| 599 | __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ |
| 600 | __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ |
| 601 | } \ |
| 602 | __r.__ll; })) |
| 603 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val)) |
| 604 | # else /* !__i386__ */ |
| 605 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val)) |
| 606 | # endif |
| 607 | #endif |
| 608 | |
| 609 | #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val)) |
| 610 | #define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val)) |
| 611 | #define GUINT32_SWAP_LE_PDP(val) ((guint32) ( \ |
| 612 | (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \ |
| 613 | (((guint32) (val) & (guint32) 0xffff0000U) >> 16))) |
| 614 | #define GUINT32_SWAP_BE_PDP(val) ((guint32) ( \ |
| 615 | (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \ |
| 616 | (((guint32) (val) & (guint32) 0xff00ff00U) >> 8))) |
| 617 | |
| 618 | /* The G*_TO_?E() macros are defined in glibconfig.h. |
| 619 | * The transformation is symmetric, so the FROM just maps to the TO. |
| 620 | */ |
| 621 | #define GINT16_FROM_LE(val) (GINT16_TO_LE (val)) |
| 622 | #define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val)) |
| 623 | #define GINT16_FROM_BE(val) (GINT16_TO_BE (val)) |
| 624 | #define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val)) |
| 625 | #define GINT32_FROM_LE(val) (GINT32_TO_LE (val)) |
| 626 | #define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val)) |
| 627 | #define GINT32_FROM_BE(val) (GINT32_TO_BE (val)) |
| 628 | #define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val)) |
| 629 | |
| 630 | #ifdef G_HAVE_GINT64 |
| 631 | #define GINT64_FROM_LE(val) (GINT64_TO_LE (val)) |
| 632 | #define GUINT64_FROM_LE(val) (GUINT64_TO_LE (val)) |
| 633 | #define GINT64_FROM_BE(val) (GINT64_TO_BE (val)) |
| 634 | #define GUINT64_FROM_BE(val) (GUINT64_TO_BE (val)) |
| 635 | #endif |
| 636 | |
| 637 | #define GLONG_FROM_LE(val) (GLONG_TO_LE (val)) |
| 638 | #define GULONG_FROM_LE(val) (GULONG_TO_LE (val)) |
| 639 | #define GLONG_FROM_BE(val) (GLONG_TO_BE (val)) |
| 640 | #define GULONG_FROM_BE(val) (GULONG_TO_BE (val)) |
| 641 | |
| 642 | #define GINT_FROM_LE(val) (GINT_TO_LE (val)) |
| 643 | #define GUINT_FROM_LE(val) (GUINT_TO_LE (val)) |
| 644 | #define GINT_FROM_BE(val) (GINT_TO_BE (val)) |
| 645 | #define GUINT_FROM_BE(val) (GUINT_TO_BE (val)) |
| 646 | |
| 647 | |
| 648 | /* Portable versions of host-network order stuff |
| 649 | */ |
| 650 | #define g_ntohl(val) (GUINT32_FROM_BE (val)) |
| 651 | #define g_ntohs(val) (GUINT16_FROM_BE (val)) |
| 652 | #define g_htonl(val) (GUINT32_TO_BE (val)) |
| 653 | #define g_htons(val) (GUINT16_TO_BE (val)) |
| 654 | |
| 655 | |
| 656 | /* Glib version. |
| 657 | * we prefix variable declarations so they can |
| 658 | * properly get exported in windows dlls. |
| 659 | */ |
| 660 | #ifdef NATIVE_WIN32 |
| 661 | # ifdef GLIB_COMPILATION |
| 662 | # define GUTILS_C_VAR __declspec(dllexport) |
| 663 | # else /* !GLIB_COMPILATION */ |
| 664 | # define GUTILS_C_VAR extern __declspec(dllimport) |
| 665 | # endif /* !GLIB_COMPILATION */ |
| 666 | #else /* !NATIVE_WIN32 */ |
| 667 | # define GUTILS_C_VAR extern |
| 668 | #endif /* !NATIVE_WIN32 */ |
| 669 | |
| 670 | GUTILS_C_VAR const guint glib_major_version; |
| 671 | GUTILS_C_VAR const guint glib_minor_version; |
| 672 | GUTILS_C_VAR const guint glib_micro_version; |
| 673 | GUTILS_C_VAR const guint glib_interface_age; |
| 674 | GUTILS_C_VAR const guint glib_binary_age; |
| 675 | |
| 676 | #define GLIB_CHECK_VERSION(major,minor,micro) \ |
| 677 | (GLIB_MAJOR_VERSION > (major) || \ |
| 678 | (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \ |
| 679 | (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \ |
| 680 | GLIB_MICRO_VERSION >= (micro))) |
| 681 | |
| 682 | /* Forward declarations of glib types. |
| 683 | */ |
| 684 | typedef struct _GAllocator GAllocator; |
| 685 | typedef struct _GArray GArray; |
| 686 | typedef struct _GByteArray GByteArray; |
| 687 | typedef struct _GCache GCache; |
| 688 | typedef struct _GCompletion GCompletion; |
| 689 | typedef struct _GData GData; |
| 690 | typedef struct _GDebugKey GDebugKey; |
| 691 | typedef struct _GHashTable GHashTable; |
| 692 | typedef struct _GHook GHook; |
| 693 | typedef struct _GHookList GHookList; |
| 694 | typedef struct _GList GList; |
| 695 | typedef struct _GMemChunk GMemChunk; |
| 696 | typedef struct _GNode GNode; |
| 697 | typedef struct _GPtrArray GPtrArray; |
| 698 | typedef struct _GRelation GRelation; |
| 699 | typedef struct _GScanner GScanner; |
| 700 | typedef struct _GScannerConfig GScannerConfig; |
| 701 | typedef struct _GSList GSList; |
| 702 | typedef struct _GString GString; |
| 703 | typedef struct _GStringChunk GStringChunk; |
| 704 | typedef struct _GTimer GTimer; |
| 705 | typedef struct _GTree GTree; |
| 706 | typedef struct _GTuples GTuples; |
| 707 | typedef union _GTokenValue GTokenValue; |
| 708 | typedef struct _GIOChannel GIOChannel; |
| 709 | |
| 710 | typedef enum |
| 711 | { |
| 712 | G_TRAVERSE_LEAFS = 1 << 0, |
| 713 | G_TRAVERSE_NON_LEAFS = 1 << 1, |
| 714 | G_TRAVERSE_ALL = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS, |
| 715 | G_TRAVERSE_MASK = 0x03 |
| 716 | } GTraverseFlags; |
| 717 | |
| 718 | typedef enum |
| 719 | { |
| 720 | G_IN_ORDER, |
| 721 | G_PRE_ORDER, |
| 722 | G_POST_ORDER, |
| 723 | G_LEVEL_ORDER |
| 724 | } GTraverseType; |
| 725 | |
| 726 | /* Log level shift offset for user defined |
| 727 | * log levels (0-7 are used by GLib). |
| 728 | */ |
| 729 | #define G_LOG_LEVEL_USER_SHIFT (8) |
| 730 | |
| 731 | /* Glib log levels and flags. |
| 732 | */ |
| 733 | typedef enum |
| 734 | { |
| 735 | /* log flags */ |
| 736 | G_LOG_FLAG_RECURSION = 1 << 0, |
| 737 | G_LOG_FLAG_FATAL = 1 << 1, |
| 738 | |
| 739 | /* GLib log levels */ |
| 740 | G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */ |
| 741 | G_LOG_LEVEL_CRITICAL = 1 << 3, |
| 742 | G_LOG_LEVEL_WARNING = 1 << 4, |
| 743 | G_LOG_LEVEL_MESSAGE = 1 << 5, |
| 744 | G_LOG_LEVEL_INFO = 1 << 6, |
| 745 | G_LOG_LEVEL_DEBUG = 1 << 7, |
| 746 | |
| 747 | G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL) |
| 748 | } GLogLevelFlags; |
| 749 | |
| 750 | /* GLib log levels that are considered fatal by default */ |
| 751 | #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR) |
| 752 | |
| 753 | |
| 754 | typedef gpointer (*GCacheNewFunc) (gpointer key); |
| 755 | typedef gpointer (*GCacheDupFunc) (gpointer value); |
| 756 | typedef void (*GCacheDestroyFunc) (gpointer value); |
| 757 | typedef gint (*GCompareFunc) (gconstpointer a, |
| 758 | gconstpointer b); |
| 759 | typedef gchar* (*GCompletionFunc) (gpointer); |
| 760 | typedef void (*GDestroyNotify) (gpointer data); |
| 761 | typedef void (*GDataForeachFunc) (GQuark key_id, |
| 762 | gpointer data, |
| 763 | gpointer user_data); |
| 764 | typedef void (*GFunc) (gpointer data, |
| 765 | gpointer user_data); |
| 766 | typedef guint (*GHashFunc) (gconstpointer key); |
| 767 | typedef void (*GFreeFunc) (gpointer data); |
| 768 | typedef void (*GHFunc) (gpointer key, |
| 769 | gpointer value, |
| 770 | gpointer user_data); |
| 771 | typedef gboolean (*GHRFunc) (gpointer key, |
| 772 | gpointer value, |
| 773 | gpointer user_data); |
| 774 | typedef gint (*GHookCompareFunc) (GHook *new_hook, |
| 775 | GHook *sibling); |
| 776 | typedef gboolean (*GHookFindFunc) (GHook *hook, |
| 777 | gpointer data); |
| 778 | typedef void (*GHookMarshaller) (GHook *hook, |
| 779 | gpointer data); |
| 780 | typedef gboolean (*GHookCheckMarshaller) (GHook *hook, |
| 781 | gpointer data); |
| 782 | typedef void (*GHookFunc) (gpointer data); |
| 783 | typedef gboolean (*GHookCheckFunc) (gpointer data); |
| 784 | typedef void (*GHookFreeFunc) (GHookList *hook_list, |
| 785 | GHook *hook); |
| 786 | typedef void (*GLogFunc) (const gchar *log_domain, |
| 787 | GLogLevelFlags log_level, |
| 788 | const gchar *message, |
| 789 | gpointer user_data); |
| 790 | typedef gboolean (*GNodeTraverseFunc) (GNode *node, |
| 791 | gpointer data); |
| 792 | typedef void (*GNodeForeachFunc) (GNode *node, |
| 793 | gpointer data); |
| 794 | typedef gint (*GSearchFunc) (gpointer key, |
| 795 | gpointer data); |
| 796 | typedef void (*GScannerMsgFunc) (GScanner *scanner, |
| 797 | gchar *message, |
| 798 | gint error); |
| 799 | typedef gint (*GTraverseFunc) (gpointer key, |
| 800 | gpointer value, |
| 801 | gpointer data); |
| 802 | typedef void (*GVoidFunc) (void); |
| 803 | |
| 804 | |
| 805 | struct _GList |
| 806 | { |
| 807 | gpointer data; |
| 808 | GList *next; |
| 809 | GList *prev; |
| 810 | }; |
| 811 | |
| 812 | struct _GSList |
| 813 | { |
| 814 | gpointer data; |
| 815 | GSList *next; |
| 816 | }; |
| 817 | |
| 818 | struct _GString |
| 819 | { |
| 820 | gchar *str; |
| 821 | gint len; |
| 822 | }; |
| 823 | |
| 824 | struct _GArray |
| 825 | { |
| 826 | gchar *data; |
| 827 | guint len; |
| 828 | }; |
| 829 | |
| 830 | struct _GByteArray |
| 831 | { |
| 832 | guint8 *data; |
| 833 | guint len; |
| 834 | }; |
| 835 | |
| 836 | struct _GPtrArray |
| 837 | { |
| 838 | gpointer *pdata; |
| 839 | guint len; |
| 840 | }; |
| 841 | |
| 842 | struct _GTuples |
| 843 | { |
| 844 | guint len; |
| 845 | }; |
| 846 | |
| 847 | struct _GDebugKey |
| 848 | { |
| 849 | gchar *key; |
| 850 | guint value; |
| 851 | }; |
| 852 | |
| 853 | |
| 854 | /* Doubly linked lists |
| 855 | */ |
| 856 | void g_list_push_allocator (GAllocator *allocator); |
| 857 | void g_list_pop_allocator (void); |
| 858 | GList* g_list_alloc (void); |
| 859 | void g_list_free (GList *list); |
| 860 | void g_list_free_1 (GList *list); |
| 861 | GList* g_list_append (GList *list, |
| 862 | gpointer data); |
| 863 | GList* g_list_prepend (GList *list, |
| 864 | gpointer data); |
| 865 | GList* g_list_insert (GList *list, |
| 866 | gpointer data, |
| 867 | gint position); |
| 868 | GList* g_list_insert_sorted (GList *list, |
| 869 | gpointer data, |
| 870 | GCompareFunc func); |
| 871 | GList* g_list_concat (GList *list1, |
| 872 | GList *list2); |
| 873 | GList* g_list_remove (GList *list, |
| 874 | gpointer data); |
| 875 | GList* g_list_remove_link (GList *list, |
| 876 | GList *llink); |
| 877 | GList* g_list_reverse (GList *list); |
| 878 | GList* g_list_copy (GList *list); |
| 879 | GList* g_list_nth (GList *list, |
| 880 | guint n); |
| 881 | GList* g_list_find (GList *list, |
| 882 | gpointer data); |
| 883 | GList* g_list_find_custom (GList *list, |
| 884 | gpointer data, |
| 885 | GCompareFunc func); |
| 886 | gint g_list_position (GList *list, |
| 887 | GList *llink); |
| 888 | gint g_list_index (GList *list, |
| 889 | gpointer data); |
| 890 | GList* g_list_last (GList *list); |
| 891 | GList* g_list_first (GList *list); |
| 892 | guint g_list_length (GList *list); |
| 893 | void g_list_foreach (GList *list, |
| 894 | GFunc func, |
| 895 | gpointer user_data); |
| 896 | GList* g_list_sort (GList *list, |
| 897 | GCompareFunc compare_func); |
| 898 | gpointer g_list_nth_data (GList *list, |
| 899 | guint n); |
| 900 | #define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL) |
| 901 | #define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL) |
| 902 | |
| 903 | |
| 904 | /* Singly linked lists |
| 905 | */ |
| 906 | void g_slist_push_allocator (GAllocator *allocator); |
| 907 | void g_slist_pop_allocator (void); |
| 908 | GSList* g_slist_alloc (void); |
| 909 | void g_slist_free (GSList *list); |
| 910 | void g_slist_free_1 (GSList *list); |
| 911 | GSList* g_slist_append (GSList *list, |
| 912 | gpointer data); |
| 913 | GSList* g_slist_prepend (GSList *list, |
| 914 | gpointer data); |
| 915 | GSList* g_slist_insert (GSList *list, |
| 916 | gpointer data, |
| 917 | gint position); |
| 918 | GSList* g_slist_insert_sorted (GSList *list, |
| 919 | gpointer data, |
| 920 | GCompareFunc func); |
| 921 | GSList* g_slist_concat (GSList *list1, |
| 922 | GSList *list2); |
| 923 | GSList* g_slist_remove (GSList *list, |
| 924 | gpointer data); |
| 925 | GSList* g_slist_remove_link (GSList *list, |
| 926 | GSList *llink); |
| 927 | GSList* g_slist_reverse (GSList *list); |
| 928 | GSList* g_slist_copy (GSList *list); |
| 929 | GSList* g_slist_nth (GSList *list, |
| 930 | guint n); |
| 931 | GSList* g_slist_find (GSList *list, |
| 932 | gpointer data); |
| 933 | GSList* g_slist_find_custom (GSList *list, |
| 934 | gpointer data, |
| 935 | GCompareFunc func); |
| 936 | gint g_slist_position (GSList *list, |
| 937 | GSList *llink); |
| 938 | gint g_slist_index (GSList *list, |
| 939 | gpointer data); |
| 940 | GSList* g_slist_last (GSList *list); |
| 941 | guint g_slist_length (GSList *list); |
| 942 | void g_slist_foreach (GSList *list, |
| 943 | GFunc func, |
| 944 | gpointer user_data); |
| 945 | GSList* g_slist_sort (GSList *list, |
| 946 | GCompareFunc compare_func); |
| 947 | gpointer g_slist_nth_data (GSList *list, |
| 948 | guint n); |
| 949 | #define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL) |
| 950 | |
| 951 | |
| 952 | /* Hash tables |
| 953 | */ |
| 954 | GHashTable* g_hash_table_new (GHashFunc hash_func, |
| 955 | GCompareFunc key_compare_func); |
| 956 | void g_hash_table_destroy (GHashTable *hash_table); |
| 957 | void g_hash_table_insert (GHashTable *hash_table, |
| 958 | gpointer key, |
| 959 | gpointer value); |
| 960 | void g_hash_table_remove (GHashTable *hash_table, |
| 961 | gconstpointer key); |
| 962 | gpointer g_hash_table_lookup (GHashTable *hash_table, |
| 963 | gconstpointer key); |
| 964 | gboolean g_hash_table_lookup_extended(GHashTable *hash_table, |
| 965 | gconstpointer lookup_key, |
| 966 | gpointer *orig_key, |
| 967 | gpointer *value); |
| 968 | void g_hash_table_freeze (GHashTable *hash_table); |
| 969 | void g_hash_table_thaw (GHashTable *hash_table); |
| 970 | void g_hash_table_foreach (GHashTable *hash_table, |
| 971 | GHFunc func, |
| 972 | gpointer user_data); |
| 973 | guint g_hash_table_foreach_remove (GHashTable *hash_table, |
| 974 | GHRFunc func, |
| 975 | gpointer user_data); |
| 976 | guint g_hash_table_size (GHashTable *hash_table); |
| 977 | |
| 978 | |
| 979 | /* Caches |
| 980 | */ |
| 981 | GCache* g_cache_new (GCacheNewFunc value_new_func, |
| 982 | GCacheDestroyFunc value_destroy_func, |
| 983 | GCacheDupFunc key_dup_func, |
| 984 | GCacheDestroyFunc key_destroy_func, |
| 985 | GHashFunc hash_key_func, |
| 986 | GHashFunc hash_value_func, |
| 987 | GCompareFunc key_compare_func); |
| 988 | void g_cache_destroy (GCache *cache); |
| 989 | gpointer g_cache_insert (GCache *cache, |
| 990 | gpointer key); |
| 991 | void g_cache_remove (GCache *cache, |
| 992 | gpointer value); |
| 993 | void g_cache_key_foreach (GCache *cache, |
| 994 | GHFunc func, |
| 995 | gpointer user_data); |
| 996 | void g_cache_value_foreach (GCache *cache, |
| 997 | GHFunc func, |
| 998 | gpointer user_data); |
| 999 | |
| 1000 | |
| 1001 | /* Balanced binary trees |
| 1002 | */ |
| 1003 | GTree* g_tree_new (GCompareFunc key_compare_func); |
| 1004 | void g_tree_destroy (GTree *tree); |
| 1005 | void g_tree_insert (GTree *tree, |
| 1006 | gpointer key, |
| 1007 | gpointer value); |
| 1008 | void g_tree_remove (GTree *tree, |
| 1009 | gpointer key); |
| 1010 | gpointer g_tree_lookup (GTree *tree, |
| 1011 | gpointer key); |
| 1012 | void g_tree_traverse (GTree *tree, |
| 1013 | GTraverseFunc traverse_func, |
| 1014 | GTraverseType traverse_type, |
| 1015 | gpointer data); |
| 1016 | gpointer g_tree_search (GTree *tree, |
| 1017 | GSearchFunc search_func, |
| 1018 | gpointer data); |
| 1019 | gint g_tree_height (GTree *tree); |
| 1020 | gint g_tree_nnodes (GTree *tree); |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | /* N-way tree implementation |
| 1025 | */ |
| 1026 | struct _GNode |
| 1027 | { |
| 1028 | gpointer data; |
| 1029 | GNode *next; |
| 1030 | GNode *prev; |
| 1031 | GNode *parent; |
| 1032 | GNode *children; |
| 1033 | }; |
| 1034 | |
| 1035 | #define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \ |
| 1036 | ((GNode*) (node))->prev == NULL && \ |
| 1037 | ((GNode*) (node))->next == NULL) |
| 1038 | #define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL) |
| 1039 | |
| 1040 | void g_node_push_allocator (GAllocator *allocator); |
| 1041 | void g_node_pop_allocator (void); |
| 1042 | GNode* g_node_new (gpointer data); |
| 1043 | void g_node_destroy (GNode *root); |
| 1044 | void g_node_unlink (GNode *node); |
| 1045 | GNode* g_node_insert (GNode *parent, |
| 1046 | gint position, |
| 1047 | GNode *node); |
| 1048 | GNode* g_node_insert_before (GNode *parent, |
| 1049 | GNode *sibling, |
| 1050 | GNode *node); |
| 1051 | GNode* g_node_prepend (GNode *parent, |
| 1052 | GNode *node); |
| 1053 | guint g_node_n_nodes (GNode *root, |
| 1054 | GTraverseFlags flags); |
| 1055 | GNode* g_node_get_root (GNode *node); |
| 1056 | gboolean g_node_is_ancestor (GNode *node, |
| 1057 | GNode *descendant); |
| 1058 | guint g_node_depth (GNode *node); |
| 1059 | GNode* g_node_find (GNode *root, |
| 1060 | GTraverseType order, |
| 1061 | GTraverseFlags flags, |
| 1062 | gpointer data); |
| 1063 | |
| 1064 | /* convenience macros */ |
| 1065 | #define g_node_append(parent, node) \ |
| 1066 | g_node_insert_before ((parent), NULL, (node)) |
| 1067 | #define g_node_insert_data(parent, position, data) \ |
| 1068 | g_node_insert ((parent), (position), g_node_new (data)) |
| 1069 | #define g_node_insert_data_before(parent, sibling, data) \ |
| 1070 | g_node_insert_before ((parent), (sibling), g_node_new (data)) |
| 1071 | #define g_node_prepend_data(parent, data) \ |
| 1072 | g_node_prepend ((parent), g_node_new (data)) |
| 1073 | #define g_node_append_data(parent, data) \ |
| 1074 | g_node_insert_before ((parent), NULL, g_node_new (data)) |
| 1075 | |
| 1076 | /* traversal function, assumes that `node' is root |
| 1077 | * (only traverses `node' and its subtree). |
| 1078 | * this function is just a high level interface to |
| 1079 | * low level traversal functions, optimized for speed. |
| 1080 | */ |
| 1081 | void g_node_traverse (GNode *root, |
| 1082 | GTraverseType order, |
| 1083 | GTraverseFlags flags, |
| 1084 | gint max_depth, |
| 1085 | GNodeTraverseFunc func, |
| 1086 | gpointer data); |
| 1087 | |
| 1088 | /* return the maximum tree height starting with `node', this is an expensive |
| 1089 | * operation, since we need to visit all nodes. this could be shortened by |
| 1090 | * adding `guint height' to struct _GNode, but then again, this is not very |
| 1091 | * often needed, and would make g_node_insert() more time consuming. |
| 1092 | */ |
| 1093 | guint g_node_max_height (GNode *root); |
| 1094 | |
| 1095 | void g_node_children_foreach (GNode *node, |
| 1096 | GTraverseFlags flags, |
| 1097 | GNodeForeachFunc func, |
| 1098 | gpointer data); |
| 1099 | void g_node_reverse_children (GNode *node); |
| 1100 | guint g_node_n_children (GNode *node); |
| 1101 | GNode* g_node_nth_child (GNode *node, |
| 1102 | guint n); |
| 1103 | GNode* g_node_last_child (GNode *node); |
| 1104 | GNode* g_node_find_child (GNode *node, |
| 1105 | GTraverseFlags flags, |
| 1106 | gpointer data); |
| 1107 | gint g_node_child_position (GNode *node, |
| 1108 | GNode *child); |
| 1109 | gint g_node_child_index (GNode *node, |
| 1110 | gpointer data); |
| 1111 | |
| 1112 | GNode* g_node_first_sibling (GNode *node); |
| 1113 | GNode* g_node_last_sibling (GNode *node); |
| 1114 | |
| 1115 | #define g_node_prev_sibling(node) ((node) ? \ |
| 1116 | ((GNode*) (node))->prev : NULL) |
| 1117 | #define g_node_next_sibling(node) ((node) ? \ |
| 1118 | ((GNode*) (node))->next : NULL) |
| 1119 | #define g_node_first_child(node) ((node) ? \ |
| 1120 | ((GNode*) (node))->children : NULL) |
| 1121 | |
| 1122 | |
| 1123 | /* Callback maintenance functions |
| 1124 | */ |
| 1125 | #define G_HOOK_FLAG_USER_SHIFT (4) |
| 1126 | typedef enum |
| 1127 | { |
| 1128 | G_HOOK_FLAG_ACTIVE = 1 << 0, |
| 1129 | G_HOOK_FLAG_IN_CALL = 1 << 1, |
| 1130 | G_HOOK_FLAG_MASK = 0x0f |
| 1131 | } GHookFlagMask; |
| 1132 | |
| 1133 | #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01) |
| 1134 | |
| 1135 | struct _GHookList |
| 1136 | { |
| 1137 | guint seq_id; |
| 1138 | guint hook_size; |
| 1139 | guint is_setup : 1; |
| 1140 | GHook *hooks; |
| 1141 | GMemChunk *hook_memchunk; |
| 1142 | GHookFreeFunc hook_free; /* virtual function */ |
| 1143 | GHookFreeFunc hook_destroy; /* virtual function */ |
| 1144 | }; |
| 1145 | |
| 1146 | struct _GHook |
| 1147 | { |
| 1148 | gpointer data; |
| 1149 | GHook *next; |
| 1150 | GHook *prev; |
| 1151 | guint ref_count; |
| 1152 | guint hook_id; |
| 1153 | guint flags; |
| 1154 | gpointer func; |
| 1155 | GDestroyNotify destroy; |
| 1156 | }; |
| 1157 | |
| 1158 | #define G_HOOK_ACTIVE(hook) ((((GHook*) hook)->flags & \ |
| 1159 | G_HOOK_FLAG_ACTIVE) != 0) |
| 1160 | #define G_HOOK_IN_CALL(hook) ((((GHook*) hook)->flags & \ |
| 1161 | G_HOOK_FLAG_IN_CALL) != 0) |
| 1162 | #define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \ |
| 1163 | G_HOOK_ACTIVE (hook)) |
| 1164 | #define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \ |
| 1165 | ((GHook*) hook)->prev == NULL && \ |
| 1166 | ((GHook*) hook)->hook_id == 0 && \ |
| 1167 | ((GHook*) hook)->ref_count == 0) |
| 1168 | |
| 1169 | void g_hook_list_init (GHookList *hook_list, |
| 1170 | guint hook_size); |
| 1171 | void g_hook_list_clear (GHookList *hook_list); |
| 1172 | GHook* g_hook_alloc (GHookList *hook_list); |
| 1173 | void g_hook_free (GHookList *hook_list, |
| 1174 | GHook *hook); |
| 1175 | void g_hook_ref (GHookList *hook_list, |
| 1176 | GHook *hook); |
| 1177 | void g_hook_unref (GHookList *hook_list, |
| 1178 | GHook *hook); |
| 1179 | gboolean g_hook_destroy (GHookList *hook_list, |
| 1180 | guint hook_id); |
| 1181 | void g_hook_destroy_link (GHookList *hook_list, |
| 1182 | GHook *hook); |
| 1183 | void g_hook_prepend (GHookList *hook_list, |
| 1184 | GHook *hook); |
| 1185 | void g_hook_insert_before (GHookList *hook_list, |
| 1186 | GHook *sibling, |
| 1187 | GHook *hook); |
| 1188 | void g_hook_insert_sorted (GHookList *hook_list, |
| 1189 | GHook *hook, |
| 1190 | GHookCompareFunc func); |
| 1191 | GHook* g_hook_get (GHookList *hook_list, |
| 1192 | guint hook_id); |
| 1193 | GHook* g_hook_find (GHookList *hook_list, |
| 1194 | gboolean need_valids, |
| 1195 | GHookFindFunc func, |
| 1196 | gpointer data); |
| 1197 | GHook* g_hook_find_data (GHookList *hook_list, |
| 1198 | gboolean need_valids, |
| 1199 | gpointer data); |
| 1200 | GHook* g_hook_find_func (GHookList *hook_list, |
| 1201 | gboolean need_valids, |
| 1202 | gpointer func); |
| 1203 | GHook* g_hook_find_func_data (GHookList *hook_list, |
| 1204 | gboolean need_valids, |
| 1205 | gpointer func, |
| 1206 | gpointer data); |
| 1207 | /* return the first valid hook, and increment its reference count */ |
| 1208 | GHook* g_hook_first_valid (GHookList *hook_list, |
| 1209 | gboolean may_be_in_call); |
| 1210 | /* return the next valid hook with incremented reference count, and |
| 1211 | * decrement the reference count of the original hook |
| 1212 | */ |
| 1213 | GHook* g_hook_next_valid (GHookList *hook_list, |
| 1214 | GHook *hook, |
| 1215 | gboolean may_be_in_call); |
| 1216 | |
| 1217 | /* GHookCompareFunc implementation to insert hooks sorted by their id */ |
| 1218 | gint g_hook_compare_ids (GHook *new_hook, |
| 1219 | GHook *sibling); |
| 1220 | |
| 1221 | /* convenience macros */ |
| 1222 | #define g_hook_append( hook_list, hook ) \ |
| 1223 | g_hook_insert_before ((hook_list), NULL, (hook)) |
| 1224 | |
| 1225 | /* invoke all valid hooks with the (*GHookFunc) signature. |
| 1226 | */ |
| 1227 | void g_hook_list_invoke (GHookList *hook_list, |
| 1228 | gboolean may_recurse); |
| 1229 | /* invoke all valid hooks with the (*GHookCheckFunc) signature, |
| 1230 | * and destroy the hook if FALSE is returned. |
| 1231 | */ |
| 1232 | void g_hook_list_invoke_check (GHookList *hook_list, |
| 1233 | gboolean may_recurse); |
| 1234 | /* invoke a marshaller on all valid hooks. |
| 1235 | */ |
| 1236 | void g_hook_list_marshal (GHookList *hook_list, |
| 1237 | gboolean may_recurse, |
| 1238 | GHookMarshaller marshaller, |
| 1239 | gpointer data); |
| 1240 | void g_hook_list_marshal_check (GHookList *hook_list, |
| 1241 | gboolean may_recurse, |
| 1242 | GHookCheckMarshaller marshaller, |
| 1243 | gpointer data); |
| 1244 | |
| 1245 | |
| 1246 | /* Fatal error handlers. |
| 1247 | * g_on_error_query() will prompt the user to either |
| 1248 | * [E]xit, [H]alt, [P]roceed or show [S]tack trace. |
| 1249 | * g_on_error_stack_trace() invokes gdb, which attaches to the current |
| 1250 | * process and shows a stack trace. |
| 1251 | * These function may cause different actions on non-unix platforms. |
| 1252 | * The prg_name arg is required by gdb to find the executable, if it is |
| 1253 | * passed as NULL, g_on_error_query() will try g_get_prgname(). |
| 1254 | */ |
| 1255 | void g_on_error_query (const gchar *prg_name); |
| 1256 | void g_on_error_stack_trace (const gchar *prg_name); |
| 1257 | |
| 1258 | |
| 1259 | /* Logging mechanism |
| 1260 | */ |
| 1261 | extern const gchar *g_log_domain_glib; |
| 1262 | guint g_log_set_handler (const gchar *log_domain, |
| 1263 | GLogLevelFlags log_levels, |
| 1264 | GLogFunc log_func, |
| 1265 | gpointer user_data); |
| 1266 | void g_log_remove_handler (const gchar *log_domain, |
| 1267 | guint handler_id); |
| 1268 | void g_log_default_handler (const gchar *log_domain, |
| 1269 | GLogLevelFlags log_level, |
| 1270 | const gchar *message, |
| 1271 | gpointer unused_data); |
| 1272 | void g_log (const gchar *log_domain, |
| 1273 | GLogLevelFlags log_level, |
| 1274 | const gchar *format, |
| 1275 | ...) G_GNUC_PRINTF (3, 4); |
| 1276 | void g_logv (const gchar *log_domain, |
| 1277 | GLogLevelFlags log_level, |
| 1278 | const gchar *format, |
| 1279 | va_list args); |
| 1280 | GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain, |
| 1281 | GLogLevelFlags fatal_mask); |
| 1282 | GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask); |
| 1283 | #ifndef G_LOG_DOMAIN |
| 1284 | #define G_LOG_DOMAIN ((gchar*) 0) |
| 1285 | #endif /* G_LOG_DOMAIN */ |
| 1286 | |
| 1287 | #define g_error(format, args...) g_log (G_LOG_DOMAIN, \ |
| 1288 | G_LOG_LEVEL_ERROR, \ |
| 1289 | format, ##args) |
| 1290 | #define g_message(format, args...) g_log (G_LOG_DOMAIN, \ |
| 1291 | G_LOG_LEVEL_MESSAGE, \ |
| 1292 | format, ##args) |
| 1293 | #define g_warning printf |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | /* Memory allocation and debugging |
| 1298 | */ |
| 1299 | #define g_malloc(size) ((gpointer)malloc(size)) |
| 1300 | #define g_malloc0(size) ((gpointer)calloc(size, 1)) |
| 1301 | #define g_realloc(mem,size) ((gpointer)realloc(mem, size)) |
| 1302 | #define g_free(mem) free(mem) |
| 1303 | |
| 1304 | |
| 1305 | void g_mem_profile (void); |
| 1306 | void g_mem_check (gpointer mem); |
| 1307 | |
| 1308 | |
| 1309 | /* String utility functions that modify a string argument or |
| 1310 | * return a constant string that must not be freed. |
| 1311 | */ |
| 1312 | #define G_STR_DELIMITERS "_-|> <." |
| 1313 | gchar* g_strdelimit (gchar *string, |
| 1314 | const gchar *delimiters, |
| 1315 | gchar new_delimiter); |
| 1316 | gdouble g_strtod (const gchar *nptr, |
| 1317 | gchar **endptr); |
| 1318 | gchar* g_strerror (gint errnum); |
| 1319 | gchar* g_strsignal (gint signum); |
| 1320 | gint g_strcasecmp (const gchar *s1, |
| 1321 | const gchar *s2); |
| 1322 | gint g_strncasecmp (const gchar *s1, |
| 1323 | const gchar *s2, |
| 1324 | guint n); |
| 1325 | void g_strdown (gchar *string); |
| 1326 | void g_strup (gchar *string); |
| 1327 | void g_strreverse (gchar *string); |
| 1328 | /* removes leading spaces */ |
| 1329 | gchar* g_strchug (gchar *string); |
| 1330 | /* removes trailing spaces */ |
| 1331 | gchar* g_strchomp (gchar *string); |
| 1332 | /* removes leading & trailing spaces */ |
| 1333 | #define g_strstrip( string ) g_strchomp (g_strchug (string)) |
| 1334 | |
| 1335 | /* String utility functions that return a newly allocated string which |
| 1336 | * ought to be freed from the caller at some point. |
| 1337 | */ |
| 1338 | gchar* g_strdup (const gchar *str); |
| 1339 | gchar* g_strdup_printf (const gchar *format, |
| 1340 | ...) G_GNUC_PRINTF (1, 2); |
| 1341 | gchar* g_strdup_vprintf (const gchar *format, |
| 1342 | va_list args); |
| 1343 | gchar* g_strndup (const gchar *str, |
| 1344 | guint n); |
| 1345 | gchar* g_strnfill (guint length, |
| 1346 | gchar fill_char); |
| 1347 | gchar* g_strconcat (const gchar *string1, |
| 1348 | ...); /* NULL terminated */ |
| 1349 | gchar* g_strjoin (const gchar *separator, |
| 1350 | ...); /* NULL terminated */ |
| 1351 | gchar* g_strescape (gchar *string); |
| 1352 | gpointer g_memdup (gconstpointer mem, |
| 1353 | guint byte_size); |
| 1354 | |
| 1355 | /* NULL terminated string arrays. |
| 1356 | * g_strsplit() splits up string into max_tokens tokens at delim and |
| 1357 | * returns a newly allocated string array. |
| 1358 | * g_strjoinv() concatenates all of str_array's strings, sliding in an |
| 1359 | * optional separator, the returned string is newly allocated. |
| 1360 | * g_strfreev() frees the array itself and all of its strings. |
| 1361 | */ |
| 1362 | gchar** g_strsplit (const gchar *string, |
| 1363 | const gchar *delimiter, |
| 1364 | gint max_tokens); |
| 1365 | gchar* g_strjoinv (const gchar *separator, |
| 1366 | gchar **str_array); |
| 1367 | void g_strfreev (gchar **str_array); |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | /* calculate a string size, guarranteed to fit format + args. |
| 1372 | */ |
| 1373 | guint g_printf_string_upper_bound (const gchar* format, |
| 1374 | va_list args); |
| 1375 | |
| 1376 | |
| 1377 | /* Retrive static string info |
| 1378 | */ |
| 1379 | gchar* g_get_user_name (void); |
| 1380 | gchar* g_get_real_name (void); |
| 1381 | gchar* g_get_home_dir (void); |
| 1382 | gchar* g_get_tmp_dir (void); |
| 1383 | gchar* g_get_prgname (void); |
| 1384 | void g_set_prgname (const gchar *prgname); |
| 1385 | |
| 1386 | |
| 1387 | /* Miscellaneous utility functions |
| 1388 | */ |
| 1389 | guint g_parse_debug_string (const gchar *string, |
| 1390 | GDebugKey *keys, |
| 1391 | guint nkeys); |
| 1392 | gint g_snprintf (gchar *string, |
| 1393 | gulong n, |
| 1394 | gchar const *format, |
| 1395 | ...) G_GNUC_PRINTF (3, 4); |
| 1396 | gint g_vsnprintf (gchar *string, |
| 1397 | gulong n, |
| 1398 | gchar const *format, |
| 1399 | va_list args); |
| 1400 | gchar* g_basename (const gchar *file_name); |
| 1401 | /* Check if a file name is an absolute path */ |
| 1402 | gboolean g_path_is_absolute (const gchar *file_name); |
| 1403 | /* In case of absolute paths, skip the root part */ |
| 1404 | gchar* g_path_skip_root (gchar *file_name); |
| 1405 | |
| 1406 | /* strings are newly allocated with g_malloc() */ |
| 1407 | gchar* g_dirname (const gchar *file_name); |
| 1408 | gchar* g_get_current_dir (void); |
| 1409 | gchar* g_getenv (const gchar *variable); |
| 1410 | |
| 1411 | |
| 1412 | /* we use a GLib function as a replacement for ATEXIT, so |
| 1413 | * the programmer is not required to check the return value |
| 1414 | * (if there is any in the implementation) and doesn't encounter |
| 1415 | * missing include files. |
| 1416 | */ |
| 1417 | void g_atexit (GVoidFunc func); |
| 1418 | |
| 1419 | |
| 1420 | /* Bit tests |
| 1421 | */ |
| 1422 | G_INLINE_FUNC gint g_bit_nth_lsf (guint32 mask, |
| 1423 | gint nth_bit); |
| 1424 | #ifdef G_CAN_INLINE |
| 1425 | G_INLINE_FUNC gint |
| 1426 | g_bit_nth_lsf (guint32 mask, |
| 1427 | gint nth_bit) |
| 1428 | { |
| 1429 | do |
| 1430 | { |
| 1431 | nth_bit++; |
| 1432 | if (mask & (1 << (guint) nth_bit)) |
| 1433 | return nth_bit; |
| 1434 | } |
| 1435 | while (nth_bit < 32); |
| 1436 | return -1; |
| 1437 | } |
| 1438 | #endif /* G_CAN_INLINE */ |
| 1439 | |
| 1440 | G_INLINE_FUNC gint g_bit_nth_msf (guint32 mask, |
| 1441 | gint nth_bit); |
| 1442 | #ifdef G_CAN_INLINE |
| 1443 | G_INLINE_FUNC gint |
| 1444 | g_bit_nth_msf (guint32 mask, |
| 1445 | gint nth_bit) |
| 1446 | { |
| 1447 | if (nth_bit < 0) |
| 1448 | nth_bit = 32; |
| 1449 | do |
| 1450 | { |
| 1451 | nth_bit--; |
| 1452 | if (mask & (1 << (guint) nth_bit)) |
| 1453 | return nth_bit; |
| 1454 | } |
| 1455 | while (nth_bit > 0); |
| 1456 | return -1; |
| 1457 | } |
| 1458 | #endif /* G_CAN_INLINE */ |
| 1459 | |
| 1460 | G_INLINE_FUNC guint g_bit_storage (guint number); |
| 1461 | #ifdef G_CAN_INLINE |
| 1462 | G_INLINE_FUNC guint |
| 1463 | g_bit_storage (guint number) |
| 1464 | { |
| 1465 | register guint n_bits = 0; |
| 1466 | |
| 1467 | do |
| 1468 | { |
| 1469 | n_bits++; |
| 1470 | number >>= 1; |
| 1471 | } |
| 1472 | while (number); |
| 1473 | return n_bits; |
| 1474 | } |
| 1475 | #endif /* G_CAN_INLINE */ |
| 1476 | |
| 1477 | /* String Chunks |
| 1478 | */ |
| 1479 | GStringChunk* g_string_chunk_new (gint size); |
| 1480 | void g_string_chunk_free (GStringChunk *chunk); |
| 1481 | gchar* g_string_chunk_insert (GStringChunk *chunk, |
| 1482 | const gchar *string); |
| 1483 | gchar* g_string_chunk_insert_const (GStringChunk *chunk, |
| 1484 | const gchar *string); |
| 1485 | |
| 1486 | |
| 1487 | /* Strings |
| 1488 | */ |
| 1489 | GString* g_string_new (const gchar *init); |
| 1490 | GString* g_string_sized_new (guint dfl_size); |
| 1491 | void g_string_free (GString *string, |
| 1492 | gint free_segment); |
| 1493 | GString* g_string_assign (GString *lval, |
| 1494 | const gchar *rval); |
| 1495 | GString* g_string_truncate (GString *string, |
| 1496 | gint len); |
| 1497 | GString* g_string_append (GString *string, |
| 1498 | const gchar *val); |
| 1499 | GString* g_string_append_c (GString *string, |
| 1500 | gchar c); |
| 1501 | GString* g_string_prepend (GString *string, |
| 1502 | const gchar *val); |
| 1503 | GString* g_string_prepend_c (GString *string, |
| 1504 | gchar c); |
| 1505 | GString* g_string_insert (GString *string, |
| 1506 | gint pos, |
| 1507 | const gchar *val); |
| 1508 | GString* g_string_insert_c (GString *string, |
| 1509 | gint pos, |
| 1510 | gchar c); |
| 1511 | GString* g_string_erase (GString *string, |
| 1512 | gint pos, |
| 1513 | gint len); |
| 1514 | GString* g_string_down (GString *string); |
| 1515 | GString* g_string_up (GString *string); |
| 1516 | void g_string_sprintf (GString *string, |
| 1517 | const gchar *format, |
| 1518 | ...) G_GNUC_PRINTF (2, 3); |
| 1519 | void g_string_sprintfa (GString *string, |
| 1520 | const gchar *format, |
| 1521 | ...) G_GNUC_PRINTF (2, 3); |
| 1522 | |
| 1523 | |
| 1524 | /* Resizable arrays, remove fills any cleared spot and shortens the |
| 1525 | * array, while preserving the order. remove_fast will distort the |
| 1526 | * order by moving the last element to the position of the removed |
| 1527 | */ |
| 1528 | |
| 1529 | #define g_array_append_val(a,v) g_array_append_vals (a, &v, 1) |
| 1530 | #define g_array_prepend_val(a,v) g_array_prepend_vals (a, &v, 1) |
| 1531 | #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &v, 1) |
| 1532 | #define g_array_index(a,t,i) (((t*) (a)->data) [(i)]) |
| 1533 | |
| 1534 | GArray* g_array_new (gboolean zero_terminated, |
| 1535 | gboolean clear, |
| 1536 | guint element_size); |
| 1537 | void g_array_free (GArray *array, |
| 1538 | gboolean free_segment); |
| 1539 | GArray* g_array_append_vals (GArray *array, |
| 1540 | gconstpointer data, |
| 1541 | guint len); |
| 1542 | GArray* g_array_prepend_vals (GArray *array, |
| 1543 | gconstpointer data, |
| 1544 | guint len); |
| 1545 | GArray* g_array_insert_vals (GArray *array, |
| 1546 | guint index, |
| 1547 | gconstpointer data, |
| 1548 | guint len); |
| 1549 | GArray* g_array_set_size (GArray *array, |
| 1550 | guint length); |
| 1551 | GArray* g_array_remove_index (GArray *array, |
| 1552 | guint index); |
| 1553 | GArray* g_array_remove_index_fast (GArray *array, |
| 1554 | guint index); |
| 1555 | |
| 1556 | /* Resizable pointer array. This interface is much less complicated |
| 1557 | * than the above. Add appends appends a pointer. Remove fills any |
| 1558 | * cleared spot and shortens the array. remove_fast will again distort |
| 1559 | * order. |
| 1560 | */ |
| 1561 | #define g_ptr_array_index(array,index) (array->pdata)[index] |
| 1562 | GPtrArray* g_ptr_array_new (void); |
| 1563 | void g_ptr_array_free (GPtrArray *array, |
| 1564 | gboolean free_seg); |
| 1565 | void g_ptr_array_set_size (GPtrArray *array, |
| 1566 | gint length); |
| 1567 | gpointer g_ptr_array_remove_index (GPtrArray *array, |
| 1568 | guint index); |
| 1569 | gpointer g_ptr_array_remove_index_fast (GPtrArray *array, |
| 1570 | guint index); |
| 1571 | gboolean g_ptr_array_remove (GPtrArray *array, |
| 1572 | gpointer data); |
| 1573 | gboolean g_ptr_array_remove_fast (GPtrArray *array, |
| 1574 | gpointer data); |
| 1575 | void g_ptr_array_add (GPtrArray *array, |
| 1576 | gpointer data); |
| 1577 | |
| 1578 | /* Byte arrays, an array of guint8. Implemented as a GArray, |
| 1579 | * but type-safe. |
| 1580 | */ |
| 1581 | |
| 1582 | GByteArray* g_byte_array_new (void); |
| 1583 | void g_byte_array_free (GByteArray *array, |
| 1584 | gboolean free_segment); |
| 1585 | GByteArray* g_byte_array_append (GByteArray *array, |
| 1586 | const guint8 *data, |
| 1587 | guint len); |
| 1588 | GByteArray* g_byte_array_prepend (GByteArray *array, |
| 1589 | const guint8 *data, |
| 1590 | guint len); |
| 1591 | GByteArray* g_byte_array_set_size (GByteArray *array, |
| 1592 | guint length); |
| 1593 | GByteArray* g_byte_array_remove_index (GByteArray *array, |
| 1594 | guint index); |
| 1595 | GByteArray* g_byte_array_remove_index_fast (GByteArray *array, |
| 1596 | guint index); |
| 1597 | |
| 1598 | #endif /* __G_LIB_H__ */ |