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 / ifncsgen.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  68 lines

  1. ############################################################################
  2. #
  3. #    File:     ifncsgen.icn
  4. #
  5. #    Subject:  Program to generate procedure wrappers for functions
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     September 28, 1996
  10. #
  11. ############################################################################
  12. #
  13. #  This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program generates a procedure for every (built-in) function
  18. #  that calls the function.
  19. #
  20. ############################################################################
  21.  
  22. procedure main()
  23.    local name, args, uname
  24.    static case1, case2
  25.  
  26.    initial {
  27.       case1 := &lcase || &ucase
  28.       case2 := &ucase || &lcase
  29.       }
  30.     
  31.    every name := function() do {
  32.       args := arglist(name)
  33.       uname := {
  34.          name ? {
  35.             map(move(1), case1, case2) || tab(0)
  36.             }
  37.          }
  38.       write("procedure ", uname, args)
  39.       write("   static ", "__fnc_", name)
  40.       write("   initial __fnc_", name, " := proc(", image(name), ", 0)")
  41.       if args == "(a[])" then write("   suspend __fnc_", name, " ! a")
  42.       else write("   suspend __fnc_", name, args)
  43.       write("end")
  44.       write()
  45.       }
  46.  
  47. end
  48.  
  49. procedure arglist(name)
  50.    local result, i, arg
  51.  
  52.    i := args(proc(name, 0))
  53.  
  54.    if i < 0 then return "(a[])"
  55.    else if i = 0 then return "()"
  56.    else {
  57.       result := "("
  58.       every arg := ("a" || (1 to i)) do {
  59.          result ||:= arg || ", "
  60.          }
  61.       }
  62.  
  63.    result[-2:0] := ")"
  64.  
  65.    return result
  66.  
  67. end
  68.