# DocDiff Readme

(C) 2000 Hisashi MORITA

## Table of Contents 目次

- News
- Todo
- Description
- Summary
- Requirement
- Installation
- Usage
- Troubleshooting and Tips
- License
- Credits
- Acknowledgments
- Resources

- ニュース
- 予定
- 簡単な説明
- 概要
- 必要なもの
- インストール方法
- 使い方
- 問題解決とヒント
- ライセンス
- クレジット
- 謝辞
- 情報源

## News ニュース

- 0.6.0 (2020-07-10)
  - User-visible changes:
    - Drop support for Ruby 1.8 (thanks to takahashim).
    - Fix various encoding problems (thanks to takahashim).
    - Add CP932 (Windows-31J) support through a new option `--cp932` (thanks to emasaka).
    - Introduce readme.md, which will obsolete readme.html eventually (thanks to takahashim).
  - Developer-related changes:
    - Use Mutex#synchronize instead of Thread.exclusive (thanks to hsbt).
    - Remove JIS0208.TXT to comply with its terms of use (thanks to kmuto).
    - Introduce top-level class DocDiff to avoid name conflict (thanks to hibariya).
- 0.5.0 (2011-08-12)
  - Gemify. Now you can download docdiff via rubygems.org.
  - Fix failing test on ruby1.9.2-p290.
- 0.4.0 (2011-02-23)
  - Compatible with Ruby 1.9 (thanks to Kazuhiko).
- 0.3.4 (2007-12-10)
  - Increased context length in digest mode from 16 to 32.
  - Added --display=inline|multi option. With inline, things before change and things after change are displayed inline. With multi, they are displayed in separate blocks. Default is inline.
  - Added --iso8859x option as an alias to --encoding=ASCII, so that users notice DocDiff can handle text in ISO-8859-* encoding.
- 0.3.3 (2006-02-03)
  - Fixed arg test so that we can compare non-normal files, such as device files and named pipes (thanks to Shugo Maeda).
  - Added DocDiff Web UI sample (experimental).
  - Fixed HTML output to produce valid XHTML (thanks to Hiroshi OHKUBO). Note that CSS in HTML output is slightly changed.
  - Replaced underscores(_) in CSS class names to hyphens(-) so that older UAs can understand them (thanks to Kazuhiro NISHIYAMA).
- 0.3.2 (2005-01-03)
  - Readme is multilingualized (added partial Japanese translation). Try switching CSS between en and ja. Monolingual files are also available (readme.en.html, readme.ja.html).
  - Outputs better error messages when it failed to auto-detect the encoding and/or eol, though the accuracy is the same.
  - Switched revision control system from CVS to Subversion.
- 0.3.1 (2004-08-29)
  - Added -L (--label) option place holder in order to be used as external diff program from Subversion.
- 0.3.0 (2004-05-29)
  - Re-designed and re-written from scratch.
  - Supports multiple encodings (ASCII, EUC-JP, Shift_JIS, UTF-8) and multiple eols (CR, LF, CRLF).
  - Supports more output formats (tty, HTML, Manued, wdiff-like, user-defined markup text).
  - Supports configuration files (/etc/docdiff/docdiff.conf, ~/etc/docdiff/docdiff.conf (or ~/.docdiff/docdiff.conf)).
  - Introduced digest (summary) mode.
  - Approximately 200% faster than older versions, thanks to akr's diff library.
  - Better documentation and help message.
  - License changed from Ruby's to modified BSD style.
  - Pure Ruby. Does not require external diff program such as GNU diff, or morphological analyzer such as ChaSen.
  - Runs on both Unix and Windows (tested on Debian GNU/Linux and Cygwin)
  - Unit tests introduced to decrease bugs and to encourage faster development.
  - Makefile introduced.
- 0.1.8 (2003-12-14)
  - Displays warning when --bymorpheme is specified but ChaSen is not available (patch by Akira YAMADA: Debian bug #192258).
  - Supports system-wide configuration file (if ~/.chasenrc.docdiff does not exist, reads /etc/docdiff/chasenrc) (patch by Akira YAMADA: Debian bug #192261).
- 0.1.7 (2003-11-21)
  - HTML output retains spaces (&nbsp; patch by Akira YAMADA).
  - Manued output is added. Use --manued command line option to get result in Manued-like format.
  - Fixed .chasenrc.docdiff to be compatible with the latest ChaSen, so that it does not cause error.
  - Alphabet words in the output may look ugly, since ChaSen does not keep spaces between alphabetical words recently.
  - Other minor bug fixes and code cleanup.
- 0.2.0b2 (2001-08-31)
  - Code cleanup.
- 0.2.0b1 (2001-08-31)
  - A bit faster than 0.1.x, using file cache.
  - A bit cleaner code.
- 0.1.6 (2001-05-16)
  - Increased diff option number from 100000 to 1000000 in order to support 900KB+ text files.
- 0.1.5 (2001-01-17)
  - Erased useless old code which were already commented out.
  - Added documentation. (Updated README, more comments)
  - First public release. Registered to RAA.
- 0.1.4 (2001-01-16)
  - Output is like <tag>ab</tag>, instead of ugly <tag>a</tag><tag>b</tag> (thanks again to Masatoshi Seki for suggestion).
  - Fixed hidden bug ('puts' was used to output result).
  - Some code clean-up, though still hairy enough.
- 0.1.3 (2001-01-09)
  - Tested with Ruby 1.6.2.
  - Fixed "meth(a,b,)" bug (thanks to Masatoshi Seki).
  - Switched development platform from Windows to Linux, but it should work fine on Windows too, except for ChaSen stuff.
- 0.1.2 (2000-12-28)
  - Mostly bug fix.
- 0.1.1 (2000-12-25)
  - Bug fix and some cleanup.
  - Quotes some of HTML special characters (<>&) when output in HTML.
  - Added support for tty output using escape sequence.
- 0.1.0 (2000-12-19)
  - ChaSen works fine now.
  - GetOptLong was introduced to support command line options.
- 0.1.0a1 (2000-12-16)
  - Added ChaSen support. Japanese word by word comparison requires ChaSen.
  - Converted scripts from Shift_JIS/CRLF to EUC-JP/LF.
- 0.0.2 (2000-12-10)
  - Rewritten to use class.
- 0.0.1 (2000-12-09)
  - First version. Proof-of-concept.
  - Supports ASCII, EUC-JP, LF only.
  - Supports HTML output only.
  - Requires GNU diff.
  - Distributed under the same license as Ruby's

See the ChangeLog for detail.

## Todo 予定

- Incorporate ignore space patch.
- Better auto-recognition of encodings and eols.
- Make CSS and tty escape sequence customizable in config files.
- Better multilingualization using Ruby 1.9 feature.
- Write "DocPatch".

## Description 簡単な説明

Compares two text files by word, by character, or by line

2つのテキストファイルを単語ごと、文字ごと、あるいは行ごとに比較する

## Summary 概要

DocDiff compares two text files and shows the difference. It can compare files word by word, character by character, or line by line. It has several output formats such as HTML, tty, Manued, or user-defined markup.

DocDiffは2つのテキストファイルを比較してその違いを表示します。単語ごと、文字ごと、そして行ごとにファイルを比較できます。結果を出力する形式は、HTML, tty（文字端末向けのエスケープシーケンス）, Manued（真鵺道という校正用のマークアップ形式）などが用意されており、ユーザ定義のタグを使うこともできます。

It supports several encodings and end-of-line characters, including ASCII (and other single byte encodings such as ISO-8859-*), UTF-8, EUC-JP, Shift_JIS, CR, LF, and CRLF.

次のエンコーディング（文字コード）と行末コード（改行文字）をサポートしています: ASCII（およびISO-8859-*などのシングルバイトエンコーディング）, UTF-8, EUC-JP, Shift_JIS、そしてCR, LF, CRLF.

## Requirement 必要なもの

- Ruby
  (Note that you may need additional ruby library such as iconv, if your OS's Ruby package does not include those.)
- Ruby
  （注意: あなたが使っているOS向けのRubyパッケージがiconvなどのライブラリを含んでいない場合は、別途それらを手に入れる必要があるかもしれません。）

## Installation インストール方法

Note that you need appropriate permission for proper installation (you may have to have a root/administrator privilege).

注意: 正しくインストールするためには適切なファイルアクセス権限が必要です（管理者権限が必要な場合があります）。

1. Place `docdiff/` directory and its contents to ruby library directory, so that ruby interpreter can load them.
   (e.g.

   > `# `cp -r docdiff /usr/lib/ruby/1.9.1``

   )
2. Place `docdiff.rb` in command binary directory.
   (e.g.

   > `# `cp docdiff.rb /usr/bin/``

   )
   (Optional) You may want to rename it to `docdiff`.
   (e.g.

   > `# `mv /usr/bin/docdiff.rb /usr/bin/docdiff``

   )
   (Optional) When invoked as `chardiff` or `worddiff`, docdiff runs with resolution set to `char` or `word`, respectively.
   (e.g.

   > `# `ln -s /usr/bin/docdiff.rb /usr/bin/chardiff.rb``
   > `# `ln -s /usr/bin/docdiff.rb /usr/bin/worddiff.rb``

   )
3. Set appropriate permission.
   (e.g.

   > `# `chmod +x /usr/bin/docdiff.rb``

   )
4. (Optional) If you want site-wide configuration file, place `docdiff.conf.example` as `/etc/docdiff/docdiff.conf` and edit it.
   (e.g.

   > `# `cp docdiff.conf.example /etc/docdiff.conf`
   > # `$EDITOR /etc/docdiff.conf``

   )
5. (Optional) If you want per-user configuration file, place `docdiff.conf.example` as `~/etc/docdiff/docdiff.conf` and edit it.
   (e.g.

   > `% `cp docdiff.conf.example ~/etc/docdiff.conf`
   > % `$EDITOR ~/etc/docdiff.conf``

   )

1. `docdiff/`ディレクトリとその内容をrubyのライブラリを格納するディレクトリに配置して、Rubyインタプリタがdocdiffライブラリをロードできるようにする。
   (e.g.

   > `# `cp -r docdiff /usr/lib/ruby/1.9.1``

   )
2. `docdiff.rb`をコマンドを格納するディレクトリに配置する。
   (e.g.

   > `# `cp docdiff.rb /usr/bin/``

   )
   ここで必要に応じてファイル名を`docdiff`のように変更してもよい。
   (e.g.

   > `# `mv /usr/bin/docdiff.rb /usr/bin/docdiff``

   )
3. 適切なパーミッションを設定する。
   (e.g.

   > `# `chmod +x /usr/bin/docdiff.rb``

   )
4. (オプション) もしサイトの全ユーザに適用される設定ファイルが必要なら、`docdiff.conf.example`を`/etc/docdiff/docdiff.conf`として配置し、編集する。
   (e.g.

   > `# `cp docdiff.conf.example /etc/docdiff.conf`
   > # `$EDITOR /etc/docdiff.conf``

   )
5. (オプション) もしユーザごとの設定ファイルが必要なら、`docdiff.conf.example`を`~/etc/docdiff/docdiff.conf`として配置し、編集する。
   (e.g.

   > `% `cp docdiff.conf.example ~/etc/docdiff.conf`
   > % `$EDITOR ~/etc/docdiff.conf``

   )

## Usage 使い方

### Synopsis 概要

> `docdiff [options] oldfile newfile`
> e.g. `% `docdiff old.txt new.txt > diff.html``

See the help message for detail (`docdiff --help`).

詳しくはヘルプメッセージを参照してください（`docdiff --help`）。

### Example 例

> `% `cat sample/01.en.ascii.lf`
> Hello, my name is Watanabe.
> I am just another Ruby porter.
> % `cat sample/02.en.ascii.lf`
> Hello, my name is matz.
> It's me who has created Ruby. I am a Ruby hacker.
> % `docdiff sample/01.en.ascii.lf sample/02.en.ascii.lf`
> Hello, my name is Watanabe.matz.
> It's me who has created Ruby. I am just another a Ruby porter.hacker.
> %
> `

> `% `cat sample/01.ja.eucjp.lf`
> こんにちは、私の名前はわたなべです。
> 私はJust Another Ruby Porterです。
> % `cat sample/02.ja.eucjp.lf`
> こんばんは、私の名前はまつもとです。
> Rubyを作ったのは私です。私はRuby Hackerです。
> % `docdiff sample/01.ja.eucjp.lf sample/02.ja.eucjp.lf`
> こんにちはこんばんは、私の名前はわたなべです名前はまつもとです。
> Rubyを作ったのは私です。私はJust Another Ruby PorterHackerです。
> %
> `

### Configuration 設定

You can place configuration files at:

設定ファイルは次の場所に配置すると有効になります:

- `/etc/docdiff/docdiff.conf` (site-wide configuration)
- `~/etc/docdiff/docdiff.conf` (user configuration)
  (`~/etc/docdiff/docdiff.conf` is used by default in order to keep home directory clean, preventing dotfiles and dotdirs from scattering around. Alternatively, you can use `~/.docdiff/docdiff.conf` as user configuration file name, following the traditional Unix convention.)

- `/etc/docdiff/docdiff.conf`（サイト全体の設定）
- `~/etc/docdiff/docdiff.conf`（ユーザごとの設定）
  （標準の設定では、ホームディレクトリにドットファイルをまき散らかさないために、`~/etc/docdiff/docdiff.conf`が使われます。または、昔ながらのUnixの慣習に従って`~/.docdiff/docdiff.conf`を使ってももちろん構いません。ただし両方同時には使えません）

Notation is as follows (also refer to the file `docdiff.conf.example` included in the distribution archive):

設定ファイルの記法は次のとおりです（`docdiff.conf.example`ファイルも参照してください。配布アーカイブに含まれているはずです）:

> `# comment
> key1 = value
> key2 = value
> ...`

Every value is treated as string, unless it seems like a number. In such case, value is treated as a number (usually an integer).

値（value）は、数字として解釈できるもの以外は、すべて文字列として扱われます。数字は数値（たいていは整数）として扱われます。

## Troubleshooting and Tips 問題解決とヒント

### wrong argument type nil (expected Module) (TypeError) wrong argument type nil (expected Module) (TypeError)

Sometimes DocDiff fails to auto-recognize encoding and/or end-of-line character. You may get an error like this.

DocDiffがたまにエンコーディングや行末文字の自動判定に失敗して、次のようなエラーを出力することがあります。

> `charstring.rb:47:in `extend': wrong argument type nil (expected Module) (TypeError)
> `

In such a case, try explicitly specifying encoding and end-of-line character (e.g. `docdiff --utf8 --crlf`).

このような場合は、エンコーディングや行末文字を明示的に指定してみてください（e.g. `docdiff --utf8 --crlf`）。

### Inappropriate Insertion / Deletion 不適切な挿入と削除

When comparing space-separated texts (such as English or program source code), the word next to the end of line is sometimes unnecessarily deleted and inserted. This is due to the limitation of DocDiff's word splitter. It splits strings into words like the following.

スペースで区切られたテキスト（英文やプログラムのソースコードなど）を比較しているときに、行末にある単語が、特に必要もないのにいったん削除されてからまた挿入されることがあります。これはDocDiffの単語分割機能に制限があるせいで起きます。テキストは次のように単語に分割されます。

text 1:

> `foo bar
> ("foo bar" => ["foo ", "bar"])`

text 2:

> `foo
> bar
> ("foo\nbar" => ["foo", "\n", "bar"])`

comparison result:

> `foo foo
> bar
> ("<del>foo </del><ins>foo</ins><ins>\n</ins>bar")`

Foo is (unnecessarily) deleted and inserted at the same time.

Fooは（必要もないのに）削除されると同時に挿入されています。

I would like to fix this sometime, but it's not easy. If you split single space as single element (i.e. `["foo", " ", "bar"]`), the word order of the comparison result will be less natural. Suggestions are welcome.

作者はこの問題をいつか解決したいと思っていますが、簡単ではなさそうです。もし空白を1つの要素として分割したなら（i.e. `["foo", " ", "bar"]`）、比較した結果出力される単語の並びが今よりも不自然になってしまいます。良い案があったら教えてください。

### Using DocDiff with Version Control Systems DocDiffをバージョン管理システムと組み合わせて使う

If you want to use DocDiff as an external diff program from VCSs, the following may work.

DocDiffをVCSの外部diffプログラムとして使いたければ、次のようにするとよいでしょう。

Subversion

  `% `svn diff --diff-cmd=docdiff --extensions "--ascii --lf --tty --digest"``

Git

  `% `GIT_EXTERNAL_DIFF=~/bin/gitdocdiff.sh git diff``

  ~/bin/gitdocdiff.sh:

      #!/bin/sh
      docdiff --ascii --lf --tty --digest $2 $5

With zsh, you can use DocDiff or other utility to compare arbitrary sources. In the following example, we compare specific revision of foo.html in a repository with one on a website.

zshを使えば、いろいろな場所にある文書をDocDiffや他のユーティリティで自由に比較できます。次の例ではリポジトリ内の特定のリビジョンのfoo.htmlとウェブサイト上のfoo.htmlとを比較しています。

> CVS:
> `% `docdiff =(cvs -Q update -p -r 1.3 foo.html) =(curl --silent http://www.example.org/foo.html)``

> Subversion:
> `% `docdiff =(svn cat -r3 http://svn.example.org/repos/foo.html) =(curl --silent http://www.example.org/foo.html)``

### Comparing Non-plain Text Files Such As HTML or Microsoft Word Documents HTMLやWord文書などのプレーンテキストではないファイルを比較する

You can compare files other than plain text, such as HTML and Microsoft Word documents, if you use appropriate converter.

適切な変換ツールを使えば、HTMLやMicrosoft Word文書など、プレーンテキスト以外のファイルも比較できます。

> Comparing the content of two HTML documents (without tags) HTML文書の内容（タグを除く）を比較:
> `% `docdiff =(w3m -dump -cols 10000 foo.html) =(w3m -dump -cols 10000 http://www.example.org/foo.html)``

> Comparing the content of two Microsoft Word documents Microsoft Word文書の内容を比較:
> `% `docdiff =(wvWare foo.doc | w3m -T text/html -dump -cols 10000) =(wvWare bar.doc | w3m -T text/html -dump -cols 10000)``

### Workaround for Latin-* (ISO-8859-*) encodings: Use ASCII Latin-* (ISO-8859-*) のための回避策: ASCIIを指定する

If you want to compare Latin-* (ISO-8859-*) texts, try using ASCII as their encoding. When ASCII is specified, DocDiff assumes single-byte characters.

文字コードがLatin-* (ISO-8859-*) のテキストを扱うときは、文字コードにASCIIを指定してみてください。ASCIIが指定されると、DocDiffは対象をシングルバイト文字のテキストとして扱います。

> Comparing Latin-1 texts:
> `% `docdiff --encoding=ASCII latin-1-old.txt latin-1-new.txt``

## License ライセンス

This software is distributed under so-called modified BSD style license (http://www.opensource.org/licenses/bsd-license.php (without advertisement clause)). By contributing to this software, you agree that your contribution may be incorporated under the same license.

このソフトウェアはいわゆる修正BSDスタイルライセンス（http://www.opensource.org/licenses/bsd-license.php（広告条項なし））のもとで配布されています。このソフトウェアに貢献すると、あなたは貢献したものが同ライセンスのもとに取り込まれることに同意したとみなされます。

Copyright and condition of use of main portion of the source:

ソースコードの主となる部分の著作権と使用条件は次のとおりです:

>     Copyright (C) Hisashi MORITA.  All rights reserved.

>     Redistribution and use in source and binary forms, with or without
>     modification, are permitted provided that the following conditions
>     are met:
>     1. Redistributions of source code must retain the above copyright
>        notice, this list of conditions and the following disclaimer.
>     2. Redistributions in binary form must reproduce the above copyright
>        notice, this list of conditions and the following disclaimer in the
>        documentation and/or other materials provided with the distribution.
>     3. Neither the name of the University nor the names of its contributors
>        may be used to endorse or promote products derived from this software
>        without specific prior written permission.

>     THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
>     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
>     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
>     ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
>     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
>     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
>     OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
>     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
>     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
>     OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>     SUCH DAMAGE.

diff library (`docdiff/diff.rb` and `docdiff/diff/*`) was originally a part of Ruby/CVS by Akira TANAKA. Ruby/CVS is licensed under modified BSD style license. See the following for detail.

diffライブラリ（`docdiff/diff.rb`および`docdiff/diff/*`）は、もともと田中哲さんによるRuby/CVSの一部分でした。Ruby/CVSは修正BSDスタイルライセンスのもとで配布されています。詳細は次を参照してください。

- http://raa.ruby-lang.org/list.rhtml?name=ruby-cvs
- http://cvs.m17n.org/~akr/ruby-cvs/

## Credits クレジット

- Hisashi MORITA (primary author)

## Acknowledgments 謝辞

- Akira TANAKA (diff library author)
- Shin'ichiro HARA (initial idea and algorithm suggestion)
- Masatoshi SEKI (patch)
- Akira YAMADA (patch, Debian package)
- Kenshi MUTO (testing, bug report, Debian package)
- Kazuhiro NISHIYAMA (bug report)
- Hiroshi OHKUBO (bug report)
- Shugo MAEDA (bug report)
- Kazuhiko (patch)

## Resources 情報源

### Format フォーマット

- HTML/XHTML
  http://www.w3.org
- tty (Graphic rendition using VT100 / ANSI escape sequence)
  VT100: http://vt100.net/docs/tp83/appendixb.html
  ANSI: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
- Manued (Manuscript Editing language: a proofreading method for text)
  http://www.archi.is.tohoku.ac.jp/~yamauchi/otherprojects/manued/index.shtml

### Similar Software 同様の目的を持ったソフトウェア

There are several other software that can compare text word by word and/or character by character.

テキストを単語単位や文字単位で比較することができるソフトウェアは、ほかにもあります。

- GNU wdiff (Seems to support single byte characters only.)
  http://www.gnu.org/directory/GNU/wdiff.html
- cdif by Kazumasa UTASHIRO (Supports several Japanese encodings.)
  http://srekcah.org/~utashiro/perl/scripts/cdif
- ediff for Emacsen
  http://www.xemacs.org/Documentation/packages/html/ediff.html
- diff-detail for xyzzy, by Hiroshi OHKUBO
  http://ohkubo.s53.xrea.com/xyzzy/index.html#diff-detail
- Manuediff (Outputs difference in Manued format.)
  http://hibiki.miyagi-ct.ac.jp/~suzuki/comp/export/manuediff.html
- YASDiff (Yet Another Scheme powered diff) by Y. Fujisawa
  http://nnri.dip.jp/~yf/cgi-bin/yaswiki2.cgi?name=YASDiff&parentid=0
- WinMerge (GUI diff tool for Windows)
  http://winmerge.org/