?? RIGHT := 110 ??
?? NEWTITLE := 'MANFC Utility: Module QCM$OPEN_FILE.' ??
MODULE qcm$open_file;

{ PURPOSE:
{   This module contains a procedures to open a file.
{
{ DESIGN:
{   The FILE is opened with the file attachment option and
{   create file definitions provided in the procedure parameters.
{
{ NOTES:
{   This procedure should be called from within a block structure
{   which has a condition handler.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc ost$status
?? POP ??
*copyc fsp$open_file

?? TITLE := 'Global Declarations Declared by This Module', EJECT ??

?? TITLE := 'qcp$open_segment_file [XDCL]', EJECT ??

{ PURPOSE:
{   This procedure opens a file.
{
{ DESIGN:
{   The FILE is opened with the attachment_option and
{        defined in the procedure parameters.
{
{ NOTES:
{   This procedure should be called from within a block structure
{   which has a condition handler.

  PROCEDURE [XDCL] qcp$open_file
    (    path_ref_p: ^fst$file_reference;
         access_level: amt$access_level;
         file_attachment: fst$file_access_option;
         create_file: boolean;
         attribute_override_p: ^array [1 .. 1] of fst$file_cycle_attribute;
     VAR file_id: amt$file_identifier;
     VAR file_opened: boolean;
     VAR status: ost$status);


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


    status.normal := TRUE;
    file_opened := FALSE;

    attachment_option [1].selector := fsc$access_and_share_modes;
    attachment_option [1].access_modes.selector := fsc$specific_access_modes;

    IF file_attachment = fsc$read THEN

      attachment_option [1].access_modes.value := $fst$file_access_options [fsc$read];
      attachment_option [2].create_file := FALSE;

    ELSEIF file_attachment = fsc$modify THEN

      attachment_option [1].access_modes.value := $fst$file_access_options
            [fsc$read, fsc$shorten, fsc$append, fsc$modify];
      IF create_file = TRUE THEN
        attachment_option [2].create_file := TRUE;
      ELSE
        attachment_option [2].create_file := FALSE;
      IFEND;

    IFEND;

    attachment_option [1].share_modes.selector := fsc$determine_from_access_modes;
    attachment_option [2].selector := fsc$create_file;

    file_opened := TRUE;
    fsp$open_file (path_ref_p^, access_level, ^attachment_option, NIL, NIL, NIL, attribute_override_p,
          file_id, status);
    IF NOT status.normal THEN
      file_opened := FALSE;
      RETURN;
    IFEND;

  PROCEND qcp$open_file;

MODEND qcm$open_file;

