*** empty log message ***
[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 #  print "****",  $_, "\n"
17
18   gsub!("@seealso", "@par See Also:")
19   gsub!("@errors", "@par Errors:")
20   gsub!("@returns", "@par Return value:")
21   gsub!("@return", "@par Return value:")
22  #let doxygen find functions
23   gsub!(/[a-zA-Z_]\s\(\)/) {|m| m.delete!(" ")}
24  #make variables in function descriptions shown in bold
25   gsub!(/\$[A-Z_]+/) {|m| m.delete!("$").reverse.downcase!.concat(" b@").reverse}
26
27    case  $_
28      when /^\s*$/
29         if doxy == 1 
30            buf.push($_)
31            end
32      when /\/\*=\*\// 
33         commentblock(buf)
34         buf = []
35    
36      when /^\/\*\s.*\*\//       # /* comment */ type comment
37         if doxy == 1            
38         buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//")) # should be included only in the example code
39         end
40
41      when /\/\*\s.*\*\//        # code + /* comment */ type comment
42         if doxy == 1            
43         buf.push($_.gsub!(/\*\//, " ").gsub!(/\/\*/, "//")) # should be included in the example code
44         else
45          if doxy == 0 
46           commentblock(buf)
47           buf = []
48           print $_.gsub!(/\/\*\s.*\*\//," ")                # should be omiited in code
49           end
50         end
51
52      when /\/\*{2,3}ja.*\*\//   #japanese one liner
53      when /\/\*\*en.*\*\//      #one liner
54      when /\/\*\*\*en.*\*\//    #one liner
55         buf.push($_.gsub!(/\/\*+en/, " ").gsub!(/\*\//, " ")).push("\n")
56      when /\/\*\*\s.*\*\//      #one liner
57      when /\/\*\*\*\s.*\*\//    #one liner
58         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
59
60      when /\/\*{1,2}\s|\/\*{2,3}ja|\/\*\*en/  #this is not for En nor users
61         doxy = -1
62      when /\/\*\*\*en/
63         buf.push($_.gsub!(/\/\*+en/, " "))
64         doxy = 1
65      when /\/\*\*\*/    
66         buf.push($_.gsub!(/\/\*+/, " "))
67         doxy = 1
68
69      when /EXAMPLE_CODE/ 
70         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "\n \n @par Example:\n @code"))
71         doxy = 1
72
73      when /#endif/
74         if doxy == 1
75            buf.push($_.gsub!(/#endif/, "@endcode"))
76         else
77            commentblock(buf)
78            buf = []
79            print $_
80         end
81         doxy = 0
82      when /\*\//
83         if doxy == 1
84            buf.push($_.gsub!(/\*\//, " "))
85         end
86         doxy = 0
87      else 
88         case doxy 
89           when -1
90           when 1        
91            buf.push($_) 
92           else 
93            commentblock(buf)
94            buf = []
95            print($_)
96         end
97    end
98 end
99
100 commentblock(buf)