*** 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         else
40           if doxy == 0 
41           commentblock(buf)
42           buf = []
43           print $_.gsub!(/\/\*\s.*\*\//," ")                # should be omiited in code
44           end
45         end
46      when /\/\*{2,3}ja.*\*\//   #japanese one liner
47      when /\/\*\*en.*\*\//      #one liner
48      when /\/\*\*\*en.*\*\//    #one liner
49         buf.push($_.gsub!(/\/\*+en/, " ").gsub!(/\*\//, " ")).push("\n")
50      when /\/\*\*\s.*\*\//      #one liner
51      when /\/\*\*\*\s.*\*\//    #one liner
52         buf.push($_.gsub!(/\/\*+/, " ").gsub!(/\*\//, " ")).push("\n")
53
54      when /\/\*{1,2}\s|\/\*{2,3}ja|\/\*\*en/  #this is not for En nor users
55         doxy = -1
56      when /\/\*\*\*en/
57         buf.push($_.gsub!(/\/\*+en/, " "))
58         doxy = 1
59      when /\/\*\*\*/    
60         buf.push($_.gsub!(/\/\*+/, " "))
61         doxy = 1
62
63      when /EXAMPLE_CODE/ 
64         buf.push($_.gsub!(/#if EXAMPLE_CODE/, "\n \n @par Example:\n @code"))
65         doxy = 1
66
67      when /#endif/
68         if doxy == 1
69            buf.push($_.gsub!(/#endif/, "@endcode"))
70         else
71            commentblock(buf)
72            buf = []
73            print $_
74         end
75         doxy = 0
76      when /\*\//
77         if doxy == 1
78            buf.push($_.gsub!(/\*\//, " "))
79         end
80         doxy = 0
81      else 
82         case doxy 
83           when -1
84           when 1        
85            buf.push($_) 
86           else 
87            commentblock(buf)
88            buf = []
89            print($_)
90         end
91    end
92 end
93
94 commentblock(buf)