Chapter Contents

Previous

Next
XEDIT Low-Level I/O Functions

XEDIT Low-Level I/O Functions



Descriptions of each XEDIT low-level I/O function follow.

Portability SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
IMPLEMENTATION
MACROS
EXAMPLE


SYNOPSIS

#include <cmsio.h>

int cmsxflst(struct CMSFSCB *fscbp, struct CMSFST *fstp);
int cmsxflrd(struct CMSFSCB *fscbp);
int cmsxflwr(struct CMSFSCB *fscbp);
int cmsxflpt(struct CMSFSCB *fscbp);


DESCRIPTION

The cmsxflst function states or verifies the existence of an XEDIT file. The first argument to cmsxflst is a pointer to a CMSFSCB structure, and the second argument is a pointer to a CMSFST structure.

The remaining functions are as follows:
cmsxflrd reads a record from XEDIT storage.
cmsxflwr writes a record to XEDIT storage.
cmsxflpt moves the current line pointer in an XEDIT file.

A pointer to a CMSFSCB structure is the only argument for these functions.

Refer to the CMS Low-Level I/O Functions for a description of these structures.


RETURN VALUE

All of the functions return the return code from their associated XEDIT subcommand. If the return code from DMSXFST is 0, cmsstate copies the information from the CMS FST to the CMSFST structure pointed to by fstp .


IMPLEMENTATION

Each function invokes the associated XEDIT subcommand. All of the functions expect an extended format (FORM=E) FSCB. The following table lists each function and the XEDIT subcommand it executes:

Function XEDIT Subcommand
cmsxflst DMSXFLST
cmsxflrd DMSXFLRD
cmsxflwr DMSXFLWR
cmsxflpt DMSXFLPT

Refer to the appropriate IBM documentation for information about the data associated with the FSCB and FST and for information about these XEDIT subcommands.


MACROS

Each of the XEDIT low-level I/O functions has an associated macro that can be used to provide a more readable name. The macros are defined in <cmsio.h> and are listed as follows:

#define xedstate(fscb,fst) cmsxflst(fscb,fst)
#define xedread(fscb) cmsxflrd(fscb)
#define xedwrite(fscb) cmsxflwr(fscb)
#define xedpoint(fscb) cmsxflpt(fscb)


EXAMPLE

The following example shows a program that uses cmsxflwr to write a date and time string at the current line of a file in XEDIT. The example shows how a program can communicate with XEDIT via the system function (using the "XEDIT prefix) and the cmsxflst function.

Note that XEDIT and either EXEC2 or REXX must be active when this function is executed. This sort of interaction between XEDIT and a program via an EXEC processor is most appropriate in a program using the SUBCOM interface or a program that is a REXX function package.

The example invokes the EXTRACT subcommand to place the filename, filetype, and filemode of the file into EXEC2 or REXX variables. Then, it calls execfetch to fetch the values of these variables and put them into a CMSFSCB structure. Next, it uses the time and ctime functions to create a date and time string. Finally, cmsxflwr writes the string into the file at the current line.

The example assumes that the file has fixed format records and a logical record length of 80. In practice, this information can be obtained with a call to cmsstat , cmsxflst , or via the EXTRACT subcommand. For clarity, all error checking after the initial call to system has been omitted. For more information on the time , ctime , or system functions, refer to Chapter 6, "Function Descriptions," in SAS/C Library Reference, Volume 1. For more information on the cmsshv function, refer to The CMS REXX SAS/C Interface.

#include <cmsio.h>
#include <lclib.h>
#include <cmsexec.h>
#include <lcstring.h>
#include <time.h>

main()
{
   time_t now;
   struct CMSFSCB fscb;
   char timestring[80];
   int s, rc;

   rc = system("xedit: extract /fname/ftype/fmode");

   if (rc != 0) {
      printf("Unable to determine current fileid.  ");
      switch (rc) {
         case SYS_TNAC:
            puts("XEDIT is not active.");
            break;
         case SYS_CUNK:
            puts("Not called from EXEC2 or REXX exec.");
            break;
         default:
            if (rc > 0)
               printf("EXTRACT subcommand returned %d\n", rc);
            else
               printf("System function returned %d\n", rc);
            break;
      }
   }
   exit(rc);
}

      /* Set all fields in CMSFSCB structure to zeros.    */
      /* Fetch fileid components.                         */
   memset((void *) &fscb,'\0',sizeof(fscb));
   cmsshv(SHV_FETCH_DIRECT,"FNAME.1",7,fscb.fn,8,&s);
   cmsshv(SHV_FETCH_DIRECT,"FTYPE.1",7,fscb.ft,8,&s);
   cmsshv(SHV_FETCH_DIRECT,"FMODE.1",7,fscb.fm,2,&s);

   fscb.fv = 'F';           /* RECFM F                    */
   fscb.size = 80;          /* LRECL 80                   */
   fscb.buff = timestring;  /* record buffer address      */
   fscb.aitn = 0;  /* A zero indicates the current line.  */
      /* Initialize record buffer.  Get the date and time */
      /* and copy to the record. Call cmsxflwr to write   */
      /* the record.                                      */
   memset(timestring,' ',80);
   now = time(NULL);
   memcpy(timestring,ctime(&now),24);
   cmsxflwr(&fscb);

   exit(0);
}


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.