Top   Types   Functions   Classes   Options   Index   Sources 

erwin/base.h


  1  /* -*- Mode: C -*- */
  2  /* Author: Henrik Theiling
  3   * Description:
  4   *       The Erwin library for standard data structures and algorithms.
  5   *
  6   * @@Begin: Licencing and Copying@@
  7   *
  8   * Copyright (c) Henrik Theiling
  9   * Licence Version 2, Special Version for Erwin.
 10   *
 11   * The term 'this software' used in the following, additional to its
 12   * usual usage, also includes the instantiated source files generated by
 13   * tools of this package.
 14   *
 15   * This software is provided 'as-is', without warranty of any kind,
 16   * express or implied.  In no event will the authors or copyright holders
 17   * be held liable for any damages arising from the use of this software.
 18   *
 19   * Permission is granted to anyone to use this software for any purpose,
 20   * including commercial applications, and to alter it and redistribute it
 21   * freely, subject to the following restrictions:
 22   *
 23   * 1. The origin of this software must not be misrepresented; you must
 24   * not claim that you wrote the original software. If you use this
 25   * software in a product, an acknowledgment in the product documentation
 26   * would be appreciated.
 27   *
 28   * 2. Altered source versions must be plainly marked as such, and must
 29   * not be misrepresented as being the original software.
 30   *
 31   * 3. You must not use any of the names of the authors or copyright
 32   * holders of the original software for advertising or publicity
 33   * pertaining to distribution without specific, written prior permission.
 34   *
 35   * 4. If you change this software and redistribute parts or all of it in
 36   * any form, you must make the source code of the altered version of this
 37   * software available.  As an exception, files that were generated by
 38   * tools of this package may be used freely, including modification.
 39   *
 40   * 5. This notice must not be removed or altered from any source
 41   * distribution.
 42   *
 43   * This licence is governed by the Laws of Germany.  Disputes shall be
 44   * settled by Saarbruecken City Court.
 45   *
 46   * @@End: Licencing and Copying@@
 47   *
 48   */
 49  
 50  #ifdef ERWIN_DEBUG_INCLUDE
 51  #warning "Including base.h."
 52  #endif
 53  
 54  #ifndef Global_ERWIN_BASE_H
 55  #define Global_ERWIN_BASE_H
 56  
 57  #ifdef ERWIN_DEBUG_INCLUDE
 58  #warning "First inclusion of base.h."
 59  #endif
 60  
 61  #ifdef Global_ERWIN_COMPILING
 62  #  include "--INCPREF2B--erwin/defs.h"
 63  #  include "--INCPREF2B--erwin/map.h"
 64  #  include "--INCPREF2B--erwin/vector.h"
 65  #  include "--INCPREF2B--erwin/list.h"
 66  #  include "--INCPREF2B--erwin/typeinfo.h"
 67  #else
 68  #  include <--INCPREF2B--erwin/defs.h>
 69  #  include <--INCPREF2B--erwin/map.h>
 70  #  include <--INCPREF2B--erwin/vector.h>
 71  #  include <--INCPREF2B--erwin/list.h>
 72  #  include <--INCPREF2B--erwin/typeinfo.h>
 73  #endif
 74  
 75  #ifdef Global_ERWIN_ADAM_NAME
 76  
 77  #COPYDEF  ERWIN_MAJOR_VERSION
 78  #COPYDEF  ERWIN_MINOR_VERSION
 79  #COPYDEF  ERWIN_MICRO_VERSION
 80  #COPYDEF  ERWIN_VERSION_CODE
 81  
 82  #COPYNAME initializer_t
 83  #COPYNAME erwin_strtoul
 84  #COPYNAME erwin_strtol
 85  #COPYNAME erwin_strtoull
 86  #COPYNAME erwin_strtoll
 87  #COPYNAME erwin_strntoul
 88  #COPYNAME erwin_strntol
 89  #COPYNAME erwin_strntoull
 90  #COPYNAME erwin_strntoll
 91  #COPYNAME string_free
 92  #COPYNAME string_cmp
 93  #COPYNAME string_equ
 94  #COPYNAME string_case_cmp
 95  #COPYNAME string_case_equ
 96  #COPYNAME string_dup
 97  #COPYNAME string_length
 98  #COPYNAME char_is_alpha
 99  #COPYNAME char_is_lower
100  #COPYNAME char_is_upper
101  #COPYNAME char_is_digit
102  #COPYNAME char_is_xdigit
103  #COPYNAME char_is_space
104  #COPYNAME char_is_space0
105  #COPYNAME char_is_cr
106  #COPYNAME char_is_cr0
107  #COPYNAME erwin_merge_sort
108  #COPYNAME erwin_register_init
109  #COPYNAME erwin_version
110  #COPYNAME erwin_package_date
111  #COPYNAME erwin_assertion_is_fatal
112  #COPYNAME erwin_install_date
113  #COPYNAME erwin_init_date
114  #COPYNAME erwin_version_1
115  #COPYNAME erwin_version_2
116  #COPYNAME erwin_set_determinism
117  #COPYNAME erwin_require_determinism
118  #COPYNAME erwin_det_random
119  
120  #else /* !defined(Global_ERWIN_ADAM_NAME) */
121  
122  /* A family of overloaded functions to write assertions of the
123   * following type:
124   *
125   *    assert (x >= 0);
126   *
127   * The problem is that this often leads to a compiler warning while
128   * you still do not want to remove the assertion; you agree with
129   * the compiler that x >= 0, but you do want to make this assertion
130   * explicit.
131   *
132   * The following function family is overloaded for all numeric types
133   * (I think), so whether the x>=0-check is necessary or not is decided
134   * here once and forall.  You can simply write:
135   *
136   *    assert (erwin_nonnegative(x));
137   *
138   * The result of the function will be a constant true for unsigned
139   * types and a dynamically checked condition for signed types.
140   *
141   * For C, the problem is not fully solved:
142   *
143   *   Because in C, there is no overloading, the whole thing does not work,
144   *   and we're still looking for a solution.  The only thing I came up
145   *   with produces additional code and/or only works for ints but not for
146   *   floats.  I consider both minor flaws, especially the float thing.
147   *   But since you may currently use erwin_nonnegative() in any expression
148   *   instead of x >= 0, producing more code is suboptimal.  Depending on
149   *   ERWIN_OPTIMISE, we either use our special test (non-optimised code) or
150   *   we use x >= 0 (optimised code), which the compiler should eliminate.
151   *
152   *   Method 1 (works only for ints, but produces faster code):
153   *
154   *          (int)(x >> (sizeof(x)*8-1)) >= 0
155   *
156   *   Method 2 (works for floats and ints, but produces more code).
157   *
158   *          (double)(x / (2 << (sizeof(x)*8-1))) >= 0
159   *
160   *          This also has the problem that 2 << ... may overflow and
161   *          that using a cast might change the result.
162   *
163   *   So we use Method 1, making erwin_nonnegative() only for for integers
164   *   in C mode.  Note that no such restriction exists in C++.
165   *
166   * assert.pl also uses this function in out_of_bounds assertions.
167   */
168  
169  #ifndef erwin_nonnegative
170  
171  #ifdef __cplusplus
172  
173  #define erwin_nonnegative erwin_nonnegative
174  
175  ERWIN_WRAPPER bool erwin_nonnegative (char) ATTR_CONST;
176  ERWIN_WRAPPER bool erwin_nonnegative (char x)
177  {
178  #ifdef __CHAR_UNSIGNED__
179       return true;
180  #else
181       return x >= 0;
182  #endif
183  }
184  
185  ERWIN_WRAPPER bool erwin_nonnegative (signed char) ATTR_CONST;
186  ERWIN_WRAPPER bool erwin_nonnegative (signed char x)
187  {
188       return x >= 0;
189  }
190  
191  ERWIN_WRAPPER bool erwin_nonnegative (signed short) ATTR_CONST;
192  ERWIN_WRAPPER bool erwin_nonnegative (signed short x)
193  {
194       return x >= 0;
195  }
196  
197  ERWIN_WRAPPER bool erwin_nonnegative (signed int) ATTR_CONST;
198  ERWIN_WRAPPER bool erwin_nonnegative (signed int x)
199  {
200       return x >= 0;
201  }
202  
203  ERWIN_WRAPPER bool erwin_nonnegative (signed long) ATTR_CONST;
204  ERWIN_WRAPPER bool erwin_nonnegative (signed long x)
205  {
206       return x >= 0;
207  }
208  
209  #ifdef ERWIN_LONG_LONG
210  ERWIN_WRAPPER bool erwin_nonnegative (ERWIN_LONG_LONG) ATTR_CONST;
211  ERWIN_WRAPPER bool erwin_nonnegative (ERWIN_LONG_LONG x)
212  {
213       return x >= 0;
214  }
215  #endif
216  
217  ERWIN_WRAPPER bool erwin_nonnegative (float) ATTR_CONST;
218  ERWIN_WRAPPER bool erwin_nonnegative (float x)
219  {
220       return x >= 0;
221  }
222  
223  ERWIN_WRAPPER bool erwin_nonnegative (double) ATTR_CONST;
224  ERWIN_WRAPPER bool erwin_nonnegative (double x)
225  {
226       return x >= 0;
227  }
228  
229  #if SIZEOF_LONG_DOUBLE > 0
230  ERWIN_WRAPPER bool erwin_nonnegative (long double) ATTR_CONST;
231  ERWIN_WRAPPER bool erwin_nonnegative (long double x)
232  {
233       return x >= 0;
234  }
235  #endif
236  
237  ERWIN_WRAPPER bool erwin_nonnegative (bool) ATTR_CONST;
238  ERWIN_WRAPPER bool erwin_nonnegative (bool)
239  {
240       return true;
241  }
242  
243  ERWIN_WRAPPER bool erwin_nonnegative (unsigned char) ATTR_CONST;
244  ERWIN_WRAPPER bool erwin_nonnegative (unsigned char)
245  {
246       return true;
247  }
248  
249  ERWIN_WRAPPER bool erwin_nonnegative (unsigned short) ATTR_CONST;
250  ERWIN_WRAPPER bool erwin_nonnegative (unsigned short)
251  {
252       return true;
253  }
254  
255  ERWIN_WRAPPER bool erwin_nonnegative (unsigned int) ATTR_CONST;
256  ERWIN_WRAPPER bool erwin_nonnegative (unsigned int)
257  {
258       return true;
259  }
260  
261  ERWIN_WRAPPER bool erwin_nonnegative (unsigned long) ATTR_CONST;
262  ERWIN_WRAPPER bool erwin_nonnegative (unsigned long)
263  {
264       return true;
265  }
266  
267  #ifdef ERWIN_UNSIGNED_LONG_LONG
268  ERWIN_WRAPPER bool erwin_nonnegative (ERWIN_UNSIGNED_LONG_LONG) ATTR_CONST;
269  ERWIN_WRAPPER bool erwin_nonnegative (ERWIN_UNSIGNED_LONG_LONG)
270  {
271       return true;
272  }
273  #endif
274  
275  #else /* !defined __cplusplus */
276  
277  /* C mode: no overloading possible, so just do the check: */
278  #if Global_ERWIN_OPTIMISE
279  #  define erwin_nonnegative(x)  ((x) >= 0)
280  #else
281  #  define erwin_nonnegative(x)  (((int)((x) >> (sizeof(x)*8-1))) >= 0)
282  #endif
283  
284  #endif /* !defined __cplusplus */
285  
286  #endif /* defined erwin_nonnegative */
287  
288  
289  #ifdef __cplusplus
290  extern "C" {
291  #endif
292  
293  /*
294   * An initialisation function */
295  typedef void (*Global_initializer_t) (int *, char ***);
296  
297  /*! enum: Global_SO_* */
298  #define Global_SO_NO_UNDERBAR    0x80
299  #define Global_SO_NO_BINARY     0x100
300  #define Global_SO_BASE_MASK      0x7f
301  
302  /*! group: strtol-Functions
303   *
304   * Read numbers from string.  Use instead of system functions as the
305   * clib functions may be broken on some systems.  Note, however,
306   * that the functions have no overflow checking. (FIXME: implement that).
307   *
308   * These functions have the following extensions compared to the
309   * standard strto* family:
310   *     - they skip and ignore _ in numbers (like Perl)
311   *     - they understand 0b and 0B as binary prefix
312   * To disable these extensions, use the following constants in the
313   * radix parameter:
314   *     - Global_SO_NO_UNDERBAR
315   *     - Global_SO_NO_BINARY
316   * And or them with the base.  E.g.:
317   *    : Global_erwin_strtol (x, &r, 16 | Global_ERWIN_NO_UNDERBAR)
318   *
319   * SO is short for 'scan option'.
320   * (Vectors have a 'format option' and this is the reverse)
321   *
322   * NULL is allowed for all pointers.  If c == NULL, the result is 0.
323   */
324  
325  extern unsigned long Global_erwin_strtoul  (
326      char const * /*c*/,
327      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
328      int /*base*/ ERWIN_DEFAULT_ARG(0));
329  
330  extern long Global_erwin_strtol (
331      char const * /*c*/,
332      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
333      int /*base*/ ERWIN_DEFAULT_ARG(0));
334  
335  #ifdef ERWIN_LONG_LONG
336  
337  extern ERWIN_UNSIGNED_LONG_LONG Global_erwin_strtoull (
338      char const * /*c*/,
339      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
340      int /*base*/ ERWIN_DEFAULT_ARG(0));
341  
342  extern ERWIN_LONG_LONG  Global_erwin_strtoll  (
343      char const * /*c*/,
344      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
345      int /*base*/ ERWIN_DEFAULT_ARG(0));
346  
347  #endif
348  
349  extern unsigned long Global_erwin_strntoul  (
350      char const * /*c*/,
351      size_t /* strlen */,
352      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
353      int /*base*/ ERWIN_DEFAULT_ARG(0));
354  
355  extern long Global_erwin_strntol (
356      char const * /*c*/,
357      size_t /* strlen */,
358      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
359      int /*base*/ ERWIN_DEFAULT_ARG(0));
360  
361  #ifdef ERWIN_LONG_LONG
362  
363  extern ERWIN_UNSIGNED_LONG_LONG Global_erwin_strntoull (
364      char const * /*c*/,
365      size_t /* strlen */,
366      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
367      int /*base*/ ERWIN_DEFAULT_ARG(0));
368  
369  extern ERWIN_LONG_LONG  Global_erwin_strntoll  (
370      char const * /*c*/,
371      size_t /* strlen */,
372      char ** /*endptr*/ ERWIN_DEFAULT_ARG (NULL),
373      int /*base*/ ERWIN_DEFAULT_ARG(0));
374  
375  #endif
376  
377  /*! end-group */
378  
379  /*
380   * Overwrites the string before free() to make sure its contents
381   * will not be used.  Do not use this as a random number generator
382   * This is NULL safe.
383   */
384  extern void Global_string_free (char * /*c*/);
385  
386  /*! group: String Comparison
387   *
388   * NULL-safe string functions:
389   *
390   * These are all NULL safe (NULL < "") comparison functions:
391   * Note that the _case_ functions use 'tolower' (via char_to_lower),
392   * so that they pay attention to the locale if that function does.
393   *
394   */
395  
396  extern int Global_string_cmp (char const * /*a*/, char const * /*b*/) ATTR_PURE;
397    /*
398     * This compares two strings like the standard strcmp().
399     *
400     * This has macro aliases Global_erwin_strcmp().
401     *
402     * For Global_erwin_strcmp(a,b) == 0, there is an alias:
403     *    : Global_erwin_strequ(a,b)
404     */
405  
406  extern int Global_memory_cmp (void const * /*a*/, void const * /*b*/, size_t /*cnt*/) ATTR_PURE;
407    /*
408     * This compares two strings like the standard memcmp().
409     *
410     * This has macro aliases Global_erwin_memcmp().
411     *
412     * For Global_erwin_strcmp(a,b) == 0, there is an alias:
413     *    : Global_erwin_strequ(a,b)
414     */
415  
416  extern int Global_string_n_cmp (char const * /*a*/, char const * /*b*/, size_t /*n*/) ATTR_PURE;
417    /* Replacement for strncmp()
418     *
419     * This has macro aliases Global_erwin_strncmp().
420     *
421     * For Global_erwin_strncmp(a,b,n) == 0, there is an alias:
422     *    : Global_erwin_strnequ(a,b,n)
423     */
424  
425  extern char *Global_string_string (char const * /*haystack*/, char const * /*needle*/) ATTR_PURE;
426    /* Like strstr: finds a substring.
427     *
428     * Has a macro alias Global_erwin_strstr.
429     */
430  
431  extern char *Global_string_n_string      (
432      char const * /*haystack*/, char const * /*needle*/, size_t) ATTR_PURE;
433    /* Like a potential strnstr: finds a substring for a needle with a limited length.
434     *
435     * Has a macro alias Global_erwin_strnstr.
436     */
437  
438  extern void *Global_memory_memory (
439      void const * /*haystack*/, size_t /*haycnt*/,
440      void const * /*needle*/,   size_t /*needlecnt*/) ATTR_PURE;
441    /* Like memmem: finds a substring.
442     *
443     * Has a macro alias Global_erwin_memmem.
444     */
445  
446  /*! group: Case Insensitive Variants
447   * Note that the _case_ functions use 'tolower' (via char_to_lower),
448   * so that they pay attention to the locale if that function does.
449   */
450  
451  extern int Global_string_case_cmp (char const * /*a*/, char const * /*b*/) ATTR_PURE;
452    /* Like strcasecmp() / stricmp().
453     *
454     * This has macro aliases Global_erwin_strcasecmp() and Global_erwin_stricmp
455     */
456  
457  extern int Global_string_n_case_cmp (char const * /*a*/, char const * /*b*/, size_t /*n*/)
458       ATTR_PURE;
459    /* Like strncasecmp() / strnicmp()
460     *
461     * This has macro aliases Global_erwin_strncasecmp() and Global_erwin_strnicmp
462     */
463  
464  extern char *Global_string_case_string   (char const * /*haystack*/, char const * /*needle*/)
465       ATTR_PURE;
466    /* Like a potential strcasestr: finds a substring case-insensitively.
467     *
468     * Has a macro alias Global_erwin_strcasestr.
469     */
470  
471  extern char *Global_string_n_case_string (
472      char const * /*haystack*/, char const * /*needle*/, size_t) ATTR_PURE;
473    /* Like a potential strcasestr: finds a substring for a needle with a limited length.
474     *
475     * Has a macro alias Global_erwin_strncasestr.
476     */
477  
478  /*! end-group */
479  /*! end-group */
480  
481  extern char *Global_string_dup   (
482      char const * /*c*/, int * /*err*/ ERWIN_DEFAULT_ARG((int*)NULL))
483      ATTR_MALLOC;
484      /*
485       * This DOES NOT change NULL to "(null)" or anything like that. NULL
486       * on input returns NULL. Otherwise, the index NULL could not be
487       * found after insertion in an array.  If there is not enough memory,
488       * *err is set to 1.  Otherwise, *err is not touched.
489       * err may be NULL. In that case, NULL is returned of the system
490       * is out of memory.
491       *
492       * This has an alias Global_erwin_strdup.
493       */
494  
495  extern char *Global_string_n_dup (
496      char const * /*c*/, size_t /*n*/, int * /*err*/ ERWIN_DEFAULT_ARG((int*)NULL))
497      ATTR_MALLOC;
498      /* Also see Global_string_dup.
499       *
500       * This has an alias Global_erwin_strdup.
501       */
502  
503  extern void *Global_erwin_memset0 (
504      void * /*p*/, size_t /*start*/, size_t /*end_plus_1*/);
505      /* Like memset or bzero, but by using start, you can clear a suffix only.
506       * This is internally used to emulate clearing after malloc and realloc.
507       * Depending on what is available, the internal implementation uses
508       * memset, bzero, or clears with a for loop manually.
509       *
510       * The returned pointer is just the one passed to the function.  If it is
511       * NULL or start >= end_plus_1, no clearing is attempted.
512       */
513  
514  extern size_t Global_string_length (char const *) ATTR_PURE;
515     /* A NULL-safe replacement for strlen(): NULL has length 0.
516      *
517      * This has an alias Global_erwin_strlen.
518      */
519  
520  extern size_t Global_string_n_length (char const *, size_t) ATTR_PURE;
521     /* A NULL-safe replacement for strnlen(): NULL has length 0.
522      *
523      * This has an alias Global_erwin_strnlen.
524      */
525  
526  extern int Global_erwin_digit_value (char) ATTR_CONST;
527     /* Returns the digit value of a given character.  Can be used up to
528      * a radix of 36.  (Probably usually used for hexadecimal digits.)
529      *
530      * If the character is invalid, returns 100, which is larger a value
531      * than that of any representable digit.
532      */
533  
534  extern char Global_erwin_get_digit (int /*digit*/) ATTR_CONST;
535     /* The reverse of the Global_erwin_digit_value.
536      * Returns '\0' if digit is not between 0 and 35.
537      */
538  
539  extern char Global_erwin_get_digit_upper (int /*digit*/) ATTR_CONST;
540     /* This variant of Global_erwin_get_digit returns upper case
541      * letters first. */
542  
543  /* The names string_... are nice to show that they all belong to the
544   * data type string, but they are not nice for remembring when you
545   * know the libc function names.  So we introduce aliases here. */
546  
547  #define Global_erwin_strcmp      Global_string_cmp
548  #define Global_erwin_memcmp      Global_memory_cmp
549  #define Global_erwin_strncmp     Global_string_n_cmp
550  #define Global_erwin_strlen      Global_string_length
551  #define Global_erwin_strnlen     Global_string_n_length
552  
553  /* non-ANSI, but BSD */
554  #define Global_erwin_strdup(A)   Global_string_dup((A), NULL)
555  
556  /* BSD, Linux: */
557  #define Global_erwin_strcasecmp  Global_string_case_cmp
558  #define Global_erwin_strncasecmp Global_string_n_case_cmp
559  #define Global_erwin_strstr      Global_string_string
560  #define Global_erwin_memmem      Global_memory_memory
561  #define Global_erwin_strcasestr  Global_string_case_string
562  #define Global_erwin_strnstr     Global_string_n_string
563  #define Global_erwin_strncasestr Global_string_n_case_string
564  
565  /* Windows: */
566  #define Global_erwin_stricmp     Global_string_case_cmp
567  #define Global_erwin_strnicmp    Global_string_n_case_cmp
568  #define Global_erwin_stristr     Global_string_case_string
569  #define Global_erwin_strnistr    Global_string_n_case_string
570  
571  /* Some invented names: */
572  #define Global_erwin_strfree             Global_string_free
573  #define Global_erwin_strndup             Global_string_n_dup
574  
575  #define Global_erwin_memequ(A,B,C)       (Global_memory_cmp(A,B,C) == 0)
576  #define Global_erwin_strequ(A,B)         (Global_string_cmp(A,B) == 0)
577  #define Global_erwin_strcaseequ(A,B)     (Global_string_case_cmp(A,B) == 0)
578  #define Global_erwin_strnequ(A,B,N)      (Global_string_n_cmp(A,B,N) == 0)
579  #define Global_erwin_strncaseequ(A,B,N)  (Global_string_n_case_cmp(A,B,N) == 0)
580  
581  #define Global_string_equ(A,B)           (Global_string_cmp(A,B) == 0)
582  #define Global_string_case_equ(A,B)      (Global_string_case_cmp(A,B) == 0)
583  #define Global_string_n_equ(A,B,N)       (Global_string_n_cmp(A,B,N) == 0)
584  #define Global_string_n_case_equ(A,B,N)  (Global_string_n_case_cmp(A,B,N) == 0)
585  
586  extern Global_ERWIN_BOOL Global_string_is_prefix (
587      int * /*needle_length*/, char const * /*haystack*/, char const * /*needle*/);
588  
589  extern Global_ERWIN_BOOL Global_string_is_suffix (
590      int * /*needle_length*/, char const * /*haystack*/, char const * /*needle*/);
591  
592  extern char const *Global_erwin_strsignal (int);
593     /* This returns NULL if the signal is not known or no name is known. */
594  
595  /*
596   * Some character functions.   These are wrappers around ctype functions. */
597  /* extern char Global_char_to_upper (char);    declared in map.h */
598  /* extern char Global_char_to_lower (char);    declared in map.h */
599  extern Global_ERWIN_BOOL Global_char_is_alpha  (char) ATTR_CONST;
600  extern Global_ERWIN_BOOL Global_char_is_lower  (char) ATTR_CONST;
601  extern Global_ERWIN_BOOL Global_char_is_upper  (char) ATTR_CONST;
602  extern Global_ERWIN_BOOL Global_char_is_digit  (char) ATTR_CONST;
603  extern Global_ERWIN_BOOL Global_char_is_xdigit (char) ATTR_CONST;
604  extern Global_ERWIN_BOOL Global_char_is_space  (char) ATTR_CONST;  /* '\0' is not space. */
605  extern Global_ERWIN_BOOL Global_char_is_space0 (char) ATTR_CONST;  /* '\0' is space. */
606  extern Global_ERWIN_BOOL Global_char_is_cr     (char) ATTR_CONST;  /* '\0' is not cr. */
607  extern Global_ERWIN_BOOL Global_char_is_cr0    (char) ATTR_CONST;  /* '\0' is cr. */
608    /* The *0 versions return Global_ERWIN_TRUE for \0. */
609  
610  #define Global_erwin_isalpha  Global_char_is_alpha
611  #define Global_erwin_islower  Global_char_is_lower
612  #define Global_erwin_isupper  Global_char_is_upper
613  #define Global_erwin_isdigit  Global_char_is_digit
614  #define Global_erwin_isxdigit Global_char_is_xdigit
615  #define Global_erwin_isspace  Global_char_is_space
616  /* invented ones: */
617  #define Global_erwin_isspace0  Global_char_is_space0
618  #define Global_erwin_iscr      Global_char_is_cr
619  #define Global_erwin_iscr0     Global_char_is_cr0
620  
621  /* The following functions hash the contents of the strings: */
622  ERWIN_WRAPPER Global_hashval_t Global_string_hash (char const *) ATTR_PURE;
623  ERWIN_WRAPPER Global_hashval_t Global_string_hash (char const *c)
624  {
625      return Global_erwin_u8_array_hash ((ERWIN_U8*)c, Global_string_length(c));
626  }
627  
628  ERWIN_WRAPPER Global_hashval_t Global_string_case_hash (char const *) ATTR_PURE;
629  ERWIN_WRAPPER Global_hashval_t Global_string_case_hash (char const *c)
630  {
631      return Global_erwin_u8_array_case_hash ((ERWIN_U8*)c, Global_string_length(c));
632  }
633  
634  typedef int (* Global_erwin_comparison_t) (void const *, void const *);
635  
636  void Global_erwin_merge_sort (
637      void *abase,
638      size_t anmemb,
639      size_t asize,
640      Global_erwin_comparison_t /*acompar*/);
641     /* The stable sort algorithm Mergesort.
642      *
643      * Warning: This needs as much additional memory as you have stored in the
644      *          array being sorted!
645      */
646  
647  /*
648   * Initialise erwin and all its modules.  This might read
649   * eventually parse options some time.
650   */
651  extern void Global_erwin_init (int * /*argc*/, char *** /*argv*/);
652  
653  extern int Global_erwin_register_init (Global_initializer_t);
654  /* The suggested usage is this:
655  
656       static void module_init (int *argc, char ***argv)
657       {
658         ....
659       }
660  
661       static int init_dummy = erwin_register_initialiser (module_init);
662  
663     module_init will then automatically be called by erwin_init
664   */
665  
666  #define Global_ERWIN_MAJOR_VERSION  --MAJOR-VERSION--
667  #define Global_ERWIN_MINOR_VERSION  --MINOR-VERSION--
668  #define Global_ERWIN_MICRO_VERSION  --MICRO-VERSION--
669  #define Global_ERWIN_VERSION_CODE   Global_ERWIN_VERSION(Global_ERWIN_MAJOR_VERSION,Global_ERWIN_MINOR_VERSION,Global_ERWIN_MICRO_VERSION)
670  /*
671   * Like in the Linux kernel, you can write something like:
672   *
673   * #if Global_ERWIN_VERSION_CODE >= Global_ERWIN_VERSION(2,0,178)
674   *
675   */
676  
677  extern char const *const Global_erwin_version;
678  extern char const *const Global_erwin_package_date;
679     /* version and release date of this Erwin package */
680  
681  extern Global_ERWIN_BOOL Global_erwin_assertion_is_fatal;
682     /* whether assertions are fatal */
683  
684  extern char const *const Global_erwin_install_date;
685     /* site install date */
686  
687  extern char const *const Global_erwin_init_date;
688     /* date of untemplatize -init */
689  
690  extern int const Global_erwin_version_1;
691  extern int const Global_erwin_version_2;
692     /* These are for link-checking Erwin in a configure script. */
693  
694  #ifdef Global_ERWIN_REQUIRE_DETERMINISM
695  
696  extern void Global_erwin_set_determinism (Global_ERWIN_BOOL);
697      /* Default: Global_ERWIN_TRUE
698       * This means: if you define Global_ERWIN_REQUIRE_DETERMINISM, you get Global_ERWIN_TRUE as a
699       *             default.  If you don't, you get Global_ERWIN_FALSE as a default because the
700       *             whole machinery needed for enforcing determinism is not compiled in.
701       */
702  
703  extern Global_ERWIN_BOOL Global_erwin_require_determinism (void);
704      /* returns the current status of the determinism state. */
705  
706  #endif
707     /* If you compile the library with ERWIN_REQUIRE_DETERMINISM, all the data
708      * structures will be able to be switched into determinism mode.  Note that
709      * you have to call this function *before* Global_erwin_init()!
710      *
711      * The influence on data structures is that, e.g for maps, functions
712      * returning a list of the entries (either key, values or pairs) will
713      * for sorted.  The same holds for iterators.  Note that when comparing
714      * pointers by their address, the sort order is still machine and
715      * machine configuration (->shared libraries, etc) dependent.  However,
716      * directly subsequent calls to your problems will probably result in
717      * the same order.
718      *
719      * NOTE: When you define Global_ERWIN_REQUIRE_DETERMINISM, maps *must* be
720      *       supplied with a compare function for the keys.  There can be
721      *       a special compare function if you do not want to influence
722      *       the rest of the data structure.
723      *
724      * FURTHER NOTE: When you define this, the library is a bit slower, because
725      *       it has to check the determinism flag.
726      *
727      * FURTHER NOTE: This feature is currently only implemented correctly
728      *       for C++ since the map iterators for C cannot be correctly
729      *       de-allocated automatically.
730      *       E.g. when an application programmer uses `break' to exit a
731      *       map_xyz_forall loop, a possibly allocated sorted array cannot
732      *       be deallocated in C.  This would require something like
733      *       MAP_XYZ_FORALL_BREAK(iter) or (which I do not like because
734      *       it breaks nestability) an additional entry in the map_xyz_t struct.
735      */
736  #ifdef Global_ERWIN_NEED_DET_RANDOM
737  extern unsigned long Global_erwin_det_random (void);
738      /* deterministic random. (haha!)
739       * No srand() necessary...
740       * Usually, use the frontend Global_ERWIN_RANDOM(N) (defs.h)
741       */
742  #endif
743  
744  #ifdef __cplusplus
745  }
746  #endif
747  
748  #endif /* !defined(Global_ERWIN_ADAM_NAME) */
749  
750  --INCLUDE-FORWARDS-LATE--
751  
752  #endif /* Global_ERWIN_BASE_H */

Index

Stoppt die Vorratsdatenspeicherung
November 26th, 2007
Comments? Suggestions? Corrections? You can drop me a line.
zpentrabvagiktu@theiling.de
Schwerpunktpraxis