bidi-type-table.i \
common.h \
debug.h \
+ env.h \
fribidi.c \
fribidi-bidi.c \
fribidi-bidi-type.c \
fribidi-env.c \
fribidi-mem.c \
fribidi-mirroring.c \
+ fribidi-run.c \
mem.h \
- mirroring-table.i
+ mirroring-table.i \
+ run.h
BUILT_SOURCES= \
bidi-type-table.i \
/* FriBidi
* bidi-types.h - define internal bidi types
*
- * $Id: bidi-types.h,v 1.1 2004-04-25 18:47:57 behdad Exp $
+ * $Id: bidi-types.h,v 1.2 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:47:57 $
- * $Revision: 1.1 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.2 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/bidi-types.h,v $
*
* Author:
#include <fribidi-begindecls.h>
+#define FRIBIDI_LEVEL_REMOVED -3
+#define FRIBIDI_LEVEL_START -2
+#define FRIBIDI_LEVEL_END -1
+
/*
* Define character types that char_type_tables use.
* define them to be 0, 1, 2, ... and then in fribidi_get_type.c map them
#if DEBUG
-#define fribidi_char_from_bidi_type FRIBIDI_NAMESPACE(char_from_bidi_type)
+#define fribidi_char_from_bidi_type FRIBIDI_PRIVATESPACE(char_from_bidi_type)
FRIBIDI_ENTRY char fribidi_char_from_bidi_type (
FriBidiCharType t /* input bidi type */
);
/* FriBidi
* common.h - common include for library sources
*
- * $Id: common.h,v 1.3 2004-04-27 23:53:43 behdad Exp $
+ * $Id: common.h,v 1.4 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-27 23:53:43 $
- * $Revision: 1.3 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.4 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/common.h,v $
*
* Author:
#include <fribidi-common.h>
+/* FRIBIDI_PRIVATESPACE is a macro used to name library internal symbols. */
+#ifndef FRIBIDI_PRIVATESPACE
+# define FRIBIDI_PRIVATESPACE(SYMBOL) FRIBIDI_NAMESPACE(SYMBOL##__internal__)
+#endif /* !FRIBIDI_PRIVATESPACE */
+
#if WIN32
# define FRIBIDI_ENTRY __declspec(dllexport)
#endif /* WIN32 */
-#ifndef FALSE
-# define FALSE (0==1)
-#endif /* !FALSE */
+#ifndef false
+# define false (0==1)
+#endif /* !false */
-#ifndef TRUE
-# define TRUE (!FALSE)
-#endif /* !TRUE */
+#ifndef true
+# define true (!false)
+#endif /* !true */
#ifndef NULL
# define NULL (void *) 0
--- /dev/null
+/* FriBidi
+ * env.h - private state variables
+ *
+ * $Id: env.h,v 1.1 2004-04-28 02:37:56 behdad Exp $
+ * $Author: behdad $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.1 $
+ * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/Attic/env.h,v $
+ *
+ * Author:
+ * Behdad Esfahbod, 2001, 2002, 2004
+ * Dov Grobgeld, 1999, 2000
+ *
+ * Copyright (C) 2004 Sharif FarsiWeb, Inc
+ * Copyright (C) 2001,2002 Behdad Esfahbod
+ * Copyright (C) 1999,2000 Dov Grobgeld
+ *
+ * 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 <license@farsiweb.info>.
+ */
+#ifndef _ENV_H
+#define _ENV_H
+
+#include <fribidi-common.h>
+
+#include <fribidi-bidi-types.h>
+
+#include "mem.h"
+
+#include "common.h"
+
+#include <fribidi-begindecls.h>
+
+#if !USE_SIMPLE_MALLOC
+
+#define free_runs FRIBIDI_PRIVATESPACE(free_runs)
+extern FriBidiRun *free_runs;
+
+#define run_mem_chunk FRIBIDI_PRIVATESPACE(run_mem_chunk)
+extern FriBidiMemChunk *run_mem_chunk;
+
+#endif /* !USE_SIMPLE_MALLOC */
+
+#include "fribidi-enddecls.h"
+
+#endif /* !_ENV_H */
+/* Editor directions:
+ * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
+ */
/* FriBidi
- * fribidi-char-type.c - get character bidi type
+ * fribidi-bidi-type.c - get character bidi type
*
- * $Id: fribidi-bidi-type.c,v 1.1 2004-04-25 18:47:57 behdad Exp $
+ * $Id: fribidi-bidi-type.c,v 1.2 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:47:57 $
- * $Revision: 1.1 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.2 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/Attic/fribidi-bidi-type.c,v $
*
* Authors:
/* FriBidi
* fribidi-bidi-types.c - character bidi types
*
- * $Id: fribidi-bidi-types.c,v 1.1 2004-04-25 18:47:57 behdad Exp $
+ * $Id: fribidi-bidi-types.c,v 1.2 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:47:57 $
- * $Revision: 1.1 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.2 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types.c,v $
*
* Authors:
#include <fribidi-bidi-types.h>
+#include "bidi-types.h"
+
#include "common.h"
#ifdef DEBUG
/* FriBidi
* fribidi-bidi-types.h - character bidi types
*
- * $Id: fribidi-bidi-types.h,v 1.1 2004-04-25 18:47:57 behdad Exp $
+ * $Id: fribidi-bidi-types.h,v 1.2 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:47:57 $
- * $Revision: 1.1 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.2 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi-types.h,v $
*
* Author:
typedef signed char FriBidiLevel;
+typedef struct _FriBidiRun FriBidiRun;
+
typedef fribidi_uint32 FriBidiMaskType;
typedef FriBidiMaskType FriBidiCharType;
/* FriBidi
* fribidi-bidi.c - bidirectional algorithm
*
- * $Id: fribidi-bidi.c,v 1.3 2004-04-25 19:12:42 behdad Exp $
+ * $Id: fribidi-bidi.c,v 1.4 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 19:12:42 $
- * $Revision: 1.3 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.4 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-bidi.c,v $
*
* Authors:
#include <fribidi-env.h>
#include "mem.h"
+#include "env.h"
#include "bidi-types.h"
+#include "run.h"
#include "common.h"
#undef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
-/*======================================================================
- * Typedef for the run-length list.
- *----------------------------------------------------------------------*/
-typedef struct _TypeLink TypeLink;
-
-struct _TypeLink
-{
- TypeLink *prev;
- TypeLink *next;
-
- FriBidiCharType type;
- FriBidiStrIndex pos, len;
- FriBidiLevel level;
-};
-
-#define FRIBIDI_LEVEL_REMOVED -3
-#define FRIBIDI_LEVEL_START -2
-#define FRIBIDI_LEVEL_END -1
-
typedef struct
{
FriBidiCharType override; /* only LTR, RTL and ON are valid */
}
}
-#if !USE_SIMPLE_MALLOC
-static TypeLink *free_type_links = NULL;
-#endif /* !USE_SIMPLE_MALLOC */
-
-static TypeLink *
-new_type_link (
- void
-)
-{
- TypeLink *link;
-
-#if USE_SIMPLE_MALLOC
- link = fribidi_malloc (sizeof (TypeLink));
-#else /* !USE_SIMPLE_MALLOC */
- if (free_type_links)
- {
- link = free_type_links;
- free_type_links = free_type_links->next;
- }
- else
- {
- static FriBidiMemChunk *mem_chunk = NULL;
-
- if (!mem_chunk)
- mem_chunk = fribidi_chunk_new_for_type (TypeLink
- );
-
- link = fribidi_chunk_new (TypeLink,
- mem_chunk
- );
- }
-#endif /* !USE_SIMPLE_MALLOC */
-
- link->len = 0;
- link->pos = 0;
- link->level = 0;
- link->next = NULL;
- link->prev = NULL;
- return link;
-}
-
-static void
-free_type_link (
- TypeLink *link
-)
-{
-#if USE_SIMPLE_MALLOC
- fribidi_free (link);
-#else /* !USE_SIMPLE_MALLOC */
- link->next = free_type_links;
- free_type_links = link;
-#endif /* !USE_SIMPLE_MALLOC */
-}
-
-#define FRIBIDI_ADD_TYPE_LINK(p,q) \
- FRIBIDI_BEGIN_STMT \
- (p)->len = (q)->pos - (p)->pos; \
- (p)->next = (q); \
- (q)->prev = (p); \
- (p) = (q); \
- FRIBIDI_END_STMT
-
-static TypeLink *
-run_length_encode_types (
- FriBidiCharType *char_type,
- FriBidiStrIndex type_len
-)
-{
- TypeLink *list, *last, *link;
-
- FriBidiStrIndex i;
-
- /* Add the starting link */
- list = new_type_link ();
- list->type = FRIBIDI_TYPE_SOT;
- list->level = FRIBIDI_LEVEL_START;
- last = list;
-
- /* Sweep over the string_type s */
- for (i = 0; i < type_len; i++)
- if (char_type[i] != last->type)
- {
- link = new_type_link ();
- link->type = char_type[i];
- link->pos = i;
- FRIBIDI_ADD_TYPE_LINK (last, link);
- }
-
- /* Add the ending link */
- link = new_type_link ();
- link->type = FRIBIDI_TYPE_EOT;
- link->level = FRIBIDI_LEVEL_END;
- link->pos = type_len;
- FRIBIDI_ADD_TYPE_LINK (last, link);
-
- return list;
-}
-
/* explicits_list is a list like type_rl_list, that holds the explicit
codes that are removed from rl_list, to reinsert them later by calling
the override_list.
*/
static void
init_list (
- TypeLink **start,
- TypeLink **end
+ FriBidiRun ** start,
+ FriBidiRun ** end
)
{
- TypeLink *list;
- TypeLink *link;
+ FriBidiRun *list;
+ FriBidiRun *link;
/* Add the starting link */
- list = new_type_link ();
+ list = new_run ();
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_run ();
link->type = FRIBIDI_TYPE_EOT;
link->level = FRIBIDI_LEVEL_END;
link->len = 0;
*end = link;
}
-/* move an element before another element in a list, the list must have a
- previous element, used to update explicits_list.
- assuming that p have both prev and next or none of them, also update
- the list that p is currently in, if any.
-*/
-static void
-move_element_before (
- TypeLink *p,
- TypeLink *list
-)
-{
- if (p->prev)
- {
- p->prev->next = p->next;
- p->next->prev = p->prev;
- }
- p->prev = list->prev;
- list->prev->next = p;
- p->next = list;
- list->prev = p;
-}
-
-/* override the rl_list 'base', with the elements in the list 'over', to
- reinsert the previously-removed explicit codes (at X9) from
- 'explicits_list' back into 'type_rl_list'. This is used at the end of I2
- to restore the explicit marks, and also to reset the character types of
- characters at L1.
-
- it is assumed that the 'pos' of the first element in 'base' list is not
- more than the 'pos' of the first element of the 'over' list, and the
- 'pos' of the last element of the 'base' list is not less than the 'pos'
- of the last element of the 'over' list. these two conditions are always
- satisfied for the two usages mentioned above.
-
- TBD: use some explanatory names instead of p, q, ...
-*/
-static void
-override_list (
- TypeLink *base,
- TypeLink *over
-)
-{
- TypeLink *p = base, *q, *r, *s, *t;
- FriBidiStrIndex pos = 0, pos2;
-
- if (!over)
- return;
- q = over;
- while (q)
- {
- if (!q->len || q->pos < pos)
- {
- t = q;
- q = q->next;
- free_type_link (t);
- continue;
- }
- pos = q->pos;
- while (p->next && p->next->pos <= pos)
- p = p->next;
- /* now p is the element that q must be inserted 'in'. */
- pos2 = pos + q->len;
- r = p;
- while (r->next && r->next->pos < pos2)
- r = r->next;
- /* now r is the last element that q affects. */
- if (p == r)
- {
- /* split p into at most 3 interval, and insert q in the place of
- the second interval, set r to be the third part. */
- /* third part needed? */
- if (p->next && p->next->pos == pos2)
- r = r->next;
- else
- {
- r = new_type_link ();
- *r = *p;
- if (r->next)
- {
- r->next->prev = r;
- r->len = r->next->pos - pos2;
- }
- else
- r->len -= pos - p->pos;
- r->pos = pos2;
- }
- /* first part needed? */
- if (p->prev && p->pos == pos)
- {
- t = p;
- p = p->prev;
- free_type_link (t);
- }
- else
- p->len = pos - p->pos;
- }
- else
- {
- /* cut the end of p. */
- p->len = pos - p->pos;
- /* if all of p is cut, remove it. */
- if (!p->len && p->prev)
- p = p->prev;
-
- /* cut the begining of r. */
- r->pos = pos2;
- if (r->next)
- r->len = r->next->pos - pos2;
- /* if all of r is cut, remove it. */
- if (!r->len && r->next)
- r = r->next;
-
- /* remove the elements between p and r. */
- for (s = p->next; s != r;)
- {
- t = s;
- s = s->next;
- free_type_link (t);
- }
- }
- /* before updating the next and prev links to point to the inserted q,
- we must remember the next element of q in the 'over' list.
- */
- t = q;
- q = q->next;
- p->next = t;
- t->prev = p;
- t->next = r;
- r->prev = t;
- }
-}
-
/* Some convenience macros */
#define RL_TYPE(list) ((list)->type)
#define RL_LEN(list) ((list)->len)
#define RL_POS(list) ((list)->pos)
#define RL_LEVEL(list) ((list)->level)
-static TypeLink *
+static FriBidiRun *
merge_with_prev (
- TypeLink *second
+ FriBidiRun * second
)
{
- TypeLink *first = second->prev;
+ FriBidiRun *first = second->prev;
first->next = second->next;
first->next->prev = first;
RL_LEN (first) += RL_LEN (second);
- free_type_link (second);
+ free_run (second);
return first;
}
static void
compact_list (
- TypeLink *list
+ FriBidiRun * list
)
{
if (list->next)
static void
compact_neutrals (
- TypeLink *list
+ FriBidiRun * list
)
{
if (list->next)
static void
print_types_re (
- TypeLink *pp
+ FriBidiRun * pp
)
{
MSG (" Run types : ");
static void
print_resolved_levels (
- TypeLink *pp
+ FriBidiRun * pp
)
{
MSG (" Res. levels: ");
static void
print_resolved_types (
- TypeLink *pp
+ FriBidiRun * pp
)
{
MSG (" Res. types : ");
/* input and output */
FriBidiCharType *pbase_dir,
/* output */
- TypeLink **ptype_rl_list,
+ FriBidiRun ** ptype_rl_list,
FriBidiLevel *pmax_level
)
{
FriBidiLevel base_level, max_level;
FriBidiCharType base_dir;
FriBidiStrIndex i;
- TypeLink *type_rl_list, *explicits_list, *explicits_list_end, *pp;
+ FriBidiRun *type_rl_list, *explicits_list, *explicits_list_end, *pp;
DBG ("Entering fribidi_analyse_string");
char_type[i] = fribidi_get_type (str[i]);
/* Run length encode the character types */
- type_rl_list = run_length_encode_types (char_type, len);
+ type_rl_list = run_list_encode_bidi_types (char_type, len);
fribidi_free (char_type);
}
DBG (" Determine character types, Done");
FriBidiStrIndex i;
int stack_size, over_pushed, first_interval;
LevelInfo *status_stack;
- TypeLink temp_link;
+ FriBidiRun temp_link;
level = base_level;
override = FRIBIDI_TYPE_ON;
/* Remove element and add it to explicits_list */
temp_link.next = pp->next;
pp->level = FRIBIDI_LEVEL_REMOVED;
- move_element_before (pp, explicits_list_end);
+ move_run_before (pp, explicits_list_end);
pp = &temp_link;
}
else
/* Implementation note: it is important that if the previous character
is not sor, then we should merge this run with the previous,
because of rules like W5, that we assume all of a sequence of
- adjacent ETs are in one TypeLink. */
+ adjacent ETs are in one FriBidiRun. */
if (this_type == FRIBIDI_TYPE_NSM)
{
if (RL_LEVEL (pp->prev) == RL_LEVEL (pp))
/* Resolving dependency of loops for rules W4 and W5, W5 may
want to prevent W4 to take effect in the next turn, do this
through "w4". */
- w4 = TRUE;
+ w4 = true;
/* Resolving dependency of loops for rules W4 and W5 with W7,
W7 may change an EN to L but it sets the prev_type_org if needed,
so W4 and W5 in next turn can still do their works. */
if (this_type == FRIBIDI_TYPE_AL)
{
RL_TYPE (pp) = FRIBIDI_TYPE_RTL;
- w4 = TRUE;
+ w4 = true;
prev_type_org = FRIBIDI_TYPE_ON;
continue;
}
RL_TYPE (pp) = prev_type;
this_type = RL_TYPE (pp);
}
- w4 = TRUE;
+ w4 = true;
/* W5. A sequence of European terminators adjacent to European
numbers changes to All European numbers. */
|| next_type == FRIBIDI_TYPE_EN))
{
RL_TYPE (pp) = FRIBIDI_TYPE_EN;
- w4 = FALSE;
+ w4 = false;
this_type = RL_TYPE (pp);
}
explicits_list to type_rl_list. */
DBG ("Reinserting explicit codes");
{
- TypeLink *p;
+ FriBidiRun *p;
- override_list (type_rl_list, explicits_list);
+ shadow_run_list (type_rl_list, explicits_list);
p = type_rl_list->next;
if (p->level < 0)
p->level = base_level;
DBG ("Reset the embedding levels");
{
int j, k, state, pos;
- TypeLink *p, *q, *list, *list_end;
+ FriBidiRun *p, *q, *list, *list_end;
/* L1. Reset the embedding levels of some chars. */
init_list (&list, &list_end);
else if (state && !FRIBIDI_IS_EXPLICIT_OR_SEPARATOR_OR_BN_OR_WS (k))
{
state = 0;
- p = new_type_link ();
+ p = new_run ();
p->prev = p->next = NULL;
p->pos = j + 1;
p->len = pos - j;
p->type = base_dir;
p->level = base_level;
- move_element_before (p, q);
+ move_run_before (p, q);
q = p;
}
}
- override_list (type_rl_list, list);
+ shadow_run_list (type_rl_list, list);
}
# if DEBUG
*----------------------------------------------------------------------*/
static void
free_rl_list (
- TypeLink *type_rl_list
+ FriBidiRun * type_rl_list
)
{
- TypeLink *pp;
+ FriBidiRun *pp;
DBG ("Entering free_rl_list");
pp = type_rl_list;
while (pp)
{
- TypeLink *p;
+ FriBidiRun *p;
p = pp;
pp = pp->next;
- free_type_link (p);
+ free_run (p);
};
#else /* !USE_SIMPLE_MALLOC */
for (pp = type_rl_list->next; pp->next; pp = pp->next)
/* Nothing */ ;
- pp->next = free_type_links;
- free_type_links = type_rl_list;
+ pp->next = free_runs;
+ free_runs = type_rl_list;
type_rl_list = NULL;
#endif /* !USE_SIMPLE_MALLOC */
)
{
FriBidiStrIndex i, j;
- fribidi_boolean private_from_this = FALSE;
+ fribidi_boolean private_from_this = false;
DBG ("Entering fribidi_remove_bidi_marks");
not given by the caller, we have to make a private instance of it. */
if (position_to_this_list && !position_from_this_list)
{
- private_from_this = TRUE;
+ private_from_this = true;
position_from_this_list =
(FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) *
length);
FriBidiLevel *embedding_level_list
)
{
- TypeLink *type_rl_list, *pp = NULL;
+ FriBidiRun *type_rl_list, *pp = NULL;
FriBidiLevel max_level;
- fribidi_boolean private_V_to_L = FALSE;
+ fribidi_boolean private_V_to_L = false;
DBG ("Entering fribidi_log2vis()\n");
if (len == 0)
{
DBG ("Leaving fribidi_log2vis()\n");
- return TRUE;
+ return true;
}
/* If l2v is to be calculated we must have v2l as well. If it is not
given by the caller, we have to make a private instance of it. */
if (position_L_to_V_list && !position_V_to_L_list)
{
- private_V_to_L = TRUE;
+ private_V_to_L = true;
position_V_to_L_list =
(FriBidiStrIndex *) fribidi_malloc (sizeof (FriBidiStrIndex) * len);
}
MSG2 (FRIBIDI ": cannot handle strings > %ld characters\n",
(long) FRIBIDI_MAX_STRING_LENGTH);
# endif /* DEBUG */
- return FALSE;
+ return false;
}
fribidi_analyse_string (str, len, pbase_dir,
/* output */
FriBidiStrIndex i, seq_end = 0;
fribidi_boolean is_nsm_seq;
- is_nsm_seq = FALSE;
+ is_nsm_seq = false;
for (i = RL_POS (pp) + RL_LEN (pp) - 1; i >= RL_POS (pp);
i--)
{
{
/* Find all stretches that are >= level_idx */
FriBidiStrIndex len = RL_LEN (pp), pos = RL_POS (pp);
- TypeLink *pp1 = pp->next;
+ FriBidiRun *pp1 = pp->next;
while (pp1->next && RL_LEVEL (pp1) >= level_idx)
{
len += RL_LEN (pp1);
free_rl_list (type_rl_list);
DBG ("Leaving fribidi_log2vis()\n");
- return TRUE;
+ return true;
}
FriBidiLevel *embedding_level_list
)
{
- TypeLink *type_rl_list, *pp;
+ FriBidiRun *type_rl_list, *pp;
FriBidiLevel max_level;
DBG ("Entering fribidi_log2vis_get_embedding_levels()\n");
if (len == 0)
{
DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
- return TRUE;
+ return true;
}
fribidi_analyse_string (str, len, pbase_dir,
free_rl_list (type_rl_list);
DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
- return TRUE;
+ return true;
}
/* Editor directions:
/* FriBidi
* fribidi-mirroring.c - get mirrored character
*
- * $Id: fribidi-env.c,v 1.1 2004-04-25 18:47:57 behdad Exp $
+ * $Id: fribidi-env.c,v 1.2 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:47:57 $
- * $Revision: 1.1 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.2 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/Attic/fribidi-env.c,v $
*
* Authors:
#include <fribidi-env.h>
+#include "env.h"
+
#include "common.h"
+/* Library state variables */
+
#if DEBUG
-static fribidi_boolean flag_debug = FALSE;
+static fribidi_boolean flag_debug = false;
#endif
+static fribidi_boolean flag_mirroring = true;
+static fribidi_boolean flag_reorder_nsm = false;
+
+
+#if !USE_SIMPLE_MALLOC
+FriBidiRun *free_runs = NULL;
+FriBidiMemChunk *run_mem_chunk = NULL;
+#endif /* !USE_SIMPLE_MALLOC */
+
+
+/* And their manipulation routines */
FRIBIDI_ENTRY fribidi_boolean
fribidi_debug_status (
#endif
}
-static fribidi_boolean flag_mirroring = TRUE;
-
FRIBIDI_ENTRY fribidi_boolean
fribidi_set_mirroring (
fribidi_boolean state
return flag_mirroring;
}
-static fribidi_boolean flag_reorder_nsm = FALSE;
-
FRIBIDI_ENTRY fribidi_boolean
fribidi_set_reorder_nsm (
fribidi_boolean state
/* FriBidi
- * mem.h - memory manipulation routines
+ * fribidi-mem.c - memory manipulation routines
*
- * $Id: fribidi-mem.c,v 1.2 2004-04-25 18:58:25 behdad Exp $
+ * $Id: fribidi-mem.c,v 1.3 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-25 18:58:25 $
- * $Revision: 1.2 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.3 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-mem.c,v $
*
* Authors:
int alloc_type
)
{
- FriBidiMemChunk *m =
+ register FriBidiMemChunk *m =
(FriBidiMemChunk *) fribidi_malloc (sizeof (FriBidiMemChunk));
- m->atom_size = atom_size;
- m->area_size = area_size;
- m->empty_size = 0;
- m->chunk = NULL;
+ if (m)
+ {
+ m->atom_size = atom_size;
+ m->area_size = area_size;
+ m->empty_size = 0;
+ m->chunk = NULL;
+ }
return m;
}
FriBidiMemChunk *mem_chunk
)
{
- void *m;
-
if (mem_chunk->empty_size < mem_chunk->atom_size)
{
- mem_chunk->chunk = fribidi_malloc (mem_chunk->area_size);
- mem_chunk->empty_size = mem_chunk->area_size;
+ register void *chunk = fribidi_malloc (mem_chunk->area_size);
+ if (chunk)
+ {
+ (void *) chunk = (void *) mem_chunk->chunk + emptysize - area_size;
+ (char *) chunk += sizeof (void *);
+ mem_chunk->chunk = chunk;
+ mem_chunk->empty_size = mem_chunk->area_size - sizeof (void *);
+ }
+ else
+ return NULL;
}
- m = mem_chunk->chunk;
- mem_chunk->chunk = (void *)
- ((char *) mem_chunk->chunk + mem_chunk->atom_size);
- mem_chunk->empty_size -= mem_chunk->atom_size;
+ {
+ register void *m;
+ m = mem_chunk->chunk;
+ mem_chunk->chunk = (void *)
+ ((char *) mem_chunk->chunk + mem_chunk->atom_size);
+ mem_chunk->empty_size -= mem_chunk->atom_size;
- return m;
+ return m;
+ }
+}
+
+void
+fribidi_mem_chunk_destroy (
+ /* input */
+ FriBidiMemChunk *mem_chunk
+)
+{
+ register void *chunk = mem_chunk->chunk + emptysize - areasize;
+ while (chunk)
+ {
+ register void *tofree = chunk;
+ chunk = *(void *) chunk;
+ fribidi_free (tofree);
+ }
+ fribidi_free (mem_chunk);
}
#endif /* !FRIBIDI_USE_GLIB */
--- /dev/null
+/* FriBidi
+ * fribidi-run.c - text run data type
+ *
+ * $Id: fribidi-run.c,v 1.1 2004-04-28 02:37:56 behdad Exp $
+ * $Author: behdad $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.1 $
+ * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-run.c,v $
+ *
+ * Authors:
+ * Behdad Esfahbod, 2001, 2002, 2004
+ * Dov Grobgeld, 1999, 2000
+ *
+ * Copyright (C) 2004 Sharif FarsiWeb, Inc
+ * Copyright (C) 2001,2002 Behdad Esfahbod
+ * Copyright (C) 1999,2000 Dov Grobgeld
+ *
+ * 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 <license@farsiweb.info>.
+ */
+
+#include "run.h"
+#include "env.h"
+#include "bidi-types.h"
+
+#include "common.h"
+
+FriBidiRun *
+new_run (
+ void
+)
+{
+ FriBidiRun *run;
+
+#if USE_SIMPLE_MALLOC
+ run = fribidi_malloc (sizeof (FriBidiRun));
+#else /* !USE_SIMPLE_MALLOC */
+ if (free_runs)
+ {
+ run = free_runs;
+ free_runs = free_runs->next;
+ }
+ else
+ {
+ if (!run_mem_chunk)
+ run_mem_chunk = fribidi_chunk_new_for_type (FriBidiRun);
+
+ run = fribidi_chunk_new (FriBidiRun, run_mem_chunk);
+ }
+#endif /* !USE_SIMPLE_MALLOC */
+
+ run->len = 0;
+ run->pos = 0;
+ run->level = 0;
+ run->next = NULL;
+ run->prev = NULL;
+ return run;
+}
+
+void
+free_run (
+ FriBidiRun * run
+)
+{
+#if USE_SIMPLE_MALLOC
+ fribidi_free (run);
+#else /* !USE_SIMPLE_MALLOC */
+ run->next = free_runs;
+ free_runs = run;
+#endif /* !USE_SIMPLE_MALLOC */
+}
+
+#define FRIBIDI_ADD_TYPE_LINK(p,q) \
+ FRIBIDI_BEGIN_STMT \
+ (p)->len = (q)->pos - (p)->pos; \
+ (p)->next = (q); \
+ (q)->prev = (p); \
+ (p) = (q); \
+ FRIBIDI_END_STMT
+
+FriBidiRun *
+run_list_encode_bidi_types (
+ FriBidiCharType *char_type,
+ FriBidiStrIndex len
+)
+{
+ FriBidiRun *list, *last, *run;
+
+ FriBidiStrIndex i;
+
+ /* Add the starting run */
+ list = new_run ();
+ list->type = FRIBIDI_TYPE_SOT;
+ list->level = FRIBIDI_LEVEL_START;
+ last = list;
+
+ /* Sweep over the string_type s */
+ for (i = 0; i < len; i++)
+ if (char_type[i] != last->type)
+ {
+ run = new_run ();
+ run->type = char_type[i];
+ run->pos = i;
+ FRIBIDI_ADD_TYPE_LINK (last, run);
+ }
+
+ /* Add the ending run */
+ run = new_run ();
+ run->type = FRIBIDI_TYPE_EOT;
+ run->level = FRIBIDI_LEVEL_END;
+ run->pos = len;
+ FRIBIDI_ADD_TYPE_LINK (last, run);
+
+ return list;
+}
+
+/* move a run before another element in a list, the list must have a
+ previous element, used to update explicits_list.
+ assuming that p have both prev and next or none of them, also update
+ the list that p is currently in, if any.
+*/
+void
+move_run_before (
+ FriBidiRun * p,
+ FriBidiRun * list
+)
+{
+ if (p->prev)
+ {
+ p->prev->next = p->next;
+ p->next->prev = p->prev;
+ }
+ p->prev = list->prev;
+ list->prev->next = p;
+ p->next = list;
+ list->prev = p;
+}
+
+/* override the run list 'base', with the runs in the list 'over', to
+ reinsert the previously-removed explicit codes (at X9) from
+ 'explicits_list' back into 'type_rl_list' for example. This is used at the
+ end of I2 to restore the explicit marks, and also to reset the character
+ types of characters at L1.
+
+ it is assumed that the 'pos' of the first element in 'base' list is not
+ more than the 'pos' of the first element of the 'over' list, and the
+ 'pos' of the last element of the 'base' list is not less than the 'pos'
+ of the last element of the 'over' list. these two conditions are always
+ satisfied for the two usages mentioned above.
+
+ Todo:
+ use some explanatory names instead of p, q, ...
+ rewrite comment above to remove references to special usage.
+*/
+void
+shadow_run_list (
+ FriBidiRun * base,
+ FriBidiRun * over
+)
+{
+ FriBidiRun *p = base, *q, *r, *s, *t;
+ FriBidiStrIndex pos = 0, pos2;
+
+ if (!over)
+ return;
+ q = over;
+ while (q)
+ {
+ if (!q->len || q->pos < pos)
+ {
+ t = q;
+ q = q->next;
+ free_run (t);
+ continue;
+ }
+ pos = q->pos;
+ while (p->next && p->next->pos <= pos)
+ p = p->next;
+ /* now p is the element that q must be inserted 'in'. */
+ pos2 = pos + q->len;
+ r = p;
+ while (r->next && r->next->pos < pos2)
+ r = r->next;
+ /* now r is the last element that q affects. */
+ if (p == r)
+ {
+ /* split p into at most 3 interval, and insert q in the place of
+ the second interval, set r to be the third part. */
+ /* third part needed? */
+ if (p->next && p->next->pos == pos2)
+ r = r->next;
+ else
+ {
+ r = new_run ();
+ *r = *p;
+ if (r->next)
+ {
+ r->next->prev = r;
+ r->len = r->next->pos - pos2;
+ }
+ else
+ r->len -= pos - p->pos;
+ r->pos = pos2;
+ }
+ /* first part needed? */
+ if (p->prev && p->pos == pos)
+ {
+ t = p;
+ p = p->prev;
+ free_run (t);
+ }
+ else
+ p->len = pos - p->pos;
+ }
+ else
+ {
+ /* cut the end of p. */
+ p->len = pos - p->pos;
+ /* if all of p is cut, remove it. */
+ if (!p->len && p->prev)
+ p = p->prev;
+
+ /* cut the begining of r. */
+ r->pos = pos2;
+ if (r->next)
+ r->len = r->next->pos - pos2;
+ /* if all of r is cut, remove it. */
+ if (!r->len && r->next)
+ r = r->next;
+
+ /* remove the elements between p and r. */
+ for (s = p->next; s != r;)
+ {
+ t = s;
+ s = s->next;
+ free_run (t);
+ }
+ }
+ /* before updating the next and prev runs to point to the inserted q,
+ we must remember the next element of q in the 'over' list.
+ */
+ t = q;
+ q = q->next;
+ p->next = t;
+ t->prev = p;
+ t->next = r;
+ r->prev = t;
+ }
+}
+
+/* Editor directions:
+ * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
+ */
/* FriBidi
* mem.h - memory manipulation routines
*
- * $Id: mem.h,v 1.2 2004-04-27 16:47:22 behdad Exp $
+ * $Id: mem.h,v 1.3 2004-04-28 02:37:56 behdad Exp $
* $Author: behdad $
- * $Date: 2004-04-27 16:47:22 $
- * $Revision: 1.2 $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.3 $
* $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/mem.h,v $
*
* Author:
#define FRIBIDI_ALLOC_ONLY 1
-#define fribidi_mem_chunk_new FRIBIDI_NAMESPACE(mem_chunk_new)
+#define fribidi_mem_chunk_new FRIBIDI_PRIVATESPACE(mem_chunk_new)
FriBidiMemChunk *fribidi_mem_chunk_new (
const char *name,
int atom_size,
int alloc_type
);
-#define fribidi_mem_chunk_alloc FRIBIDI_NAMESPACE(mem_chunk_alloc)
+#define fribidi_mem_chunk_alloc FRIBIDI_PRIVATESPACE(mem_chunk_alloc)
void *fribidi_mem_chunk_alloc (
FriBidiMemChunk *mem_chunk
);
+#define fribidi_mem_chunk_destroy FRIBIDI_PRIVATESPACE(mem_chunk_destroy)
+void *fribidi_mem_chunk_destroy (
+ FriBidiMemChunk *mem_chunk
+);
+
#else /* FRIBIDI_USE_GLIB */
#ifndef __C2MAN__
#define FRIBIDI_ALLOC_ONLY G_ALLOC_ONLY
#define fribidi_mem_chunk_new g_mem_chunk_new
#define fribidi_mem_chunk_alloc g_mem_chunk_alloc
+#define fribidi_mem_chunk_destroy g_mem_chunk_destroy
#endif /* FRIBIDI_USE_GLIB */
--- /dev/null
+/* FriBidi
+ * run.h - text run data type
+ *
+ * $Id: run.h,v 1.1 2004-04-28 02:37:56 behdad Exp $
+ * $Author: behdad $
+ * $Date: 2004-04-28 02:37:56 $
+ * $Revision: 1.1 $
+ * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/run.h,v $
+ *
+ * Authors:
+ * Behdad Esfahbod, 2001, 2002, 2004
+ * Dov Grobgeld, 1999, 2000
+ *
+ * Copyright (C) 2004 Sharif FarsiWeb, Inc
+ * Copyright (C) 2001,2002 Behdad Esfahbod
+ * Copyright (C) 1999,2000 Dov Grobgeld
+ *
+ * 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 <license@farsiweb.info>.
+ */
+#ifndef _RUN_H
+#define _RUN_H
+
+#include <fribidi-common.h>
+
+#include <fribidi-types.h>
+#include <fribidi-bidi-types.h>
+
+#include "common.h"
+
+#include <fribidi-begindecls.h>
+
+struct _FriBidiRun
+{
+ FriBidiRun *prev;
+ FriBidiRun *next;
+
+ FriBidiCharType type;
+ FriBidiStrIndex pos, len;
+ FriBidiLevel level;
+};
+
+
+FriBidiRun *new_run (
+ void
+);
+
+void free_run (
+ FriBidiRun * run
+);
+
+FriBidiRun *run_list_encode_bidi_types (
+ FriBidiCharType *char_type,
+ FriBidiStrIndex len
+);
+
+void move_run_before (
+ FriBidiRun * p,
+ FriBidiRun * list
+);
+
+void shadow_run_list (
+ FriBidiRun * base,
+ FriBidiRun * over
+);
+
+#include <fribidi-enddecls.h>
+
+#endif /* !_MEM_H */
+/* Editor directions:
+ * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
+ */