Skip to content

Instantly share code, notes, and snippets.

@matvore
Created February 24, 2016 17:25
Show Gist options
  • Save matvore/f0fe86c2e6774c415b4f to your computer and use it in GitHub Desktop.
Save matvore/f0fe86c2e6774c415b4f to your computer and use it in GitHub Desktop.
ほー連想のコードをSTDOUTに出力
#!/usr/bin/perl
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ほー連想ダイレクトリーにコピーして実行してください。
use strict;
use utf8;
use warnings;
use FindBin;
use lib $FindBin::Bin;
use CodeMap;
use ReadCodes;
binmode STDOUT, ':utf8';
my $shiftable_keys = '1234567890qwertyuiopasdfghjkl;zxcvbnm,./';;
my $unshiftable_keys;
if (ReadCodes::keyboard_layout('jpn')) {
$unshiftable_keys = q{ -^\@[:]_};
} else {
$unshiftable_keys = q{ -=\[]'`};
}
my $code_map = CodeMap->new();
ReadCodes::process_lines {
my ($key, $value, %notes_by_prefix) = @_;
$code_map->register(
$key, ReadCodes::sorted_variants($value, %notes_by_prefix));
};
$code_map->register_autogenerated_codes();
sub output_codes {
my ($prefix) = @_;
my $value = $code_map->lookup($prefix);
if ($value) {
print "$prefix\t$value\n";
return;
}
# 未割り当て漢字を表示しない。
return if length($prefix) > 3;
return if $prefix && !$code_map->is_code_prefix($prefix);
for my $shiftable_key (split q{}, $shiftable_keys) {
my $concated = $prefix . $shiftable_key;
output_codes($concated);
$concated = ReadCodes::shift_last_char($concated);
output_codes($concated);
}
for my $unshiftable_key (split q{}, $unshiftable_keys) {
my $concated = $prefix . $unshiftable_key;
output_codes($concated);
}
}
output_codes q{};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment