Main Module PPACKBUG Use TEXTIO Declare Null_char is char initially $ Max_prompt_length = 50 Command_type is [ noop_command, reset, poll, open, close, start, stop, show, set_ ] Max_command_name_length = 10 Command_name_type is packed array [ 1..max_command_name_length ] of null_char Command_name_table_type is array [ command_type ] of command_name_type Command_name_table = command_name_table_type ( [ reset ] : "Reset", [ open ] : "Open", [ close ] : "Close", [ start ] : "Start", [ stop ] : "Stop", [ show ] : "Show", [ set_ ] : "Set" ) Qualifier_type is [ no_qualifier, when_met, override, cal_factor, setpoint ] Qualifier_name_type is packed array [ 1..10 ] of null_char Qualifier_name_table_type is array [ qualifier_type ] of qualifier_name_type Qualifier_name_table = qualifier_name_table_type ( [ when_met ] : "When Met", [ override ] : "Override", [ cal_factor ] : "Cal Factor", [ setpoint ] : "Setpoint" ) Max_num_of_devices = 300 Device_number_range is 12 bit cardinal range 1..max_num_of_devices GCP_function_type is [ Noop_function, Second, Self_test, Enter, Clear ] Max_function_name_length = 10 GCP_function_name_type is packed array [ 1..max_function_name_length ] of null_char GCP_function_name_table_type is array [ GCP_function_type ] of GCP_function_name_type GCP_function_name_table = GCP_function_name_table_type ( [ noop_function ] : "Undefined", [ second ] : "Second", [ self_test ] : "Self-Test", [ enter ] : "Enter", [ clear ] : "Clear" ) Key_number_range is 8 bit cardinal range 0..127 Key_class_type is [ function_key, command_key, qualifier_key, device_key ] Max_key_class_name_length = 10 Key_class_name_type is packed array [ 1..max_key_class_name_length ] of null_char Key_class_name_table_type is array [ key_class_type ] of key_class_name_type Key_class_name_table = key_class_name_table_type ( [ function_key ] : "Function", [ command_key ] : "Command", [ qualifier_key ] : "Qualifier", [ device_key ] : "Device" ) Key_record_type is packed // 16 bits total: Structure Class : key_class_type // 2 bit Select class from Case function_key: Func : GCP_function_type // <= 6 bits Case command_key, qualifier_key: Select class from Case command_key: Command : command_type // <= 6 bits Case qualifier_key: Qualifier : qualifier_type// <= 6 bits EndSelect Data : char // 8 bits Case device_key: Defined : boolean // 1 bit Device_number : device_number_range // 12 bits EndSelect EndStructure Key_table_type is array [ key_number_range ] of Key_record_type Overlay_template : static key_table_type Initially key_table_type ( [ cardinal ( 0 )..cardinal ( 44 ) ]: Key_record_type ( class: device_key, Defined: false ), [ cardinal ( 45 ) ]: Key_record_type ( class: function_key, func: second ), [ cardinal ( 46 ) ]: Key_record_type ( class: command_key, command: reset, data: $+ ), [ cardinal ( 47 ) ]: Key_record_type ( class: qualifier_key, qualifier: no_qualifier,data: $- ), [ cardinal ( 48 )..cardinal ( 60 ) ]: Key_record_type ( class: device_key, Defined: false ), [ cardinal ( 61 ) ]: Key_record_type ( class: command_key, command: open, data: $1 ), [ cardinal ( 62 ) ]: Key_record_type ( class: command_key, command: close, data: $2 ), [ cardinal ( 63 ) ]: Key_record_type ( class: qualifier_key, qualifier: when_met, data: $3 ), [ cardinal ( 64 )..cardinal ( 76 ) ]: Key_record_type ( class: device_key, Defined: false ), [ cardinal ( 77 ) ]: Key_record_type ( class: command_key, command: start, data: $4), [ cardinal ( 78 ) ]: Key_record_type ( class: command_key, command: stop, data: $5 ), [ cardinal ( 79 ) ]: Key_record_type ( class: qualifier_key, qualifier: override, data: $6 ), [ cardinal ( 80 )..cardinal ( 92 ) ]: Key_record_type ( class: device_key, Defined: false ), [ cardinal ( 93 ) ]: Key_record_type ( class: command_key, command: show, data: $7 ), [ cardinal ( 94 ) ]: Key_record_type ( class: command_key, command: set_, data: $8 ), [ cardinal ( 95 ) ]: Key_record_type ( class: qualifier_key, qualifier: cal_factor, data: $9 ), [ cardinal ( 96 )..cardinal ( 108 ) ]: Key_record_type ( class: device_key, Defined: false ), [ cardinal ( 109 ) ]: Key_record_type ( class: command_key, command: noop_command, data: $. ), [ cardinal ( 110 ) ]: Key_record_type ( class: command_key, command: noop_command, data: $0 ), [ cardinal ( 111 ) ]: Key_record_type ( class: qualifier_key, qualifier: setpoint, data: $E ), [ cardinal ( 112 )..cardinal ( 124 ) ]: Key_record_type ( class: device_key, Defined: false ), [ cardinal ( 125 ) ]: Key_record_type ( class: function_key, func: enter ), [ cardinal ( 126 ) ]: Key_record_type ( class: function_key, func: clear ), [ cardinal ( 127 ) ]: Key_record_type ( class: function_key, func: self_test ) ) EndDeclare Procedure out_prompt Param F : inout ref file prompt : in ref packed array [ 1..?N ] of char EndParam For index := 1 to when N <= max_prompt_length then N else max_prompt_length do Out_character ( f, prompt[ index ] ) EndFor For index := N + 1 to max_prompt_length do Out_character ( f, $ ) EndFor Out_character ( f, $: ) Out_record ( TTY, false ) EndProcedure Procedure out_key Param F : inout ref file Key : in ref key_record_type EndParam Out_prompt ( f, "Class" ) Out_padded_string ( f, key_class_name_table[ key.class ] ) Out_record ( f ) Select key.class from Case function_key: Out_prompt ( f, "Function" ) Out_padded_string ( f, GCP_function_name_table[ key.func ] ) Out_record ( f ) Case command_key: Out_prompt ( f, "Command" ) Out_padded_string ( f, command_name_table[ key.command ] ) Out_record ( f ) Out_prompt ( f, "Data" ) Out_character ( f, key.data ) Out_record ( f ) Case qualifier_key: Out_prompt ( f, "Qualifier" ) Out_padded_string ( f, qualifier_name_table[ key.qualifier ] ) Out_record ( f ) Out_prompt ( f, "Data" ) Out_character ( f, key.data ) Out_record ( f ) EndSelect Out_record ( f ) EndProcedure Out_prompt ( TTY, "Overlay template" ) Out_record ( TTY ) For key_number in key_number_range do Select overlay_template[ key_number ].class from Case function_key, command_key, qualifier_key: Out_prompt ( TTY, "Key number" ) Out_integer ( TTY, integer ( key_number ) ) Out_record ( TTY ) Out_key ( TTY, overlay_template[ key_number ] ) Case device_key: EndSelect EndFor EndModule { PPACKBUG }