10d409444671e49d38360d1e691ab8b68daf267c
[m17n/m17n-docs.git] / utils / usr_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 See Also:")
17   gsub!("@errors", "@par Errors:")
18   gsub!("@returns", "@par Return value:")
19   gsub!("@return", "@par Return value:")
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           # should be included only in the example code
37           ## We used to do the following substituion as a workaround of
38           ## a Doxygen bug.
39           ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
40           buf.push($_)
41         end
42
43      when /\/\*\s.*\*\//        # code + /* comment */ type comment
44         if doxy == 1            
45           # should be included in the example code
46           ## See the above comment.
47           ## buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//"))
48           buf.push($_) # should be included in the example code
49         else
50           if doxy == 0 
51             commentblock(buf)
52             buf = []
53             print $_.gsub!(/\/\*\s.*\*\//," ") # should be omiited in code
54           end
55         end
56
57      when /\/\*{2,3}ja.*\*\//   #japanese one liner
58      when /\/\*\*en.*\*\//      #one liner
59      when /\/\*\*\*en.*\*\//    #one liner
60         buf.push($_.gsub!(/\/\*+en/, " ").gsub!(/\*\//, " ")).push("\n")
61      when /\/\*\*\s.*\*\//      #one liner
62      when /\/\*\*\*\s.*\*\//    #one liner
63         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
64
65      when /\/\*{1,2}\s|\/\*{2,3}ja|\/\*\*en/  #this is not for En nor users
66         doxy = -1
67      when /\/\*\*\*en/
68         buf.push($_.gsub!(/\/\*+en/, " "))
69         doxy = 1
70      when /\/\*\*\*/    
71         buf.push($_.gsub!(/\/\*+/, " "))
72         doxy = 1
73
74      when /EXAMPLE_CODE/ 
75         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "\n \n @par Example:\n @code"))
76         doxy = 1
77
78      when /#endif/
79         if doxy == 1
80            buf.push($_.gsub!(/#endif/, "@endcode"))
81         else
82            commentblock(buf)
83            buf = []
84            print $_
85         end
86         doxy = 0
87      when /\*\//
88         if doxy == 1
89            buf.push($_.gsub!(/\*\//, " "))
90         end
91         doxy = 0
92      else 
93         case doxy 
94           when -1
95           when 1        
96            buf.push($_) 
97           else 
98            commentblock(buf)
99            buf = []
100            print($_)
101         end
102    end
103 end
104
105 commentblock(buf)