*** empty log message ***
[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-z_]\s\(\)/) {|m| m.delete!(" ")}
22  #make variables in function descriptions shown in bold
23   gsub!(/\$[A-Z_]+/) {|m| m.delete!("$").reverse.downcase!.concat(" e@").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}en.*\*\//   #english one liner is omitted
45      when /\/\*{2,3}ja.*\*\//   #one liner
46         buf.push($_.gsub!(/\/\*+ja/, " ").gsub!(/\*\//, " "))
47      when /\/\*{2,3}.*\*\//     #one liner
48         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " "))
49
50      when /\/\*\s|\/\*{2,3}en/
51         doxy = -1
52      when /\/\*{2,3}ja/
53         buf.push($_.gsub!(/\/\*+ja/, " "))
54         doxy = 1
55      when /\/\*{2,3}/   
56         buf.push($_.gsub!(/\/\*+/, " "))
57         doxy = 1
58
59      when /EXAMPLE_CODE/ 
60         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "@par Î㡧 \n @code \n"))
61         doxy = 1
62
63      when /#endif/
64         if doxy == 1
65            buf.push($_.gsub!(/#endif/, "@endcode"))
66         else
67            commentblock(buf)
68            buf = []
69            print $_
70         end
71         doxy = 0
72      when /\*\//
73         if doxy == 1
74            buf.push($_.gsub!(/\*\//, " "))
75         end
76         doxy = 0
77      else 
78         case doxy 
79           when -1
80           when 1        
81            buf.push($_) 
82           else 
83            commentblock(buf)
84            buf = []
85            print($_)
86         end
87    end
88 end