?? RIGHT := 110 ??
?? NEWTITLE := 'PACKAGE_SOFTWARE Utility: CHECKSUM_FILE Subcommand.' ??
MODULE ram$checksum_file_command;

{ PURPOSE:
{   This module contains the command interface that checksums a file.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
?? POP ??
*copyc clp$convert_integer_to_string
*copyc clp$change_variable
*copyc clp$evaluate_parameters
*copyc clp$include_line
*copyc rap$checksum_file
?? OLDTITLE ??
?? NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??

?? OLDTITLE ??
?? NEWTITLE := '[XDCL] rap$checksum_file_command', EJECT ??

{ PURPOSE:
{   This command interface returns the checksum for the specified file.
{
{ DESIGN:
{
{ NOTES:
{

  PROCEDURE [XDCL] rap$checksum_file_command
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);


{ PROCEDURE chef_pdt (
{   file, f: file = $required
{   checksum, c: (var) integer = $optional
{   status)

?? PUSH (LISTEXT := ON) ??

    VAR
      pdt: [STATIC, READ, cls$declaration_section] record
        header: clt$pdt_header,
        names: array [1 .. 5] of clt$pdt_parameter_name,
        parameters: array [1 .. 3] of clt$pdt_parameter,
        type1: record
          header: clt$type_specification_header,
        recend,
        type2: record
          header: clt$type_specification_header,
          qualifier: clt$integer_type_qualifier,
        recend,
        type3: record
          header: clt$type_specification_header,
        recend,
      recend := [[1, [88, 10, 5, 23, 20, 19, 210], clc$command, 5, 3, 1, 0, 0, 1, 3, 'CHEF_PDT'],
            [['C                              ', clc$abbreviation_entry, 2],
            ['CHECKSUM                       ', clc$nominal_entry, 2],
            ['F                              ', clc$abbreviation_entry, 1],
            ['FILE                           ', clc$nominal_entry, 1],
            ['STATUS                         ', clc$nominal_entry, 3]], [
{ PARAMETER 1
      [4, 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
      [2, clc$normal_usage_entry, clc$non_secure_parameter, $clt$parameter_spec_methods
            [clc$specify_by_name, clc$specify_positionally], clc$pass_by_reference, clc$immediate_evaluation,
            clc$standard_parameter_checking, 20, clc$optional_parameter, 0, 0],
{ PARAMETER 3
      [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
      [[1, 0, clc$file_type]],
{ PARAMETER 2
      [[1, 0, clc$integer_type], [clc$min_integer, clc$max_integer, 10]],
{ PARAMETER 3
      [[1, 0, clc$status_type]]];

?? POP ??

    CONST
      p$file = 1,
      p$checksum = 2,
      p$status = 3;

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


    VAR
      checksum: integer,
      checksum_str: ost$string,
      line: string (osc$max_string_size),
      length: integer,
      value: ^clt$data_value;


    status.normal := TRUE;

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

    rap$checksum_file (pvt [p$file].value^.file_value^, checksum, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    IF pvt [p$checksum].specified THEN

      { Write SCL checksum variable.

      PUSH value;

      value^.kind := clc$integer;
      value^.integer_value.value := checksum;
      value^.integer_value.radix := 10;
      value^.integer_value.radix_specified := FALSE;

      clp$change_variable (pvt [p$checksum].variable^, value, status);

    ELSE { not specified }

      { Display checksum value.

      clp$convert_integer_to_string (checksum, 10, FALSE, checksum_str, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

      STRINGREP (line, length, '$system.put_line ''   Checksum: ', checksum_str.value (1, checksum_str.size),
         ', File: ', pvt [p$file].value^.file_value^, ''' o=$response');

      clp$include_line (line (1, length), TRUE, osc$null_name, status);

    IFEND;

  PROCEND rap$checksum_file_command;
MODEND ram$checksum_file_command;
