File: generate.pl

package info (click to toggle)
therion 6.3.4-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,544 kB
  • sloc: cpp: 195,273; tcl: 19,779; ansic: 8,434; perl: 1,895; makefile: 1,281; python: 255; asm: 219; sh: 104
file content (236 lines) | stat: -rwxr-xr-x 4,748 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/perl

%ifiles = (
  'ascii' => 'ASCII.TXT',
  'iso8859-1' => '8859-1.TXT',
  'iso8859-2' => '8859-2.TXT',
  'iso8859-5' => '8859-5.TXT',
  'iso8859-7' => '8859-7.TXT',
  'cp1250' => 'CP1250.TXT',
  'cp1251' => 'CP1251.TXT',
  'cp1252' => 'CP1252.TXT',
  'cp1253' => 'CP1253.TXT',
);

$undef_u = '0X005F';
$undef_c = 'LOW LINE';
$undef_a = '0X5F';


$thchenc_facc = '0X80';
$thchenc_fucc = '0X0080';

$thtt_encoding_uc = "";
$thtt_encoding_lc = "";
$thtt_enum = "\tTT_UNKNOWN_ENCODING = -1,\n";
$thtt_enum_val = -1;

foreach $ename (sort keys %ifiles) {

  $ENAME = uc $ename;
  $ekey = "TT_$ENAME";
  $ekey =~ s/\W/\_/g;
  $fname = $ifiles{$ename}, "\n";
  
  $thtt_encoding_uc .= "\t{\"$ENAME\",\t$ekey},\n";
  $thtt_encoding_lc .= "\t{\"$ename\",\t$ekey},\n";
  $thtt_enum_val++;
  $thtt_enum .= "\t$ekey = $thtt_enum_val,\n";
  print "$fname => $ename, $ENAME, $ekey ... ";
  
  # let's build the structures
  open(INP,"$fname");
  
  $id = $thtt_enum_val;
  LINE: while (<INP>) {
    next LINE if /^\s*\#/;
    
    ($d, $c) = split /\#/;
    $d =~ s/^\s+//;
    $d =~ s/\s+$//;
    $c =~ s/^\s*\#//;
    $c =~ s/^\s+//;
    $c =~ s/\s+$//g;
    
    ($a, $u) = split /\s+/, $d;
    unless (defined $u) {
      $u = $undef_u;
      $c = $undef_c;
    }
    
    $a = uc $a;
    $u = uc $u;
    $c = uc $c;

    $c2u{$c} = $u;
    $u2c{$u} = $c;
    $uu2aa{$u}[$id] = $a;
    $aa2uu{$a}[$id] = $u;
    
    if ($a lt $thchenc_facc) {
      if ($u ge $thchenc_fucc) {
        die "ERROR: You have to use lower facc and fucc !!!\n";
      }
      next LINE;
    }
    
    if ($u ne $undef_u) {
       $u2a{$u}[$id] = $a;
    }
    $a2u{$a}[$id] = $u;
    
  }
  
  close(INP);
  print "done\n";
  
}

$thtt_enum_val++;
$maxid = $thtt_enum_val;
@ka2u = sort keys %a2u;
@ku2a = sort keys %u2a;
$maxascii = $#ka2u + 1;
$maxunicode = $#ku2a + 1;
$ENAME = 'UTF-8';
$ename = 'utf-8';
$ekey = 'TT_UTF_8';

$thtt_enum = "enum {\n$thtt_enum\t$ekey = $thtt_enum_val\n};\n";
$thtt_encoding = "static const thstok thtt_encoding[] = {\n" .
  "$thtt_encoding_uc\t{\"$ENAME\",\t$ekey},\n" .
  "$thtt_encoding_lc\t{\"$ename\",\t$ekey},\n" .
  "\t{NULL, TT_UNKNOWN_ENCODING}\n};\n";
  
# now let's generate encoding tables
print "processing conversion tables: E$maxid, A$maxascii, U$maxunicode ... ";
$thencode_tbl_def = "static const char32_t thencode_tbl[][];\n";
$thencode_tbl = "static const char32_t thencode_tbl[$maxascii][$maxid] = {\n";
foreach $av (@ka2u) {
  @current = @{$a2u{$av}};
  for($i = 0; $i < $maxid; $i++) {
    if ($current[$i] eq '') {
      $current[$i] = $undef_u;
    }
  }
  $thencode_tbl .= "\t{" . join(", ", @current) . "},\n";
}
$thencode_tbl .= "};\n";


# and now let's generate decoding tables
$thdecode_tbl_def = "static const unsigned char thdecode_tbl[][];\n";
$thdecode_tbl_idx_def = "static const char32_t thdecode_tbl_idx[];\n";
$thdecode_tbl = "static const unsigned char thdecode_tbl[$maxunicode][$maxid] = {\n";
$thdecode_tbl_idx = "static const char32_t thdecode_tbl_idx[$maxunicode] = {\n";
foreach $uv (@ku2a) {
  @current = @{$u2a{$uv}};
  for($i = 0; $i < $maxid; $i++) {
    
    if ($current[$i] eq '') {  
      $j = 0;
      while ($current[$i] eq '') {
        if ($j == 0) {
          if ($u2c{$uv} =~ /(LATIN (?:CAPITAL|SMALL) LETTER [A-Z])/) {
            $current[$i] = $uu2aa{$c2u{$1}}[$i];
          }
        } else {
          $current[$i] = $undef_a;
        }
        $j++;
      }
    }
  }
  $thdecode_tbl .= "\t{" . join(", ", @current) . "},    //$uv\n";
  $thdecode_tbl_idx .= "\t$uv,\n";
}
$thdecode_tbl_idx .= "};\n";
$thdecode_tbl .= "};\n";
print "done\n";

  
  
open(OUTPT, ">../thchencdata.cxx");
print OUTPT <<ENDOUTPT;
/**
 * \@file thchencdata.cxx
 *
 * THIS FILE IS GENERATED AUTOMATICALLY, DO NOT MODIFY IT !!!
 */  
 
#ifndef thchencdata_cxx
#define thchencdata_cxx

#include <sys/types.h>


/**
 * First ascii en-de-coded character.
 */
 
static const unsigned char thchenc_facc = $thchenc_facc;
 

/**
 * First unicode en-de-coded character.
 */
 
static const char32_t thchenc_fucc = $thchenc_fucc;
 

/**
 * Size of decoding table.
 */
 
static const size_t thdecode_tbl_size = $maxunicode;


/**
 * Undefined ascii character.
 */

static const unsigned char thdecode_undef = $undef_a;
 

$thencode_tbl

$thdecode_tbl_idx

$thdecode_tbl

#endif
ENDOUTPT
close(OUTPT);


open(OUTPT, ">../thchencdata.h");
print OUTPT <<ENDOUTPT;
/**
 * \@file thchencdata.h
 * Therion character encodings module data.
 *
 * THIS FILE IS GENERATED AUTOMATICALLY, DO NOT MODIFY IT !!!
 */
  
#ifndef thchencdata_h
#define thchencdata_h

#include \"thparse.h\"


/**
 * Encoding tokens.
 */

$thtt_enum

/**
 * Encoding parsing table.
 */
 
$thtt_encoding

#endif
ENDOUTPT

close(OUTPT);