Annotation of OpenXM/src/asir-doc/jtexindex/Perl/jptexindex, Revision 1.1.1.1
1.1 noro 1: #!/usr/bin/jperl
2: # jptexindex -- 日本語対応 texindex
3: # Copyright (C) 1996, 1997 Mikio Nakajima <gy2m-nkjm@asahi-net.or.jp>
4:
5: # Author: Mikio Nakajima <gy2m-nkjm@asahi-net.or.jp>
6: # Created: Dec 12, 1996
7: # Last Modified: Sat Jan 25 18:15:08 1997
8: # Keywords: Texinfo, TeX, japanese
9: $Version = 0.5;
10: # This program is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either versions 2, or (at your option)
13: # any later version.
14:
15: # This program is distributed in the hope that it will be useful
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19:
20: # You should have received a copy of the GNU General Public License
21: # along with SKK, see the file COPYING. If not, write to the Free
22: # Software Foundation Inc., 59 Temple Place - Suite 330, Boston,
23: # MA 02111-1307, USA.
24:
25: # Commentary:
26: #
27: # 日本語対応 (というか Perl が split 関数を対応させている言語なら多分どんな言
28: # 語でも対応) の texindex です。
29: # Texinfo のインデクスコマンド (@cindex など) の引数に日本語を使うときは、
30: #
31: # @cindex インデクス[いんてくす]
32: # @cindex 言語[けんこ]
33: #
34: # などのように `@cindex 項目[よみ]' の形式で書くとこの texindex でソートして索
35: # 引を作ってくれます。
36:
37: # texindex.c の仕様を良く読んだわけではないので、何か忘れている仕事があるかも
38: # しれません。お気付きの点は是非お知らせ下さい。特に TeX コマンドでクォートさ
39: # れる文字は、
40: #
41: # `_' -> {\_}
42: # `^' -> {\tt\hat}
43: # `>' -> {\tt\gtr}
44: # `<' -> {\tt\less}
45: # `"' -> {\tt\char '042}
46: # `+' -> {\tt\char 43}
47: # `=' -> {\\tt\\char 61} #NTT jTeX only?
48: # `@' -> {\\tt\\char '100} #NTT jTeX only?
49: # `{' -> {\tt\char '173}
50: # `|' -> {\tt\char '174}
51: # `}' -> {\tt\char '175}
52: # `~' -> {\tt\char '176}
53: # `\' -> {\tt\indexbackslash }
54: #
55: #
56: # しか知らないので、漏れがあるかもしれません。
57:
58: # Change log:
59:
60: # Code:
61:
62: $CONVERTER = "nkf -e";
63: $Version .= " (January 25, 1997)";
64:
65: require "getopts.pl";
66: &Getopts(':v');
67:
68: die "jptexindex $Version\n" if $opt_v;
69:
70: foreach $rawfile (@ARGV){
71: $processedfile = $rawfile . "s";
72: # nkf を使う必要のない方は、下記 2 行をコメントアウトの上、85 行目の
73: # while(<IN>) を while(<>) に変更して下さい。
74: open(IN, "$CONVERTER $rawfile |") || die "Cannot run $CONVERTER: $!\n";
75: open(OUT, "> $processedfile") || die "Cannot open $processedfile: $!\n";
76:
77: #
78: # \entry{Makefile}{10}{\file {Makefile}}
79: # -> $item := Makefile, $page := 10, $realitem := {\file {Makefile}}
80: #
81: #initialize
82: %entries = ();
83: while(<IN>){
84: #while(<>){
85: ($item, $page, $realitem) = m/^\\entry(.+){([0-9]+)}(.+)$/o;
86: $item =~ s/{\\_}/_/o || $item =~ s/{\\tt\\hat}/^/o || $item =~ s/{\\tt\\gtr}/>/o ||
87: $item =~ s/{\\tt\\less}/</o || $item =~ s/{\\tt\\char *'042}/"/o ||
88: $item =~ s/{\\tt\\char *43}/+/o ||
89: $item =~ s/{\\tt\\char *61}/=/o || # NTT/jTeX only?
90: $item =~ s/{\\tt\\char *'100}/@/o || # NTT/jTeX only?
91: $item =~ s/{\\tt\\char *'173}/{/o ||
92: $item =~ s/{\\tt\\char *'174}/|/o || $item =~ s/{\\tt\\char *'175}/}/o ||
93: $item =~ s/{\\tt\\char *'176}/~/o || $item =~ s/{\\tt\\indexbackslash }/\\/o;
94: # {hogehoge} -> hogehoge
95: substr($item, 0, 2) = "";
96: chop($item);
97: # hogehoge -> HOGEHOGE
98: $item =~ tr/a-z/A-Z/;
99: # HOGEHOGE[ほげほげ] -> ほげほげ
100: if ($item =~ /^[^[]+\[([^]]+)\]$/o) {
101: $item = $1;
102: }
103: #print "\$item is ", $item, "\n";
104: if ($entries{$item} ne "") {
105: chop($entries{$item});
106: # \\entry{HOGEHOGE}{page1, page2}
107: $entries{$item} .= ", " . $page . "}";
108: }else {
109: if ($realitem =~ /^{([^[]+)\[[^]]+\]}$/o) {
110: # {HOGEHOGE[ほげほげ]} -> {HOGEHOGE}
111: $realitem = "{" . $1 . "}";
112: }
113: # \\entry{HOGEHOGE}{page}
114: $entries{$item} = "\\entry " . $realitem . "{" . $page . "}";
115: }
116: }
117: @chars= ();
118: # 見出し語でソート
119: foreach $key (sort keys(%entries)) {
120: # $key == HOGEHOGE
121: @chars = split(//, $key);
122: # $thisheadchar == $chars[0] == H
123: #print "\$chars[0] is ", $chars[0], "\n";
124: $thisheadchar = $chars[0];
125: $thisheadchar =~ s/_/{\\_}/o || $thisheadchar =~ s/\^/{\\tt\\hat}/o ||
126: $thisheadchar =~ s/>/{\\tt\\gtr}/o || $thisheadchar =~ s/</{\\tt\\less}/o ||
127: $thisheadchar =~ s/"/{\\tt\\char '042}/o || $thisheadchar =~ s/\+/{\\tt\\char 43}/o ||
128: $thisheadchar =~ s/=/{\\tt\\char 61}/o || $thisheadchar =~ s/@/{\\tt\\char '100}/o ||
129: $thisheadchar =~ s/{/{\\tt\\char '173}/o || $thisheadchar =~ s/\|/{\\tt\\char '174}/o ||
130: $thisheadchar =~ s/}/{\\tt\\char '175}/o || $thisheadchar =~ s/~/{\\tt\\char '176}/o ||
131: $thisheadchar =~ s/\\/{\\tt\\indexbackslash }/o;
132: #print "\$thisheadchar is ", $thisheadchar, "\n";
133: #print "\$headchar is", $headchar, "\n";
134: if ($thisheadchar ne $headchar){
135: print OUT "\\initial {", $thisheadchar, "}", "\n";
136: $headchar = $thisheadchar;
137: }
138: print OUT $entries{$key}, "\n";
139: }
140: }
141: # end of jtexindex
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>