rept 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/init.yaml +1 -1
- data/lib/lib.rb +1 -0
- data/lib/rept.rb +162 -63
- data/lib/rept.yaml +6 -0
- data/lib/rept4diff.rb +6 -4
- data/test/addTest.rept +1 -1
- data/test/rept1.rept +5 -0
- data/test/rept1.txt +2 -0
- data/test/rept2.rept +18 -0
- data/test/rept2.txt +4 -0
- data/test/rept3.cpp +27 -0
- data/test/rept3.rept +15 -0
- data/test/rept4.rept +6 -0
- data/test/rept4.txt +4 -0
- data/test/rept5.rept +7 -0
- data/test/rept5.txt +5 -0
- data/test/test.rb +2 -1
- data/test/test_rept.rb +19 -0
- data/test/test_rept4diff.rb +4 -4
- metadata +13 -2
data/lib/init.yaml
CHANGED
data/lib/lib.rb
CHANGED
data/lib/rept.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
#! ruby -Ks
|
2
2
|
|
3
|
+
$:.unshift(File.dirname(__FILE__))
|
4
|
+
|
3
5
|
require 'optparse'
|
4
6
|
require 'fileutils'
|
5
|
-
require File.join(File.dirname(__FILE__), 'fileinsert')
|
6
|
-
require File.join(File.dirname(__FILE__), 'yamltext')
|
7
7
|
require 'readline'
|
8
|
-
|
8
|
+
|
9
|
+
require 'fileinsert'
|
10
|
+
require 'yamltext'
|
11
|
+
require 'lib'
|
12
|
+
|
13
|
+
require 'test/unit/assertions'
|
14
|
+
include Test::Unit::Assertions
|
9
15
|
|
10
16
|
# ���b�Z�[�W�ꗗ
|
11
17
|
$init = YamlText.new(File.join(File.dirname(__FILE__), 'init.yaml'))
|
@@ -14,7 +20,7 @@ $text = YamlText.new(File.join(File.dirname(__FILE__), 'rept.yaml'))
|
|
14
20
|
# �o�[�W�����ԍ�
|
15
21
|
Version = $init.get('version')
|
16
22
|
|
17
|
-
class
|
23
|
+
class ReptParser
|
18
24
|
attr_reader :args
|
19
25
|
attr_reader :creator
|
20
26
|
|
@@ -146,12 +152,12 @@ class Creator
|
|
146
152
|
end
|
147
153
|
|
148
154
|
mode = :none
|
149
|
-
|
155
|
+
markerTexts = []
|
150
156
|
insertTexts = []
|
151
157
|
|
152
158
|
@text.each_with_index do |data, no|
|
153
159
|
if (data =~ /\A\s*\z/)
|
154
|
-
if (!insertFromMode(mode,
|
160
|
+
if (!insertFromMode(mode, markerTexts, insertTexts))
|
155
161
|
success = false
|
156
162
|
end
|
157
163
|
mode = :none
|
@@ -159,13 +165,13 @@ class Creator
|
|
159
165
|
insertTexts << convertString(data.gsub(/^-->/, ""))
|
160
166
|
mode = :insert
|
161
167
|
else
|
162
|
-
|
168
|
+
markerTexts << convertString(data).chomp
|
163
169
|
mode = :marker
|
164
170
|
end
|
165
171
|
end
|
166
172
|
|
167
173
|
if (mode != :none)
|
168
|
-
if (!insertFromMode(mode,
|
174
|
+
if (!insertFromMode(mode, markerTexts, insertTexts))
|
169
175
|
success = false
|
170
176
|
end
|
171
177
|
end
|
@@ -173,38 +179,41 @@ class Creator
|
|
173
179
|
success
|
174
180
|
end
|
175
181
|
|
176
|
-
def insertFromMode(mode,
|
177
|
-
|
182
|
+
def insertFromMode(mode, markerTexts, insertTexts)
|
183
|
+
# �}������
|
184
|
+
success = insertText(markerTexts, insertTexts, headOrTail(mode))
|
178
185
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
elsif (mode == :marker)
|
183
|
-
insertText(markerText, insertTexts, 0)
|
184
|
-
end
|
185
|
-
rescue
|
186
|
-
success = false
|
187
|
-
ensure
|
188
|
-
insertTexts.clear
|
189
|
-
markerText = nil
|
190
|
-
end
|
186
|
+
# �����A���s�Ɋւ�炸�}���Ώۂ��N���A
|
187
|
+
insertTexts.clear
|
188
|
+
markerTexts.clear
|
191
189
|
|
190
|
+
# ���ʂ�Ԃ�
|
192
191
|
success
|
193
192
|
end
|
194
193
|
|
195
|
-
def
|
196
|
-
|
194
|
+
def headOrTail(mode)
|
195
|
+
case mode
|
196
|
+
when :insert
|
197
|
+
:tail
|
198
|
+
when :marker
|
199
|
+
:head
|
200
|
+
else
|
201
|
+
raise
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def insertText(markerTexts, insertTexts, headOrTail)
|
206
|
+
lineNo = getInsertPos(@conv_file_name, markerTexts, headOrTail)
|
197
207
|
|
198
208
|
if (lineNo != -1)
|
199
209
|
if (!@testMode)
|
200
|
-
insertTexts.
|
201
|
-
|
202
|
-
end
|
203
|
-
file_insert(@conv_file_name, lineNo + lineNoOffset, insertTexts.to_s)
|
210
|
+
puts $text.get('real_insert', '"' + insertTexts.inspect + '"', '"' + markerTexts.inspect + '"')
|
211
|
+
file_insert(@conv_file_name, lineNo, insertTexts.to_s)
|
204
212
|
end
|
213
|
+
true
|
205
214
|
else
|
206
|
-
puts $text.get('insert_not_found', '"' + insertTexts
|
207
|
-
|
215
|
+
puts $text.get('insert_not_found', '"' + insertTexts.inspect + '"', '"' + markerTexts.inspect + '"')
|
216
|
+
false
|
208
217
|
end
|
209
218
|
end
|
210
219
|
|
@@ -214,12 +223,12 @@ class Creator
|
|
214
223
|
puts $text.get('delete_insert', @conv_file_name)
|
215
224
|
|
216
225
|
mode = :none
|
217
|
-
|
226
|
+
markerTexts = []
|
218
227
|
insertTexts = []
|
219
228
|
|
220
229
|
@text.each_with_index do |data, no|
|
221
230
|
if (data =~ /\A\s*\z/)
|
222
|
-
if (!deleteInsertFromMode(mode,
|
231
|
+
if (!deleteInsertFromMode(mode, markerTexts, insertTexts))
|
223
232
|
success = false
|
224
233
|
end
|
225
234
|
mode = :none
|
@@ -227,13 +236,13 @@ class Creator
|
|
227
236
|
insertTexts << convertString(data.gsub(/^-->/, ""))
|
228
237
|
mode = :insert
|
229
238
|
else
|
230
|
-
|
239
|
+
markerTexts << convertString(data).chomp
|
231
240
|
mode = :marker
|
232
241
|
end
|
233
242
|
end
|
234
243
|
|
235
244
|
if (mode != :none)
|
236
|
-
if (!deleteInsertFromMode(mode,
|
245
|
+
if (!deleteInsertFromMode(mode, markerTexts, insertTexts))
|
237
246
|
success = false
|
238
247
|
end
|
239
248
|
end
|
@@ -241,51 +250,53 @@ class Creator
|
|
241
250
|
success
|
242
251
|
end
|
243
252
|
|
244
|
-
def deleteInsertFromMode(mode,
|
253
|
+
def deleteInsertFromMode(mode, markerTexts, insertTexts)
|
245
254
|
# �}���폜
|
246
|
-
|
247
|
-
deleteInsertText(markerText, insertTexts, 1)
|
248
|
-
elsif (mode == :marker)
|
249
|
-
deleteInsertText(markerText, insertTexts, -insertTexts.size)
|
250
|
-
end
|
255
|
+
deleteInsertText(markerTexts, insertTexts, headOrTail(mode))
|
251
256
|
|
252
257
|
# �㏈��
|
253
258
|
insertTexts.clear
|
254
|
-
|
259
|
+
markerTexts.clear
|
255
260
|
|
256
261
|
# ���̏��A���s�͖���
|
257
262
|
true
|
258
263
|
end
|
259
264
|
|
260
|
-
def deleteInsertText(
|
261
|
-
lineNo =
|
265
|
+
def deleteInsertText(markerTexts, insertTexts, headOrTail)
|
266
|
+
lineNo = getInsertPos(@conv_file_name, markerTexts, headOrTail)
|
262
267
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
data << line
|
268
|
-
end
|
269
|
-
end
|
268
|
+
# ������Ȃ���ΏI��
|
269
|
+
if (lineNo == -1)
|
270
|
+
return
|
271
|
+
end
|
270
272
|
|
271
|
-
|
272
|
-
|
273
|
+
# ����������ꍇ�́A�}���e�L�X�g�̃T�C�Y���l������
|
274
|
+
if (headOrTail == :head)
|
275
|
+
lineNo -= insertTexts.size
|
276
|
+
end
|
273
277
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
278
|
+
# �폜�J�n
|
279
|
+
data = []
|
280
|
+
open(@conv_file_name) do |file|
|
281
|
+
file.each do |line|
|
282
|
+
data << line
|
279
283
|
end
|
284
|
+
end
|
280
285
|
|
281
|
-
|
282
|
-
|
283
|
-
puts $text.get('real_delete_insert', '"' + insertTexts[index].chomp + '"', '"' + markerText + '"')
|
284
|
-
end
|
286
|
+
startLineNo = lineNo
|
287
|
+
success = true
|
285
288
|
|
286
|
-
|
289
|
+
insertTexts.size.times do |index|
|
290
|
+
if (insertTexts[index] != data[startLineNo + index])
|
291
|
+
success = false
|
292
|
+
break
|
287
293
|
end
|
288
294
|
end
|
295
|
+
|
296
|
+
if (success)
|
297
|
+
puts $text.get('real_delete_insert', '"' + insertTexts.inspect + '"', '"' + markerTexts.inspect + '"')
|
298
|
+
file_deleteline(@conv_file_name, startLineNo, insertTexts.size)
|
299
|
+
end
|
289
300
|
end
|
290
301
|
|
291
302
|
def createNewFile
|
@@ -335,6 +346,94 @@ class Creator
|
|
335
346
|
def insert?
|
336
347
|
@text.to_s =~ /^-->/
|
337
348
|
end
|
349
|
+
|
350
|
+
# �}���ʒu��������A������Ȃ������ꍇ��-1��Ԃ�
|
351
|
+
def getInsertPos(fileName, markerTexts, headOrTail)
|
352
|
+
# �e�L�X�g�̓��e��z��ɓǂݍ���
|
353
|
+
texts = []
|
354
|
+
File.open(fileName) {|f| f.each {|line| texts << line }}
|
355
|
+
|
356
|
+
# �T���J�n
|
357
|
+
t_head = 0
|
358
|
+
t_tail = 0
|
359
|
+
|
360
|
+
while (t_tail < texts.size)
|
361
|
+
# �}�[�J�[��擪��
|
362
|
+
m_no = 0
|
363
|
+
|
364
|
+
# �ǂݍ�����
|
365
|
+
loop do
|
366
|
+
# �ǂݐi�߂�
|
367
|
+
if (markerTexts[m_no] =~ /^REPT_\*\*/)
|
368
|
+
t_tail, m_no = readMultiGlob(texts, t_tail, markerTexts, m_no)
|
369
|
+
else
|
370
|
+
t_tail, m_no = readNormal(texts, t_tail, markerTexts, m_no)
|
371
|
+
end
|
372
|
+
|
373
|
+
# ���ʏ���
|
374
|
+
if (t_tail == -1)
|
375
|
+
break
|
376
|
+
elsif (m_no >= markerTexts.size)
|
377
|
+
return (headOrTail == :head) ? t_head : t_tail
|
378
|
+
elsif (t_tail >= texts.size)
|
379
|
+
break # @todo ���̎��_��return���Ă��܂��Ă��������H
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
# �擪�����炷
|
384
|
+
t_head += 1
|
385
|
+
t_tail = t_head
|
386
|
+
end
|
387
|
+
|
388
|
+
# ������Ȃ�
|
389
|
+
return -1
|
390
|
+
end
|
391
|
+
|
392
|
+
def readMultiGlob(texts, t_tail, markerTexts, m_no)
|
393
|
+
# �}�[�J�[�擪�ł̃}���`�O���u�͋֎~
|
394
|
+
assert(m_no > 0, $text.get('error_multiglob_head'))
|
395
|
+
|
396
|
+
# �}�[�J�[�I�[�ł̃}���`�O���u�͋֎~
|
397
|
+
assert(m_no < markerTexts.size - 1, $text.get('error_multiglob_term'))
|
398
|
+
|
399
|
+
# �}�[�J�[�����ɐi�߂�
|
400
|
+
m_no += 1
|
401
|
+
|
402
|
+
# �}���`�O���u�̎��̃}�[�J�[�Ɉ���������܂ŒT����i�߂�
|
403
|
+
# rept�̃}���`�O���u�͍ŒZ��v�ł�
|
404
|
+
loop do
|
405
|
+
# �e�L�X�g�̏I�[�܂ŗ��Ă��܂�����T���ł���
|
406
|
+
if (t_tail >= texts.size)
|
407
|
+
return -1, -1
|
408
|
+
end
|
409
|
+
|
410
|
+
# ��v����ꏊ������������}���`�O���u�����I��
|
411
|
+
if (match? texts[t_tail], markerTexts[m_no])
|
412
|
+
return t_tail + 1, m_no + 1
|
413
|
+
end
|
414
|
+
|
415
|
+
# ���̃e�L�X�g��
|
416
|
+
t_tail += 1
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
def readNormal(texts, t_tail, markerTexts, m_no)
|
421
|
+
if (match? texts[t_tail], markerTexts[m_no])
|
422
|
+
return t_tail + 1, m_no + 1
|
423
|
+
else
|
424
|
+
return -1, -1
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
def match?(text, markerText)
|
429
|
+
# REPT_*��.*�ɕϊ��������K�\�������
|
430
|
+
pattern = Regexp.escape(markerText).gsub(/REPT_\\\*/, '.*?')
|
431
|
+
|
432
|
+
# ����
|
433
|
+
return /#{pattern}/ =~ text
|
434
|
+
end
|
435
|
+
|
436
|
+
private :headOrTail, :readMultiGlob, :readNormal, :match?
|
338
437
|
end
|
339
438
|
|
340
439
|
def rept
|
@@ -349,7 +448,7 @@ def rept
|
|
349
448
|
|
350
449
|
# ���s�{��
|
351
450
|
if (ARGV.size > 0)
|
352
|
-
parser =
|
451
|
+
parser = ReptParser.new(ARGV[0])
|
353
452
|
parser.parse
|
354
453
|
|
355
454
|
args = parser.args
|
data/lib/rept.yaml
CHANGED
@@ -63,4 +63,10 @@ real_delete_insert: "
|
|
63
63
|
# �Θb���s�킸�Ɏ��s���s��
|
64
64
|
force: "�Θb���s�킸�Ɏ��s���s��"
|
65
65
|
|
66
|
+
# �}�[�J�[�擪�ł̃}���`�O���u�͋֎~
|
67
|
+
error_multiglob_head: "�}�[�J�[�擪�ł̃}���`�O���u�͋֎~�ł�"
|
68
|
+
|
69
|
+
# �}�[�J�[�I�[�ł̃}���`�O���u���֎~
|
70
|
+
error_multiglob_term: "�}�[�J�[�I�[�ł̃}���`�O���u�͋֎~�ł�"
|
71
|
+
|
66
72
|
# @insert
|
data/lib/rept4diff.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
#! ruby -Ks
|
2
2
|
|
3
|
+
$:.unshift(File.dirname(__FILE__))
|
4
|
+
|
3
5
|
require 'optparse'
|
4
|
-
require File.join(File.dirname(__FILE__), 'yamltext')
|
5
6
|
require 'pathname'
|
6
|
-
require File.join(File.dirname(__FILE__), 'lib')
|
7
7
|
require 'test/unit/assertions'
|
8
8
|
include Test::Unit::Assertions
|
9
9
|
|
10
|
+
require 'lib'
|
11
|
+
|
10
12
|
# ���b�Z�[�W�ꗗ
|
11
13
|
$init = YamlText.new(File.join(File.dirname(__FILE__), 'init.yaml'))
|
12
14
|
$text = YamlText.new(File.join(File.dirname(__FILE__), 'rept4diff.yaml'))
|
@@ -14,7 +16,7 @@ $text = YamlText.new(File.join(File.dirname(__FILE__), 'rept4diff.yaml'))
|
|
14
16
|
# �o�[�W�����ԍ�
|
15
17
|
Version = $init.get('version')
|
16
18
|
|
17
|
-
class
|
19
|
+
class Rept4DiffParser
|
18
20
|
def initialize(fname, args)
|
19
21
|
@data = []
|
20
22
|
@args = args
|
@@ -215,7 +217,7 @@ def rept4diff
|
|
215
217
|
|
216
218
|
# ���s�{��
|
217
219
|
if (ARGV.size > 1)
|
218
|
-
parser =
|
220
|
+
parser = Rept4DiffParser.new(ARGV[0], ARGV[1..-1])
|
219
221
|
parser.parse
|
220
222
|
output.print parser.result
|
221
223
|
else
|
data/test/addTest.rept
CHANGED
data/test/rept1.rept
ADDED
data/test/rept1.txt
ADDED
data/test/rept2.rept
ADDED
data/test/rept2.txt
ADDED
data/test/rept3.cpp
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
// --------------------------------------------------------------------------
|
2
|
+
/**
|
3
|
+
* �}���e�X�g
|
4
|
+
*/
|
5
|
+
|
6
|
+
void hoge()
|
7
|
+
{
|
8
|
+
ffff();
|
9
|
+
}
|
10
|
+
|
11
|
+
// �����s�p�^�[��
|
12
|
+
void foo()
|
13
|
+
{
|
14
|
+
ffff();
|
15
|
+
ffff();
|
16
|
+
ffff();
|
17
|
+
ffff();
|
18
|
+
ffff();
|
19
|
+
ffff();
|
20
|
+
ffff();
|
21
|
+
ffff();
|
22
|
+
}
|
23
|
+
|
24
|
+
// �}�[�J�[����v���Ȃ��p�^�[��
|
25
|
+
void bar()
|
26
|
+
{
|
27
|
+
ffff();
|
data/test/rept3.rept
ADDED
data/test/rept4.rept
ADDED
data/test/rept4.txt
ADDED
data/test/rept5.rept
ADDED
data/test/test.rb
CHANGED
data/test/test_rept.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rept'
|
3
|
+
|
4
|
+
class TC_rept < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Dir.chdir('test')
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
Dir.chdir('..')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_rept1
|
14
|
+
parser = ReptParser.new('rept1.rept')
|
15
|
+
parser.parse
|
16
|
+
# �����ɖ{���̓e�X�g����������
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/test/test_rept4diff.rb
CHANGED
@@ -17,25 +17,25 @@ class TC_Rept4Diff < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_test1
|
20
|
-
parser =
|
20
|
+
parser = Rept4DiffParser.new('test1.diff', ['Bar'])
|
21
21
|
parser.parse
|
22
22
|
assert_equal(parser.result, readRept('test1.rept'))
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_test2
|
26
|
-
parser =
|
26
|
+
parser = Rept4DiffParser.new('test2.diff', ['Bar'])
|
27
27
|
parser.parse
|
28
28
|
assert_equal(parser.result, readRept('test2.rept'))
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_test3
|
32
|
-
parser =
|
32
|
+
parser = Rept4DiffParser.new('test3.diff', ['Bar'])
|
33
33
|
parser.parse
|
34
34
|
assert_equal(parser.result, readRept('test3.rept'))
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_test4
|
38
|
-
parser =
|
38
|
+
parser = Rept4DiffParser.new('test4.diff', ['FooBar'])
|
39
39
|
parser.parse
|
40
40
|
assert_equal(parser.result, readRept('test4.rept'))
|
41
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rept
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ongaeshi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-03 00:00:00 +09:00
|
13
13
|
default_executable: rept
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -56,6 +56,16 @@ files:
|
|
56
56
|
- test/fileinsert_lf_000.txt
|
57
57
|
- test/fileinsert_lf_001.txt
|
58
58
|
- test/fileinsert_lf_002.txt
|
59
|
+
- test/rept1.rept
|
60
|
+
- test/rept1.txt
|
61
|
+
- test/rept2.rept
|
62
|
+
- test/rept2.txt
|
63
|
+
- test/rept3.cpp
|
64
|
+
- test/rept3.rept
|
65
|
+
- test/rept4.rept
|
66
|
+
- test/rept4.txt
|
67
|
+
- test/rept5.rept
|
68
|
+
- test/rept5.txt
|
59
69
|
- test/test.rb
|
60
70
|
- test/test1.diff
|
61
71
|
- test/test1.rept
|
@@ -66,6 +76,7 @@ files:
|
|
66
76
|
- test/test4.diff
|
67
77
|
- test/test4.rept
|
68
78
|
- test/test_fileinsert.rb
|
79
|
+
- test/test_rept.rb
|
69
80
|
- test/test_rept4diff.rb
|
70
81
|
has_rdoc: true
|
71
82
|
homepage: http://rubyforge.org/projects/rept/
|