docdiff 0.6.5 → 0.6.7
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 +4 -4
- data/Gemfile +7 -7
- data/Guardfile +4 -4
- data/Makefile +1 -1
- data/Rakefile +6 -6
- data/bin/docdiff +1 -1
- data/devutil/Rakefile +12 -5
- data/devutil/char_by_charclass.rb +43 -20
- data/devutil/charclass_by_char.rb +40 -19
- data/devutil/jis0208.rb +263 -231
- data/devutil/jis0208_test.rb +196 -0
- data/doc/news.md +15 -0
- data/docdiff.gemspec +12 -10
- data/lib/doc_diff.rb +59 -60
- data/lib/docdiff/charstring.rb +225 -241
- data/lib/docdiff/cli.rb +291 -250
- data/lib/docdiff/diff/contours.rb +1 -1
- data/lib/docdiff/diff/editscript.rb +1 -1
- data/lib/docdiff/diff/rcsdiff.rb +1 -1
- data/lib/docdiff/diff/shortestpath.rb +1 -1
- data/lib/docdiff/diff/speculative.rb +1 -1
- data/lib/docdiff/diff/subsequence.rb +1 -1
- data/lib/docdiff/diff/unidiff.rb +1 -1
- data/lib/docdiff/diff.rb +1 -1
- data/lib/docdiff/difference.rb +71 -70
- data/lib/docdiff/document.rb +129 -109
- data/lib/docdiff/encoding/en_ascii.rb +64 -58
- data/lib/docdiff/encoding/ja_eucjp.rb +250 -235
- data/lib/docdiff/encoding/ja_sjis.rb +240 -226
- data/lib/docdiff/encoding/ja_utf8.rb +6952 -6939
- data/lib/docdiff/version.rb +1 -1
- data/lib/docdiff/view.rb +522 -438
- data/lib/docdiff.rb +2 -2
- data/test/charstring_test.rb +475 -351
- data/test/cli_test.rb +103 -101
- data/test/diff_test.rb +15 -16
- data/test/difference_test.rb +40 -31
- data/test/docdiff_test.rb +162 -136
- data/test/document_test.rb +280 -175
- data/test/test_helper.rb +2 -1
- data/test/view_test.rb +636 -497
- metadata +8 -8
- data/devutil/testjis0208.rb +0 -38
data/lib/docdiff/cli.rb
CHANGED
|
@@ -1,281 +1,322 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "optparse"
|
|
2
2
|
|
|
3
3
|
class DocDiff
|
|
4
4
|
module CLI
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
parser
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
5
|
+
class << self
|
|
6
|
+
def parse_options!(args, base_options: {})
|
|
7
|
+
o = base_options.dup
|
|
8
|
+
|
|
9
|
+
option_parser = OptionParser.new do |parser|
|
|
10
|
+
parser.on(
|
|
11
|
+
"--resolution=RESOLUTION",
|
|
12
|
+
resolutions = ["line", "word", "char"],
|
|
13
|
+
"specify resolution (granularity)",
|
|
14
|
+
"#{resolutions.join("|")} (default: word)",
|
|
15
|
+
) { |s| o[:resolution] = (s || "word") }
|
|
16
|
+
parser.on("--line", "same as --resolution=line") { o[:resolution] = "line" }
|
|
17
|
+
parser.on("--word", "same as --resolution=word") { o[:resolution] = "word" }
|
|
18
|
+
parser.on("--char", "same as --resolution=char") { o[:resolution] = "char" }
|
|
19
|
+
|
|
20
|
+
parser.on(
|
|
21
|
+
'--encoding=ENCODING',
|
|
22
|
+
encodings = ['ASCII', 'EUC-JP', 'Shift_JIS', 'CP932', 'UTF-8', 'auto'],
|
|
23
|
+
encoding_aliases = {
|
|
24
|
+
"ascii" => "ASCII",
|
|
25
|
+
"euc-jp" => "EUC-JP",
|
|
26
|
+
"shift_jis" => "Shift_JIS",
|
|
27
|
+
"cp932" => "CP932",
|
|
28
|
+
"utf-8" => "UTF-8",
|
|
29
|
+
},
|
|
30
|
+
"specify character encoding",
|
|
31
|
+
"#{encodings.join("|")} (default: auto)",
|
|
32
|
+
"(try ASCII for single byte encodings such as ISO-8859)",
|
|
33
|
+
) { |s| o[:encoding] = (s || "auto") }
|
|
34
|
+
parser.on("--ascii", "same as --encoding=ASCII") { o[:encoding] = "ASCII" }
|
|
35
|
+
parser.on("--iso8859", "same as --encoding=ASCII") { o[:encoding] = "ASCII" }
|
|
36
|
+
parser.on("--iso8859x", "same as --encoding=ASCII (deprecated)") { o[:encoding] = "ASCII" }
|
|
37
|
+
parser.on("--eucjp", "same as --encoding=EUC-JP") { o[:encoding] = "EUC-JP" }
|
|
38
|
+
parser.on("--sjis", "same as --encoding=Shift_JIS") { o[:encoding] = "Shift_JIS" }
|
|
39
|
+
parser.on("--cp932", "same as --encoding=CP932") { o[:encoding] = "CP932" }
|
|
40
|
+
parser.on("--utf8", "same as --encoding=UTF-8") { o[:encoding] = "UTF-8" }
|
|
41
|
+
|
|
42
|
+
parser.on(
|
|
43
|
+
"--eol=EOL",
|
|
44
|
+
eols = ["CR", "LF", "CRLF", "auto"],
|
|
45
|
+
eol_aliases = { "cr" => "CR", "lf" => "LF", "crlf" => "CRLF" },
|
|
46
|
+
"specify end-of-line character",
|
|
47
|
+
"#{eols.join("|")} (default: auto)",
|
|
48
|
+
) { |s| o[:eol] = (s || "auto") }
|
|
49
|
+
parser.on("--cr", "same as --eol=CR") { o[:eol] = "CR" }
|
|
50
|
+
parser.on("--lf", "same as --eol=LF") { o[:eol] = "LF" }
|
|
51
|
+
parser.on("--crlf", "same as --eol=CRLF") { o[:eol] = "CRLF" }
|
|
52
|
+
|
|
53
|
+
parser.on(
|
|
54
|
+
"--format=FORMAT",
|
|
55
|
+
formats = ["tty", "manued", "html", "wdiff", "stat", "user"],
|
|
56
|
+
"specify output format",
|
|
57
|
+
"#{formats.join("|")} (default: html) (stat is deprecated)",
|
|
58
|
+
"(user tags can be defined in config file)",
|
|
59
|
+
) { |s| o[:format] = (s || "manued") }
|
|
60
|
+
parser.on("--tty", "same as --format=tty") { o[:format] = "tty" }
|
|
61
|
+
parser.on("--manued", "same as --format=manued") { o[:format] = "manued" }
|
|
62
|
+
parser.on("--html", "same as --format=html") { o[:format] = "html" }
|
|
63
|
+
parser.on("--wdiff", "same as --format=wdiff") { o[:format] = "wdiff" }
|
|
64
|
+
parser.on("--stat", "same as --format=stat (not implemented) (deprecated)") { o[:format] = "stat" }
|
|
65
|
+
|
|
66
|
+
parser.on(
|
|
67
|
+
"--label LABEL",
|
|
68
|
+
"-L LABEL",
|
|
69
|
+
"use label instead of file name (not implemented; exists for compatibility with diff)",
|
|
70
|
+
) do |s|
|
|
71
|
+
o[:label] ||= []
|
|
72
|
+
o[:label] << s
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
parser.on("--digest", "digest output, do not show all") { o[:digest] = true }
|
|
76
|
+
parser.on("--summary", "same as --digest") { o[:digest] = true }
|
|
77
|
+
|
|
78
|
+
parser.on(
|
|
79
|
+
"--display=DISPLAY",
|
|
80
|
+
display_types = ["inline", "block", "multi"],
|
|
81
|
+
"specify presentation type (effective only with digest; experimental feature)",
|
|
82
|
+
"#{display_types.join("|")} (default: inline) (multi is deprecated)",
|
|
83
|
+
) { |s| o[:display] ||= s.downcase }
|
|
84
|
+
|
|
85
|
+
parser.on("--cache", "use file cache (not implemented) (deprecated)") { o[:cache] = true }
|
|
86
|
+
parser.on(
|
|
87
|
+
"--pager=PAGER",
|
|
88
|
+
String,
|
|
89
|
+
"specify pager (if available, $DOCDIFF_PAGER is used by default)",
|
|
90
|
+
) { |s| o[:pager] = s }
|
|
91
|
+
parser.on("--no-pager", "do not use pager") { o[:pager] = false }
|
|
92
|
+
parser.on("--config-file=FILE", String, "specify config file to read") { |s| o[:config_file] = s }
|
|
93
|
+
parser.on("--no-config-file", "do not read config files") { o[:no_config_file] = true }
|
|
94
|
+
parser.on("--verbose", "run verbosely (not well-supported) (deprecated)") { o[:verbose] = true }
|
|
95
|
+
|
|
96
|
+
parser.on("--help", "show this message") do
|
|
97
|
+
puts parser
|
|
98
|
+
exit(0)
|
|
99
|
+
end
|
|
100
|
+
parser.on("--version", "show version") do
|
|
101
|
+
puts Docdiff::VERSION
|
|
102
|
+
exit(0)
|
|
103
|
+
end
|
|
104
|
+
parser.on("--license", "show license (deprecated)") do
|
|
105
|
+
puts DocDiff::License
|
|
106
|
+
exit(0)
|
|
107
|
+
end
|
|
108
|
+
parser.on("--author", "show author(s) (deprecated)") do
|
|
109
|
+
puts DocDiff::Author
|
|
110
|
+
exit(0)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
parser.on_tail(
|
|
114
|
+
"When invoked as worddiff or chardiff, resolution will be set accordingly.",
|
|
115
|
+
"Config files: /etc/docdiff/docdiff.conf, ~/.config/docdiff/docdiff.conf (or ~/etc/docdiff/docdiff.conf (deprecated))",
|
|
116
|
+
)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
option_parser.parse!(args)
|
|
120
|
+
o
|
|
91
121
|
end
|
|
92
122
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
123
|
+
def parse_config_file_content(content)
|
|
124
|
+
result = {}
|
|
125
|
+
return result if content.size <= 0
|
|
96
126
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
end
|
|
127
|
+
lines = content.dup.split(/\r\n|\r|\n/).compact
|
|
128
|
+
lines.collect! { |line| line.sub(/#.*$/, "") }
|
|
129
|
+
lines.collect!(&:strip)
|
|
130
|
+
lines.delete_if { |line| line == "" }
|
|
131
|
+
lines.each do |line|
|
|
132
|
+
raise 'line does not include " = ".' unless /[\s]+=[\s]+/.match(line)
|
|
133
|
+
|
|
134
|
+
name_src, value_src = line.split(/[\s]+=[\s]+/)
|
|
135
|
+
raise "Invalid name: #{name_src.inspect}" if /\s/.match(name_src)
|
|
136
|
+
raise "Invalid value: #{value_src.inspect}" unless value_src.is_a?(String)
|
|
137
|
+
|
|
138
|
+
name = name_src.intern
|
|
139
|
+
value = value_src
|
|
140
|
+
value = true if ["on", "yes", "true"].include?(value_src.downcase)
|
|
141
|
+
value = false if ["off", "no", "false"].include?(value_src.downcase)
|
|
142
|
+
value = value_src.to_i if /^[0-9]+$/.match(value_src)
|
|
143
|
+
result[name] = value
|
|
144
|
+
end
|
|
145
|
+
result
|
|
146
|
+
end
|
|
118
147
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
148
|
+
def read_config_from_file(filename)
|
|
149
|
+
content = nil
|
|
150
|
+
begin
|
|
151
|
+
File.open(filename, "r") { |f| content = f.read }
|
|
152
|
+
rescue => exception
|
|
153
|
+
raise exception
|
|
154
|
+
ensure
|
|
155
|
+
message =
|
|
156
|
+
case exception
|
|
157
|
+
in Errno::ENOENT
|
|
158
|
+
"config file not found: #{filename.inspect}"
|
|
159
|
+
in Errno::EACCES
|
|
160
|
+
"permission denied for reading: #{filename.inspect}"
|
|
161
|
+
in NilClass
|
|
162
|
+
nil
|
|
163
|
+
else
|
|
164
|
+
"#{exception}: something unexpected happened: #{filename.inspect}"
|
|
165
|
+
end
|
|
166
|
+
if content
|
|
167
|
+
config = parse_config_file_content(content)
|
|
132
168
|
else
|
|
133
|
-
"
|
|
169
|
+
message = "config file empty: #{filename.inspect}"
|
|
134
170
|
end
|
|
135
|
-
if content
|
|
136
|
-
config = parse_config_file_content(content)
|
|
137
|
-
else
|
|
138
|
-
message = "config file empty: #{filename.inspect}"
|
|
139
171
|
end
|
|
172
|
+
[config, message]
|
|
140
173
|
end
|
|
141
|
-
[config, message]
|
|
142
|
-
end
|
|
143
174
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
175
|
+
def print_or_write_to_pager(content, pager)
|
|
176
|
+
if $stdout.tty? && pager.is_a?(String) && !pager.empty?
|
|
177
|
+
IO.popen(pager, "w") { |f| f.print(content) }
|
|
178
|
+
else
|
|
179
|
+
print(content)
|
|
180
|
+
end
|
|
149
181
|
end
|
|
150
|
-
end
|
|
151
182
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
183
|
+
def run
|
|
184
|
+
command_line_config = parse_options!(ARGV)
|
|
185
|
+
|
|
186
|
+
system_config =
|
|
187
|
+
unless command_line_config[:no_config_file]
|
|
188
|
+
possible_system_config_file_names = [
|
|
189
|
+
DocDiff::SystemConfigFileName,
|
|
190
|
+
]
|
|
191
|
+
existing_system_config_file_names =
|
|
192
|
+
possible_system_config_file_names.select { |fn| File.exist?(fn) }
|
|
193
|
+
if existing_system_config_file_names.size >= 2
|
|
194
|
+
raise <<~EOS
|
|
195
|
+
More than one system config file found, using the first one: \
|
|
196
|
+
#{existing_system_config_file_names.inspect}
|
|
197
|
+
EOS
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
unless existing_system_config_file_names.empty?
|
|
201
|
+
filename = existing_system_config_file_names.first
|
|
202
|
+
config, message = read_config_from_file(filename)
|
|
203
|
+
$stderr.print(message) if command_line_config[:verbose]
|
|
204
|
+
config
|
|
205
|
+
end
|
|
167
206
|
end
|
|
168
|
-
filename = existing_system_config_file_names.first
|
|
169
|
-
config, message = read_config_from_file(filename)
|
|
170
|
-
STDERR.print message if command_line_config[:verbose]
|
|
171
|
-
config
|
|
172
|
-
end
|
|
173
207
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
208
|
+
user_config =
|
|
209
|
+
unless command_line_config[:no_config_file]
|
|
210
|
+
possible_user_config_file_names = [
|
|
211
|
+
DocDiff::UserConfigFileName,
|
|
212
|
+
DocDiff::AltUserConfigFileName,
|
|
213
|
+
DocDiff::XDGUserConfigFileName,
|
|
214
|
+
]
|
|
215
|
+
existing_user_config_file_names =
|
|
216
|
+
possible_user_config_file_names.select { |fn| File.exist?(fn) }
|
|
217
|
+
if existing_user_config_file_names.size >= 2
|
|
218
|
+
raise <<~EOS
|
|
219
|
+
Only one user config file can be used at the same time. \
|
|
220
|
+
Keep one and remove or rename the others: \
|
|
221
|
+
#{existing_user_config_file_names.inspect}
|
|
222
|
+
EOS
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
unless existing_user_config_file_names.empty?
|
|
226
|
+
filename = existing_user_config_file_names.first
|
|
227
|
+
config, message = read_config_from_file(filename)
|
|
228
|
+
$stderr.print(message) if command_line_config[:verbose]
|
|
229
|
+
config
|
|
230
|
+
end
|
|
189
231
|
end
|
|
190
|
-
filename = existing_user_config_file_names.first
|
|
191
|
-
config, message = read_config_from_file(filename)
|
|
192
|
-
STDERR.print message if command_line_config[:verbose]
|
|
193
|
-
config
|
|
194
|
-
end
|
|
195
232
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
233
|
+
config_from_specified_file =
|
|
234
|
+
if (filename = command_line_config[:config_file])
|
|
235
|
+
config, message = read_config_from_file(filename)
|
|
236
|
+
$stderr.print(message) if command_line_config[:verbose] == true
|
|
237
|
+
config
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
config_from_program_name =
|
|
241
|
+
case File.basename($PROGRAM_NAME, ".*")
|
|
242
|
+
when "worddiff" then { resolution: "word" }
|
|
243
|
+
when "chardiff" then { resolution: "char" }
|
|
244
|
+
end
|
|
202
245
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
when "chardiff" then {:resolution => "char"}
|
|
246
|
+
config_from_env_vars = {}
|
|
247
|
+
if (pager = ENV["DOCDIFF_PAGER"]) && !pager.empty?
|
|
248
|
+
config_from_env_vars[:pager] = pager
|
|
207
249
|
end
|
|
208
250
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
251
|
+
config_in_effect = DocDiff::DEFAULT_CONFIG.dup
|
|
252
|
+
config_in_effect.merge!(config_from_program_name) if config_from_program_name
|
|
253
|
+
config_in_effect.merge!(system_config) if system_config
|
|
254
|
+
config_in_effect.merge!(user_config) if user_config
|
|
255
|
+
config_in_effect.merge!(config_from_env_vars) if config_from_env_vars
|
|
256
|
+
config_in_effect.merge!(config_from_specified_file) if config_from_specified_file
|
|
257
|
+
config_in_effect.merge!(command_line_config) if command_line_config
|
|
258
|
+
|
|
259
|
+
docdiff = DocDiff.new(config: config_in_effect)
|
|
260
|
+
|
|
261
|
+
file1_content = nil
|
|
262
|
+
file2_content = nil
|
|
263
|
+
raise "Try `#{File.basename($PROGRAM_NAME)} --help' for more information." if ARGV[0].nil?
|
|
264
|
+
raise "Specify at least 2 target files." unless ARGV[0] && ARGV[1]
|
|
265
|
+
|
|
266
|
+
ARGV[0] = "/dev/stdin" if ARGV[0] == "-"
|
|
267
|
+
ARGV[1] = "/dev/stdin" if ARGV[1] == "-"
|
|
268
|
+
raise "No such file: #{ARGV[0]}." unless FileTest.exist?(ARGV[0])
|
|
269
|
+
raise "No such file: #{ARGV[1]}." unless FileTest.exist?(ARGV[1])
|
|
270
|
+
raise "#{ARGV[0]} is not readable." unless FileTest.readable?(ARGV[0])
|
|
271
|
+
raise "#{ARGV[1]} is not readable." unless FileTest.readable?(ARGV[1])
|
|
272
|
+
|
|
273
|
+
File.open(ARGV[0], "r") { |f| file1_content = f.read }
|
|
274
|
+
File.open(ARGV[1], "r") { |f| file2_content = f.read }
|
|
213
275
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
raise "Specify at least 2 target files." unless ARGV[0] && ARGV[1]
|
|
228
|
-
ARGV[0] = "/dev/stdin" if ARGV[0] == "-"
|
|
229
|
-
ARGV[1] = "/dev/stdin" if ARGV[1] == "-"
|
|
230
|
-
raise "No such file: #{ARGV[0]}." unless FileTest.exist?(ARGV[0])
|
|
231
|
-
raise "No such file: #{ARGV[1]}." unless FileTest.exist?(ARGV[1])
|
|
232
|
-
raise "#{ARGV[0]} is not readable." unless FileTest.readable?(ARGV[0])
|
|
233
|
-
raise "#{ARGV[1]} is not readable." unless FileTest.readable?(ARGV[1])
|
|
234
|
-
File.open(ARGV[0], "r"){|f| file1_content = f.read}
|
|
235
|
-
File.open(ARGV[1], "r"){|f| file2_content = f.read}
|
|
236
|
-
|
|
237
|
-
doc1 = nil
|
|
238
|
-
doc2 = nil
|
|
239
|
-
|
|
240
|
-
encoding1 = docdiff.config[:encoding]
|
|
241
|
-
encoding2 = docdiff.config[:encoding]
|
|
242
|
-
eol1 = docdiff.config[:eol]
|
|
243
|
-
eol2 = docdiff.config[:eol]
|
|
244
|
-
|
|
245
|
-
if docdiff.config[:encoding] == "auto"
|
|
246
|
-
encoding1 = DocDiff::CharString.guess_encoding(file1_content)
|
|
247
|
-
encoding2 = DocDiff::CharString.guess_encoding(file2_content)
|
|
248
|
-
case
|
|
249
|
-
when (encoding1 == "UNKNOWN" or encoding2 == "UNKNOWN")
|
|
250
|
-
raise "Document encoding unknown (#{encoding1}, #{encoding2})."
|
|
251
|
-
when encoding1 != encoding2
|
|
252
|
-
raise "Document encoding mismatch (#{encoding1}, #{encoding2})."
|
|
276
|
+
encoding1 = docdiff.config[:encoding]
|
|
277
|
+
encoding2 = docdiff.config[:encoding]
|
|
278
|
+
eol1 = docdiff.config[:eol]
|
|
279
|
+
eol2 = docdiff.config[:eol]
|
|
280
|
+
|
|
281
|
+
if docdiff.config[:encoding] == "auto"
|
|
282
|
+
encoding1 = DocDiff::CharString.guess_encoding(file1_content)
|
|
283
|
+
encoding2 = DocDiff::CharString.guess_encoding(file2_content)
|
|
284
|
+
if (encoding1 == "UNKNOWN") || (encoding2 == "UNKNOWN")
|
|
285
|
+
raise "Document encoding unknown (#{encoding1}, #{encoding2})."
|
|
286
|
+
elsif encoding1 != encoding2
|
|
287
|
+
raise "Document encoding mismatch (#{encoding1}, #{encoding2})."
|
|
288
|
+
end
|
|
253
289
|
end
|
|
254
|
-
end
|
|
255
290
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
291
|
+
if docdiff.config[:eol] == "auto"
|
|
292
|
+
eol1 = DocDiff::CharString.guess_eol(file1_content)
|
|
293
|
+
eol2 = DocDiff::CharString.guess_eol(file2_content)
|
|
294
|
+
if eol1.nil? || eol2.nil?
|
|
295
|
+
raise "Document eol is nil (#{eol1.inspect}, #{eol2.inspect}). The document might be empty."
|
|
296
|
+
elsif (eol1 == "UNKNOWN") || (eol2 == "UNKNOWN")
|
|
297
|
+
raise "Document eol unknown (#{eol1.inspect}, #{eol2.inspect})."
|
|
298
|
+
elsif eol1 != eol2
|
|
299
|
+
raise "Document eol mismatch (#{eol1}, #{eol2})."
|
|
300
|
+
end
|
|
266
301
|
end
|
|
267
|
-
end
|
|
268
302
|
|
|
269
|
-
|
|
270
|
-
|
|
303
|
+
doc1 = DocDiff::Document.new(file1_content, encoding1, eol1)
|
|
304
|
+
doc2 = DocDiff::Document.new(file2_content, encoding2, eol2)
|
|
271
305
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
306
|
+
output =
|
|
307
|
+
docdiff.run(
|
|
308
|
+
doc1,
|
|
309
|
+
doc2,
|
|
310
|
+
{
|
|
311
|
+
resolution: docdiff.config[:resolution],
|
|
312
|
+
format: docdiff.config[:format],
|
|
313
|
+
digest: docdiff.config[:digest],
|
|
314
|
+
display: docdiff.config[:display],
|
|
315
|
+
},
|
|
316
|
+
)
|
|
277
317
|
|
|
278
|
-
|
|
318
|
+
print_or_write_to_pager(output, docdiff.config[:pager])
|
|
319
|
+
end
|
|
279
320
|
end
|
|
280
321
|
end
|
|
281
322
|
end
|
data/lib/docdiff/diff/rcsdiff.rb
CHANGED
data/lib/docdiff/diff/unidiff.rb
CHANGED
data/lib/docdiff/diff.rb
CHANGED