(root)/
fribidi-1.0.13/
lib/
common.h
       1  /* FriBidi
       2   * common.h - common include for library sources
       3   *
       4   * Author:
       5   *   Behdad Esfahbod, 2004
       6   *
       7   * Copyright (C) 2004 Sharif FarsiWeb, Inc.
       8   * 
       9   * This library is free software; you can redistribute it and/or
      10   * modify it under the terms of the GNU Lesser General Public
      11   * License as published by the Free Software Foundation; either
      12   * version 2.1 of the License, or (at your option) any later version.
      13   * 
      14   * This library is distributed in the hope that it will be useful,
      15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17   * Lesser General Public License for more details.
      18   * 
      19   * You should have received a copy of the GNU Lesser General Public License
      20   * along with this library, in a file named COPYING; if not, write to the
      21   * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      22   * Boston, MA 02110-1301, USA
      23   *
      24   * For licensing issues, contact <fribidi.license@gmail.com>.
      25   */
      26  #ifndef _COMMON_H
      27  #define _COMMON_H
      28  
      29  #ifdef HAVE_CONFIG_H
      30  # include <config.h>
      31  #endif
      32  
      33  #include <fribidi-common.h>
      34  
      35  #ifndef false
      36  # define false (0)
      37  # endif	/* !false */
      38  # ifndef true
      39  #  define true (!false)
      40  # endif	/* !true */
      41  
      42  #ifndef NULL
      43  #  ifdef __cplusplus
      44  #    define NULL        (0L)
      45  #  else	/* !__cplusplus */
      46  #    define NULL        ((void*) 0)
      47  #  endif /* !__cplusplus */
      48  #endif /* !NULL */
      49  
      50  /* fribidi_malloc and fribidi_free should be used instead of malloc and free. 
      51   * No need to include any headers. */
      52  #ifndef fribidi_malloc
      53  # if HAVE_STDLIB_H
      54  #  ifndef __FRIBIDI_DOC
      55  #   include <stdlib.h>
      56  #  endif /* __FRIBIDI_DOC */
      57  #  define fribidi_malloc malloc
      58  # else /* !HAVE_STDLIB_H */
      59  #  define fribidi_malloc (void *) malloc
      60  # endif	/* !HAVE_STDLIB_H */
      61  # define fribidi_free free
      62  #else /* fribidi_malloc */
      63  # ifndef fribidi_free
      64  #  error "You should define fribidi_free too when you define fribidi_malloc."
      65  # endif	/* !fribidi_free */
      66  #endif /* fribidi_malloc */
      67  
      68  #ifdef HAVE_STRING_H
      69  # if !STDC_HEADERS && HAVE_MEMORY_H
      70  #  include <memory.h>
      71  # endif
      72  # include <string.h>
      73  #endif
      74  #ifdef HAVE_STRINGS_H
      75  # include <strings.h>
      76  #endif
      77  
      78  /* FRIBIDI_BEGIN_STMT should be used at the beginning of your macro
      79   * definitions that are to behave like simple statements.  Use
      80   * FRIBIDI_END_STMT at the end of the macro after the semicolon or brace. */
      81  #ifndef FRIBIDI_BEGIN_STMT
      82  # define FRIBIDI_BEGIN_STMT do {
      83  # define FRIBIDI_END_STMT } while (0)
      84  #endif /* !FRIBIDI_BEGIN_STMT */
      85  
      86  /* LIKEYLY and UNLIKELY are used to give a hint on branch prediction to the
      87   * compiler. */
      88  #ifndef LIKELY
      89  # if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
      90  #  define FRIBIDI_BOOLEAN_EXPR(expr)              \
      91     __extension__ ({                               \
      92       int fribidi_bool_var;                        \
      93       if (expr)                                    \
      94          fribidi_bool_var = 1;                     \
      95       else                                         \
      96          fribidi_bool_var = 0;                     \
      97       fribidi_bool_var;                            \
      98     })
      99  #  define LIKELY(expr) (__builtin_expect (FRIBIDI_BOOLEAN_EXPR(expr), 1))
     100  #  define UNLIKELY(expr) (__builtin_expect (FRIBIDI_BOOLEAN_EXPR(expr), 0))
     101  # else
     102  #  define LIKELY
     103  #  define UNLIKELY
     104  # endif /* _GNUC_ */
     105  #endif /* !LIKELY */
     106  
     107  #ifndef FRIBIDI_EMPTY_STMT
     108  # define FRIBIDI_EMPTY_STMT FRIBIDI_BEGIN_STMT (void) 0; FRIBIDI_END_STMT
     109  #endif /* !FRIBIDI_EMPTY_STMT */
     110  
     111  #ifdef HAVE_STRINGIZE
     112  # define STRINGIZE(symbol) #symbol
     113  #else /* !HAVE_STRINGIZE */
     114  #  error "No stringize operator available?"
     115  #endif /* !HAVE_STRINGIZE */
     116  
     117  /* As per recommendation of GNU Coding Standards. */
     118  #ifndef _GNU_SOURCE
     119  # define _GNU_SOURCE
     120  #endif /* !_GNU_SOURCE */
     121  
     122  /* We respect our own rules. */
     123  #ifndef FRIBIDI_NO_DEPRECATED
     124  #  define FRIBIDI_NO_DEPRECATED
     125  #endif /* !FRIBIDI_NO_DEPRECATED */
     126  
     127  
     128  #include "debug.h"
     129  
     130  #endif /* !_COMMON_H */
     131  /* Editor directions:
     132   * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
     133   */