ILE C/C++ Programmer's Guide

Source Code Samples

The figures in this section show the source code used in Instructions.

Figure 186. T1520DDJ -- DDS Source for a Phone Book Display




A DSPSIZ(24 80 *DS3)
A INDARA
A R PHONE
A CF03(03 'EXIT')
A CF05(05 'REFRESH')
A 7 28'Name:'
A NAME 11A B 7 34
A 9 25'Address:'
A ADDRESS 20A B 9 34
A 11 25'Phone #:'
A PHONE_NUM 8A B 11 34
A 1 35'PHONE BOOK'
A DSPATR(HI)
A 16 19'<ENTER> : Saves changes'
A 17 21'f3 : Exits with changes saved'
A 18 21'f5 : Brings back original fiel-
A d values'
A 05 21 32'Screen refreshed'
A 05 DSPATR(HI)

Figure 187. T1520EHD -- ILE C Source to Handle Exceptions




/* 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);
}


[ Top of Page | Previous Page | Next Page | Table of Contents ]