add packaging
[platform/upstream/fribidi.git] / lib / fribidi-bidi-types.c
1 /* FriBidi
2  * fribidi-bidi-types.c - character bidi types
3  *
4  * $Id: fribidi-bidi-types.c,v 1.9 2006-01-31 03:23:13 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2006-01-31 03:23:13 $
7  * $Revision: 1.9 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types.c,v $
9  *
10  * Authors:
11  *   Behdad Esfahbod, 2001, 2002, 2004
12  *
13  * Copyright (C) 2004 Sharif FarsiWeb, Inc.
14  * Copyright (C) 2001,2002 Behdad Esfahbod
15  * 
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  * 
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Lesser General Public License for more details.
25  * 
26  * You should have received a copy of the GNU Lesser General Public License
27  * along with this library, in a file named COPYING; if not, write to the
28  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29  * Boston, MA 02110-1301, USA
30  *
31  * For licensing issues, contact <license@farsiweb.info>.
32  */
33
34 #include "common.h"
35
36 #include <fribidi-bidi-types.h>
37
38 #include "bidi-types.h"
39
40 enum FriBidiCharTypeLinearEnum
41 {
42 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
43 # include "fribidi-bidi-types-list.h"
44 # undef _FRIBIDI_ADD_TYPE
45   _FRIBIDI_NUM_TYPES
46 };
47
48 #include "bidi-type.tab.i"
49
50 /* Map FriBidiCharTypeLinearEnum to FriBidiCharType. */
51 static const FriBidiCharType linear_enum_to_char_type[] = {
52 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) FRIBIDI_TYPE_##TYPE,
53 # include "fribidi-bidi-types-list.h"
54 # undef _FRIBIDI_ADD_TYPE
55 };
56
57 FRIBIDI_ENTRY FriBidiCharType
58 fribidi_get_bidi_type (
59   /* input */
60   FriBidiChar ch
61 )
62 {
63   return linear_enum_to_char_type[FRIBIDI_GET_BIDI_TYPE (ch)];
64 }
65
66 FRIBIDI_ENTRY void
67 fribidi_get_bidi_types (
68   /* input */
69   const FriBidiChar *str,
70   const FriBidiStrIndex len,
71   /* output */
72   FriBidiCharType *btypes
73 )
74 {
75   register FriBidiStrIndex i = len;
76   for (; i; i--)
77     {
78       *btypes++ = linear_enum_to_char_type[FRIBIDI_GET_BIDI_TYPE (*str)];
79       str++;
80     }
81 }
82
83 FRIBIDI_ENTRY const char *
84 fribidi_get_bidi_type_name (
85   /* input */
86   FriBidiCharType t
87 )
88 {
89   switch (t)
90     {
91 #   define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) case FRIBIDI_TYPE_##TYPE: return STRINGIZE(TYPE);
92 #   define _FRIBIDI_ALL_TYPES
93 #   include "fribidi-bidi-types-list.h"
94 #   undef _FRIBIDI_ALL_TYPES
95 #   undef _FRIBIDI_ADD_TYPE
96     default:
97       return "?";
98     }
99 }
100
101 #if DEBUG+0
102
103 char
104 fribidi_char_from_bidi_type (
105   /* input */
106   FriBidiCharType t
107 )
108 {
109   switch (t)
110     {
111 #   define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) case FRIBIDI_TYPE_##TYPE: return SYMBOL;
112 #   define _FRIBIDI_ALL_TYPES
113 #   include "fribidi-bidi-types-list.h"
114 #   undef _FRIBIDI_ALL_TYPES
115 #   undef _FRIBIDI_ADD_TYPE
116     default:
117       return '?';
118     }
119 }
120
121 #endif /* DEBUG */
122
123 /* Editor directions:
124  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
125  */