copy-expander 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/cobol-source/COPY1LVL.CBL +1 -1
- data/cobol-source/COPY1LVLA.CBL +1 -1
- data/cobol-source/COPY2LVL.CBL +1 -1
- data/cobol-source/COPY3LVL.CBL +1 -1
- data/cobol-source/NOCOPY.CBL +1 -1
- data/expected/EXPECTED1.CBL +1 -1
- data/expected/EXPECTED2.CBL +1 -1
- data/expected/EXPECTED3.CBL +1 -1
- data/expected/EXPECTED4.CBL +1 -1
- data/lib/copy-expander/version.rb +1 -1
- data/lib/copy_expander.rb +24 -4
- data/lib/expander.rb +3 -3
- data/spec/lib/copy-expander/copy_expander_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed65ef74cac0a03730ed691a3dee8638f59df508
|
4
|
+
data.tar.gz: e337b014e70643b9500f74f833bd8ddbfc2ffb56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa16130a1610f5148e7cb8c5532c0b958f7578073c72aefdcb57a76496832cca2ab3d37507252de8f5857d3384b971d4526a7552a8cbb938b57c63882be99421
|
7
|
+
data.tar.gz: e64975b09422a3ffdf5e01d3e98aaebcd5deb3e57c4e7bb7f3d5f654bd28425f50c9593ec0143c84a4a82b93ecb3d84f20f19817076a4d401ffb8f7de0c9e1a7
|
data/.gitignore
CHANGED
data/cobol-source/COPY1LVL.CBL
CHANGED
data/cobol-source/COPY1LVLA.CBL
CHANGED
data/cobol-source/COPY2LVL.CBL
CHANGED
data/cobol-source/COPY3LVL.CBL
CHANGED
data/cobol-source/NOCOPY.CBL
CHANGED
data/expected/EXPECTED1.CBL
CHANGED
data/expected/EXPECTED2.CBL
CHANGED
data/expected/EXPECTED3.CBL
CHANGED
data/expected/EXPECTED4.CBL
CHANGED
data/lib/copy_expander.rb
CHANGED
@@ -22,21 +22,29 @@ module CopyExpander
|
|
22
22
|
# Expand COPY statement found on a single line of COBOL source code.
|
23
23
|
#
|
24
24
|
def process line
|
25
|
+
return line if blank? line
|
25
26
|
return line if comment? line
|
26
27
|
break_up_source_line line
|
27
28
|
return line unless has_copy_statement?
|
28
29
|
@copy_statement_count += 1
|
30
|
+
@depth = 0
|
29
31
|
expand_copybook CopyStatement.new(@work_area)
|
32
|
+
nil
|
30
33
|
end
|
31
34
|
|
32
35
|
##
|
33
36
|
# Recursively expand copybooks and replace tokens
|
34
37
|
#
|
35
38
|
def expand_copybook copy_statement
|
39
|
+
@depth += 1
|
40
|
+
if @depth > 8
|
41
|
+
puts "recursion depth is #{@depth}"
|
42
|
+
exit(1)
|
43
|
+
end
|
36
44
|
copybook = File.open("#{copy_dir}/#{copy_statement.copybook_name}", 'r')
|
37
45
|
begin
|
38
|
-
line = copybook.readline
|
39
|
-
if comment?
|
46
|
+
line = ('%-80.80s' % copybook.readline.chomp)
|
47
|
+
if blank?(line) || comment?(line)
|
40
48
|
write_from line
|
41
49
|
else
|
42
50
|
break_up_source_line line
|
@@ -49,6 +57,7 @@ module CopyExpander
|
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end while copybook.eof? == false
|
60
|
+
@depth -= 1
|
52
61
|
end
|
53
62
|
|
54
63
|
##
|
@@ -62,6 +71,13 @@ module CopyExpander
|
|
62
71
|
line.length >= 72 ? @work_area = line[6..71] : nil
|
63
72
|
end
|
64
73
|
|
74
|
+
##
|
75
|
+
# Is this line logically blank?
|
76
|
+
#
|
77
|
+
def blank? line
|
78
|
+
line == nil || line.gsub(/\s/, '').length == 0
|
79
|
+
end
|
80
|
+
|
65
81
|
##
|
66
82
|
# Is this line a comment?
|
67
83
|
# Source comments in COBOL are identified by an asterisk in position 7.
|
@@ -81,7 +97,7 @@ module CopyExpander
|
|
81
97
|
# Reconstruct the original source line.
|
82
98
|
#
|
83
99
|
def reconstruct_line
|
84
|
-
@first_six_characters + ('%-66.66s' % @work_area) + @last_eight_characters
|
100
|
+
@first_six_characters + ('%-66.66s' % @work_area) + @last_eight_characters
|
85
101
|
end
|
86
102
|
|
87
103
|
##
|
@@ -96,7 +112,11 @@ module CopyExpander
|
|
96
112
|
# Carry out token replacement in a source line per the REPLACING option
|
97
113
|
#
|
98
114
|
def replace_tokens line, copy_statement
|
99
|
-
|
115
|
+
if copy_statement.old_value == nil || copy_statement.new_value == nil
|
116
|
+
line
|
117
|
+
else
|
118
|
+
line.gsub(copy_statement.old_value, copy_statement.new_value) unless copy_statement.old_value == nil
|
119
|
+
end
|
100
120
|
end
|
101
121
|
|
102
122
|
end
|
data/lib/expander.rb
CHANGED
@@ -25,18 +25,18 @@ class Expander
|
|
25
25
|
init
|
26
26
|
begin
|
27
27
|
output_line = process read_line
|
28
|
-
write_from output_line
|
28
|
+
write_from output_line.to_s unless output_line == nil
|
29
29
|
end while @eof == false
|
30
30
|
end
|
31
31
|
|
32
32
|
def read_line
|
33
|
-
line = @source_file.readline
|
33
|
+
line = ('%-80.80s' % @source_file.readline.chomp)
|
34
34
|
@eof = @source_file.eof?
|
35
35
|
line
|
36
36
|
end
|
37
37
|
|
38
38
|
def write_from line
|
39
|
-
@expanded_file.write line
|
39
|
+
@expanded_file.write ('%-80.80s' % line.chomp) + "\n"
|
40
40
|
end
|
41
41
|
|
42
42
|
def eof?
|
@@ -116,14 +116,14 @@ describe CopyExpander do
|
|
116
116
|
@work_area = ' something something'
|
117
117
|
@first_six_characters = '123456'
|
118
118
|
@last_eight_characters = 'abcdefgh'
|
119
|
-
expect(reconstruct_line).to eq('123456 something something' + ' '*40 + " abcdefgh
|
119
|
+
expect(reconstruct_line).to eq('123456 something something' + ' '*40 + " abcdefgh")
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'reconstructs a source line as a comment line' do
|
123
123
|
@work_area = ' something something'
|
124
124
|
@first_six_characters = '123456'
|
125
125
|
@last_eight_characters = 'abcdefgh'
|
126
|
-
expect(commentize(reconstruct_line)).to eq('123456* something something' + ' '*40 + " abcdefgh
|
126
|
+
expect(commentize(reconstruct_line)).to eq('123456* something something' + ' '*40 + " abcdefgh")
|
127
127
|
end
|
128
128
|
|
129
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy-expander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Nicolette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|