/*****************************************************************
* FILE_STRUCT.H
*****************************************************************/
struct file_struct
        {
        struct FAB fabst;      /* define file access block */
        struct RAB rabst;      /* define record acccess block */
        };

-----------------------------------------------------------------

#include rms
#include "or_src:file_struct.h"
/*****************************************************************
* RMS_FAB_RAB_INIT().C
*
* PURPOSE               :   To initialize the FAB and RAB for a file,
*                           and link the RAB to the FAB.
*
* CALLING MODULES       : This fundction is called by: RMS_OPEN.C
*
*****************************************************************/
rms_fab_rab_init(pfs)
 struct file_struct *pfs;

{
pfs->fabst = cc$rms_fab;               /* init FAB */

pfs->rabst = cc$rms_rab;               /* init RAB */

pfs->rabst.rab$l_fab = &pfs->fabst;    /* associate RAB with FAB */
}

-----------------------------------------------------------------

#include rms
#include "or_src:file_struct.h"
extern int rms_fab_rab_init();
/*****************************************************************
* RMS_OPEN.C
*
* PURPOSE       :   To assign FAB and RAB characteristics, create the file,
*                   and connect the rab.
*
* PARAMETERS    :   pfs - a pointer to file_struct which is a structure
*                         containing the FAB and RAB structures.
*                   fna - a pointer to the name of the file
*                   fac - file access options
*                   fop - file processing options
*                   org - file organization
*                   rfm - record format
*                   rat - record attribute
*                   shr - file sharing options
*****************************************************************/
int rms_open (pfs, fna, fac, fop, org, rfm, rat, shr)
struct file_struct *pfs;
char  *fna;
int    fac;
int    fop;
int    org;
int    rfm;
int    rat;
int    shr;

{
int   ret_status, conn_status;

rms_fab_rab_init(pfs);                     /* initialize fab and rab */

/* set up fields for fab */

pfs->fabst.fab$l_fna = fna;           /* assign file name */
pfs->fabst.fab$b_fns = strlen(fna);   /* length of file name */
pfs->fabst.fab$b_fac = fac;           /* assign file access code */
pfs->fabst.fab$b_org = org;           /* assign file organization code */
pfs->fabst.fab$b_rfm = rfm;           /* assign record format code */
pfs->fabst.fab$l_fop = fop;           /* fop information */
pfs->fabst.fab$b_rat = rat;           /* assign record attribute */
pfs->fabst.fab$b_shr = shr;           /* assign shared access */

/********* CREATE FILE ***************/
ret_status = sys$create(&pfs->fabst);
if(ret_status != RMS$_NORMAL)
 {
 printf("FAILED TO CREATE FILE. STATUS = %d\n",ret_status);
 return(ret_status);
 }

/********* CONNECT ***************/
conn_status = sys$connect(&pfs->rabst);
if(conn_status != RMS$_NORMAL)
 {
 printf("FAILED TO CONNECT. STATUS = %d\n",conn_status);
 return (conn_status);
 }

/*** SUCCESS ***/
return (RMS$_NORMAL);
}
-----------------------------------------------------------------

#include rms
#include "or_src:file_struct.h"
/*****************************************************************
* RMS_WRITE.C
*
* PURPOSE       :   To write a record to a file from a char buffer.
*
* PARAMETERS    :   pfs - a pointer to file_struct, a structure
*                         containing the FAB and RAB.
*                   rbf - a pointer to the char buffer
*****************************************************************/
int rms_write(pfs, rbf)
struct file_struct *pfs;
char *rbf;

{
int ret_status;

pfs->rabst.rab$l_rbf = rbf;            /* assign record buffer */
pfs->rabst.rab$w_rsz = strlen(rbf);    /* assign record size */
pfs->rabst.rab$l_rop = 0;              /* record operation field */
pfs->rabst.rab$b_rac = RAB$C_SEQ;      /* sequential record access mode */

/* write the record out */
ret_status = sys$put(&pfs->rabst);

if(ret_status != RMS$_NORMAL)
 {
 printf("FAILED TO WRITE RECORD. STATUS = %d\n",ret_status);
 return(ret_status);
 }

/* flush the buffer */
ret_status = sys$flush(&(pfs->rabst));

if(ret_status != RMS$_NORMAL)
 {
 printf("FAILED TO FLUSH BUFFER. STATUS = %d\n",ret_status);
 return(ret_status);
 }

/* SUCCESS */
return (RMS$_NORMAL);
}
-----------------------------------------------------------------
#include rms
#include "or_src:file_struct.h"
/*****************************************************************
* RMS_CLOSE.C
*
* PURPOSE       :   To disconnect the RAB and close the file.
*
* PARAMETERS    :   pfs - a pointer to file_struct, a structure
*                         containing the FAB and RAB.
*****************************************************************/
int rms_close(pfs)
struct file_struct *pfs;
{
int   ret_status;

ret_status = sys$disconnect(&pfs->rabst);    /* DISCONNECT RAB */

if (!(ret_status & RMS$_NORMAL))
 {
 printf("FAILED TO DISCONNECT RAB. STATUS = %d\n",ret_status);
 return(ret_status);
 }

ret_status = sys$close(&pfs->fabst);         /* CLOSE FILE */

if(!(ret_status & RMS$_NORMAL))
 {
 printf("FAILED TO CLOSE FILE. STATUS = %d\n",ret_status);
 return (ret_status);
 }

/** SUCCESS **/
return (RMS$_NORMAL);
}
-----------------------------------------------------------------
#include rms
#include "or_src:file_struct.h"
/*****************************************************************
* RMS_ERASE.C
*
* PURPOSE       :   To delete a file.
*
* PARAMETERS    :   pfs - a pointer to file_struct, a structure
*                         containing the FAB and RAB.
*****************************************************************/
int rms_erase(pfs)
struct file_struct *pfs;
{
  int   ret_status;

  ret_status = sys$erase(&pfs->fabst);    /* DELETE FILE */

  if ((ret_status != RMS$_NORMAL))
  {
    printf("FAILED TO DELETE FILE. STATUS = %d\n",ret_status);
    return(ret_status);
  }
  else /*** Success ***/
  {
    return(RMS$_NORMAL);
  }
}
-----------------------------------------------------------------

And the relevant pieces of the program:

  struct file_struct     p_mailfile;
  char   	mailfilestr[100];
  unsigned long		status;

  strcpy (mailfilestr, "reg_mail_");
  strcat (mailfilestr, logon_id.arr);
  strcat (mailfilestr, ".tmp");

  status = rms_open(&p_mailfile,
                    mailfilestr,
                    FAB$M_PUT,
                    FAB$M_SUP,
                    FAB$C_SEQ,
                    FAB$C_VAR,
                    FAB$M_CR,
                    FAB$M_SHRGET);

  if (status != RMS$_NORMAL)
  {
    display_message("\007%%REGISTER-F MAILFILE OPEN ERROR\007");
    sprintf (buffer,"Failed to open %s. Status = %d",mailfilestr,status);
    check_status (rms_write (&p_errfile, buffer));
  }

  /** fill buf here (not included) **/

  sprintf (buffer, "%s",buf);
  check_status (rms_write (&p_mailfile, buffer));

  status = rms_close (&p_mailfile);
  if (status != RMS$_NORMAL)
  {
    display_message("%%REGISTER-F-RMS Mailfile Close Error");
    sprintf (buffer,"Failed to close %s. Status = %d",
             mailfilestr,status);
    check_status (rms_write (&p_errfile, buffer));
  }
  send_mail ("register_alert", subj, mailfilestr);

  status = rms_erase (&p_mailfile);
  if (status != RMS$_NORMAL)
  {
    display_message("%%REGISTER-F-RMS Mailfile Delete Error.");
    sprintf (buffer,"Failed to delete %s. Status = %u",
             mailfilestr,status);
    check_status (rms_write (&p_errfile, buffer));
  }
-----------------------------------------------------------------
Notes:
  display_message writes the message to the 24th line of the screen.
  check_status uses sys$getmsg to retrieve any non-success message and
    display it and write it to a log file.

Thanks in advance.
_____________________________________________________________________
Jennifer R. Amon            PHONE: (216) 775-6987
Houck Computing Center        FAX: (216) 775-8573
Oberlin College
Oberlin, OH 44074        INTERNET: bamon@ocvaxc.cc.oberlin.edu
_____________________________________________________________________

