copy-expander 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fbe6c5515216267422bea2aa60dd219255297dd
4
- data.tar.gz: 245721ae907ee85ba3926a355cca7eaf9123db98
3
+ metadata.gz: ed65ef74cac0a03730ed691a3dee8638f59df508
4
+ data.tar.gz: e337b014e70643b9500f74f833bd8ddbfc2ffb56
5
5
  SHA512:
6
- metadata.gz: 68d368ebcde68b7231e5ea6b534080c83aa66c4ac369d7be2b62cf3feadcd7d5591373d2e5ac8f2995308e2efc805951d85c5e8fff4a5f7eabea40bce444a827
7
- data.tar.gz: 96724b3656176cb931044bda19bd1d2863a9a47b2faddbc0aac3af31f01b99475f18ab855ea9bb5628ce1e084d6070b8b94f856cf0be4048891680c3f1fb6b7d
6
+ metadata.gz: fa16130a1610f5148e7cb8c5532c0b958f7578073c72aefdcb57a76496832cca2ab3d37507252de8f5857d3384b971d4526a7552a8cbb938b57c63882be99421
7
+ data.tar.gz: e64975b09422a3ffdf5e01d3e98aaebcd5deb3e57c4e7bb7f3d5f654bd28425f50c9593ec0143c84a4a82b93ecb3d84f20f19817076a4d401ffb8f7de0c9e1a7
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  *.sublime-workspace
4
4
  *~
5
5
  TEMP.CBL
6
+ *.gem
@@ -13,4 +13,4 @@
13
13
  000130 PROCEDURE DIVISION. AAAAAAAA
14
14
  000140 DISPLAY 'This program contains COPY statements 1 level deep.'AAAAAAAA
15
15
  000150 GOBACK AAAAAAAA
16
- 000160 . AAAAAAAA
16
+ 000160 . AAAAAAAA
@@ -15,4 +15,4 @@
15
15
  000150 DISPLAY 'This program contains 2 COPY statements ' AAAAAAAA
16
16
  000160 '1 LEVEL DEEP.' AAAAAAAA
17
17
  000170 GOBACK AAAAAAAA
18
- 000180 . AAAAAAAA
18
+ 000180 . AAAAAAAA
@@ -14,4 +14,4 @@
14
14
  000140 DISPLAY 'This program contains COPY statements ' AAAAAAAA
15
15
  000150 '2 LEVELS DEEP.' AAAAAAAA
16
16
  000160 GOBACK AAAAAAAA
17
- 000170 . AAAAAAAA
17
+ 000170 . AAAAAAAA
@@ -14,4 +14,4 @@
14
14
  000140 DISPLAY 'This program contains COPY statements ' AAAAAAAA
15
15
  000150 '3 LEVELS DEEP.' AAAAAAAA
16
16
  000160 GOBACK AAAAAAAA
17
- 000170 . AAAAAAAA
17
+ 000170 . AAAAAAAA
@@ -13,4 +13,4 @@
13
13
  000013 PROCEDURE DIVISION. AAAAAAAA
14
14
  000014 DISPLAY 'This program contains no COPY statements.' AAAAAAAA
15
15
  000015 GOBACK AAAAAAAA
16
- 000016 . AAAAAAAA
16
+ 000016 . AAAAAAAA
@@ -16,4 +16,4 @@
16
16
  000130 PROCEDURE DIVISION. AAAAAAAA
17
17
  000140 DISPLAY 'This program contains COPY statements 1 level deep.'AAAAAAAA
18
18
  000150 GOBACK AAAAAAAA
19
- 000160 . AAAAAAAA
19
+ 000160 . AAAAAAAA
@@ -21,4 +21,4 @@
21
21
  000150 DISPLAY 'This program contains 2 COPY statements ' AAAAAAAA
22
22
  000160 '1 LEVEL DEEP.' AAAAAAAA
23
23
  000170 GOBACK AAAAAAAA
24
- 000180 . AAAAAAAA
24
+ 000180 . AAAAAAAA
@@ -24,4 +24,4 @@
24
24
  000140 DISPLAY 'This program contains COPY statements ' AAAAAAAA
25
25
  000150 '2 LEVELS DEEP.' AAAAAAAA
26
26
  000160 GOBACK AAAAAAAA
27
- 000170 . AAAAAAAA
27
+ 000170 . AAAAAAAA
@@ -38,4 +38,4 @@
38
38
  000140 DISPLAY 'This program contains COPY statements ' AAAAAAAA
39
39
  000150 '3 LEVELS DEEP.' AAAAAAAA
40
40
  000160 GOBACK AAAAAAAA
41
- 000170 . AAAAAAAA
41
+ 000170 . AAAAAAAA
@@ -1,3 +1,3 @@
1
1
  module Dfhmdf
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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? line
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 + "\n"
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
- line.gsub(copy_statement.old_value, copy_statement.new_value)
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\n")
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\n")
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.1
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-09-22 00:00:00.000000000 Z
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler