autocolors 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def up(c,last)
4
+ return nil if (c.nil? || c.length == 0)
5
+ return last if c.upcase == c.downcase
6
+ return c.upcase == c
7
+ end
8
+
9
+ FULLWORDS = ['preproc', 'nontext', 'specialkey', 'errormsg', 'moremsg',
10
+ 'warningmsg', 'modemsg', 'matchparen','spellbad', 'spellrare', 'spellcap',
11
+ 'spelllocal', 'specialchar', 'precondit', 'specialcomment', 'storageclass',
12
+ 'typedef', 'colorcolumn'].join('|')
13
+
14
+ def wordparts(word)
15
+ word = word.strip.gsub(/#{FULLWORDS}/ium){|m| m.capitalize}
16
+ res = []; acc = []; upc = nil
17
+ word = word.split //um
18
+ begin
19
+ letter = word.shift
20
+ cupc = up(letter, upc)
21
+ if cupc != upc
22
+ if cupc # lowercase to uppercase
23
+ res << acc.join('').downcase unless acc.size == 0
24
+ acc = [letter]
25
+ else # uppercase to lowercase
26
+ mine = acc.pop
27
+ res << acc.join('').downcase unless acc.size == 0
28
+ acc = [mine, letter]
29
+ end
30
+ else acc << letter end
31
+ upc = cupc
32
+ end while word.size > 0
33
+ res << acc.join('').downcase unless acc.size == 0
34
+ res = res.join('_')
35
+ return res.split(/_+/).reject{|s|(s.nil? || s.length==0)}.compact
36
+ end
37
+
38
+ mappings = {}
39
+ IO.readlines('./statements.list').each do |stmt|
40
+ orig = stmt
41
+ next unless stmt.start_with? 'map'
42
+ stmt = stmt.split(' ')
43
+ next unless stmt.size == 3
44
+ _, from, to = stmt
45
+ from = wordparts(from)
46
+ to = wordparts(to)
47
+ from[0] = '(lang)' if from.size > 1
48
+
49
+ fr = []
50
+ begin
51
+ fr << from.pop
52
+ fr << from.pop if from.last == '(lang)'
53
+ source = fr.reverse.join('/')
54
+ dest = to.join('/')
55
+ source = "#{from.size}/#{source}" if from.size > 0
56
+ mappings[dest] ||= {}
57
+ mappings[dest][source] ||= 0
58
+ mappings[dest][source] += 1
59
+ end while from.size > 0
60
+ end
61
+
62
+ mappings = mappings.map do |dest, sources|
63
+ sources = sources.to_a.reject{|src,num| num < 3 }
64
+ sources = sources.to_a
65
+ mag = sources.inject(0){|a,sn| a + sn[1]}
66
+ [dest, mag, sources.sort_by{|s,n| - n}]
67
+ end
68
+ require 'pp'
69
+ pp mappings.sort_by{|d,mag,srs| - mag }.reject{|d,mag,srs| (mag < 2 || srs.size == 0)}