
*** WARNING ***

Under 4dos 4.0, attempting to %@select[] a zero-length file seems to reliably
trigger a "Bad memory block" error under plain DOS, and crash DESQview out
entirely. Hence, my check on the length of the temporary file before I use
@%select[] on it.

---/ snip /---

@echo off
goto begin

  SNORT.BTM: a batch file to pop up a list of files in the
  current directory with descriptions matching command-line
  supplied strings, and display one of them.

  Requires a decent grep or fgrep.

  Note: my grep, if it finds a match in its input, will always
  say "File: STDIN" before displaying the lines that match, hence
  the extra test in the batch file. My fgrep doesn't do this, so
  I'm using it instead. If you want to use grep, change the
  appropriate lines.

  grep and fgrep are fairly widely available; check in archives
  of unix-alike utilities for DOS.

  People with long paths and slow machines might want to remove
  the test that checks to see whether fgrep (etc) can be found on
  the path.

  This batch file hereby released to the public domain.

:begin
iff "%1"=="" then
  echo Usage: snort [pattern to match]
elseiff %_env LT 32 then
  echo Not enough environment space.
elseiff "%@search[fgrep]"=="" then
  echo Can't find fgrep on the path.
else
  iff "%temp%"=="" then
    set tn=%@unique[.]
  else
    set tn=%@unique[%temp%]
  endiff

  *dir /1 /a-h-s-d *.*|fgrep %&>%tn%

  iff %@filesize[%tn%,b] LT 2 then
    echo No matches found.
  else
    set cho=%@substr[%@select[%tn%,0,0,%_rows,%_columns,select:],0,12]
    del /q %tn%

    iff "%cho%"=="" .or. "%cho%"=="File STDIN:" then
      echo Aborted.
    elseiff not exist %cho% then
      echo %chosen%: file not found.
    else
      *list %cho%
    endiff
  endiff

  set tn=
  set cho=
endiff

