Home Home > GIT Browse > SLE12-SP4
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Suchanek <msuchanek@suse.de>2019-08-09 08:23:13 +0200
committerMichal Suchanek <msuchanek@suse.de>2019-08-09 08:23:13 +0200
commit398394fe5ff169dc9b36c637d21460d5c91bd048 (patch)
treefb6ddd68e0f28d9f3116929577061aa990f78968
parentaa6b5279bf9c7b56d23fc934e4dff233b9dc9d2e (diff)
scripts/sort_supported.rb: Script for sorting supported.conf
This script uses a heuristic that works on 99% entries. There are two lines in current supported.conf that need adjustment in comment to pass.
-rwxr-xr-xscripts/sort_supported.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/scripts/sort_supported.rb b/scripts/sort_supported.rb
new file mode 100755
index 0000000000..f89890299c
--- /dev/null
+++ b/scripts/sort_supported.rb
@@ -0,0 +1,89 @@
+#!/usr/bin/ruby
+
+def max x, y
+ (x >= y) ? x : y
+end
+
+class String
+ def tablen
+ (length + 8) / 8
+ end
+ def tabfill tabs
+ self + "\t" * (tabs - (length / 8))
+ end
+ def ** other
+ star = nil
+ star = length - 1 if self[length - 1] == '*'
+ star = other.length - 1 if other[other.length - 1] == '*'
+ if star then
+ if self[0...star] == other[0...star] then
+ return 1 if star == length - 1
+ return -1
+ end
+ end
+ return self <=> other
+ end
+end
+
+header = []
+supported = []
+maxtabs = [0,0]
+maxlen = [0,0]
+
+File.open("supported.conf"){|f|
+ f.each_line{|l|
+ l.chomp!
+ l.gsub! %r<//>, '/'
+ split = (l.match %r<^([^[:blank:]/]*)[[:blank:]]+(?:([^[:blank:]/]+)[[:blank:]]+)?(?:([^[:blank:]/]+)[[:blank:]]+)?([^[:blank:]]+/[^[:blank:]]+)(?:[[:blank:]]+(.*))?$>)
+ if ! split then
+ header << l
+ else
+ # [[flag, ..],module,comment,is_kmp]
+ s = [[]]
+ slash = false
+ split[1..-1].each{|e|
+ if slash then
+ raise l + split.inspect if s[2]
+ s[2] = e
+ else
+ if e =~ %r</> then
+ slash = true
+ s[1] = e
+ else
+ s[0] << e if e
+ s[3] = true if e =~ /-kmp/
+ end
+ end
+ }
+ supported << s
+ maxtabs[0] = max(maxtabs[0], s[0].join(" ").tablen)
+ maxlen[0] = max(maxlen[0], s[0].join(" ").length)
+ if s[2] then
+ maxtabs[1] = max(maxtabs[1], s[1].tablen)
+ maxlen[1] = max(maxlen[1], s[1].length)
+ end
+ end
+ }
+}
+
+supported = supported.sort{|s1,s2|
+ cmp = 0
+ if s1[3] then
+ if s2[3] then
+ cmp = s1[0] <=> s2[0]
+ else
+ cmp = -1
+ end
+ elsif s2[3]
+ cmp = 1
+ end
+ cmp != 0 ? cmp : s1[1] ** s2[1]
+}
+
+File.open("supported.conf",'wb'){|f|
+ header.each{|l| f.puts l }
+ supported.each{|s|
+ f.puts s[0].join(" ").tabfill(maxtabs[0]) + (s[2] ? s[1].tabfill(maxtabs[1]) : s[1]) + s[2].to_s
+ }
+}
+#STDERR.puts (0..maxlen[1]).each{|n| STDERR.puts ("a"*n).tabfill(maxtabs[1]) + "|"}