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

  1. ############################################################################
  2. #
  3. #    File:     ineeds.icn
  4. #
  5. #    Subject:  Program to print modules required by an Icon program
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     May 18, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #
  18. # Program to determine Icon modules required by an Icon module.  Expects
  19. # environment variable LPATH to be set properly as for the Icon Compiler.
  20. #
  21. ############################################################################
  22.  
  23. procedure main(arg)
  24.   local linkSet,doneSet,fn,f,line,linkName,libSet,a
  25.   libSet := set()
  26.   linkSet := set()
  27.   while a := get(arg) do {
  28.     if match("-I",a) then {
  29.       insert(libSet,"" ~== a[3:0] | get(arg))
  30.     }
  31.     else insert(linkSet,a)
  32.   }
  33.   every insert(libSet,PathDirs())
  34.   doneSet := set()
  35.   while fn := !linkSet do {
  36.     delete(linkSet,fn)
  37.     insert(doneSet,fn)
  38.     f := open(("" | !libSet) || fn || ".icn") | {
  39.       write(&errout,"Can't find \"",fn,"\"")
  40.       next
  41.     }
  42.     while line := read(f) do line ? {
  43.       if ="link" & tab(many(' \t')) then {
  44.         while linkName := trim(tab(upto(', \t#')) |
  45.         (not pos(0),tab(0)),' \t') do {
  46.       if not member(doneSet,linkName) then insert(linkSet,linkName)
  47.       if not ="," then break
  48.       tab(many(' \t'))
  49.     }
  50.       }
  51.     }
  52.     close(f)
  53.   }
  54.   every write(!sort(doneSet))
  55. end
  56.  
  57. procedure PathDirs(s)
  58. #
  59. # Generate the directory names in a "path" string.
  60. #
  61.   local pathDir
  62.   static pathSep,fileSep
  63.   initial {
  64.     if match("MS-DOS" | "OS/2",&features) then {
  65.       pathSep := ";"
  66.       fileSep := "\\"
  67.     }
  68.     else if match("Macintosh",&features) then {
  69.       pathSep := ","
  70.       fileSep := ":"
  71.     }
  72.     else if match("UNIX",&features) then {
  73.       pathSep := ":"
  74.       fileSep := "/"
  75.     }
  76.   }
  77.   /s := getenv("LPATH")
  78.   \s ? {
  79.     until pos(0) do {
  80.       pathDir := tab(find(pathSep) | 0)
  81.       if not match(fileSep,pathDir,-1) then pathDir ||:= fileSep
  82.       suspend "" ~== pathDir
  83.       move(*pathSep)
  84.     }
  85.   }
  86. end
  87.