This archive contains version 2.0 of my "Directory Database" suite.

Please note these programs ALL require 2.04 or greater. :-)

 Contents :
 ~~~~~~~~

The programs contained are :

  MakeDirDB
  FindDBEntry
  DBEntry

Also contained in this archive is Jonas Petersson's 'upd' program,
which is an ARexx 8SVX sample server, and some scripts to use the
Directory Database with your sound samples.


 Purpose :
 ~~~~~~~

These programs make and search databases created from Amiga directory
trees. It is much faster to search one of these databases for a file,
than it is to search the filesystem. Also, you can use these programs
to do something with all the files which match a pattern, or with
random files.


 Uses :
 ~~~~

 - Finding a file, when only part of its name is known
 - Choosing a file at random
  ++ Playing a random sound sample, either from a script (see the
     examples), by a hot key (using FKey and the scripts) or
     a cron program (and the scripts). My amiga plays a random
     sound sample every quarter hour, between reasonable hours,
     to keep me awake. Look for CyberCron.
  ++ Choosing a random background picture (for WB3.0 or via NickPrefs).
     1. Set up a directory of background images
     2. Make a (hard) link to one of them,
      eg. "MakeLink sys:BGPic.link sys:wbpics/Maddonna hard" :-)
     3. Use WBPattern or NickPrefs WBPicture to load sys:BGPic.link
       (for WBPattern, initially BGPic.link must be a picture,
        rather than a link to a picture, as WBPattern resolves the link.
        Copy a file to sys:BGPic.link, use WBPattern to load the picture,
        and save your preferences, then use WBPattern again, load
        a different picture, or no picture and Use this (this unlocks
        BGPic.link) then delete BGPic.link, and use MakeLink to
        replace it with a link to a picture file.)
     4. In your startup-sequence, before IPrefs or NickPrefs,
        insert the lines:
      delete >NIL: sys:BGPic.link
      utilities:dbentry >NIL: dh0:dirdbs/WBPics.db random
        pre="makelink sys:BGPic.link " post=" hard" execute unique
         (The last line was wrapped for readability, it should be
          all one line)


 Installation :
 ~~~~~~~~~~~~
 
 1. Place the 3 programs somewhere on your path
 2. Put the scripts somewhere on your path (s: comes to mind)
 3. Execute the MakeDBPath script, specifying where you want
    your database files to go. This script creates then
    Env:db directory, sets up the Path variable there, and
    duplicates the directory to EnvArc:, so it will be there
    when you reboot.
 4. Unpack and install upd, reading its documentation

 5. (Optional) Set up a cron to play sounds regularly, and
    put the scripts on function keys using FKey. Set up a
    function key with the upd Fade command to stop samples
    if necessary.

 Maintenence :
 ~~~~~~~~~~~

Directories change. It is necessary to reconstruct the databases
occassionally. It is possible to automate this into a cron task,
so that once a day, say at 1:15am, any databases you use are
updated. Then again, you may only use the databases for non-essential
tasks, so you can update them when you require.

 Environment Variables :
 ~~~~~~~~~~~~~~~~~~~~~

These programs use a number of environment variables, which are kept
in your Env:DB directory, which is created by the MakeDBPath script.
These variables include a Path variable, which tells the programs where
to look for your databases, a Seed variable, used by the Random Number
generator, and initialised based on the system time, first time they
are run. Also, each call to DBEntry sets up variables containing the
last file name, and its position in the database.

 History :
 ~~~~~~~

Version 2.0 improves on the previous (unnumbered) version buy
moving the random seed, and the 'Unique' function into the databases.

This has two benefits:
 1. Speed at closure. The random seed is written to the database
    instead of to ENV: and ENVARC:, which is quicker
 2. True unique selection across multiple calls of DBEntry.
    If you are using DBEntry to play random sounds, this means that
    you will get random sounds, with no sound repeated until all
    the sounds named in your database have been played. You should
    update all calls to DBEntry in your scripts, etc, to include
    the 'Unique' keyword.

The Version 2.0 programs can read the old databases, while the old
programs cannot read the 2.0 databases.

-----------

MakeDirDB :

Makes a database containing all the file names in the specified
directory/directories and their subdirectories.

Usage :
 MakeDirDB DIR/M/A,DEST/A,PATTERN/K

Notes -
 The database will contain any assigns specified in the Dir
specification, but MakeDirDB cannot handle multiple path assigns.
The assigns must be present when the database is referenced.

The Pattern defaults to #?, you might like to specify something
like ~(#?.info) to exclude icons. You must use the Pattern keyword
to specify this parameter (sorry I missed this in the old documentation).

For example,
  MakeDirDB Sounds: sys:DBDir/Sounds.db Pattern=~(#?.info)

-----------

FindDBEntry :

Finds all occurences of a pattern in specified directory database(s).
Optionally do something with the found names.

Usage :
 FindDBEntry  DIRDB/A/M,PAT=PATTERN/A,PRE=PREPEND/K,POST=APPEND/K,NOLINE/S,
              EXECUTE/S,INFO/S,NOTINMEM/S,FULL/S,DIRS/S,NOFILES/S

Arguments :

 DIRDB/A/M :
    Specifies the databases to search. See note later on
    Environment Variables, and Paths.

 PAT=PATTERN/A :
    Specifies the DOS pattern to search using.
    By default, just searches filenames. You can specify directories in
    the pattern, and even patterns in the directory part.
    Examples
       #?foo#?         matches anything with foo in its name.
       #?bar#?/#?foo#? matches anything with foo in its name, which is in a
                       directory containing bar in its name.

 PRE=PREPEND/K :
    Specfies text to place before the result in the output.
 POST=APPEND/K :
    Specfies text to place after the result in the output.

    Examples :
       prepend="type "
       -- will type all matching files
       pre="rx *"address play 'file' '" post="' '-S'*""
       -- uses upd to play the resulting sound samples.
          *'s are used to insert the quotes in a DOS commandline

 NOLINE/S :
    When printing the results, don't put each on a new line.

 EXECUTE/S :
    Instead of printing the results to the console, execute each line of
    output (including pre and post strings) as DOS commands.

 INFO/S :
    Output how many files are in the DataBase

 NOTINMEM/S :
    Don't load the full database into memory before searching.
    Greatly decreases speed, but saves memory, equal to
    the size of the DB file.

 FULL/S :
    Matches the pattern against the full file path, rather than just the
    file name. This is done automatically if the pattern contains a '/'.
    This option allows the pattern to match directory names, and so
    anything in that directory.

 DIRS/S :
    If a directory matches the pattern, it's full name is output.

 NOFILES/S :
    Use with DIRS to search only for matching directories.


-------

DBEntry :

 DBEntry DIRDB/A,PRE=PREPEND/K,POST=APPEND/K,NUM/N,RANDOM/S,NOLINE/S,
         SPEC=SPECIFIC/N/K,EXECUTE/S,STARTRANGE/K/N,ENDRANGE/K/N,
         LAST/S,NEXT/S,WRAP/S,INFO/S,INMEM/S,UNIQUE/S

 DIRDB/A/M :
    Specifies the databases to search. See note later on
    Environment Variables, and Paths.

 PRE=PREPEND/K :
    Specfies text to place before the result in the output.
 POST=APPEND/K :
    Specfies text to place after the result in the output.

    Examples :
       prepend="type "
       -- will type all matching files
       pre="rx *"address play 'file' '" post="' '-S'*""
       -- uses upd to play the resulting sound samples.
          *'s are used to insert the quotes in a DOS commandline

 NUM/N :
    Specifies how many file names to output, see RANDOM

 RANDOM/S :
    Choose the file names to output at random. If not specified,
    DBEntry will just start at the first (or nth if SPECIFIC is
    specified) and proceed linearly through the entries.
    See UNIQUE.

 NOLINE/S :
    When printing the results, don't put each on a new line.

 SPEC=SPECIFIC/N/K :
    Specifies a starting point in the database, or the specific
    entry to output if NUM is not specified or equals 1

 EXECUTE/S :
    Instead of printing the results to the console, execute each line of
    output (including pre and post strings) as DOS commands.

 STARTRANGE/K/N
 ENDRANGE/K/N :
    Limit the range to choose from with RANDOM

 LAST/S
 NEXT/S :
    Various information is stored in environment variables.
    These options use that information to select the most recent entry,
    or the one after that.
    As DBs are kept in alphabetic order, by subdirectory, this can
    play the next sound in a subtopic.

 WRAP/S :
    If you specify a large number, or -1 to NUM, and there aren't that
    many entries, wrap back to the start.

 INFO/S :
    Output how many files are in the DataBase

 INMEM/S :
    Load the full database into memory. Don't use for one-offs, but
    if you are fetching multiple entries, saves time at the expense
    of memory, equal to the size of the DB file.
    Note the difference to the option for FindDBEntry.

 UNIQUE/S :
    Makes sure entries are only selected once each, until all entries
    in the database have been selected.

    This option (now) survives repeated calls to DBEntry on the same
    database. Any use of DBEntry with 'Unique' may not select a
    particular file, as that file was selected previously.
    
    Unique works even when Random was not specified.

