Class: BConv::ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ConfigParser.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, projToConvert) ⇒ ConfigParser

Returns a new instance of ConfigParser.



9
10
11
12
# File 'lib/ConfigParser.rb', line 9

def initialize(filename, projToConvert)
  @filename = filename
  @projToConvert = projToConvert
end

Instance Method Details

#readConfigObject



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
# File 'lib/ConfigParser.rb', line 14

def readConfig
  begin
    File.open(@filename) do |l|
      mappings = []
      mapForProj = {} 
      while(line = l.gets) != nil
        mapping = {}
        ar = []
        setEndLabel = false
        if line.match(/^Mapping/)
          lineNumber = l.lineno
          while(line = l.gets) != nil
            line.gsub!('\\','/')
            ar = line.split("=")
            if (ar.length == 2)
              comPos = ar[1].index("#")
              ar[1] = ar[1][0..comPos-1] if comPos != nil
              mapping.store(ar[0].strip,ar[1].strip)
            elsif ar[1] == ""
              mapping.store(ar[0].strip,"")
            end
            
            if line.match(/^}$/)
              raise "Error: Workspace parameter from Mapping in line #{lineNumber} is missing!" if mapping.has_key?('Workspace') == false
              raise "Error: MainProj parameter from Mapping in line #{lineNumber} is missing!" if mapping.has_key?('MainProj') == false
              raise "Error: BuildConfig parameter from Mapping in line #{lineNumber} is missing!" if mapping.has_key?('BuildConfig') == false
              raise "Error: Proj2Convert parameter from Mapping in line #{lineNumber} is missing!" if mapping.has_key?('Proj2Convert') == false
              raise "Error: OutputFileName parameter from Mapping in line #{lineNumber} is missing!" if mapping.has_key?('OutputFileName') == false
              raise "Error: TemplateFile parameter from Mapping in line #{lineNumber} is missing!" if mapping.has_key?('TemplateFile') == false
              
              if @projToConvert != "" && @projToConvert != mapping['Proj2Convert']
                mapping = {}
              else
                mappings << mapping
              end
              
              # if @projToConvert.length != 0

                # @projToConvert.each do |val|

                  # if val == mapping['Proj2Convert']

                    # mappings << mapping

                  # end

                # end

              # else

                # mappings << mapping

              # end

              
              setEndLabel = true
              break
            elsif line.include?("Mapping")
              raise "Error: end label } from Mapping in line #{lineNumber} is missing!"
            end
          end
          raise "Error: end label } from Mapping in line #{lineNumber} is missing!" if setEndLabel == false
        elsif line.match(/^( *)Workspace/)
          lineNumber = l.lineno
          raise "Error: Mapping keyword in front of line #{lineNumber} is missing?"
        end
      end
      return mappings
    end
  rescue Exception => e
    puts e.message
    #puts e.back_trace    #for debug mode

    abort
  end
end