1 Introduction
This specification defines the form and syntax of the coded interchange between terminal products and other system components. It applies directly to serial line communications consisting of a stream of 7-bit or 8-bit combinations referred to as "coded characters". The mechanisms employed for achieving this form of communication, however, may be applied within the context of block oriented line protocols, networking packet protocols, and program call interfaces over high-bandwidth bus interconnects.
1.1 Scope
The recognition and coding of characters as described in this specification applies uniformly to all display terminals, printing terminals, computing terminals and workstations, and is independent of the actual character sets implemented in a particular terminal product. The syntax defined herein applies equally to the transmission and receipt of coded interchange at the terminal interface.
1.2 National Replacement Character Set (NRCS) Extension
Support for National Replacement Character Sets was introduced as an extension to the VT200 family of Digital terminals for backward compatibility with national versions of the VT100 family. The NRCS extension allows U.S. ASCII to be replaced by one of 12 NRC sets corresponding to the keyboard dialect selected (when the keyboard dialect is other than "North American"). These 7-bit character sets are similar to U.S. ASCII, but replace certain reserved character positions with national use characters. The National Replacement Character Mode (DECNRCM) is intended for backward compatibility and restricts the terminal to 7-bit characters. New applications are encouraged to use one of the 8-⁠bit multinational character sets. See "Character Set Mode" in DEC STD 070-6 Video Systems Reference Manual - Keyboard Processing. The rest of this section of DEC STD 070 does not assume the NRCS Extension is present.
1.3 8-Bit Interface Architecture Extension
Support for 96-character graphic character sets, ISO Latin-1 Supplemental, and the User Preference Supplemental Set (UPSS) was introduced on the VT300 family of Digital terminals. The 8-bit Interface Architecture Extension is required for Level 3 conformance to the Character Cell Display service class, and is strongly recommended (but not mandatory) for Level 2. It is also mandatory for Level 2 of the Character Cell Printer service class. The rest of this section for DEC STD 070 assumes the 8-bit Interface Architecture Extension is present.
1.4 Relationship To Terminal Interface Architecture (TIA)
Character encoding forms a part of the Code Extension Layer of the Terminal Interface Architecture. It is independent of any specific service class, and therefore applies across all products implementing any aspect of the architecture.
USER
.......... -----------------------------------------------
. . | |
. . | Input Processing |
. . | |
. . | |
. T M . -----------------------------------------------
. e a . -----------------------------------------------
. r n . | |
. m a . | Presentation |
. i g . | Service Class |
. n e . | |
. a m . | |
. l e . -----------------------------------------------
. n . ===============================================
. t . || . . ||
. . || Code Extension . NRCS . 8-bit||
. . || Layer . . IA ||
. . || . . ||
.......... ===============================================
APPLICATION PROCESS
The interfaces defined within this standard apply to both internal and external product interfaces. External interfaces are interfaces between a terminal, personal computer, or workstation and a remote system. Internal interfaces are interfaces between a terminal subsystem and software processes running within a terminal, personal computer, or workstation.
*
*
terminal system * host system
--------------------------* ---------------
| | * | |
| physical | virtual *.......... | application |
| terminal | terminal * ..............| process |
| | * | |
--------------------------* ---------------
<hardware> <firmware> * <communications link> <software>
*
*
* EXTERNAL INTERFACE
*
*
terminal system
--------------------------*--------------
| | * |
| physical | virtual * application |
| terminal | terminal * process |
| | * |
--------------------------*--------------
<hardware> <software/ * <software>
firmware> *
*
* INTERNAL INTERFACE
2 Terminology
- bit combination
- Ordered set of bits that represent a character.
- byte
- A 7-bit or 8-bit string that is used to represent control or graphic information. The size of the byte is independent of redundancy or framing technique. (Note: this term commonly refers to the 8-bit unit.)
- character
- Member of a set of elements that is used for the organization, control and representation of data.
- code; Coded Character Set
- Set of unambiguous rules that establishes a character set and the one-to-one relationship between the characters of the set and their bit combinations.
- code extension
- Techniques for the encoding of characters that are not included in the character set of a given code.
- code table
- Table showing the character corresponding to each bit combination in a code.
- control character
- Control function of which the coded representation consists of a single bit combination.
- control function
- Action that affects the recording, processing, transmission, or interpretation of data. The coded representation of a control function consists of one or more bit combinations.
- control sequence
- Bit string that is for control purposes in code extension procedures consisting of two or more bit combinations, beginning with a Control Sequence Introducer (CSI) control function, and that may contain parametric information for the control function.
- control string
- A string of characters that is used to perform a control function and is delimited by an opening and closing delimiter control. The opening delimiter is one of a small set of introducer control functions (APC, DCS, OSC, PM), and the closing delimiter is String Terminator (ST). Within Digital, the syntax of control strings has been extended to include an introducer sequence that acts as a protocol selector and specifies how to interpret subsequent control string data.
- designate
- To identify a set of characters that are to be represented, in some cases immediately and in others upon further occurrence of a control function, in a prescribed manner.
- environment
- The characteristic that identifies the number of bits used to represent a character in a data processing or data communication system, or in part of such a system.
- escape sequence
- Bit string that is for control purposes in code extension procedures consisting of two or more bit combinations, the first of which is an Escape (ESC) character.
- expansion escape sequence (Fe)
- 2-character escape sequence in which the final character is in columns 4 and 5, and is used to extend the 7-bit code table by being the row equivalent to the corresponding C1 set of controls in columns 8 and 9 of an 8-bit code.
- final character
- The character whose bit combination terminates an escape sequence, control sequence, or control string introducer sequence.
- graphic character
- Character, other than a control character, that has a handwritten, printed, or displayed visual representation and that has a coded representation consisting of one bit combination.
- intermediate character
- A character whose bit combination precedes a Final character in an escape sequence, control sequence, or control string introducer sequence.
- invoke
- To cause a designated set of characters to be represented by the prescribed bit combinations whenever those bit combinations occur (until an appropriate code extension function occurs).
- numeric parameter
- A control sequence parameter used for passing numeric values.
- parameter string
- A character string, the bit combination of which occurs between the Control Sequence Introducer character and the first intermediate character or final character of a control sequence.
- position
- Item in a code table identified by its column and row coordinates.
- represent
- 1) To use a prescribed bit combination with the meaning of a character in a set of characters that has been designated and invoked. 2) To use an escape sequence with the meaning of an additional control function.
- selective parameter
- A control sequence parameter used to select particular entries from a specified list.
3 Character Coding Description
3.1 Character Codes
A character code is a unique bit combination that defines a position in a coded character set by its column and row coordinate within that set. Characters may be coded using 7-bit combinations or 8-bit combinations. The choice of whether 7-bit or 8-bit character codes are used is dependent on the "width" (frame size) of the communications channel (referred to in this specification as the "environment").
If the channel is only seven bits wide, then only 7-bit character codes may be used. If the channel is eight bits wide, then either 7-⁠bit or 8-bit character codes may be used (7-bit character codes are a specific subset of the 8-bit code structure). The following table describes how the column and row position in the coded character set is derived from both 7-bit and 8-bit character codes.
_________________________________________
| | | | | | | | |
Bits of a 7-bit | -- | b7 | b6 | b5 | b4 | b3 | b2 | b1 |
combination |____|____|____|____|____|____|____|____|
| | | | | | | | |
Bits of an 8-bit | a8 | a7 | a6 | a5 | a4 | a3 | a2 | a1 |
combination |____|____|____|____|____|____|____|____|
| | |
| COLUMN | ROW |
|___________________|___________________|
Column and Row Reference
3.2 7-Bit Character Sets
A 7-bit coded character set has the following features.
A set of 32 control characters allocated to columns 00 and 01 (bit combinations in the range 0/0 to 1/15 inclusive).
AND EITHER
A character Space (SP) in position 2/0, that may be regarded as either a control character or a graphic character.
A set of 94 graphic characters allocated to columns 02 to 07 (bit combinations from 2/1 to 7/14, inclusive).
A control character Delete (DEL) in position 7/15.
OR
A set of 96 graphic characters allocated to columns 02 to 07 (bit combinations from 2/0 to 7/15, inclusive).
The following table describes the structure of a 7-bit coded character set including a 94-character graphic character set.
row column
00 01 02 03 04 05 06 07
+---+---+---+---+---+---+---+---+
00| |SP | |
+ +---+ |
01| | |
+ | |
02| | |
+ | |
03| | |
+ | |
04| | |
+ | |
05| | |
+ | |
06| | |
+ | |
07| C0 | GL |
+control| graphic |
08| codes | codes |
+ | |
09| | |
+ | |
10| | |
+ | |
11| | |
+ | |
12| | |
+ | |
13| | |
+ | |
14| | |
+ | +---+
15| | |DEL|
+---+---+---+---+---+---+---+---+
3.3 8-Bit Character Sets
An 8-bit coded character set has the following features.
All the features of a 7-bit coded character set as previously listed.
A set of thirty-two control characters allocated to columns 08 and 09, called the C1 control set (bit combinations from 8/0 to 9/15, inclusive).
AND EITHER
A set of 94 graphic characters allocated to columns 10 to 15 (bit combinations from 10/1 to 15/14, inclusive), called the GR graphics set (for right-hand graphics set).
OR
A set of 96 graphic characters allocated to columns 10 to 15 (bit combinations from 10/0 to 15/15, inclusive).
The following table describes the structure of an 8-bit coded character set with 94-character graphic character sets.
Row Column 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 00| |SP | | |XXX| | + +---+ | +---+ + 01| | | | | + | | | + 02| | | | | + | | | + 03| | | | | + | | | + 04| | | | | + | | | + 05| | | | | + | | | + 06| | | | | + | | | + 07| C0 | GL | C1 | GR | +control| graphic |control| graphic + 08| codes | codes | codes | codes | + | | | + 09| | | | | + | | | + 10| | | | | + | | | + 11| | | | | + | | | + 12| | | | | + | | | + 13| | | | | + | | | + 14| | | | | + | +---+ | +---+ 15| | |DEL| | |XXX| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ <------ seven bit codes -------> <----------------------- eight bit codes ----------------------->
3.4 Control And Graphic Codes
The coded character stream can be separated into two categories: control functions and coded graphic characters. Control functions are actions that affect the recording, processing, transmission, or interpretation of data. Coded graphic characters represent actual presentation data. All bit combinations in the coded character stream are specifically categorized as being either part of a control function or a coded graphic character.
3.4.1 Control Characters
A control character is a single character whose occurrence in a particular context initiates, modifies, or stops a control function. The control characters are referred to as C0 and C1. DEL (delete, 7/15) is also a control character, although it is not a member of the C0 or C1 sets. SP (space, 2/0) is also not a member of C0 or C1, but it may be considered to be either a control character or a graphic character.
In a 7-bit environment, the values of a C0 control character are in the range of columns 00 and 01 of the code table. The C1 control characters are represented in 7-bit environments by 2-⁠character escape sequences.
In an 8-bit environment, the values of C0 control characters are from columns 00 and 01 and the values of C1 control characters are from columns 08 and 09.
3.4.2 Graphic Characters
Graphic characters are characters other than a control character having a visual representation which is normally printed or displayed. This includes all characters from the GL and GR portions of the code table (2/1 to 7/14 inclusive and 10/1 to 15/14 inclusive for 94 character sets; 2/0 to 7/15, inclusive and 10/0 to 15/15 inclusive for 96 character sets). Graphic characters are frequently referred to as "printing characters".
Bit combinations in this same range that occur within escape or control sequences are not treated as graphic characters, but are processed as part of the control function.
4 Special Characters
When 94-character graphic character sets are used, the following characters are not part of either the control or graphic sets in a 7-⁠bit or 8-bit code, and therefore have special processing as described below.
4.1 2/0 (Space)
The Space character may be interpreted as a graphic character, a control character, or both. As a graphic character it has the visual representation of the absence of a graphic symbol. The Space character will be displayed using whatever display attributes are currently active.
4.2 7/15 (Delete)
When received by a terminal, the Delete character is treated as an unimplemented control character and shall be ignored. Conforming software shall not use Delete as a pad character. The Delete character may be issued as a result of keyboard processing. Refer to DEC STD 070-6 for more information.
4.3 10/0
The character code 10/0 in 8-bit environments is treated as an unassigned graphic character code, and will cause the error character (usually imaged as a REVERSE QUESTION MARK) to be displayed on conforming devices. Within escape sequences and control sequences, the high order bit of this character will be ignored, and it will be treated as syntactically equivalent to Space (2/0).
4.4 15/15
The character code 15/15 in 8-bit environments is treated as an unimplemented control code and shall be ignored.
5 Control Code Extension Techniques
Because the number of controls typically required for effective communication far exceeds the number provided in either the 7-bit or 8-bit code tables, special methods of providing additional control functions have evolved. These methods can be divided into three categories: escape sequences, control sequences, and control strings.
5.1 General Rules
5.1.1 Precedence of Control Functions
Control characters, escape sequences, control sequences, control strings, and graphic characters are processed serially in the forward direction in the data stream with the following precedence:
Control characters
Escape sequences, control sequences, and control strings (equal precedence)
Graphic characters
Thus, if a control character is transmitted in the middle of an escape sequence, the control character is executed as if the escape sequence were not present (that is, as if the control character had been received immediately before the escape sequence), with the exceptions noted below. The next character received is assumed to be part of the escape sequence. However, when transmitting to a device, implementors are warned not to count on this property if they wish to follow the emerging ANSI and ISO standards that specify this as an error condition whose recovery is not specified. Control characters, escape sequences, control sequences, and control strings should not (not mandatory) be embedded in other escape sequences, control sequences, or control strings.
5.1.2 Termination Conditions
Escape sequences and control sequences normally terminate only on the receipt of a valid final character. However, there are certain conditions that will cause a sequence to be terminated without valid interpretation. In all of these cases, the terminated sequence is ignored.
5.1.2.1 Cancel
Cancel (CAN, 1/8) is used to indicate that the data with which it is sent is in error or is to be disregarded. Therefore, the receipt of CAN causes immediate termination, without execution, of any sequence in progress. The CAN character itself receives no further processing. The characters following the CAN are not interpreted as part of the escape or control sequence, but rather are interpreted normally.
5.1.2.2 Substitute
Substitute (SUB, 1/10) is used to indicate replacement of a character that could not be represented. The receipt of SUB causes immediate termination, without execution, of any sequence in progress. The SUB character itself, and all subsequent characters, are not interpreted as part of the escape or control sequence, but rather are interpreted normally.
5.1.2.3 Escape
If an Escape (ESC, 1/11) is embedded in an escape or control sequence, the sequence is canceled and a new sequence begins with that ESC.
5.1.2.4 C1 Control Codes
Since C1 control functions may be represented as ESC Fe sequences in 7-bit environments, C1 control characters embedded in an escape sequence or control sequence shall cause the sequence to be canceled and a new control function to begin with the C1 control character. This provides for compatibility between 7-bit and 8-⁠bit implementations.
5.1.2.5 Universal Terminator
In many instances it is important that the communications link be set into a known state in order for conforming interchange to proceed. Because of the complexity of the parsing algorithms and rules regarding control code processing, it is desirable to provide a single escapement that aborts any code processing in progress and restore the terminal to a base state. This may be accomplished using the String Terminator control code, transmitted in its 7-bit format as ESC \ (1/11 5/12). This control terminates the following conditions.
Escape Sequence in Progress - The initial Escape control character will cause the sequence in progress to be canceled. The String Terminator will then be processed as an ESC Fe sequence (7-bit C1 control code). If no control string is in progress, the String Terminator will be ignored.
Control Sequence in Progress - Same as Escape Sequence in Progress.
Control String in Progress - If received before the Final Character, the control string will be treated as a Control Sequence in Progress. If the String Terminator is received after the Final Character, it causes normal termination of the control string.
No Control Function in Progress - If a control function is not in progress when the String Terminator is received, it will be processed as an ESC Fe sequence (7-⁠bit C1 control code) and will be ignored by the receiving party.
5.1.3 Unimplemented Functions
Unimplemented functions shall be ignored as if they were not received. This applies to unimplemented control characters, escape sequences, control sequences, parameters of control sequences, and control strings.
For example, unimplemented selective parameter values of control sequences shall be ignored as if that parameter were not received. Processing of the sequence shall continue with the next parameter. For example, if the control sequence Select Graphic Rendition (SGR) is sent with parameters: 1 (bold), 3 (italicized), 7 (negative image), and 21 (doubly underlined), and the terminal implements bold and negative image, but does not implement italicized or doubly underlined, the parameters 1 and 7 shall be executed, and 3 and 21 shall be ignored.
5.1.4 Transformation Between 7-bit and 8-bit Environments
To simplify the transformation between 7-bit and 8-bit environments, relaxations in constraints for the structure of Control Sequences (introduced by CSI), control string introducer sequences (introduced by APC, DCS, PM, and OSC), G2 sequences (introduced by SS2), and G3 sequences (introduced by SS3) are defined as follows:
In an 8-bit code, the bit combinations of columns 10 to 15 (except 15/15) are permitted to represent:
Parameters, intermediates, and finals of a control sequence
The contents of a control string introducer sequence
The operand of a single-shift character
In these situations, the bit combinations in the range 10/0 to 15/15 have the same meaning as the bit combinations in the corresponding row from columns 02 to 07 (bit combinations in the range 2/0 to 7/15 inclusive).
In a 7-bit code, the control characters Shift Out (SO, 0/14) and Shift In (SI, 0/15) are permitted to occur:
Between the Control Sequence Introducer (CSI, 9/11) and the final bit combination of a control sequence
Between the opening delimiter of a control string and the String Terminator (ST, 9/12)
Between a single-shift character and its operand
Shift Out and Shift In have no effect on the interpretation of a control sequence, a control string, or the operand of a single shift character, but may affect the meanings of sebsequent bit combinations in the data stream.
5.2 Escape Sequences
An escape sequence is a bit string that is used for control purposes in code extension procedures and that consists of two or more bit combinations, of which the first is the bit combination corresponding to the Escape character (1/11).
The general form of an escape sequence is:
ESC I..I F
where:
ESC (Escape) is the introducer character, coded as 1/11 in both 7-bit and 8-bit environments.
I..I are zero or more intermediate bit combinations used in combination with the final character to specify the particular function. Intermediate characters for escape sequences are bit combinations in the range of 2/0 to 2/15, inclusive.
Conforming implementations shall recognize at least three intermediate characters. If more intermediates than can be recognized are received, the entire sequence shall be ignored up to and including the final character.
F is a final, function defining character. It is used either by itself or in combination with the intermediate characters (if any) to establish the encoded function. Final characters for escape sequences are bit combinations in the range 3/0 to 7/14 inclusive.
The occurrence of bit combinations 0/0 to 1/15, inclusive, as well as 7/15 and 15/15 in escape sequences are special conditions that are handled by immediately executing the control function indicated, and by continuing processing of the escape sequence as if the intervening control code had not been received. Note that if the control code is CAN, ESC, or SUB, the sequence in progress is terminated.
The receipt of any 8-bit C1 control character in the range 8/0 to 9/15, inclusive, during the processing of an escape sequence causes the sequence in progress to be terminated. (See subhead 3.6.1.2.4 under Termination Conditions)
Characters from columns 10 to 15 (10/0 to 15/14 inclusive) may occur in escape sequences and have the same interpretation as the character from the corresponding row in columns 02 to 07. Thus, the 8th bit of graphic characters should be ignored when interpreting an escape sequence.
5.2.1 Expansion Escape Sequence (Fe)
An expansion escape sequence is a special 2-character escape sequence ( ESC Fe ), where Fe is in columns 04 and 05 (bit combinations from 4/0 to 5/15 inclusive). Expansion escape sequences are used to expand the 7-bit code table by being equivalent to the 8-bit C1 control code in the row in columns 08 and 09 corresponding to the row of the Fe character.
5.3 Control Sequences
A control sequence is a bit string consisting of two or more bit combinations, beginning with the Control Sequence Introducer (CSI), and that may contain parametric information for the control function.
The general form of a control sequence is:
CSI P..P I..I F
where:
CSI is the introducer character coded as 9/11 in 8-bit environments and the 2-character escape sequence 1/11 5/11 ( ESC [ ) in 7-bit environments.
P..P is called the "parameter string". The minimum length is zero and the maximum length is defined by the implementation. However, all bit combinations are from 3/0 to 3/15 inclusive.
I..I are the intermediate characters that may be used to expand the repertoire of functions beyond the limit of 63 implied by the single final character value.
Intermediate characters for control sequences are bit combinations in the range 2/0 to 2/15 inclusive. If 3/0 to 3/15 occur after the occurrence of one or more intermediate characters, the sequence is invalid. However, the end of the control sequence is still defined by the final character. Interpretation will continue until a valid final character is received.
Conforming implementations shall recognize at least three intermediate characters. If more intermediates than can be recognized are received, the entire sequence shall be ignored, up to and including the final character.
F is a final, function defining character. It is used either by itself or with the intermediate characters (if any) to establish what function is encoded. Final characters are bit combinations in the range 4/0 to 7/14, inclusive.
The occurrence of bit combinations 0/0 to 1/15, inclusive, as well as 7/15 and 15/15 in control sequences, are special conditions that are handled by immediately executing the control function indicated, and continuing processing of the control sequence as if the intervening control code had not been received. Note that if the control code is CAN, ESC, or SUB, the sequence in progress is terminated.
The receipt of any 8-bit C1 control character in the range 8/0 to 9/15 inclusive during the processing of a control sequence causes the sequence in progress to be terminated. (See subhead 3.6.1.2.4 under Termination Conditions)
Characters from columns 10 to 15 (10/0 to 15/14 inclusive) may occur in control sequences and have the same interpretation as the character from the corresponding row in columns 02 to 07. Thus, the 8th bit of graphic characters should be ignored when interpreting a control sequence.
5.3.1 Parameter Values In Control Sequences
A parameter string consists of bit combinations from 3/0 to 3/15 inclusive. The string represents one or more numeric or selective parameter values. The maximum value of each parameter is defined by implementation. A minimum of 16384 decimal (14 bits) is recommended. Parameter values larger than the maximum supported by an implementation should be mapped to the largest value supported (although this is not mandatory).
The maximum number of parameters that can be contained in a single parameter string is also implementation defined; however, support for up to 16 parameters is required for compatibility. Parameters beyond the maximum number supported may be ignored.
Each parameter value consists of zero or more bit combinations from 3/0 to 3/9 inclusive, representing the decimal digits 0 to 9. If more than one parameter value is to be supplied, the parameters are separated from each other by the bit combination 3/11 (ASCII semicolon ";"). The bit combination 3/10 is reserved for future standardization. If 3/10 is received within a parameter string, the entire sequence up to and including the final character shall be ignored. Bit combinations 3/12 through 3/15 are used for private parameter strings (see subhead 3.5.3.4).
In each parameter, leading bit combinations of 3/0 are not significant and may be omitted. A zero length parameter, or one consisting only of 3/0 bit combinations, represents a default whose value depends upon the control function.
5.3.2 Numeric Parameters
Numeric parameters are used for passing numeric values. If more than one parameter value is supplied, the ordering of parameters is significant and must be preserved by the use of additional separators to replace omitted parameter values. A zero or omitted numeric parameter represents a default that can apply to that one parameter or to the entire parameter string, depending on the control function.
5.3.3 Selective Parameters
Selective parameters are used for selecting options from a list. The list of options and corresponding parameter values is defined by the control function. A control sequence with selective parameters is specified as taking either a fixed or variable number of selective parameters.
If a fixed number of selective parameters is specified, the meaning of each parameter is determined from a separate list of values or actions. All of the parameters are required (or are assumed to be defaulted) for the particular control function to take effect.
If a variable number of selective parameters is specified, each parameter selects a particular entry from a single list identified by the control.
In control sequences with a variable number of parameters, the parameters shall be processed sequentially beginning with the first parameter. A control sequence containing more than one such selective parameter shall have the same effect as a corresponding number of separate control sequences, each with a single parameter.
For example, if Select Graphic Rendition (SGR) is sent with the following parameters, the resulting rendition will be negative image, slowly blinking, since the 0 parameter, executed after setting bold and underline, would return the current rendition value to normal.
- 1 (bold)
- 4 (underlined)
- 0 (all attributes off)
- 7 (negative image)
- 5 (slowly blinking)
5.3.4 Private Parameter Strings
If a parameter string begins with a bit combination from 3/12 through 3/15, inclusive, the entire parameter string is subject to private interpretation. This means that the control has a special interpretation that is not specified in national or international standards. If bit combinations 3/12 through 3/15 occur anywhere else in the control sequence other than as the first character of the parameter string, the entire sequence up to and including the final character shall be ignored.
Syntactically, the subsequent processing of private parameter strings is identical to the processing of standard parameter strings.
5.3.5 Examples of Parameter Strings
| Char Form | Column/row Form | Explanation |
|---|---|---|
| 7 | 3/7 | A single parameter value of 7 |
| 0007 | 3/0 3/0 3/0 3/7 | A single parameter value of 7 |
| 98 | 3/9 3/8 | A single parameter value of 98 |
| 4;2 | 3/4 3/11 3/2 | Two parameters with values 4 and 2 |
| ?3 | 3/12 3/3 | A private parameter with value of 3 |
| 2; | 3/2 3/11 | Two parameters with the first having the value 2 and the second having the default value |
| ;5 | 3/11 3/5 | Two parameters with the first having the default value and the second having the value 5 |
| 1;;4 | 3/1 3/11 3/11 3/4 | Three parameters with the first having the value 1, the second having the default value, and the third having the value 4 |
| ?3;4 | 3/15 3/3 3/11 3/4 | A private parameter string containing two parameter values, 3 and 4 |
| 3;?4 | 3/3 3/11 3/15 3/4 | An error. The occurrence of 3/15 as any but the first character of the parameter string invalidates the control sequence. |
5.4 Control Strings
Control strings are a special class of control code extensions that provide a wide range of functions. There are four types of control strings, each of which has the same general structure with its own introducer character and internal variations. The four types and their formats are:
- Application Program Command — APC (9/15) D..D ST (9/12)
- Device Control Strings — DCS (9/0) D..D ST (9/12)
- Operating System Command — OSC (9/13) D..D ST (9/12)
- Privacy Message — PM (9/14) D..D ST (9/12)
where:
APC, DCS, OSC, or PM is the introducer character that starts the control string and determines its type. In 7-⁠bit environments, the introducer control characters are encoded as 1/11 5/15 (ESC _), 1/11 5/0 (ESC P), 1/11 5/13 (ESC ]), and 1/11 5/14 (ESC ^), respectively
D..D is a command string which has a unique format for each control string type. However, the command string must be made up of characters in the range 0/8 to 0/13 inclusive and 2/0 to 7/14 inclusive. The inclusion of C0 Controls 0/8 to 0/13 in control string data is intended for convenience in formating and storing control strings. It is recommended that these characters not affect the interpretation of the control string.
ST is the String Terminator control character (in 7-bit environments ST is coded as ESC \ (1/11 5/12)).
5.4.1 Device Control Strings
The internal format of a Device Control String is:
DCS P..P I..I F D..D ST
where:
DCS is the Device Control String introducer.
P..P is an optional parameter string, identical in syntax to the parameter string of a control sequence.
I..I is zero or more intermediate characters in the range 2/0 to 2/15 inclusive.
F is a final, function defining character, in the range 7/0 to 7/14 inclusive (the same as for private Control Sequences).
D..D is the command string, whose format is determined by the combination of parameters, intermediate characters, and final character that precede it.
ST is the String Terminator control character.
5.4.2 Other Control Strings
Other control string types (Application Program Command, Operating System Command, and Privacy Message) are defined to have the following internal format.
APC I..I F D..D ST
OSC I..I F D..D ST
PM I..I F D..D ST
where:
APC, OSC, or PM is the Control String introducer.
I..I is zero or more intermediate characters in the range 2/0 to 2/15 inclusive.
F is a final, function defining character, in the range 3/0 to 3/15 inclusive (the same as for private Escape Sequences).
D..D is the command string, whose format is determined by the combination of intermediate characters and final character which precede it.
ST is the String Terminator control character.
5.4.3 Character Strings
Future device implementations should treat the SOS C1 control as the start of an unimplemented control string, although this is not mandatory.
A syntax is not yet specified for the interpretation of character strings; the use of SOS and character strings within Digital is reserved for future standardization. Note that ISO may define the inclusion of escape and control sequences inside Character Strings.
5.4.4 Termination Conditions
Control strings will normally terminate upon receipt of a String Terminator (9/12) character. The receipt of the control characters 0/8 through 0/13 is valid within control strings. For backward compatibility, and to minimize the effect of a lost String Terminator, the control codes CAN (1/8), SUB (1/10), ESC (1/11), or any C1 control will also terminate control strings.
Conforming software should not depend on this practice however, and shall only use the String Terminator control function to terminate a control string. Control characters other than those recognized within the command string syntax may be defined to have other meanings in the future. It is recommended that all other control codes not used within a command string be ignored by hardware.
5.4.5 GR Graphic Characters Within Control Strings
GR (8-bit) graphic characters in APC, OSC, and PM control strings will be treated as their 7-bit equivalent (the eighth bit will be ignored).
GR (8-bit) graphic characters are permitted within Device Control Strings, and the graphic character's interpretation will be dependent on the internal control string format. When they occur in the introducer sequence to a Device Control String, the eighth bit will be ignored, and they will be treated as their 7-bit equivalent. (Note that this is the same way 8-bit graphic characters are handled within control sequences.)
5.4.6 Unimplemented Control Strings
The contents of received control strings that are not implemented by the receiving party will be ignored. Therefore, all data (control and graphic characters) from the control string introducer to the string terminator (inclusive) will be discarded without being displayed.
5.5 Parsing Algorithms
This section describes the rules required to correctly parse a 7-⁠bit or 8-bit character stream, separating the control functions from data contained in the stream.
Implementation Notes:
This coding is intended to serve as a guideline to implementors and a clear specification of the parsing rules against which product certification can be performed. The code is typical of actual implementations, but is optimized for architectural clarity. It is recognized that specific implementations may alter the algorithms or program structure to optimize memory or execution speed. Such implementations must not violate the external functionality or rules provided by the parsing algorithms.
VAX-11 C was selected as the implementation language because of its simplicity, portability, and wide use both inside and outside of Digital.
Module Overview:
The parser is broken into modules as follows.
- gparse.h — global include file (must be included by external routines that call the parser)
- lparse.h — local include file (contains definitions used internally by the parser)
- vtparse.c — parse routines
- ptexec.c — parser tester executive
Other modules not shown here include system-dependent character I/⁠O routines and interrupt handling.
5.5.1 C Language Source Code
/******************* module gparse.h ********************
*
* Global #include file for callable re-entrant ANSI parser.
*
* Environment: VAX/VMS
* Author: Peter Sichel 24-Feb-1984
*
* Modification history:
* 13-Nov-1984 P. Sichel
* added external events for control
* string introducers APC, OSC, and PM
* 16-May-1988 P. Sichel
* added parse limits
* changed default stack size to 32
*
*********************************************************/
/* parse limits */
#define MAX_NUM_INTERMEDIATES 3
#define MAX_NUM_PARAMETERS 16
#define MAX_PARAMETER_VALUE 16383
/* parse stack */
#define STACK_SIZE 32
struct parse_stack
{
char index; /* stack pointer */
unsigned char class[STACK_SIZE];
unsigned char value[STACK_SIZE];
unsigned short int data[STACK_SIZE];
};
/* common parse states */
#define SEQ_START 0
#define CON_START 1
/* external parse events */
#define R_PARSE_ERROR 0
#define R_CONTINUE 1
#define R_GRAPHIC 2
#define R_CONTROL 3
#define R_ESC_SEQ 4
#define R_CSI_SEQ 5
#define R_DCS_SEQ 6
#define R_APC_SEQ 7
#define R_OSC_SEQ 8
#define R_PM_SEQ 9
/* e s c a p e s e q u e n c e parser definitions */
/* (includes control character parser also) */
/* parse states */
/* SEQ_START 0 */ /* already defined above */
/* CON_START 1 */ /* already defined above */
#define ES_IN_SEQ 2
#define ES_IGNORE 3
/* c o n t r o l s e q u e n c e parser definitions */
/* parse states */
/* SEQ_START 0 */ /* already defined above */
#define CS_PRIVATE 1
#define CS_PARAM 2 /* parameter value */
#define CS_INTER 3
#define CS_IGNORE 4 /* ignore sequence,
but parse until final */
#define CS_IGNORE_P 5 /* ignore any further parameters,
but accept sequence if otherwise
valid */
/*********************** module lparse.h ***********************
*
* Local #include file for callable re-entrant ANSI parser
*
* Environment: VAX/VMS VAX-11 C V1.2
* Author: Peter Sichel 24-Feb-1984
*
* Modification history:
* 2-May-1984 T. Lasko
* Fixed overlapping #define's in parser states
* 29-May-1984 P. Sichel
* fixed pseq_parse_table to correcly
* ignore invalid sequences
* 1-Jun-1984 P. Sichel
* added state CS_OMIT to indicate
* omitted parameters explicitly
* 16-May-1988 P. Sichel
* removed CS_OMIT
* Added CS_IGNORE_P to ignore parameters
* beyond MAX_NUM_PARAMETERS.
* Added ES_IGNORE to ignore escape sequences
* with more than MAX_NUM_INTERMEDIATES.
* Fixed bug in parse table that would accept
* intermediates from CS_IGNORE state.
* 5-Feb-1989 P. Sichel
* converted parse table data declaration to use
* symbolic constants, and moved to module vtparse.c
*
****************************************************************/
/* state classes - used by parse executive to determine which
parser to invoke */
#define ESEQ 0 /* escape sequence */
#define CSI 1 /* control sequence */
#define DCS 2 /* control sequence */
#define LAST_SEQ 2 /* "in sequence" marker */
#define CON 3 /* control and graphic characters */
/* internal parse events returned by parse_ansi() */
#define PARSE_ERROR 0x00
#define CONTINUE 0x10
#define GRAPHIC 0x20
#define CONTROL 0x30
#define ESC_SEQ 0x40
#define PAR_SEQ 0X50
#define CANCEL 0xD0
#define PARAM 0xE0 /* reduce a numeric parameter */
#define IGNORE 0xF0
/* e s c a p e s e q u e n c e parser definitions */
/* (includes control character parser also) */
/* parse inputs (count by number of states) */
#define ES_CONTROL 0
#define ES_INTER 4
#define ES_FINAL 8
#define ES_GRAPHIC 12
/* c o n t r o l s e q u e n c e parser definitions */
/* parse inputs (count by number of states) */
#define PI_CONTROL 0
#define PI_PRIVATE 6
#define PI_NUMERAL 12
#define PI_SEMICOL 18
#define PI_INTER 24
#define PI_FINAL 30
#define PI_OTHER 36
/****************** module vtparse.c ***************
*
* Callable re-entrant ANSI parser. This module contains
* the entire parser, and the action routines that alter
* the parse state.
*
* Environment: VAX/VMS VAX-11 C V1.2
*
* Author: Peter Sichel 24-Feb-1984
*
* Modified by:
* PAS 30-May-84 added missing "break" to switch case "IGNORE".
* PAS 12-Nov-84 modified eseq_class and pseq_class to
* recognize 0xFF as a control character
* PAS 13-Nov-84 added code to recognize OSC, PM, and APC
* control strings
* PAS 16-May-88 Added code to test for MAX_NUM_INTERMEDIATES.
* Added code to ignore parameters beyond
* MAX_NUM_PARAMETERS.
* Added code to handle parameter values
* larger than MAX_PARAMETER_VALUE.
* Removed distinction between omitted
* and zero parameters.
* Included basic documentation in this file.
* PAS 5-Feb-89 Included parse tables in this module.
*/
/*
Introduction To VTPARSE
VTPARSE is a table-driven, character re-entrant, callable parser
designed to recognize control functions encoded according to the
ANSI syntax for information interchange. The rules for encoding
control functions are defined in several standards including
ANSI 3.41, DEC STD 138-0 and DEC STD 070-3.
VTPARSE accepts one input character at a time (per call), and
recognizes the following catagories of control functions when
they occur in the input stream.
o Graphic Characters
o C0 and C1 Control Characters
o Escape Sequences
o Control Sequences
o Control String Introducer Sequences including:
DCS, OSC, PM, and APC
Interpreting Return Information From parse_ansi
Parse_ansi returns with "event" set to one of the following.
R_PARSE_ERROR parse stack overflow, or software bug
R_CONTINUE no event, continue parsing
R_GRAPHIC recognized a graphic character
R_CONTROL recognized a control character
R_ESC_SEQ recognized an escape sequence
R_CSI_SEQ recognized a control sequence
R_DCS_SEQ recognized a DCS introducer sequence
R_OSC_SEQ recognized a OSC introducer sequence
R_PM_SEQ recognized a PM introducer sequence
R_APC_SEQ recognized a APC introducer sequence
The character or character sequence recognized is on the
"state" stack. Parse_ansi returns two integers pointing to
the first and final characters of the sequence on the stack.
Each stack entry has three fields: a "class" field, a "value"
field, and a "data" field. The possible values for these fields
are defined in the include files "gparse.h" and "lparse.h".
The "class" field is used internally by the parser to determine
which subparser to invoke (that is, the parse table to use). To
keep the tables reasonably small, a separate table is used for
parsing parameter sequences.
The "value" field is used by the parser to maintain its current
state. The parser is a table driven finite state automata,
where the next state and action are a function of the current
state and input. The "value" field of the parse stack provides
a history of what states the parser has been in and is useful
for interpreting the contents of the parse stack. The "value"
field may be used to identify the contents of the "data" field
except for the final character of a sequence. The final "value"
is usually meaningless because when a sequence is recognized,
it is removed from the stack eliminating the need for a parse
state. A single graphic or control character is considered both
the start and final character of a sequence.
The "data" field contains the actual character data input to the
parser or a number of characters in reduced form. Examples of
reduced forms are a single C1 control replacing an Fe sequence
or a complete parameter value replacing a number of individual
parameter characters. Reduced forms will always be identified
by the contents of the "value" field.
Examples of typical stack data are:
value data
---------- --------
final -> CON_START 41 'A' event = R_GRAPHIC
(the letter "A")
final -> CON_START 0D event = R_CONTROL
(carriage return)
final -> CON_START 41 'A' event = R_ESC_SEQ
ES_IN_SEQ 28 '(' (designate UK into G0)
start -> SEQ_START 1B ESC
final -> CS_IGNORE 68 'h' event = R_CSI_SEQ
CS_PARAM 3 parameter value 3
CS_PRIVATE 3F '?' DEC private char
start -> SEQ_START 9B CSI (set 132 col mode)
final -> CS_IGNORE 72 'r' event = R_CSI_SEQ
CS_PARAM 14 parameter value 14(hex)
CS_PARAM 0 zero or omitted parameter
start -> SEQ_START 9B CSI (set scroll region from
line 1 to line 18)
final -> CS_IGNORE 72 'p' event = R_DCS_SEQ
start -> SEQ_START 90 DCS (begin REGIS DCS)
final -> CON_START 9C ST event = R_CONTROL
(string terminator)
Errors And Exceptions
The parser ignores any invalid sequences it receives.
No control function is recognized, and the parser resynchronizes
the input stream according to the rules for error recovery in
DEC STD 138-0.
To summarize:
o ESC restarts any escape, control, or control string
introducer sequence in progress.
o CAN and SUB immediately cancel any escape, control, or
control string introducer sequence in progress. SUB is
recognized as a C0 control if no sequence is in
progress.
o All other C0 controls are immediately recognized within
escape, control, or control string introducer sequences.
The escape, control, or control string introducer
sequence continues where it left off.
o C1 controls immediately cancel any escape, control, or
control string introducer sequence in progress. The C1
control is then recognized normally. This is for 7-bit
compatibility where C1 controls are represented by two
character Fe escape sequences.
Two character Fe escape sequences are converted to C1
controls by the parser.
o Within escape, control, and control string introducer
sequences, eight-bit graphic codes (GR set) are
truncated to seven-bit codes.
o If a private parameter character (<, =, >, ?) occurs
after the first parameter, the entire sequence will be
ignored up to and including its final character.
o If a parameter character occurs after the first
intermediate character, the entire sequence will be
ignored up to and including its final character.
o The parser recognizes parameter values up to
16383 (14 bits) as specified by the constant
MAX_PARAMETER_VALUE in "gparse.h". If a parameter
exceeds the maximum value, the parameter will be set
to the maximum value.
o The parser recognizes up to 16 parameters in a
single parameter sequence as specified by the
constant MAX_NUM_PARAMETERS in "gparse.h". If more
than MAX_NUM_PARAMETERS are received, parameters
beyond the maximum number are ignored and the "value"
field for the last parameter will be set to
"CS_IGNORE_P" (this may be used to detect that
parametershave been ignored). The sequence will
still be recognized if it is otherwise valid.
o The parser will recognize up to three intermediate
characters in a single escape, control, or introducer
sequence specified by the constant MAX_NUM_INTERMEDIATES
in "gparse.h". If more than MAX_NUM_INTERMEDIATES are
received, the entire sequence will be ignored up to and
including its final character.
o DCS introducer sequences are parsed according to the
rules for control sequences. APC, OSC, and PM
introducer sequences are parsed according to the rules
for escape sequences. The parser recognizes the
introducer sequence upon receiving a valid final
character. The parser does not keep track of whether
a control string is in progress. Therefore it is
possible to receive control codes, escape sequences,
and control sequences within a control string. Handling
of control strings must be performed at a higher level
than the parser.
Each intermediate character requires one stack entry. Each
parameter value also requires one stack entry. The default stack
size of 32 is sufficient to hold a sequence starting character, a
private parameter character, 16 parameters, 3 intermediates, and
still recognize nested C0 control characters. If the maximum
number of parameters or intermediates are increased, the stack
size should be increased accordingly. If the stack overflows,
the parser will re-initialize the stack, and return with event
PARSE_ERROR.
*/
#include "gparse.h" /* global parse definitions */
#include "lparse.h" /* local parse definitions */
/* escape sequence parse table */
/* eseq_parse_table[input+from_state] ==> action,to_state */
char eseq_parse_table[16] =
{
/* input: ES_CONTROL */
/* from_state action to_state */
/* -----------------------------------*/
/* SEQ_START */ CONTROL | ES_IN_SEQ,
/* CON_START */ CONTROL | CON_START,
/* ES_IN_SEQ */ CONTROL | ES_IN_SEQ,
/* ES_IGNORE */ CONTROL | ES_IGNORE,
/* input: ES_INTER */
/* from_state action to_state */
/* -----------------------------------*/
/* SEQ_START */ CONTINUE | ES_IN_SEQ,
/* CON_START */ GRAPHIC | CON_START,
/* ES_IN_SEQ */ CONTINUE | ES_IN_SEQ,
/* ES_IGNORE */ IGNORE | ES_IGNORE,
/* input: ES_FINAL */
/* from_state action to_state */
/* -----------------------------------*/
/* SEQ_START */ ESC_SEQ | CON_START,
/* CON_START */ GRAPHIC | CON_START,
/* ES_IN_SEQ */ ESC_SEQ | CON_START,
/* ES_IGNORE */ CANCEL | ES_IGNORE,
/* input: ES_GRPAHIC */
/* from_state action to_state */
/* -----------------------------------*/
/* SEQ_START */ PARSE_ERROR | ES_IN_SEQ,
/* CON_START */ GRAPHIC | CON_START,
/* ES_IN_SEQ */ PARSE_ERROR | ES_IN_SEQ,
/* ES_IGNORE */ PARSE_ERROR | ES_IGNORE
};
/* control sequense parse table */
/* pseq_parse_table[input+from_state] ==> action,to_state */
char pseq_parse_table[42] =
{
/* input: PI_CONTROL */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ CONTROL | CS_IGNORE,
/* CS_PRIVATE */ CONTROL | CS_IGNORE,
/* CS_PARAM */ CONTROL | CS_IGNORE,
/* CS_INTER */ CONTROL | CS_IGNORE,
/* CS_IGNORE */ CONTROL | CS_IGNORE,
/* CS_IGNORE_P */ CONTROL | CS_IGNORE_P,
/* input: PI_PRIVATE */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ CONTINUE | CS_PRIVATE,
/* CS_PRIVATE */ CONTINUE | CS_IGNORE,
/* CS_PARAM */ CONTINUE | CS_IGNORE,
/* CS_INTER */ CONTINUE | CS_IGNORE,
/* CS_IGNORE */ IGNORE | CS_IGNORE,
/* CS_IGNORE_P */ IGNORE | CS_IGNORE,
/* input: PI_NUMERAL */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ PARAM | CS_PARAM,
/* CS_PRIVATE */ PARAM | CS_PARAM,
/* CS_PARAM */ PARAM | CS_PARAM,
/* CS_INTER */ CONTINUE | CS_IGNORE,
/* CS_IGNORE */ IGNORE | CS_IGNORE,
/* CS_IGNORE_P */ IGNORE | CS_IGNORE_P,
/* input: PI_SEMICOL */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ PARAM | CS_PARAM,
/* CS_PRIVATE */ PARAM | CS_PARAM,
/* CS_PARAM */ PARAM | CS_PARAM,
/* CS_INTER */ CONTINUE | CS_IGNORE,
/* CS_IGNORE */ IGNORE | CS_IGNORE,
/* CS_IGNORE_P */ IGNORE | CS_IGNORE_P,
/* input: PI_INTER */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ CONTINUE | CS_INTER,
/* CS_PRIVATE */ CONTINUE | CS_INTER,
/* CS_PARAM */ CONTINUE | CS_INTER,
/* CS_INTER */ CONTINUE | CS_INTER,
/* CS_IGNORE */ IGNORE | CS_IGNORE,
/* CS_IGNORE_P */ CONTINUE | CS_INTER,
/* input: PI_FINAL */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ PAR_SEQ | CS_IGNORE,
/* CS_PRIVATE */ PAR_SEQ | CS_IGNORE,
/* CS_PARAM */ PAR_SEQ | CS_IGNORE,
/* CS_INTER */ PAR_SEQ | CS_IGNORE,
/* CS_IGNORE */ CANCEL | CS_IGNORE,
/* CS_IGNORE_P */ PAR_SEQ | CS_IGNORE,
/* input: PI_OTHER */
/* from_state action to_state */
/* ---------------------------------------*/
/* SEQ_START */ CONTINUE | CS_IGNORE,
/* CS_PRIVATE */ CONTINUE | CS_IGNORE,
/* CS_PARAM */ CONTINUE | CS_IGNORE,
/* CS_INTER */ CONTINUE | CS_IGNORE,
/* CS_IGNORE */ IGNORE | CS_IGNORE,
/* CS_IGNORE_P */ CONTINUE | CS_IGNORE
};
/* shorthand for "Stack Pointer" of parse stack */
#define SP state->index
/*************************************
*
* parse_init - initialize parse state
*
*************************************/
parse_init(state)
struct parse_stack *state;
{
state->index = 0:
state->class[0] = CON;
state->value[0] = CON_START;
return(0);
}
/*******************************************************
*
* parse_ansi - callable re-entrant ansi parser executive
*
********************************************************/
parse_ansi(c, state, event, start, final)
struct parse_stack *state; /* address of parse stack structure */
int c; /* input character */
int *event; /* event recognized (by ref) */
int *start; /* stack index of first char of event (by ref) */
int *final; /* stack index of final char of event (by ref) */
{
int action, i;
/*..............................................*/
/* if in sequence, convert 8 bit graphics to 7 bits */
if (state->class[SP] <= LAST_SEQ)
if (c >= 0xA0) c &= 0x7F;
/* invoke appropriate parser based on state class */
switch (state->class[SP])
{
case CON:
/* parse graphic and CONtrol characters */
action = parse(state, c, eseq_class(c), eseq_parse_table);
break;
case ESEQ:
/* parse escape sequences */
action = parse(state, c, eseq_class(c), eseq_parse_table);
/* check for too many intermediates */
i = 0;
while (state->value[SP-i] == ES_IN_SEQ)
{
i++;
if (i > MAX_NUM_INTERMEDIATES)
{
/* ignore sequence (but parse until final) */
state->value[SP] = ES_IGNORE;
}
}
break;
case CSI:
case DCS:
/* parse parameter sequence */
action = parse(state, c, pseq_class(c), pseq_parse_table);
/* check for too many intermediates */
i = 0;
while (state->value[SP-i] == CS_INTER)
{
i++;
if (i > MAX_NUM_INTERMEDIATES)
{
/* ignore sequence (but parse until final) */
state->value[SP] = CS_IGNORE;
}
}
break;
}
/* process recognized events */
switch (action)
{
case CONTINUE:
*event = R_CONTINUE;
break;
case GRAPHIC:
*event = R_GRAPHIC;
*start = SP;
*final = SP;
SP -= 1;
break;
case CONTROL:
pcontrol(state, event, start, final);
break;
case ESC_SEQ:
pescseq(state, event, start, final);
break;
case PAR_SEQ:
*final = SP;
/* find start of sequence */
*start = SP;
while (state->value[*start] != SEQ_START) *start -= 1;
switch (state->data[*start])
{
case 0x9B: *event = R_CSI_SEQ; break;
case 0x90: *event = R_DCS_SEQ; break;
default: *event = R_PARSE_ERROR; break;
}
/* remove seq from parse stack,
and return to previous parser */
SP = *start - 1;
break;
case PARAM:
/* input was either a numeral, or a semicolon,
reduce parameter chars to parameter value
if current char is a numeral then
if prev is a value, mul by 10, add current,
range check.
else store current as a value.
else if current is a semicolon
store value of zero
if prev is not a value,
advance stack and store a value of zero.
finally, check for too many parameters. */
*event = R_CONTINUE;
i = SP; /* remember stack pointer */
if (state->data[SP] != 0x3B)
{ /* numeral */
if (state->value[SP-1] == CS_PARAM)
{
SP -= 1;
if (state->data[SP] > MAX_PARAMETER_VALUE/10)
state->data[SP] = MAX_PARAMETER_VALUE;
else
{
state->data[SP] *= 10;
state->data[SP] += state->data[SP+1] - 0x30;
if (state->data[SP] > MAX_PARAMETER_VALUE)
state->data[SP] = MAX_PARAMETER_VALUE;
}
}
else
state->data[SP] -= 0x30;
}
else
{ /* semicolon */
state->data[SP] = 0;
if (state->value[SP-1] != CS_PARAM)
{
SP += 1;
state->class[SP] = state->class[SP-1];
state->value[SP] = CS_PARAM;
state->data[SP] = 0;
}
}
/* check for too many parameters */
if (SP >= i) /* did we add a parameter? */
{
i = 0;
while (state->value[SP-i] == CS_PARAM)
{
i++;
if (i > MAX_NUM_PARAMETERS)
{
/* ignore last parameter */
SP -= 1;
/* ignore any further parameters */
state->value[SP] = CS_IGNORE_P;
}
}
}
break;
case CANCEL:
if (state->class[SP] <= LAST_SEQ)
{
while (state->value[SP] != SEQ_START) SP -= 1;
SP -= 1;
}
*event = R_CONTINUE;
break;
case IGNORE:
*event = R_CONTINUE;
SP -= 1;
break;
default:
*event = R_PARSE_ERROR;
parse_init(state); /* re-initialize */
break;
} /* end switch event */
return(*event);
} /* end routine parse_ansi */
/*************************************************************
*
* eseq_class - return escape sequence parser input class
* of given character.
*
**************************************************************/
eseq_class(c)
int c;
{
int c_class;
/*.....................*/
/* determine character class */
if (0x20 <= c && c <= 0x2F)
c_class = ES_INTER;
else if ( (0x00 <= c && c <= 0x1F) ||
(0x7F <= c && c <= 0x9F) ||
(c == 0xFF) )
c_class = ES_CONTROL;
else if (0x30 <= c && c <= 0x7E)
c_class = ES_FINAL;
else
c_class = ES_GRAPHIC;
return(c_class);
}
/*************************************************************
*
* pseq_class - return parameter sequence parser input class of
* given character.
*
**************************************************************/
pseq_class(c)
int c;
{
int pi_class;
/*.....................*/
/* determine character class */
if (0x30 <= c && c <= 0x39)
pi_class = PI_NUMERAL;
else if (c == 0x3B)
pi_class = PI_SEMICOL;
else if (0x20 <= c && c <= 0x2F)
pi_class = PI_INTER;
else if (0x3C <= c && c <= 0x3F)
pi_class = PI_PRIVATE;
else if (0x40 <= c && c <= 0x7E)
pi_class = PI_FINAL;
else if ( (0x00 <= c && c <= 0x1F) ||
(0x7F <= c && c <= 0x9F) ||
(c == 0xFF) )
pi_class = PI_CONTROL;
else
pi_class = PI_OTHER;
return(pi_class);
}
/*******************************************
*
* parse - table driven parse routine
*
* returns the following events:
* PARSE_ERROR
* CONTINUE
* GRAPHIC
* CONTROL
* ESC_SEQ
* CON_SEQ
* PARAM
* CANCEL
* IGNORE
*
* The parser is a table driven finite state automata,
* where the next state and action are a function of
* the current state and input.
*
*********************************************/
parse(state, c, c_class, parse_table)
struct parse_stack *state; /* parse stack */
int c; /* input character */
int c_class; /* input class */
char parse_table[]; /* parse table */
{
int next_action;
int current_state;
int next_state;
/*...................................*/
/* get next state */
current_state = state->value[SP];
next_state = parse_table[c_class + current_state] & 0x0F;
/* get action */
next_action = parse_table[c_class + current_state] & 0xF0;
/* default action */
if (SP >= STACK_SIZE) return(PARSE_ERROR);
SP += 1;
state->class[SP] = state->class[SP-1];
state->value[SP] = next_state;
state->data[SP] = c;
/* return action */
return(next_action);
} /* end routine parse */
/*****************************************
*
* pcontrol - process controls that alter
* the parse state.
*
******************************************/
pcontrol(state, event, start, final)
struct parse_stack *state;
int *event;
int *start;
int *final;
{
int sp, code;
/*..................*/
sp = state->index;
code = state->data[sp];
/* ESC */
if (code == 0x1B)
{
/* if already in escape or control sequence, restart it */
if (state->class[sp] <= LAST_SEQ)
while (state->value[sp] != SEQ_START) sp -= 1;
state->class[sp] = ESEQ; /* switch to escape seq parser */
state->value[sp] = SEQ_START;
state->data[sp] = 0x1B;
state->index = sp;
*event = R_CONTINUE;
return(0);
}
/* CAN */
if (code == 0x18)
{
/* if already in escape or control sequence, cancel it */
if (state->class[sp] <= LAST_SEQ)
{
while (state->value[sp] != SEQ_START) sp -= 1;
}
state->index = sp - 1;
*event = R_CONTINUE;
return(0);
}
/* SUB */
if (code == 0x1A)
{
/* if already in escape or control sequence, cancel it */
if (state->class[sp] <= LAST_SEQ)
{
while (state->value[sp] != SEQ_START) sp -= 1;
state->index = sp-1;
*event = R_CONTINUE;
}
else
{ /* not in sequence, recognize SUB */
*event = R_CONTROL;
*start = sp;
*final = sp;
state->index = sp;
}
return(0);
}
/* is it a C1 control ? */
if (code > 0x7F)
{
/* if already in escape or control sequence, cancel it */
if (state->class[sp] <= LAST_SEQ)
while (state->value[sp] != SEQ_START) sp -= 1;
/* CSI */
if (code == 0x9B)
{
/* switch to parameter seq parser */
state->class[sp] = CSI;
state->value[sp] = SEQ_START;
state->data[sp] = code;
state->index = sp;
*event = R_CONTINUE;
return(0);
}
/* DCS */
if (code == 0x90)
{
/* switch to parameter seq parser */
state->class[sp] = DCS;
state->value[sp] = SEQ_START;
state->data[sp] = code;
state->index = sp;
*event = R_CONTINUE;
return(0);
}
/* OSC, PM, APC */
if ( (code == 0x9D) || (code == 0x9E) || (code == 0x9F) )
{
/* switch to escape sequence parser */
state->class[sp] = ESEQ;
state->value[sp] = SEQ_START;
state->data[sp] = code;
state->index = sp;
*event = R_CONTINUE;
return(0);
}
} /* end C1 control */
/* recognize other controls */
*event = R_CONTROL;
state->data[sp] = code;
*start = sp;
*final = sp;
/* remove control character from parse stack */
state->index = sp - 1;
return(0);
}
/*************************************
*
* pescseq - process escape sequences
* that alter the parse state.
*
**************************************/
pescseq(state, event, start, final)
struct parse_stack *state;
int *event;
int *start;
int *final;
{
int sp;
/*.....................*/
sp = state->index;
/* two character escape sequence ? */
if (state->data[sp-1] == 0x1B)
{
/* convert 7-bit Fe sequences to C1 controls */
if ((0x40 <= state->data[sp]) && (state->data[sp] <= 0x5F))
{
/* store C1 control */
state->data[sp-1] = state->data[sp] + 0x40;
state->index = sp-1;
/* steal code from pcontrol */
pcontrol(state, event, start, final);
return(0);
}
}
/* recognize other escape sequences */
/* find start of sequence */
while (state->value[sp] != SEQ_START) sp -= 1;
*start = sp;
*final = state->index;
switch (state->data[*start])
{
case 0x1B: *event = R_ESC_SEQ; break;
case 0x9D: *event = R_OSC_SEQ; break;
case 0x9E: *event = R_PM_SEQ; break;
case 0x9F: *event = R_APC_SEQ; break;
default: *event = R_PARSE_ERROR; break;
}
state->index = *start - 1; /* remove seq from parse stack */
return(0);
} /* end routine pescseq */
/********************** module ptexec.c **************
*
* This module contains the parser test executive.
* It reads characters from the keyboard and dumps the
* parse stack when a control function is recognized.
*
* Environment: VAX/VMS
*
* Author: Peter Sichel 24-Feb-1984
*
* Modification history
* 8-May-1984 T. Lasko
* Made ^Y (power off) cleaner.
* 9-MAY-1984 T. Lasko
* Fixed several protocols.
* 13-Nov-1984 P. Sichel
* Added OSC, PM, and APC control strings
* 9-May-1988 P. Sichel
* Cosmetic changes for inclusion in VSRM
*/
#include <stdio.h>
#include "gparse.h" /* global parse definitions */
#include "lparse.h" /* local parse definitions */
/* global storage */
extern int poweron;
/* module wide storage */
struct parse_stack kbd_state;
static char *eseq_state[3] =
{
"SEQ_START",
"CON_START",
"ES_IN_SEQ"
};
static char *pseq_state[6] =
{
"SEQ_START",
"CS_PRIVATE",
"CS_PARAM",
"CS_INTER",
"CS_IGNORE",
"CS_IGNORE_P"
};
/*******************************************
* ptstart() -
*
* This is the startup routine for the parser tester.
* It simply initializes the internal state and the terminal
* screen, then calls the executive loop, which returns when
* we give it a ^Y (power turns off).
**********************************************/
ptstart()
{
unsigned short n;
/* erase screen, move cursor to home */
printf("\33[2J\33[H");
printf("A N S I P a r s e r T e s t e r\n");
printf(" Press ^Y to exit \n\n");
parse_init(&kbd_state);
poweron = 1; /* ready....*/
set_passall();
execloop(); /* go! */
set_nopassall();
return(0); /* when power off...return */
}
/*******************************************
*
* execloop - parser test executive
*
********************************************/
execloop()
{
int c;
int event, start, final, i;
/*..............................................*/
while (poweron)
{
/* get character from KEYBOARD and parse it */
c = readkbd();
parse_ansi(c, &kbd_state, &event, &start, &final);
/* process recognized events */
switch (event)
{
case R_CONTINUE:
break;
case R_GRAPHIC:
printf("\nR_GRAPHIC:");
ptdump(&kbd_state, start, final);
break;
case R_CONTROL:
printf("\nR_CONTROL:");
ptdump(&kbd_state, start, final);
break;
case R_ESC_SEQ:
printf("\nR_ESC_SEQ:");
ptdump(&kbd_state, start, final);
break;
case R_CSI_SEQ:
printf("\nR_CSI_SEQ:");
ptdump(&kbd_state, start, final);
break;
case R_DCS_SEQ:
printf("\nR_DCS_SEQ:");
ptdump(&kbd_state, start, final);
break;
case R_OSC_SEQ:
printf("\nR_OSC_SEQ:");
ptdump(&kbd_state, start, final);
break;
case R_PM_SEQ:
printf("\nR_PM_SEQ:");
ptdump(&kbd_state, start, final);
break;
case R_APC_SEQ:
printf("\nR_APC_SEQ:");
ptdump(&kbd_state, start, final);
break;
default:
printf("\nR_PARSE_ERROR:");
ptdump(&kbd_state, start, final);
break;
} /* end switch case */
} /* while (poweron) */
return(0);
} /* end routine execloop */
/**********************************
*
* ptdump - parser test stack dump
*
***********************************/
ptdump( state, start, final )
struct parse_stack *state;
int start, final;
{
int i;
for (i=start; i<=final; i++)
{
printf("\n ");
switch (state->class[i])
{
case ESEQ:
printf("ESEQ %-11s", eseq_state[state->value[i]]);
break;
case CSI:
printf("CSI %-11s", pseq_state[state->value[i]]);
break;
case DCS:
printf("DCS %-11s", pseq_state[state->value[i]]);
break;
case CON:
printf("CON %-11s", eseq_state[state->value[i]]);
break;
default:
printf("??? %02x ", state->value[i]);
}
if (state->data[i] < 16) printf(" %02x ", state->data[i]);
else printf("%4x ", state->data[i]);
if ((0x1F < state->data[i]) && (state->data[i] < 0x7F))
putchar((int)state->data[i]);
}
return(0);
};
6 Graphic Code Extension Techniques
In a 7-bit environment, the basic graphics' portion of the code table consists of a single 94- or 96-character set. In an 8-bit environment, this is supplemented with an additional 94- or 96-⁠character set, and the two sets are referred to as the GL set (left half graphics, corresponding to the single set in 7-bits), and the GR set (right half). In both environments, the graphic codes in the table can be further extended by the designation and invocation of a potentially unlimited repertory of graphics sets. This is implemented by the provision of four sets of 94 or 96 graphic characters, referred to as the G0, G1, G2, and G3 sets.
Character sets may be designated to any of the four G-sets, which may be currently or subsequently invoked into either the GL or GR positions in the code table.
6.1 Description Of Shift Functions
Shift functions are used to invoke one of the G-sets into the left or right half side of the code table. There are two kinds of shift functions: locking shifts and single shifts. Locking shifts cause a G-set to be permanently invoked into the code table, where it will remain until another shift function occurs to replace it. Single shifts cause a G-set to be invoked only for the occurrence of the single character code following the single shift control in the code stream, after which the table reverts to its previous state before the shift occurred.
For example, if on power-up the ASCII character set is designated into G0 and G1, and G0 is invoked into GL, then any graphic codes in the GL portion of the table (2/1 through 7/14) will cause an ASCII character to be generated. Subsequently, the Line Drawing character set may be designated into G1 to replace ASCII in that G-set. No visible effect will occur until G1 is invoked into GL using a shift function. Thereafter, any GL graphic codes received will cause Line Drawing characters to be displayed.
ASCII_C Supplemental_C
+--+ +--+
| | | |
| | | |
| | | | Control Sets
| | | |
| | | |
+--+ +--+
v v designate
| | & invoke: C -> C0 = ESC ! F
v v C -> C1 = ESC " F
+--++-----+--++-----+
| ++ | ++ |
| | | | |
|C0| GL |C1| GR | In Use Table
| | | | |
| | ++ | ++
+--+-----++--+-----++
^ ^ ^
| | | invoke: G0 -> GL = LS0 (SI)
+--------+ +---+----+ G1 -> GL = LS1 (SO)
| | G2 -> GL = LS2, SS2
| +---+-----+---------+ G3 -> GL = LS3, SS3
| | | | G1 -> GR = LS1R
^ ^ ^ ^ G2 -> GR = LS2R
+-----+ ++-----+ ++-----+ ++-----+ G3 -> GR = LS3R
++ | ++ | ++ | ++ |
| | | | | | | |
| G0 | | G1 | | G2 | | G3 | Designated
| | | | | | | | Graphic Sets
| ++ | ++ | ++ | ++
+-----+ +-----++ +-----++ +-----++
^ ^ ^ ^
| | | |
+---------+----+----+---------+
| designate: ESC I F
|
| 94 Chars: 96 Chars:
+---------+---------+---- . . . ---+ G0 = (
| | | | G1 = ) G1 = _
^ ^ ^ ^ G2 = * G2 = .
+-----+ +------+ ++-----+ ++-----+ G3 = + G3 = /
++ | | | ++ | ++ |
| | | | | | | | ASCII_G = B
| 94 | | 96 | | | . . . | | UPSS = <
| Char | | Char | | | | | Line_Drawing = 0
| ++ | | | ++ | ++ DEC_Supplemental = % 5
+-----+ +------+ +-----++ +-----++ ISO_Latin-1 = A (96)
DRCS (as defined,
Repertory of Graphic Character Sets 94 or 96)
6.1.1 Locking Shifts
Conforming terminal products will provide the following locking shift functions in Level 1 operation.
| Code | Name | G-set invoked | Table position |
|---|---|---|---|
| LS0 * | Locking Shift Zero | G0 | GL |
| LS1 * | Locking Shift One | G1 | GL |
| LS2 | Locking Shift Two | G2 | GL |
| LS3 | Locking Shift Three | G3 | GL |
| * Note - The functions Locking Shift Zero and Locking Shift One have been previously referred to as Shift In (SI) and Shift Out (SO). The effect of executing these controls has not been changed. | |||
Conforming terminals will provide the following additional locking shift functions in Level 2 operation.
| Code | Name | G-set invoked | Table position |
|---|---|---|---|
| LS1R | Locking Shift One Right | G1 | GR |
| LS2R | Locking Shift Two Right | G2 | GR |
| LS3R | Locking Shift Three Right | G3 | GR |
The following bit combinations are not affected by the use of the locking shifts.
Those corresponding to control characters in columns 00, 01, 08, and 09
Those corresponding to the character Space (SP) in position 2/0, and Delete (DEL) in position 7/15 when a 94-character set is invoked into GL
Those corresponding to positions 10/0 and 15/15 when a 94-character set is invoked into GR
Those included in any escape or control sequence (see notes to subheadings 3.5.2 Escape Sequences and 3.5.3 Control Sequences for a full explanation of the use of bit combinations within escape and control sequences)
The bit combination following a single shift function (SS2 or SS3)
6.1.2 Single Shift Functions
Conforming terminal products will provide the following single shift functions in both 7-bit and 8-bit environments.
| Code | Name | G-set invoked | Table position |
|---|---|---|---|
| SS2 | Single Shift Two | G2 | GL |
| SS3 | Single Shift Three | G3 | GL |
6.2 Designating Character Sets
Each terminal shall maintain a repertory of available character sets, which may be designated to any of the four G-sets (note there is no direct way to designate a 96 character set into G0). Once a character set is designated to a G-set, it remains in that set until explicitly replaced by another character set designator. If the G-set is invoked into the code table at the time the character set is designated, it immediately replaces the existing set in the code table.
Note: For a complete description of conforming software use of the designating and invoking controls, see DEC STD 070-1. DEC STD 70 addresses conformance of software when communicating directly with a presentation device, or when writing data to a file that is intended only for subsequent transmission to a presentation device. It does not address conformance of software when processing terminal input or when writing data to a file that is intended for subsequent processing by application software.
DEC STD 169-0 DEC Standard Coded Graphic Character Sets for Hardware and Software requires that when data is intended for subsequent processing conforming software shall not use either locking shift or single shift functions. This requirement is in fact a subset of the conformance requirements defined in this document, therefore the two documents do conflict.
6.3 The User Preference Supplemental Set (Upss)
The User Preference Supplemental Set is a logical character set name similar in concept to a G-set (G0-G3) but at the next higher level. The UPSS allows one level of software indirection for designating supplemental character sets. The UPSS is designated and invoked like any other character set, but the character set used can be selected by the user as a SETUP option or by host control function in response to a user request.
The UPSS was introduced to facilitate migration from DEC-MCS to ISO Latin-1. Software applications that do not need to be concerned with which supplemental character set is used can defer the choice of a specific supplemental set to the user, thus not imposing a choice that might interfere with the customers migration plan. The designating sequence previously used for DEC Supplemental was changed to designate the UPSS, providing automatic transparent migration from DEC MCS to ISO Latin-1 for existing applications as soon as terminal devices can support ISO Latin-1.
The concept of a User Preference Supplemental Set also accomodates existing CSS Specials that used the old DEC Supplemental designating sequence to designate a local country specific character set.
Support for the UPSS is part of the 8-bit Interface Architecture Extension to Level 2, and required for conformance to Level 3. As a minimum, the UPSS must be selectable between DEC Supplemental and ISO Latin-1 supplemental. The UPSS also establishes the initial supplemental set for display (defaults to G2 on power-up), and determines the keyboard supplemental character set when 8-bit multinational characters are enabled. See DEC STD 070-6.
typedef enum /* upss_type */
{
UPSS_DEC_SUPPLEMENTAL_G, UPSS_ISO_LATIN1_SUPPLEMENTAL_G
} upss_type;
upss_type upss;
6.4 Default Designation And Invocation
The following assignments will apply to the power-on and soft reset states of the terminal.
6.4.1 Level 1
In Level 1 operation, the default character set designations will be ASCII in G0, G1, G2, and G3. Furthermore, the G0 set (ASCII) will be invoked into the GL position of the In Use Table. Level 1 operation is 7-bits only.
6.4.2 Level 2 (without 8-bit Interface Architecture Extension)
In Level 2 operation, the default character set designations will be ASCII in G0 and G1, and the DEC Supplemental graphics set in G2 and G3. Furthermore, the G0 set (ASCII) will be invoked into the GL position of the In Use Table, and the G2 set (DEC Supplemental graphics) will be invoked into the GR position of the In Use Table.
6.4.3 Level 3 (or Level 2 with 8-bit Interface Architecture Extension)
In Level 3 operation, the default character set designations will be ASCII in G0 and G1, and the User Preference Supplemental Set (UPSS) in G2 and G3. Furthermore, the G0 set (ASCII) will be invoked into the GL position of the In Use Table, and the G2 set (UPSS, typically DEC Supplemental or ISO Latin-1 supplemental) will be invoked into the GR position of the In Use Table.
Level 3 (or Level 2 with the 8-bit Interface Architecture Extension) also recognizes the "Announce Subset Of Code Extension Facilities" defined in ISO 4873 which re-initialize the designated and invoked character sets as described later in this chapter.
6.4.4 NRCS Extension
When the NRCS Extension is present, ASCII may be replaced with a National Replacement Character set as a Set-Up option. In this case, the default character set designations will be the NRCS in G0, G1, G2, and G3, with G0 in GL. National Replacement Character Sets are intended for backward compatibility and may be used as above in Level 1, Level 2, and Level 3 by selecting "7-bit NRCS Characters" in Set-Up or setting DECNRCM (National Replacement Character set Mode) from the host. Setting this mode has the side effect of resetting the display character sets to their default state as described above. Note that the NRC Mode is 7-bits only, GR is not available. The actual NRC set used is determined by the "Keyboard Dialect", and the selection of "Typewriter" or "Data Processing" keys. See DEC STD 070-6 for more information.
7 State Descriptions
7.1 Control Sets
At the present time the C0 and C1 control sets are fixed as the ANSI control sets defined in ANSI X3.4 - 1986 and ISO 6429: 1988.
typedef enum /* c0_control_set_type */
{
ASCII_C
} c0_control_set_type;
typedef enum /* c1_control_set_type */
{
SUPPLEMENTAL_C
} c1_control_set_type;
7.2 G-Sets
Graphic character sets are defined for each service class. (See DEC STD 070-5 Video Systems Reference Manual - Character Cell Display for a complete description of the available character sets and designating sequences.) The actual character sets available will vary for different conformance levels and extensions (NRCS, 8-bit IA, TCS) ). Four character sets may be designated at any time, each into one of the four G-sets, which may be subsequently invoked into the In Use Table.
typedef enum /* graphic_character_set_type */
{
ASCII_G,
LINE_DRAWING_G,
DEC_SUPPLEMENTAL_G,
ISO_LATIN1_SUPPLEMENTAL_G, /* 8-bit IA */
UPSS_G /* 8-bit IA */
} graphic_character_set_type;
graphic_character_set_type designated_graphic_sets[4];
7.3 In Use Table
Mapping of received control functions and graphic character data is provided by the 8-bit code table, as described above. Since the 8-bit table is a superset of the 7-bit table, all references will be to the 8-bit table in both environments.
typedef enum /* gset_name_type */
{
G0, G1, G2, G3
} gset_name_type;
typedef struct /* in_use_table_type */
{
c0_control_set_type c0;
graphic_character_set_type gl;
gset_name_type invoked_gl;
c1_control_set_type c1;
graphic_character_set_type gr;
gset_name_type invoked_gr;
} in_use_table_type;
in_use_table_type in_use_table;
7.4 Single Shift Functions
Since single shift controls affect the processing of the next graphic character in the received data stream, it is necessary to retain their occurrence until subsequent processing occurs.
typedef enum /* single_shift_type */
{
NONE, SS2, SS3
} single_shift_type;
single_shift_type single_shift;
7.5 Environments
The environment of the host port can be selected for either a seven or eight bit data path in set-up. The environment of the printer port can be selected independently of the host environment as a set-up function. See DEC STD 070-7 Video Systems Reference Manual - Printer Port Extension.
Note that the logical environment for which each port is set is independent of the actual physical hardware setting of the ports, and may in fact be different. For example, it may be possible to set the host port for an 8-bit environment, even though the physical channel is limited by the hardware to 7-bits. The architecture assumes that the physical and logical settings are compatible, and does not define the results when this is not the case. The terminal characteristics are dependent on both the environment and the conformance level of operation. However, there are only three possible states for the terminal to be in that this architecture specifies:
Level 1 operation
Host Port transmit - 7-bit controls 7-bit graphics receive - 7-bit controls 7-bit graphics (Printer Port transmit - 7-bit controls 7-bit graphics) Level 2 or Level 3 operation, 7-bit C1 controls
Host Port transmit - 7-bit controls 8-bit graphics receive - 8-bit controls 8-bit graphics Level 2 or Level 3 operation, 8-bit C1 controls
Host Port transmit - 8-bit controls 8-bit graphics receive - 8-bit controls 8-bit graphics
7.5.1 Level 1 - Host Port
Level 1 operation provides only for 7-bit communications. Thus, in Level 1 all control and graphic characters can only be received and transmitted in seven bits. The high order bit of all 8-bit characters received will be stripped by the terminal before any processing occurs. All C1 controls will be transmitted by the terminal as ESC Fe sequences. Only 7-bit characters will be generated from the keyboard (that is, attempts to generate 8-bit characters will fail).
7.5.2 Level 2 or Level 3 - Host Port
In Level 2 or Level 3 operation both 7-bit and 8-bit communications are supported. The terminal will accept C1 control characters and GR graphic characters in both 7-bit and 8-bit C1 Transmission Modes.
When 7-bit communications is selected (7-bit host port environment), C1 controls will only be transmitted as ESC Fe sequences, and only 7-bit characters will be generated from the keyboard (that is, attempts to generate 8-bit characters on line will fail).
When 8-bit communications is selected (8-bit host port environment), the terminal can be selected to transmit C1 control characters either as 7-bit ESC Fe sequences, or as 8-bit control characters. The terminal will generate GR characters from the keyboard in eight bits.
typedef enum /* environment_type */
{
SEVEN_BIT, EIGHT_BIT
} environment_type;
environment_type
host_port_environment,
printer_port_environment,
c1_transmission_mode;
8 Control Operations
8.1 Announce Subset Of Code Extension Facilities
Announce Subset Of Code Extension Facilities
Levels: 2X, 3 (8-bit Interface Architecture Extension)
Purpose: To indicate which subset of code extension facilities defined in ISO 4873 conforming interchange will use.
Format:
ESC SP <final> 1/11 2/0
| <final> | Level of conformance |
|---|---|
| L 4/12 | Level 1 of ISO 4873 |
| M 4/13 | Level 2 of ISO 4873 |
| N 4/14 | Level 3 of ISO 4873 |
Description: This sequence announces the level of conformance that the subsequent interchange will conform to. Conformance to ISO 4873 requires some default designation and invocations on the part of the terminal.
Upon receipt of a Level 1, 2, or 3 announcer sequence, the terminal will make the following designations and invocations:
- Level 1
- ASCII is designated into G0
- ISO Latin Alphabet Nr 1 supplemental is designated into G1
- G0 is invoked into GL
- G1 is invoked into GR
- Level 2
- ASCII is designated into G0
- ISO Latin Alphabet Nr 1 supplemental is designated into G1
- G0 is invoked into GL
- G1 is invoked into GR
- Level 3
- ASCII is designated into G0
- G0 is invoked into GL
State Affected:
graphic_character_set_type designated_graphic_sets[4];graphic_character_set_type gl;graphic_character_set_type gr;gset_name_type invoked_gl;gset_name_type invoked_gr;
Algorithm:
void announce_level_1 ()
{
if ( (conformance_level > 2) ||
(level_2_extensions[8bit_ia]) )
{
designated_graphic_sets[0] = ASCII_G;
designated_graphic_sets[1] = ISO_LATIN1_SUPPLEMENTAL_G;
gl = designated_graphic_sets[0];
invoked_gl = G0;
gr = designated_graphic_sets[1];
invoked_gr = G1;
}
}
void announce_level_2 ()
{
if ( (conformance_level > 2) ||
(level_2_extensions[8bit_ia]) )
{
designated_graphic_sets[0] = ASCII_G;
designated_graphic_sets[1] = ISO_LATIN1_SUPPLEMENTAL_G;
gl = designated_graphic_sets[0];
invoked_gl = G0;
gr = designated_graphic_sets[1];
invoked_gr = G1;
}
}
void announce_level_3 ()
{
if ( (conformance_level > 2) ||
(level_2_extensions[8bit_ia]) )
{
designated_graphic_sets[0] = ASCII_G;
gl = designated_graphic_sets[0];
invoked_gl = G0;
}
}
Known Deviations: None
8.2 Communications Environment
Select 7-Bit C1 Transmission — S7C1T
Levels: 2, 3
Purpose: Cause the device to generate C1 controls in 7-bits as two character ESC Fe sequences.
Format:
ESC SP F 1/11 2/0 4/6
Description: The S7C1T control causes the terminal to use the 7-⁠bit encoding for all C1 control characters transmitted. Therefore, all C1 characters will be represented as two character ESC Fe sequences.
Notes:
The coding of this control is defined in ISO and ANSI standards, but is not assigned a name in those standards.
State Affected:
environment_type c1_transmission_mode;
Algorithm:
void select_7_bit_c1_transmission ()
{
if (conformance_level != LEVEL_1)
c1_transmission_mode = SEVEN_BIT;
}
Known Deviations: None
Select 8-Bit C1 Transmission — S8C1T
Levels: 2, 3
Purpose: Cause the device to generate C1 controls in 8-bits as single character control codes.
Format:
ESC SP G 1/11 2/0 4/7
Description: The S8C1T control causes the terminal to use the 8-bit encoding for all C1 control characters transmitted. Therefore, all C1 characters will be represented as single character control codes.
Notes:
The coding of this control is defined in ISO and ANSI standards, but is not assigned a name in those standards.
If the Host_Port_environment is set to Seven_Bit, this control will be ignored by the terminal.
State Affected:
environment_type c1_transmission_mode;
Algorithm:
void select_8_bit_c1_transmission ()
{
if ( (conformance_level != LEVEL_1) &&
(host_port_environment == EIGHT_BIT) )
c1_transmission_mode = EIGHT_BIT;
}
Known Deviations: None
8.3 Shift Functions
8.3.1 Locking Shifts
Shift In/Locking Shift Zero — SI/LS0
Levels: 1, 2, 3
Purpose: Invoke the G0 graphic character set into the GL position of the code table.
Format:
LS0 (SI) 1/15
Description: The LS0 or SI control invokes the set of graphic characters currently designated as a G0 set into the left-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 2/1 through 7/14 that is entered into the display to be rendered according to the current contents of the G0 character set.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void shift_in ()
{
in_use_table.gl = designated_graphic_sets[0];
in_use_table.invoked_gl = G0;
}
Known Deviations: None
Shift Out/Locking Shift One — SO/LS1
Levels: 1, 2, 3
Purpose: Invoke the G1 graphic character set into the GL position of the code table.
Format:
LS1 (SO) 1/14
Description: The LS1 or SO control invokes the set of graphic characters currently designated as a G1 set into the left-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 2/1 through 7/14 (or 2/0 through 7/15 for 96 character sets) that is entered into the display to be rendered according to the current contents of the G1 character set.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void shift_out ()
{
in_use_table.gl = designated_graphic_sets[1];
in_use_table.invoked_gl = G1;
}
Known Deviations: None
Locking Shift Two — LS2
Levels: 2, 3
Purpose: Invoke the G2 graphic character set into the GL position of the code table.
Format:
ESC n 1/11 6/14
Description: The LS2 control invokes the set of graphic characters currently designated as a G2 set into the left-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 2/1 through 7/14 (or 2/0 through 7/15 for 96 character sets) that is entered into the display to be rendered according to the current contents of the G2 character set.
Notes:
This control is included in the terminal interface for interchange compatibility with ISO and ANSI standards. It is not to be used by conforming software.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void locking_shift_two ()
{
if (conformance_level == LEVEL_2)
{
in_use_table.gl = designated_graphic_sets[2];
in_use_table.invoked_gl = G2;
}
}
Known Deviations: None
Locking Shift Three — LS3
Levels: 2, 3
Purpose: Invoke the G3 graphic character set into the GL position of the code table.
Format:
ESC o 1/11 6/15
Description: The LS3 control invokes the set of graphic characters currently designated as a G3 set into the left-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 2/1 through 7/14 (or 2/0 through 7/15 for 96 character sets) that is entered into the display to be rendered according to the current contents of the G3 character set.
Notes:
This control is included in the terminal interface for interchange compatibility with ISO and ANSI standards. It is not to be used by conforming software. See DEC STD 070-1.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void locking_shift_three ()
{
if (conformance_level == LEVEL_2)
{
in_use_table.gl = designated_graphic_sets[3];
in_use_table.invoked_gl = G3;
}
}
Known Deviations: None
Locking Shift One Right — LS1R
Levels: 2
Purpose: Invoke the G1 graphic character set into the GR position of the code table.
Format:
ESC ~ 1/11 7/14
Description: The LS1R control invokes the set of graphic characters currently designated as a G1 set into the right-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 10/1 through 15/14 (or 10/0 through 15/15 for 96 character sets) that is entered into the display to be rendered according to the current contents of the G1 character set.
Notes:
This control is included in the terminal interface for interchange compatibility with ISO and ANSI standards. It is not to be used by conforming software. (See DEC STD 070-1.)
Conformance to Level 3 of ISO 4873 requires the use of LS1R to invoke the right-hand part of the eight-bit code table.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void locking_shift_one_right ()
{
if (conformance_level == LEVEL_2)
{
in_use_table.gr = designated_graphic_sets[1];
in_use_table.invoked_gr = G1;
}
}
Known Deviations: None
Locking Shift Two Right — LS2R
Levels: 2, 3
Purpose: Invoke the G2 graphic character set into the GR position of the code table.
Format:
ESC } 1/11 7/13
Description: The LS2R control invokes the set of graphic characters currently designated as a G2 set into the right-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 10/1 through 15/14 (or 10/0 through 15/15 for 96 character sets), that is entered into the display to be rendered according to the current contents of the G2 character set.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void locking_shift_two_right ()
{
if (conformance_level == LEVEL_2)
{
in_use_table.gr = designated_graphic_sets[2];
in_use_table.invoked_gr = G2;
}
}
Known Deviations: None
Locking Shift Three Right — LS3R
Levels: 2, 3
Purpose: Invoke the G3 graphic character set into the GR position of the code table.
Format:
ESC | 1/11 7/12
Description: The LS3R control invokes the set of graphic characters currently designated as a G3 set into the right-hand graphics portion of the Code Table. Receipt of this control causes subsequent data in the range 10/1 through 15/14 (or 10/0 through 15/15 for 96 character sets) that is entered into the display to be rendered according to the current contents of the G3 character set.
State Affected:
in_use_table_type in_use_table;
Algorithm:
void locking_shift_three_right ()
{
if (conformance_level == LEVEL_2)
{
in_use_table.gr = designated_graphic_sets[3];
in_use_table.invoked_gr = G3;
}
}
Known Deviations: None
8.3.2 Single Shifts
Single Shift Two — SS2
Levels: 1, 2, 3
Purpose: Temporarily invoke a single character from the designated G2 set.
Format:
SS2 8/14
Description: The SS2 control causes the next character in the received data stream, which must be in the range 2/0 through 7/15 or 10/0 through 15/15, to be rendered according to the current contents of the G2 set. If the next character in the received data stream is not a graphic character in this range, the single shift function is ignored and the received character is processed as if the single shift had not been received.
The only exception to this rule is that a single Shift Out (0/14) or Shift In (0/15) control character may occur between the Single Shift and the subsequent graphic character. The Shift Out or Shift In character will be interpreted normally, but does not cancel the Single Shift. The following bit combination shall be interpreted as a character from the G2 set. This is done for conformance to ISO 2022, and is intended to facilitate the design of 8-bit to 7-bit transformation facilities.
State Affected:
single_shift_type single_shift;boolean_type cancel_single_shift;
Algorithm:
(See "Single Shift Three" below.)
Single Shift Three — SS3
Levels: 1, 2, 3
Purpose: Temporarily invoke a single character from the designated G3 set.
Format:
SS3 8/15
Description: The SS3 control causes the next character in the received data stream, which must be in the range 2/0 through 7/15 or 10/0 through 15/15, to be rendered according to the current contents of the G3 set. If the next character in the received data stream is not a graphic character in this range, the single shift function is ignored and the received character is processed as if the single shift had not been received.
The only exception to this rule is that a single Shift Out (0/14) or Shift In (0/15) control character may occur between the Single Shift and the subsequent graphic character. The Shift Out or Shift In character will be interpreted normally, but does not cancel the Single Shift. The following bit combination shall be interpreted as a character from the G3 set. This is done for conformance to ISO 2022, and is intended to facilitate the design of 8-bit to 7-bit transformation facilities.
State Affected:
single_shift_type single_shift;boolean_type cancel_single_shift;
Algorithm:
/* . . . main loop */
c = readcom();
parse_ansi(c, &com_state, &event, &start, &final);
if (single_shift != NONE)
{
if (cancel_single_shift) single_shift = NONE;
cancel_single_shift = IS_TRUE;
}
/* process recognized events . . . */
if (event == R_CONTROL)
{
code = com_state->data[final];
if (code == 0x0E) /* SO (LS1) */
{
shift_out();
cancel_single_shift = IS_FALSE;
}
else if (code == 0x0F) /* SI (LS0) */
{
shift_in();
cancel_single_shift = IS_FALSE;
}
else if (code == 0x8E)
{
single_shift = SS2;
cancel_single_shift = IS_FALSE;
}
else if (code == 0x8F)
{
single_shift = SS3;
cancel_single_shift = IS_FALSE;
}
/* . . . */
}
/* continue main loop . . . */
Known Deviations:
Previous versions of this standard incorrectly stated that an SO or SI between a Single Shift and its operand would be ignored. Since we do not normally translate between 7-bit and 8-bit environments within Digital, this has not been a problem. Future implementations should conform to ISO 2022 as described above.
9 Change History
9.1 Revision 0.2 to 0.3
The standard's title was changed from "Communications and Coding Interchange" to "Code Extension Layer".
The names of the Reference Standards were corrected.
The conformance section was removed, and will later be integrated into the section "Concepts and Conformance Criteria".
The terminology section was moved from the back of the document to the front.
A sentence was added to the section on graphic character codes to clarify the handling of bit combinations in the range 2/1 through 7/14 and 10/1 through 15/14 when received within a control function.
Qualifications were added to the section on rate limiting in terminals.
XON was removed from the definition of the Universal Terminator.
Sections were added to the notes on Escape Sequences and Control Sequences to clarify the processing of 7/15 and 15/15 and C1 control characters within control functions.
The section on processing of control sequence parameter values was substantially rewritten.
The section on Control Strings was moved ahead of the parser design.
A note was added on the non-conformance of the VT125 in processing CAN within control strings.
Global changes were made to the parser design to incorporate the processing of DCS introducer sequences.
A figure was added showing the logical relationship of the C sets, G sets, In Use Table, and character sets.
A note was added referencing DEC STD 169-0 and clarifying the distinction between conforming Presentation interchange and conforming Application interchange.
The 8-bit locking shifts table was corrected for LS3R.
All state descriptions were rewritten, and the names changed for consistency with other parts of the SRM.
The environments section was substantially rewritten.
The default character set designations were changed to distinguish between Level 1 operation and Level 2 operation.
The names of Select 7-bit C1 and Select 8-bit C1 were changed to include "Transmission". These controls are now called S7C1T and S8C1T.
GR Transmission Mode and Send/Receive Mode were removed from the architecture.
The coding was changed for LS0, LS1, LS1R, LS2R, LS3R, SS2 and SS3. Notes were added on conforming software use of these controls.
The character set designators were removed from this section and will later be incorporated into the section "Character Cell Display".
9.2 Revision 0.3 to AX10
Removed reference to use of Delete as a pad character, and made wording stronger that conforming software must use NUL only.
Added note to description of the processing of the 10/0 character to indicate that it is treated as Space (2/0) within control functions.
Made minor corrections and changed a few variable names in the parser algorithms to be consistent with other sections of the SRM.
Added a note to the section on environments indicating that the "logical" environment might in fact be different from the "physical" environment of the hardware, and if this is the case the architecture does not define the result.
Changed descriptions of Single_Shift_Two and Single_Shift_Three as well as the algorithms to indicate that they will be ignored if the next character in the received data stream is not a graphic character. (With the exception that a single Shift Out or Shift In character may occur.)
Removed the notes which restricted conforming software from using Single Shift Two and Single Shift Three.
Added a note that rate limiting should be the factory default in devices which have a capability of defeating this feature.
Changed the description of control characters occurring within control strings to permit, but deprecate the use of, any function other than String Terminator to terminate a string.
Added a note that GR (8-bit) graphic characters may occur within control strings.
9.3 Revision AX10 to AX11
Removed Rev AX10 change bars. Added change bars to any change that could affect conformance or interpretation of the document or should be brought to the attention of terminal implementors or software engineers.
Changed GET__NEXT__CODE__FROM__INPUT__BUFFER to strip parity bit in Level 1.
Added statement that the inclusion of C0 Controls 0/8 to 0/13 in control string data is intended for convenience in formating and storing control strings. It is recommended that these characters not affect the interpretation of the control string.
9.4 Revision AX11 to AX12
Removed Rev AX11 change bars. Added change bars to any change that could affect conformance or interpretation of the document or should be brought to the attention of terminal implementors or software engineers.
Added description of 8-bit Interface Architecture Extension including Support for 96-character graphic character sets, ISO Latin-1 Supplemental, and the User Preference Supplemental Set (UPSS). The 8-bit Interface Architecture Extension is required for Level 3 conformance, and strongly recommended for Level 2. Modified rest of chapter to assume the 8-bit Interface Architecture Extension is present. Graphic characters can now be in the range 2/0-7/15 and 10/0-15/15 when 96-⁠character graphic sets are used. Expanded description of default designations and invocations for 8-bit Interface Architecture.
Updated referenced standards section. Added dpANS X3.134.1-1985, X3.134.2-1985, and ISO 8859-1:1987.
Removed one page section on communication controls (XON/⁠XOFF, padding, and rate limiting) because they are not really part of Code Extension. These will included in chapter 12 on Terminal Synchronization.
Changed recommendation for minimum size of parameters that should be supported. Was 255 (8-bits), changed to 16384 (14-bits).
Added recommendation for handling parameters beyond the device maximum. Parameters beyond the maximum number supported should be ignored.
Extended description of multiple selective parameters to conform with current usage. Not all sequences containing more than one selective parameter have the same effect as a corresponding number of separate control sequences, each with a single parameter.
Clarified range of final characters for DCS sequences 7/0 to 7/14 (same as for private control sequences).
Added description of Digital extended syntax for other Control Strings (APC, OSC, PM). Syntax is patterned after Private Escape Sequences.
Added description of Character Strings (SOS) and anticipatory guidelines compatible with ISO 6429.
Clarified rules for 8-bit graphic characters within control strings including exception for DCS strings. 8-⁠bit graphic characters are treated as their 7-bit equivalents (8th bit ignored) in APC, OSC, PM strings, and DCS introducer sequences. Interpretation of 8-bit characters in data portion of DCS strings is dependent on the internal control string format.
Added description of NRCS Extension allowing ASCII to be replaced with NRC set (including default designations and invocations). Removed previous description of British NRCS as a special case. Included reference to section 6 where DECNRCM is documented.
Removed description of Printer Port Environment (7-⁠bits/8-bits) within Host Port Environment. Added reference to "Printer Port Extension" chapter.
Added description of "Announce Subset of Code Extension Facilities" per ISO 4873 including algorithm and escape sequences.
Added note about the possibility of a 96-character UPSS being designated as G0. Normally there is no way to directly designate a 96-character set as G0. Conforming software shall not designate a 96-character UPSS as G0.
Changed algorithms to use character re-entrant parser coded in VAX-11 C. This table driven ANSI parser is easier to follow, and is being used in actual products.
Changed standard to show that SI or SO occurring between a Single Shift and its operand does not cancel the Single Shift (SS2 or SS3) but may still affect subsequent data.
10 Referenced Documents
DIGITAL STANDARDS
- EL-00070-01
- DEC STD 070-1 Video Systems Reference Manual - Concepts and Conformance Criteria
- EL-00070-05
- DEC STD 070-5 Video Systems Reference Manual - Character Cell Display
- EL-00070-06
- DEC STD 070-6 Video Systems Reference Manual - Keyboard Processing
- EL-00070-07
- DEC STD 070-7 Video Systems Reference Manual - Printer Port Extension
- EL-00138-00
- DEC STD 138-0 Registry of Control Functions for Character Imaging Devices
- EL-00169-00
- DEC STD 169-0 DEC Standard Coded Graphic Character Sets for Hardware and Software
Copies of Digital Standards Can be obtained from Standards and Methods Control, $ VTX SMC, JOKUR::SMC, DTN 287-3724, or CTS1-⁠2/⁠D4.
Please provide your name, badge number, cost center, mailstop, and ENET node when ordering.
ANSI AND ISO STANDARDS
- ANSI X3.4 - 1986
- American National Standard Code for Information Interchange (ASCII character set)
- ANSI X3.41 - 1974
- American National Standard Code Extension Techniques for use with the 7-Bit Coded Character Set of the American National Standard Code for Information Interchange
- ANSI X3.64 - 1979
- Additional Controls for use with American National Standard Code for Information Interchange
- ANSI X4.23 - 1982
- Keyboard Arrangement for Alphanumeric Machines
- dpANS X3.134.1-1985
- 8-bit ASCII Structure and Rules
- dpANS X3.134.2-1985
- 7-bit and 8-bit ASCII Supplemental Multinational Graphic Character Set
- ISO 646
- Information Processing / 7-Bit Coded Character Set for Information Interchange
- ISO 2022:1986
- Information Processing / ISO 7-Bit and 8-Bit Coded Character Sets - Code Extension Techniques
- ISO 6429:1988
- Information Processing / Control Functions for Coded Character Sets
- ISO 8859-1:1987
- Information Processing / 8-Bit Single-Byte Coded Character Sets - Part 1 : ISO Latin Alphabet Nr 1;
Copies of ANSI and ISO Standards can be obtained from local Digital Libraries.
This page deliberately left blank.