96: def read(file)
97: text = Puppet::Util::FileType.filetype(:flat).new(file).read
98: raise "Could not find #{file}" if text.nil?
99:
100: section = nil
101: optname = nil
102: line = 0
103: @files[file] = []
104: text.each_line do |l|
105: line += 1
106: if l.strip.empty? || "#;".include?(l[0,1]) ||
107: (l.split(nil, 2)[0].downcase == "rem" && l[0,1].downcase == "r")
108:
109: if section.nil?
110: @files[file] << l
111: else
112: section.add_line(l)
113: end
114: elsif " \t\r\n\f".include?(l[0,1]) && section && optname
115:
116: section[optname] += "\n#{l.chomp}"
117: elsif l =~ /^\[([^\]]+)\]/
118:
119: section.mark_clean unless section.nil?
120: section = add_section($1, file)
121: optname = nil
122: elsif l =~ /^\s*([^\s=]+)\s*\=(.*)$/
123:
124:
125: if section.nil?
126: raise "#{file}:#{line}:Key/value pair outside of a section for key #{$1}"
127: else
128: section[$1] = $2
129: optname = $1
130: end
131: else
132: raise "#{file}:#{line}: Can't parse '#{l.chomp}'"
133: end
134: end
135: section.mark_clean unless section.nil?
136: end