Method: Ccfg::Handler#parse_line

Defined in:
lib/ccfg/handler.rb

#parse_line(line, deflist) ⇒ Object



7
8
9
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
# File 'lib/ccfg/handler.rb', line 7

def parse_line(line, deflist)
  if line.length > 0 then
 if line.include? Ccfg::CCONFIGURE_DEFINE_DIRECTIVE then
      line.strip!
      lineary = line.split(' ')
      if lineary.size >=2 and lineary[0] == Ccfg::CCONFIGURE_DEFINE_DIRECTIVE then
        deflist.each do |defname, defval|
          if defname == lineary[1] then
            line = "#define #{defname} #{defval}"
            if lineary.size > 2 then
              comment = ''
              tail = ''
              lineary.each do |e|
                tail += "#{e} "
              end
              if tail.include? "//" then
                comment = tail[tail.index("//") + "//".length, tail.length]
                comment.strip!
                comment = " //#{comment}"
              elsif tail.include? "/*" then
                start_index = tail.index("/*") + "/*".length
                len = tail.index("*/") - start_index
                comment = tail[start_index, len]
                comment.strip!
                comment = " /*#{comment} */"
              end
              line += comment
            end
            return line
          end
        end
        line = "/* #undef #{lineary[1]} */"
      end
    end
  end
  return line
end