Open System Services Programmer's Guide
Example 49 Accessing an OSS Terminal With Guardian Procedures in the OSS API
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,READX,WRITEX,WRITEREADX,\
PROCESS_GETINFO_,FILE_CLOSE_)>
short filenum; /* file code number */
short retcode; /* procedure call return code */
_cc_status CC; /* condition code */
char *terminal; /* name of terminal */
char hometerm[64]; /* name of home terminal */
short htlen; /* length of home terminal name */
char buffer[134]; /* buffer for input/output line */
char *buf; /* pointer to buffer string */
short bytesread; /* bytes read */
int main(int argc, char *argv[]) {
/* Get the Guardian terminal filename from the command argument. */
if (argc > 1)
terminal = argv[1];
else {
retcode = PROCESS_GETINFO_( /* get Home terminal name */
, /* process handle */
, /* process filename */
, /* maximum length of filename */
, /* actual length of filename */
, /* execution priority */
, /* process handle of MOM */
hometerm, /* home terminal name */
64, /* maximum length of hometerm name */
&htlen /* actual length of hometerm name */
);
/* Check if PROCESS_GETINFO_ was successful. */
if (retcode != 0) {
fprintf(stderr, "PROCESS_GETINFO_ failed: retcode = %d\n", \
retcode);
exit(1);
}
terminal = hometerm;
}
retcode = FILE_OPEN_(terminal, /* name of Guardian terminal */
(short)strlen(terminal), /* terminal name length */
&filenum, /* file number returned */
0, /* open for read/write access */
);
/* Check if the open was successful. */
if (retcode != 0) {
fprintf(stderr, "Can't open %s\n", terminal);
fprintf(stderr, "retcode = %d\n", retcode);
exit(1);
}
/* Write to the terminal using WRITEX. */
CC = WRITEX(filenum, /* terminal file number */
buf = "Type in a line followed by ENTER:", /* output string */
(short)strlen(buf) /* size of string */
);
/* Check for successful terminal write operation. */
if (_status_ne(CC)) {
fprintf(stderr, "WRITEX to terminal failed: %s\n", terminal);
exit(1);
}
Terminal I/O 213