[FriBidi-commit] fribidi2/gen.tab Makefile.am, 1.16, 1.17 gen-arabic-liga.sh, NONE, 1.1 gen-arabic-shaping-tab.c, NONE, 1.1 gen-bidi-type-tab.c, 1.15, 1.16 gen-joining-type-tab.c, 1.4, 1.5 gen-mirroring-tab.c, 1.12, 1.13 gen-unicode-version.c, 1.10, 1.11 packtab.c, 1.5, 1.6

Behdad Esfahbod behdad at freedesktop.org
Wed Nov 2 17:39:03 PST 2005


Update of /cvs/fribidi/fribidi2/gen.tab
In directory gabe:/tmp/cvs-serv12087/gen.tab

Modified Files:
	Makefile.am gen-bidi-type-tab.c gen-joining-type-tab.c 
	gen-mirroring-tab.c gen-unicode-version.c packtab.c 
Added Files:
	gen-arabic-liga.sh gen-arabic-shaping-tab.c 
Log Message:
Arabic shaping support added.


Index: Makefile.am
===================================================================
RCS file: /cvs/fribidi/fribidi2/gen.tab/Makefile.am,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Makefile.am	7 Jun 2005 08:43:17 -0000	1.16
+++ Makefile.am	3 Nov 2005 01:39:01 -0000	1.17
@@ -2,11 +2,13 @@
 		gen-unicode-version \
 		gen-bidi-type-tab \
 		gen-joining-type-tab \
+		gen-arabic-shaping-tab \
 		gen-mirroring-tab
 
 gen_unicode_version_SOURCES = gen-unicode-version.c
 gen_bidi_type_tab_SOURCES = gen-bidi-type-tab.c packtab.c packtab.h
 gen_joining_type_tab_SOURCES = gen-joining-type-tab.c packtab.c packtab.h
+gen_arabic_shaping_tab_SOURCES = gen-arabic-shaping-tab.c
 gen_mirroring_tab_SOURCES = gen-mirroring-tab.c packtab.c packtab.h
 
 CLEANFILES = $(EXTRA_PROGRAMS)
@@ -36,7 +38,7 @@
 
 EXTRA_DIST = $(UCD_FILES)
 
-COMPRESSION = 4
+COMPRESSION = 2
 
 # generate bidi-type.tab.i
 
@@ -73,6 +75,18 @@
 	./$(gen_joining_type_tab) $(COMPRESSION) $^ > $@ \
 	|| ($(RM) $@ && false)
 
+# generate arabic-shaping.tab.i
+
+gen_arabic_shaping_tab = gen-arabic-shaping-tab$(EXEEXT)
+
+arabic-shaping.tab.i: \
+		UnicodeData.txt \
+		fribidi-unicode-version.h \
+		$(gen_arabic_shaping_tab_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) $(gen_arabic_shaping_tab)
+	./$(gen_arabic_shaping_tab) $(COMPRESSION) $^ > $@ \
+	|| ($(RM) $@ && false)
+
 # generate mirroring.tab.i
 
 gen_mirroring_tab = gen-mirroring-tab$(EXEEXT)

--- NEW FILE: gen-arabic-liga.sh ---
#!/bin/sh

ARABICSHAPING=unidata/ArabicShaping.txt
UNICODEDATA=unidata/UnicodeData.txt

LAMclass="(`grep '; LAM$' "$ARABICSHAPING" | cut -d';' -f1 | sort | tr '\n' '|' | sed 's/|$//'`)"
ALEFclass="(`grep '; ALEF$' "$ARABICSHAPING" | cut -d';' -f1 | sort | tr '\n' '|' | sed 's/|$//'`)"

grep -E ";<(final|isolated)> $LAMclass $ALEFclass;" "$UNICODEDATA"

--- NEW FILE: gen-arabic-shaping-tab.c ---
/* FriBidi
 * gen-arabic-shaping-tab.c - generate arabic-shaping.tab.i
 *
 * $Id: gen-arabic-shaping-tab.c,v 1.1 2005/11/03 01:39:01 behdad Exp $
 * $Author: behdad $
 * $Date: 2005/11/03 01:39:01 $
 * $Revision: 1.1 $
 * $Source: /cvs/fribidi/fribidi2/gen.tab/gen-arabic-shaping-tab.c,v $
 *
 * Author:
 *   Behdad Esfahbod, 2004, 2005
 *
 * Copyright (C) 2004 Sharif FarsiWeb, Inc
 * Copyright (C) 2004, 2005 Behdad Esfahbod
 * 
 * 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 <common.h>

#include <fribidi-unicode.h>

#include <stdio.h>
#if STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#if HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#if HAVE_STRINGS_H
# include <strings.h>
#endif

#include "packtab.h"

#define appname "gen-arabic-shaping-tab"
#define outputname "arabic-shaping.tab.i"

static void
die (
  const char *msg
)
{
  fprintf (stderr, appname ": %s\n", msg);
  exit (1);
}

static void
die2 (
  const char *fmt,
  const char *p
)
{
  fprintf (stderr, appname ": ");
  fprintf (stderr, fmt, p);
  fprintf (stderr, "\n");
  exit (1);
}

static void
die3 (
  const char *fmt,
  const char *p,
  const char *q
)
{
  fprintf (stderr, appname ": ");
  fprintf (stderr, fmt, p, q);
  fprintf (stderr, "\n");
  exit (1);
}

static void
die3l (
  const char *fmt,
  unsigned long l,
  const char *p
)
{
  fprintf (stderr, appname ": ");
  fprintf (stderr, fmt, l, p);
  fprintf (stderr, "\n");
  exit (1);
}

static const char *arabic_shaping_tags[] = {
  "isolated",
  "final",
  "initial",
  "medial",
  NULL
};

static int
shape_is (
  const char *s,
  const char *type_list[]
)
{
  const char **p = type_list;
  for (; *p; p++)
    if (!strcmp (s, p[0]))
      return  p - type_list;
  return -1;
}

#define table_name "ArShap"
#define macro_name "FRIBIDI_GET_ARABIC_SHAPE_PRES"

#define START_CHAR 0x600
#define END_CHAR 0x700

static FriBidiChar table[FRIBIDI_UNICODE_CHARS][4];
static char buf[4000];
static char tag[sizeof (buf)], buf2[sizeof (buf)];
static FriBidiChar minshaped, maxshaped;

static void
clear_tab (
  void
)
{
  register FriBidiChar c;
  register int shape;

  for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
    for (shape = 0; shape < 4; shape++)
      table[c][shape] = c;
}

static void
init (
  void
)
{
  minshaped = FRIBIDI_UNICODE_CHARS;
  maxshaped = 0;

  clear_tab ();
}

static void
read_unicode_data_txt (
  FILE *f
)
{
  unsigned long c, unshaped, l;

  l = 0;
  while (fgets (buf, sizeof buf, f))
    {
      int i, shape;
      const char *s = buf;

      l++;

      while (*s == ' ')
	s++;

      if (*s == '#' || *s == '\0' || *s == '\n')
	continue;

      i = sscanf (s, "%lx;%*[^;];%*[^;];%*[^;];%*[^;];<%[^;> ]> %lx %[^; ]", &c, tag, &unshaped, buf2);

      if (i != 3)
        continue;

      if (i != 3 || c >= FRIBIDI_UNICODE_CHARS || unshaped >= FRIBIDI_UNICODE_CHARS)
	die3l ("UnicodeData.txt: invalid input at line %ld: %s", l, s);

      shape = shape_is (tag, arabic_shaping_tags);
      if (shape >= 0)
        {
	  table[unshaped][shape] = c;
	  if (unshaped < minshaped)
	    minshaped = unshaped;
	  if (unshaped > maxshaped)
	    maxshaped = unshaped;
	}
    }
}

static void
read_data (
  const char *data_file_type[],
  const char *data_file_name[]
)
{
  FILE *f;

  for (; data_file_name[0] && data_file_type[0];
       data_file_name++, data_file_type++)
    {
      fprintf (stderr, "Reading `%s'\n", data_file_name[0]);
      if (!(f = fopen (data_file_name[0], "rt")))
	die2 ("error: cannot open `%s' for reading", data_file_name[0]);

      if (!strcmp (data_file_type[0], "UnicodeData.txt"))
	read_unicode_data_txt (f);
      else
	die2 ("error: unknown data-file type %s", data_file_type[0]);

      fclose (f);
    }

}

static void
gen_arabic_shaping_tab (
  int max_depth /* currently unused */,
  const char *data_file_type[]
)
{
  register FriBidiChar c;
  register int shape;
 
  if (maxshaped < minshaped)
    die ("error: no shaping pair found, something wrong with reading input");

  fprintf (stderr,
	   "Generating `" outputname "', it may take up to a few minutes\n");
  printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
	  FRIBIDI_VERSION ")\n" " * from the files %s, %s of Unicode version "
	  FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type[0],
	  data_file_type[1]);

  printf ("/*\n"
	   "  use %s(key,shape) to access your table\n\n"
	   "  required memory: %ld\n"
	   " */\n\n",
	   macro_name, (long)(maxshaped - minshaped + 1) * 4 * sizeof (FriBidiChar));

  printf ("\n" "/* *IND" "ENT-OFF* */\n\n");

  printf ("static const FriBidiChar %s[%d][%d] = {\n", table_name, maxshaped - minshaped + 1, 4);
  for (c = minshaped; c <= maxshaped; c++)
    {
      printf ("  {");
      for (shape = 0; shape < 4; shape++)
        printf ("0x%04lx,", (unsigned long)table[c][shape]);
      printf ("},\n");
    }
      

  printf ("};\n\n");

  printf ("/* *IND" "ENT-ON* */\n\n");

  printf ("#ifndef FRIBIDI_ACCESS_SHAPE_TABLE\n"
	  "# define FRIBIDI_ACCESS_SHAPE_TABLE(table,min,max,x,shape) \\\n"
	  "	(((x)<(min)||(x)>(max))?(x):(table)[(x)-(min)][(shape)])\n"
	  "#endif\n\n");
  printf ("#define %s(x,shape) "
	  "FRIBIDI_ACCESS_SHAPE_TABLE(%s, 0x%04lx, 0x%04lx, (x), (shape))\n\n",
	  macro_name, table_name, (unsigned long)minshaped, (unsigned long)maxshaped);

  printf ("/* End of generated " outputname " */\n");
}

int
main (
  int argc,
  const char **argv
)
{
  const char *data_file_type[] =
    { "UnicodeData.txt", NULL };

  if (argc < 3)
    die3 ("usage:\n  " appname " max-depth /path/to/%s /path/to/%s [junk...]",
	  data_file_type[0], data_file_type[1]);

  {
    int max_depth = atoi (argv[1]);
    const char *data_file_name[] = { NULL, NULL };
    data_file_name[0] = argv[2];

    if (max_depth < 2)
      die ("invalid depth");

    init ();
    read_data (data_file_type, data_file_name);
    gen_arabic_shaping_tab (max_depth, data_file_type);
  }

  return 0;
}

Index: gen-bidi-type-tab.c
===================================================================
RCS file: /cvs/fribidi/fribidi2/gen.tab/gen-bidi-type-tab.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- gen-bidi-type-tab.c	7 Jun 2005 08:42:15 -0000	1.15
+++ gen-bidi-type-tab.c	3 Nov 2005 01:39:01 -0000	1.16
@@ -126,7 +126,7 @@
   const char *s
 )
 {
-  int i;
+  unsigned int i;
 
   for (i = 0; i < type_names_count; i++)
     if (!strcmp (s, type_names[i].name))
@@ -144,6 +144,7 @@
 
 static void
 init (
+  void
 )
 {
   register int i;
@@ -156,6 +157,7 @@
 
 static void
 clear_tab (
+  void
 )
 {
   register FriBidiChar c;
@@ -166,6 +168,7 @@
 
 static void
 init_tab_unicode_data_txt (
+  void
 )
 {
   register FriBidiChar c;
@@ -209,6 +212,7 @@
 
 static void
 init_tab_derived_bidi_class_txt (
+  void
 )
 {
   clear_tab ();

Index: gen-joining-type-tab.c
===================================================================
RCS file: /cvs/fribidi/fribidi2/gen.tab/gen-joining-type-tab.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- gen-joining-type-tab.c	7 Jun 2005 08:42:15 -0000	1.4
+++ gen-joining-type-tab.c	3 Nov 2005 01:39:01 -0000	1.5
@@ -135,7 +135,7 @@
   const char *s
 )
 {
-  int i;
+  unsigned int i;
 
   for (i = 0; i < type_names_count; i++)
     if (!strcmp (s, type_names[i].name))
@@ -181,6 +181,7 @@
 
 static void
 clear_tab (
+  void
 )
 {
   register FriBidiChar c;
@@ -191,6 +192,7 @@
 
 static void
 init (
+  void
 )
 {
   register int i;

Index: gen-mirroring-tab.c
===================================================================
RCS file: /cvs/fribidi/fribidi2/gen.tab/gen-mirroring-tab.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- gen-mirroring-tab.c	7 Jun 2005 08:42:15 -0000	1.12
+++ gen-mirroring-tab.c	3 Nov 2005 01:39:01 -0000	1.13
@@ -103,6 +103,7 @@
 
 static void
 init (
+  void
 )
 {
   max_dist = 0;
@@ -110,6 +111,7 @@
 
 static void
 clear_tab (
+  void
 )
 {
   register FriBidiChar c;
@@ -120,6 +122,7 @@
 
 static void
 init_tab_mirroring_txt (
+  void
 )
 {
   clear_tab ();
@@ -151,8 +154,7 @@
 	continue;
 
       k = sscanf (s, "%lx; %lx", &i, &j);
-      if (k != 2 || i < 0 || i >= FRIBIDI_UNICODE_CHARS || j < 0
-	  || j >= FRIBIDI_UNICODE_CHARS)
+      if (k != 2 || i >= FRIBIDI_UNICODE_CHARS || j >= FRIBIDI_UNICODE_CHARS)
 	die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j);
       dist = ((signed long) j - (signed long) i);
       table[i] = dist;

Index: gen-unicode-version.c
===================================================================
RCS file: /cvs/fribidi/fribidi2/gen.tab/gen-unicode-version.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- gen-unicode-version.c	30 Jul 2005 09:06:28 -0000	1.10
+++ gen-unicode-version.c	3 Nov 2005 01:39:01 -0000	1.11
@@ -84,6 +84,7 @@
 
 static void
 init (
+  void
 )
 {
   version_major = version_minor = version_micro = 0;

Index: packtab.c
===================================================================
RCS file: /cvs/fribidi/fribidi2/gen.tab/packtab.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- packtab.c	13 Jun 2004 20:11:42 -0000	1.5
+++ packtab.c	3 Nov 2005 01:39:01 -0000	1.6
@@ -383,6 +383,7 @@
 
 static void
 write_out (
+  void
 )
 {
   int i;



More information about the fribidi-commit mailing list