*** empty log message ***
[m17n/m17n-docs.git] / utils / ja_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 »²¾È:")
18   gsub!("@errors", "@par ¥¨¥é¡¼:")
19   gsub!("@returns", "@par Ìá¤êÃÍ:")
20   gsub!("@return", "@par Ìá¤êÃÍ:")
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      when /^\s*$/
39         if doxy == 1                        # empty line in doxygen comment
40            buf.push($_)
41            end
42      when /\/\*=\*\//                         #/*=*/ (flush)
43         commentblock(buf)
44         buf = []
45    
46       when /^\/\*\s.*\*\//      # /* comment */ type comment 
47 #       if doxy == 1            
48 #         # should be included only in the example code
49 #         ## We used to do the following substituion as a workaround of
50 #         ## a Doxygen bug.
51 #         ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
52 #         buf.push($_)
53 #       end
54
55       when /\/\*\s.*\*\//       # code + /* comment */ type comment
56 #       if doxy == 1            
57 #         # should be included in the example code
58 #         ## See the above comment.
59 #         ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
60 #         buf.push($_) # should be included in the example code
61 #       else
62           if doxy == 0 
63             commentblock(buf)
64             buf = []
65             print $_.gsub!(/\/\*\s.*\*\//," ") # should be omiited in code
66 #         end
67         end
68
69      when /\/\*{2,3}en.*\*\//   #english one liner is omitted
70      when /\/\*\*ja.*\*\//      #one liner
71      when /\/\*\*\*ja.*\*\//    #one liner
72         buf.push($_.gsub!(/\/\*+ja/, " ").gsub!(/\*\//, " ")).push("\n")
73      when /\/\*\*\s.*\*\//      #one liner
74      when /\/\*\*\*\s.*\*\//    #one liner
75         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
76
77      when /\/\*{1,2}\s|\/\*{2,3}en|\/\*\*ja/  #this is not for Ja nor users
78         doxy = -1
79      when /\/\*\*\*ja/
80         buf.push($_.gsub!(/\/\*+ja/, " "))
81         doxy = 1
82      when /\/\*\*\*/    
83         buf.push($_.gsub!(/\/\*+/, " "))
84         doxy = 1
85
86      when /EXAMPLE_CODE/ 
87         #start example code lines
88         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "\n \n @par Î㡧 \n @code"))
89         example = 1
90
91      when /\*\//
92         if doxy == 1
93            buf.push($_.gsub!(/\*\//, " "))
94         end
95         doxy = 0
96      else 
97         case doxy 
98           when -1
99           when 1        
100            buf.push($_) 
101           else 
102            commentblock(buf)
103            buf = []
104            print($_)
105         end
106     end
107    end
108 end
109
110 commentblock(buf)
111
112 # Local Variables:
113 # coding: euc-jp
114 # End: