*** 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 /\/\* @[{}] \*\//    # /* comment */ type comment 
49         commentblock(buf)
50         buf = []
51         print($_)
52
53       when /^\/\*\s.*\*\//      # /* comment */ type comment 
54 #       if doxy == 1            
55 #         # should be included only in the example code
56 #         ## We used to do the following substituion as a workaround of
57 #         ## a Doxygen bug.
58 #         ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
59 #         buf.push($_)
60 #       end
61
62       when /\/\*\s.*\*\//       # code + /* comment */ type comment
63 #       if doxy == 1            
64 #         # should be included in the example code
65 #         ## See the above comment.
66 #         ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
67 #         buf.push($_) # should be included in the example code
68 #       else
69           if doxy == 0 
70             commentblock(buf)
71             buf = []
72             print $_.gsub!(/\/\*\s.*\*\//," ") # should be omiited in code
73 #         end
74         end
75
76      when /\/\*{2,3}ja.*\*\//   #japanese one liner
77      when /\/\*\*en.*\*\//      #one liner
78      when /\/\*\*\*en.*\*\//    #one liner
79         buf.push($_.gsub!(/\/\*+en/, " ").gsub!(/\*\//, " ")).push("\n")
80      when /\/\*\*\s.*\*\//      #one liner
81      when /\/\*\*\*\s.*\*\//    #one liner
82         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
83
84      when /\/\*{1,2}\s|\/\*{2,3}ja|\/\*\*en/  #this is not for En nor users
85         doxy = -1
86      when /\/\*\*\*en/
87         buf.push($_.gsub!(/\/\*+en/, " "))
88         doxy = 1
89      when /\/\*\*\*/    
90         buf.push($_.gsub!(/\/\*+/, " "))
91         doxy = 1
92
93      when /EXAMPLE_CODE/ 
94         #start example code lines
95         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "\n \n @par Example:\n @code"))
96         example = 1
97
98      when /\*\//
99         if doxy == 1
100            buf.push($_.gsub!(/\*\//, " "))
101         end
102         doxy = 0
103      else 
104         case doxy 
105           when -1
106           when 1        
107            buf.push($_) 
108           else 
109            commentblock(buf)
110            buf = []
111            print($_)
112         end
113      end        
114    end
115 end
116
117 commentblock(buf)