Guardian Programmer's Guide

Table Of Contents
Writing a Command-Interpreter Monitor ($CMON)
Guardian Programmer’s Guide 421922-014
23 - 69
Sample $CMON Program
!------------------------------------------------------------
! Main procedure performs initialization, then goes into a
! loop in which it reads the $RECEIVE file and then calls the
! appropriate procedure depending on whether the message read
! was a system message, the message read was a user message,
! or the read generated an error.
!------------------------------------------------------------
PROC CMON^MAIN MAIN;
BEGIN
INT BYTES^READ;
INT ERROR;
INT I;
INT ERROR^CODE;
! Initialize:
CALL INIT;
! Loop forever:
WHILE 1 DO
BEGIN
ERROR := 0;
! Read a message from $RECEIVE and check for an error:
CALL READUPDATEX(RECVNUM,SBUFFER,BUFSIZE,BYTES^READ);
CALL FILE_GETINFO_(RECVNUM,ERROR);
CASE ERROR OF
BEGIN
! For a system message, reply with an error code
! of 0:
6 -> BEGIN
ERROR^CODE := 0;
CALL REPLYX(!buffer!,
!write^count!,
!count^written!,
!message^tag!,
ERROR^CODE);
END;