]> arthur.barton.de Git - netatalk.git/commitdiff
Merge branch 'nouuidaclcheck'
authorFrank Lahm <franklahm@googlemail.com>
Wed, 7 Sep 2011 10:26:56 +0000 (12:26 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 7 Sep 2011 10:26:56 +0000 (12:26 +0200)
15 files changed:
NEWS
VERSION
configure.in
contrib/Makefile.am
contrib/misc/Makefile.am [new file with mode: 0644]
contrib/misc/cnid.lua [new file with mode: 0644]
contrib/misc/make-casetable.pl [deleted file]
contrib/misc/make-precompose.h.pl [deleted file]
contrib/shell_utils/Makefile.am
contrib/shell_utils/make-casetable.pl [new file with mode: 0755]
contrib/shell_utils/make-precompose.h.pl [new file with mode: 0755]
contrib/wireshark/cnid.lua [deleted file]
etc/cnid_dbd/cmd_dbd_scanvol.c
etc/cnid_dbd/dbd_rebuild_add.c
etc/cnid_dbd/dbd_resolve.c

diff --git a/NEWS b/NEWS
index 3d244199799c9d84a698696edb6ca412d2d39572..29be671d2ed716f141b79693a703decf41c97b97 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Changes in 2.2.2
+================
+* FIX: dbd: Better checking for duplicated or bogus CNIDs from AppleDouble files
+
 Changes in 2.2.1
 ================
 
diff --git a/VERSION b/VERSION
index fae692e41d4f76365046a2c9da3349f2f6f1384d..89fbff8f4a97fefd64a478518d14320a709a13ea 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.2.1
\ No newline at end of file
+2.2.2dev
\ No newline at end of file
index e64a0e6f3f707f1bf13eaecd3de7c7243dc8a251..e9facb2f13686ed6de9544c19b58a1f74977cd0c 100644 (file)
@@ -1322,6 +1322,7 @@ AC_OUTPUT([Makefile
        contrib/Makefile
        contrib/macusers/Makefile
        contrib/macusers/macusers
+       contrib/misc/Makefile
        contrib/printing/Makefile
        contrib/shell_utils/Makefile
        contrib/shell_utils/apple_dump
index 5652b1bb74d2ad283927a2c398cc40cba3b43da9..0d2f10741ae95fa8f208fba46270e6fbe7013fcb 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile.am for contrib/
 
-SUBDIRS = macusers shell_utils
+SUBDIRS = macusers misc shell_utils
 
 if COMPILE_TIMELORD
 SUBDIRS += timelord
diff --git a/contrib/misc/Makefile.am b/contrib/misc/Makefile.am
new file mode 100644 (file)
index 0000000..d25d876
--- /dev/null
@@ -0,0 +1,3 @@
+# Makefile for contrib/misc/
+
+EXTRA_DIST = cnid.lua
diff --git a/contrib/misc/cnid.lua b/contrib/misc/cnid.lua
new file mode 100644 (file)
index 0000000..3b21723
--- /dev/null
@@ -0,0 +1,123 @@
+-- 
+-- Netatalk DBD protocol 
+-- wireshark -X lua_script:cnid.lua
+-- don't forget to comment out the line disable_lua = true; do return end;
+-- in /etc/wireshark/init.lua
+
+-- global environment
+local b = _G
+
+-- declare our protocol
+local dbd_proto = Proto("dbd","Netatalk Dbd Wire Protocol")
+
+local cmd = ProtoField.uint32("dbd.cmd", "Request") -- , base.HEX
+local len = ProtoField.uint32("dbd.name.len", "Name Length")
+local filename = ProtoField.string("dbd.name", "Name")
+local error = ProtoField.uint32("dbd.error", "Error code")
+local cnid = ProtoField.uint32("dbd.cnid", "Cnid")
+local did  = ProtoField.uint32("dbd.did", "Parent Directory Id")
+local dev  = ProtoField.uint64("dbd.dev", "Device number")
+local ino  = ProtoField.uint64("dbd.ino", "Inode number")
+local type = ProtoField.uint32("dbd.type", "File type")
+
+dbd_proto.fields = {cmd, error, cnid, did, dev, ino, type, filename, len}
+
+--- Request list
+local Cmd = { [3] = "add", 
+             [4] = "get", 
+             [5] = "resolve", 
+             [6] = "lookup", 
+             [7] = "update", 
+             [8] = "delete", 
+             [11] = "timestamp" 
+           }
+
+--- display a filename 
+local function fname(buffer, pinfo, tree, len, ofs)
+
+    pinfo.cols.info:append(" Name=" .. buffer(ofs +4, len):string())
+
+    local subtree = tree:add(buffer(ofs, len +4), buffer(ofs +4, len):string())
+    subtree:add(filename, buffer(ofs +4, len))
+
+    return subtree
+end
+
+-- create a function to dissect it
+function dbd_proto.dissector(buffer, pinfo, tree)
+
+
+    pinfo.cols.protocol = "DBD"
+
+    local subtree = tree:add(dbd_proto,buffer(),"Netatalk DBD Wire Protocol")
+
+    if pinfo.dst_port == 4700 then
+           pinfo.cols.info = "Query"
+           local val = buffer(0,4):uint()
+           local item = subtree:add(cmd, buffer(0,4))
+           if Cmd[val] then
+               item:append_text(" (" .. Cmd[val] .. ")")
+               pinfo.cols.info = Cmd[val]
+
+               local val = buffer(4,4):uint()
+               if val ~= 0 then
+                       pinfo.cols.info:append(" Cnid=" .. val)
+               end
+               subtree:add(cnid, buffer(4, 4))
+               subtree:add(dev, buffer(8, 8))
+               subtree:add(ino, buffer(16, 8))
+               subtree:add(type, buffer(24, 4))
+
+               local val = buffer(28,4):uint()
+               if val ~= 0 then
+                  pinfo.cols.info:append(" Did=" .. val)
+               end
+               subtree:add(did, buffer(28, 4))
+
+               local val = buffer(36,4):uint()
+               if val ~= 0 then
+                  item = fname(buffer, pinfo, subtree, val, 36)
+                  item:add(len, buffer(36, 4))
+                       
+               end
+           end
+    else
+           pinfo.cols.info = "Reply"
+
+           local rply = {}
+           
+           local val = buffer(0,4):uint()
+           rply.error = val
+           subtree:add(error, buffer(0,4))
+           if val ~= 0 then
+               pinfo.cols.info:append(" Error=" .. val)
+           end
+
+           val = buffer(4,4):uint()
+           rply.cnid = val
+           subtree:add(cnid, buffer(4,4))
+           if val ~= 0 then
+               pinfo.cols.info:append(" Cnid=" .. val)
+           end
+
+           val = buffer(8,4):uint()
+           rply.did = val
+           subtree:add(did, buffer(8,4))
+           if val ~= 0 then
+               pinfo.cols.info:append(" Did=" .. val)
+           end
+
+           val = buffer(16,4):uint()
+           rply.len = val
+           
+           if rply.error == 0 and rply.did ~= 0 then
+              subtree = fname(buffer, pinfo, subtree, val, 16)
+              subtree:add(len, buffer(16,4))
+           end
+    end
+end
+
+-- load the tcp.port table
+local tcp_table = DissectorTable.get("tcp.port")
+-- register our protocol 
+tcp_table:add(4700, dbd_proto)
diff --git a/contrib/misc/make-casetable.pl b/contrib/misc/make-casetable.pl
deleted file mode 100755 (executable)
index 9af15a9..0000000
+++ /dev/null
@@ -1,324 +0,0 @@
-#!/usr/bin/perl
-#
-# usage: make-casetable.pl <infile> <outfile1> <outfile2>
-#        make-casetable.pl UnicodeData.txt utf16_casetable.h utf16_case.c
-#
-# (c) 2011 by HAT <hat@fa2.so-net.ne.jp>
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program 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 General Public License for more details.
-#
-
-# See
-# http://www.unicode.org/reports/tr44/
-# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
-
-# One block has 64 chars.
-#
-# BMP
-# block    0 = dummy
-# block    1 = U+0000 - U+003F
-# block    2 = U+0040 - U+007F
-# .....
-# block 1024 = U+FFC0 - U+FFFF
-# block 1025 = dummy
-#
-# Surrogate Pair
-# block  1024 = dummy
-# block  1025 = U+010000 - U+01003F
-# block  1026 = U+010040 - U+01007F
-# .....
-# block 17408 = U+10FFC0 - U+10FFFF
-# block 17409 = dummy
-#
-# Dummy block is for edge detection.
-# If block include upper/lower chars, block_enable[]=1.
-
-use strict;
-use warnings;
-
-our $code0;
-our $Name1;
-our $General_Category2;
-our $Canonical_Combining_Class3;
-our $Bidi_Class4;
-our $Decomposition_Mapping5;
-our $Numeric_Value6;
-our $Numeric_Value7;
-our $Numeric_Value8;
-our $Bidi_Mirrored9;
-our $Unicode_1_Name10;
-our $ISO_Comment11;
-our $Simple_Uppercase_Mapping12;
-our $Simple_Lowercase_Mapping13;
-our $Simple_Titlecase_Mapping14;
-
-our $hex_code0;
-our $Mapping;
-our $hex_Mapping;
-
-our $char;
-our $sp;
-our $block;
-
-our @table;
-our @table_sp;
-
-our @block_enable;
-our @block_enable_sp;
-
-our $table_no;
-our $block_start;
-our $block_end;
-our $char_start;
-our $char_end;
-
-open(CHEADER, ">$ARGV[1]");
-open(CSOURCE, ">$ARGV[2]");
-
-printf (CHEADER "\/\*\n");
-printf (CHEADER "DO NOT EDIT BY HAND\!\!\!\n");
-printf (CHEADER "\n");
-printf (CHEADER "This file is generated by\n");
-printf (CHEADER " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
-printf (CHEADER "\n");
-printf (CHEADER "%s is got from\n", $ARGV[0]);
-printf (CHEADER "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
-printf (CHEADER "\*\/\n");
-printf (CHEADER "\n");
-
-printf (CSOURCE "\/\*\n");
-printf (CSOURCE "DO NOT EDIT BY HAND\!\!\!\n");
-printf (CSOURCE "\n");
-printf (CSOURCE "This file is generated by\n");
-printf (CSOURCE " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
-printf (CSOURCE "\n");
-printf (CSOURCE "%s is got from\n", $ARGV[0]);
-printf (CSOURCE "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
-printf (CSOURCE "\*\/\n");
-printf (CSOURCE "\n");
-printf (CSOURCE "\#include \<stdint.h\>\n");
-printf (CSOURCE "\#include \<atalk\/unicode.h\>\n");
-printf (CSOURCE "\#include \"%s\"\n", $ARGV[1]);
-printf (CSOURCE "\n");
-
-&make_array("upper");
-&make_array("lower");
-
-printf (CHEADER "\/\* EOF \*\/\n");
-printf (CSOURCE "\/\* EOF \*\/\n");
-
-close(CHEADER);
-close(CSOURCE);
-
-
-###########################################################################
-sub make_array{
-
-    # init table -----------------------------------------------------
-
-    for ($char = 0 ; $char <= 0xFFFF ; $char++) {
-        $table[$char][0] = $char;       # mapped char
-        $table[$char][1] = $char;       # orig char
-        $table[$char][2] = "";          # char name
-    }
-
-    for ($char = 0x10000 ; $char <= 0x10FFFF ; $char++) {
-        $sp = ((0xD800 - (0x10000 >> 10) + ($char >> 10)) << 16)
-            + (0xDC00 + ($char & 0x3FF));
-        $table_sp[$char][0] = $sp;      # mapped surrogate pair
-        $table_sp[$char][1] = $sp;      # orig surrogate pair
-        $table_sp[$char][2] = $char;    # mapped char
-        $table_sp[$char][3] = $char;    # orig char
-        $table_sp[$char][4] = "";       # char name
-    }
-
-    for ($block = 0 ; $block <= 1025 ; $block++) {
-        $block_enable[$block] = 0;
-    }
-
-    $block_enable[1] = 1;           # ASCII block is forcibly included
-    $block_enable[2] = 1;           # in the array for Speed-Up.
-
-    for ($block = 1024 ; $block <= 17409 ; $block++) {
-        $block_enable_sp[$block] = 0;
-    }
-
-    # write data to table --------------------------------------------
-
-    open(UNICODEDATA, "<$ARGV[0]");
-
-    while (<UNICODEDATA>) {
-        chop;
-        (
-            $code0,
-            $Name1,
-            $General_Category2,
-            $Canonical_Combining_Class3,
-            $Bidi_Class4,
-            $Decomposition_Mapping5,
-            $Numeric_Value6,
-            $Numeric_Value7,
-            $Numeric_Value8,
-            $Bidi_Mirrored9,
-            $Unicode_1_Name10,
-            $ISO_Comment11,
-            $Simple_Uppercase_Mapping12,
-            $Simple_Lowercase_Mapping13,
-            $Simple_Titlecase_Mapping14
-        ) = split(/\;/);
-
-        if ($_[0] eq "upper") {
-            $Mapping = $Simple_Uppercase_Mapping12;
-        } elsif ($_[0] eq "lower") {
-            $Mapping = $Simple_Lowercase_Mapping13;
-        } else {
-            exit(1);
-        }
-
-        next if ($Mapping eq "");
-
-        $hex_code0 = hex($code0);
-        $hex_Mapping = hex($Mapping);
-
-        if ($hex_code0 <= 0xFFFF) {
-            $table[$hex_code0][0] = $hex_Mapping;
-            #table[$hex_code0][1]   already set
-            $table[$hex_code0][2] = $Name1;
-            $block_enable[($hex_code0 / 64) +1] = 1;
-        } else {
-            $sp = ((0xD800 - (0x10000 >> 10) + ($hex_Mapping >> 10)) << 16)
-                + (0xDC00 + ($hex_Mapping & 0x3FF));
-            $table_sp[$hex_code0][0] = $sp;
-            #table_sp[$hex_code0][1]   already set
-            $table_sp[$hex_code0][2] = $hex_Mapping;
-            #table_sp[$hex_code0][3]   already set
-            $table_sp[$hex_code0][4] = $Name1;
-            $block_enable_sp[($hex_code0 / 64) +1] = 1;
-        }
-    }
-
-    close(UNICODEDATA);
-
-    # array for BMP --------------------------------------------------
-
-    printf(CSOURCE "\/*******************************************************************\n");
-    printf(CSOURCE " Convert a wide character to %s case.\n", $_[0]);
-    printf(CSOURCE "*******************************************************************\/\n");
-    printf(CSOURCE "ucs2\_t to%s\_w\(ucs2\_t val\)\n", $_[0]);
-    printf(CSOURCE "{\n");
-
-    $table_no = 1;
-
-    for ($block = 1 ; $block <= 1024 ; $block++) {
-
-        # rising edge detection
-        if ($block_enable[$block - 1] == 0 && $block_enable[$block] == 1) {
-            $block_start = $block;
-        }
-
-        # falling edge detection
-        if ($block_enable[$block] == 1 && $block_enable[$block + 1] == 0) {
-            $block_end = $block;
-
-            $char_start = ($block_start -1)* 64;
-            $char_end = ($block_end * 64) -1;
-
-            printf(CHEADER "static const uint16\_t %s\_table\_%d\[%d\] \= \{\n",
-                   $_[0], $table_no, $char_end - $char_start +1);
-
-            for ($char = $char_start ; $char <= $char_end ; $char++) {
-                printf(CHEADER "  0x%04X, /*U\+%04X*/ /*%s*/\n",
-                       $table[$char][0],
-                       $table[$char][1],
-                       $table[$char][2]
-                   );
-            }
-            printf(CHEADER "\}\;\n");
-            printf(CHEADER "\n");
-
-            if ($char_start == 0x0000) {
-                printf(CSOURCE "    if \( val \<\= 0x%04X)\n",
-                       $char_end);
-                printf(CSOURCE "        return %s\_table\_%d\[val]\;\n",
-                       $_[0], $table_no);
-            } else {
-                printf(CSOURCE "    if \( val \>\= 0x%04X \&\& val \<\= 0x%04X)\n",
-                       $char_start, $char_end);
-                printf(CSOURCE "        return %s\_table\_%d\[val-0x%04X\]\;\n",
-                       $_[0], $table_no, $char_start);
-            }
-            printf(CSOURCE "\n");
-
-            $table_no++;
-        }
-    }
-
-    printf(CSOURCE "\treturn \(val\)\;\n");
-    printf(CSOURCE "\}\n");
-    printf(CSOURCE "\n");
-
-    # array for Surrogate Pair ---------------------------------------
-
-    printf(CSOURCE "\/*******************************************************************\n");
-    printf(CSOURCE " Convert a surrogate pair to %s case.\n", $_[0]);
-    printf(CSOURCE "*******************************************************************\/\n");
-    printf(CSOURCE "uint32\_t to%s\_sp\(uint32\_t val\)\n", $_[0]);
-    printf(CSOURCE "{\n");
-
-    $table_no = 1;
-
-    for ($block = 1025 ; $block <= 17408 ; $block++) {
-
-        # rising edge detection
-        if ((($block_enable_sp[$block - 1] == 0) || ((($block - 1) & 0xF) == 0))
-                && ($block_enable_sp[$block] == 1)) {
-            $block_start = $block;
-        }
-
-        # falling edge detection
-        if (($block_enable_sp[$block] == 1) &&
-                ((($block - 1) & 0xF == 0xF) || ($block_enable_sp[$block + 1] == 0))) {
-            $block_end = $block;
-
-            $char_start = ($block_start -1)* 64;
-            $char_end = ($block_end * 64) -1;
-
-            printf(CHEADER "static const uint32\_t %s\_table\_sp\_%d\[%d\] \= \{\n",
-                   $_[0], $table_no, $char_end - $char_start +1);
-
-            for ($char = $char_start ; $char <= $char_end ; $char++) {
-                printf(CHEADER "  0x%08X, /*0x%08X*/ /*U\+%06X*/ /*U\+%06X*/ /*%s*/\n",
-                       $table_sp[$char][0],
-                       $table_sp[$char][1],
-                       $table_sp[$char][2],
-                       $table_sp[$char][3],
-                       $table_sp[$char][4]
-                   );
-            }
-            printf(CHEADER "\}\;\n");
-            printf(CHEADER "\n");
-
-            printf(CSOURCE "    if \( val \>\= 0x%08X \&\& val \<\= 0x%08X)\n",
-                   $table_sp[$char_start][1], $table_sp[$char_end][1]);
-            printf(CSOURCE "        return %s\_table\_sp\_%d\[val-0x%08X\]\;\n",
-                   $_[0], $table_no, $table_sp[$char_start][1]);
-            printf(CSOURCE "\n");
-
-            $table_no++;
-        }
-    }
-
-    printf(CSOURCE "\treturn \(val\)\;\n");
-    printf(CSOURCE "\}\n");
-    printf(CSOURCE "\n");
-}
-
-# EOF
diff --git a/contrib/misc/make-precompose.h.pl b/contrib/misc/make-precompose.h.pl
deleted file mode 100755 (executable)
index 11cb8d9..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/usr/bin/perl
-#
-# usage: make-precompose.h.pl UnicodeData.txt > precompose.h
-#
-# (c) 2008-2011 by HAT <hat@fa2.so-net.ne.jp>
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program 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 General Public License for more details.
-# 
-
-# See
-# http://www.unicode.org/Public/UNIDATA/UCD.html
-# http://www.unicode.org/reports/tr15/
-# http://www.unicode.org/Public/*/ucd/UnicodeData*.txt
-# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
-
-
-# temp files for binary search (compose.TEMP, compose_sp.TEMP) -------------
-
-open(UNICODEDATA, "<$ARGV[0]");
-
-open(COMPOSE_TEMP, ">compose.TEMP");
-open(COMPOSE_SP_TEMP, ">compose_sp.TEMP");
-
-while (<UNICODEDATA>) {
-    chop;
-    (
-     $code0,
-     $Name1,
-     $General_Category2,
-     $Canonical_Combining_Class3,
-     $Bidi_Class4,
-     $Decomposition_Mapping5,
-     $Numeric_Value6,
-     $Numeric_Value7,
-     $Numeric_Value8,
-     $Bidi_Mirrored9,
-     $Unicode_1_Name10,
-     $ISO_Comment11,
-     $Simple_Uppercase_Mapping12,
-     $Simple_Lowercase_Mapping13,
-     $Simple_Titlecase_Mapping14
-    ) = split(/\;/);
-
-    if (($Decomposition_Mapping5 ne "") && ($Decomposition_Mapping5 !~ /\</) && ($Decomposition_Mapping5 =~ / /)) {
-       ($base, $comb) = split(/ /,$Decomposition_Mapping5);
-
-       $leftbracket  = "  { ";
-       $rightbracket =" },     ";
-
-       # AFP 3.x Spec
-       if ( ((0x2000  <= hex($code0)) && (hex($code0) <=  0x2FFF))
-            || ((0xFE30  <= hex($code0)) && (hex($code0) <=  0xFE4F))
-            || ((0x2F800 <= hex($code0)) && (hex($code0) <= 0x2FA1F))) {
-           $leftbracket  = "\/\*{ ";
-           $rightbracket =" },\*\/   ";
-       }
-
-       if (hex($code0) > 0xFFFF) {
-
-           $code0_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($code0) >> 10);
-           $code0_sp_lo = 0xDC00 + (hex($code0) & 0x3FF);
-
-           $base_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($base) >> 10);
-           $base_sp_lo = 0xDC00 + (hex($base) & 0x3FF);
-
-           $comb_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($comb) >> 10);
-           $comb_sp_lo = 0xDC00 + (hex($comb) & 0x3FF);
-
-           printf(COMPOSE_SP_TEMP "%s0x%04X%04X, 0x%04X%04X, 0x%04X%04X%s\/\* %s \*\/\n",
-                  $leftbracket, $code0_sp_hi ,$code0_sp_lo, $base_sp_hi, $base_sp_lo, $comb_sp_hi, $comb_sp_lo, $rightbracket, $Name1);
-
-           $leftbracket  = "\/\*{ ";
-           $rightbracket =" },\*\/   ";
-       }
-
-       printf(COMPOSE_TEMP "%s0x%08X, 0x%08X, 0x%08X%s\/\* %s \*\/\n", $leftbracket, hex($code0), hex($base), hex($comb), $rightbracket, $Name1);
-
-    }
-}
-
-close(UNICODEDATA);
-
-close(COMPOSE_TEMP);
-close(COMPOSE_SP_TEMP);
-
-# macros for BMP (PRECOMP_COUNT, DECOMP_COUNT, MAXCOMBLEN) ----------------
-
-open(COMPOSE_TEMP, "<compose.TEMP");
-
-@comp_table = ();
-$comp_count = 0;
-
-while (<COMPOSE_TEMP>) {
-    if (m/^\/\*/) {
-       next;
-    }
-    $comp_table[$comp_count][0] = substr($_, 4, 10);
-    $comp_table[$comp_count][1] = substr($_, 16, 10);
-    $comp_count++;
-}
-
-$maxcomblen = 2;      # Hangul's maxcomblen is already 2. That is, VT.
-
-for ($i = 0 ; $i < $comp_count ; $i++) {
-    $base = $comp_table[$i][1];
-    $comblen = 1;
-    $j = 0;
-    while ($j < $comp_count) {
-       if ($base ne $comp_table[$j][0]) {
-           $j++;
-           next;
-       } else {
-           $comblen++;
-           $base =  $comp_table[$j][1];
-           $j = 0;
-       }
-    }
-    $maxcomblen = ($maxcomblen > $comblen) ? $maxcomblen : $comblen;
-}
-
-close(COMPOSE_TEMP);
-
-# macros for SP (PRECOMP_SP_COUNT,DECOMP_SP_COUNT, MAXCOMBSPLEN) -----------
-
-open(COMPOSE_SP_TEMP, "<compose_sp.TEMP");
-
-@comp_sp_table = ();
-$comp_sp_count = 0;
-
-while (<COMPOSE_SP_TEMP>) {
-    if (m/^\/\*/) {
-       next;
-    }
-    $comp_sp_table[$comp_sp_count][0] = substr($_, 4, 10);
-    $comp_sp_table[$comp_sp_count][1] = substr($_, 16, 10);
-    $comp_sp_count++;
-}
-
-$maxcombsplen = 2;     # one char have 2 codepoints, like a D8xx DCxx.
-
-for ($i = 0 ; $i < $comp_sp_count ; $i++) {
-    $base_sp = $comp_sp_table[$i][1];
-    $comblen = 2;
-    $j = 0;
-    while ($j < $comp_sp_count) {
-       if ($base_sp ne $comp_sp_table[$j][0]) {
-           $j++;
-           next;
-       } else {
-           $comblen += 2;
-           $base_sp =  $comp_sp_table[$j][1];
-           $j = 0;
-       }
-    }
-    $maxcombsplen = ($maxcombsplen > $comblen) ? $maxcombsplen : $comblen;
-}
-
-close(COMPOSE_SP_TEMP);
-
-# macro for buffer length (COMBBUFLEN) -------------------------------------
-
-$combbuflen = ($maxcomblen > $maxcombsplen) ? $maxcomblen : $maxcombsplen;
-
-# sort ---------------------------------------------------------------------
-
-system("sort -k 3 compose.TEMP \> precompose.SORT");
-system("sort -k 2 compose.TEMP \>  decompose.SORT");
-
-system("sort -k 3 compose_sp.TEMP \> precompose_sp.SORT");
-system("sort -k 2 compose_sp.TEMP \>  decompose_sp.SORT");
-
-# print  -------------------------------------------------------------------
-
-print ("\/\* DO NOT EDIT BY HAND\!\!\!                                           \*\/\n");
-print ("\/\* This file is generated by                                        \*\/\n");
-printf ("\/\*              contrib/misc/make-precompose.h.pl %s   \*\/\n", $ARGV[0]);
-print ("\n");
-printf ("\/\* %s is got from                                      \*\/\n", $ARGV[0]);
-print ("\/\* http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt            \*\/\n");
-print ("\n");
-
-print ("\#define SBASE 0xAC00\n");
-print ("\#define LBASE 0x1100\n");
-print ("\#define VBASE 0x1161\n");
-print ("\#define TBASE 0x11A7\n");
-print ("\#define LCOUNT 19\n");
-print ("\#define VCOUNT 21\n");
-print ("\#define TCOUNT 28\n");
-print ("\#define NCOUNT 588     \/\* (VCOUNT \* TCOUNT) \*\/\n");
-print ("\#define SCOUNT 11172   \/\* (LCOUNT \* NCOUNT) \*\/\n");
-print ("\n");
-
-printf ("\#define PRECOMP_COUNT %d\n", $comp_count);
-printf ("\#define DECOMP_COUNT %d\n", $comp_count);
-printf ("\#define MAXCOMBLEN %d\n", $maxcomblen);
-print ("\n");
-printf ("\#define PRECOMP_SP_COUNT %d\n", $comp_sp_count);
-printf ("\#define DECOMP_SP_COUNT %d\n", $comp_sp_count);
-printf ("\#define MAXCOMBSPLEN %d\n", $maxcombsplen);
-print ("\n");
-printf ("\#define COMBBUFLEN %d  \/\* max\(MAXCOMBLEN\,MAXCOMBSPLEN\) \*\/\n", $combbuflen);
-print ("\n");
-
-print ("static const struct \{\n");
-print ("  unsigned int replacement\;\n");
-print ("  unsigned int base\;\n");
-print ("  unsigned int comb\;\n");
-print ("\} precompositions\[\] \= \{\n");
-
-system("cat precompose.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-print ("static const struct \{\n");
-print ("  unsigned int replacement\;\n");
-print ("  unsigned int base\;\n");
-print ("  unsigned int comb\;\n");
-print ("\} decompositions\[\] \= \{\n");
-
-system("cat decompose.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-
-
-print ("static const struct \{\n");
-print ("  unsigned int replacement_sp\;\n");
-print ("  unsigned int base_sp\;\n");
-print ("  unsigned int comb_sp\;\n");
-print ("\} precompositions_sp\[\] \= \{\n");
-
-system("cat precompose_sp.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-print ("static const struct \{\n");
-print ("  unsigned int replacement_sp\;\n");
-print ("  unsigned int base_sp\;\n");
-print ("  unsigned int comb_sp\;\n");
-print ("\} decompositions_sp\[\] \= \{\n");
-
-system("cat decompose_sp.SORT");
-
-print ("\}\;\n");
-print ("\n");
-
-print ("\/\* EOF \*\/\n");
-
-# EOF
index 6ae8b2771c00e971a37b0d010e1deccc16ecf3b4..5e4aaa91abe17fedd8f559c67f94567a379e51de 100644 (file)
@@ -20,4 +20,4 @@ CLEANFILES = $(GENERATED_FILES)
 
 bin_SCRIPTS = $(PERLSCRIPTS) $(GENERATED_FILES)
 
-EXTRA_DIST = $(TEMPLATE_FILES)
+EXTRA_DIST = $(TEMPLATE_FILES) make-casetable.pl make-precompose.h.pl
diff --git a/contrib/shell_utils/make-casetable.pl b/contrib/shell_utils/make-casetable.pl
new file mode 100755 (executable)
index 0000000..9af15a9
--- /dev/null
@@ -0,0 +1,324 @@
+#!/usr/bin/perl
+#
+# usage: make-casetable.pl <infile> <outfile1> <outfile2>
+#        make-casetable.pl UnicodeData.txt utf16_casetable.h utf16_case.c
+#
+# (c) 2011 by HAT <hat@fa2.so-net.ne.jp>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program 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 General Public License for more details.
+#
+
+# See
+# http://www.unicode.org/reports/tr44/
+# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
+
+# One block has 64 chars.
+#
+# BMP
+# block    0 = dummy
+# block    1 = U+0000 - U+003F
+# block    2 = U+0040 - U+007F
+# .....
+# block 1024 = U+FFC0 - U+FFFF
+# block 1025 = dummy
+#
+# Surrogate Pair
+# block  1024 = dummy
+# block  1025 = U+010000 - U+01003F
+# block  1026 = U+010040 - U+01007F
+# .....
+# block 17408 = U+10FFC0 - U+10FFFF
+# block 17409 = dummy
+#
+# Dummy block is for edge detection.
+# If block include upper/lower chars, block_enable[]=1.
+
+use strict;
+use warnings;
+
+our $code0;
+our $Name1;
+our $General_Category2;
+our $Canonical_Combining_Class3;
+our $Bidi_Class4;
+our $Decomposition_Mapping5;
+our $Numeric_Value6;
+our $Numeric_Value7;
+our $Numeric_Value8;
+our $Bidi_Mirrored9;
+our $Unicode_1_Name10;
+our $ISO_Comment11;
+our $Simple_Uppercase_Mapping12;
+our $Simple_Lowercase_Mapping13;
+our $Simple_Titlecase_Mapping14;
+
+our $hex_code0;
+our $Mapping;
+our $hex_Mapping;
+
+our $char;
+our $sp;
+our $block;
+
+our @table;
+our @table_sp;
+
+our @block_enable;
+our @block_enable_sp;
+
+our $table_no;
+our $block_start;
+our $block_end;
+our $char_start;
+our $char_end;
+
+open(CHEADER, ">$ARGV[1]");
+open(CSOURCE, ">$ARGV[2]");
+
+printf (CHEADER "\/\*\n");
+printf (CHEADER "DO NOT EDIT BY HAND\!\!\!\n");
+printf (CHEADER "\n");
+printf (CHEADER "This file is generated by\n");
+printf (CHEADER " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
+printf (CHEADER "\n");
+printf (CHEADER "%s is got from\n", $ARGV[0]);
+printf (CHEADER "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
+printf (CHEADER "\*\/\n");
+printf (CHEADER "\n");
+
+printf (CSOURCE "\/\*\n");
+printf (CSOURCE "DO NOT EDIT BY HAND\!\!\!\n");
+printf (CSOURCE "\n");
+printf (CSOURCE "This file is generated by\n");
+printf (CSOURCE " contrib/misc/make-casetable.pl %s %s %s\n", $ARGV[0], $ARGV[1], $ARGV[2]);
+printf (CSOURCE "\n");
+printf (CSOURCE "%s is got from\n", $ARGV[0]);
+printf (CSOURCE "http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt\n");
+printf (CSOURCE "\*\/\n");
+printf (CSOURCE "\n");
+printf (CSOURCE "\#include \<stdint.h\>\n");
+printf (CSOURCE "\#include \<atalk\/unicode.h\>\n");
+printf (CSOURCE "\#include \"%s\"\n", $ARGV[1]);
+printf (CSOURCE "\n");
+
+&make_array("upper");
+&make_array("lower");
+
+printf (CHEADER "\/\* EOF \*\/\n");
+printf (CSOURCE "\/\* EOF \*\/\n");
+
+close(CHEADER);
+close(CSOURCE);
+
+
+###########################################################################
+sub make_array{
+
+    # init table -----------------------------------------------------
+
+    for ($char = 0 ; $char <= 0xFFFF ; $char++) {
+        $table[$char][0] = $char;       # mapped char
+        $table[$char][1] = $char;       # orig char
+        $table[$char][2] = "";          # char name
+    }
+
+    for ($char = 0x10000 ; $char <= 0x10FFFF ; $char++) {
+        $sp = ((0xD800 - (0x10000 >> 10) + ($char >> 10)) << 16)
+            + (0xDC00 + ($char & 0x3FF));
+        $table_sp[$char][0] = $sp;      # mapped surrogate pair
+        $table_sp[$char][1] = $sp;      # orig surrogate pair
+        $table_sp[$char][2] = $char;    # mapped char
+        $table_sp[$char][3] = $char;    # orig char
+        $table_sp[$char][4] = "";       # char name
+    }
+
+    for ($block = 0 ; $block <= 1025 ; $block++) {
+        $block_enable[$block] = 0;
+    }
+
+    $block_enable[1] = 1;           # ASCII block is forcibly included
+    $block_enable[2] = 1;           # in the array for Speed-Up.
+
+    for ($block = 1024 ; $block <= 17409 ; $block++) {
+        $block_enable_sp[$block] = 0;
+    }
+
+    # write data to table --------------------------------------------
+
+    open(UNICODEDATA, "<$ARGV[0]");
+
+    while (<UNICODEDATA>) {
+        chop;
+        (
+            $code0,
+            $Name1,
+            $General_Category2,
+            $Canonical_Combining_Class3,
+            $Bidi_Class4,
+            $Decomposition_Mapping5,
+            $Numeric_Value6,
+            $Numeric_Value7,
+            $Numeric_Value8,
+            $Bidi_Mirrored9,
+            $Unicode_1_Name10,
+            $ISO_Comment11,
+            $Simple_Uppercase_Mapping12,
+            $Simple_Lowercase_Mapping13,
+            $Simple_Titlecase_Mapping14
+        ) = split(/\;/);
+
+        if ($_[0] eq "upper") {
+            $Mapping = $Simple_Uppercase_Mapping12;
+        } elsif ($_[0] eq "lower") {
+            $Mapping = $Simple_Lowercase_Mapping13;
+        } else {
+            exit(1);
+        }
+
+        next if ($Mapping eq "");
+
+        $hex_code0 = hex($code0);
+        $hex_Mapping = hex($Mapping);
+
+        if ($hex_code0 <= 0xFFFF) {
+            $table[$hex_code0][0] = $hex_Mapping;
+            #table[$hex_code0][1]   already set
+            $table[$hex_code0][2] = $Name1;
+            $block_enable[($hex_code0 / 64) +1] = 1;
+        } else {
+            $sp = ((0xD800 - (0x10000 >> 10) + ($hex_Mapping >> 10)) << 16)
+                + (0xDC00 + ($hex_Mapping & 0x3FF));
+            $table_sp[$hex_code0][0] = $sp;
+            #table_sp[$hex_code0][1]   already set
+            $table_sp[$hex_code0][2] = $hex_Mapping;
+            #table_sp[$hex_code0][3]   already set
+            $table_sp[$hex_code0][4] = $Name1;
+            $block_enable_sp[($hex_code0 / 64) +1] = 1;
+        }
+    }
+
+    close(UNICODEDATA);
+
+    # array for BMP --------------------------------------------------
+
+    printf(CSOURCE "\/*******************************************************************\n");
+    printf(CSOURCE " Convert a wide character to %s case.\n", $_[0]);
+    printf(CSOURCE "*******************************************************************\/\n");
+    printf(CSOURCE "ucs2\_t to%s\_w\(ucs2\_t val\)\n", $_[0]);
+    printf(CSOURCE "{\n");
+
+    $table_no = 1;
+
+    for ($block = 1 ; $block <= 1024 ; $block++) {
+
+        # rising edge detection
+        if ($block_enable[$block - 1] == 0 && $block_enable[$block] == 1) {
+            $block_start = $block;
+        }
+
+        # falling edge detection
+        if ($block_enable[$block] == 1 && $block_enable[$block + 1] == 0) {
+            $block_end = $block;
+
+            $char_start = ($block_start -1)* 64;
+            $char_end = ($block_end * 64) -1;
+
+            printf(CHEADER "static const uint16\_t %s\_table\_%d\[%d\] \= \{\n",
+                   $_[0], $table_no, $char_end - $char_start +1);
+
+            for ($char = $char_start ; $char <= $char_end ; $char++) {
+                printf(CHEADER "  0x%04X, /*U\+%04X*/ /*%s*/\n",
+                       $table[$char][0],
+                       $table[$char][1],
+                       $table[$char][2]
+                   );
+            }
+            printf(CHEADER "\}\;\n");
+            printf(CHEADER "\n");
+
+            if ($char_start == 0x0000) {
+                printf(CSOURCE "    if \( val \<\= 0x%04X)\n",
+                       $char_end);
+                printf(CSOURCE "        return %s\_table\_%d\[val]\;\n",
+                       $_[0], $table_no);
+            } else {
+                printf(CSOURCE "    if \( val \>\= 0x%04X \&\& val \<\= 0x%04X)\n",
+                       $char_start, $char_end);
+                printf(CSOURCE "        return %s\_table\_%d\[val-0x%04X\]\;\n",
+                       $_[0], $table_no, $char_start);
+            }
+            printf(CSOURCE "\n");
+
+            $table_no++;
+        }
+    }
+
+    printf(CSOURCE "\treturn \(val\)\;\n");
+    printf(CSOURCE "\}\n");
+    printf(CSOURCE "\n");
+
+    # array for Surrogate Pair ---------------------------------------
+
+    printf(CSOURCE "\/*******************************************************************\n");
+    printf(CSOURCE " Convert a surrogate pair to %s case.\n", $_[0]);
+    printf(CSOURCE "*******************************************************************\/\n");
+    printf(CSOURCE "uint32\_t to%s\_sp\(uint32\_t val\)\n", $_[0]);
+    printf(CSOURCE "{\n");
+
+    $table_no = 1;
+
+    for ($block = 1025 ; $block <= 17408 ; $block++) {
+
+        # rising edge detection
+        if ((($block_enable_sp[$block - 1] == 0) || ((($block - 1) & 0xF) == 0))
+                && ($block_enable_sp[$block] == 1)) {
+            $block_start = $block;
+        }
+
+        # falling edge detection
+        if (($block_enable_sp[$block] == 1) &&
+                ((($block - 1) & 0xF == 0xF) || ($block_enable_sp[$block + 1] == 0))) {
+            $block_end = $block;
+
+            $char_start = ($block_start -1)* 64;
+            $char_end = ($block_end * 64) -1;
+
+            printf(CHEADER "static const uint32\_t %s\_table\_sp\_%d\[%d\] \= \{\n",
+                   $_[0], $table_no, $char_end - $char_start +1);
+
+            for ($char = $char_start ; $char <= $char_end ; $char++) {
+                printf(CHEADER "  0x%08X, /*0x%08X*/ /*U\+%06X*/ /*U\+%06X*/ /*%s*/\n",
+                       $table_sp[$char][0],
+                       $table_sp[$char][1],
+                       $table_sp[$char][2],
+                       $table_sp[$char][3],
+                       $table_sp[$char][4]
+                   );
+            }
+            printf(CHEADER "\}\;\n");
+            printf(CHEADER "\n");
+
+            printf(CSOURCE "    if \( val \>\= 0x%08X \&\& val \<\= 0x%08X)\n",
+                   $table_sp[$char_start][1], $table_sp[$char_end][1]);
+            printf(CSOURCE "        return %s\_table\_sp\_%d\[val-0x%08X\]\;\n",
+                   $_[0], $table_no, $table_sp[$char_start][1]);
+            printf(CSOURCE "\n");
+
+            $table_no++;
+        }
+    }
+
+    printf(CSOURCE "\treturn \(val\)\;\n");
+    printf(CSOURCE "\}\n");
+    printf(CSOURCE "\n");
+}
+
+# EOF
diff --git a/contrib/shell_utils/make-precompose.h.pl b/contrib/shell_utils/make-precompose.h.pl
new file mode 100755 (executable)
index 0000000..11cb8d9
--- /dev/null
@@ -0,0 +1,260 @@
+#!/usr/bin/perl
+#
+# usage: make-precompose.h.pl UnicodeData.txt > precompose.h
+#
+# (c) 2008-2011 by HAT <hat@fa2.so-net.ne.jp>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program 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 General Public License for more details.
+# 
+
+# See
+# http://www.unicode.org/Public/UNIDATA/UCD.html
+# http://www.unicode.org/reports/tr15/
+# http://www.unicode.org/Public/*/ucd/UnicodeData*.txt
+# http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
+
+
+# temp files for binary search (compose.TEMP, compose_sp.TEMP) -------------
+
+open(UNICODEDATA, "<$ARGV[0]");
+
+open(COMPOSE_TEMP, ">compose.TEMP");
+open(COMPOSE_SP_TEMP, ">compose_sp.TEMP");
+
+while (<UNICODEDATA>) {
+    chop;
+    (
+     $code0,
+     $Name1,
+     $General_Category2,
+     $Canonical_Combining_Class3,
+     $Bidi_Class4,
+     $Decomposition_Mapping5,
+     $Numeric_Value6,
+     $Numeric_Value7,
+     $Numeric_Value8,
+     $Bidi_Mirrored9,
+     $Unicode_1_Name10,
+     $ISO_Comment11,
+     $Simple_Uppercase_Mapping12,
+     $Simple_Lowercase_Mapping13,
+     $Simple_Titlecase_Mapping14
+    ) = split(/\;/);
+
+    if (($Decomposition_Mapping5 ne "") && ($Decomposition_Mapping5 !~ /\</) && ($Decomposition_Mapping5 =~ / /)) {
+       ($base, $comb) = split(/ /,$Decomposition_Mapping5);
+
+       $leftbracket  = "  { ";
+       $rightbracket =" },     ";
+
+       # AFP 3.x Spec
+       if ( ((0x2000  <= hex($code0)) && (hex($code0) <=  0x2FFF))
+            || ((0xFE30  <= hex($code0)) && (hex($code0) <=  0xFE4F))
+            || ((0x2F800 <= hex($code0)) && (hex($code0) <= 0x2FA1F))) {
+           $leftbracket  = "\/\*{ ";
+           $rightbracket =" },\*\/   ";
+       }
+
+       if (hex($code0) > 0xFFFF) {
+
+           $code0_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($code0) >> 10);
+           $code0_sp_lo = 0xDC00 + (hex($code0) & 0x3FF);
+
+           $base_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($base) >> 10);
+           $base_sp_lo = 0xDC00 + (hex($base) & 0x3FF);
+
+           $comb_sp_hi = 0xD800 - (0x10000 >> 10) + (hex($comb) >> 10);
+           $comb_sp_lo = 0xDC00 + (hex($comb) & 0x3FF);
+
+           printf(COMPOSE_SP_TEMP "%s0x%04X%04X, 0x%04X%04X, 0x%04X%04X%s\/\* %s \*\/\n",
+                  $leftbracket, $code0_sp_hi ,$code0_sp_lo, $base_sp_hi, $base_sp_lo, $comb_sp_hi, $comb_sp_lo, $rightbracket, $Name1);
+
+           $leftbracket  = "\/\*{ ";
+           $rightbracket =" },\*\/   ";
+       }
+
+       printf(COMPOSE_TEMP "%s0x%08X, 0x%08X, 0x%08X%s\/\* %s \*\/\n", $leftbracket, hex($code0), hex($base), hex($comb), $rightbracket, $Name1);
+
+    }
+}
+
+close(UNICODEDATA);
+
+close(COMPOSE_TEMP);
+close(COMPOSE_SP_TEMP);
+
+# macros for BMP (PRECOMP_COUNT, DECOMP_COUNT, MAXCOMBLEN) ----------------
+
+open(COMPOSE_TEMP, "<compose.TEMP");
+
+@comp_table = ();
+$comp_count = 0;
+
+while (<COMPOSE_TEMP>) {
+    if (m/^\/\*/) {
+       next;
+    }
+    $comp_table[$comp_count][0] = substr($_, 4, 10);
+    $comp_table[$comp_count][1] = substr($_, 16, 10);
+    $comp_count++;
+}
+
+$maxcomblen = 2;      # Hangul's maxcomblen is already 2. That is, VT.
+
+for ($i = 0 ; $i < $comp_count ; $i++) {
+    $base = $comp_table[$i][1];
+    $comblen = 1;
+    $j = 0;
+    while ($j < $comp_count) {
+       if ($base ne $comp_table[$j][0]) {
+           $j++;
+           next;
+       } else {
+           $comblen++;
+           $base =  $comp_table[$j][1];
+           $j = 0;
+       }
+    }
+    $maxcomblen = ($maxcomblen > $comblen) ? $maxcomblen : $comblen;
+}
+
+close(COMPOSE_TEMP);
+
+# macros for SP (PRECOMP_SP_COUNT,DECOMP_SP_COUNT, MAXCOMBSPLEN) -----------
+
+open(COMPOSE_SP_TEMP, "<compose_sp.TEMP");
+
+@comp_sp_table = ();
+$comp_sp_count = 0;
+
+while (<COMPOSE_SP_TEMP>) {
+    if (m/^\/\*/) {
+       next;
+    }
+    $comp_sp_table[$comp_sp_count][0] = substr($_, 4, 10);
+    $comp_sp_table[$comp_sp_count][1] = substr($_, 16, 10);
+    $comp_sp_count++;
+}
+
+$maxcombsplen = 2;     # one char have 2 codepoints, like a D8xx DCxx.
+
+for ($i = 0 ; $i < $comp_sp_count ; $i++) {
+    $base_sp = $comp_sp_table[$i][1];
+    $comblen = 2;
+    $j = 0;
+    while ($j < $comp_sp_count) {
+       if ($base_sp ne $comp_sp_table[$j][0]) {
+           $j++;
+           next;
+       } else {
+           $comblen += 2;
+           $base_sp =  $comp_sp_table[$j][1];
+           $j = 0;
+       }
+    }
+    $maxcombsplen = ($maxcombsplen > $comblen) ? $maxcombsplen : $comblen;
+}
+
+close(COMPOSE_SP_TEMP);
+
+# macro for buffer length (COMBBUFLEN) -------------------------------------
+
+$combbuflen = ($maxcomblen > $maxcombsplen) ? $maxcomblen : $maxcombsplen;
+
+# sort ---------------------------------------------------------------------
+
+system("sort -k 3 compose.TEMP \> precompose.SORT");
+system("sort -k 2 compose.TEMP \>  decompose.SORT");
+
+system("sort -k 3 compose_sp.TEMP \> precompose_sp.SORT");
+system("sort -k 2 compose_sp.TEMP \>  decompose_sp.SORT");
+
+# print  -------------------------------------------------------------------
+
+print ("\/\* DO NOT EDIT BY HAND\!\!\!                                           \*\/\n");
+print ("\/\* This file is generated by                                        \*\/\n");
+printf ("\/\*              contrib/misc/make-precompose.h.pl %s   \*\/\n", $ARGV[0]);
+print ("\n");
+printf ("\/\* %s is got from                                      \*\/\n", $ARGV[0]);
+print ("\/\* http\:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt            \*\/\n");
+print ("\n");
+
+print ("\#define SBASE 0xAC00\n");
+print ("\#define LBASE 0x1100\n");
+print ("\#define VBASE 0x1161\n");
+print ("\#define TBASE 0x11A7\n");
+print ("\#define LCOUNT 19\n");
+print ("\#define VCOUNT 21\n");
+print ("\#define TCOUNT 28\n");
+print ("\#define NCOUNT 588     \/\* (VCOUNT \* TCOUNT) \*\/\n");
+print ("\#define SCOUNT 11172   \/\* (LCOUNT \* NCOUNT) \*\/\n");
+print ("\n");
+
+printf ("\#define PRECOMP_COUNT %d\n", $comp_count);
+printf ("\#define DECOMP_COUNT %d\n", $comp_count);
+printf ("\#define MAXCOMBLEN %d\n", $maxcomblen);
+print ("\n");
+printf ("\#define PRECOMP_SP_COUNT %d\n", $comp_sp_count);
+printf ("\#define DECOMP_SP_COUNT %d\n", $comp_sp_count);
+printf ("\#define MAXCOMBSPLEN %d\n", $maxcombsplen);
+print ("\n");
+printf ("\#define COMBBUFLEN %d  \/\* max\(MAXCOMBLEN\,MAXCOMBSPLEN\) \*\/\n", $combbuflen);
+print ("\n");
+
+print ("static const struct \{\n");
+print ("  unsigned int replacement\;\n");
+print ("  unsigned int base\;\n");
+print ("  unsigned int comb\;\n");
+print ("\} precompositions\[\] \= \{\n");
+
+system("cat precompose.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+print ("static const struct \{\n");
+print ("  unsigned int replacement\;\n");
+print ("  unsigned int base\;\n");
+print ("  unsigned int comb\;\n");
+print ("\} decompositions\[\] \= \{\n");
+
+system("cat decompose.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+
+
+print ("static const struct \{\n");
+print ("  unsigned int replacement_sp\;\n");
+print ("  unsigned int base_sp\;\n");
+print ("  unsigned int comb_sp\;\n");
+print ("\} precompositions_sp\[\] \= \{\n");
+
+system("cat precompose_sp.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+print ("static const struct \{\n");
+print ("  unsigned int replacement_sp\;\n");
+print ("  unsigned int base_sp\;\n");
+print ("  unsigned int comb_sp\;\n");
+print ("\} decompositions_sp\[\] \= \{\n");
+
+system("cat decompose_sp.SORT");
+
+print ("\}\;\n");
+print ("\n");
+
+print ("\/\* EOF \*\/\n");
+
+# EOF
diff --git a/contrib/wireshark/cnid.lua b/contrib/wireshark/cnid.lua
deleted file mode 100644 (file)
index 3b21723..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
--- 
--- Netatalk DBD protocol 
--- wireshark -X lua_script:cnid.lua
--- don't forget to comment out the line disable_lua = true; do return end;
--- in /etc/wireshark/init.lua
-
--- global environment
-local b = _G
-
--- declare our protocol
-local dbd_proto = Proto("dbd","Netatalk Dbd Wire Protocol")
-
-local cmd = ProtoField.uint32("dbd.cmd", "Request") -- , base.HEX
-local len = ProtoField.uint32("dbd.name.len", "Name Length")
-local filename = ProtoField.string("dbd.name", "Name")
-local error = ProtoField.uint32("dbd.error", "Error code")
-local cnid = ProtoField.uint32("dbd.cnid", "Cnid")
-local did  = ProtoField.uint32("dbd.did", "Parent Directory Id")
-local dev  = ProtoField.uint64("dbd.dev", "Device number")
-local ino  = ProtoField.uint64("dbd.ino", "Inode number")
-local type = ProtoField.uint32("dbd.type", "File type")
-
-dbd_proto.fields = {cmd, error, cnid, did, dev, ino, type, filename, len}
-
---- Request list
-local Cmd = { [3] = "add", 
-             [4] = "get", 
-             [5] = "resolve", 
-             [6] = "lookup", 
-             [7] = "update", 
-             [8] = "delete", 
-             [11] = "timestamp" 
-           }
-
---- display a filename 
-local function fname(buffer, pinfo, tree, len, ofs)
-
-    pinfo.cols.info:append(" Name=" .. buffer(ofs +4, len):string())
-
-    local subtree = tree:add(buffer(ofs, len +4), buffer(ofs +4, len):string())
-    subtree:add(filename, buffer(ofs +4, len))
-
-    return subtree
-end
-
--- create a function to dissect it
-function dbd_proto.dissector(buffer, pinfo, tree)
-
-
-    pinfo.cols.protocol = "DBD"
-
-    local subtree = tree:add(dbd_proto,buffer(),"Netatalk DBD Wire Protocol")
-
-    if pinfo.dst_port == 4700 then
-           pinfo.cols.info = "Query"
-           local val = buffer(0,4):uint()
-           local item = subtree:add(cmd, buffer(0,4))
-           if Cmd[val] then
-               item:append_text(" (" .. Cmd[val] .. ")")
-               pinfo.cols.info = Cmd[val]
-
-               local val = buffer(4,4):uint()
-               if val ~= 0 then
-                       pinfo.cols.info:append(" Cnid=" .. val)
-               end
-               subtree:add(cnid, buffer(4, 4))
-               subtree:add(dev, buffer(8, 8))
-               subtree:add(ino, buffer(16, 8))
-               subtree:add(type, buffer(24, 4))
-
-               local val = buffer(28,4):uint()
-               if val ~= 0 then
-                  pinfo.cols.info:append(" Did=" .. val)
-               end
-               subtree:add(did, buffer(28, 4))
-
-               local val = buffer(36,4):uint()
-               if val ~= 0 then
-                  item = fname(buffer, pinfo, subtree, val, 36)
-                  item:add(len, buffer(36, 4))
-                       
-               end
-           end
-    else
-           pinfo.cols.info = "Reply"
-
-           local rply = {}
-           
-           local val = buffer(0,4):uint()
-           rply.error = val
-           subtree:add(error, buffer(0,4))
-           if val ~= 0 then
-               pinfo.cols.info:append(" Error=" .. val)
-           end
-
-           val = buffer(4,4):uint()
-           rply.cnid = val
-           subtree:add(cnid, buffer(4,4))
-           if val ~= 0 then
-               pinfo.cols.info:append(" Cnid=" .. val)
-           end
-
-           val = buffer(8,4):uint()
-           rply.did = val
-           subtree:add(did, buffer(8,4))
-           if val ~= 0 then
-               pinfo.cols.info:append(" Did=" .. val)
-           end
-
-           val = buffer(16,4):uint()
-           rply.len = val
-           
-           if rply.error == 0 and rply.did ~= 0 then
-              subtree = fname(buffer, pinfo, subtree, val, 16)
-              subtree:add(len, buffer(16,4))
-           end
-    end
-end
-
--- load the tcp.port table
-local tcp_table = DissectorTable.get("tcp.port")
--- register our protocol 
-tcp_table:add(4700, dbd_proto)
index ece70dd48953cb33e4523813de26eb1667c49e8e..50433c66de807a1dab6888ad7ca815a4cbd9729b 100644 (file)
@@ -755,24 +755,22 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
         /* Everything is fine */
         return db_cnid;
     } else if (ad_cnid && db_cnid && (ad_cnid != db_cnid)) {
-        /* Mismatch ? Delete both from db and re-add data from file */
+        /* Mismatch, overwrite ad file with value from db */
         dbd_log( LOGSTD, "CNID mismatch for '%s/%s', db: %u, ad-file: %u", cwdbuf, name, ntohl(db_cnid), ntohl(ad_cnid));
         if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
-            rqst.cnid = db_cnid;
-            ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID);
-            if (dbif_txn_close(dbd, ret) != 0)
-                return CNID_INVALID;
-
-            rqst.cnid = ad_cnid;
-            ret = dbd_delete(dbd, &rqst, &rply, DBIF_CNID);
-            if (dbif_txn_close(dbd, ret) != 0)
-                return CNID_INVALID;
-
-            ret = dbd_rebuild_add(dbd, &rqst, &rply);
-            if (dbif_txn_close(dbd, ret) != 0)
+            dbd_log(LOGSTD, "Updating AppleDouble file for '%s/%s' with CNID: %u from database",
+                            cwdbuf, name, ntohl(db_cnid));
+            ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+            if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
+                dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
+                        cwdbuf, name, strerror(errno));
                 return CNID_INVALID;
+            }
+            ad_setid( &ad, st->st_dev, st->st_ino, db_cnid, did, stamp);
+            ad_flush(&ad);
+            ad_close_metadata(&ad);
         }
-        return ad_cnid;
+        return db_cnid;
     } else if (ad_cnid && (db_cnid == 0)) {
         /* in ad-file but not in db */
         if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
@@ -782,7 +780,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
 
             rqst.cnid = ad_cnid;
             ret = dbd_resolve(dbd, &rqst, &rply);
-            if (ret == CNID_DBD_RES_OK) {
+            if (rply.result == CNID_DBD_RES_OK) {
                 /* Occupied! Choose another, update ad-file */
                 ret = dbd_add(dbd, &rqst, &rply, 1);
                 if (dbif_txn_close(dbd, ret) != 0)
index 90b2ffd3e1238b485406fde186492b536b9c2c30..f3a93e4ca54d3d9ae03fb3bd0f60771f3551542e 100644 (file)
@@ -48,6 +48,11 @@ int dbd_rebuild_add(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *
         return -1;
     }
 
+    LOG(log_debug, logtype_cnid,
+        "dbd_rebuild_add(CNID: %u, did: %u, name: \"%s\", dev/ino:0x%llx/0x%llx): success",
+        ntohl(rqst->cnid), ntohl(rqst->did), rqst->name,
+        (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
+
     key.data = ROOTINFO_KEY;
     key.size = ROOTINFO_KEYLEN;
 
index 17a42de0ff1a5f362885edd4826fd9bbbc6e0521..1c2e2da914bc0143df5d1c54f523be86c99e5281 100644 (file)
@@ -53,8 +53,8 @@ int dbd_resolve(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply
     rply->namelen = data.size;
     rply->name = (char *)data.data;
 
-    LOG(log_debug, logtype_cnid, "dbd_resolve: Resolving CNID %u to did %u name %s",
-        ntohl(rqst->cnid), ntohl(rply->did), rply->name);
+    LOG(log_debug, logtype_cnid, "dbd_resolve(CNID: %u): did: %u, name: \"%s\"",
+        ntohl(rqst->cnid), ntohl(rply->did), rply->name + CNID_NAME_OFS);
 
     rply->result = CNID_DBD_RES_OK;
     return 1;