*** empty log message ***
[m17n/m17n-docs.git] / utils / usr_filter.rb
1 #! /usr/bin/ruby
2
3 buf = [] 
4 doxy = 0
5 example = 0
6
7 def commentblock(buf)
8     unless buf == []    
9       print "/** "      
10       buf.each do |i| print i end
11       print "*/\n"      
12     end 
13    end  
14
15 while gets
16
17   gsub!("@seealso", "@par See Also:")
18   gsub!("@errors", "@par Errors:")
19   gsub!("@returns", "@par Return value:")
20   gsub!("@return", "@par Return value:")
21  #let doxygen find functions
22   gsub!(/[a-zA-Z_]\s\(\)/) {|m| m.delete!(" ")}
23  #make variables in function descriptions shown in bold
24   gsub!(/\$[A-Z_]+/) {|m| m.delete!("$").reverse.downcase!.concat(" b@").reverse}
25
26   if example == 1
27      case $_ 
28       when /#endif/
29         buf.push($_.gsub!(/#endif/, "@endcode"))
30         example = 0
31       else      
32         buf.push($_)
33     end
34
35     else  # when example == 0
36
37      case  $_
38
39       when /^\s*$/                         
40          if doxy == 1                       # empty line in doxygen comment
41             buf.push($_)
42             end
43
44       when /\/\*=\*\//                      #/*=*/ (flush)
45         commentblock(buf)
46         buf = []
47
48       when /^\/\*\s.*\*\//      # /* comment */ type comment 
49 #       if doxy == 1            
50 #         # should be included only in the example code
51 #         ## We used to do the following substituion as a workaround of
52 #         ## a Doxygen bug.
53 #         ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
54 #         buf.push($_)
55 #       end
56
57       when /\/\*\s.*\*\//       # code + /* comment */ type comment
58 #       if doxy == 1            
59 #         # should be included in the example code
60 #         ## See the above comment.
61 #         ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
62 #         buf.push($_) # should be included in the example code
63 #       else
64           if doxy == 0 
65             commentblock(buf)
66             buf = []
67             print $_.gsub!(/\/\*\s.*\*\//," ") # should be omiited in code
68 #         end
69         end
70
71      when /\/\*{2,3}ja.*\*\//   #japanese one liner
72      when /\/\*\*en.*\*\//      #one liner
73      when /\/\*\*\*en.*\*\//    #one liner
74         buf.push($_.gsub!(/\/\*+en/, " ").gsub!(/\*\//, " ")).push("\n")
75      when /\/\*\*\s.*\*\//      #one liner
76      when /\/\*\*\*\s.*\*\//    #one liner
77         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
78
79      when /\/\*{1,2}\s|\/\*{2,3}ja|\/\*\*en/  #this is not for En nor users
80         doxy = -1
81      when /\/\*\*\*en/
82         buf.push($_.gsub!(/\/\*+en/, " "))
83         doxy = 1
84      when /\/\*\*\*/    
85         buf.push($_.gsub!(/\/\*+/, " "))
86         doxy = 1
87
88      when /EXAMPLE_CODE/ 
89         #start example code lines
90         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "\n \n @par Example:\n @code"))
91         example = 1
92
93      when /\*\//
94         if doxy == 1
95            buf.push($_.gsub!(/\*\//, " "))
96         end
97         doxy = 0
98      else 
99         case doxy 
100           when -1
101           when 1        
102            buf.push($_) 
103           else 
104            commentblock(buf)
105            buf = []
106            print($_)
107         end
108      end        
109    end
110 end
111
112 commentblock(buf)