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