home *** CD-ROM | disk | FTP | other *** search
/ Bila Vrana / BILA_VRANA.iso / 028A / AUROR.ZIP / WHERE.AML < prev    next >
Text File  |  1996-07-17  |  4KB  |  168 lines

  1. //--------------------------------------------------------------------
  2. // WHERE.AML
  3. // Where-is Utility, (C) 1993-1996 by nuText Systems
  4. //
  5. // (see Where.dox for user help)
  6. //
  7. // This macro searches all directories on one or more disk drives for a
  8. // filename or filespec. After the search has completed, a file manager
  9. // window will be displayed, listing all the located files in
  10. // fully-qualified format.
  11. //
  12. // Usage:
  13. //
  14. // Select this macro from the Macro List (on the Macro menu), or run it
  15. // from the macro picklist <shift f12>.
  16. //--------------------------------------------------------------------
  17.  
  18. // compile time macros and function definitions
  19. include  bootpath "define.aml"
  20.  
  21. constant where_border_color        = color white on gray
  22. constant where_text_color          = color black on gray
  23. constant where_border_flash_color  = color brightgreen on gray
  24. constant where_south_title_color   = color darkgray on green
  25.  
  26. // create the status window
  27. private function createstatus (filespec)
  28.   createwindow 'scan'
  29.   setframe ">bsv"
  30.   setcolor  border_color        where_border_color
  31.   setcolor  north_title_color   where_border_color
  32.   setcolor  south_title_color   where_border_color
  33.   setcolor  text_color          where_text_color
  34.   setcolor  border_flash_color  where_border_flash_color
  35.   setcolor  south_title_color   where_south_title_color
  36.   settitle "Where is " + filespec
  37.   setwinctrl "≡"
  38.   setborder "1i"
  39.   setshadow 2 1
  40.  
  41.   // center the window
  42.   width  = 67
  43.   height = 14
  44.   ox = (getvidcols - width) / 2
  45.   oy = (getvidrows - height) / 2
  46.   sizewindow ox oy ox + width oy + height "ad"
  47. end
  48.  
  49. variable resultbuf, filespec, formatopt
  50.  
  51. dircount = 0
  52. filecount = 0
  53.  
  54. // scan directories recursively for a filespec
  55. private function scandir (filespec directory)
  56.  
  57.   // is filespec found in the directory?
  58.   if file? filespec directory then
  59.     fullspec = qualify filespec directory
  60.  
  61.     // wildcard filespec specified?
  62.     if poschar '*?' filespec then
  63.       insertbuf fullspec resultbuf '' "fh" + formatopt '' '' (getlines)
  64.       filecount = filecount + (getloadinfo 'f')
  65.  
  66.     // complete filename was specified
  67.     else
  68.       addline (getfileinfo fullspec 'e' + formatopt) '' '' resultbuf
  69.       filecount = filecount + 1
  70.     end
  71.     writeline fullspec
  72.   end
  73.  
  74.   // scan window status line
  75.   dircount = dircount + 1
  76.   settitle  "Files: " + (thousands filecount) +
  77.             "  Directories Searched: " + (thousands dircount) 'sl' 2
  78.   display
  79.  
  80.   // get a directory listing
  81.   if loadbuf directory + "*.*" '' '' "dhs" + formatopt then
  82.     if getloadinfo 'd' then
  83.       repeat
  84.         scandir filespec (gettext)
  85.       until not down
  86.     end
  87.     destroybuf
  88.   end
  89. end
  90.  
  91. macrofile = arg 1
  92.  
  93. // called by Lib.x when a key is entered in the dialog box
  94. function ondialog (keycode)
  95.   // macro help
  96.   if keycode == <f1> then
  97.     helpmacro macrofile
  98.   end
  99. end
  100.  
  101. // set default drives (all drives except floppies)
  102. initdrives = sub 'B' '' (sub 'A' '' (getdisk 'm'))
  103. drives = initdrives
  104.  
  105. // dialog box to get filespec and drives
  106. dialog "Where is" 65 5 "c"
  107. field "&Search for: >"  3  2 38 (getname (getbufname)) "_load"
  108. field "In &Drives:  >"  3  4 35 drives
  109. button "O&k"      55 2 8
  110. button "Cancel"   55 4 8
  111. if (getdialog ref filespec ref drives) <> 'Ok' then
  112.   return
  113. end
  114.  
  115. // check filespec and drives
  116. filespec = onname filespec
  117. path = getpath filespec
  118. if path then
  119.   filespec = getname filespec
  120. else
  121.   path = '\\'
  122. end
  123.  
  124. if not filespec then
  125.   filespec = "*.*"
  126. end
  127.  
  128. // directory format for resultbuf
  129. formatopt = 'vq'+ _NameStyle + (if? (pos 'k' _FmgrOpt) 'k')
  130.  
  131. // create result buffer and status window
  132. resultbuf = createbuf
  133. createstatus filespec
  134. settitle "Press <ctrl break> to stop" 'r' 3
  135.  
  136. if path [2] == ':' then
  137.   scandir (getname filespec) path
  138. else
  139.   // scan each drive
  140.   if not drives then
  141.     drives = initdrives
  142.   end
  143.   drives = upcase drives
  144.   for i = 1 to length drives do
  145.     scandir filespec (onname drives [i]) + ":" + path
  146.   end
  147.   breakoff
  148. end
  149.  
  150. // cleanup
  151. breakoff
  152. destroywindow
  153. currbuf resultbuf
  154.  
  155. // success
  156. if getlines > 1 then
  157.   // delete first blank line
  158.   delline
  159.   setbufname filespec + (if? not (poschar '*?' filespec) '*' '')
  160.   queue "openbuf" resultbuf
  161.   say "Sorting..."
  162.  
  163. // nothing found
  164. else
  165.   destroybuf
  166.   queue "msgbox" filespec + " not found"
  167. end
  168.