*copyc osd$default_pragmats

?? TITLE := 'NOS/VE : Basic Access Methods : Path evaluator' ??

MODULE fmm$evaluate_path;

{ PURPOSE: Resolve the given file path and return information about the path.


?? PUSH (LISTEXT := ON) ??
*copyc cle$ecc_lexical
*copyc fme$file_management_errors
*copyc fsc$local
*copyc fst$path_element_size
*copyc fst$path_size
*copyc fsv$evaluated_file_reference
*copyc ost$name
*copyc pfe$error_condition_codes
?? POP ??
*copyc clp$check_name_for_path_handle
*copyc clp$evaluate_file_reference
*copyc clp$trimmed_string_size
*copyc clp$validate_name
*copyc fsp$path_element
*copyc fmp$process_pt_request
*copyc osp$set_status_abnormal

  PROCEDURE [INLINE] validate_local_file_name (potential_name:
    fst$file_reference;
    VAR local_file_name: amt$local_file_name;
    VAR path_handle: fmt$path_handle;
    VAR name_is_path_handle: boolean;
    VAR name_is_valid: boolean;
    VAR cl_path_handle: clt$path_handle);

    VAR
      name_size: fst$path_size;

    name_size := STRLENGTH (potential_name);
    WHILE (name_size > 1) AND (potential_name (name_size) = ' ') DO
      name_size := name_size - 1;
    WHILEND;
    name_is_path_handle := FALSE;
    IF name_size > STRLENGTH (amt$local_file_name) THEN
      name_is_valid := FALSE;
    ELSE
      clp$validate_name (potential_name (1, name_size), local_file_name,
            name_is_valid);
      IF name_is_valid THEN
        clp$check_name_for_path_handle (local_file_name, cl_path_handle);
        IF cl_path_handle.kind = clc$regular_path_handle THEN
          name_is_path_handle  := TRUE;
          path_handle := cl_path_handle.regular_handle;
        IFEND;
      IFEND;
    IFEND;

  PROCEND validate_local_file_name;

?? TITLE := 'PROCEDURE [XDCL, #GATE] fmp$evaluate_path', EJECT ??

  PROCEDURE [XDCL, #GATE] fmp$evaluate_path
    (    file: fst$file_reference;
         process_pt_work_list: bat$process_pt_work_list;
     VAR evaluated_file_reference: fst$evaluated_file_reference;
     VAR cycle_description: ^fmt$cycle_description;
     VAR status: ost$status);

    VAR
      cl_path_handle: clt$path_handle,
      file_reference_parsing_options : clt$file_ref_parsing_options,
      name_is_path_handle: boolean,
      name_is_valid: boolean,
      name_size: fst$path_element_size,
      path_handle: fmt$path_handle,
      process_pt_results: bat$process_pt_results,
      validated_name: amt$local_file_name;

    status.normal := TRUE;

    evaluated_file_reference := fsv$evaluated_file_reference;

    validate_local_file_name (file, validated_name, path_handle,
          name_is_path_handle, name_is_valid, cl_path_handle);
    IF name_is_path_handle THEN
      evaluated_file_reference.path_handle_info.path_handle := path_handle;
      evaluated_file_reference.path_handle_info.path_handle_present := TRUE;
    ELSE
      IF (NOT name_is_valid) OR (cl_path_handle.kind = clc$command_file_handle) THEN
        IF NOT (bac$create_cycle_description IN process_pt_work_list) THEN
          file_reference_parsing_options := $clt$file_ref_parsing_options [clc$command_file_ref_allowed];
        ELSE
          file_reference_parsing_options := $clt$file_ref_parsing_options [];
        IFEND;
        clp$evaluate_file_reference (file, file_reference_parsing_options, FALSE,
              evaluated_file_reference, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
      ELSE { name is valid }
        evaluated_file_reference.path_structure (1) := $char (fsc$local_size);
        evaluated_file_reference.path_structure (2, fsc$local_size) := fsc$local;
        name_size := clp$trimmed_string_size (validated_name);
        evaluated_file_reference.path_structure (fsc$local_size + 2) := $char (name_size);
        evaluated_file_reference.path_structure (fsc$local_size + 3, name_size) := validated_name;
        evaluated_file_reference.path_structure_size := fsc$local_size +
              name_size + 2;
        evaluated_file_reference.number_of_path_elements := 2;
      IFEND;
    IFEND;

    fmp$process_pt_request (process_pt_work_list, osc$null_name,
          evaluated_file_reference, cycle_description, process_pt_results,
          status);
    IF (cycle_description = NIL) AND (bac$return_cycle_description IN process_pt_work_list) AND
          (status.normal OR (status.condition = pfe$unknown_permanent_file) OR
          (status.condition = fme$obsolete_path_handle)) THEN
      osp$set_status_abnormal (amc$access_method_id, fme$no_cycle_description, '', status);
    IFEND;

  PROCEND fmp$evaluate_path;
MODEND fmm$evaluate_path;


