#variable initialize
state = "INIT"
f.each_line do |l|
+ l.tr!("\r","")
# commant
if l.strip.start_with? "#" then next end
- field_name = l.split(':')[0].strip
+ field_name = l.split(':')[0]
case state
when "INIT" then
case field_name
- when /^$/ then next
- when /^Source$/i then
+ when /^[ \t]*$/ then next
+ when /^[ \t]*Source[ \t]*$/i then
state = "COMMON"
if common_source.empty? then common_source = l.sub(/^[ \t]*Source[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
- when /^Version$/i then
+ when /^[ \t]*Version[ \t]*$/i then
state = "COMMON"
if common_version.empty? then common_version = check_version l.sub(/^[ \t]*Version[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
- when /^Maintainer$/i then
+ when /^[ \t]*Maintainer[ \t]*$/i then
state = "COMMON"
if common_maintainer.empty? then common_maintainer = l.sub(/^[ \t]*Maintainer[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
- when /^Package$/i then
+ when /^[ \t]*Package[ \t]*$/i then
state = "PACKAGE"
package_name = l.sub(/^[ \t]*Package[ \t]*:[ \t]*/i,"").strip
if not package_name.empty? then
else
raise RuntimeError, "Package name is not set in \"#{file}\" file"
end
- when /^\*[ \t]*([0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*)[ \t]*$/ then
+ when /^\*[ \t]*([0-9][.0-9]*)[ \t]*$/ then
state = "CHANGELOG"
change_log[change_version] = change_contents.strip if not change_version.nil?
change_version = Version.new($1)
change_contents = ""
- when /^Include$/i then
+ when /^[ \t]*Include[ \t]*$/i then
pfile = File.dirname(file) + "/" + l.sub(/^[ \t]*Include[ \t]*:[ \t]*/i,"").strip
if File.exist? pfile then
pkglist = pkglist + (Parser.read_multy_pkginfo_from pfile)
else
raise RuntimeError, "Not exist \"#{pfile}\""
end
- when /^ORIGIN$/ then #for compatable
+ when /^[ \t]*ORIGIN[ \t]*$/ then #for compatable
multi_line = nil
next
else raise RuntimeError, "Can't parse below line in \"#{file}\" file \n\t#{l}"
end
when "COMMON" then
case field_name
- when /^$/ then state = "INIT"
- when /^Source$/i then
+ when /^[ \t]*$/ then state = "INIT"
+ when /^[ \t]*Source[ \t]*$/i then
state = "COMMON"
if common_source.empty? then common_source = l.sub(/^[ \t]*Source[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
- when /^Version$/i then
+ when /^[ \t]*Version[ \t]*$/i then
state = "COMMON"
if common_version.empty? then common_version = check_version l.sub(/^[ \t]*Version[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
- when /^Maintainer$/i then
+ when /^[ \t]*Maintainer[ \t]*$/i then
state = "COMMON"
if common_maintainer.empty? then common_maintainer = l.sub(/^[ \t]*Maintainer[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
- when /^ORIGIN$/ then #for compatable
+ when /^[ \t]*ORIGIN[ \t]*$/ then #for compatable
multi_line = nil
next
else raise RuntimeError, "Can't parse below line in \"#{file}\" file \n\t#{l}"
end
when "PACKAGE" then
case field_name
- when /^$/ then
+ when /^[ \t]*$/ then
state = "INIT"
if not package.package_name.empty? then
pkglist.push package
else raise RuntimeError, "Package name is not set in \"#{file}\" file"
end
multi_line = nil
- when /^Source$/i then
+ when /^[ \t]*Source[ \t]*$/i then
if common_source.empty? and package.source.empty? then package.source = l.sub(/^[ \t]*Source[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
multi_line = nil
- when /^Version$/i then
+ when /^[ \t]*Version[ \t]*$/i then
if common_version.empty? and package.version.empty? then package.version = check_version l.sub(/^[ \t]*Version[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
multi_line = nil
- when /^Maintainer$/i then
+ when /^[ \t]*Maintainer[ \t]*$/i then
if common_maintainer.empty? and package.maintainer.empty? then package.maintainer = l.sub(/^[ \t]*Maintainer[ \t]*:[ \t]*/i,"").strip
else raise RuntimeError, "#{field_name} information is conflict in \"#{file}\" file\nIf use #{field_name} field in Common section then Package section can't contain #{field_name} field"
end
multi_line = nil
- when /^OS$/i then
+ when /^[ \t]*OS[ \t]*$/i then
package.os_list = l.sub(/^[ \t]*OS[ \t]*:[ \t]*/i,"").tr(" \t\n\r", "").split(",")
package.os = package.os_list[0]
multi_line = nil
- when /^Label$/i then
+ when /^[ \t]*Label[ \t]*$/i then
package.label = l.sub(/^[ \t]*Label[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^Build-host-os$/i then
+ when /^[ \t]*Build-host-os[ \t]*$/i then
package.build_host_os = l.sub(/^[ \t]*Build-host-os[ \t]*:[ \t]*/i,"").tr(" \t\n\r", "").split(",")
multi_line = nil
- when /^Attribute$/i then
+ when /^[ \t]*Attribute[ \t]*$/i then
package.attribute = l.sub(/^[ \t]*Attribute[ \t]*:[ \t]*/i,"").tr(" \t\n\r","").split("|")
multi_line = nil
- when /^Install-dependency$/i then
+ when /^[ \t]*Install-dependency[ \t]*$/i then
package.install_dep_list = dep_parser l.sub(/^[ \t]*Install-dependency[ \t]*:[ \t]*/i,"").split(',')
multi_line = nil
- when /^Build-dependency$/i then
+ when /^[ \t]*Build-dependency[ \t]*$/i then
package.build_dep_list = dep_parser l.sub(/^[ \t]*Build-dependency[ \t]*:[ \t]*/i,"").split(',')
multi_line = nil
- when /^Source-dependency$/i then
+ when /^[ \t]*Source-dependency[ \t]*$/i then
package.source_dep_list = dep_parser l.sub(/^[ \t]*Source-dependency[ \t]*:[ \t]*/i,"").split(',')
multi_line = nil
- when /^Conflicts$/i then
+ when /^[ \t]*Conflicts[ \t]*$/i then
package.conflicts = dep_parser l.sub(/^[ \t]*Conflicts[ \t]*:[ \t]*/i,"").split(',')
multi_line = nil
- when /^Src-path$/i then
+ when /^[ \t]*Src-path[ \t]*$/i then
package.src_path = l.sub(/^[ \t]*Src-path[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^Path$/i then
+ when /^[ \t]*Path[ \t]*$/i then
package.path = l.sub(/^[ \t]*Path[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^Origin$/i then
+ when /^[ \t]*Origin[ \t]*$/i then
package.origin = l.sub(/^[ \t]*Origin[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^SHA256$/i then
+ when /^[ \t]*SHA256[ \t]*$/i then
package.checksum = l.sub(/^[ \t]*SHA256[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^Size$/i then
+ when /^[ \t]*Size[ \t]*$/i then
package.size = l.sub(/^[ \t]*Size[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^Uncompressed-size$/i then
+ when /^[ \t]*Uncompressed-size[ \t]*$/i then
package.uncompressed_size = l.sub(/^[ \t]*Uncompressed-size[ \t]*:[ \t]*/i,"").strip
multi_line = nil
- when /^Description$/i then
+ when /^[ \t]*Description[ \t]*$/i then
package.description = l.sub(/^[ \t]*Description[ \t]*:[ \t]*/i,"").strip
multi_line = "Description"
- when /^ORIGIN$/ then #for compatable
+ when /^[ \t]*ORIGIN[ \t]*$/ then #for compatable
multi_line = nil
next
- when /^C-/ then
+ when /^[ \t]*C-/ then
if package.custom.empty? then package.custom = l.rstrip
else package.custom = package.custom + "\n" + l.rstrip
end
end
when "CHANGELOG" then
case field_name
- when /^$/ then
+ when /^[ \t]*$/ then
state = "INIT"
if not change_version.nil? then
if change_log[change_version].nil? then change_log[change_version] = change_contents.strip
end
change_version = nil
change_contents = ""
- when /^\*[ \t]*([0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*)[ \t]*$/ then
+ when /^\*[ \t]*([0-9][.0-9]*)[ \t]*$/ then
if not change_version.nil? then
if change_log[change_version].nil? then change_log[change_version] = change_contents.strip
else raise RuntimeError, "change log version is duplicated in \"#{file}\" file \n\t#{l}"
end
def Parser.check_version(version)
- if not version =~ /^[0-9][0-9]*(.[0-9][0-9]*)*$/ then
- raise RuntimeError, "Version format not matched \"#{version}\"\nVersion format must be \"{digit}.{digit}.{digit}\""
+ if not version =~ /^[0-9][.0-9]*$/ then
+ raise RuntimeError, "Version format not matched \"#{version}\"\nVersion format must be \"{digit}.{digit}...\""
end
return version
end