Technical information
Serial Solutions Cterm
Figure 7-6. Function main._______________________
void main(int argc, char **argv)
{
init_screen(); /* Set up screen. */
init_xlat(); /* initialise translation tables. */
/* This may need to be replaced. */
exec_defaults(argv); /* Find and execute a file of commands */
open_com(); /* Open com files. */
while( TRUE ) /* Main program loop. */
{
readin(); /* get any characters from port. */
/* send to display. */
switchout(); /* Read and process characters */
/* from keyboard. */
};
}
Init_screen() and init_xlat() set up internal variables for use
by CTERM. Exec_defaults checks for a command line parameter
and attempts to execute the file of commands to which it refers.
If it cannot find the file, or if no file is specified on the
command line then the file ’TERMDEF.TXT’ is tried.
Open_com opens the serial port, as discussed in the previous
section. The program then enters an infinite loop which
alternately calls two functions, switchout() and readin().
Readin() checks for characters at the serial port, calling the
function inxlat() (that is input and translate), which in turn calls
inpstr(), discussed in the previous section. If inxlat() returns a
non-nul string of characters the readin() prints them out.
Switchout() polls the keyboard using kbdinp(). A character,
if entered, is compared with zero. A zero byte indicates an
extended character code, used for the function, cursor and edit
keys and ALT key combinations. These are all taken to be
commands, and so the function menuout() is called to deal with
them. All other keys are echoed (if echo to screen has been set),
and then passed on to outxlat(). Outxlat() translates the
characters and uses outstr() to send them on to the serial port.
Outstr() is examined in the section above.
Page 126 Chapter 7