~ubuntu-branches/ubuntu/vivid/fribidi/vivid

« back to all changes in this revision

Viewing changes to fribidi_create_mirroring.c

  • Committer: Bazaar Package Importer
  • Author(s): Lior Kaplan
  • Date: 2006-09-16 10:37:10 UTC
  • mfrom: (3.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20060916103710-1ktngzyx9azkujhl
Tags: 0.10.7-4
* Fix manual page name section (Closes: #368632)
* debian/control: Upgrade standards version to 3.7.2 (no changes needed).
* debian/copyright: Update Dov Grobgeld's contact address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FriBidi - Library of BiDi algorithm
 
2
 * Copyright (C) 2001,2002 Behdad Esfahbod. 
 
3
 * 
 
4
 * This library is free software; you can redistribute it and/or 
 
5
 * modify it under the terms of the GNU Lesser General Public 
 
6
 * License as published by the Free Software Foundation; either 
 
7
 * version 2.1 of the License, or (at your option) any later version. 
 
8
 * 
 
9
 * This library is distributed in the hope that it will be useful, 
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 
12
 * Lesser General Public License for more details. 
 
13
 * 
 
14
 * You should have received a copy of the GNU Lesser General Public License 
 
15
 * along with this library, in a file named COPYING; if not, write to the 
 
16
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 
17
 * Boston, MA 02111-1307, USA  
 
18
 * 
 
19
 * For licensing issues, contact <fwpg@sharif.edu>. 
 
20
 */
 
21
 
 
22
#include <stdlib.h>
 
23
#include <stdio.h>
 
24
#include <string.h>
 
25
#ifdef HAVE_CONFIG_H
 
26
#include "config.h"
 
27
#endif
 
28
#include "fribidi_unicode.h"
 
29
 
 
30
static void
 
31
err2 (const char *fmt, char *p)
 
32
{
 
33
  fprintf (stderr, "fribidi_create_mirroring: error: ");
 
34
  fprintf (stderr, fmt, p);
 
35
  fprintf (stderr, "\n");
 
36
  exit (1);
 
37
}
 
38
 
 
39
static int table[0x110000];
 
40
static char *bidi_mirroring_file;
 
41
 
 
42
static int mirroring_count;
 
43
 
 
44
static void
 
45
read_bidi_mirroring (void)
 
46
{
 
47
  char s[500];
 
48
  unsigned int i, j;
 
49
  FILE *f;
 
50
 
 
51
  for (i = 0; i < 0x110000; i++)
 
52
    table[i] = 0;
 
53
  mirroring_count = 0;
 
54
  printf ("Reading `BidiMirroring.txt'\n");
 
55
  if (!(f = fopen (bidi_mirroring_file, "rt")))
 
56
    err2 ("cannot open `%s' for reading", bidi_mirroring_file);
 
57
/*  fgets (s, sizeof s, f);
 
58
  sscanf (s, "# BidiMirroring-%s.txt", bidi_mirroring_version = malloc (20));*/
 
59
  while (fgets (s, sizeof s, f))
 
60
    {
 
61
      if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
 
62
        continue;
 
63
      sscanf (s, "%x; %x", &i, &j);
 
64
      table[i] = j;
 
65
      table[j] = i;
 
66
      mirroring_count++;
 
67
    }
 
68
  fclose (f);
 
69
}
 
70
 
 
71
static char *
 
72
headermacro (char *file)
 
73
{
 
74
  char *t = strdup (file);
 
75
  char *p = t;
 
76
  while (*p)
 
77
    {
 
78
      if (*p >= 'a' && *p <= 'z')
 
79
        *p += 'A' - 'a';
 
80
      else if ((*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9'))
 
81
        *p = '_';
 
82
      p++;
 
83
    }
 
84
  return t;
 
85
}
 
86
 
 
87
static void
 
88
write_mirror (char *file)
 
89
{
 
90
  int i;
 
91
  FILE *f;
 
92
  char *FILENAME = headermacro (file);
 
93
 
 
94
  printf ("Writing `%s'\n", file);
 
95
  if (!(f = fopen (file, "wt")))
 
96
    err2 ("cannot open `%s' for writing", file);
 
97
  fprintf (f, "/*\n"
 
98
           "  This file was automatically created from BidiMirroring.txt, version %s\n"
 
99
           "  by fribidi_create_mirroring\n*/\n\n", FRIBIDI_UNICODE_VERSION);
 
100
  fprintf (f, "#ifndef %s\n#define %s\n\n#include \"fribidi.h\"\n\n",
 
101
           FILENAME, FILENAME);
 
102
  fprintf (f, "/*\n"
 
103
           "  Mirrored characters include all the characters in the Unicode list\n"
 
104
           "  that have been declared as being mirrored and that have a mirrored\n"
 
105
           "  equivalent.\n"
 
106
           "\n"
 
107
           "  There are lots of characters that are designed as being mirrored\n"
 
108
           "  but do not have any mirrored glyph, e.g. the sign for there exist.\n");
 
109
  fprintf (f,
 
110
           "  Are these used in Arabic? That is are all the mathematical signs\n"
 
111
           "  that are assigned to be mirrorable actually mirrored in Arabic?\n"
 
112
           "  If that is the case, we'll change the below code to include also\n"
 
113
           "  characters that mirror to themself. It will then be the responsibility\n"
 
114
           "  of the display engine to actually mirror these.\n" "*/\n\n");
 
115
  fprintf (f, "/* *INDENT-OFF" "* */\n\n");
 
116
  fprintf (f, "static const struct\n"
 
117
           "{\n"
 
118
           "  FriBidiChar ch, mirrored_ch;\n"
 
119
           "}\n" "FriBidiMirroredChars[] =\n" "{\n");
 
120
  for (i = 0; i < 0x110000; i++)
 
121
    if (table[i])
 
122
      fprintf (f, "  {0x%04X, 0x%04X},\n", i, table[i]);
 
123
  fprintf (f, "} ;\n\n");
 
124
  fprintf (f, "/* *INDE" "NT-ON* */\n\n");
 
125
  fprintf (f, "const int nFriBidiMirroredChars = %d;\n\n", mirroring_count);
 
126
  fprintf (f, "\n#endif /* %s */\n", FILENAME);
 
127
  fclose (f);
 
128
}
 
129
 
 
130
int
 
131
main (int argc, char **argv)
 
132
{
 
133
  const char *p;
 
134
 
 
135
  p = (argc >= 2) ? argv[1] : "unidata";
 
136
  bidi_mirroring_file = malloc (50 + strlen (p));
 
137
  sprintf (bidi_mirroring_file, "%s/BidiMirroring.txt", p);
 
138
  read_bidi_mirroring ();
 
139
  write_mirror ("fribidi_tab_mirroring.i");
 
140
  return 0;
 
141
}