docdiff 0.6.2 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +29 -52
  3. data/README.md +352 -0
  4. data/README_ja.md +352 -0
  5. data/Rakefile +2 -42
  6. data/bin/docdiff +1 -185
  7. data/{docdiff.conf.example → doc/example/docdiff.conf.example} +4 -3
  8. data/doc/man/docdiff.adoc +146 -0
  9. data/doc/news.md +189 -0
  10. data/doc/shell_completion/_docdiff.zsh +51 -0
  11. data/doc/shell_completion/docdiff.bash +68 -0
  12. data/docdiff.gemspec +2 -0
  13. data/lib/doc_diff.rb +19 -40
  14. data/lib/docdiff/cli.rb +281 -0
  15. data/lib/docdiff/version.rb +1 -1
  16. data/lib/docdiff/view.rb +22 -10
  17. data/test/charstring_test.rb +121 -121
  18. data/test/cli_test.rb +312 -0
  19. data/test/docdiff_test.rb +0 -23
  20. data/test/document_test.rb +109 -109
  21. data/test/fixture/01_ja_utf8_lf.txt +2 -0
  22. data/test/fixture/02_ja_utf8_lf.txt +2 -0
  23. data/test/fixture/format_wdiff.conf +1 -0
  24. data/test/fixture/simple.conf +9 -0
  25. data/test/view_test.rb +135 -111
  26. metadata +58 -37
  27. data/devutil/changelog.sh +0 -40
  28. data/index.html +0 -181
  29. data/langfilter.rb +0 -10
  30. data/readme.html +0 -750
  31. data/readme.md +0 -185
  32. /data/{docdiffwebui.cgi → doc/example/docdiffwebui.cgi} +0 -0
  33. /data/{docdiffwebui.html → doc/example/docdiffwebui.html} +0 -0
  34. /data/{img/docdiff-screenshot-format-html-digest-firefox.png → doc/img/screenshot-format-html-digest-firefox.png} +0 -0
  35. /data/{img/docdiff-screenshot-format-html-firefox.png → doc/img/screenshot-format-html-firefox.png} +0 -0
  36. /data/{img/docdiff-screenshot-format-tty-cmdexe-en.png → doc/img/screenshot-format-tty-cmdexe-en.png} +0 -0
  37. /data/{img/docdiff-screenshot-format-tty-cmdexe-ja.png → doc/img/screenshot-format-tty-cmdexe-ja.png} +0 -0
  38. /data/{img/docdiff-screenshot-format-tty-rxvtunicode-en.png → doc/img/screenshot-format-tty-rxvtunicode-en.png} +0 -0
  39. /data/{img/docdiff-screenshot-format-tty-rxvtunicode-ja.png → doc/img/screenshot-format-tty-rxvtunicode-ja.png} +0 -0
  40. /data/{img/docdiff-screenshot-format-tty-xterm-en.png → doc/img/screenshot-format-tty-xterm-en.png} +0 -0
  41. /data/{img/docdiff-screenshot-format-tty-xterm-ja.png → doc/img/screenshot-format-tty-xterm-ja.png} +0 -0
  42. /data/{img/docdiff-screenshot-resolution-linewordchar-xterm.png → doc/img/screenshot-resolution-linewordchar-xterm.png} +0 -0
  43. /data/{sample/01.en.ascii.cr → test/fixture/01_en_ascii_cr.txt} +0 -0
  44. /data/{sample/01.en.ascii.crlf → test/fixture/01_en_ascii_crlf.txt} +0 -0
  45. /data/{sample/01.en.ascii.lf → test/fixture/01_en_ascii_lf.txt} +0 -0
  46. /data/{sample/01.ja.eucjp.lf → test/fixture/01_ja_eucjp_lf.txt} +0 -0
  47. /data/{sample/01.ja.sjis.cr → test/fixture/01_ja_sjis_cr.txt} +0 -0
  48. /data/{sample/01.ja.sjis.crlf → test/fixture/01_ja_sjis_crlf.txt} +0 -0
  49. /data/{sample/01.ja.utf8.crlf → test/fixture/01_ja_utf8_crlf.txt} +0 -0
  50. /data/{sample/02.en.ascii.cr → test/fixture/02_en_ascii_cr.txt} +0 -0
  51. /data/{sample/02.en.ascii.crlf → test/fixture/02_en_ascii_crlf.txt} +0 -0
  52. /data/{sample/02.en.ascii.lf → test/fixture/02_en_ascii_lf.txt} +0 -0
  53. /data/{sample/02.ja.eucjp.lf → test/fixture/02_ja_eucjp_lf.txt} +0 -0
  54. /data/{sample/02.ja.sjis.cr → test/fixture/02_ja_sjis_cr.txt} +0 -0
  55. /data/{sample/02.ja.sjis.crlf → test/fixture/02_ja_sjis_crlf.txt} +0 -0
  56. /data/{sample/02.ja.utf8.crlf → test/fixture/02_ja_utf8_crlf.txt} +0 -0
  57. /data/{sample/humpty_dumpty01.ascii.lf → test/fixture/humpty_dumpty01_ascii_lf.txt} +0 -0
  58. /data/{sample/humpty_dumpty02.ascii.lf → test/fixture/humpty_dumpty02_ascii_lf.txt} +0 -0
data/README_ja.md ADDED
@@ -0,0 +1,352 @@
1
+ # DocDiff
2
+
3
+ * [English](README.md) | Japanese
4
+
5
+ (C) 2000 Hisashi MORITA
6
+
7
+ ## 簡単な説明
8
+
9
+ 2つのテキストファイルを単語ごと、文字ごと、あるいは行ごとに比較する
10
+
11
+ ## スクリーンショット
12
+
13
+ <div style="display: grid; grid-template-columns: 1fr 1fr;">
14
+
15
+ <p>HTML出力<br />
16
+ <img src="doc/img/screenshot-format-html-firefox.png" alt="HTML output"/></p>
17
+
18
+ <p>HTML出力(ダイジェスト)<br />
19
+ <img src="doc/img/screenshot-format-html-digest-firefox.png" alt="HTML output (digest)" /></p>
20
+
21
+ <p>tty出力<br />
22
+ <img src="doc/img/screenshot-format-tty-rxvtunicode-en.png" alt="tty output" /></p>
23
+
24
+ <p>tty出力(日本語のテキストを比較)<br />
25
+ <img src="doc/img/screenshot-format-tty-rxvtunicode-ja.png" alt="tty output (comparing Japanese text)" /></p>
26
+
27
+ <p>tty出力<br />
28
+ <img src="doc/img/screenshot-format-tty-xterm-en.png" alt="tty output" /></p>
29
+
30
+ <p>tty出力(日本語のテキストを比較)<br />
31
+ <img src="doc/img/screenshot-format-tty-xterm-ja.png" alt="tty output (comparing Japanese text)" /></p>
32
+
33
+ </div>
34
+
35
+ <p>英語のテキスト(コードページ437)を比較(Windows上のCygwin環境)<br />
36
+ <img src="doc/img/screenshot-format-tty-cmdexe-en.png" alt="Comparing English text (codepage 437) on Windows (Cygwin)" /></p>
37
+
38
+ <p>日本語のテキスト(コードページ937)を比較(Windows上のCygwin環境)<br />
39
+ <img src="doc/img/screenshot-format-tty-cmdexe-ja.png" alt="Comparing Japanese text (codepage 932) on Windows (Cygwin)" /></p>
40
+
41
+ <p>行ごと、単語ごと、文字ごとの比較が可能(フォーマットはtty)<br/>
42
+ <img src="doc/img/screenshot-resolution-linewordchar-xterm.png" alt="You can compare text files by line, word, or character (format: tty)" /></p>
43
+
44
+ (バージョン0.3.2時点のスクリーンショットです。)
45
+
46
+ ## 概要
47
+
48
+ DocDiffは2つのテキストファイルを比較してその違いを表示します。単語ごと、文字ごと、そして行ごとにファイルを比較できます。結果を出力する形式は、HTML、tty(文字端末向けのエスケープシーケンス)、Manued(真鵺道という校正用のマークアップ形式)などが用意されており、ユーザ定義のタグを使うこともできます。
49
+
50
+ 次のエンコーディング(文字コード)と行末コード(改行文字)をサポートしています: ASCII(およびISO-8859-*などのシングルバイトエンコーディング)、UTF-8、EUC-JP、Shift_JIS(Windows-31J)、そしてCR、LF、CRLF。
51
+
52
+ ## 使い方
53
+
54
+ ### 概要
55
+
56
+ ```
57
+ $ docdiff [options] oldfile newfile
58
+ ```
59
+
60
+ e.g.
61
+
62
+ ```
63
+ $ docdiff old.txt new.txt > diff.html
64
+ ```
65
+
66
+ 詳しくはヘルプメッセージを参照してください(`docdiff --help`)。
67
+
68
+ ### 例
69
+
70
+ <pre>
71
+ $ cat 01_ja_eucjp_lf.txt
72
+ こんにちは、私の名前はわたなべです。
73
+ 私はJust Another Ruby Porterです。
74
+ $ cat 02_ja_eucjp_lf.txt
75
+ こんばんは、私の名前はまつもとです。
76
+ Rubyを作ったのは私です。私はRuby Hackerです。
77
+ $ docdiff --tty 01_ja_eucjp_lf.txt 02_ja_eucjp_lf.txt
78
+ <span class="before-change" style="background: yellow; border: thin inset;"><del>こんにちは</del></span><span class="after-change" style="background: lime; font-weight: bolder; border: thin outset;"><ins>こんばんは</ins></span>、私の<span class="before-change" style="background: yellow; border: thin inset;"><del>名前はわたなべです</del></span><span class="after-change" style="background: lime; font-weight: bolder; border: thin outset;"><ins>名前はまつもとです</ins></span>。
79
+ <span class="add" style="background: deepskyblue; font-weight: bolder; border: thin outset;"><ins>Rubyを作ったのは私です。</ins></span>私は<span class="del" style="background: hotpink; border: thin inset;"><del>Just Another </del></span>Ruby <span class="before-change" style="background: yellow; border: thin inset;"><del>Porter</del></span><span class="after-change" style="background: lime; font-weight: bolder; border: thin outset;"><ins>Hacker</ins></span>です。
80
+ $
81
+ </pre>
82
+
83
+ ## 必要なソフトウェア
84
+
85
+ * 実行時に必要なソフトウェア:
86
+ - [Ruby](https://www.ruby-lang.org/) (>= 3.0)
87
+ * 開発時に必要なソフトウェア:
88
+ - [Test::Unit](https://test-unit.github.io/)
89
+ - Make ([GNU Make](https://www.gnu.org/software/make/))
90
+ - [Git](https://git-scm.com/)
91
+ - [md2html](https://github.com/mity/md4c)(ドキュメント生成用)
92
+ - [Rake](https://ruby.github.io/rake/)(オプショナル)
93
+ - sed, gzip, tar, etc.
94
+
95
+ ## インストール方法
96
+
97
+ いくつかのOSでは、DocDiffがパッケージとして提供されていることがあります。そのような場合は、それらのパッケージを使ってインストールするのが早道でしょう。
98
+
99
+ ### Debianパッケージ
100
+
101
+ サイト単位でのインストール:
102
+
103
+ ```
104
+ $ sudo apt update
105
+ $ sudo apt install docdiff
106
+ ```
107
+
108
+ ### Gemパッケージ
109
+
110
+ Rubyに詳しいならば、gemパッケージとしてDocDiffをインストールしたいと思うかもしれません。
111
+
112
+ ユーザ単位でのインストール([RubyGems.org](https://rubygems.org/)から):
113
+
114
+ ```
115
+ $ gem install docdiff
116
+ ```
117
+
118
+ ユーザ単位でのインストール(手元でのビルドから):
119
+
120
+ ```
121
+ $ rake build
122
+ $ gem install pkg/docdiff-X.Y.Z.gem
123
+ ```
124
+
125
+ (注意:Gemとしてインストールしたアプリケーションを起動するには、`PATH`環境変数を適切に設定する必要があります。[rbenv](https://github.com/rbenv/rbenv)などのRuby環境管理ツールを使うと便利かもしれません。)
126
+
127
+ ### Makeを使ってソースからインストールする
128
+
129
+ やむをえずMakeを使ってソースからDocDiffをインストールするときは、事前によくテストしてください。
130
+
131
+ `tmp`ディレクトリへのテストインストール:
132
+
133
+ ```
134
+ $ mkdir tmp
135
+ $ make install DESTDIR=tmp PREFIX=/local
136
+ $ tree tmp || la -lR tmp
137
+ ```
138
+
139
+ ユーザ単位でのインストールの例(ファイルを上書きしたりディレクトリ構造を汚くしたりしかねないので、おすすめしませんが):
140
+
141
+ ```
142
+ $ make install DESTDIR=~ PREFIX=/local
143
+ ```
144
+
145
+ ## 設定
146
+
147
+ 設定ファイルは次の場所に配置すると有効になります:
148
+
149
+ * `/etc/docdiff/docdiff.conf`(サイト全体の設定)
150
+
151
+ * `~/.config/docdiff/docdiff.conf`(ユーザごとの設定)([`$XDG_CONFIG_HOME`](https://specifications.freedesktop.org/basedir/0.8/)参照)
152
+
153
+ (警告:`~/etc/docdiff/docdiff.conf`や`~/.docdiff/docdiff.conf`は、互換性のために今のところは有効なままですが、廃止される予定であり、使うことは推奨されません。また、同時に存在できるユーザ設定ファイルは一つだけです。)
154
+
155
+ 設定ファイルの記法は次のとおりです(`docdiff.conf.example`ファイルも参照してください。配布アーカイブに含まれているはずです):
156
+
157
+ ```
158
+ # comment
159
+ key1 = value
160
+ key2 = value
161
+ ...
162
+ ```
163
+
164
+ 値(value)は、数字として解釈できるもの以外は、すべて文字列として扱われます。数字は数値(たいていは整数)として扱われます。
165
+
166
+ ## 問題解決とヒント
167
+
168
+ ### Wrong argument type nil (expected Module) (TypeError)
169
+
170
+ DocDiffがたまにエンコーディングや行末文字の自動判定に失敗して、次のようなエラーを出力することがあります。
171
+
172
+ ```
173
+ charstring.rb:47:in `extend': wrong argument type nil (expected Module) (TypeError)
174
+ ```
175
+
176
+ このような場合は、エンコーディングや行末文字を明示的に指定してみてください(e.g. `docdiff --utf8 --crlf`)。
177
+
178
+ ### 不適切な挿入と削除
179
+
180
+ スペースで区切られたテキスト(英文やプログラムのソースコードなど)を比較しているときに、行末にある単語が、特に必要もないのにいったん削除されてからまた挿入されることがあります。これはDocDiffの単語分割機能に制限があるせいで起きます。テキストは次のように単語に分割されます。
181
+
182
+ * Text 1:
183
+ ```
184
+ foo bar
185
+ ```
186
+ (`"foo bar" => ["foo ", "bar"]`)
187
+
188
+ * Text 2:
189
+ ```
190
+ foo
191
+ bar
192
+ ```
193
+ (`"foo\nbar" => ["foo", "\n", "bar"]`)
194
+
195
+ * 比較した結果:
196
+ <pre>
197
+ <del>foo </del><ins>foo</ins><ins>
198
+ </ins>bar
199
+ </pre>
200
+ (`"<del>foo </del><ins>foo</ins><ins>\n</ins>bar"`)
201
+
202
+ Fooは(必要もないのに)削除されると同時に挿入されています。
203
+
204
+ 作者はこの問題をいつか解決したいと思っていますが、簡単ではなさそうです。もし空白を1つの要素として分割したなら(i.e. `["foo", " ", "bar"]`)、比較した結果出力される単語の並びが今よりも不自然になってしまいます。良い案があったら教えてください。
205
+
206
+ ### DocDiffをバージョン管理システムと組み合わせて使う
207
+
208
+ DocDiffをVCSの外部diffプログラムとして使いたければ、次のようにするとよいでしょう。
209
+
210
+ * Git:
211
+ ```
212
+ $ GIT_EXTERNAL_DIFF=~/bin/gitdocdiff.sh git diff
213
+ ```
214
+ `~/bin/gitdocdiff.sh`:
215
+ ```
216
+ #!/bin/sh
217
+ docdiff --ascii --lf --tty --digest $2 $5
218
+ ```
219
+
220
+ * Subversion:
221
+ ```
222
+ $ svn diff --diff-cmd=docdiff --extensions "--ascii --lf --tty --digest"
223
+ ```
224
+
225
+ (場合によっては`git diff --word-diff-regex="\w"`で十分なこともありますが。)
226
+
227
+ zshを使えば、いろいろな場所にある文書をDocDiffや他のユーティリティで自由に比較できます。次の例ではリポジトリ内の特定のリビジョンのfoo.htmlとウェブサイト上のfoo.htmlとを比較しています。
228
+
229
+ * Git:
230
+ ```
231
+ $ docdiff =(git show abc1234:foo.html) =(curl --silent http://www.example.org/foo.html)
232
+ ```
233
+
234
+ * Subversion:
235
+ ```
236
+ $ docdiff =(svn cat -r3 http://svn.example.org/repos/foo.html) =(curl --silent http://www.example.org/foo.html)
237
+ ```
238
+
239
+ ### プレーンテキストではない文書ファイルを比較する
240
+
241
+ 適切な変換ツールを使えば、プレーンテキスト以外のファイルも比較できる場合があります。
242
+
243
+ * PDF文書中のテキストを比較する:
244
+ ```
245
+ $ docdiff =(pdftotext foo.pdf -) =(pdftotext bar.pdf -)
246
+ ```
247
+
248
+ * HTML文書中のテキスト(タグを除く)を比較する:
249
+ ```
250
+ $ docdiff =(w3m -dump -cols 10000 foo.html) =(w3m -dump -cols 10000 http://www.example.org/foo.html)
251
+ ```
252
+
253
+ * Microsoft Word文書中のテキストを比較する:
254
+ ```
255
+ $ docdiff =(wvWare foo.doc | w3m -T text/html -dump -cols 10000) =(wvWare bar.doc | w3m -T text/html -dump -cols 10000)
256
+ ```
257
+
258
+ ### Latin-* (ISO-8859-*) のための回避策: ASCIIを指定する
259
+
260
+ 文字コードがLatin-* (ISO-8859-*) のテキストを扱うときは、文字コードに`ASCII`を指定してみてください。`ASCII`が指定されると、DocDiffは対象をシングルバイト文字のテキストとして扱います。
261
+
262
+ * Latin-1テキストを比較する:
263
+ ```
264
+ $ docdiff --encoding=ASCII latin-1-old.txt latin-1-new.txt
265
+ ```
266
+
267
+ ## ライセンス
268
+
269
+ このソフトウェアはいわゆる修正BSDスタイルライセンス(<http://www.opensource.org/licenses/bsd-license.php>(広告条項なし))のもとで配布されています。このソフトウェアに貢献すると、あなたは貢献したものが同ライセンスのもとに取り込まれることに同意したとみなされます。
270
+
271
+ ソースコードの主となる部分の著作権と使用条件は次のとおりです:
272
+
273
+ ```
274
+ Copyright (C) Hisashi MORITA. All rights reserved.
275
+
276
+ Redistribution and use in source and binary forms, with or without
277
+ modification, are permitted provided that the following conditions
278
+ are met:
279
+ 1. Redistributions of source code must retain the above copyright
280
+ notice, this list of conditions and the following disclaimer.
281
+ 2. Redistributions in binary form must reproduce the above copyright
282
+ notice, this list of conditions and the following disclaimer in the
283
+ documentation and/or other materials provided with the distribution.
284
+ 3. Neither the name of the University nor the names of its contributors
285
+ may be used to endorse or promote products derived from this software
286
+ without specific prior written permission.
287
+
288
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
289
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
290
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
292
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
293
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
294
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
295
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
296
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
297
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298
+ SUCH DAMAGE.
299
+ ```
300
+
301
+ Diffライブラリ(`lib/docdiff/diff.rb`および`lib/docdiff/diff/*`)は、もともと田中哲さんによるRuby/CVSの一部分でした。Ruby/CVSは修正BSDスタイルライセンスのもとで配布されています。詳細は次を参照してください。
302
+
303
+ * <http://raa.ruby-lang.org/list.rhtml?name=ruby-cvs>
304
+ * <http://cvs.m17n.org/~akr/ruby-cvs/>
305
+
306
+ ## クレジット
307
+
308
+ * Hisashi MORITA (author)
309
+
310
+ ## 謝辞
311
+
312
+ * Akira TANAKA (diff library author)
313
+ * Shin'ichiro HARA (initial idea and algorithm suggestion)
314
+ * Masatoshi SEKI (patch)
315
+ * Akira YAMADA (patch, Debian package)
316
+ * Kenshi MUTO (testing, bug report, Debian package)
317
+ * Kazuhiro NISHIYAMA (bug report)
318
+ * Hiroshi OHKUBO (bug report)
319
+ * Shugo MAEDA (bug report)
320
+ * Kazuhiko (patch)
321
+ * Shintaro Kakutani (patches)
322
+ * Masayoshi Takahashi (patches)
323
+ * Masakazu Takahashi (patch)
324
+ * Hibariya (bug report)
325
+ * Hiroshi SHIBATA (patch)
326
+ * Tamotsu Takahashi (patches)
327
+ * MIKAMI Yoshiyuki (patch)
328
+
329
+ このリストが全く不完全で、いろいろな形で貢献してくださった多くの方々へ謝意を表しそこねていることをお詫びします。本当にありがとうございます。
330
+
331
+ ## 情報源
332
+
333
+ ### フォーマット
334
+
335
+ * [HTML/XHTML](https://www.w3.org/)
336
+ * tty (Graphic rendition using VT100 / ANSI escape sequences)
337
+ - [VT100](https://vt100.net/docs/tp83/appendixb.html)
338
+ - [ANSI](https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html)
339
+ * [Manued](https://sundayresearch.eu/hitoshi/otherprojects/manued/) ([in Japanese](https://sundayresearch.eu/hitoshi/otherprojects/manued/index-j.html)) (Manuscript Editing Language: a proofreading method for text)
340
+
341
+ ### 同様の機能を備えたソフトウェア
342
+
343
+ テキストを単語単位や文字単位で比較することができるソフトウェアは、数多く存在します。
344
+
345
+ * CLI:
346
+ - [wdiff](https://www.gnu.org/software/wdiff/) (requires spaces between words)
347
+ - cdif / [sdif-tools](https://github.com/kaz-utashiro/sdif-tools)
348
+ * GUI:
349
+ - [WinMerge](https://winmerge.org/) (Windows)
350
+ * Editor extensions:
351
+ - [ediff](https://www.gnu.org/software/emacs/manual/html_mono/ediff.html) (Emacs)
352
+ - [diff-detail](http://ohkubo.s53.xrea.com/xyzzy/index.html#diff-detail) ([xyzzy](https://github.com/xyzzy-022/xyzzy))
data/Rakefile CHANGED
@@ -2,51 +2,11 @@ require 'rake/clean'
2
2
  require 'rake/testtask'
3
3
  require 'bundler/gem_tasks'
4
4
 
5
- RUBY = ENV['RUBY'] ||= 'ruby'
6
- DOCS = FileList['ChangeLog', 'readme.en.html', 'readme.ja.html',
7
- 'index.en.html', 'index.ja.html']
8
- DOCSRC = FileList['readme.html', 'index.html', 'img', 'sample']
9
- TESTS = FileList['test/*_test.rb']
10
- TESTLOGS = Dir.glob('test/*_test.rb').map{|f|
11
- File.basename(f).ext('log')
12
- }
13
-
14
- WWWUSER = ENV['WWWUSER'] ||= 'hisashim,docdiff'
15
- WWWSITE = ENV['WWWSITE'] ||= 'web.sourceforge.net'
16
- WWWSITEPATH = ENV['WWWSITEPATH'] ||= 'htdocs/'
17
- WWWDRYRUN = ENV['WWWDRYRUN'] ||= '--dry-run'
5
+ ENV['SOURCE_DATE_EPOCH'] ||= `git show --quiet --format=%ct HEAD`
18
6
 
19
7
  Rake::TestTask.new do |t|
20
- t.test_files = TESTS
8
+ t.test_files = FileList['test/*_test.rb']
21
9
  t.verbose = true
22
10
  end
23
11
 
24
12
  task :default => :test
25
-
26
- desc "generate documents"
27
- task :docs => DOCS
28
-
29
- file 'ChangeLog' do |t|
30
- sh "devutil/changelog.sh > #{t.name}"
31
- end
32
-
33
- rule(/.*\.(?:en|ja)\.html/ => proc{|tn| tn.gsub(/\.(?:en|ja)/, '')}) do |t|
34
- sh "#{RUBY} -E UTF-8 langfilter.rb" +
35
- " --#{t.name.gsub(/.*?\.(en|ja)\.html/){$1}}" +
36
- " #{t.prerequisites.first} > #{t.name}"
37
- end
38
-
39
- desc "force to rsync web contents"
40
- task :wwwupload do |t|
41
- sh "rake www WWWDRYRUN="
42
- end
43
-
44
- desc "rsync web contents"
45
- task :www => DOCSRC + DOCS do |t|
46
- sh "rsync #{WWWDRYRUN} -auv -e ssh --delete" +
47
- " --exclude='.svn' --exclude='.git'" +
48
- t.prerequisites.join(' ') +
49
- " #{WWWUSER}@#{WWWSITE}:#{WWWSITEPATH}"
50
- end
51
-
52
- CLEAN.include(DOCS, TESTLOGS)
data/bin/docdiff CHANGED
@@ -3,189 +3,5 @@
3
3
  # Copyright (C) 2002-2011 Hisashi MORITA
4
4
  # Requirements: Ruby (>= 2.0)
5
5
  require 'docdiff'
6
- require 'optparse'
7
6
 
8
- # do_config_stuff
9
-
10
- default_config = {
11
- :resolution => "word",
12
- :encoding => "auto",
13
- :eol => "auto",
14
- :format => "html",
15
- :cache => true,
16
- :digest => false,
17
- :verbose => false
18
- }
19
-
20
- clo = command_line_options = {}
21
-
22
- # if invoked as "worddiff" or "chardiff",
23
- # appropriate resolution is set respectively.
24
- case File.basename($0, ".*")
25
- when "worddiff" then; clo[:resolution] = "word"
26
- when "chardiff" then; clo[:resolution] = "char"
27
- end
28
-
29
- ARGV.options {|o|
30
- o.def_option('--resolution=RESOLUTION',
31
- possible_resolutions = ['line', 'word', 'char'],
32
- 'specify resolution (granularity)',
33
- possible_resolutions.join('|') + ' (default is word)'
34
- ){|s| clo[:resolution] = (s || "word")}
35
- o.def_option('--line', 'set resolution to line'){clo[:resolution] = "line"}
36
- o.def_option('--word', 'set resolution to word'){clo[:resolution] = "word"}
37
- o.def_option('--char', 'set resolution to char'){clo[:resolution] = "char"}
38
-
39
- o.def_option('--encoding=ENCODING',
40
- possible_encodings = ['ASCII','EUC-JP','Shift_JIS','CP932','UTF-8','auto'],
41
- 'specify character encoding',
42
- possible_encodings.join('|'), "(default is auto. try ASCII for single byte encodings such as ISO-8859-X)"
43
- ){|s| clo[:encoding] = (s || "auto")}
44
- o.def_option('--ascii', 'same as --encoding=ASCII'){clo[:encoding] = "ASCII"}
45
- o.def_option('--iso8859x', 'same as --encoding=ASCII'){clo[:encoding] = "ASCII"}
46
- o.def_option('--eucjp', 'same as --encoding=EUC-JP'){clo[:encoding] = "EUC-JP"}
47
- o.def_option('--sjis', 'same as --encoding=Shift_JIS'){clo[:encoding] = "Shift_JIS"}
48
- o.def_option('--cp932', 'same as --encoding=CP932'){clo[:encoding] = "CP932"}
49
- o.def_option('--utf8', 'same as --encoding=UTF-8'){clo[:encoding] = "UTF-8"}
50
-
51
- o.def_option('--eol=EOL',
52
- possible_eols = ['CR','LF','CRLF','auto'],
53
- 'specify end-of-line character',
54
- possible_eols.join('|') + ' (default is auto)'
55
- ){|s| clo[:eol] = (s || "auto")}
56
- o.def_option('--cr', 'same as --eol=CR'){clo[:eol] = "CR"}
57
- o.def_option('--lf', 'same as --eol=LF'){clo[:eol] = "LF"}
58
- o.def_option('--crlf', 'same as --eol=CRLF'){clo[:eol] = "CRLF"}
59
-
60
- o.def_option('--format=FORMAT',
61
- possible_formats = ['tty','manued','html','wdiff','stat','user'],
62
- 'specify output format',
63
- possible_formats.join('|'),
64
- "(default is html)",
65
- '(user tags can be defined in config file)'
66
- ){|s| clo[:format] = (s || "manued")}
67
- o.def_option('--tty', 'same as --format=tty'){clo[:format] = "tty"}
68
- o.def_option('--manued', 'same as --format=manued'){clo[:format] = "manued"}
69
- o.def_option('--html', 'same as --format=html'){clo[:format] = "html"}
70
- o.def_option('--wdiff', 'same as --format=wdiff'){clo[:format] = "wdiff"}
71
- o.def_option('--stat', 'same as --format=stat (not supported yet)'){clo[:format] = "stat"}
72
-
73
- o.def_option('--label LABEL', '-L LABEL',
74
- 'Use label instead of filename (not supported yet)'
75
- ){|s1, s2| clo[:label1], clo[:label2] = s1, s2}
76
-
77
- o.def_option('--digest', 'digest output, do not show all'){clo[:digest] = true}
78
- o.def_option('--summary', 'same as --digest'){clo[:digest] = true}
79
- o.def_option('--display=DISPLAY',
80
- possible_types = ['inline', 'multi'],
81
- 'specify presentation type (effective only with digest; experimental feature)',
82
- possible_types.join('|'),
83
- '(default is inline)'){|s| clo[:display] ||= s.downcase}
84
- o.def_option('--cache', 'use file cache (not supported yet)'){clo[:cache] = true}
85
- o.def_option('--no-config-file',
86
- 'do not read config files'){clo[:no_config_file] = true}
87
- o.def_option('--config-file=FILE',
88
- 'specify config file to read'){|s| clo[:config_file] = s}
89
- o.def_option('--verbose', 'run verbosely (not supported yet)'){clo[:verbose] = true}
90
-
91
- o.def_option('--help', 'show this message'){puts o; exit(0)}
92
- o.def_option('--version', 'show version'){puts DocDiff::AppVersion; exit(0)}
93
- o.def_option('--license', 'show license'){puts DocDiff::License; exit(0)}
94
- o.def_option('--author', 'show author(s)'){puts DocDiff::Author; exit(0)}
95
-
96
- o.on_tail("When invoked as worddiff or chardiff, resolution will be set accordingly.",
97
- "Config files: /etc/docdiff/docdiff.conf, ~/etc/docdiff/docdiff.conf")
98
-
99
- o.parse!
100
- } or exit(1)
101
-
102
- docdiff = DocDiff.new()
103
- docdiff.config.update(default_config)
104
- unless clo[:no_config_file] == true # process_commandline_option
105
- message = docdiff.process_config_file(DocDiff::SystemConfigFileName)
106
- if clo[:verbose] == true || docdiff.config[:verbose] == true
107
- STDERR.print message
108
- end
109
- # message = docdiff.process_config_file(DocDiff::UserConfigFileName)
110
- case
111
- when File.exist?(DocDiff::UserConfigFileName) && File.exist?(DocDiff::AltUserConfigFileName)
112
- raise "#{DocDiff::UserConfigFileName} and #{DocDiff::AltUserConfigFileName} cannot be used at the same time. Remove or rename either one."
113
- when File.exist?(DocDiff::UserConfigFileName)
114
- message = docdiff.process_config_file(DocDiff::UserConfigFileName)
115
- when File.exist?(DocDiff::AltUserConfigFileName)
116
- message = docdiff.process_config_file(DocDiff::AltUserConfigFileName)
117
- end
118
- if clo[:verbose] == true || docdiff.config[:verbose] == true
119
- STDERR.print message
120
- end
121
- end
122
- unless clo[:config_file].nil?
123
- if File.exist?(clo[:config_file])
124
- message = docdiff.process_config_file(clo[:config_file])
125
- else
126
- raise "#{clo[:config_file]} does not exist."
127
- end
128
- if clo[:verbose] == true || docdiff.config[:verbose] == true
129
- STDERR.pring message
130
- end
131
- end
132
- docdiff.config.update(clo)
133
-
134
- # config stuff done
135
-
136
- # process the documents
137
-
138
- file1_content = nil
139
- file2_content = nil
140
- raise "Try `#{File.basename($0)} --help' for more information." if ARGV[0].nil?
141
- raise "Specify at least 2 target files." unless ARGV[0] && ARGV[1]
142
- ARGV[0] = "/dev/stdin" if ARGV[0] == "-"
143
- ARGV[1] = "/dev/stdin" if ARGV[1] == "-"
144
- raise "No such file: #{ARGV[0]}." unless FileTest.exist?(ARGV[0])
145
- raise "No such file: #{ARGV[1]}." unless FileTest.exist?(ARGV[1])
146
- raise "#{ARGV[0]} is not readable." unless FileTest.readable?(ARGV[0])
147
- raise "#{ARGV[1]} is not readable." unless FileTest.readable?(ARGV[1])
148
- File.open(ARGV[0], "r"){|f| file1_content = f.read}
149
- File.open(ARGV[1], "r"){|f| file2_content = f.read}
150
-
151
- doc1 = nil
152
- doc2 = nil
153
-
154
- encoding1 = docdiff.config[:encoding]
155
- encoding2 = docdiff.config[:encoding]
156
- eol1 = docdiff.config[:eol]
157
- eol2 = docdiff.config[:eol]
158
-
159
- if docdiff.config[:encoding] == "auto"
160
- encoding1 = DocDiff::CharString.guess_encoding(file1_content)
161
- encoding2 = DocDiff::CharString.guess_encoding(file2_content)
162
- case
163
- when (encoding1 == "UNKNOWN" or encoding2 == "UNKNOWN")
164
- raise "Document encoding unknown (#{encoding1}, #{encoding2})."
165
- when encoding1 != encoding2
166
- raise "Document encoding mismatch (#{encoding1}, #{encoding2})."
167
- end
168
- end
169
-
170
- if docdiff.config[:eol] == "auto"
171
- eol1 = DocDiff::CharString.guess_eol(file1_content)
172
- eol2 = DocDiff::CharString.guess_eol(file2_content)
173
- case
174
- when (eol1.nil? or eol2.nil?)
175
- raise "Document eol is nil (#{eol1.inspect}, #{eol2.inspect}). The document might be empty."
176
- when (eol1 == 'UNKNOWN' or eol2 == 'UNKNOWN')
177
- raise "Document eol unknown (#{eol1.inspect}, #{eol2.inspect})."
178
- when (eol1 != eol2)
179
- raise "Document eol mismatch (#{eol1}, #{eol2})."
180
- end
181
- end
182
-
183
- doc1 = DocDiff::Document.new(file1_content, encoding1, eol1)
184
- doc2 = DocDiff::Document.new(file2_content, encoding2, eol2)
185
-
186
- output = docdiff.run(doc1, doc2,
187
- {:resolution => docdiff.config[:resolution],
188
- :format => docdiff.config[:format],
189
- :digest => docdiff.config[:digest],
190
- :display => docdiff.config[:display]})
191
- print output
7
+ DocDiff::CLI.run
@@ -6,10 +6,11 @@
6
6
  # eol = LF
7
7
  # format = html
8
8
  # digest = off
9
- # cache = off # not implemented yet
10
- # verbose = no # not implemented yet
9
+ # cache = off # (not implemented) (deprecated)
10
+ # pager = less --raw-control-chars
11
+ # verbose = no # (not well-supported) (deprecated)
11
12
  #
12
- ## user-defined tags (not well-supported yet)
13
+ ## user-defined tags (not well-supported)
13
14
  # tag_common_start = '<=>'
14
15
  # tag_common_end = '</=>'
15
16
  # tag_del_start = '<->'