[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2657 - branches/pingus_sdl
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2657 - branches/pingus_sdl |
Date: |
Mon, 15 Jan 2007 17:21:21 +0100 |
Author: grumbel
Date: 2007-01-15 17:21:21 +0100 (Mon, 15 Jan 2007)
New Revision: 2657
Modified:
branches/pingus_sdl/xml2sexpr.rb
Log:
- some formating improvmenets
Modified: branches/pingus_sdl/xml2sexpr.rb
===================================================================
--- branches/pingus_sdl/xml2sexpr.rb 2007-01-15 15:36:38 UTC (rev 2656)
+++ branches/pingus_sdl/xml2sexpr.rb 2007-01-15 16:21:21 UTC (rev 2657)
@@ -61,34 +61,76 @@
return :unknown
end
+def line_breaker(str)
+ lines = []
+ line = ""
+ word = ""
+
+ str.each_byte{|c|
+ word <<= c
+
+ if c == ?\ then
+ line += word
+ word = ""
+
+ if line.length > 72 then
+ lines.push(line)
+ line = ""
+ end
+ end
+ }
+
+ line += word
+ if not line.empty? then
+ lines.push(line)
+ end
+ return lines
+end
+
def xml2array(section, indent, el)
if el.is_a?(REXML::Text) then
# puts section #, " -> ", $typespec[section], "\n"
case get_type(section)
when :section
# indention white space, ignore it
- when :string
- print "\"#{el.value}\""
when :integer
print el.value.to_i
else
- puts "unknown: section: #{section} #{el.value}"
+ if section != ""
+ puts "unknown: section: #{section} #{el.value}"
+ end
end
elsif el.is_a?(REXML::Element)
case get_type("#{section}/#{el.name}")
when :section
- puts "#{indent}(#{el.name} "
+ if el.children.length == 0 then
+ print "#{indent}(#{el.name} )"
+ else
+ puts "#{indent}(#{el.name} "
+ el.children.each{|child|
+ xml2array("#{section}/#{el.name}", "#{indent} ", child)
+ }
+ print ")"
+ end
+ when :string
+ print "#{indent}(#{el.name} "
el.children.each{|child|
- xml2array("#{section}/#{el.name}", "#{indent} ", child)
+ line_breaker(child.value).each_with_index{|line,idx|
+ if idx == 0 then
+ print "\"#{line}\""
+ else
+ print "\n#{indent} #{" " * el.name.length}\"#{line}\""
+ end
+ }
}
- puts "#{indent} )"
- when :string, :integer
+ print ")"
+ when :integer
print "#{indent}(#{el.name} "
el.children.each{|child|
- xml2array("#{section}/#{el.name}", "#{indent} ", child)
+ print "#{child.value.to_i}"
}
- puts ")"
+ print ")"
when :vector
print "#{indent}(#{el.name} "
print el.elements["x"][0].value
@@ -96,15 +138,17 @@
print el.elements["y"][0].value
print " "
print el.elements["z"][0].value
- puts ")"
+ print ")"
else
puts "#{indent}(#{el.name} "
el.children.each{|child|
xml2array("#{section}/#{el.name}", "#{indent} ", child)
}
- puts "#{indent} )"
+ print "#{indent} )"
end
-
+ if el.next_element then
+ puts ""
+ end
elsif el.is_a?(REXML::Comment)
elsif el.is_a?(REXML::XMLDecl)
else
@@ -117,6 +161,7 @@
dir = File.dirname(arg)
doc = REXML::Document.new(File.new(arg))
doc.children.each{ |el|
+ puts ";; generated by xml2sexpr.rb convert script"
xml2array("", "", el)
}
puts "\n;; EOF ;;"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2657 - branches/pingus_sdl,
grumbel at BerliOS <=