aRts audio server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /* GSL - Generic Sound Layer
  2. * Copyright (C) 2001 Stefan Westerfeld and Tim Janik
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library 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 GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General
  15. * Public License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __GSL_GLIB_H__
  20. #define __GSL_GLIB_H__
  21. #ifndef G_LOG_DOMAIN
  22. #define G_LOG_DOMAIN "GSL"
  23. #endif
  24. #include <limits.h>
  25. #include <float.h>
  26. #include <stddef.h>
  27. #include <stdarg.h>
  28. #ifdef HAVE_CONFIG_H
  29. #include <config.h>
  30. #endif
  31. /* for -ansi -pedantic */
  32. #ifdef __GNUC__
  33. #define asm __asm__
  34. #endif
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif /* __cplusplus */
  38. #define GSL_ASSERT(foo) do { if (!(foo)) g_error ("assertion failed `%s'", #foo); } while (0)
  39. /* --- GLib typedefs --- */
  40. typedef void* gpointer;
  41. typedef const void* gconstpointer;
  42. typedef char gchar;
  43. typedef unsigned char guchar;
  44. typedef signed short gshort;
  45. typedef unsigned short gushort;
  46. typedef signed int gint;
  47. typedef unsigned int guint;
  48. typedef signed long glong;
  49. typedef unsigned long gulong;
  50. typedef float gfloat;
  51. typedef double gdouble;
  52. typedef size_t gsize;
  53. typedef gchar gint8;
  54. typedef guchar guint8;
  55. typedef gshort gint16;
  56. typedef gushort guint16;
  57. typedef gint gint32;
  58. typedef guint guint32;
  59. typedef gint gboolean;
  60. typedef gint32 GTime;
  61. #ifdef __alpha
  62. typedef long int gint64;
  63. typedef unsigned long int guint64;
  64. #else
  65. typedef long long int gint64;
  66. typedef unsigned long long int guint64;
  67. #endif
  68. typedef struct _GString GString;
  69. typedef struct _GDebugKey GDebugKey;
  70. struct _GDebugKey
  71. {
  72. const gchar *key;
  73. guint value;
  74. };
  75. typedef struct _GTimeVal GTimeVal;
  76. struct _GTimeVal
  77. {
  78. glong tv_sec;
  79. glong tv_usec;
  80. };
  81. typedef gint (*GCompareFunc) (gconstpointer a,
  82. gconstpointer b);
  83. /* --- standard macros --- */
  84. #ifndef ABS
  85. #define ABS(a) ((a) > 0 ? (a) : -(a))
  86. #endif
  87. #ifndef MAX
  88. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  89. #endif
  90. #ifndef MIN
  91. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  92. #endif
  93. #ifndef CLAMP
  94. #define CLAMP(v,l,h) ((v) < (l) ? (l) : (v) > (h) ? (h) : (v))
  95. #endif
  96. #ifndef FALSE
  97. #define FALSE 0
  98. #endif
  99. #ifndef TRUE
  100. #define TRUE (!FALSE)
  101. #endif
  102. #ifndef NULL
  103. #define NULL ((void*) 0)
  104. #endif
  105. /* --- glib macros --- */
  106. #define G_MINFLOAT FLT_MIN
  107. #define G_MAXFLOAT FLT_MAX
  108. #define G_MINDOUBLE DBL_MIN
  109. #define G_MAXDOUBLE DBL_MAX
  110. #define G_MINSHORT SHRT_MIN
  111. #define G_MAXSHORT SHRT_MAX
  112. #define G_MAXUSHORT USHRT_MAX
  113. #define G_MININT INT_MIN
  114. #define G_MININT64 ((gint64) 0x8000000000000000)
  115. #define G_MAXINT INT_MAX
  116. #define G_MAXINT64 ((gint64) 0x7fffffffffffffff)
  117. #define G_MAXUINT UINT_MAX
  118. #define G_MAXUINT64 ((guint64) 0xffffffffffffffff)
  119. #define G_MINLONG LONG_MIN
  120. #define G_MAXLONG LONG_MAX
  121. #define G_MAXULONG ULONG_MAX
  122. #define G_USEC_PER_SEC 1000000
  123. #define G_LITTLE_ENDIAN 1234
  124. #define G_BIG_ENDIAN 4321
  125. #define G_DIR_SEPARATOR '/'
  126. #ifdef MAXPATHLEN
  127. #define G_PATH_LENGTH MAXPATHLEN
  128. #elif defined (PATH_MAX)
  129. #define G_PATH_LENGTH PATH_MAX
  130. #elif defined (_PC_PATH_MAX)
  131. #define G_PATH_LENGTH sysconf(_PC_PATH_MAX)
  132. #else
  133. #define G_PATH_LENGTH 2048
  134. #endif
  135. #define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
  136. #define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
  137. #define G_STRINGIFY_ARG(contents) #contents
  138. #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
  139. #if !(defined (G_STMT_START) && defined (G_STMT_END))
  140. # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
  141. # define G_STMT_START (void)(
  142. # define G_STMT_END )
  143. # else
  144. # if (defined (sun) || defined (__sun__))
  145. # define G_STMT_START if (1)
  146. # define G_STMT_END else (void)0
  147. # else
  148. # define G_STMT_START do
  149. # define G_STMT_END while (0)
  150. # endif
  151. # endif
  152. #endif
  153. #define G_STRUCT_OFFSET(struct_type, member) \
  154. ((glong) ((guint8*) &((struct_type*) 0)->member))
  155. #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
  156. ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
  157. #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
  158. (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
  159. #define GINT_TO_POINTER(i) ((gpointer) (int) (i))
  160. #define GUINT_TO_POINTER(i) ((gpointer) (guint) (i))
  161. #define GPOINTER_TO_INT(p) ((int) (p))
  162. #define GPOINTER_TO_UINT(p) ((guint) (p))
  163. #define GUINT16_SWAP_LE_BE(val) ((guint16) ( \
  164. (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
  165. (((guint16) (val) & (guint16) 0xff00U) >> 8)))
  166. #define GUINT32_SWAP_LE_BE(val) ((guint32) ( \
  167. (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
  168. (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \
  169. (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \
  170. (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
  171. #ifdef WORDS_BIGENDIAN
  172. #define GUINT16_TO_LE(val) GUINT16_SWAP_LE_BE(val)
  173. #define GUINT32_TO_LE(val) GUINT32_SWAP_LE_BE(val)
  174. #define GUINT16_TO_BE(val) ((guint16) (val))
  175. #define GUINT32_TO_BE(val) ((guint32) (val))
  176. #else /* LITTLEENDIAN */
  177. #define GUINT16_TO_LE(val) ((guint16) (val))
  178. #define GUINT32_TO_LE(val) ((guint32) (val))
  179. #define GUINT16_TO_BE(val) GUINT16_SWAP_LE_BE(val)
  180. #define GUINT32_TO_BE(val) GUINT32_SWAP_LE_BE(val)
  181. #endif
  182. #define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val))
  183. #define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val))
  184. #define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val))
  185. #define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val))
  186. #define g_memmove memmove
  187. #define g_assert GSL_ASSERT
  188. #define g_assert_not_reached() g_assert(!G_STRLOC": should not be reached")
  189. #define g_return_if_fail(foo) do { if (!(foo)) g_message (G_STRLOC ": assertion failed `%s'", #foo); } while (0)
  190. #define g_return_val_if_fail(foo,v) do { if (!(foo)) { g_message (G_STRLOC ": assertion failed `%s'", #foo); return(v);}} while (0)
  191. /* from galloca.h */
  192. #ifdef __GNUC__
  193. /* GCC does the right thing */
  194. # undef alloca
  195. # define alloca(size) __builtin_alloca (size)
  196. #elif defined (GLIB_HAVE_ALLOCA_H)
  197. /* a native and working alloca.h is there */
  198. # include <alloca.h>
  199. #else /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
  200. # ifdef _MSC_VER
  201. # include <malloc.h>
  202. # define alloca _alloca
  203. # else /* !_MSC_VER */
  204. # ifdef _AIX
  205. #pragma alloca
  206. # else /* !_AIX */
  207. # ifndef alloca /* predefined by HP cc +Olibcalls */
  208. char *alloca ();
  209. # endif /* !alloca */
  210. # endif /* !_AIX */
  211. # endif /* !_MSC_VER */
  212. #endif /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
  213. #define g_alloca(size) alloca (size)
  214. #define g_newa(struct_type, n_structs) ((struct_type*) g_alloca (sizeof (struct_type) * (gsize) (n_structs)))
  215. /* needs inline configure check */
  216. #if defined (__xlc__)
  217. # if !defined (inline)
  218. # define inline _Inline
  219. # endif
  220. #elif defined (__GNUC__)
  221. #define inline __inline__
  222. #else
  223. #define inline /* no inline */
  224. #endif
  225. /* --- inline functions --- */
  226. void
  227. gsl_g_log (const gchar*msg,const char *format, va_list ap);
  228. void
  229. gsl_g_print_fd (int fd,const char *format, va_list ap);
  230. static inline void
  231. g_error (const gchar *format,
  232. ...)
  233. {
  234. va_list args;
  235. va_start (args, format);
  236. gsl_g_log ("**ERROR**", format, args);
  237. va_end (args);
  238. }
  239. static inline void
  240. g_message (const gchar *format,
  241. ...)
  242. {
  243. va_list args;
  244. va_start (args, format);
  245. gsl_g_log ("**MESSAGE**", format, args);
  246. va_end (args);
  247. }
  248. static inline void
  249. g_critical (const gchar *format,
  250. ...)
  251. {
  252. va_list args;
  253. va_start (args, format);
  254. gsl_g_log ("**CRITICAL**", format, args);
  255. va_end (args);
  256. }
  257. static inline void
  258. g_warning (const gchar *format,
  259. ...)
  260. {
  261. va_list args;
  262. va_start (args, format);
  263. gsl_g_log ("**WARNING**", format, args);
  264. va_end (args);
  265. }
  266. static inline void
  267. g_print (const gchar *format,
  268. ...)
  269. {
  270. va_list args;
  271. va_start (args, format);
  272. gsl_g_print_fd (1, format, args);
  273. va_end (args);
  274. }
  275. static inline void
  276. g_printerr (const gchar *format,
  277. ...)
  278. {
  279. va_list args;
  280. va_start (args, format);
  281. gsl_g_print_fd (2, format, args);
  282. va_end (args);
  283. }
  284. typedef struct _GTrashStack GTrashStack;
  285. struct _GTrashStack
  286. {
  287. GTrashStack *next;
  288. };
  289. static inline guint
  290. g_bit_storage (gulong number)
  291. {
  292. register guint n_bits = 0;
  293. do
  294. {
  295. n_bits++;
  296. number >>= 1;
  297. }
  298. while (number);
  299. return n_bits;
  300. }
  301. static inline void
  302. g_trash_stack_push (GTrashStack **stack_p,
  303. gpointer data_p)
  304. {
  305. GTrashStack *data = (GTrashStack *) data_p;
  306. data->next = *stack_p;
  307. *stack_p = data;
  308. }
  309. static inline gpointer
  310. g_trash_stack_pop (GTrashStack **stack_p)
  311. {
  312. GTrashStack *data;
  313. data = *stack_p;
  314. if (data)
  315. {
  316. *stack_p = data->next;
  317. /* NULLify private pointer here, most platforms store NULL as
  318. * subsequent 0 bytes
  319. */
  320. data->next = NULL;
  321. }
  322. return data;
  323. }
  324. static inline gpointer
  325. g_trash_stack_peek (GTrashStack **stack_p)
  326. {
  327. GTrashStack *data;
  328. data = *stack_p;
  329. return data;
  330. }
  331. static inline guint
  332. g_trash_stack_height (GTrashStack **stack_p)
  333. {
  334. GTrashStack *data;
  335. guint i = 0;
  336. for (data = *stack_p; data; data = data->next)
  337. i++;
  338. return i;
  339. }
  340. /* --- GCC features --- */
  341. #if __GNUC__ >= 2 && __GNUC_MINOR__ > 95
  342. #define G_GNUC_PRINTF( format_idx, arg_idx ) \
  343. __attribute__((format (printf, format_idx, arg_idx)))
  344. #define G_GNUC_SCANF( format_idx, arg_idx ) \
  345. __attribute__((format (scanf, format_idx, arg_idx)))
  346. #define G_GNUC_FORMAT( arg_idx ) \
  347. __attribute__((format_arg (arg_idx)))
  348. #define G_GNUC_NORETURN \
  349. __attribute__((noreturn))
  350. #define G_GNUC_CONST \
  351. __attribute__((const))
  352. #define G_GNUC_UNUSED \
  353. __attribute__((unused))
  354. #define G_GNUC_NO_INSTRUMENT \
  355. __attribute__((no_instrument_function))
  356. #else /* !__GNUC__ */
  357. #define G_GNUC_PRINTF( format_idx, arg_idx )
  358. #define G_GNUC_SCANF( format_idx, arg_idx )
  359. #define G_GNUC_FORMAT( arg_idx )
  360. #define G_GNUC_NORETURN
  361. #define G_GNUC_CONST
  362. #define G_GNUC_UNUSED
  363. #define G_GNUC_NO_INSTRUMENT
  364. #endif /* !__GNUC__ */
  365. /* --- GPollFD (for poll(2)) --- */
  366. #define G_IO_IN (0x0001 /* There is data to read */)
  367. #define G_IO_PRI (0x0002 /* There is urgent data to read */)
  368. #define G_IO_OUT (0x0004 /* Writing now will not block */)
  369. #define G_IO_ERR (0x0008 /* Error condition */)
  370. #define G_IO_HUP (0x0010 /* Hung up */)
  371. #define G_IO_NVAL (0x0020 /* Invalid request: fd not open */)
  372. typedef struct
  373. {
  374. gint fd;
  375. gushort events;
  376. gushort revents;
  377. } GPollFD;
  378. /* --- functions --- */
  379. #define g_malloc gsl_g_malloc
  380. #define g_malloc0 gsl_g_malloc0
  381. #define g_realloc gsl_g_realloc
  382. #define g_free gsl_g_free
  383. #define g_strdup gsl_g_strdup
  384. #define g_strndup gsl_g_strndup
  385. #define g_memdup gsl_g_memdup
  386. #define g_strdup_printf gsl_g_strdup_printf
  387. #define g_strdup_vprintf gsl_g_strdup_vprintf
  388. #define g_strndup gsl_g_strndup
  389. #define g_strconcat gsl_g_strconcat
  390. #define g_usleep gsl_g_usleep
  391. #define g_strerror gsl_g_strerror
  392. #define g_convert gsl_g_convert
  393. #define g_direct_hash gsl_g_direct_hash
  394. #define g_direct_equal gsl_g_direct_equal
  395. #define g_str_equal gsl_g_str_equal
  396. #define g_str_hash gsl_g_str_hash
  397. #define g_strtod gsl_g_strtod
  398. #define g_stpcpy gsl_g_stpcpy
  399. #define g_strescape gsl_g_strescape
  400. #define g_get_current_dir gsl_g_get_current_dir
  401. #define g_path_is_absolute gsl_g_path_is_absolute
  402. #define g_printf_string_upper_bound gsl_g_printf_string_upper_bound
  403. gpointer g_malloc (gulong n_bytes);
  404. gpointer g_malloc0 (gulong n_bytes);
  405. gpointer g_realloc (gpointer mem,
  406. gulong n_bytes);
  407. void g_free (gpointer mem);
  408. gpointer g_memdup (gconstpointer mem,
  409. guint byte_size);
  410. gchar* g_strdup (const gchar *str);
  411. gchar* g_strndup (const gchar *str,
  412. gsize n);
  413. gchar* g_strdup_printf (const gchar *format,
  414. ...) G_GNUC_PRINTF (1, 2);
  415. gchar* g_strdup_vprintf (const gchar *format,
  416. va_list args);
  417. gchar* g_strndup (const gchar *str,
  418. gsize n);
  419. gchar* g_strconcat (const gchar *string1,
  420. ...); /* NULL terminated */
  421. gchar* g_convert (const gchar *str,
  422. gsize len, /* gssize */
  423. const gchar *to_codeset,
  424. const gchar *from_codeset,
  425. gsize *bytes_read,
  426. gsize *bytes_written,
  427. void **error); /* GError */
  428. void g_usleep(unsigned long usec);
  429. char* g_strerror(int e);
  430. guint g_direct_hash (gconstpointer v);
  431. gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
  432. gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
  433. guint g_str_hash (gconstpointer key);
  434. gdouble g_strtod (const gchar *nptr, gchar **endptr);
  435. gsize g_printf_string_upper_bound (const gchar *format, va_list args);
  436. gchar * g_stpcpy (gchar *dest, const gchar *src);
  437. gchar * g_strescape (const gchar *source, const gchar *exceptions);
  438. gchar * g_get_current_dir (void);
  439. gboolean g_path_is_absolute (const gchar *file_name);
  440. /* --- function defines --- */
  441. #define g_new(struct_type, n_structs) \
  442. ((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
  443. #define g_new0(struct_type, n_structs) \
  444. ((struct_type *) g_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
  445. #define g_renew(struct_type, mem, n_structs) \
  446. ((struct_type *) g_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
  447. #define g_try_malloc malloc
  448. #define g_try_realloc realloc
  449. /* --- configure stuff!!! --- */
  450. #ifdef WORDS_BIGENDIAN
  451. #define G_BYTE_ORDER G_BIG_ENDIAN
  452. #else
  453. #define G_BYTE_ORDER G_LITTLE_ENDIAN
  454. #endif
  455. /* #define GLIB_HAVE_STPCPY 1 */
  456. /* Define G_VA_COPY() to do the right thing for copying va_list variables.
  457. * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
  458. */
  459. #if !defined (G_VA_COPY)
  460. # if defined (__GNUC__) && ( defined (__PPC__) || defined (__s390__) ) && (defined (_CALL_SYSV) || defined (_WIN32) || defined (__s390__) )
  461. # define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
  462. # elif defined (G_VA_COPY_AS_ARRAY)
  463. # define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
  464. # else /* va_list is a pointer */
  465. # define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
  466. # endif /* va_list is a pointer */
  467. #endif /* !G_VA_COPY */
  468. /* subtract from biased_exponent to form base2 exponent (normal numbers) */
  469. typedef union _GDoubleIEEE754 GDoubleIEEE754;
  470. typedef union _GFloatIEEE754 GFloatIEEE754;
  471. #define G_IEEE754_FLOAT_BIAS (127)
  472. #define G_IEEE754_DOUBLE_BIAS (1023)
  473. /* multiply with base2 exponent to get base10 exponent (nomal numbers) */
  474. #define G_LOG_2_BASE_10 (0.30102999566398119521)
  475. #if G_BYTE_ORDER == G_LITTLE_ENDIAN
  476. union _GFloatIEEE754
  477. {
  478. gfloat v_float;
  479. struct {
  480. guint mantissa : 23;
  481. guint biased_exponent : 8;
  482. guint sign : 1;
  483. } mpn;
  484. };
  485. union _GDoubleIEEE754
  486. {
  487. gdouble v_double;
  488. struct {
  489. guint mantissa_low : 32;
  490. guint mantissa_high : 20;
  491. guint biased_exponent : 11;
  492. guint sign : 1;
  493. } mpn;
  494. };
  495. #elif G_BYTE_ORDER == G_BIG_ENDIAN
  496. union _GFloatIEEE754
  497. {
  498. gfloat v_float;
  499. struct {
  500. guint sign : 1;
  501. guint biased_exponent : 8;
  502. guint mantissa : 23;
  503. } mpn;
  504. };
  505. union _GDoubleIEEE754
  506. {
  507. gdouble v_double;
  508. struct {
  509. guint sign : 1;
  510. guint biased_exponent : 11;
  511. guint mantissa_high : 20;
  512. guint mantissa_low : 32;
  513. } mpn;
  514. };
  515. #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
  516. #error unknown ENDIAN type
  517. #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
  518. /* --- GHashTable --- */
  519. typedef struct _GHashTable GHashTable;
  520. typedef gboolean (*GHRFunc) (gpointer key,
  521. gpointer value,
  522. gpointer user_data);
  523. typedef void (*GHFunc) (gpointer key,
  524. gpointer value,
  525. gpointer user_data);
  526. typedef guint (*GHashFunc) (gconstpointer key);
  527. typedef gboolean (*GEqualFunc) (gconstpointer a,
  528. gconstpointer b);
  529. typedef void (*GDestroyNotify) (gpointer data);
  530. #define g_hash_table_new gsl_g_hash_table_new
  531. #define g_hash_table_new_full gsl_g_hash_table_new_full
  532. #define g_hash_table_destroy gsl_g_hash_table_destroy
  533. #define g_hash_table_insert gsl_g_hash_table_insert
  534. #define g_hash_table_replace gsl_g_hash_table_replace
  535. #define g_hash_table_remove gsl_g_hash_table_remove
  536. #define g_hash_table_steal gsl_g_hash_table_steal
  537. #define g_hash_table_lookup gsl_g_hash_table_lookup
  538. #define g_hash_table_lookup_extended gsl_g_hash_table_lookup_extended
  539. #define g_hash_table_foreach gsl_g_hash_table_foreach
  540. #define g_hash_table_foreach_remove gsl_g_hash_table_foreach_remove
  541. #define g_hash_table_foreach_steal gsl_g_hash_table_foreach_steal
  542. #define g_hash_table_size gsl_g_hash_table_size
  543. GHashTable* g_hash_table_new (GHashFunc hash_func,
  544. GEqualFunc key_equal_func);
  545. GHashTable* g_hash_table_new_full (GHashFunc hash_func,
  546. GEqualFunc key_equal_func,
  547. GDestroyNotify key_destroy_func,
  548. GDestroyNotify value_destroy_func);
  549. void g_hash_table_destroy (GHashTable *hash_table);
  550. void g_hash_table_insert (GHashTable *hash_table,
  551. gpointer key,
  552. gpointer value);
  553. void g_hash_table_replace (GHashTable *hash_table,
  554. gpointer key,
  555. gpointer value);
  556. gboolean g_hash_table_remove (GHashTable *hash_table,
  557. gconstpointer key);
  558. gboolean g_hash_table_steal (GHashTable *hash_table,
  559. gconstpointer key);
  560. gpointer g_hash_table_lookup (GHashTable *hash_table,
  561. gconstpointer key);
  562. gboolean g_hash_table_lookup_extended (GHashTable *hash_table,
  563. gconstpointer lookup_key,
  564. gpointer *orig_key,
  565. gpointer *value);
  566. void g_hash_table_foreach (GHashTable *hash_table,
  567. GHFunc func,
  568. gpointer user_data);
  569. guint g_hash_table_foreach_remove (GHashTable *hash_table,
  570. GHRFunc func,
  571. gpointer user_data);
  572. guint g_hash_table_foreach_steal (GHashTable *hash_table,
  573. GHRFunc func,
  574. gpointer user_data);
  575. guint g_hash_table_size (GHashTable *hash_table);
  576. /* --- GScanner --- */
  577. typedef struct _GScanner GScanner;
  578. typedef struct _GScannerConfig GScannerConfig;
  579. typedef union _GTokenValue GTokenValue;
  580. typedef void (*GScannerMsgFunc) (GScanner *scanner,
  581. gchar *message,
  582. gint error);
  583. #define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  584. #define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"
  585. #define G_CSET_DIGITS "0123456789"
  586. #define G_CSET_LATINC "\300\301\302\303\304\305\306"\
  587. "\307\310\311\312\313\314\315\316\317\320"\
  588. "\321\322\323\324\325\326"\
  589. "\330\331\332\333\334\335\336"
  590. #define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\
  591. "\347\350\351\352\353\354\355\356\357\360"\
  592. "\361\362\363\364\365\366"\
  593. "\370\371\372\373\374\375\376\377"
  594. typedef enum
  595. {
  596. G_ERR_UNKNOWN,
  597. G_ERR_UNEXP_EOF,
  598. G_ERR_UNEXP_EOF_IN_STRING,
  599. G_ERR_UNEXP_EOF_IN_COMMENT,
  600. G_ERR_NON_DIGIT_IN_CONST,
  601. G_ERR_DIGIT_RADIX,
  602. G_ERR_FLOAT_RADIX,
  603. G_ERR_FLOAT_MALFORMED
  604. } GErrorType;
  605. typedef enum
  606. {
  607. G_TOKEN_EOF = 0,
  608. G_TOKEN_LEFT_PAREN = '(',
  609. G_TOKEN_RIGHT_PAREN = ')',
  610. G_TOKEN_LEFT_CURLY = '{',
  611. G_TOKEN_RIGHT_CURLY = '}',
  612. G_TOKEN_LEFT_BRACE = '[',
  613. G_TOKEN_RIGHT_BRACE = ']',
  614. G_TOKEN_EQUAL_SIGN = '=',
  615. G_TOKEN_COMMA = ',',
  616. G_TOKEN_NONE = 256,
  617. G_TOKEN_ERROR,
  618. G_TOKEN_CHAR,
  619. G_TOKEN_BINARY,
  620. G_TOKEN_OCTAL,
  621. G_TOKEN_INT,
  622. G_TOKEN_HEX,
  623. G_TOKEN_FLOAT,
  624. G_TOKEN_STRING,
  625. G_TOKEN_SYMBOL,
  626. G_TOKEN_IDENTIFIER,
  627. G_TOKEN_IDENTIFIER_NULL,
  628. G_TOKEN_COMMENT_SINGLE,
  629. G_TOKEN_COMMENT_MULTI,
  630. G_TOKEN_LAST
  631. } GTokenType;
  632. union _GTokenValue
  633. {
  634. gpointer v_symbol;
  635. gchar *v_identifier;
  636. gulong v_binary;
  637. gulong v_octal;
  638. gulong v_int;
  639. gdouble v_float;
  640. gulong v_hex;
  641. gchar *v_string;
  642. gchar *v_comment;
  643. guchar v_char;
  644. guint v_error;
  645. };
  646. struct _GScannerConfig
  647. {
  648. const gchar *cset_skip_characters; /* default: " \t\n" */
  649. const gchar *cset_identifier_first;
  650. const gchar *cset_identifier_nth;
  651. const gchar *cpair_comment_single; /* default: "#\n" */
  652. guint case_sensitive : 1;
  653. guint skip_comment_multi : 1; /* C like comment */
  654. guint skip_comment_single : 1; /* single line comment */
  655. guint scan_comment_multi : 1; /* scan multi line comments? */
  656. guint scan_identifier : 1;
  657. guint scan_identifier_1char : 1;
  658. guint scan_identifier_NULL : 1;
  659. guint scan_symbols : 1;
  660. guint scan_binary : 1;
  661. guint scan_octal : 1;
  662. guint scan_float : 1;
  663. guint scan_hex : 1; /* `0x0ff0' */
  664. guint scan_hex_dollar : 1; /* `$0ff0' */
  665. guint scan_string_sq : 1; /* string: 'anything' */
  666. guint scan_string_dq : 1; /* string: "\\-escapes!\n" */
  667. guint numbers_2_int : 1; /* bin, octal, hex => int */
  668. guint int_2_float : 1; /* int => G_TOKEN_FLOAT? */
  669. guint identifier_2_string : 1;
  670. guint char_2_token : 1; /* return G_TOKEN_CHAR? */
  671. guint symbol_2_token : 1;
  672. guint scope_0_fallback : 1; /* try scope 0 on lookups? */
  673. };
  674. struct _GScanner
  675. {
  676. gpointer user_data;
  677. guint max_parse_errors;
  678. guint parse_errors;
  679. const gchar *input_name;
  680. /* GData *qdata; */
  681. GScannerConfig *config;
  682. GTokenType token;
  683. GTokenValue value;
  684. guint line;
  685. guint position;
  686. GTokenType next_token;
  687. GTokenValue next_value;
  688. guint next_line;
  689. guint next_position;
  690. GHashTable *symbol_table;
  691. gint input_fd;
  692. const gchar *text;
  693. const gchar *text_end;
  694. gchar *buffer;
  695. guint scope_id;
  696. GScannerMsgFunc msg_handler;
  697. };
  698. #define g_scanner_new gsl_g_scanner_new
  699. #define g_scanner_destroy gsl_g_scanner_destroy
  700. #define g_scanner_input_file gsl_g_scanner_input_file
  701. #define g_scanner_sync_file_offset gsl_g_scanner_sync_file_offset
  702. #define g_scanner_input_text gsl_g_scanner_input_text
  703. #define g_scanner_get_next_token gsl_g_scanner_get_next_token
  704. #define g_scanner_peek_next_token gsl_g_scanner_peek_next_token
  705. #define g_scanner_cur_token gsl_g_scanner_cur_token
  706. #define g_scanner_cur_value gsl_g_scanner_cur_value
  707. #define g_scanner_cur_line gsl_g_scanner_cur_line
  708. #define g_scanner_cur_position gsl_g_scanner_cur_position
  709. #define g_scanner_eof gsl_g_scanner_eof
  710. #define g_scanner_set_scope gsl_g_scanner_set_scope
  711. #define g_scanner_scope_add_symbol gsl_g_scanner_scope_add_symbol
  712. #define g_scanner_scope_remove_symbol gsl_g_scanner_scope_remove_symbol
  713. #define g_scanner_scope_lookup_symbol gsl_g_scanner_scope_lookup_symbol
  714. #define g_scanner_scope_foreach_symbol gsl_g_scanner_scope_foreach_symbol
  715. #define g_scanner_lookup_symbol gsl_g_scanner_lookup_symbol
  716. #define g_scanner_unexp_token gsl_g_scanner_unexp_token
  717. #define g_scanner_error gsl_g_scanner_error
  718. #define g_scanner_warn gsl_g_scanner_warn
  719. GScanner* g_scanner_new (const GScannerConfig *config_templ);
  720. void g_scanner_destroy (GScanner *scanner);
  721. void g_scanner_input_file (GScanner *scanner,
  722. gint input_fd);
  723. void g_scanner_sync_file_offset (GScanner *scanner);
  724. void g_scanner_input_text (GScanner *scanner,
  725. const gchar *text,
  726. guint text_len);
  727. GTokenType g_scanner_get_next_token (GScanner *scanner);
  728. GTokenType g_scanner_peek_next_token (GScanner *scanner);
  729. GTokenType g_scanner_cur_token (GScanner *scanner);
  730. GTokenValue g_scanner_cur_value (GScanner *scanner);
  731. guint g_scanner_cur_line (GScanner *scanner);
  732. guint g_scanner_cur_position (GScanner *scanner);
  733. gboolean g_scanner_eof (GScanner *scanner);
  734. guint g_scanner_set_scope (GScanner *scanner,
  735. guint scope_id);
  736. void g_scanner_scope_add_symbol (GScanner *scanner,
  737. guint scope_id,
  738. const gchar *symbol,
  739. gpointer value);
  740. void g_scanner_scope_remove_symbol (GScanner *scanner,
  741. guint scope_id,
  742. const gchar *symbol);
  743. gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,
  744. guint scope_id,
  745. const gchar *symbol);
  746. void g_scanner_scope_foreach_symbol (GScanner *scanner,
  747. guint scope_id,
  748. GHFunc func,
  749. gpointer user_data);
  750. gpointer g_scanner_lookup_symbol (GScanner *scanner,
  751. const gchar *symbol);
  752. void g_scanner_unexp_token (GScanner *scanner,
  753. GTokenType expected_token,
  754. const gchar *identifier_spec,
  755. const gchar *symbol_spec,
  756. const gchar *symbol_name,
  757. const gchar *message,
  758. gint is_error);
  759. void g_scanner_error (GScanner *scanner,
  760. const gchar *format,
  761. ...) G_GNUC_PRINTF (2,3);
  762. void g_scanner_warn (GScanner *scanner,
  763. const gchar *format,
  764. ...) G_GNUC_PRINTF (2,3);
  765. #define g_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \
  766. g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
  767. } G_STMT_END
  768. #define g_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \
  769. g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
  770. } G_STMT_END
  771. #define g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
  772. g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
  773. } G_STMT_END
  774. #ifdef __cplusplus
  775. }
  776. #endif /* __cplusplus */
  777. #include <gsl/gslconfig.h>
  778. #if GSL_USE_ARTS_THREADS
  779. #include <gsl/gslartsthreads.h>
  780. #endif
  781. /* if inline is defined in C++ mode, it can cause a lot of grief with C++ */
  782. /* header files so we need to undefine it here again */
  783. #if defined(__cplusplus) && defined(inline)
  784. #undef inline
  785. #endif
  786. #endif /* __GSL_GLIB_H__ */ /* vim: set ts=8 sw=2 sts=2: */