File indexing completed on 2024-05-12 16:39:54

0001 #!/bin/bash
0002 #
0003 #   Copyright (C) 2006-2007 Jarosław Staniek <staniek@kde.org>
0004 #
0005 #   Based on the original script by Michal Svec <rebel@atrey.karlin.mff.cuni.cz>
0006 #
0007 #   This program is free software; you can redistribute it and/or
0008 #   modify it under the terms of the GNU General Public
0009 #   License as published by the Free Software Foundation; either
0010 #   version 2 of the License, or (at your option) any later version.
0011 #
0012 #   This program is distributed in the hope that it will be useful,
0013 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015 #    General Public License for more details.
0016 #
0017 #   You should have received a copy of the GNU General Public License
0018 #   along with this program; see the file COPYING.  If not, write to
0019 #   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020 #   Boston, MA 02110-1301, USA.
0021 
0022 #
0023 # Generates a transliteration_table.h and transliteration_table.cpp.orig.bz2 files using recode's "flat" character set
0024 #
0025 
0026 out_cpp="transliteration_table.cpp.orig"
0027 out_h="transliteration_table.h"
0028 max=65534
0029 
0030 decl="const char *const transliteration_table"
0031 
0032 header=\
0033 "/* Transliteration table of `expr $max + 1` unicode characters
0034    Do not edit this file, it is generated
0035    by $0 script. */
0036 "
0037 echo "$header
0038 #ifndef KEXI_TRANSLITERATION_TABLE_H
0039 #define KEXI_TRANSLITERATION_TABLE_H
0040 
0041 #define TRANSLITERATION_TABLE_SIZE `expr $max + 1`
0042 const char* const* transliteration_table();
0043 
0044 #endif" > $out_h
0045 
0046 echo "$header
0047 #include \"$out_h\"
0048 static const char *const g_transliteration_table[TRANSLITERATION_TABLE_SIZE + 1] = {
0049 " > $out_cpp
0050 
0051 for i in `seq 0 $max` ; do
0052         f=`printf "%04x" $i`
0053         if [ "$i" -lt 16 -o "$i" -eq 92 ] ; then
0054                 printf "$i\n/*$f*/\n_\n" $i
0055         elif [ "$i" -lt 128 ] ; then
0056                 ch=`printf "%03o" $i`
0057                 printf "$i\n/*$f*/\n\\"$ch"\n"
0058         else
0059                 { /usr/bin/printf "${i}\n/*${f}*/\n\u${f}\n" 2>&- || echo "_"; }
0060         fi
0061 done | \
0062 while read i && read f && read ch; do
0063         if ! expr "$i" % 8 > /dev/null ; then
0064                 expr "$i" % 320 > /dev/null || echo -n ..`expr "$i" \* 100 / $max `% >&2 #progress
0065                 echo
0066         else
0067                 f= # <-- comment to add /*numbers*/ everywhere
0068         fi
0069         r=`echo -n "$ch" | recode -f utf-8..flat | \
0070                 sed -r -e 's/[^[:alnum:]]//g;s/_+/_/g'`
0071         if [ -z "$r" -o "$r" == "_" ] ; then
0072                 echo -n "${f}0/*${ch}*/,"
0073         else
0074                 echo -n "${f}\"$r\"/*${ch}*/,"
0075         fi
0076 done >> $out_cpp
0077 
0078 echo "0};
0079 
0080 const char* const* transliteration_table() { return g_transliteration_table; }
0081 " >> $out_cpp;
0082 
0083 bzip2 -9 $out_cpp || exit 1