Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Message
| There are many times when I want to know the ASCII character code for a letter (eg. "M") or what the code is for IAC SB. This small plugin below displays a code chart in the output window.
For each of the characters in the range 0 to 255 it displays:
- Its number in decimal
- Any special significance (eg. 9 is "tab")
- The character displayed (eg. 116 is "t")
- The code number in hex
- For known telnet options, what the option is (eg. 91 for MXP, 200 for ATCP)
|
To save and install the Code_Chart plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Code_Chart.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Code_Chart.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Code_Chart"
author="Nick Gammon"
id="fe800afdd06ded4235f35baa"
language="Lua"
purpose="Displays an ASCII code chart"
date_written="2010-08-01 13:51:03"
requires="4.40"
version="1.0"
>
<description trim="y">
<![CDATA[
Type 'code_chart' to display a code chart.
]]>
</description>
</plugin>
<!-- Aliases -->
<aliases>
<alias
script="ascii_chart"
match="code_chart"
enabled="y"
sequence="100"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
function ascii_chart (name, line, wildcards)
local control_characters = {
-- control sequences
[0] = "NUL", "SOH", "STX", "ETX", "EOT", "ENQ",
"ACK", "BEL", "BS", "TAB", "LF", "VT",
"FF", "CR", "SO", "SI", "DLE", "DC1",
"DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM", "SUB", "ESC", "FS", "GS",
"RS", "US", "Space",
[127] = "DEL",
-- telnet codes
[0xEF] = "EOR",
[0xF0] = "SE",
[0xF1] = "NOP",
[0xF2] = "DM",
[0xF3] = "BRK",
[0xF4] = "IP",
[0xF5] = "AO",
[0xF6] = "AYT",
[0xF7] = "EC",
[0xF8] = "EL",
[0xF9] = "GA",
[0xFA] = "SB",
[0xFB] = "WILL",
[0xFC] = "WONT",
[0xFD] = "DO",
[0xFE] = "DONT",
[0xFF] = "IAC",
}
-- telnet negotiation requests (eg. IAC WILL ECHO)
local telnet_options = {
[0x01] = "ECHO", -- 1 Echo
[0x03] = "Suppress Go-ahead (GA)", -- 3 Suppress go ahead
[0x05] = "Status", -- 5 Status
[0x06] = "Timing Mark", -- 6 Timing mark
[0x18] = "Termtype", -- 24 Terminal type
[0x19] = "End of record (EOR)", -- 25 EOR
[0x1F] = "Window Size (NAWS)", -- 31 Window size
[0x20] = "Terminal Speed", -- 32 Terminal speed
[0x21] = "RFC", -- 33 Remote flow control
[0x22] = "LM", -- 34 Line mode
[0x24] = "EV", -- 36 Environment variables
[0x2A] = "Charset", -- 42 Character set
[0x55] = "MCCP1", -- 85 MUD Compression Protocol v1
[0x56] = "MCCP2", -- 86 MUD Compression Protocol v2
[0x5A] = "MSP", -- 90 (MUD Sound Protocol)
[0x5B] = "MXP", -- 91 (MUD eXtension Protocol)
[0x5D] = "ZMP", -- 93 (ZMP Protocol)
[0x66] = "Aardwolf", -- 102
[0xC8] = "ATCP", -- 200 ATCP (Achaea Telnet Protocol)
[0xC9] = "ATCP2/GMCP", -- 201 ATCP2/GMCP (Generic Mud Control Protocol)
[0xFF] = "Extended Options", -- for future expansion
}
-- show each character
for i = 0, 255 do
local special = control_characters [i] or ""
local telnet = telnet_options [i] or ""
if i >= 32 then
if GetOption ("utf_8") == 1 then
char = utils.utf8encode (i)
else
char = string.char (i)
end -- if Unicode or not
else
char = " ";
end -- if printable
print (string.format ("%3i %-5s %s 0x%02X %s", i, special, char, i, telnet))
end -- for
end -- ascii_chart
-- show description
ColourNote ("cyan", "", GetPluginInfo (GetPluginID (), 3))
]]>
</script>
</muclient>
Example output:
0 NUL 0x00
1 SOH 0x01 ECHO
2 STX 0x02
3 ETX 0x03 Suppress Go-ahead (GA)
4 EOT 0x04
5 ENQ 0x05 Status
6 ACK 0x06 Timing Mark
7 BEL 0x07
8 BS 0x08
9 TAB 0x09
10 LF 0x0A
11 VT 0x0B
12 FF 0x0C
13 CR 0x0D
14 SO 0x0E
15 SI 0x0F
16 DLE 0x10
17 DC1 0x11
18 DC2 0x12
19 DC3 0x13
20 DC4 0x14
21 NAK 0x15
22 SYN 0x16
23 ETB 0x17
24 CAN 0x18 Termtype
25 EM 0x19 End of record (EOR)
26 SUB 0x1A
27 ESC 0x1B
28 FS 0x1C
29 GS 0x1D
30 RS 0x1E
31 US 0x1F Window Size (NAWS)
32 Space 0x20 Terminal Speed
33 ! 0x21 RFC
34 " 0x22 LM
35 # 0x23
36 $ 0x24 EV
37 % 0x25
38 & 0x26
39 ' 0x27
40 ( 0x28
41 ) 0x29
42 * 0x2A Charset
43 + 0x2B
44 , 0x2C
45 - 0x2D
46 . 0x2E
47 / 0x2F
48 0 0x30
49 1 0x31
50 2 0x32
51 3 0x33
52 4 0x34
53 5 0x35
54 6 0x36
55 7 0x37
56 8 0x38
57 9 0x39
58 : 0x3A
59 ; 0x3B
60 < 0x3C
61 = 0x3D
62 > 0x3E
63 ? 0x3F
64 @ 0x40
65 A 0x41
66 B 0x42
67 C 0x43
68 D 0x44
69 E 0x45
70 F 0x46
71 G 0x47
72 H 0x48
73 I 0x49
74 J 0x4A
75 K 0x4B
76 L 0x4C
77 M 0x4D
78 N 0x4E
79 O 0x4F
80 P 0x50
81 Q 0x51
82 R 0x52
83 S 0x53
84 T 0x54
85 U 0x55 MCCP1
86 V 0x56 MCCP2
87 W 0x57
88 X 0x58
89 Y 0x59
90 Z 0x5A MSP
91 [ 0x5B MXP
92 \ 0x5C
93 ] 0x5D ZMP
94 ^ 0x5E
95 _ 0x5F
96 ` 0x60
97 a 0x61
98 b 0x62
99 c 0x63
100 d 0x64
101 e 0x65
102 f 0x66 Aardwolf
103 g 0x67
104 h 0x68
105 i 0x69
106 j 0x6A
107 k 0x6B
108 l 0x6C
109 m 0x6D
110 n 0x6E
111 o 0x6F
112 p 0x70
113 q 0x71
114 r 0x72
115 s 0x73
116 t 0x74
117 u 0x75
118 v 0x76
119 w 0x77
120 x 0x78
121 y 0x79
122 z 0x7A
123 { 0x7B
124 | 0x7C
125 } 0x7D
126 ~ 0x7E
... more follows
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|