docdiff 0.5.0 → 0.6.1
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.
- checksums.yaml +7 -0
- data/.travis.yml +5 -3
- data/Gemfile +1 -1
- data/Makefile +15 -19
- data/Rakefile +45 -10
- data/bin/docdiff +9 -11
- data/devutil/Rakefile +9 -0
- data/devutil/changelog.sh +40 -0
- data/docdiff.gemspec +4 -4
- data/docdiffwebui.cgi +1 -1
- data/langfilter.rb +1 -5
- data/lib/doc_diff.rb +5 -1
- data/lib/docdiff.rb +1 -1
- data/lib/docdiff/charstring.rb +6 -282
- data/lib/docdiff/diff.rb +2 -0
- data/lib/docdiff/diff/contours.rb +2 -1
- data/lib/docdiff/diff/editscript.rb +2 -0
- data/lib/docdiff/diff/rcsdiff.rb +2 -0
- data/lib/docdiff/diff/shortestpath.rb +2 -0
- data/lib/docdiff/diff/speculative.rb +6 -3
- data/lib/docdiff/diff/subsequence.rb +2 -0
- data/lib/docdiff/diff/unidiff.rb +2 -0
- data/lib/docdiff/difference.rb +2 -0
- data/lib/docdiff/document.rb +2 -0
- data/lib/docdiff/encoding/en_ascii.rb +3 -1
- data/lib/docdiff/encoding/ja_eucjp.rb +3 -1
- data/lib/docdiff/encoding/ja_sjis.rb +3 -1
- data/lib/docdiff/encoding/ja_utf8.rb +3 -1
- data/lib/docdiff/version.rb +1 -1
- data/lib/docdiff/view.rb +4 -10
- data/lib/viewdiff.rb +9 -5
- data/readme.html +23 -3
- data/readme.md +184 -0
- data/test/charstring_test.rb +13 -26
- data/test/diff_test.rb +2 -1
- data/test/difference_test.rb +2 -1
- data/test/docdiff_test.rb +9 -2
- data/test/document_test.rb +4 -6
- data/test/view_test.rb +3 -1
- data/test/viewdiff_test.rb +14 -11
- metadata +23 -29
- data/devutil/JIS0208.TXT +0 -6952
data/lib/docdiff/diff.rb
CHANGED
@@ -50,6 +50,7 @@ So, reduced input has following properties:
|
|
50
50
|
* Any elemnt in B is also exist in A.
|
51
51
|
|
52
52
|
=end
|
53
|
+
class DocDiff
|
53
54
|
class Diff
|
54
55
|
def initialize(a, b)
|
55
56
|
@original_a = a
|
@@ -215,3 +216,4 @@ class Diff
|
|
215
216
|
end
|
216
217
|
end
|
217
218
|
end
|
219
|
+
end # class DocDiff
|
@@ -46,6 +46,7 @@ Also in Nordic Journal of Computing (NJC), Vol. 2, No. 4, Winter 1995, 444 - 461
|
|
46
46
|
http://web.informatik.uni-bonn.de/IV/Mitarbeiter/rick/lcs.dvi.Z
|
47
47
|
=end
|
48
48
|
|
49
|
+
class DocDiff
|
49
50
|
class Diff
|
50
51
|
class Contours
|
51
52
|
def initialize(a, b)
|
@@ -379,4 +380,4 @@ class Diff
|
|
379
380
|
end
|
380
381
|
end
|
381
382
|
end
|
382
|
-
|
383
|
+
end # class DocDiff
|
data/lib/docdiff/diff/rcsdiff.rb
CHANGED
@@ -2,6 +2,7 @@ require 'docdiff/diff/shortestpath'
|
|
2
2
|
require 'docdiff/diff/contours'
|
3
3
|
require 'thread'
|
4
4
|
|
5
|
+
class DocDiff
|
5
6
|
class Diff
|
6
7
|
class Speculative
|
7
8
|
def initialize(a, b)
|
@@ -14,21 +15,22 @@ class Diff
|
|
14
15
|
result = nil
|
15
16
|
|
16
17
|
tg = ThreadGroup.new
|
18
|
+
m = Mutex.new
|
17
19
|
|
18
20
|
# Since ShortestPath is faster than Contours if two sequences are very similar,
|
19
21
|
# try it first.
|
20
22
|
tg.add(Thread.new {
|
21
23
|
#print "ShortestPath start.\n"
|
22
24
|
result = ShortestPath.new(@a, @b).lcs
|
23
|
-
|
25
|
+
m.synchronize {tg.list.each {|t| t.kill if t != Thread.current}}
|
24
26
|
#print "ShortestPath win.\n"
|
25
27
|
})
|
26
28
|
|
27
|
-
# start Contours unless ShortestPath is already ended with first quantum,
|
29
|
+
# start Contours unless ShortestPath is already ended with first quantum,
|
28
30
|
tg.add(Thread.new {
|
29
31
|
#print "Contours start.\n"
|
30
32
|
result = Contours.new(@a, @b).lcs
|
31
|
-
|
33
|
+
m.synchronize {tg.list.each {|t| t.kill if t != Thread.current}}
|
32
34
|
#print "Contours win.\n"
|
33
35
|
}) unless tg.list.empty?
|
34
36
|
|
@@ -38,3 +40,4 @@ class Diff
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
43
|
+
end # class DocDiff
|
data/lib/docdiff/diff/unidiff.rb
CHANGED
data/lib/docdiff/difference.rb
CHANGED
data/lib/docdiff/document.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# English ASCII encoding module for CharString
|
2
2
|
# 2003- Hisashi MORITA
|
3
3
|
|
4
|
+
class DocDiff
|
4
5
|
module CharString
|
5
6
|
module ASCII
|
6
7
|
|
@@ -94,4 +95,5 @@ module CharString
|
|
94
95
|
CharString.register_encoding(self)
|
95
96
|
|
96
97
|
end # module ASCII
|
97
|
-
end
|
98
|
+
end # module CharString
|
99
|
+
end # class DocDiff
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# Japanese EUC-JP encoding module for CharString
|
2
2
|
# 2003- Hisashi MORITA
|
3
3
|
|
4
|
+
class DocDiff
|
4
5
|
module CharString
|
5
6
|
module EUC_JP
|
6
7
|
|
@@ -266,4 +267,5 @@ module CharString
|
|
266
267
|
CharString.register_encoding(self)
|
267
268
|
|
268
269
|
end # module EUCJP
|
269
|
-
end
|
270
|
+
end # module CharString
|
271
|
+
end # class DocDiff
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# Japanese Shift_JIS encoding module for CharString
|
2
2
|
# 2003- Hisashi MORITA
|
3
3
|
|
4
|
+
class DocDiff
|
4
5
|
module CharString
|
5
6
|
module Shift_JIS
|
6
7
|
|
@@ -257,4 +258,5 @@ module CharString
|
|
257
258
|
CharString.register_encoding(self)
|
258
259
|
|
259
260
|
end # module SJIS
|
260
|
-
end
|
261
|
+
end # module CharString
|
262
|
+
end # class DocDiff
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# Japanese UTF-8 encoding module for CharString
|
3
3
|
# 2003- Hisashi MORITA
|
4
4
|
|
5
|
+
class DocDiff
|
5
6
|
module CharString
|
6
7
|
module UTF8
|
7
8
|
|
@@ -6971,4 +6972,5 @@ module CharString
|
|
6971
6972
|
CharString.register_encoding(self)
|
6972
6973
|
|
6973
6974
|
end # module UTF8
|
6974
|
-
end
|
6975
|
+
end # module CharString
|
6976
|
+
end # class DocDiff
|
data/lib/docdiff/version.rb
CHANGED
data/lib/docdiff/view.rb
CHANGED
@@ -21,6 +21,7 @@ class String
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
class DocDiff
|
24
25
|
class View
|
25
26
|
|
26
27
|
# EOL_CHARS_PAT = Regexp.new(/\r\n|\r(?!\n)|(?:\A|[^\r])\n/m)
|
@@ -84,16 +85,8 @@ class View
|
|
84
85
|
end
|
85
86
|
|
86
87
|
def encname_for_regexp(encname)
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
if ruby_m17n?
|
91
|
-
# in 1.9.x, encoding names are deprecated except for N (ASCII-8BIT (binary))
|
92
|
-
nil
|
93
|
-
else
|
94
|
-
# in 1.8.x, U|E|S|N are accepted
|
95
|
-
encname.sub(/US-ASCII/i, 'none')
|
96
|
-
end
|
88
|
+
# in 1.9.x, encoding names are deprecated except for N (ASCII-8BIT (binary))
|
89
|
+
nil
|
97
90
|
end
|
98
91
|
|
99
92
|
CONTEXT_PRE_LENGTH = 32
|
@@ -474,3 +467,4 @@ class View
|
|
474
467
|
end
|
475
468
|
|
476
469
|
end
|
470
|
+
end # class DocDiff
|
data/lib/viewdiff.rb
CHANGED
@@ -16,6 +16,7 @@ class String
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
class DocDiff
|
19
20
|
def scan_text_for_diffs(src)
|
20
21
|
eol = "(?:\r\n|\n|\r)"
|
21
22
|
pats = {
|
@@ -333,6 +334,7 @@ def anatomize_unified_hunk(a_hunk, src_encoding, src_eol)
|
|
333
334
|
body.scan(/(#{del}+)(#{add}+)|(#{del}+#{eol}?)|(#{add}+)|(#{common}+#{eol}?)|(.*#{eol}?)/m){|m|
|
334
335
|
cf, cl, d, a, cmn, msc = m[0..5]
|
335
336
|
[cf, cl, d, a, cmn, msc].collect{|e|
|
337
|
+
next if e.nil?
|
336
338
|
e.extend(CharString)
|
337
339
|
e.encoding, e.eol = src_encoding, src_eol
|
338
340
|
}
|
@@ -358,17 +360,19 @@ def anatomize_unified_hunk(a_hunk, src_encoding, src_eol)
|
|
358
360
|
}
|
359
361
|
return diffed
|
360
362
|
end
|
363
|
+
end # class DocDiff
|
361
364
|
|
362
365
|
if $0 == __FILE__
|
363
366
|
|
364
367
|
src = ARGF.read
|
365
|
-
enc, eol = CharString.guess_encoding(src),
|
366
|
-
|
367
|
-
|
368
|
+
enc, eol = DocDiff::CharString.guess_encoding(src),
|
369
|
+
DocDiff::CharString.guess_eol(src)
|
370
|
+
DocDiff.new.scan_text_for_diffs(src).each{|fragment|
|
371
|
+
if DocDiff::DiffFile.new('').guess_diff_type(fragment) == "unknown"
|
368
372
|
print fragment
|
369
373
|
else
|
370
|
-
diff = DiffFile.new(fragment).anatomize
|
371
|
-
print View.new(diff, enc, eol).to_tty
|
374
|
+
diff = DocDiff::DiffFile.new(fragment).anatomize
|
375
|
+
print DocDiff::View.new(diff, enc, eol).to_tty
|
372
376
|
end
|
373
377
|
}
|
374
378
|
|
data/readme.html
CHANGED
@@ -55,7 +55,7 @@
|
|
55
55
|
<body>
|
56
56
|
<h1>DocDiff Readme</h1>
|
57
57
|
<p>
|
58
|
-
2000
|
58
|
+
(C) 2000 Hisashi MORITA
|
59
59
|
</p>
|
60
60
|
|
61
61
|
<hr />
|
@@ -100,11 +100,31 @@
|
|
100
100
|
<span lang="ja">ニュース</span>
|
101
101
|
</h2>
|
102
102
|
<ul>
|
103
|
-
<!--
|
104
|
-
<li>
|
103
|
+
<!--
|
104
|
+
<li>x.y.z (xxxx-xx-xx)<ul>
|
105
105
|
<li></li>
|
106
106
|
</ul></li>
|
107
107
|
-->
|
108
|
+
<li>0.6.1 (2021-06-07)<ul>
|
109
|
+
<li>Update information in .gemspec.</li>
|
110
|
+
</ul></li>
|
111
|
+
<li>0.6.0 (2020-07-10)<ul>
|
112
|
+
<li>User-visible changes:<ul>
|
113
|
+
<li>Drop support for Ruby 1.8 (thanks to takahashim).</li>
|
114
|
+
<li>Fix various encoding problems (thanks to takahashim).</li>
|
115
|
+
<li>Add CP932 (Windows-31J) support through a new option <code>--cp932</code> (thanks to emasaka).</li>
|
116
|
+
<li>Introduce readme.md, which will obsolete readme.html eventually (thanks to takahashim).</li>
|
117
|
+
</ul></li>
|
118
|
+
<li>Developer-related changes:<ul>
|
119
|
+
<li>Use Mutex#synchronize instead of Thread.exclusive (thanks to hsbt).</li>
|
120
|
+
<li>Remove JIS0208.TXT to comply with its terms of use (thanks to kmuto).</li>
|
121
|
+
<li>Introduce top-level class DocDiff to avoid name conflict (thanks to hibariya).</li>
|
122
|
+
</ul></li>
|
123
|
+
</ul></li>
|
124
|
+
<li>0.5.0 (2011-08-12)<ul>
|
125
|
+
<li>Gemify. Now you can download docdiff via rubygems.org.</li>
|
126
|
+
<li>Fix failing test on ruby1.9.2-p290.</li>
|
127
|
+
</ul></li>
|
108
128
|
<li>0.4.0 (2011-02-23)<ul>
|
109
129
|
<li>Compatible with Ruby 1.9 (thanks to Kazuhiko).</li>
|
110
130
|
</ul></li>
|
data/readme.md
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# DocDiff
|
2
|
+
|
3
|
+
(C) 2000 Hisashi MORITA
|
4
|
+
|
5
|
+
## Todo
|
6
|
+
|
7
|
+
* Incorporate ignore space patch.
|
8
|
+
* Better auto-recognition of encodings and eols.
|
9
|
+
* Make CSS and tty escape sequence customizable in config files.
|
10
|
+
* Better multilingualization using Ruby 1.9 feature.
|
11
|
+
* Write "DocPatch".
|
12
|
+
|
13
|
+
|
14
|
+
## Description
|
15
|
+
|
16
|
+
Compares two text files by word, by character, or by line
|
17
|
+
|
18
|
+
## Summary
|
19
|
+
|
20
|
+
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.
|
21
|
+
|
22
|
+
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.
|
23
|
+
|
24
|
+
|
25
|
+
## Requirement
|
26
|
+
|
27
|
+
* Ruby (http://www.ruby-lang.org)
|
28
|
+
(Note that you may need additional ruby library such as iconv, if your OS's Ruby package does not include those.)
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Note that you need appropriate permission for proper installation (you may have to have a root/administrator privilege).
|
33
|
+
|
34
|
+
* Place `docdiff/` directory and its contents to ruby library directory, so that ruby interpreter can load them.
|
35
|
+
|
36
|
+
```
|
37
|
+
# cp -r docdiff /usr/lib/ruby/1.9.1
|
38
|
+
```
|
39
|
+
|
40
|
+
* Place `docdiff.rb` in command binary directory.
|
41
|
+
|
42
|
+
```
|
43
|
+
# cp docdiff.rb /usr/bin/
|
44
|
+
```
|
45
|
+
|
46
|
+
* (Optional) You may want to rename it to `docdiff`.
|
47
|
+
|
48
|
+
```
|
49
|
+
# mv /usr/bin/docdiff.rb /usr/bin/docdiff
|
50
|
+
```
|
51
|
+
|
52
|
+
* (Optional) When invoked as `chardiff` or `worddiff`, docdiff runs with resolution set to `char` or `word`, respectively.
|
53
|
+
|
54
|
+
```
|
55
|
+
# ln -s /usr/bin/docdiff.rb /usr/bin/chardiff.rb
|
56
|
+
# ln -s /usr/bin/docdiff.rb /usr/bin/worddiff.rb
|
57
|
+
```
|
58
|
+
|
59
|
+
* Set appropriate permission.
|
60
|
+
|
61
|
+
```
|
62
|
+
# chmod +x /usr/bin/docdiff.rb
|
63
|
+
```
|
64
|
+
|
65
|
+
* (Optional) If you want site-wide configuration file, place `docdiff.conf.example` as `/etc/docdiff/docdiff.conf` and edit it.
|
66
|
+
|
67
|
+
```
|
68
|
+
# cp docdiff.conf.example /etc/docdiff.conf
|
69
|
+
# $EDITOR /etc/docdiff.conf
|
70
|
+
```
|
71
|
+
|
72
|
+
* (Optional) If you want per-user configuration file, place `docdiff.conf.example` as `~/etc/docdiff/docdiff.conf` and edit it.
|
73
|
+
|
74
|
+
```
|
75
|
+
% cp docdiff.conf.example ~/etc/docdiff.conf
|
76
|
+
% $EDITOR ~/etc/docdiff.conf
|
77
|
+
```
|
78
|
+
|
79
|
+
## Usage
|
80
|
+
|
81
|
+
### Synopsis
|
82
|
+
|
83
|
+
% docdiff [options] oldfile newfile
|
84
|
+
|
85
|
+
e.g.
|
86
|
+
|
87
|
+
% docdiff old.txt new.txt > diff.html
|
88
|
+
|
89
|
+
See the help message for detail (`docdiff --help`).
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
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.
|
94
|
+
|
95
|
+
Copyright and condition of use of main portion of the source:
|
96
|
+
|
97
|
+
```
|
98
|
+
Copyright (C) Hisashi MORITA. All rights reserved.
|
99
|
+
|
100
|
+
Redistribution and use in source and binary forms, with or without
|
101
|
+
modification, are permitted provided that the following conditions
|
102
|
+
are met:
|
103
|
+
1. Redistributions of source code must retain the above copyright
|
104
|
+
notice, this list of conditions and the following disclaimer.
|
105
|
+
2. Redistributions in binary form must reproduce the above copyright
|
106
|
+
notice, this list of conditions and the following disclaimer in the
|
107
|
+
documentation and/or other materials provided with the distribution.
|
108
|
+
3. Neither the name of the University nor the names of its contributors
|
109
|
+
may be used to endorse or promote products derived from this software
|
110
|
+
without specific prior written permission.
|
111
|
+
|
112
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
113
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
114
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
115
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
116
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
117
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
118
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
119
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
120
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
121
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
122
|
+
SUCH DAMAGE.
|
123
|
+
```
|
124
|
+
|
125
|
+
diff library (`docdiff/diff.rb` and `docdiff/diff/*`) was originally a part of Ruby/CVS by Akira TANAKA.
|
126
|
+
Ruby/CVS is licensed under modified BSD style license.
|
127
|
+
See the following for detail.
|
128
|
+
|
129
|
+
* http://raa.ruby-lang.org/list.rhtml?name=ruby-cvs
|
130
|
+
* http://cvs.m17n.org/~akr/ruby-cvs/
|
131
|
+
|
132
|
+
## Credits
|
133
|
+
|
134
|
+
* Hisashi MORITA (primary author)
|
135
|
+
|
136
|
+
## Acknowledgments
|
137
|
+
|
138
|
+
* Akira TANAKA (diff library author)
|
139
|
+
* Shin'ichiro HARA (initial idea and algorithm suggestion)
|
140
|
+
* Masatoshi SEKI (patch)
|
141
|
+
* Akira YAMADA (patch, Debian package)
|
142
|
+
* Kenshi MUTO (testing, bug report, Debian package)
|
143
|
+
* Kazuhiro NISHIYAMA (bug report)
|
144
|
+
* Hiroshi OHKUBO (bug report)
|
145
|
+
* Shugo MAEDA (bug report)
|
146
|
+
* Kazuhiko (patch)
|
147
|
+
* Shintaro Kakutani (patches)
|
148
|
+
* Masayoshi Takahashi (patches)
|
149
|
+
* Masakazu Takahashi (patch)
|
150
|
+
* Hibariya (bug report)
|
151
|
+
* Hiroshi SHIBATA (patch)
|
152
|
+
|
153
|
+
Excuse us this list is far from complete and fails to acknowledge many
|
154
|
+
more who have helped us somehow. We really appreciate it.
|
155
|
+
|
156
|
+
## Resources
|
157
|
+
|
158
|
+
### Format
|
159
|
+
|
160
|
+
* HTML/XHTML http://www.w3.org
|
161
|
+
* tty (Graphic rendition using VT100 / ANSI escape sequence)
|
162
|
+
* VT100: http://vt100.net/docs/tp83/appendixb.html
|
163
|
+
* ANSI: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
|
164
|
+
* Manued (Manuscript Editing language: a proofreading method for text)
|
165
|
+
* http://www.archi.is.tohoku.ac.jp/~yamauchi/otherprojects/manued/index.shtml
|
166
|
+
|
167
|
+
### Similar Software
|
168
|
+
|
169
|
+
There are several other software that can compare text word by word and/or character by character.
|
170
|
+
|
171
|
+
* GNU wdiff (Seems to support single byte characters only.)
|
172
|
+
http://www.gnu.org/directory/GNU/wdiff.html
|
173
|
+
* cdif by Kazumasa UTASHIRO (Supports several Japanese encodings.)
|
174
|
+
http://srekcah.org/~utashiro/perl/scripts/cdif
|
175
|
+
* ediff for Emacsen
|
176
|
+
http://www.xemacs.org/Documentation/packages/html/ediff.html
|
177
|
+
* diff-detail for xyzzy, by Hiroshi OHKUBO
|
178
|
+
http://ohkubo.s53.xrea.com/xyzzy/index.html#diff-detail
|
179
|
+
* Manuediff (Outputs difference in Manued format.)
|
180
|
+
http://hibiki.miyagi-ct.ac.jp/~suzuki/comp/export/manuediff.html
|
181
|
+
* YASDiff (Yet Another Scheme powered diff) by Y. Fujisawa
|
182
|
+
http://nnri.dip.jp/~yf/cgi-bin/yaswiki2.cgi?name=YASDiff&parentid=0
|
183
|
+
* WinMerge (GUI diff tool for Windows)
|
184
|
+
http://winmerge.org/
|