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