sample/mkproto.rb


DEFINITIONS

This source file includes following functions.


   1  $/ = nil
   2  while line = gets()
   3    if /^((void|VALUE|int|char *\*|ID|struct [\w_]+ *\*|st_table *\*) *)?\n([\w\d_]+)\(.*\)\n\s*((.+;\n)*)\{/ =~ line
   4      line = $'
   5      printf "%s %s(", $2, $3
   6      args = []
   7      for arg in $4.split(/;\n\s*/)
   8        arg.gsub!(/ +/, ' ')
   9        if arg =~ /,/
  10          if arg =~ /(([^*]+) *\** *[\w\d_]+),/
  11            type = $2.strip
  12            args.push $1.strip
  13            arg = $'
  14          else
  15            type = ""
  16          end
  17          while arg.sub!(/(\** *[\w\d_]+)(,|$)/, "") && $~
  18            args.push type + " " + $1.strip
  19          end
  20        else
  21          args.push arg.strip
  22        end
  23      end
  24      printf "%s);\n", args.join(', ')
  25      redo
  26    end
  27  end