From: behdad Date: Wed, 28 Apr 2004 02:37:56 +0000 (+0000) Subject: Added FriBidiRun type, private for now. Moved all library-wide static variables... X-Git-Tag: FRIBIDI_0_19_1~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1fb4c69145a5222169e8b8f852807046a30d6870;p=fribidi Added FriBidiRun type, private for now. Moved all library-wide static variables to env.h. --- diff --git a/lib/Makefile.am b/lib/Makefile.am index b260142..c715d0e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -34,6 +34,7 @@ libfribidi_la_SOURCES = \ bidi-type-table.i \ common.h \ debug.h \ + env.h \ fribidi.c \ fribidi-bidi.c \ fribidi-bidi-type.c \ @@ -41,8 +42,10 @@ libfribidi_la_SOURCES = \ 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 \ diff --git a/lib/bidi-types.h b/lib/bidi-types.h index b9b571b..fed3125 100644 --- a/lib/bidi-types.h +++ b/lib/bidi-types.h @@ -1,10 +1,10 @@ /* 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: @@ -42,6 +42,10 @@ #include +#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 @@ -63,7 +67,7 @@ extern const FriBidiCharType fribidi_prop_to_type_[]; #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 */ ); diff --git a/lib/common.h b/lib/common.h index 0a6a745..f8f0a50 100644 --- a/lib/common.h +++ b/lib/common.h @@ -1,10 +1,10 @@ /* 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: @@ -38,17 +38,22 @@ #include +/* 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 diff --git a/lib/env.h b/lib/env.h new file mode 100644 index 0000000..ae21ba7 --- /dev/null +++ b/lib/env.h @@ -0,0 +1,63 @@ +/* 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 . + */ +#ifndef _ENV_H +#define _ENV_H + +#include + +#include + +#include "mem.h" + +#include "common.h" + +#include + +#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 + */ diff --git a/lib/fribidi-bidi-type.c b/lib/fribidi-bidi-type.c index 9f1b547..b593c7b 100644 --- a/lib/fribidi-bidi-type.c +++ b/lib/fribidi-bidi-type.c @@ -1,10 +1,10 @@ /* 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: diff --git a/lib/fribidi-bidi-types.c b/lib/fribidi-bidi-types.c index 1c3788d..b148afe 100644 --- a/lib/fribidi-bidi-types.c +++ b/lib/fribidi-bidi-types.c @@ -1,10 +1,10 @@ /* 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: @@ -33,6 +33,8 @@ #include +#include "bidi-types.h" + #include "common.h" #ifdef DEBUG diff --git a/lib/fribidi-bidi-types.h b/lib/fribidi-bidi-types.h index 778ef81..37af7f5 100644 --- a/lib/fribidi-bidi-types.h +++ b/lib/fribidi-bidi-types.h @@ -1,10 +1,10 @@ /* 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: @@ -41,6 +41,8 @@ typedef signed char FriBidiLevel; +typedef struct _FriBidiRun FriBidiRun; + typedef fribidi_uint32 FriBidiMaskType; typedef FriBidiMaskType FriBidiCharType; diff --git a/lib/fribidi-bidi.c b/lib/fribidi-bidi.c index db87523..e4cb741 100644 --- a/lib/fribidi-bidi.c +++ b/lib/fribidi-bidi.c @@ -1,10 +1,10 @@ /* 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: @@ -40,32 +40,15 @@ #include #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 */ @@ -103,126 +86,28 @@ index_array_reverse ( } } -#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; @@ -234,160 +119,28 @@ init_list ( *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) @@ -399,7 +152,7 @@ compact_list ( static void compact_neutrals ( - TypeLink *list + FriBidiRun * list ) { if (list->next) @@ -539,7 +292,7 @@ static char char_from_level_array[] = { static void print_types_re ( - TypeLink *pp + FriBidiRun * pp ) { MSG (" Run types : "); @@ -554,7 +307,7 @@ print_types_re ( static void print_resolved_levels ( - TypeLink *pp + FriBidiRun * pp ) { MSG (" Res. levels: "); @@ -570,7 +323,7 @@ print_resolved_levels ( static void print_resolved_types ( - TypeLink *pp + FriBidiRun * pp ) { MSG (" Res. types : "); @@ -609,14 +362,14 @@ fribidi_analyse_string ( /* 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"); @@ -629,7 +382,7 @@ 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"); @@ -680,7 +433,7 @@ fribidi_analyse_string ( 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; @@ -726,7 +479,7 @@ fribidi_analyse_string ( /* 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 @@ -804,7 +557,7 @@ fribidi_analyse_string ( /* 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)) @@ -831,7 +584,7 @@ fribidi_analyse_string ( /* 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. */ @@ -852,7 +605,7 @@ fribidi_analyse_string ( if (this_type == FRIBIDI_TYPE_AL) { RL_TYPE (pp) = FRIBIDI_TYPE_RTL; - w4 = TRUE; + w4 = true; prev_type_org = FRIBIDI_TYPE_ON; continue; } @@ -869,7 +622,7 @@ fribidi_analyse_string ( 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. */ @@ -878,7 +631,7 @@ fribidi_analyse_string ( || next_type == FRIBIDI_TYPE_EN)) { RL_TYPE (pp) = FRIBIDI_TYPE_EN; - w4 = FALSE; + w4 = false; this_type = RL_TYPE (pp); } @@ -981,9 +734,9 @@ fribidi_analyse_string ( 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; @@ -1004,7 +757,7 @@ fribidi_analyse_string ( 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); @@ -1026,17 +779,17 @@ fribidi_analyse_string ( 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 @@ -1062,11 +815,11 @@ fribidi_analyse_string ( *----------------------------------------------------------------------*/ static void free_rl_list ( - TypeLink *type_rl_list + FriBidiRun * type_rl_list ) { - TypeLink *pp; + FriBidiRun *pp; DBG ("Entering free_rl_list"); @@ -1080,17 +833,17 @@ 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 */ @@ -1116,7 +869,7 @@ fribidi_remove_bidi_marks ( ) { FriBidiStrIndex i, j; - fribidi_boolean private_from_this = FALSE; + fribidi_boolean private_from_this = false; DBG ("Entering fribidi_remove_bidi_marks"); @@ -1124,7 +877,7 @@ 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); @@ -1180,23 +933,23 @@ fribidi_log2vis ( 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); } @@ -1207,7 +960,7 @@ fribidi_log2vis ( 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 */ @@ -1291,7 +1044,7 @@ fribidi_log2vis ( 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--) { @@ -1338,7 +1091,7 @@ fribidi_log2vis ( { /* 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); @@ -1372,7 +1125,7 @@ fribidi_log2vis ( free_rl_list (type_rl_list); DBG ("Leaving fribidi_log2vis()\n"); - return TRUE; + return true; } @@ -1391,7 +1144,7 @@ fribidi_log2vis_get_embedding_levels ( 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"); @@ -1399,7 +1152,7 @@ fribidi_log2vis_get_embedding_levels ( if (len == 0) { DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n"); - return TRUE; + return true; } fribidi_analyse_string (str, len, pbase_dir, @@ -1417,7 +1170,7 @@ fribidi_log2vis_get_embedding_levels ( free_rl_list (type_rl_list); DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n"); - return TRUE; + return true; } /* Editor directions: diff --git a/lib/fribidi-env.c b/lib/fribidi-env.c index 0a98304..8c5bc21 100644 --- a/lib/fribidi-env.c +++ b/lib/fribidi-env.c @@ -1,10 +1,10 @@ /* 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: @@ -35,11 +35,26 @@ #include +#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 ( @@ -65,8 +80,6 @@ fribidi_set_debug ( #endif } -static fribidi_boolean flag_mirroring = TRUE; - FRIBIDI_ENTRY fribidi_boolean fribidi_set_mirroring ( fribidi_boolean state @@ -83,8 +96,6 @@ fribidi_mirroring_status ( return flag_mirroring; } -static fribidi_boolean flag_reorder_nsm = FALSE; - FRIBIDI_ENTRY fribidi_boolean fribidi_set_reorder_nsm ( fribidi_boolean state diff --git a/lib/fribidi-mem.c b/lib/fribidi-mem.c index c9327da..0fe5fcb 100644 --- a/lib/fribidi-mem.c +++ b/lib/fribidi-mem.c @@ -1,10 +1,10 @@ /* 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: @@ -54,13 +54,16 @@ fribidi_mem_chunk_new ( 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; } @@ -71,20 +74,45 @@ fribidi_mem_chunk_alloc ( 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 */ diff --git a/lib/fribidi-run.c b/lib/fribidi-run.c new file mode 100644 index 0000000..c00318c --- /dev/null +++ b/lib/fribidi-run.c @@ -0,0 +1,267 @@ +/* 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 . + */ + +#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 + */ diff --git a/lib/mem.h b/lib/mem.h index cdaf510..bc4c00d 100644 --- a/lib/mem.h +++ b/lib/mem.h @@ -1,10 +1,10 @@ /* 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: @@ -47,7 +47,7 @@ typedef struct _FriBidiMemChunk FriBidiMemChunk; #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, @@ -55,11 +55,16 @@ FriBidiMemChunk *fribidi_mem_chunk_new ( 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__ @@ -70,6 +75,7 @@ void *fribidi_mem_chunk_alloc ( #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 */ diff --git a/lib/run.h b/lib/run.h new file mode 100644 index 0000000..a12f3e3 --- /dev/null +++ b/lib/run.h @@ -0,0 +1,86 @@ +/* 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 . + */ +#ifndef _RUN_H +#define _RUN_H + +#include + +#include +#include + +#include "common.h" + +#include + +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 + +#endif /* !_MEM_H */ +/* Editor directions: + * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent + */