b09f7fb397afab7d5a8cb18f5f253f2c54126ebb
[m17n/m17n-docs.git] / utils / usr_filter.rb
1 #! /usr/bin/ruby
2
3 buf = [] 
4 doxy = 0
5
6 def commentblock(buf)
7     unless buf == []    
8       print "/** "      
9       buf.each do |i| print i end
10       print "*/\n"      
11     end 
12    end  
13
14 while gets
15
16   gsub!("@seealso", "@par See Also:")
17   gsub!("@errors", "@par Errors:")
18   gsub!("@returns", "@par Return value:")
19   gsub!("@return", "@par Return value:")
20  #let doxygen find functions
21   gsub!(/[a-zA-Z_]\s\(\)/) {|m| m.delete!(" ")}
22  #make variables in function descriptions shown in bold
23   gsub!(/\$[A-Z_]+/) {|m| m.delete!("$").reverse.downcase!.concat(" b@").reverse}
24
25    case  $_
26      when /^$/
27         if doxy == 1 
28            buf.push($_)
29            end
30      when /\/\/\/\// 
31         commentblock(buf)
32         buf = []
33    
34      when /\/\*\s.*\*\//        # /* comment */ type comment
35         if doxy == 1            
36         buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//")) # should be included only in the example code
37         else
38           if doxy == 0 
39           commentblock(buf)
40           buf = []
41           print $_.gsub!(/\/\*\s.*\*\//," ")                # should be omiited in code
42           end
43         end
44      when /\/\*{2,3}ja.*\*\//   #japanese one liner
45      when /\/\*\*en.*\*\//      #one liner
46      when /\/\*\*\*en.*\*\//    #one liner
47         buf.push($_.gsub!(/\/\*+en/, " ").gsub!(/\*\//, " ")).push("\n")
48      when /\/\*\*\s.*\*\//      #one liner
49      when /\/\*\*\*\s.*\*\//    #one liner
50         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
51
52      when /\/\*{1,2}\s|\/\*{2,3}ja|\/\*\*en/
53         doxy = -1
54      when /\/\*\*\*en/
55         buf.push($_.gsub!(/\/\*+en/, " "))
56         doxy = 1
57      when /\/\*\*\*/    
58         buf.push($_.gsub!(/\/\*+/, " "))
59         doxy = 1
60
61      when /EXAMPLE_CODE/ 
62         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "@code \n"))
63         doxy = 1
64
65      when /#endif/
66         if doxy == 1
67            buf.push($_.gsub!(/#endif/, "@endcode"))
68         else
69            commentblock(buf)
70            buf = []
71            print $_
72         end
73         doxy = 0
74      when /\*\//
75         if doxy == 1
76            buf.push($_.gsub!(/\*\//, " "))
77         end
78         doxy = 0
79      else 
80         case doxy 
81           when -1
82           when 1        
83            buf.push($_) 
84           else 
85            commentblock(buf)
86            buf = []
87            print($_)
88         end
89    end
90 end