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 / filexref.icn < prev    next >
Text File  |  2000-07-29  |  5KB  |  191 lines

  1. #############################################################################
  2. #
  3. #       File:     filexref.icn
  4. #
  5. #       Subject:  Program to cross-reference files by components
  6. #
  7. #       Author:   David Gamey
  8. #
  9. #       Date:     July 7, 1994
  10. #
  11. #############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  History:
  18. #
  19. #  11Jul94 - D.Gamey -  Reorganized to eliminate empty columns
  20. #  13Jul94 - D.Gamey -  Added dateline & total number of files
  21. #  29Jul94 - D.Gamey -  Page numbers in headers
  22. #   6Jan95 - D.Gamey -  Allow DOS wild cards to select within directories
  23. #  
  24. ############################################################################
  25. #
  26. #  Usage:
  27. #  
  28. #              dir dir1 /b /a:d > dirlist
  29. #              filexref < dirlist
  30. #
  31. #  Note:
  32. #
  33. #              Dir does not preface its results with the parent directory
  34. #              - take care!
  35. #
  36. #  Options:
  37. #
  38. #     -D       Produce an ascii delimited file
  39. #     -h       Exclude hidden files
  40. #     -n       Page Length ... must be integer >= 25 
  41. #
  42. #############################################################################
  43. #
  44. #  Requires:  MS-DOS compatible operating system
  45. #
  46. ############################################################################
  47. #
  48. #  Links:  io, options
  49. #
  50. ############################################################################
  51.  
  52. link io
  53. link options
  54.  
  55. procedure main(arglist)
  56.  
  57. local opt, diropts, dir, paths , fn, ext 
  58. local tempfn, tempf, file, line
  59. local b10, tens, header, _pl, _ppage, _fnw
  60. local _asciid, _exchidden 
  61. local _star, _dot, _sepr, _q
  62. local pagenum, linenum
  63. local N, E, D, DET, t
  64.  
  65. opt   := options(arglist,"D!h!n+")              # parse command line options
  66.  
  67. _asciid := opt["D"]                          # ascii delimited
  68. _exchidden := opt["-h"]                      # exclude hidden files
  69. _pl := ( 25 <= integer(\opt["n"])) | 55      # page length
  70. _fnw  := 10                                  # width for file name field
  71. _ppage := [73,4]                             # position & width of page number
  72.  
  73.  
  74. if \_asciid then 
  75. {
  76.    _star := ",\"@\""
  77.    _dot  := ",\" \""
  78.    _sepr := ","
  79.    _q    := "\"" 
  80. }
  81. else 
  82. {
  83.    _star := "@"
  84.    _dot  := "."
  85.    _sepr := " "
  86.    _q    := ""
  87. }
  88.  
  89. if \_exchidden then 
  90.    diropts := " /b /a:-d-h >> "
  91. else
  92.    diropts := " /b /a:-d   >> "
  93.  
  94. N := set()                                   # file names
  95. E := set()                                   # file extensions
  96. D := set()                                   # directory list
  97. DET := table()                               # directory - extension table
  98.  
  99. if not close(open(tempfn := tempname(),"w")) then
  100.    stop(&errout,"Unable to create temporary file, e.g. ",tempfn)
  101.  
  102. diropts ||:= tempfn
  103.  
  104. while dir := read() do 
  105. {
  106.    dir := trim( dir ? tab(upto('#')) )       # strip icon style comments
  107.    if *dir > 0 then
  108.       system( "dir " || dir || diropts )
  109. }
  110.  
  111. if not ( tempf := open(tempfn,"r") ) then
  112.    stop(&errout,"Unable to open(read) temporary file ",tempfn)
  113.  
  114. while line := map(trim(read(tempf))) do
  115. {
  116.    file := DOS_FileParts(line)
  117.    /DET[file.devpath] := table()
  118.    /DET[file.devpath][file.extension] := set()
  119.    insert( DET[file.devpath][file.extension],  file.name )
  120.    insert( D, file.devpath )
  121.    insert( E, file.extension )
  122.    insert( N, file.name )
  123. }
  124.  
  125. close(tempf)
  126. D := sort( D )
  127. E := sort( E )
  128. N := sort( N )
  129.  
  130. write( _q, "File Inventory Cross-Reference Report -- ", 
  131.            &dateline, _q, "\r\n" )
  132. write( _q, "Directories Searched (cross-reference number and path):", _q )
  133.  
  134. paths := 0
  135. every dir := !D & ext := !E do 
  136.    if \DET[dir][ext] then
  137.       write( right(paths +:= 1, 4), _sepr, _q, dir, " [", ext, "]", _q )
  138.  
  139. if \_asciid then 
  140. {
  141.    write( "\r\n", _q, "Files by Directory:", _q )
  142.    write()
  143.    writes( _q,_q,_sepr, _q,_q )
  144.    every writes( _sepr, 1 to paths )
  145.    write()
  146. }
  147. else 
  148. {
  149.    header := []
  150.    tens := ""
  151.    b10 := repl(" ",10)
  152.    every tens ||:= (b10 || (1 to (paths / 10)))[-10:0]
  153.    put( header, "Files by Directory:" )
  154.    header[1] ||:= right("Page ",_ppage[1] - *header[1]) || repl("X",_ppage[2])
  155.    put( header, left("",_fnw + *_sepr) || tens )
  156.    put( header, 
  157.         left("",_fnw + *_sepr) || 
  158.         repl( "1234567890", (paths / 10) + 1)[1:paths+1] )
  159.    put( header, 
  160.         left("",_fnw + *_sepr) || 
  161.         repl( "----+----|", (paths / 10) + 1)[1:paths+1] )
  162. }
  163.  
  164. linenum := pagenum := 0
  165. every fn := !N do 
  166. {
  167.    if \header & ( ( ( linenum +:= 1 ) % _pl ) = 1 ) then 
  168.    {
  169.       pagenum +:= 1 
  170.       writes( "\f" )
  171.       header[1][-_ppage[2]:0] := right(pagenum,_ppage[2])
  172.       every write( !header ) do linenum +:= 1
  173.    }
  174.    writes( _q,_q,_sepr, _q,left( fn, _fnw),_q )
  175.    every ( dir := !D ) & ( ext := !E ) do 
  176.    {
  177.       if ( t := \DET[dir][ext] ) then
  178.          if member( t, fn ) then
  179.             writes( _star )
  180.          else
  181.             writes( _dot  )
  182.    }
  183.    write()
  184. }
  185.  
  186. write()
  187. write( _q, "Total files in inventory is ", _q, _sepr, *N )
  188.  
  189. exit(0)
  190. end
  191.