?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE SCL Interpreter : Set Working Catalog Command' ??
MODULE clm$set_working_cataog_command;

{
{ PURPOSE:
{   This module contains the processor for the set_working_catalog command.
{

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc clt$parameter_list
*copyc ost$status
?? POP ??
*copyc clp$evaluate_parameters
*copyc clp$set_working_catalog
*IF $true(osv$unix)
*copyc clp_chdir
*copyc osp$set_status_from_errno
*IFEND

?? TITLE := 'clp$_change_working_catalog', EJECT ??

  PROCEDURE [XDCL] clp$_change_working_catalog
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

*IF NOT $true(osv$unix)
{ PROCEDURE (osm$chawc) change_working_catalog, set_working_catalog, setwc, chawc (
{   catalog, c: file = $required
{   status)

?? PUSH (LISTEXT := ON) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 3] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [88, 6, 13, 13, 56, 2, 764],
    clc$command, 3, 2, 1, 0, 0, 0, 2, 'OSM$CHAWC'], [
    ['C                              ',clc$abbreviation_entry, 1],
    ['CATALOG                        ',clc$nominal_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3, clc$required_parameter, 0
  , 0],
{ PARAMETER 2
    [3, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$file_type]],
{ PARAMETER 2
    [[1, 0, clc$status_type]]];

?? POP ??

  CONST
    p$catalog = 1,
    p$status = 2;

  VAR
    pvt: array [1 .. 2] of clt$parameter_value;
*ELSE
{  PROCEDURE (osm$chawc) change_working_catalog, set_working_catalog, setwc, ..
{  chawc, cd (
{    catalog, c, directory, d: file = $HOME
{    status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 5] of clt$pdt_parameter_name,
      parameters: array [1 .. 2] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        default_value: ALIGNED [0 MOD 4] string (5),
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [2,
    [92, 1, 12, 10, 22, 7, 0],
    clc$command, 5, 2, 0, 0, 0, 0, 2, 'OSM$CHAWC'], [
    ['C                              ',clc$alias_entry, 1],
    ['CATALOG                        ',clc$nominal_entry, 1],
    ['D                              ',clc$abbreviation_entry, 1],
    ['DIRECTORY                      ',clc$alias_entry, 1],
    ['STATUS                         ',clc$nominal_entry, 2]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_default_parameter, 0, 5],
{ PARAMETER 2
    [5, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation,
  clc$standard_parameter_checking, 3, clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[2, 0, clc$file_type],
    '$HOME'],
{ PARAMETER 2
    [[2, 0, clc$status_type]]];

?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$catalog = 1,
      p$status = 2;

    VAR
      pvt: array [1 .. 2] of clt$parameter_value;

    VAR
      errno: ost_c_integer,
      file_reference: fst$path,
      stat: integer,
      syserrlist_message: string (256);

    errno := 0;
    syserrlist_message := ' ';
*IFEND

    clp$evaluate_parameters (parameter_list, #SEQ(pdt), NIL, ^pvt, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

*IF NOT $true(osv$unix)
    clp$set_working_catalog (pvt [p$catalog].value^.file_value^, status);
*ELSE
    file_reference := pvt [p$catalog].value^.file_value^;
    clp_chdir (file_reference, errno, syserrlist_message, stat);
    IF stat <> 0 THEN
      osp$set_status_from_errno ('CHDIR', errno, syserrlist_message, status);
      RETURN;
    IFEND;
*IFEND

  PROCEND clp$_change_working_catalog;

MODEND clm$set_working_cataog_command;
