home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / where.aml < prev    next >
Text File  |  1995-08-10  |  6KB  |  196 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        WHERE.AML                                            */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro searches all directories on one or more   */
  6. /*               disk drives for a filename or filespec. When the     */
  7. /*               search is completed, the located files are           */
  8. /*               displayed in a popup menu.                           */
  9. /*                                                                    */
  10. /* Usage:        Select this macro from the Macro List (on the Macro  */
  11. /*               menu), or run it from the macro picklist <shift f12> */
  12. /*                                                                    */
  13. /*               You will be prompted for the filespec and drives.    */
  14. /*               The filespec and drives must be entered in           */
  15. /*               multi-string format, e.g. 'filespec/drives'. If no   */
  16. /*               drives are specified, then all drives on your        */
  17. /*               computer will be searched (excluding A: and B:).     */
  18. /*                                                                    */
  19. /*               Select a file from the popup menu to display it in   */
  20. /*               an edit window.                                      */
  21. /*                                                                    */
  22. /*               Select the first line of the popup menu to edit the  */
  23. /*               contents of the menu (you can then use the           */
  24. /*               'openword' <ctrl ]> command to open each file).      */
  25. /* ------------------------------------------------------------------ */
  26.  
  27.   // compile time macros and function definitions
  28.   include  bootpath "define.aml"
  29.  
  30.  
  31.   // function to show progress while scanning directories
  32.   function  onscanning (directory found filespec)
  33.  
  34.     // create the progress window
  35.     if not window? 'scan' then
  36.  
  37.       createwindow 'scan'
  38.       setwinobj
  39.       setframe ">b"
  40.       setcolor  border_color   color white on gray
  41.       setcolor  text_color     color black on gray
  42.       settitle "Where is '" + filespec + "'" 'c'
  43.       setborder "1i"
  44.       setshadow 2 1
  45.  
  46.       // center the window
  47.       width  = 60
  48.       height = 16
  49.       ox = (getvidcols - width) / 2
  50.       oy = (getvidrows - height) / 2
  51.       sizewindow ox oy ox + width oy + height "ad"
  52.       writestr directory
  53.  
  54.     elseif found then
  55.       writestr " FOUND" (color brightgreen on gray) (getcoord 'x1') - 7
  56.  
  57.     elseif directory then
  58.       writeline
  59.       writestr directory
  60.  
  61.     else
  62.       destroywindow
  63.     end
  64.  
  65.     display
  66.   end
  67.  
  68.  
  69.   // scan directories recursively for a filespec
  70.   function  scandir (filespec directory resultbuf)
  71.  
  72.     onscanning directory
  73.  
  74.     // is filespec found in the directory?
  75.     if locatefile filespec (getpath directory) then
  76.  
  77.       // wildcard filespec specified?
  78.       if poschar '*?' filespec then
  79.         filebuf = loadbuf (qualify filespec directory)
  80.         if filebuf then
  81.           repeat
  82.             addline (qualify (sendobject "fmgr" "getffile") directory)
  83.                     '' '' resultbuf
  84.           until not down
  85.           destroybuf filebuf
  86.         end
  87.  
  88.       // complete filename was specified
  89.       else
  90.         addline (qualify filespec directory) '' '' resultbuf
  91.       end
  92.  
  93.       // notify progress window that filespec is found
  94.       onscanning directory 1
  95.     end
  96.  
  97.     // get a directory listing
  98.     if loadbuf directory '' '' "dh1" then
  99.       ss = '^' + (char 0)
  100.       if find ss 'x*' then
  101.         // do recursively for all subdirectories
  102.         repeat
  103.           name = qualify (sendobject "fmgr" "getffile") directory
  104.           // don't go back to parent directory
  105.           if (sizeof name) > (sizeof directory) then
  106.             scandir filespec name resultbuf
  107.           end
  108.         until not (find ss 'x')
  109.       end
  110.       destroybuf
  111.     end
  112.   end
  113.  
  114.  
  115.   var filespec
  116.   var drives
  117.   var i
  118.  
  119.   // get default drives (all drives except floppies)
  120.   drives = sub 'B' '' (sub 'A' '' (getdisk 'm'))
  121.  
  122.   if _PromptStyle == 'd' then
  123.      dialog "Where is" 65 5 "c"
  124.      field "&Filespec: >"  3  2 40 (getname (getbufname)) "_load"
  125.      field "&Drives:   >"  3  4 37 drives
  126.      button "O&k"      55 2 8
  127.      button "Cancel"   55 4 8
  128.      if (getdialog ref filespec ref drives) <> 'Ok' then
  129.        return
  130.      end
  131.   else
  132.     // get filespec to search for and drives to search through
  133.     file_and_drives = ask "[filespec/drives] Where is"
  134.     splitstr '' file_and_drives  ref filespec  ref drives
  135.   end
  136.  
  137.   if not filespec then
  138.     return
  139.   end
  140.  
  141.   // search all available drives (except floppies), if none specified
  142.   if not drives then
  143.     drives = sub 'B' '' (sub 'A' '' (getdisk 'm'))
  144.   end
  145.  
  146.   // convert to upper case
  147.   filespec = upcase filespec
  148.   drives   = upcase drives
  149.  
  150.   // create buffer to hold located files
  151.   resultbuf = createbuf
  152.   if resultbuf then
  153.  
  154.     // set first line in resultbuf
  155.     ovltext "≡≡≡≡≡≡ Select this line to edit the file list ≡≡≡≡≡≡"
  156.  
  157.     // setup progress window
  158.     onscanning '' '' filespec
  159.  
  160.     // scan each drive
  161.     repeat
  162.       i = i + 1
  163.       directory = drives [i] + ":\\*.*"
  164.       scandir filespec directory resultbuf
  165.     until i >= (sizeof drives)
  166.  
  167.     // destroy progress window
  168.     onscanning
  169.  
  170.     currbuf resultbuf
  171.     if getlines > 1 then
  172.  
  173.       // sort and display the located file list in a popup menu
  174.       sendobject "fmgr" "fsort" 'n'
  175.       file = popup resultbuf "Where is '" + filespec + "'" 60
  176.  
  177.       if file then
  178.         if file [1] == '≡' then
  179.           // edit the file list
  180.           delline 1 1 resultbuf
  181.           setbufname (qualify "TEMP.TXT" (getbufname (getwinbuf))) resultbuf
  182.           openbuf resultbuf
  183.           return
  184.         else
  185.           // open the selected file
  186.           open file
  187.         end
  188.       end
  189.     else
  190.       display
  191.       say filespec + " not found" 'b'
  192.     end
  193.     destroybuf resultbuf
  194.   end
  195.  
  196.