[FriBidi-commit] fribidi/lib env.h, NONE, 1.1 fribidi-run.c, NONE, 1.1 run.h, NONE, 1.1 Makefile.am, 1.1.1.1, 1.2 bidi-types.h, 1.1.1.1, 1.2 common.h, 1.3, 1.4 fribidi-bidi-type.c, 1.1.1.1, 1.2 fribidi-bidi-types.c, 1.1.1.1, 1.2 fribidi-bidi-types.h, 1.1.1.1, 1.2 fribidi-bidi.c, 1.3, 1.4 fribidi-env.c, 1.1.1.1, 1.2 fribidi-mem.c, 1.2, 1.3 mem.h, 1.2, 1.3

Behdad Esfahbod behdad at pdx.freedesktop.org
Wed Apr 28 12:37:58 EST 2004


Update of /cvs/fribidi/fribidi/lib
In directory pdx:/tmp/cvs-serv1755

Modified Files:
	Makefile.am bidi-types.h common.h fribidi-bidi-type.c 
	fribidi-bidi-types.c fribidi-bidi-types.h fribidi-bidi.c 
	fribidi-env.c fribidi-mem.c mem.h 
Added Files:
	env.h fribidi-run.c run.h 
Log Message:
Added FriBidiRun type, private for now.  Moved all library-wide static variables to env.h.


--- NEW FILE: env.h ---
/* 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: /cvs/fribidi/fribidi/lib/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 at 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
 */

--- NEW FILE: fribidi-run.c ---
/* 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: /cvs/fribidi/fribidi/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 at 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
 */

--- NEW FILE: run.h ---
/* 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: /cvs/fribidi/fribidi/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 at 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
 */

Index: Makefile.am
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/Makefile.am,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/Makefile.am	25 Apr 2004 18:47:57 -0000	1.1.1.1
+++ b/Makefile.am	28 Apr 2004 02:37:56 -0000	1.2
@@ -34,6 +34,7 @@
 		bidi-type-table.i \
 		common.h \
 		debug.h \
+		env.h \
 		fribidi.c \
 		fribidi-bidi.c \
 		fribidi-bidi-type.c \
@@ -41,8 +42,10 @@
 		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 \

Index: bidi-types.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/bidi-types.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/bidi-types.h	25 Apr 2004 18:47:57 -0000	1.1.1.1
+++ b/bidi-types.h	28 Apr 2004 02:37:56 -0000	1.2
@@ -42,6 +42,10 @@
 
 #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
@@ -63,7 +67,7 @@
 
 #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 */
 );

Index: common.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/common.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/common.h	27 Apr 2004 23:53:43 -0000	1.3
+++ b/common.h	28 Apr 2004 02:37:56 -0000	1.4
@@ -38,17 +38,22 @@
 
 #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

Index: fribidi-bidi-type.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi-type.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/fribidi-bidi-type.c	25 Apr 2004 18:47:57 -0000	1.1.1.1
+++ b/fribidi-bidi-type.c	28 Apr 2004 02:37:56 -0000	1.2
@@ -1,5 +1,5 @@
 /* FriBidi
- * fribidi-char-type.c - get character bidi type
+ * fribidi-bidi-type.c - get character bidi type
  *
  * $Id$
  * $Author$

Index: fribidi-bidi-types.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi-types.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/fribidi-bidi-types.c	25 Apr 2004 18:47:57 -0000	1.1.1.1
+++ b/fribidi-bidi-types.c	28 Apr 2004 02:37:56 -0000	1.2
@@ -33,6 +33,8 @@
 
 #include <fribidi-bidi-types.h>
 
+#include "bidi-types.h"
+
 #include "common.h"
 
 #ifdef DEBUG

Index: fribidi-bidi-types.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi-types.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/fribidi-bidi-types.h	25 Apr 2004 18:47:57 -0000	1.1.1.1
+++ b/fribidi-bidi-types.h	28 Apr 2004 02:37:56 -0000	1.2
@@ -41,6 +41,8 @@
 
 typedef signed char FriBidiLevel;
 
+typedef struct _FriBidiRun FriBidiRun;
+
 typedef fribidi_uint32 FriBidiMaskType;
 typedef FriBidiMaskType FriBidiCharType;
 

Index: fribidi-bidi.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-bidi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/fribidi-bidi.c	25 Apr 2004 19:12:42 -0000	1.3
+++ b/fribidi-bidi.c	28 Apr 2004 02:37:56 -0000	1.4
@@ -40,32 +40,15 @@
 #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 */
@@ -103,126 +86,28 @@
     }
 }
 
-#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 @@
   *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 @@
 
 static void
 compact_neutrals (
-  TypeLink *list
+  FriBidiRun * list
 )
 {
   if (list->next)
@@ -539,7 +292,7 @@
 
 static void
 print_types_re (
-  TypeLink *pp
+  FriBidiRun * pp
 )
 {
   MSG ("  Run types  : ");
@@ -554,7 +307,7 @@
 
 static void
 print_resolved_levels (
-  TypeLink *pp
+  FriBidiRun * pp
 )
 {
   MSG ("  Res. levels: ");
@@ -570,7 +323,7 @@
 
 static void
 print_resolved_types (
-  TypeLink *pp
+  FriBidiRun * pp
 )
 {
   MSG ("  Res. types : ");
@@ -609,14 +362,14 @@
   /* 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 @@
       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 @@
     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 @@
 	    /* 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 @@
 	/* 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 @@
     /* 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 @@
 	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 @@
 	    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 @@
 		|| next_type == FRIBIDI_TYPE_EN))
 	  {
 	    RL_TYPE (pp) = FRIBIDI_TYPE_EN;
-	    w4 = FALSE;
+	    w4 = false;
 	    this_type = RL_TYPE (pp);
 	  }
 
@@ -981,9 +734,9 @@
    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 @@
   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 @@
 	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 @@
  *----------------------------------------------------------------------*/
 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 @@
   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 @@
 )
 {
   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 @@
      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 @@
   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 @@
       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 @@
 		    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 @@
 		  {
 		    /* 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 @@
   free_rl_list (type_rl_list);
 
   DBG ("Leaving fribidi_log2vis()\n");
-  return TRUE;
+  return true;
 
 }
 
@@ -1391,7 +1144,7 @@
   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 @@
   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 @@
   free_rl_list (type_rl_list);
 
   DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
-  return TRUE;
+  return true;
 }
 
 /* Editor directions:

Index: fribidi-env.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-env.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/fribidi-env.c	25 Apr 2004 18:47:57 -0000	1.1.1.1
+++ b/fribidi-env.c	28 Apr 2004 02:37:56 -0000	1.2
@@ -35,11 +35,26 @@
 
 #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 (
@@ -65,8 +80,6 @@
 #endif
 }
 
-static fribidi_boolean flag_mirroring = TRUE;
-
 FRIBIDI_ENTRY fribidi_boolean
 fribidi_set_mirroring (
   fribidi_boolean state
@@ -83,8 +96,6 @@
   return flag_mirroring;
 }
 
-static fribidi_boolean flag_reorder_nsm = FALSE;
-
 FRIBIDI_ENTRY fribidi_boolean
 fribidi_set_reorder_nsm (
   fribidi_boolean state

Index: fribidi-mem.c
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/fribidi-mem.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/fribidi-mem.c	25 Apr 2004 18:58:25 -0000	1.2
+++ b/fribidi-mem.c	28 Apr 2004 02:37:56 -0000	1.3
@@ -1,5 +1,5 @@
 /* FriBidi
- * mem.h - memory manipulation routines
+ * fribidi-mem.c - memory manipulation routines
  *
  * $Id$
  * $Author$
@@ -54,13 +54,16 @@
   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 @@
   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 */

Index: mem.h
===================================================================
RCS file: /cvs/fribidi/fribidi/lib/mem.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/mem.h	27 Apr 2004 16:47:22 -0000	1.2
+++ b/mem.h	28 Apr 2004 02:37:56 -0000	1.3
@@ -47,7 +47,7 @@
 
 #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 @@
   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 @@
 #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 */
 




More information about the FriBidi-Commit mailing list