summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbehdad <behdad>2002-03-16 15:46:50 +0000
committerbehdad <behdad>2002-03-16 15:46:50 +0000
commit2e23e0ea1ec7edf087297753d9622e3ba6eae023 (patch)
treea3b7d0add1d35ee34ac98163f3f075a626af4c7f
parentc58e65a38b2b6c540ece5adc0acec710373e17d1 (diff)
FriBidiEnv patch of Omer Zak applied.
-rw-r--r--ChangeLog11
-rw-r--r--Makefile.am8
-rw-r--r--NEWS6
-rw-r--r--fribidi.c201
-rw-r--r--fribidi.h100
-rw-r--r--fribidi_benchmark.c2
-rw-r--r--fribidi_char_sets_cap_rtl.c12
-rw-r--r--fribidi_char_type.c9
-rw-r--r--fribidi_create_char_types.c2
-rw-r--r--fribidi_create_mirroring.c2
-rw-r--r--fribidi_env.c268
-rw-r--r--fribidi_env.h270
-rw-r--r--fribidi_main.c30
-rw-r--r--fribidi_mem.c26
-rw-r--r--fribidi_mem.h32
-rw-r--r--fribidi_mirroring.c3
-rw-r--r--fribidi_tab_char_type_2.i4
-rw-r--r--fribidi_tab_char_type_9.i4
-rw-r--r--fribidi_tab_mirroring.i2
-rw-r--r--fribidi_types.h2
-rw-r--r--fribidi_utils.c54
-rw-r--r--packtab.c2
22 files changed, 807 insertions, 243 deletions
diff --git a/ChangeLog b/ChangeLog
index 48e2f5c..dfac033 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2002-03-16 Behdad Esfahbod <behdad@bamdad.org>
+ * Applied the FriBidiEnv patch from Omer Zak dated 2002-02-24,
+ updated it with to reflect the new changes.
+ * NOTE: These changes alter the interface, so are not recommended for
+ any use before they are released.
+
+2002-03-16 Omer Zak <omerz@actcom.co.il>
+ * This is the big FriBidiEnv patch.
+ * Several files: Added FriBidiEnv* parameter to several procedures.
+ * fribidi_env.c, fribidi_env.h: Added.
+
2002-03-15 Behdad Esfahbod <behdad@bamdad.org>
* 0.10.2 released.
* configure.in: Changed version to 0.10.2.
diff --git a/Makefile.am b/Makefile.am
index 16ff7dc..af47f2e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,6 +34,7 @@ libfribidi_la_SOURCES = \
fribidi.c \
fribidi_types.c \
fribidi_mem.c \
+ fribidi_env.c \
fribidi_mirroring.c \
fribidi_char_type.c \
fribidi_wcwidth.c \
@@ -49,6 +50,7 @@ libfribidiinc_HEADERS = \
fribidi.h \
fribidi_types.h \
fribidi_mem.h \
+ fribidi_env.h \
fribidi_unicode.h \
$(libfribidi_charsets_h) \
$(libfribidi_charsets_extra_h) \
@@ -144,6 +146,9 @@ fribidi_tab_char_type_stamp:
touch "$(srcdir)/fribidi_char_type.c" || $(MAKE) clean
touch "$@"
+fribidi_tabs: fribidi_tab_mirroring.i \
+ fribidi_tab_char_type_2.i fribidi_tab_char_type_9.i
+
config.h: fribidi_tab_char_type_stamp
./config.status --recheck
./config.status
@@ -171,7 +176,8 @@ test: fribidi
"$(srcdir)/run.tests"
.PHONY: test test.reference \
- fribidi_tab_char_type_small fribidi_tab_char_type_large
+ fribidi_tab_char_type_small fribidi_tab_char_type_large \
+ fribidi_tabs
TESTS = run.tests
diff --git a/NEWS b/NEWS
index a3517eb..03a53c3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+New in CVS:
+
+* fribidi has been restructured, to become reentrant. The api is completely
+ changed. So please do not use the new api in any public code, before the
+ next version is released (the api is heavily subject to changes).
+
New in 0.10.2:
* Rule L3 of UAX#9 implemented. Now fribidi implements the whole Unicode
diff --git a/fribidi.c b/fribidi.c
index f28a5a5..caced13 100644
--- a/fribidi.c
+++ b/fribidi.c
@@ -41,8 +41,8 @@
#endif
#ifdef DEBUG
-#define DBG(s) do { if (fribidi_debug) { fprintf(stderr, s); } } while (0)
-#define DBG2(s, t) do { if (fribidi_debug) { fprintf(stderr, s, t); } } while (0)
+#define DBG(s) do { if (fribidi_debug_status(fribidienv)) { fprintf(stderr, s); } } while (0)
+#define DBG2(s, t) do { if (fribidi_debug_status(fribidienv)) { fprintf(stderr, s, t); } } while (0)
#else
#define DBG(s)
#define DBG2(s, t)
@@ -80,19 +80,6 @@ typedef struct
}
LevelInfo;
-#ifdef DEBUG
-static boolean fribidi_debug = FALSE;
-#endif
-
-boolean
-fribidi_set_debug (boolean debug)
-{
-#ifdef DEBUG
- return fribidi_debug = debug;
-#else
- return 0;
-#endif
-}
static void
bidi_string_reverse (FriBidiChar *str, FriBidiStrIndex len)
@@ -123,12 +110,12 @@ static TypeLink *free_type_links = NULL;
#endif
static TypeLink *
-new_type_link (void)
+new_type_link (FriBidiEnv* fribidienv)
{
TypeLink *link;
#ifdef USE_SIMPLE_MALLOC
- link = malloc (sizeof (TypeLink));
+ link = (TypeLink*) fribidi_malloc (fribidienv, sizeof (TypeLink));
#else /* !USE_SIMPLE_MALLOC */
if (free_type_links)
{
@@ -141,10 +128,11 @@ new_type_link (void)
if (!mem_chunk)
mem_chunk =
- fribidi_mem_chunk_create (TypeLink, FRIBIDI_CHUNK_SIZE,
+ fribidi_mem_chunk_create (fribidienv,
+ TypeLink, FRIBIDI_CHUNK_SIZE,
FRIBIDI_ALLOC_ONLY);
- link = fribidi_chunk_new (TypeLink, mem_chunk);
+ link = fribidi_chunk_new (fribidienv, TypeLink, mem_chunk);
}
#endif /* !USE_SIMPLE_MALLOC */
@@ -157,10 +145,10 @@ new_type_link (void)
}
static void
-free_type_link (TypeLink *link)
+free_type_link (FriBidiEnv* fribidienv, TypeLink *link)
{
#ifdef USE_SIMPLE_MALLOC
- free (link);
+ fribidi_free (fribidienv,link);
#else
link->next = free_type_links;
free_type_links = link;
@@ -176,14 +164,15 @@ free_type_link (TypeLink *link)
} while (0)
static TypeLink *
-run_length_encode_types (FriBidiCharType *char_type, FriBidiStrIndex type_len)
+run_length_encode_types (FriBidiEnv* fribidienv,
+ FriBidiCharType *char_type, FriBidiStrIndex type_len)
{
TypeLink *list, *last, *link;
FriBidiStrIndex i;
/* Add the starting link */
- list = new_type_link ();
+ list = new_type_link (fribidienv);
list->type = FRIBIDI_TYPE_SOT;
list->level = FRIBIDI_LEVEL_START;
last = list;
@@ -192,14 +181,14 @@ run_length_encode_types (FriBidiCharType *char_type, FriBidiStrIndex type_len)
for (i = 0; i < type_len; i++)
if (char_type[i] != last->type)
{
- link = new_type_link ();
+ link = new_type_link (fribidienv);
link->type = char_type[i];
link->pos = i;
FRIBIDI_ADD_TYPE_LINK (last, link);
}
/* Add the ending link */
- link = new_type_link ();
+ link = new_type_link (fribidienv);
link->type = FRIBIDI_TYPE_EOT;
link->level = FRIBIDI_LEVEL_END;
link->pos = type_len;
@@ -213,20 +202,21 @@ run_length_encode_types (FriBidiCharType *char_type, FriBidiStrIndex type_len)
the override_list.
*/
static void
-init_list (TypeLink **start, TypeLink **end)
+init_list (FriBidiEnv* fribidienv,
+ TypeLink **start, TypeLink **end)
{
TypeLink *list;
TypeLink *link;
/* Add the starting link */
- list = new_type_link ();
+ list = new_type_link (fribidienv);
list->type = FRIBIDI_TYPE_SOT;
list->level = FRIBIDI_LEVEL_START;
list->len = 0;
list->pos = 0;
/* Add the ending link */
- link = new_type_link ();
+ link = new_type_link (fribidienv);
link->type = FRIBIDI_TYPE_EOT;
link->level = FRIBIDI_LEVEL_END;
link->len = 0;
@@ -272,7 +262,7 @@ move_element_before (TypeLink *p, TypeLink *list)
TBD: use some explanatory names instead of p, q, ...
*/
static void
-override_list (TypeLink *base, TypeLink *over)
+override_list (FriBidiEnv* fribidienv, TypeLink *base, TypeLink *over)
{
TypeLink *p = base, *q, *r, *s, *t;
FriBidiStrIndex pos = 0, pos2;
@@ -286,7 +276,7 @@ override_list (TypeLink *base, TypeLink *over)
{
t = q;
q = q->next;
- free_type_link (t);
+ free_type_link (fribidienv, t);
continue;
}
pos = q->pos;
@@ -307,7 +297,7 @@ override_list (TypeLink *base, TypeLink *over)
r = r->next;
else
{
- r = new_type_link ();
+ r = new_type_link (fribidienv);
*r = *p;
if (r->next)
{
@@ -323,7 +313,7 @@ override_list (TypeLink *base, TypeLink *over)
{
t = p;
p = p->prev;
- free_type_link (t);
+ free_type_link (fribidienv, t);
}
else
p->len = pos - p->pos;
@@ -349,7 +339,7 @@ override_list (TypeLink *base, TypeLink *over)
{
t = s;
s = s->next;
- free_type_link (t);
+ free_type_link (fribidienv, t);
}
}
/* before updating the next and prev links to point to the inserted q,
@@ -371,28 +361,28 @@ override_list (TypeLink *base, TypeLink *over)
#define RL_LEVEL(list) ((list)->level)
static TypeLink *
-merge_with_prev (TypeLink *second)
+merge_with_prev (FriBidiEnv* fribidienv, TypeLink *second)
{
TypeLink *first = second->prev;
first->next = second->next;
first->next->prev = first;
RL_LEN (first) += RL_LEN (second);
- free_type_link (second);
+ free_type_link (fribidienv, second);
return first;
}
static void
-compact_list (TypeLink *list)
+compact_list (FriBidiEnv* fribidienv, TypeLink *list)
{
if (list->next)
for (list = list->next; list; list = list->next)
if (RL_TYPE (list->prev) == RL_TYPE (list)
&& RL_LEVEL (list->prev) == RL_LEVEL (list))
- list = merge_with_prev (list);
+ list = merge_with_prev (fribidienv, list);
}
static void
-compact_neutrals (TypeLink *list)
+compact_neutrals (FriBidiEnv* fribidienv, TypeLink *list)
{
if (list->next)
{
@@ -404,7 +394,7 @@ compact_neutrals (TypeLink *list)
(list->prev) == RL_TYPE (list)
|| (FRIBIDI_IS_NEUTRAL (RL_TYPE (list->prev))
&& FRIBIDI_IS_NEUTRAL (RL_TYPE (list))))))
- list = merge_with_prev (list);
+ list = merge_with_prev (fribidienv, list);
}
}
}
@@ -572,7 +562,7 @@ print_bidi_string (FriBidiChar *str)
fprintf (stderr, " Org. types : ");
for (i = 0; str[i]; i++)
fprintf (stderr, "%c",
- fribidi_char_from_type (fribidi_get_type (str[i])));
+ fribidi_char_from_type (fribidi_get_type (fribidienv,str[i])));
fprintf (stderr, "\n");
}
#endif
@@ -581,8 +571,9 @@ print_bidi_string (FriBidiChar *str)
* This function should follow the Unicode specification closely!
*----------------------------------------------------------------------*/
static void
-fribidi_analyse_string ( /* input */
- FriBidiChar *str, FriBidiStrIndex len,
+fribidi_analyse_string ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str, FriBidiStrIndex len,
FriBidiCharType *pbase_dir,
/* output */
TypeLink **ptype_rl_list, FriBidiLevel *pmax_level)
@@ -598,17 +589,17 @@ fribidi_analyse_string ( /* input */
DBG (" Determine character types\n");
{
FriBidiCharType *char_type =
- (FriBidiCharType *) malloc (len * sizeof (FriBidiCharType));
+ (FriBidiCharType *) fribidi_malloc (fribidienv, len * sizeof (FriBidiCharType));
for (i = 0; i < len; i++)
- char_type[i] = fribidi_get_type (str[i]);
+ char_type[i] = fribidi_get_type (fribidienv,str[i]);
/* Run length encode the character types */
- type_rl_list = run_length_encode_types (char_type, len);
- free (char_type);
+ type_rl_list = run_length_encode_types (fribidienv, char_type, len);
+ fribidi_free (fribidienv,char_type);
}
DBG (" Determine character types, Done\n");
- init_list (&explicits_list, &explicits_list_end);
+ init_list (fribidienv, &explicits_list, &explicits_list_end);
/* Find base level */
DBG (" Finding the base level\n");
@@ -636,7 +627,7 @@ fribidi_analyse_string ( /* input */
DBG (" Finding the base level, Done\n");
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_types_re (type_rl_list);
}
@@ -663,7 +654,7 @@ fribidi_analyse_string ( /* input */
over_pushed = 0;
first_interval = 0;
status_stack =
- (LevelInfo *) malloc (sizeof (LevelInfo) * (UNI_MAX_BIDI_LEVEL + 2));
+ (LevelInfo *) fribidi_malloc (fribidienv, sizeof (LevelInfo) * (UNI_MAX_BIDI_LEVEL + 2));
for (pp = type_rl_list->next; pp->next; pp = pp->next)
{
@@ -727,7 +718,7 @@ fribidi_analyse_string ( /* input */
stack_size = 0;
over_pushed = 0;
- free (status_stack);
+ fribidi_free (fribidienv,status_stack);
}
/* X10. The remaining rules are applied to each run of characters at the
same level. For each run, determine the start-of-level-run (sor) and
@@ -739,10 +730,10 @@ fribidi_analyse_string ( /* input */
/* Resolving Implicit Levels can be done out of X10 loop, so only change
of Resolving Weak Types and Resolving Neutral Types is needed. */
- compact_list (type_rl_list);
+ compact_list (fribidienv, type_rl_list);
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_types_re (type_rl_list);
print_bidi_string (str);
@@ -781,7 +772,7 @@ fribidi_analyse_string ( /* input */
if (this_type == FRIBIDI_TYPE_NSM)
{
if (RL_LEVEL (pp->prev) == RL_LEVEL (pp))
- pp = merge_with_prev (pp);
+ pp = merge_with_prev (fribidienv, pp);
else
RL_TYPE (pp) = prev_type;
continue; /* As we know the next condition cannot be true. */
@@ -871,10 +862,10 @@ fribidi_analyse_string ( /* input */
}
}
- compact_neutrals (type_rl_list);
+ compact_neutrals (fribidienv, type_rl_list);
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_resolved_levels (type_rl_list);
print_resolved_types (type_rl_list);
@@ -903,10 +894,10 @@ fribidi_analyse_string ( /* input */
}
}
- compact_list (type_rl_list);
+ compact_list (fribidienv, type_rl_list);
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_resolved_levels (type_rl_list);
print_resolved_types (type_rl_list);
@@ -921,7 +912,7 @@ fribidi_analyse_string ( /* input */
for (pp = type_rl_list->next; pp->next; pp = pp->next)
{
FriBidiCharType this_type;
- int level;
+ FriBidiLevel level;
this_type = RL_TYPE (pp);
level = RL_LEVEL (pp);
@@ -939,10 +930,10 @@ fribidi_analyse_string ( /* input */
}
}
- compact_list (type_rl_list);
+ compact_list (fribidienv, type_rl_list);
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_bidi_string (str);
print_resolved_levels (type_rl_list);
@@ -956,7 +947,7 @@ fribidi_analyse_string ( /* input */
{
TypeLink *p;
- override_list (type_rl_list, explicits_list);
+ override_list (fribidienv, type_rl_list, explicits_list);
p = type_rl_list->next;
if (p->level < 0)
p->level = base_level;
@@ -966,7 +957,7 @@ fribidi_analyse_string ( /* input */
}
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_types_re (type_rl_list);
print_resolved_levels (type_rl_list);
@@ -980,7 +971,7 @@ fribidi_analyse_string ( /* input */
TypeLink *p, *q, *list, *list_end;
/* L1. Reset the embedding levels of some chars. */
- init_list (&list, &list_end);
+ init_list (fribidienv, &list, &list_end);
q = list_end;
state = 1;
pos = len - 1;
@@ -988,7 +979,7 @@ fribidi_analyse_string ( /* input */
{
/* if state is on at the very first of string, do this too. */
if (j >= 0)
- k = fribidi_get_type (str[j]);
+ k = fribidi_get_type (fribidienv,str[j]);
else
k = FRIBIDI_TYPE_ON;
if (!state && FRIBIDI_IS_SEPARATOR (k))
@@ -999,8 +990,8 @@ fribidi_analyse_string ( /* input */
else if (state && !FRIBIDI_IS_EXPLICIT_OR_SEPARATOR_OR_BN_OR_WS (k))
{
state = 0;
- p = new_type_link ();
- p->prev = p->next = NULL;
+ p = new_type_link (fribidienv);
+ p->prev = p->next = (TypeLink*) NULL;
p->pos = j + 1;
p->len = pos - j;
p->type = base_dir;
@@ -1009,11 +1000,11 @@ fribidi_analyse_string ( /* input */
q = p;
}
}
- override_list (type_rl_list, list);
+ override_list (fribidienv, type_rl_list, list);
}
#ifdef DEBUG
- if (fribidi_debug)
+ if (fribidi_debug_status(fribidienv))
{
print_types_re (type_rl_list);
print_resolved_levels (type_rl_list);
@@ -1034,7 +1025,7 @@ fribidi_analyse_string ( /* input */
* fribidi_analyse_string(), after the list is not needed anymore.
*----------------------------------------------------------------------*/
static void
-free_rl_list (TypeLink *type_rl_list)
+free_rl_list (FriBidiEnv* fribidienv, TypeLink *type_rl_list)
{
TypeLink *pp;
@@ -1055,7 +1046,7 @@ free_rl_list (TypeLink *type_rl_list)
p = pp;
pp = pp->next;
- free_type_link (p);
+ free_type_link (fribidienv, p);
};
#else
for (pp = type_rl_list->next; pp->next; pp = pp->next)
@@ -1069,33 +1060,6 @@ free_rl_list (TypeLink *type_rl_list)
return;
}
-static boolean mirroring = TRUE;
-
-boolean
-fribidi_mirroring_status (void)
-{
- return mirroring;
-}
-
-void
-fribidi_set_mirroring (boolean mirror)
-{
- mirroring = mirror;
-}
-
-static boolean reorder_nsm = FALSE;
-
-boolean
-fribidi_reorder_nsm_status (void)
-{
- return reorder_nsm;
-}
-
-void
-fribidi_set_reorder_nsm (boolean reorder)
-{
- reorder_nsm = reorder;
-}
/*======================================================================
* Here starts the exposed front end functions.
@@ -1106,7 +1070,8 @@ fribidi_set_reorder_nsm (boolean reorder)
* the new length, updates each of other inputs if not NULL.
*----------------------------------------------------------------------*/
FriBidiStrIndex
-fribidi_remove_bidi_marks (FriBidiChar *str, FriBidiStrIndex length,
+fribidi_remove_bidi_marks (FriBidiEnv* fribidienv,
+ FriBidiChar *str, FriBidiStrIndex length,
FriBidiStrIndex *position_to_this_list,
FriBidiStrIndex *position_from_this_list,
FriBidiLevel *embedding_level_list)
@@ -1122,12 +1087,12 @@ fribidi_remove_bidi_marks (FriBidiChar *str, FriBidiStrIndex length,
{
private_from_this = TRUE;
position_from_this_list =
- (FriBidiStrIndex *) malloc (sizeof (FriBidiStrIndex) * length);
+ (FriBidiStrIndex *) fribidi_malloc (fribidienv, sizeof (FriBidiStrIndex) * length);
}
j = 0;
for (i = 0; i < length; i++)
- if (!FRIBIDI_IS_EXPLICIT (fribidi_get_type (str[i]))
+ if (!FRIBIDI_IS_EXPLICIT (fribidi_get_type (fribidienv,str[i]))
&& str[i] != UNI_LRM && str[i] != UNI_RLM)
{
str[j] = str[i];
@@ -1150,7 +1115,7 @@ fribidi_remove_bidi_marks (FriBidiChar *str, FriBidiStrIndex length,
}
if (private_from_this)
- free (position_from_this_list);
+ fribidi_free (fribidienv, position_from_this_list);
DBG ("Leaving fribidi_remove_bidi_marks()\n");
return j;
@@ -1162,8 +1127,9 @@ fribidi_remove_bidi_marks (FriBidiChar *str, FriBidiStrIndex length,
* does reordering and fills in the output strings.
*----------------------------------------------------------------------*/
boolean
-fribidi_log2vis ( /* input */
- FriBidiChar *str, FriBidiStrIndex len,
+fribidi_log2vis ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str, FriBidiStrIndex len,
FriBidiCharType *pbase_dir,
/* output */
FriBidiChar *visual_str,
@@ -1171,7 +1137,7 @@ fribidi_log2vis ( /* input */
FriBidiStrIndex *position_V_to_L_list,
FriBidiLevel *embedding_level_list)
{
- TypeLink *type_rl_list, *pp = NULL;
+ TypeLink *type_rl_list, *pp = (TypeLink*) NULL;
FriBidiLevel max_level;
boolean private_V_to_L = FALSE;
@@ -1189,7 +1155,7 @@ fribidi_log2vis ( /* input */
{
private_V_to_L = TRUE;
position_V_to_L_list =
- (FriBidiStrIndex *) malloc (sizeof (FriBidiStrIndex) * len);
+ (FriBidiStrIndex *) fribidi_malloc (fribidienv, sizeof (FriBidiStrIndex) * len);
}
if (len > FRIBIDI_MAX_STRING_LENGTH && position_V_to_L_list)
@@ -1200,7 +1166,7 @@ fribidi_log2vis ( /* input */
#endif
return FALSE;
}
- fribidi_analyse_string (str, len, pbase_dir,
+ fribidi_analyse_string (fribidienv, str, len, pbase_dir,
/* output */
&type_rl_list, &max_level);
@@ -1249,7 +1215,7 @@ fribidi_log2vis ( /* input */
/* Reorder both the outstring and the order array */
if (visual_str || position_V_to_L_list)
{
- if (mirroring && visual_str)
+ if (fribidi_mirroring_status(fribidienv) && visual_str)
{
/* L4. Mirror all characters that are in odd levels and have mirrors. */
DBG (" Mirroring\n");
@@ -1262,7 +1228,7 @@ fribidi_log2vis ( /* input */
{
FriBidiChar mirrored_ch;
if (fribidi_get_mirror_char
- (visual_str[i], &mirrored_ch))
+ (fribidienv, visual_str[i], &mirrored_ch))
visual_str[i] = mirrored_ch;
}
}
@@ -1270,7 +1236,7 @@ fribidi_log2vis ( /* input */
DBG (" Mirroring, Done\n");
}
- if (reorder_nsm)
+ if (fribidi_reorder_nsm_status(fribidienv))
{
/* L3. Reorder NSMs. */
DBG (" Reordering NSM sequences\n");
@@ -1287,7 +1253,7 @@ fribidi_log2vis ( /* input */
{
FriBidiCharType this_type;
- this_type = fribidi_get_type (visual_str[i]);
+ this_type = fribidi_get_type (NULL, visual_str[i]);
if (is_nsm_seq && this_type != FRIBIDI_TYPE_NSM)
{
if (visual_str)
@@ -1357,9 +1323,9 @@ fribidi_log2vis ( /* input */
DBG ("Reordering resolved levels, Done\n");
if (private_V_to_L)
- free (position_V_to_L_list);
+ fribidi_free (fribidienv, position_V_to_L_list);
- free_rl_list (type_rl_list);
+ free_rl_list (fribidienv, type_rl_list);
DBG ("Leaving fribidi_log2vis()\n");
return TRUE;
@@ -1371,8 +1337,9 @@ fribidi_log2vis ( /* input */
* the embedding levels.
*----------------------------------------------------------------------*/
boolean
-fribidi_log2vis_get_embedding_levels ( /* input */
- FriBidiChar *str,
+fribidi_log2vis_get_embedding_levels ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str,
FriBidiStrIndex len,
FriBidiCharType *pbase_dir,
/* output */
@@ -1389,7 +1356,7 @@ fribidi_log2vis_get_embedding_levels ( /* input */
return TRUE;
}
- fribidi_analyse_string (str, len, pbase_dir,
+ fribidi_analyse_string (fribidienv, str, len, pbase_dir,
/* output */
&type_rl_list, &max_level);
@@ -1401,7 +1368,7 @@ fribidi_log2vis_get_embedding_levels ( /* input */
embedding_level_list[pos + i] = level;
}
- free_rl_list (type_rl_list);
+ free_rl_list (fribidienv, type_rl_list);
DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
return TRUE;
@@ -1409,7 +1376,7 @@ fribidi_log2vis_get_embedding_levels ( /* input */
-const char *fribidi_version_info =
+const char fribidi_version_info[] =
FRIBIDI_PACKAGE " " FRIBIDI_VERSION " (interface version "
FRIBIDI_INTERFACE_VERSION_STR ")\n"
"Copyright (C) 2001 FriBidi Project (http://fribidi.sf.net/).\n" "\n"
diff --git a/fribidi.h b/fribidi.h
index 85230f9..a616654 100644
--- a/fribidi.h
+++ b/fribidi.h
@@ -28,6 +28,8 @@
#include "fribidi_unicode.h"
#include "fribidi_mem.h"
#include "fribidi_types.h"
+#include "fribidi_env.h"
+
#ifndef FRIBIDI_NO_CHARSETS
#include "fribidi_char_sets.h"
#endif
@@ -37,8 +39,10 @@ extern "C"
{
#endif
- boolean fribidi_log2vis ( /* input */
- FriBidiChar *str, FriBidiStrIndex len,
+ boolean fribidi_log2vis ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str,
+ FriBidiStrIndex len,
FriBidiCharType *pbase_dirs,
/* output */
FriBidiChar *visual_str,
@@ -46,8 +50,9 @@ extern "C"
FriBidiStrIndex *position_V_to_L_list,
FriBidiLevel *embedding_level_list);
- boolean fribidi_log2vis_get_embedding_levels ( /* input */
- FriBidiChar *str,
+ boolean fribidi_log2vis_get_embedding_levels ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str,
FriBidiStrIndex len,
FriBidiCharType *pbase_dir,
/* output */
@@ -58,7 +63,8 @@ extern "C"
* fribidi_remove_bidi_marks() removes bidirectional marks, and returns
* the new length, also updates each of other inputs if not NULL.
*----------------------------------------------------------------------*/
- FriBidiStrIndex fribidi_remove_bidi_marks (FriBidiChar *str,
+ FriBidiStrIndex fribidi_remove_bidi_marks (FriBidiEnv* fribidienv,
+ FriBidiChar *str,
FriBidiStrIndex length,
FriBidiStrIndex
*position_to_this_list,
@@ -70,13 +76,20 @@ extern "C"
/*======================================================================
* fribidi_get_type() returns bidi type of a character.
*----------------------------------------------------------------------*/
- FriBidiCharType fribidi_get_type (FriBidiChar uch);
+ FriBidiCharType fribidi_get_type_internal (FriBidiChar uch);
+
+ /* At present, the fribidienv parameter is not actually used
+ * by this procedure.
+ */
+#define fribidi_get_type(fribidienv,uch) fribidi_get_type_internal(uch)
/*======================================================================
* fribidi_get_types() returns bidi type of a string.
*----------------------------------------------------------------------*/
- void fribidi_get_types ( /* input */
- FriBidiChar *str, FriBidiStrIndex len,
+ void fribidi_get_types ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str,
+ FriBidiStrIndex len,
/* output */
FriBidiCharType *type);
@@ -85,38 +98,19 @@ extern "C"
* character has a mirror, or the input itself.
* if mirrored_ch is NULL, just returns if character has a mirror or not.
*----------------------------------------------------------------------*/
- boolean fribidi_get_mirror_char ( /* Input */
+ boolean fribidi_get_mirror_char ( FriBidiEnv* fribidienv,
+ /* Input */
FriBidiChar ch,
/* Output */
FriBidiChar *mirrored_ch);
-
-/*======================================================================
- * fribidi_mirroring_status() returns whether mirroring is on or off,
- * default is on.
- *----------------------------------------------------------------------*/
- boolean fribidi_mirroring_status (void);
-
-/*======================================================================
- * fribidi_set_mirroring() sets mirroring on or off.
- *----------------------------------------------------------------------*/
- void fribidi_set_mirroring (boolean mirror);
-
-/*======================================================================
- * fribidi_reorder_nsm_status() returns whether reordering of NSM
- * sequences is on or off, default is off.
- *----------------------------------------------------------------------*/
- boolean fribidi_reorder_nsm_status (void);
-
-/*======================================================================
- * fribidi_set_reorder_nsm() sets reordering of NSM characters on or off.
- *----------------------------------------------------------------------*/
- void fribidi_set_reorder_nsm (boolean);
-
/*======================================================================
- * fribidi_set_debug() turn on or off debugging, default is off, return
- * false is fribidi is not compiled with debug enabled.
+ * The following functions were moved to fribidi_env:
+ * - fribidi_mirroring_status()
+ * - fribidi_set_mirroring()
+ * - fribidi_reorder_nsm_status()
+ * - fribidi_set_reorder_nsm()
+ * - fribidi_set_debug()
*----------------------------------------------------------------------*/
- boolean fribidi_set_debug (boolean debug);
/* fribidi_utils.c */
@@ -125,10 +119,11 @@ extern "C"
* of characters that need redrawing. It returns the start and the
* length of the section in the new string that needs redrawing.
*----------------------------------------------------------------------*/
- void fribidi_find_string_changes ( /* input */
- FriBidiChar *old_str,
+ void fribidi_find_string_changes ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *old_str,
FriBidiStrIndex old_len,
- FriBidiChar *new_str,
+ const FriBidiChar *new_str,
FriBidiStrIndex new_len,
/* output */
FriBidiStrIndex *change_start,
@@ -164,10 +159,13 @@ extern "C"
* // output
* &num_vis_ranges, *vis_ranges);
**----------------------------------------------------------------------*/
- void fribidi_map_range (FriBidiStrIndex span[2], FriBidiStrIndex len,
+ void fribidi_map_range (FriBidiEnv* fribidienv,
+ /* input */
+ FriBidiStrIndex span[2],
+ FriBidiStrIndex len,
boolean is_v2l_map,
- FriBidiStrIndex *position_map,
- FriBidiLevel *embedding_level_list,
+ const FriBidiStrIndex *position_map,
+ const FriBidiLevel *embedding_level_list,
/* output */
int *num_mapped_spans, FriBidiStrIndex spans[3][2]);
@@ -176,7 +174,8 @@ extern "C"
* was resolved in the rtl direction. This simply involves asking
* if the embedding level for the character is odd.
*----------------------------------------------------------------------*/
- boolean fribidi_is_char_rtl (FriBidiLevel *embedding_level_list,
+ boolean fribidi_is_char_rtl (FriBidiEnv* fribidienv,
+ const FriBidiLevel *embedding_level_list,
FriBidiCharType base_dir, FriBidiStrIndex idx);
/*======================================================================
@@ -227,11 +226,14 @@ extern "C"
* beyond the end of the line, res_attach_before is true.
*
*----------------------------------------------------------------------*/
- void fribidi_xpos_resolve (int x_pos, int x_offset,
+ void fribidi_xpos_resolve (FriBidiEnv* fribidienv,
+ /* input */
+ int x_pos, int x_offset,
FriBidiStrIndex len,
- FriBidiLevel *embedding_level_list,
+ const FriBidiLevel *embedding_level_list,
FriBidiCharType base_dir,
- FriBidiStrIndex *vis2log, int *char_widths,
+ const FriBidiStrIndex *vis2log,
+ const int *char_widths,
/* output */
FriBidiStrIndex *res_log_pos,
FriBidiStrIndex *res_vis_pos,
@@ -244,9 +246,11 @@ extern "C"
* a list of visual runs. A run is defined as a sequence that has
* the same attributes.
*----------------------------------------------------------------------*/
- void fribidi_runs_log2vis ( /* input */
- FriBidiList *logical_runs, /* List of FriBidiRunType */
- FriBidiStrIndex len, FriBidiStrIndex *log2vis,
+ void fribidi_runs_log2vis ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiList *logical_runs, /* List of FriBidiRunType */
+ FriBidiStrIndex len,
+ const FriBidiStrIndex *log2vis,
FriBidiCharType base_dir,
/* output */
FriBidiList **visual_runs);
diff --git a/fribidi_benchmark.c b/fribidi_benchmark.c
index 5e91112..670b911 100644
--- a/fribidi_benchmark.c
+++ b/fribidi_benchmark.c
@@ -163,7 +163,7 @@ benchmark (char *S_, int niter)
{
/* Create a bidi string */
base = FRIBIDI_TYPE_ON;
- fribidi_log2vis (us, len, &base,
+ fribidi_log2vis (NULL, us, len, &base,
/* output */
out_us, positionVtoL, positionLtoV, embedding_list);
}
diff --git a/fribidi_char_sets_cap_rtl.c b/fribidi_char_sets_cap_rtl.c
index 82632b8..a0cee9b 100644
--- a/fribidi_char_sets_cap_rtl.c
+++ b/fribidi_char_sets_cap_rtl.c
@@ -161,7 +161,7 @@ fribidi_unicode_to_cap_rtl (FriBidiChar *us, int length, char *s)
for (i = 0; i < length; i++)
{
FriBidiChar ch = us[i];
- if (!FRIBIDI_IS_EXPLICIT (fribidi_get_type (ch)) && ch != '_'
+ if (!FRIBIDI_IS_EXPLICIT (fribidi_get_type_internal (ch)) && ch != '_'
&& ch != UNI_LRM && ch != UNI_RLM)
s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
else
@@ -218,7 +218,7 @@ fribidi_char_set_desc_cap_rtl (void)
return s;
l = 4000;
- s = (char *) malloc (l);
+ s = (char *) fribidi_malloc (NULL, l);
i = 0;
i += snprintf (s + i, l - i,
"CapRTL is a character set for testing with the reference\n"
@@ -262,11 +262,11 @@ fribidi_char_set_enter_cap_rtl (void)
int i, count;
caprtl_to_unicode =
- (FriBidiChar *) malloc (CAPRTL_CHARS * sizeof caprtl_to_unicode[0]);
+ (FriBidiChar *) fribidi_malloc (NULL, CAPRTL_CHARS * sizeof caprtl_to_unicode[0]);
for (i = 0; i < FRIBIDI_TYPES_COUNT; i++)
request[i] = 0;
for (i = 0; i < CAPRTL_CHARS; i++)
- if (fribidi_get_mirror_char (i, NULL))
+ if (fribidi_get_mirror_char (NULL, i, NULL))
caprtl_to_unicode[i] = i;
for (count = 0, i = 0; i < CAPRTL_CHARS; i++)
if (caprtl_to_unicode[i] == 0)
@@ -275,11 +275,11 @@ fribidi_char_set_enter_cap_rtl (void)
count++;
}
for (i = 1; i < 0x10000 && count; i++) /* Assign BMP chars to CapRTL entries */
- if (!fribidi_get_mirror_char (i, NULL))
+ if (!fribidi_get_mirror_char (NULL, i, NULL))
{
int j, k;
for (j = 0; j < FRIBIDI_TYPES_COUNT; j++)
- if (fribidi_prop_to_type[j] == fribidi_get_type (i))
+ if (fribidi_prop_to_type[j] == fribidi_get_type_internal (i))
break;
if (!request[j]) /* Do not need this type */
continue;
diff --git a/fribidi_char_type.c b/fribidi_char_type.c
index 2d172fd..a16f904 100644
--- a/fribidi_char_type.c
+++ b/fribidi_char_type.c
@@ -27,18 +27,19 @@
/*======================================================================
* fribidi_get_type() returns the bidi type of a character.
*----------------------------------------------------------------------*/
-FriBidiCharType fribidi_get_type (FriBidiChar uch);
+FriBidiCharType fribidi_get_type_internal (FriBidiChar uch);
void
-fribidi_get_types ( /* input */
- FriBidiChar *str, FriBidiStrIndex len,
+fribidi_get_types ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *str, FriBidiStrIndex len,
/* output */
FriBidiCharType *type)
{
FriBidiStrIndex i;
for (i = 0; i < len; i++)
- type[i] = fribidi_get_type (str[i]);
+ type[i] = fribidi_get_type_internal (str[i]);
}
#ifdef MEM_OPTIMIZED
diff --git a/fribidi_create_char_types.c b/fribidi_create_char_types.c
index 34c62f0..9e1cbb9 100644
--- a/fribidi_create_char_types.c
+++ b/fribidi_create_char_types.c
@@ -103,7 +103,7 @@ get_type (char *s)
#define table_name "FriBidiPropertyBlock"
#define key_type_name "FriBidiPropCharType"
#define macro_name "FRIBIDI_GET_TYPE"
-#define function_name "fribidi_get_type"
+#define function_name "fribidi_get_type_internal"
#define char_type_name "FriBidiCharType"
#define char_name "FriBidiChar"
#define prop_to_type_name "fribidi_prop_to_type"
diff --git a/fribidi_create_mirroring.c b/fribidi_create_mirroring.c
index 057046e..0b3fc0d 100644
--- a/fribidi_create_mirroring.c
+++ b/fribidi_create_mirroring.c
@@ -119,7 +119,7 @@ write_mirror (char *file)
fprintf (f, " {0x%04X, 0x%04X},\n", i, table[i]);
fprintf (f, "} ;\n\n");
fprintf (f, "/* *INDE" "NT-ON* */\n\n");
- fprintf (f, "int nFriBidiMirroredChars = %d;\n\n", mirroring_count);
+ fprintf (f, "const int nFriBidiMirroredChars = %d;\n\n", mirroring_count);
fprintf (f, "\n#endif /* %s */\n", FILENAME);
fclose (f);
}
diff --git a/fribidi_env.c b/fribidi_env.c
new file mode 100644
index 0000000..20f3733
--- /dev/null
+++ b/fribidi_env.c
@@ -0,0 +1,268 @@
+/* fribidi_env.c - FriBidi environment management
+ * Copyright (C) 2002 Omer Zak
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library, in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA
+ *
+ * For licensing issues, contact <omerz@actcom.co.il>
+ */
+
+
+/*======================================================================
+ * The FriBidiEnv structure encapsulates data about the environment
+ * in which a particular instance of FriBidi runs.
+ *
+ * The structure was introduced to meet the following objectives:
+ * 1. Mechanism for freeing all memory allocated by FriBidi procedures
+ * if a procedure stopped executing in middle due to any reason,
+ * such as memory allocation failure.
+ * This mechanism is necessary for using FriBidi in small-memory
+ * devices, such as devices which run the GEOS and Symbian EPOC 6
+ * operating systems.
+ * 2. Avoidance of modifiable static memory variables, which are
+ * not allowed in Symbian EPOC 6 applications, and which prevent
+ * the FriBidi library from being reentrant in certain operating
+ * systems. The structure also allows FriBidi to be used in
+ * multithreaded environments.
+ * 3. Allow an application to run FriBidi under independent environments,
+ * using different settings in each environment.
+ *
+ * Every FriBidi function requires a pointer to FriBidiEnv as its first
+ * argument.
+ *----------------------------------------------------------------------*/
+
+/* For standard malloc() and free(). */
+#include <stdlib.h>
+
+#include <assert.h>
+
+#include "fribidi_env.h"
+
+/*======================================================================
+ * Initialize a FriBidiEnv structure. Must be called before any
+ * other use of the structure.
+ *
+ * It initializes the doubly-linked list of memory chunks and the flags.
+ *----------------------------------------------------------------------*/
+
+void init_fribidienv(FriBidiEnv* fribidienv, FriBidiFlags aFlags)
+{
+ VALIDATE_FRIBIDIENV(fribidienv);
+ fribidienv->iAllocatedMemoryChunks = NULL;
+ fribidienv->iFlags = aFlags;
+ /* fribidienv->iReserved3 = NULL; */
+}
+
+/*======================================================================
+ * Free all memory linked to this FriBidiEnv instance.
+ * After calling this procedure, the instance is legally initialized,
+ * so there is no need for a separate init_fribidienv() call (but it
+ * does not harm).
+ *----------------------------------------------------------------------*/
+void destroy_fribidienv(FriBidiEnv* fribidienv)
+{
+ FriBidiMemChunkPrefix* lChunkPtr;
+ FriBidiMemChunkPrefix* lChunkNext;
+
+ VALIDATE_FRIBIDIENV(fribidienv);
+
+ lChunkPtr = fribidienv->iAllocatedMemoryChunks;
+ while (NULL != lChunkPtr) {
+ lChunkNext = (FriBidiMemChunkPrefix*) (lChunkPtr->iNext);
+ free(lChunkPtr);
+ lChunkPtr = lChunkNext;
+ }
+ fribidienv->iAllocatedMemoryChunks = NULL;
+}
+
+
+/*======================================================================
+ * Allocate memory and link it to this FriBidiEnv instance.
+ * This function may throw an Out-Of-Memory exception in
+ * environments, which support exceptions.
+ *----------------------------------------------------------------------*/
+void* fribidi_malloc(FriBidiEnv* fribidienv, size_t size)
+{
+ FriBidiMemChunkPrefix* lChunk_ptr;
+ FriBidiMemChunkPrefix* lNextChunk_ptr;
+
+ VALIDATE_FRIBIDIENV(fribidienv);
+
+ lChunk_ptr = (FriBidiMemChunkPrefix*) malloc(sizeof(FriBidiMemChunkPrefix) + size);
+ if (NULL == lChunk_ptr) {
+ FRIBIDI_OOM_ACTION;
+ }
+
+ /* Before:
+ * fribidienv->iAllocatedMemoryChunks points at lNextChunk_ptr.
+ * if (NULL != lNextChunk_Ptr):
+ * lNextChunk_ptr->iNext points at something.
+ * lNextChunk_ptr->iPrev points back at fribidienv.
+ *
+ * After:
+ * fribidienv->iAllocatedMemoryChunks points at lChunk_ptr.
+ * if (NULL != lNextChunk_Ptr):
+ * lNextChunk_ptr->iNext unchanged.
+ * lNextChunk_ptr->iPrev points at lChunk_ptr.
+ * lChunk_ptr->iNext points at lNextChunk_ptr.
+ * lChunk_ptr->iPrev points back at fribidienv.
+ */
+
+ lNextChunk_ptr = fribidienv->iAllocatedMemoryChunks;
+ fribidienv->iAllocatedMemoryChunks = lChunk_ptr;
+ if (NULL != lNextChunk_ptr) {
+ lNextChunk_ptr->iPrev = lChunk_ptr;
+ }
+ lChunk_ptr->iNext = lNextChunk_ptr;
+ lChunk_ptr->iPrev = (FriBidiMemChunkPrefix*)fribidienv;
+
+ return((void*) (&lChunk_ptr[1]));
+}
+
+/*======================================================================
+ * Unlink the memory chunk pointed at by ptr from this
+ * FriBidiEnv instance and free it.
+ * If the memory chunk is not properly linked, then panic.
+ *----------------------------------------------------------------------*/
+void fribidi_free(FriBidiEnv* fribidienv, void* ptr)
+{
+ FriBidiMemChunkPrefix* lChunk_ptr;
+ FriBidiMemChunkPrefix* lNextChunk_ptr;
+ FriBidiMemChunkPrefix* lPrevChunk_ptr;
+
+ /* VALIDATE_FRIBIDIENV(fribidienv); */
+ /* At normal operation (i.e. not when debugging the memory management
+ * subsystem), fribidienv is not used in this implementation of
+ * fribidi_free().
+ */
+
+ if (NULL == ptr) return;
+
+ lChunk_ptr = (FriBidiMemChunkPrefix*)
+ (((char *)ptr) - sizeof(FriBidiMemChunkPrefix));
+
+ lNextChunk_ptr = (FriBidiMemChunkPrefix*) (lChunk_ptr->iNext);
+ lPrevChunk_ptr = (FriBidiMemChunkPrefix*) (lChunk_ptr->iPrev);
+
+ assert(NULL != lPrevChunk_ptr);
+
+ /* Remove the current memory chunk from the doubly-linked list. */
+ lPrevChunk_ptr->iNext = lNextChunk_ptr;
+ if (NULL != lNextChunk_ptr) {
+ lNextChunk_ptr->iPrev = lPrevChunk_ptr;
+ }
+
+ free(lChunk_ptr);
+}
+
+
+
+
+/*======================================================================
+ * fribidi_mirroring_status() returns whether mirroring is on or off,
+ * default is on.
+ *----------------------------------------------------------------------*/
+boolean fribidi_mirroring_status (FriBidiEnv* fbenv)
+{
+ VALIDATE_FRIBIDIENV(fbenv);
+
+ return(0 != (fbenv->iFlags & FRIBIDIENV_MIRRORING_MODE) ? TRUE : FALSE);
+}
+
+/*======================================================================
+ * fribidi_set_mirroring() sets mirroring on or off.
+ *----------------------------------------------------------------------*/
+void fribidi_set_mirroring (FriBidiEnv* fbenv, boolean mirror)
+{
+ VALIDATE_FRIBIDIENV(fbenv);
+
+ if (FALSE != mirror) {
+ fbenv->iFlags |= FRIBIDIENV_MIRRORING_MODE;
+ }
+ else {
+ fbenv->iFlags &= (~FRIBIDIENV_MIRRORING_MODE);
+ }
+}
+
+/*======================================================================
+ * fribidi_reorder_nsm_status() returns whether reordering of nsm
+ * sequences is on or off, default is off.
+ *----------------------------------------------------------------------*/
+boolean fribidi_reorder_nsm_status (FriBidiEnv* fbenv)
+{
+ VALIDATE_FRIBIDIENV(fbenv);
+
+ return(0 != (fbenv->iFlags & FRIBIDIENV_REORDER_NSM_MODE) ? TRUE : FALSE);
+}
+
+/*======================================================================
+ * fribidi_set_reorder_nsm() sets reordering of nsm sequences on or off.
+ *----------------------------------------------------------------------*/
+void fribidi_set_reorder_nsm (FriBidiEnv* fbenv, boolean reorder)
+{
+ VALIDATE_FRIBIDIENV(fbenv);
+
+ if (FALSE != reorder) {
+ fbenv->iFlags |= FRIBIDIENV_REORDER_NSM_MODE;
+ }
+ else {
+ fbenv->iFlags &= (~FRIBIDIENV_REORDER_NSM_MODE);
+ }
+}
+
+/*======================================================================
+ * fribidi_debug_status() returns whether debugging is on or off,
+ * default is off.
+ *----------------------------------------------------------------------*/
+boolean fribidi_debug_status (FriBidiEnv* fbenv)
+{
+ VALIDATE_FRIBIDIENV(fbenv);
+
+ return(0 != (fbenv->iFlags & FRIBIDIENV_DEBUG_MODE) ? TRUE : FALSE);
+}
+
+/*======================================================================
+ * fribidi_set_debug() turn on or off debugging, default is off.
+ * if the library was compiled without DEBUG option, this function
+ * returns FALSE.
+ *----------------------------------------------------------------------*/
+boolean fribidi_set_debug (FriBidiEnv* fbenv, boolean debug)
+{
+#ifdef DEBUG
+ VALIDATE_FRIBIDIENV(fbenv);
+
+ if (FALSE != debug) {
+ fbenv->iFlags |= FRIBIDIENV_DEBUG_MODE;
+ }
+ else {
+ fbenv->iFlags &= (~FRIBIDIENV_DEBUG_MODE);
+ }
+ return(debug);
+#else /* DEBUG */
+ return(FALSE);
+#endif /* DEBUG */
+}
+
+
+/*======================================================================
+ * For environments with global FriBidiEnv instance.
+ *----------------------------------------------------------------------*/
+#ifdef GLOBAL_FRIBIDIENV
+FriBidiEnv fribidi_global_env = {NULL, FRIBIDIENV_DEFAULT_SETTINGS};
+/* fribidi_global_env needs no explicit initialization. */
+#endif /* GLOBAL_FRIBIDIENV */
+
+
+/* End of fribidi_env.c */
diff --git a/fribidi_env.h b/fribidi_env.h
new file mode 100644
index 0000000..3852af8
--- /dev/null
+++ b/fribidi_env.h
@@ -0,0 +1,270 @@
+/* fribidi_env.h - FriBidi environment management
+ * Copyright (C) 2002 Omer Zak
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library, in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA
+ *
+ * For licensing issues, contact <omerz@actcom.co.il>
+ */
+
+/***********************************************************************
+ * The FriBidiEnv structure encapsulates data about the environment
+ * in which a particular instance of FriBidi runs.
+ *
+ * The structure was introduced to meet the following objectives:
+ * 1. Mechanism for freeing all memory allocated by FriBidi procedures
+ * if a procedure stopped executing in middle due to any reason,
+ * such as memory allocation failure.
+ * This mechanism is necessary for using FriBidi in small-memory
+ * devices, such as devices which run the GEOS and Symbian EPOC 6
+ * operating systems.
+ * 2. Avoidance of modifiable static memory variables, which are
+ * not allowed in Symbian EPOC 6 applications, and which prevent
+ * the FriBidi library from being reentrant in certain operating
+ * systems. The structure also allows FriBidi to be used in
+ * multithreaded environments.
+ * 3. Allow an application to run FriBidi under independent environments,
+ * using different settings in each environment.
+ *
+ * Every FriBidi function requires a pointer to FriBidiEnv as its first
+ * argument.
+ **********************************************************************/
+
+#ifndef FRIBIDI_ENV_H
+#define FRIBIDI_ENV_H
+
+#include "fribidi_mem.h"
+
+/* One of the following must be #defined. */
+#define GLOBAL_FRIBIDIENV
+/* #define VERIFY_NO_GLOBAL_FRIBIDIENV */
+/* #define NO_FRIBIDIENV_VALIDATION */
+
+
+/* Define to be the appropriate action for your environment. */
+#define FRIBIDI_OOM_ACTION return(NULL)
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*======================================================================
+ * Memory Management Structure
+ *----------------------------------------------------------------------*/
+
+/***********************************************************************
+ * The following structure is needed unless fribidi_malloc() and
+ * fribidi_free() are #define'd to be the same as the operating system
+ * provided malloc() and free() procedures.
+ *
+ * Each dynamically-allocated memory chunk is prefixed with two
+ * pointers.
+ * The chunk is added to a doubly-linked list.
+ * When its time to be deleted comes, it is deleted from whatever
+ * position it is in the doubly-linked list.
+ *
+ * The head of the list is in a FriBidiEnv structure instance, and it
+ * is mapped in such a way that fribidi_free() does not have to distinguish
+ * between it and a memory chunk in middle of the doubly-linked list.
+ **********************************************************************/
+
+typedef struct _FriBidiMemChunkPrefix FriBidiMemChunkPrefix;
+
+struct _FriBidiMemChunkPrefix {
+ FriBidiMemChunkPrefix* iNext;
+ /* must be first item in the chunk prefix, so that the
+ * fribidi_free() can handle the list head without checking
+ * for special cases.
+ */
+ FriBidiMemChunkPrefix* iPrev;
+ /* Points at either FriBidiMemChunkPrefix or at
+ * FriBidiEnv.
+ */
+};
+
+
+/*======================================================================
+ * FriBidiEnv Structure Declaration
+ *----------------------------------------------------------------------*/
+
+/* The truth is that uint16 is enough for the number of flags
+ * currently defined.
+ * But we want to keep all FriBidiEnv fields word-aligned.
+ */
+typedef uint32 FriBidiFlags;
+
+/* The following is defined in fribidi_mem.h, must be defined
+ * there due to forward references.
+ */
+/* typedef struct _FriBidiEnv FriBidiEnv; */
+
+struct _FriBidiEnv {
+ FriBidiMemChunkPrefix* iAllocatedMemoryChunks;
+ /* Pointer to doubly-linked list of allocated memory chunks.
+ * Must be the first item in the structure, so that the
+ * fribidi_free() can handle list head without checking for
+ * special cases.
+ */
+ FriBidiFlags iFlags;
+ /* The flags will define:
+ * - Debug mode
+ * - Mirroring
+ * - L3 rule on/off
+ * - remove BiDi marks on/off
+ * - Arabic joining on/off
+ * - Ligaturing on/off
+ * They will be set and cleared by inlined access procedures.
+ */
+
+ /* The following are reserved for future expansion without breaking
+ * binary compatibility of existing software.
+ */
+ uint32 iReserved1;
+ uint32 iReserved2;
+ void* iReserved3; /* If necessary, will point at extension to FriBidiEnv. */
+};
+
+/*======================================================================
+ * Initialize a FriBidiEnv structure. Must be called before any
+ * other use of the structure.
+ *
+ * It initializes the doubly-linked list of memory chunks and the flags.
+ *----------------------------------------------------------------------*/
+void init_fribidienv(FriBidiEnv* fribidienv, FriBidiFlags aFlags);
+
+
+/*======================================================================
+ * Free all memory linked to this FriBidiEnv instance.
+ * After calling this procedure, the instance is legally initialized,
+ * so there is no need for a separate init_fribidienv() call (but it
+ * does not harm).
+ *----------------------------------------------------------------------*/
+void destroy_fribidienv(FriBidiEnv* fribidienv);
+
+
+/*======================================================================
+ * Allocate memory and link it to this FriBidiEnv instance.
+ * This function may throw an Out-Of-Memory exception in
+ * environments, which support exceptions.
+ *----------------------------------------------------------------------*/
+void* fribidi_malloc(FriBidiEnv* fribidienv, size_t size);
+
+
+/*======================================================================
+ * Unlink the memory chunk pointed at by ptr from this
+ * FriBidiEnv instance and free it.
+ * If the memory chunk is not properly linked, then panic.
+ *----------------------------------------------------------------------*/
+void fribidi_free(FriBidiEnv* fribidienv, void* ptr);
+
+
+/*====================================================================*/
+
+/* Flag definitions.
+ *
+ * When initializing a FriBidiEnv instance, OR together the constants
+ * corresponding to the flags which you want to set.
+ */
+#define FRIBIDIENV_DEBUG_MODE 0x0001
+#define FRIBIDIENV_MIRRORING_MODE 0x0002
+#define FRIBIDIENV_REORDER_NSM_MODE 0x0004
+#define FRIBIDIENV_REMOVE_MARKS_MODE 0x0008
+#define FRIBIDIENV_ARABIC_JOINING_MODE 0x0010
+#define FRIBIDIENV_LIGATURING_MODE 0x0020
+
+
+/* Use FRIBIDIENV_DEFAULT_SETTINGS as a shorthand to frequently-used
+ * defaults for the flags.
+ */
+#define FRIBIDIENV_DEFAULT_SETTINGS (FRIBIDIENV_MIRRORING_MODE | 0)
+
+
+/*======================================================================
+ * fribidi_mirroring_status() returns whether mirroring is on or off,
+ * default is on.
+ *----------------------------------------------------------------------*/
+boolean fribidi_mirroring_status (FriBidiEnv* fbenv);
+
+/*======================================================================
+ * fribidi_set_mirroring() sets mirroring on or off.
+ *----------------------------------------------------------------------*/
+void fribidi_set_mirroring (FriBidiEnv* fbenv, boolean mirror);
+
+/*======================================================================
+ * fribidi_reorder_nsm_status() returns whether reordering of nsm
+ * sequences is on or off, default is off.
+ *----------------------------------------------------------------------*/
+boolean fribidi_reorder_nsm_status (FriBidiEnv* fbenv);
+
+/*======================================================================
+ * fribidi_set_reorder_nsm() sets reordering of nsm sequences on or off.
+ *----------------------------------------------------------------------*/
+void fribidi_set_reorder_nsm (FriBidiEnv* fbenv, boolean reorder);
+
+/*======================================================================
+ * fribidi_debug_status() returns whether debugging is on or off,
+ * default is off. Returns false if fribidi is not compiled with debug
+ * enabled.
+ *----------------------------------------------------------------------*/
+boolean fribidi_debug_status (FriBidiEnv* fbenv);
+
+/*======================================================================
+ * fribidi_set_debug() turn on or off debugging, default is off.
+ * if the library was compiled without DEBUG option, this function
+ * returns FALSE.
+ *----------------------------------------------------------------------*/
+boolean fribidi_set_debug (FriBidiEnv* fbenv, boolean debug);
+
+/*======================================================================
+ * Management of various styles of defining and using FriBidiEnv.
+ *----------------------------------------------------------------------*/
+
+/*======================================================================
+ * For environments with global FriBidiEnv instance.
+ *----------------------------------------------------------------------*/
+#ifdef GLOBAL_FRIBIDIENV
+#define VALIDATE_FRIBIDIENV(env) if ((env) == NULL) (env) = &(fribidi_global_env)
+
+extern FriBidiEnv fribidi_global_env;
+#endif /* GLOBAL_FRIBIDIENV */
+
+
+/*======================================================================
+ * For environments with disallow global variables.
+ *----------------------------------------------------------------------*/
+#ifdef VERIFY_NO_GLOBAL_FRIBIDIENV
+#define VALIDATE_FRIBIDIENV(env) if ((env) == NULL) Panic()
+#endif /* VERIFY_NO_GLOBAL_FRIBIDIENV */
+
+
+/*======================================================================
+ * For environments which need speed/code size optimization.
+ *----------------------------------------------------------------------*/
+#ifdef NO_FRIBIDIENV_VALIDATION
+#define VALIDATE_FRIBIDIENV(env)
+ /* Null definition, for environments, which guarantee valid
+ ** environments, and need the efficiency.
+ */
+#endif /* NO_FRIBIDIENV_VALIDATION */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FRIBIDI_ENV_H */
+
+/* End of fribidi_env.h */
diff --git a/fribidi_main.c b/fribidi_main.c
index 430adf8..a2857e0 100644
--- a/fribidi_main.c
+++ b/fribidi_main.c
@@ -46,7 +46,7 @@ extern char *fribidi_version_info;
#define MAX_STR_LEN 65000
-#define ALLOCATE(tp,ln) ((tp *) malloc (sizeof (tp) * (ln)))
+#define ALLOCATE(frenv, tp,ln) ((tp *) fribidi_malloc (frenv, sizeof (tp) * (ln)))
static void
die (char *fmt, ...)
{
@@ -271,7 +271,7 @@ main (int argc, char *argv[])
eol_text = optarg;
break;
case 'd':
- if (!fribidi_set_debug (TRUE))
+ if (!fribidi_set_debug (NULL, TRUE))
die
("%s lib must be compiled with DEBUG option to enable\nturn debug info on.\n",
FRIBIDI_PACKAGE);
@@ -327,8 +327,8 @@ main (int argc, char *argv[])
#endif
die ("unrecognized character set `%s'\n", char_set);
- fribidi_set_mirroring (do_mirror);
- fribidi_set_reorder_nsm (do_reorder_nsm);
+ fribidi_set_mirroring (NULL, do_mirror);
+ fribidi_set_reorder_nsm (NULL, do_reorder_nsm);
exit_val = 0;
file_found = FALSE;
while (optind < argc || !file_found)
@@ -403,14 +403,14 @@ main (int argc, char *argv[])
FriBidiStrIndex new_len;
boolean log2vis;
- visual = show_visual ? ALLOCATE (FriBidiChar, len + 1) : NULL;
- ltov = show_ltov ? ALLOCATE (FriBidiStrIndex, len + 1) : NULL;
- vtol = show_vtol ? ALLOCATE (FriBidiStrIndex, len + 1) : NULL;
- levels = show_levels ? ALLOCATE (FriBidiLevel, len + 1) : NULL;
+ visual = show_visual ? ALLOCATE (NULL, FriBidiChar, len + 1) : NULL;
+ ltov = show_ltov ? ALLOCATE (NULL, FriBidiStrIndex, len + 1) : NULL;
+ vtol = show_vtol ? ALLOCATE (NULL, FriBidiStrIndex, len + 1) : NULL;
+ levels = show_levels ? ALLOCATE (NULL, FriBidiLevel, len + 1) : NULL;
/* Create a bidi string. */
base = input_base_direction;
- log2vis = fribidi_log2vis (logical, len, &base,
+ log2vis = fribidi_log2vis (NULL, logical, len, &base,
/* output */
visual, ltov, vtol, levels);
if (log2vis)
@@ -424,7 +424,7 @@ main (int argc, char *argv[])
/* Remove explicit marks, if asked for. */
if (do_clean)
len =
- fribidi_remove_bidi_marks (visual, len, ltov, vtol,
+ fribidi_remove_bidi_marks (NULL, visual, len, ltov, vtol,
levels);
if (show_visual)
@@ -532,7 +532,7 @@ main (int argc, char *argv[])
if (show_changes)
{
FriBidiStrIndex change_start, change_len;
- fribidi_find_string_changes (logical, len,
+ fribidi_find_string_changes (NULL, logical, len,
visual, new_len,
&change_start,
&change_len);
@@ -547,13 +547,13 @@ main (int argc, char *argv[])
}
if (show_visual)
- free (visual);
+ fribidi_free (NULL, visual);
if (show_ltov)
- free (ltov);
+ fribidi_free (NULL, ltov);
if (show_vtol)
- free (vtol);
+ fribidi_free (NULL, vtol);
if (show_levels)
- free (levels);
+ fribidi_free (NULL, levels);
}
if (*nl_found)
diff --git a/fribidi_mem.c b/fribidi_mem.c
index 3034a31..26ce370 100644
--- a/fribidi_mem.c
+++ b/fribidi_mem.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <ctype.h>
+#include "fribidi_env.h"
#include "fribidi_mem.h"
struct _FriBidiMemChunk
@@ -35,11 +36,11 @@ struct _FriBidiMemChunk
};
FriBidiList *
-fribidi_list_append (FriBidiList *list, void *data)
+fribidi_list_append (FriBidiEnv* fribidienv, FriBidiList *list, void *data)
{
FriBidiList *node, *last;
- node = malloc (sizeof (FriBidiList));
+ node = fribidi_malloc (fribidienv, sizeof (FriBidiList));
node->data = data;
node->next = NULL;
node->prev = NULL;
@@ -54,10 +55,11 @@ fribidi_list_append (FriBidiList *list, void *data)
}
FriBidiMemChunk *
-fribidi_mem_chunk_new (char *name, int atom_size, unsigned long area_size,
+fribidi_mem_chunk_new (FriBidiEnv* fribidienv,
+ char *name, int atom_size, unsigned long area_size,
int type)
{
- FriBidiMemChunk *m = (FriBidiMemChunk *) malloc (sizeof (FriBidiMemChunk));
+ FriBidiMemChunk *m = (FriBidiMemChunk *) fribidi_malloc (fribidienv, sizeof (FriBidiMemChunk));
m->name = name;
m->atom_size = atom_size;
@@ -71,14 +73,15 @@ fribidi_mem_chunk_new (char *name, int atom_size, unsigned long area_size,
}
void
-fribidi_mem_chunk_destroy (FriBidiMemChunk *mem_chunk)
+fribidi_mem_chunk_destroy (FriBidiEnv* fribidienv,
+ FriBidiMemChunk *mem_chunk)
{
- free (mem_chunk);
+ fribidi_free (fribidienv,mem_chunk);
return;
}
void *
-fribidi_mem_chunk_alloc (FriBidiMemChunk *mem_chunk)
+fribidi_mem_chunk_alloc (FriBidiEnv* fribidienv, FriBidiMemChunk *mem_chunk)
{
void *m;
@@ -86,7 +89,7 @@ fribidi_mem_chunk_alloc (FriBidiMemChunk *mem_chunk)
{
if (mem_chunk->empty_size < mem_chunk->atom_size)
{
- mem_chunk->chunk = malloc (mem_chunk->area_size);
+ mem_chunk->chunk = fribidi_malloc (fribidienv, mem_chunk->area_size);
mem_chunk->empty_size = mem_chunk->area_size;
}
m = mem_chunk->chunk;
@@ -95,15 +98,16 @@ fribidi_mem_chunk_alloc (FriBidiMemChunk *mem_chunk)
mem_chunk->empty_size -= mem_chunk->atom_size;
}
else
- m = (void *) malloc (mem_chunk->atom_size);
+ m = (void *) fribidi_malloc (fribidienv, mem_chunk->atom_size);
return m;
}
void
-fribidi_mem_chunk_free (FriBidiMemChunk *mem_chunk, void *mem)
+fribidi_mem_chunk_free (FriBidiEnv* fribidienv,
+ FriBidiMemChunk *mem_chunk, void *mem)
{
if (mem_chunk->type == FRIBIDI_ALLOC_AND_FREE)
- free (mem);
+ fribidi_free (fribidienv, mem);
return;
}
diff --git a/fribidi_mem.h b/fribidi_mem.h
index ba0ab5f..dd90511 100644
--- a/fribidi_mem.h
+++ b/fribidi_mem.h
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include "fribidi_config.h"
+/* #include "fribidi_env.h" */
#ifdef __cplusplus
extern "C"
@@ -55,29 +56,38 @@ extern "C"
FriBidiList *prev;
};
- FriBidiList *fribidi_list_append (FriBidiList *list, void *data);
+ typedef struct _FriBidiEnv FriBidiEnv;
+
+ FriBidiList *fribidi_list_append (FriBidiEnv* fribidienv,
+ FriBidiList *list, void *data);
typedef struct _FriBidiMemChunk FriBidiMemChunk;
#define FRIBIDI_ALLOC_ONLY 1
#define FRIBIDI_ALLOC_AND_FREE 2
- FriBidiMemChunk *fribidi_mem_chunk_new (char *name,
+ FriBidiMemChunk *fribidi_mem_chunk_new (FriBidiEnv* fribidienv,
+ char *name,
int atom_size,
unsigned long area_size, int type);
- void fribidi_mem_chunk_destroy (FriBidiMemChunk *mem_chunk);
- void *fribidi_mem_chunk_alloc (FriBidiMemChunk *mem_chunk);
- void *fribidi_mem_chunk_alloc0 (FriBidiMemChunk *mem_chunk);
- void fribidi_mem_chunk_free (FriBidiMemChunk *mem_chunk, void *mem);
-
-#define fribidi_mem_chunk_create(type, pre_alloc, alloc_type) ( \
- fribidi_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
+ void fribidi_mem_chunk_destroy (FriBidiEnv* fribidienv,
+ FriBidiMemChunk *mem_chunk);
+ void *fribidi_mem_chunk_alloc (FriBidiEnv* fribidienv,
+ FriBidiMemChunk *mem_chunk);
+ void *fribidi_mem_chunk_alloc0 (FriBidiEnv* fribidienv,
+ FriBidiMemChunk *mem_chunk);
+ void fribidi_mem_chunk_free (FriBidiEnv* fribidienv,
+ FriBidiMemChunk *mem_chunk, void *mem);
+
+#define fribidi_mem_chunk_create(fbenv, type, pre_alloc, alloc_type) ( \
+ fribidi_mem_chunk_new (fbenv, \
+ #type " mem chunks (" #pre_alloc ")", \
sizeof (type), \
sizeof (type) * (pre_alloc), \
(alloc_type)) \
)
-#define fribidi_chunk_new(type, chunk) ( \
- (type *) fribidi_mem_chunk_alloc (chunk) \
+#define fribidi_chunk_new(fbenv, type, chunk) ( \
+ (type *) fribidi_mem_chunk_alloc (fbenv, chunk) \
)
int fribidi_strcasecmp (const char *s1, const char *s2);
diff --git a/fribidi_mirroring.c b/fribidi_mirroring.c
index 8f28134..27b7b7c 100644
--- a/fribidi_mirroring.c
+++ b/fribidi_mirroring.c
@@ -30,7 +30,8 @@
#include "fribidi_tab_mirroring.i"
boolean
-fribidi_get_mirror_char ( /* Input */
+fribidi_get_mirror_char ( FriBidiEnv* fribidienv,
+ /* Input */
FriBidiChar ch,
/* Output */
FriBidiChar *mirrored_ch)
diff --git a/fribidi_tab_char_type_2.i b/fribidi_tab_char_type_2.i
index 7120f99..eda58c4 100644
--- a/fribidi_tab_char_type_2.i
+++ b/fribidi_tab_char_type_2.i
@@ -3198,10 +3198,10 @@ static const FriBidiPropCharType *FriBidiPropertyBlockLevel0[2176*1] = {
#undef RTL
#undef LTR
/*======================================================================
- * fribidi_get_type() returns the bidi type of a character.
+ * fribidi_get_type_internal() returns the bidi type of a character.
*----------------------------------------------------------------------*/
FriBidiCharType
-fribidi_get_type (FriBidiChar uch)
+fribidi_get_type_internal (FriBidiChar uch)
{
if (uch < 0x110000)
return fribidi_prop_to_type[(unsigned char)FRIBIDI_GET_TYPE (uch)];
diff --git a/fribidi_tab_char_type_9.i b/fribidi_tab_char_type_9.i
index 63e1d2f..0e24c8c 100644
--- a/fribidi_tab_char_type_9.i
+++ b/fribidi_tab_char_type_9.i
@@ -2397,10 +2397,10 @@ static const FriBidiPropCharType ********FriBidiPropertyBlockLevel0[17*1] = {
#undef RTL
#undef LTR
/*======================================================================
- * fribidi_get_type() returns the bidi type of a character.
+ * fribidi_get_type_internal() returns the bidi type of a character.
*----------------------------------------------------------------------*/
FriBidiCharType
-fribidi_get_type (FriBidiChar uch)
+fribidi_get_type_internal (FriBidiChar uch)
{
if (uch < 0x110000)
return fribidi_prop_to_type[(unsigned char)FRIBIDI_GET_TYPE (uch)];
diff --git a/fribidi_tab_mirroring.i b/fribidi_tab_mirroring.i
index 52b9620..465b47e 100644
--- a/fribidi_tab_mirroring.i
+++ b/fribidi_tab_mirroring.i
@@ -174,7 +174,7 @@ FriBidiMirroredChars[] =
/* *INDENT-ON* */
-int nFriBidiMirroredChars = 140;
+const int nFriBidiMirroredChars = 140;
#endif /* FRIBIDI_TAB_MIRRORING_I */
diff --git a/fribidi_types.h b/fribidi_types.h
index 61fef35..f7b6b42 100644
--- a/fribidi_types.h
+++ b/fribidi_types.h
@@ -196,7 +196,7 @@ extern "C"
/* Return the minimum level of the direction, 0 for FRIBIDI_TYPE_LTR and
1 for FRIBIDI_TYPE_RTL and FRIBIDI_TYPE_AL. */
-#define FRIBIDI_DIR_TO_LEVEL(dir) (dir & 1)
+#define FRIBIDI_DIR_TO_LEVEL(dir) ((FriBidiLevel)(dir & 1))
/* Is right to left? */
#define FRIBIDI_IS_RTL(p) ((p) & FRIBIDI_MASK_RTL)
diff --git a/fribidi_utils.c b/fribidi_utils.c
index cc98708..d2d0f54 100644
--- a/fribidi_utils.c
+++ b/fribidi_utils.c
@@ -61,10 +61,12 @@
* &num_vis_ranges, *vis_ranges);
**----------------------------------------------------------------------*/
void
-fribidi_map_range (FriBidiStrIndex in_span[2], /* Start and end span */
+fribidi_map_range (FriBidiEnv* fribidienv,
+ /* input */
+ FriBidiStrIndex in_span[2], /* Start and end span */
FriBidiStrIndex len, boolean is_v2l_map, /* Needed for embedding_level */
- FriBidiStrIndex *position_map,
- FriBidiLevel *embedding_level_list,
+ const FriBidiStrIndex *position_map,
+ const FriBidiLevel *embedding_level_list,
/* output */
int *num_mapped_spans, FriBidiStrIndex mapped_spans[63][2])
{
@@ -111,9 +113,11 @@ fribidi_map_range (FriBidiStrIndex in_span[2], /* Start and end span */
* length of the section in the new string that needs redrawing.
*----------------------------------------------------------------------*/
void
-fribidi_find_string_changes ( /* input */
- FriBidiChar *old_str,
- FriBidiStrIndex old_len, FriBidiChar *new_str,
+fribidi_find_string_changes ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiChar *old_str,
+ FriBidiStrIndex old_len,
+ const FriBidiChar *new_str,
FriBidiStrIndex new_len,
/* output */
FriBidiStrIndex *change_start,
@@ -189,10 +193,13 @@ fribidi_find_string_changes ( /* input */
*
*----------------------------------------------------------------------*/
void
-fribidi_xpos_resolve (int x_pos, int x_offset, FriBidiStrIndex len,
- FriBidiLevel *embedding_level_list,
+fribidi_xpos_resolve (FriBidiEnv* fribidienv,
+ /* input */
+ int x_pos, int x_offset, FriBidiStrIndex len,
+ const FriBidiLevel *embedding_level_list,
FriBidiCharType base_dir,
- FriBidiStrIndex *vis2log, int *char_widths,
+ const FriBidiStrIndex *vis2log,
+ const int *char_widths,
/* output */
FriBidiStrIndex *res_log_pos,
FriBidiStrIndex *res_vis_pos,
@@ -231,7 +238,8 @@ fribidi_xpos_resolve (int x_pos, int x_offset, FriBidiStrIndex len,
{
/* Found position */
*res_cursor_dir_is_rtl =
- fribidi_is_char_rtl (embedding_level_list, base_dir, log_pos);
+ fribidi_is_char_rtl (fribidienv,
+ embedding_level_list, base_dir, log_pos);
/* Are we in the left hand side of the clicked character? */
if (x_pos - (x_offset + char_width_sum + char_width / 2) < 0)
{
@@ -295,7 +303,8 @@ fribidi_xpos_resolve (int x_pos, int x_offset, FriBidiStrIndex len,
* if the embedding level for the character is odd.
*----------------------------------------------------------------------*/
boolean
-fribidi_is_char_rtl (FriBidiLevel *embedding_level_list,
+fribidi_is_char_rtl (FriBidiEnv* fribidienv,
+ const FriBidiLevel *embedding_level_list,
FriBidiCharType base_dir, FriBidiStrIndex idx)
{
if (!embedding_level_list || idx < 0)
@@ -311,16 +320,20 @@ fribidi_is_char_rtl (FriBidiLevel *embedding_level_list,
* the same attributes.
*----------------------------------------------------------------------*/
void
-fribidi_runs_log2vis ( /* input */
- FriBidiList *logical_runs, /* List of FriBidiRunType */
- FriBidiStrIndex len, FriBidiStrIndex *log2vis, FriBidiCharType base_dir, /* TBD: remove it, not needed */
+fribidi_runs_log2vis ( FriBidiEnv* fribidienv,
+ /* input */
+ const FriBidiList *logical_runs, /* List of FriBidiRunType */
+ FriBidiStrIndex len,
+ const FriBidiStrIndex *log2vis,
+ FriBidiCharType base_dir, /* TBD: remove it, not needed */
/* output */
FriBidiList **visual_runs)
{
- void **visual_attribs = (void **) malloc (sizeof (void *) * len);
+ void **visual_attribs = (void **) fribidi_malloc (fribidienv, sizeof (void *) * len);
void *current_attrib;
FriBidiStrIndex pos, i;
- FriBidiList *list, *last;
+ const FriBidiList *list;
+ FriBidiList *last;
FriBidiStrIndex current_idx;
@@ -349,17 +362,18 @@ fribidi_runs_log2vis ( /* input */
if (i == len || current_attrib != visual_attribs[i])
{
FriBidiRunType *run =
- (FriBidiRunType *) malloc (sizeof (FriBidiRunType));
+ (FriBidiRunType *) fribidi_malloc (fribidienv, sizeof (FriBidiRunType));
run->length = i - current_idx;
run->attribute = current_attrib;
/* Keeping track of the last node is crucial for efficiency
for long lists... */
if (last == NULL)
- last = *visual_runs = fribidi_list_append (NULL, run);
+ last = *visual_runs = fribidi_list_append (fribidienv,
+ NULL, run);
else
{
- fribidi_list_append (last, run);
+ fribidi_list_append (fribidienv, last, run);
last = last->next;
}
if (i == len)
@@ -369,5 +383,5 @@ fribidi_runs_log2vis ( /* input */
current_idx = i;
}
}
- free (visual_attribs);
+ fribidi_free (fribidienv, visual_attribs);
}
diff --git a/packtab.c b/packtab.c
index 76c6abc..95c3555 100644
--- a/packtab.c
+++ b/packtab.c
@@ -336,3 +336,5 @@ pack_table (int *base, int key_num, int key_size, int ptr_size,
free (tab);
return 1;
}
+
+/* End of packtab.c */