/* This program illustrates how to: */
/* - check the major/minor return code */
/* - check the errno global variable */
/* - get error information from the */
/* _EXCP_MSGID global variable */
/* - use the signal function. */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <errno.h>
#include <signal.h>
#include <recio.h>
#define IND_ON '1'
#define IND_OFF '0'
#define HELP 0
#define EXIT 2
#define REFRESH 4
#define FALSE 0
#define TRUE 1
typedef struct PHONE_LIST_T{
char name[11];
char address[20];
char phone[8];
}PHONE_LIST_T;
void error_check(void);
/* The error checking routine. */
void error_check(void)
{
if (errno == EIOERROR || errno == EIORECERR)
printf("id:%7.7s\n", _EXCP_MSGID);
if (strncmp(_Maj_Min_rc.major_rc,"00",2) ||
strncmp(_Maj_Min_rc.major_rc,"00",2))
printf("Major : %2.2s\tMinor : %2.2s\n",
_Maj_Min_rc.major_rc,_Maj_Min_rc.minor_rc);
errno = 0;
}
/* The signal handler routine. */
void sighd(int sig)
{
signal(SIGIO,&sighd);
}
/* M A I N L I N E */
int main(void)
{
FILE *dspf;
PHONE_LIST_T phone_inp_rec,
phone_out_rec = { "Smith, John",
"2711 Westsyde Rd. ",
"721-9729" };
_SYSindara indicator_area;
int ret_code;
errno = 0;
signal(SIGIO,&sighd); /* Register sighd as a handler for I/O exceptions */
if ((dspf = fopen("*LIBL/T1520DDJ", "ab+ type=record indicators=y"))
== NULL)
{
printf("Display file could not be opened");
exit(1);
}
_Rindara((_RFILE *) dspf,indicator_area);
_Rformat((_RFILE *) dspf,"PHONE");
memset(indicator_area,IND_OFF,sizeof(indicator_area));
do
{
ret_code = fwrite(&phone_out_rec,1,sizeof(phone_out_rec),dspf);
error_check(); /* Write the records to the display file. */
ret_code = fread(&phone_inp_rec,1,sizeof(phone_inp_rec),dspf);
error_check(); /* Read the records from the display file. */
if (indicator_area[EXIT] == IND_ON)
phone_inp_rec = phone_out_rec;
}
while (indicator_area[REFRESH] == IND_ON);
_Rclose((_RFILE *)dspf);
}
|