
{HSP} program DB3_Safe;       {quick & dirty shell}

  {Wrapper utility to disable the ICD write caches during execution}
  {of Diamond Back 3, to avoid data loss due to SCSI contention.}

  {Reads a sequence of programs to run from a script file (DB3_SAFE.DAT),}
  {normally: CACHEOFF to disable, D_BACK3, then CACHEON to re-enable.}

  {Written by Mark O'Bryan on Jun17/94, in HighSpeed Pascal}

  {Copyright 1994 Mark O'Bryan.  Free distribution permitted with attribution.}
  {DISCLAIMER: No warranty is made regarding fitness for any purpose.}

{DIRECTIVES}
  {$M 2,0,0,0 -- small (2kB) stack}

{----- Declarations -----------------------------------------------------}

uses
  Dos;                                   {for Exec, SwapVectors...}
const
  ver     = 'DB3_Safe: Version 1.1 of Jun17/94';
  scrFile = 'DB3_Safe.DAT';              {script file name}
type
  commandLine = string[80];
var
  scr    : text;                         {script file}
  script : array [1..10] of commandLine; {only using 3}
  cnt    : integer;                      {total # of commands in file}
  num    : integer;                      {loop var}

{----- Support primitives -----------------------------------------------}

  procedure Abort (msg: commandLine);
  begin
    writeln;
    writeln (msg);
    writeln ('Aborting script execution.  Press RETURN to exit...');
    readln  {pause};
    Halt    (-1);
  end {Abort};

{----- master launchPad routine -----------------------------------------}

  procedure RunOne (VAR cmd: commandLine);
    {- CacheOn/Off return large positive error codes: 14218 (IGNORED)}
  var
    app: commandLine;
    arg: commandLine;
    loc: integer;
  begin
    {separate the program name/path from possible command line arguments}
      loc := Pos (' ', cmd);                            {find separator}
      if (loc = 0) then loc := length(cmd)+1;           {no args}
      app := Copy ({from} cmd, {at} 1, {num} loc-1);    {head=program}
      arg := Omit ({from} cmd, {at} 1, {num} loc-1);    {tail+leading space}

    {now launch the application}
      SwapVectors;
        Exec (app, arg);
      SwapVectors;

    {report errors & quit}
      if (DosError = -33) then
        Abort ('Application file could not be found: "' + app + '"');
  end {RunOne};

{----- Main program -----------------------------------------------------}

begin
  {identification}
    {...none here, so we can run D_Back3 transparently...}

  {read the entire script & don't leave file open}
    reset (SCR, scrFile);               {try to open script file}
    if (IOresult <> 0) then             {notify user & quit if not found}
      Abort ('Could not find script file: ' + scrFile + '.');
    cnt := 0;

    while (not eof(SCR)) do begin
      Inc (cnt);
      readln (SCR, script[cnt]);
      if (script[cnt] = '') then Dec (cnt);  {trim blank lines}
    end {while};
    close (SCR);

  {execute the sequence of programs}
    for num := 1 to cnt do begin
      RunOne (script[num]);
    end {for};
end {program}.

