 File CD.TXT - Version 4.04 Released 02/11/96 - Mike Bessy 75300,1215
 --------------------------------------------------------------------

 PURPOSE:

  This file outlines a disk navigation system for 4DOS/4OS2 users.  It
  requires no external program and can probably replace most any "CD Utility"
  add-on often suggested to users of the more restrictive free sample command
  processors generally bundled with various DOS and OS/2 versions.

 REQUIREMENTS:

   4DOS 5.5 or 4OS2 2.5
   at least 512 bytes of free alias space.
   at least 128 bytes of free environment space.

 LEGALITIES:

  4DOS is a registered trademark and 4OS2 is a trademark of JP Software,
  Inc., PO Box 1470, East Arlington, MA 02174 (617-646-3975).

  This file is offered as an example of 4DOS/4OS2 shell programming and a
  demonstration of the power available to users of JP Software's command
  processors.  It may be freely distributed as long as no fee is charged
  and its contents are not altered without JP Software's consent.

  No guarantee is made that the information in this file is correct, and
  that the various components will work as expected.  This file is provided
  solely to demonstrate some possible techniques.  Actual implementation
  responsibility rests entirely with the reader.

 LIMITATIONS:

  Many of the "bells & whistles" may be overkill for many users, and might
  prove to be too slow or too inconvenient for slower or floppy-only
  machines.  This file is meant to give users a starting point from which
  to build a system which meets their specific needs.

 HIGHLIGHTS:

      CD {directory name} goes to that directory
      CD {string} goes to the first occurrence of 'string' in the Directories
       List File
      CD by itself returns to the previous current directory - if
       the search string is not found, CD beeps and echoes the current
       directory
      GO (or G) by itself displays all the occurrences of the last
       search string in a "popup windows" for easy selection
      GO (or G) {string} is equivalent to CD
      Additional keywords may be added manually to the Directories List
       File, as in:  "d:\path\foo  bar here"
      The file names and locations are merely examples, and should be
       modified to reflect _your_ specific configuration.

 COMPONENTS:

      optional REFRESH.BTM batch file to automatically create the ASCII
       list of directories.  The directories list can also be easily
       created and maintained with any ASCII editor.

      aliases in a format suitable for inclusion into a file to be
       loaded at boot time with the "alias /r" command.

 USAGE:

    Create an ASCII file containing the name of all the directories on
     your system.  If you prefer, you can use the enclosed file
     "REFRESH.BTM" to get things started.  Feel free to add, after each
     directory name, any keywords you may want to use later to go to that
     directory, such as:
         d:\cserve\wincim    compuserve CIS
         d:\path\xtalk\xts   scripts crosstalk
	 d:\path\123         lotus wk1

    Load the enclosed "CD*D" alias and optionally "G*O" and "GX" aliases.

    To change directories, type CD followed by a valid directory name,
     if you know it, or any partial name, eg. "CD DOC".

    If the requested directory exists, 4DOS/4OS2 will take you there. If
     not, you will go to the first match found on the string you provided,
     eg. "C:\COMM\CSERVE\DOC".

    If the directory was not the one you wanted, you can type "GO", or
     "G" to "pop up" a selection window with a list of all possible matches.
     Use the conventional window navigation keys to select the drive and
     directory you want and press ENTER to go there.  To cancel without
     changing directory, hit ESCAPE.

    If GO is invoked with an argument, it will behave exactly like CD.

    The search algorithm allows you to type "CD keyword", eg. "CD CIM" to
     go to the directory paired with that keyword in the DIR file
     ("C:\COMM\CSERVE\DOC" in the previous example)

    Either CD or GO can include other command to be executed after going to
     the new directory.  Anything after the first argument will be
     processed as a command.  For example, "g pc list *.log" will go to
     whatever drive and directory contains the string "pc" in its name or as
     a keyword in the directories list file ("d:\comm\procomm\pc", perhaps),
     and will list any file with the "log" extension there.

    Make sure you use a consistent name for the directory file.  The
     example assumes "c:\cdd.ini", but it can be anything you want,
     as long as REFRESH.BTM and aliases "CD*D" and "G*O" all use the same
     file name.  Note that the file can be given the "system" and/or "hidden"
     attributes if desired (see the ATTRIB command for details).

    This scheme assumes that your directory structure is fairly static.  If
     you often create many new directories,  you may want to modify MD and
     RD so that they automatically maintain the  directory file.  See the
     "ENHANCEMENTS" section below for a few thoughts, but the potential
     extensions are too numerous to detail here.  Please *experiment*!

 REFRESH.BTM:

   Notes:

    The logic assumes that you're using drive letters in alphabetical order
     ending with the drive defined as "last drive" by the operating system and
     reported by 4DOS/4OS2 in the "_lastdisk" variable.  If your configuration
     differs, you may have to modify the file.

    If you invoke REFRESH.BTM without an argument, it will scan all available
     drives starting with "C:", bypassing any drive reported as "removable"
     or "CD-ROM".

    If you invoke REFRESH.BTM with an argument( eg. "refresh c"), it will
     assume the argument is a drive letter and will only process that drive,
     appending to any existing directories list file.  It is recommended
     that only non-removable partitions be listed.

    You _must_ change the directories list file name to something suitable
     for your system.  REFRESH will _not_create a directory for you (only a
     file in an existing directory), and you may have to modify the "set
     _f" line accordingly.

 :------ cut everything above this line to create REFRESH.BTM -----
 @echo off
 *setlocal
 *unalias *
 set _f=C:\CDD.INI
 echo ` `
 iff exist %_f then
   echo %@upper[%0] will add to existing file "%_f".
 else
   echo %@upper[%0] will create directory file "%_f".
 endiff
 echo ` `
 echos Hit CTRL-C to Abort now, or` `
 pause
 set i=%@upper[%1]
 if "%i" eq "" set i=C
 :0
 iff exist %i:\nul. then
   iff %@eval[%@removable[%i:]+%@cdrom[%i:]] eq 0 .or. "%1" eq "%i" then
     echo ``
     echos Processing drive %i:
     cdd %i:\
     global /iq (
       echo %_cwd>>! %_f
       echos .
     )
   else
     echo ``
     echo Bypassing drive %i:
   endiff
 else
     echo ``
   echo Invalid drive: %i:
   quit
 endiff
 set i=%@char[%@eval[%@ascii[%i]+1]]
 if %i le %@upper[%_lastdisk] .and. "%1" eq "" goto 0
 : ------ cut everything below this line to create REFRESH.BTM -----


 ALIASES:

   Notes:

     Each alias should be entered on a single line, but is broken down
      here for added legibility.

     As shown, the aliases assume the 4DOS defaults for EscapeChar,
      ParameterChar, and CommandSep.  Alter accordingly if you are using
      different values.

     While pipes are implemented under DOS as simple temporary files, in the
      current session and thread (since DOS offers neither multitasking nor
      multithreading), OS/2 uses "true" piping.  Two sets of aliases are
      offered.  The first one can be used in both DOS and OS/2 sessions.  The
      second one has been optimized for use in DOS sessions (including OS/2
      VDMs and VMBs) by directly piping the output of FFIND into the INPUT
      command.  Select the appropriate alias for your needs (use the first one
      if unsure)

     With the combined 4DOS/OS2 version of the aliases, a small temporary
      work file will be created in the root directory of your "TEMP" drive,
      or of the current drive if TEMP is not defined.


 ;---- Option 1:
 ;---- add the two lines below to your 4DOS or 4OS2 "ALIAS /R" file  ----------

 CD*D=*set _cdd=%1 %+ if .%1 eq . *set _cdd=%_cd %+
      iff not isdir %_cdd\. then %+
      ffind /kmt"%1" c:\cdd.ini>!%[temp]%[_pid]cdd %+
      *set _cdd=%@word[0,%@line[%[temp]%[_pid]cdd,0]] %+
      *if .%_cdd eq .**eof** *unset _cdd %+ *del /q %[temp]%[_pid]cdd>nul %+
      endiff %+ iff .%_cdd eq . then %+ *beep %+ echo %_cwd %+ else %+
      *set _cd=%_cwd %+ *set _go=%1 %+ *cdd %@word[0,%_cdd] %+ *set _cdd= %+
      iff .%2 ne .  then %+ %2& %+ endiff %+ endiff

 G*O=iff .%1 eq . then %+ ffind /vkmt"%_go" c:\cdd.ini>!%[temp]%[_pid]go %+
   *cdd %@word[0,%@select[%[temp]%[_pid]go,2,40,15,79,* Go where?  * ]] . %+
   *del /q %[temp]%[_pid]go %+ else %+ cdd %& %+ endiff


 ;---- Option 2 for 4DOS users:
 ;---- add the two lines below to your 4DOS "ALIAS /R" file ----------

 CD*D=*set _cdd=%1 %+ if .%1 eq . *set _cdd=%_cd %+
         iff not isdir %_cdd\. then %+
         ffind /kmt"%1" c:\cdd.ini | input %%_cdd %+ endiff%+
         iff "%_cdd" eq "" then %+ beep %+ echo %_cwd %+ else %+
         *set _cd=%_cwd^*set _go=%1 %+ *cdd %@word[0,%_cdd] %+
         *set _cdd=%+ iff .%2 ne . then %+ %2& %+ endiff %+ endiff

 G*O=iff .%1 eq . then %+ ffind /vkmt"%_go" c:\cdd.ini |
         *cdd %@word[0,%@select[con,2,40,15,79,* Go where?  * ]] .%+
         else %+ cdd %& %+ endiff



 ; The following GX alias is a bonus for having made it this far into the
 ; file.  It will "popup" a selection windows containing all the
 ; subdirectories in your current working directory.  Select the one you
 ; want (including ".." for the parent directory) by using the usual
 ; navigation keys, and pressing ENTER, or hit ESCAPE to cancel.

  GX=*echo ..>!%[temp]_gx %+ *dir /kmba:d>>!%[temp]_gx %+
       *cdd %@select[%[temp]_gx,2,50,15,73,* Subdirs *]>&nul %+
         *del /q %[temp]_gx


 ;-----cut everything below this line -----------------------

 ENHANCEMENTS:

  If your disk organization and work habits require that you create and
  remove directories often enough that manually editing the Directories List
  or running REFRESH becomes inconvenient, it's quite feasible to have that
  file update for you automatically whenever you invoke the MD and/or RD
  commands. Some users may prefer _not_ to enable that function in order to
  separate "permanent" directory structures from temporary trees created
  for a specific transient purpose.  As usual, the choice is yours.

  One possible alias will not only update the existing directories list
  file, but also enhance the basic MD commands by allowing several
  directories to be entered in their command tail (ie. "MD foo bar fubar").

  MD=for %i in (%&) (*md %i && (echo %@full[%i] >>! c:\cdd.ini))

  RD could be similarly enhanced, but deleting a line from the middle of a
  file is a somewhat clumsy process, and may be best suited for a BTM file.
  For many users, directly deleting an obsolete line from the Directories
  List File may be the most practical approach.

  The aliases discussed above can also be adjusted for "4DOS for Windows NT"
  (4NT) and Take Command (16-bit, 32-bit, and PM).  This particular exercise
  is left up to the user.

 HISTORY:

  1.0  02-25-91 Initial posting on CompuServe by users request
  1.1  02-28-91 Corrected REFRESH.BTM to search all drives
                Corrected UM alias
                Eliminated the CDD Syntax error message on invalid searches
  1.2  03-28-91 Eliminated variable _CD
  2.0  06-03-91 Greatly simplified - dropped MARKS and added ability to
                add commands to the CD line
  2.1  06-25-91 Replaced the missing GO alias
  3.0  11-25-91 Rewritten to use the 4DOS 4.0 features
  3.01 11-28-91 Corrected a couple of small typos in REFRESH and GO
  3.02 01-17-92 Fixed bug in GO when directory name contains a "."
  3.03 04-25-92 Remove extra ENDIFF in the "~d" alias
  3.04 01-31-93 Adjusted "~d" for better HPFS "long names" support
  4.00 10-19-94 Removed all references to externals thanks to FFIND.
                Incorporated "~d" into the CD*D alias.
  4.01 12-20-94 Corrected CD alias to isolate the first word in a
                directories file entry that contains user-defined keywords.
  4.02 12-25-94 Corrected GO and GX for better HPFS/NTFS LFN support.
  4.03 03-21-95 Additional corrections to CD for quoted LFNs.
  4.04 02-11-96 Removed CommandSep dependencies.  Miscellenaous cleanup.

 SUPPORT:

 Please post all questions and comments as public messages in the JP
 Software Support Section 10 of the PC Vendor 'B' Forum ("GO PCVENB"
 or "GO JPSOFT").
 --------------------------------------------------------------------


