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 / cfuncs / mkfunc.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2001-11-06  |  2KB  |  74 lines

  1. #!/bin/sh
  2. #
  3. #  mkfunc libname file.o ...
  4. #
  5. #  looks at the corresponding C files and generates an Icon procedure
  6. #  corresponding to each C function header that matches the pattern below.
  7. #
  8. #  If a function name begins with "icon_", those characters are removed
  9. #  to form the procedure name.  Otherwise, the name is copied verbatim.
  10.  
  11. LIB=${1?"usage: $0 libname obj..."}
  12. shift
  13.  
  14. cat <<ENDHDR
  15. ############################################################################
  16. #
  17. #    File:     cfunc.icn
  18. #
  19. #    Subject:  Procedures implemented in C
  20. #
  21. #    Author:   Gregg M. Townsend
  22. #
  23. #    Date:     June 8, 2001
  24. #
  25. ############################################################################
  26. #
  27. #     These Icon procedures transparently load and execute functions
  28. #  implemented in C.  Each procedure is a simple stub.  The first call
  29. #  to a stub causes it to replace itself with the corresponding
  30. #  dynamically loaded C function, after which the C function processes
  31. #  the arguments and returns a result (or fails).  Subsequent calls
  32. #  go straight to the C function without involving the Icon stub.
  33. #
  34. #     C functions are loaded from a file "$LIB" that is found by
  35. #  searching \$FPATH.  The default \$FPATH is set by iconx to include
  36. #  this library.
  37. #
  38. ############################################################################
  39. #
  40. #  Requires:  Dynamic loading
  41. #
  42. ############################################################################
  43.  
  44. #  DO NOT EDIT THIS FILE DIRECTLY. 
  45. #  It was created mechanically by the shell file "$0".
  46. #  Edit that instead.
  47.  
  48. link io
  49.  
  50. \$define LIB "$LIB"
  51. ENDHDR
  52.  
  53. LC_ALL=POSIX
  54. export LC_ALL
  55.  
  56. for i
  57. do
  58.    FNAME=`basename $i .o`
  59.    echo ""
  60.    echo "# $FNAME.c:"
  61.    sed '
  62. s/    / /g
  63. s/^int  *//
  64. /^[a-z][a-z0-9_]* *(.*argc.*argv.*).*\/\*:.*\*\//!d
  65. s/\([a-z0-9_]*\).*)\(.*\)$/\1(a[])\2@   return(\1:=pathload(LIB,"\1"))!a;end/
  66. s/^[a-z]/procedure &/
  67. s/\([^"]\)icon_/\1/g
  68. s/)[     ]*\/\*\(.*\)\*\/.*@/)              #\1@/
  69.    ' $FNAME.c | tr '@' '\012'
  70. done
  71.  
  72. echo ""
  73. echo "#---"
  74.