Abstract interfrace class for forth character i/o. More...
#include <forth.h>

Public Member Functions | |
| virtual void | ConsoleOut (const CHAR *text, UCELL textLength)=0 |
| virtual CELL | ConsoleIn ()=0 |
Public Attributes | |
| CHAR | NewLine [4] |
Abstract interfrace class for forth character i/o.
The forth VM uses this object to request character input and output. Here is an example implementation of this class using the C standard library...
#include <stdio.h> #include <unistd.h> #include <termios.h> class StdForthIo : public ForthIo { public: StdForthIo() { // set new line sequence as CR/LF... NewLine[0]=2; NewLine[1]=13; NewLine[2]=10; // if stdin is a terminal then set non-canonical input mode without echo... if((IsTerminal = tcgetattr(fileno(stdin),&InitialSettings)==0)) { struct termios settings = InitialSettings; settings.c_lflag &= ~(ICANON|ECHO); settings.c_cc[VMIN] = 1; settings.c_cc[VTIME] = 0; tcsetattr(fileno(stdin),TCSANOW,&settings); } } ~StdForthIo() { // restore terminal settings... if(IsTerminal) tcsetattr(fileno(stdin),TCSANOW,&InitialSettings); } virtual void ConsoleOut(const CHAR* text,UCELL textLength) { while(textLength--) putchar(*text++); } virtual CELL ConsoleIn() { return getchar(); } private: bool IsTerminal; struct termios InitialSettings; };
Definition at line 143 of file forth.h.
Display a text string on the console. This is called by the forth words TYPE and EMIT.
| text | Pointer to string. | |
| textLength | Number of characters in string. |
Implemented in StdForthIo, and TestForthIo.
| virtual CELL ForthIo::ConsoleIn | ( | ) | [pure virtual] |
Get a single character from the console input. This is called by the forth word KEY.
Implemented in StdForthIo, and TestForthIo.
A counted string representing the system's line terminating sequence. This is used by the forth word CR and the first character in this string is also used as the input termination character by ACECPT.
NewLine[0] is the character count, NewLine[1] and subsequent are the characters of the line terminating sequence; unused characters may be left uninitialised. E.g. the following sequence initialises the string with a carriage-return line-feed sequence:
1.6.1