MODULE ram$find_string_command;
?? RIGHT := 110 ??

{ PURPOSE:
{   Find_String command in osf$site_command_library

?? NEWTITLE := 'Global Declarations Referenced By This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
?? POP ??
*copyc amp$get_next
*copyc amp$put_next
*copyc clp$evaluate_parameters
*copyc clp$trimmed_string_size
*copyc fsp$close_file
*copyc fsp$open_file
*copyc nlp$name_match
?? OLDTITLE ??
?? NEWTITLE := 'RAP$FIND_COMMAND', EJECT ??
  PROGRAM rap$find_command
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE (ram$fins) find_pdt (
{   search_string, ss: string = $required
{   input, i: file = $required
{   output, o: file = $output
{   )

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

  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 6] of clt$pdt_parameter_name,
      parameters: array [1 .. 3] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
        qualifier: clt$string_type_qualifier,
      recend,
      type2: record
        header: clt$type_specification_header,
      recend,
      type3: record
        header: clt$type_specification_header,
        default_value: string (7),
      recend,
    recend := [
    [1,
    [104, 3, 28, 20, 47, 54, 393],
    clc$command, 6, 3, 2, 0, 0, 0, 0, 'RAM$FINS'], [
    ['I                              ',clc$abbreviation_entry, 2],
    ['INPUT                          ',clc$nominal_entry, 2],
    ['O                              ',clc$abbreviation_entry, 3],
    ['OUTPUT                         ',clc$nominal_entry, 3],
    ['SEARCH_STRING                  ',clc$nominal_entry, 1],
    ['SS                             ',clc$abbreviation_entry, 1]],
    [
{ PARAMETER 1
    [5, 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, 8, 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_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3, clc$required_parameter, 0
  , 0],
{ PARAMETER 3
    [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$optional_default_parameter, 0, 7]],
{ PARAMETER 1
    [[1, 0, clc$string_type], [0, clc$max_string_size, FALSE]],
{ PARAMETER 2
    [[1, 0, clc$file_type]],
{ PARAMETER 3
    [[1, 0, clc$file_type],
    '$output']];

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

    CONST
      p$search_string = 1,
      p$input = 2,
      p$output = 3;

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

    TYPE
      work_files = (input_file, output_file);

    VAR
      file: work_files,
      file_identifier: array [work_files] of amt$file_identifier,
      ignore_byte_address: amt$file_byte_address,
      input_line: string (255),
      local_status: ost$status,
      output_line: ost$string,
      position_of_file: amt$file_position,
      search_string: ^nat$title_pattern,
      transfer_count: amt$transfer_count;

?? OLDTITLE ??
?? NEWTITLE := 'OPEN_FILES', EJECT ??

    PROCEDURE open_files
      (VAR local_status: ost$status);

      VAR
        file_attachment: array [1 .. 3] of fst$attachment_option;

      file_attachment [1].selector := fsc$access_and_share_modes;
      file_attachment [1].access_modes.selector := fsc$specific_access_modes;
      file_attachment [1].access_modes.value := $fst$file_access_options [fsc$read];
      file_attachment [1].share_modes.selector := fsc$specific_share_modes;
      file_attachment [1].share_modes.value := $fst$file_access_options [fsc$read, fsc$execute];
      file_attachment [2].selector := fsc$open_share_modes;
      file_attachment [2].open_share_modes := $fst$file_access_options [fsc$read, fsc$execute];
      file_attachment [3].selector := fsc$create_file;
      file_attachment [3].create_file := FALSE;

      fsp$open_file (pvt [p$input].value^.file_value^, amc$record, ^file_attachment, NIL, NIL, NIL, NIL,
            file_identifier [input_file], local_status);
      IF NOT local_status.normal THEN
        RETURN; {----->
      IFEND;

      file_attachment [1].selector := fsc$access_and_share_modes;
      file_attachment [1].access_modes.selector := fsc$specific_access_modes;
      file_attachment [1].access_modes.value := $fst$file_access_options [fsc$append, fsc$shorten];
      file_attachment [1].share_modes.selector := fsc$specific_share_modes;
      file_attachment [1].share_modes.value := $fst$file_access_options [];
      file_attachment [2].selector := fsc$access_and_share_modes;
      file_attachment [2].access_modes.selector := fsc$specific_access_modes;
      file_attachment [2].access_modes.value := $fst$file_access_options [fsc$append];
      file_attachment [2].share_modes.selector := fsc$specific_share_modes;
      file_attachment [2].share_modes.value := $fst$file_access_options [];
      file_attachment [3].selector := fsc$open_share_modes;
      file_attachment [3].open_share_modes := -$fst$file_access_options [];

      fsp$open_file (pvt [p$output].value^.file_value^, amc$record, ^file_attachment, NIL, NIL, NIL, NIL,
            file_identifier [output_file], local_status);
      IF NOT local_status.normal THEN
        fsp$close_file (file_identifier [input_file], local_status);
        RETURN; {----->
      IFEND;
    PROCEND open_files;
?? OLDTITLE ??
?? EJECT ??
    clp$evaluate_parameters (parameter_list, #SEQ (pdt), NIL, ^pvt, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    PUSH search_string: [clp$trimmed_string_size (pvt [p$search_string].value^.string_value^)];
    search_string^ := pvt [p$search_string].value^.string_value^;
    open_files (local_status);
    IF NOT local_status.normal THEN
      status := local_status;
      RETURN; {----->
    IFEND;

  /process_input_file/
    WHILE TRUE DO
      amp$get_next (file_identifier [input_file], ^input_line, osc$max_string_size, transfer_count,
            ignore_byte_address, position_of_file, status);
      IF NOT status.normal THEN
        RETURN; {----->
      IFEND;
      IF position_of_file = amc$eoi THEN
        EXIT /process_input_file/; {----->
      IFEND;
      IF nlp$name_match (search_string^, input_line (1, transfer_count)) THEN
        amp$put_next (file_identifier [output_file], ^input_line (1, transfer_count), transfer_count,
              ignore_byte_address, status);
        IF NOT status.normal THEN
          RETURN; {----->
        IFEND;
      IFEND;
    WHILEND /process_input_file/;

    FOR file := LOWERVALUE (file) TO UPPERVALUE (file) DO
      fsp$close_file (file_identifier [file], local_status);
      IF (NOT local_status.normal) AND status.normal THEN
        status := local_status;
      IFEND;
    FOREND;

  PROCEND rap$find_command;
?? OLDTITLE ??
MODEND ram$find_string_command;
