TYPE state IS (reset, good);
PROCEDURE display_state (current_state : IN state) IS
FILE flush : TEXT IS OUT "/dev/tty";
VARIABLE state_string : STRING(1 to 7);
WHEN reset => state_string := "reset ";
WHEN good => state_string := "good ";
WRITE (k, state_string, LEFT, 7);
This procedure displays the current state of a FSM
This example displays the current state of a finite state machine model execution. First, the USE clause makes the contents of the TEXTIO package available. The enumerated type STATE is then locally declared. The procedure display_state requires only one input value, the current state of the FSM.
Several local variables are declared within the procedure. The buffer k of type LINE will be used for WRITE storage. The FILE flush is of type TEXT and will output to a file named /dev/tty (i.e. the system console in UNIX; that is, the procedure will write to the screen). The variable state_string holds the text value of the state.
The CASE statement is used to assign the appropriate string value to the variable state_string in preparation for outputting the information to a file. The WRITE statement then writes the value of state_string to the buffer k. The WRITE statement further specifies that the string should be left justified and be 7 spaces wide.
Finally, the WRITELINE sends the buffer k to the file flush. The text is then written to the screen.
Note that this particular procedure would not work well for writing to a file since the file is re-initialized every time the procedure is used, and thus the text would always be written to the beginning of the file. However, using TEXTIO to write to a file may be accomplished by passing the file to the procedure as a parameter, or by using a process that implements the same functionality, for example.