home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / fnctmpl.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  71 lines

  1. ############################################################################
  2. #
  3. #    File:     fnctmpl.icn
  4. #
  5. #    Subject:  Program to produce function templates
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     February 27, 1992
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program processes the rt.db database for the Icon compiler produced
  18. #  by rtt and produces procedures for each Icon function to be used by
  19. #  iftrace.icn.
  20. #
  21. #  The data base is expected from standard input.
  22. #
  23. ############################################################################
  24.  
  25. procedure main()
  26.    local line, header, proto, rettype, name, varargs
  27.  
  28.    while line := read() do
  29.       line ? {
  30.          if pos(0) then {
  31.             header := read() | stop("eof")
  32.             proto := read() | stop("eof")
  33.             header ? {
  34.                if ="$endsect" then exit()
  35.                tab(upto('{'))
  36.                tab(upto(',') + 1)
  37.                if =("*" | "1+") then rettype := "suspend"
  38.                else rettype := "return"
  39.                }
  40.             proto ? {
  41.                ="\"" | next
  42.                name := tab(bal(' ')) | stop("bad proto")
  43.                name := trim(name,',')
  44.                name ?:= {
  45.                   map(move(1),&lcase,&ucase) || tab(0)
  46.                   }
  47.                name ?:= {
  48.                   if find("...") then {
  49.                      varargs := 1
  50.                      tab(upto('(') + 1) || "x[])"
  51.                      }
  52.                   else {
  53.                      varargs := &null
  54.                      tab(0)
  55.                      }
  56.                   }
  57.                }
  58.             write("procedure ",name)
  59.             if /varargs then write("   ",rettype," ",name)
  60.             else {
  61.                name ?:= {
  62.                   tab(upto('('))
  63.                   }
  64.                write("   ",rettype," ",name," ! x")
  65.                }
  66.             write("end\n")
  67.             }
  68.         else if ="$endsect" then exit()
  69.         }
  70. end
  71.