pragma list_on:'tt:', list_off;
{pragma list_on, show_syntax:0, show_expr:0, show_macro:0, show_macrosrc:0;}

string    $job_name   := 'TT:',    { Job Name }
          $cpsh_name  := 'TT:',    { Command file Specification }
          $list_name  := 'TT:',    { Listing File Specification }
          $chaine_cmd := 'chaine ''',  { to prepare the chaine command }

          $cpsh_hlpf  := 'PASENV:cpsh.help';

integer   $ver_flag   :=     0,    { Verify/Debug Flag }
          $mdb_flag   :=     0,    { Debug Macro Flag }
          $sys_iprm   :=     1;    { Current Index in the parameter list }


begin { *** Open a local variable scope *** }
  string   str;
  integer  ipc, ind;
  integer  ipar := -1;

  string  dirtab[ 4] := ( '-ver',  { To specify the verify/debug mode }
                          '-mdb',  { To activate the macro debuging exp. list }
                          '-out',  { To specify the output mode }
                          '-hel'   { To specify a "help cpsh" request }
                        );

  if $sys_nparm > 0 then
    repeat
      str := $sys_parm[$sys_iprm];
      ind := ARRAY_SEARCH( dirtab, SETCASE( SUBSTR( str, 1, 4 ) ), 0 );
      case ind
      when 1: { Verify Option }
        ipc := INDEX( str, ':' );
        if ipc > 0 then $ver_flag := SUBSTR( str, ipc+1 );
                   else $ver_flag := 1;
                   end;

      when 2: { Mdb Option }
        $mdb_flag := 1;

      when 3: { Out Option }
        ipc := INDEX( str, ':' );
        if ipc > 0 then
          $list_name := SUBSTR( str, ipc+1 );
          if INDEX( str, '.' ) = 0 then $list_name := $list_name||'.lis'; end
        end;

      when 4: { Help Command }
        if FILE_EXIST( $cpsh_hlpf ) then
          $cpsh_hlpf := FILE_SPC( $cpsh_hlpf );
          ipc := INDEX( str, ':' );
          if ipc > 0 then
            RUN_PROGRAM( 'cp '||$cpsh_hlpf||' '||SUBSTR( str, ipc+1 ) )
          else
            RUN_PROGRAM( 'less '||$cpsh_hlpf )
          end;
          display ' *** Cannot find the displayer of help file ***'
        else
          display ' *** Cannot find the help file "', $cpsh_hlpf, '" ***'
        end;
        EXIT( 0 );

      when other { Code to proceed commande }
        if ipar < 0 then
          $job_name  := str;
          ipc := INDEX( str, '.' );
          if ipc = 0 then $cpsh_name := $job_name||'.cpsh'
                     else $cpsh_name := $job_name;
                          $job_name := SUBSTR( $job_name, 1, ipc-1 )
                     end;
          ipar := 0;
        else
          ipar := ipar + 1;
          $sys_parm[ipar] := $sys_parm[$sys_iprm]
        end
      end { case };
      $sys_iprm := $sys_iprm + 1
    until $sys_iprm > $sys_nparm;
    while $sys_nparm > ipar do
       $sys_parm[$sys_nparm] := '';
       $sys_nparm := $sys_nparm - 1
    end
  end
end; { End Of Local Scope }

if not FILE_EXIST( $cpsh_name ) then
  display ' Cannot open the file "', $cpsh_name, '" (probably no such file).';
  DISPLAY ' *** Stop ON Error. ***';
  EXIT( 2 )
end;

$chaine_cmd := $chaine_cmd||$cpsh_name||''', list_on:'''||$list_name||'''';

if $ver_flag then
  display ' Run File "', $cpsh_name, '".';
else
  $chaine_cmd := $chaine_cmd||', list_off'
end;

if $mdb_flag then
  $chaine_cmd := $chaine_cmd||', show_macro'
end;

{***}  end; {** of Initialize CPSH Sequence **}

"$chaine_cmd;
