[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Plugin to display an ASCII code-chart
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Plugin to display an ASCII code-chart

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Sun 01 Aug 2010 04:01 AM (UTC)

Amended on Sun 01 Aug 2010 05:57 AM (UTC) by Nick Gammon

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)


Template:saveplugin=Code_Chart To save and install the Code_Chart plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Code_Chart.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Code_Chart.xml (which you just saved in step 3) as a plugin
  7. 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
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #1 on Sun 01 Aug 2010 05:24 AM (UTC)
Message
Just to err on the side of correctness...

Bytes 128-255 are dependent on the selected codepage as they are part of what is called 'Extended ASCII'. Or when using UTF8, they don't even exist as those bytes are what is used to implement other Unicode characters.

I assume the 128-255 range is depended by the default Windows codepage here?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 01 Aug 2010 06:04 AM (UTC)

Amended on Sun 01 Aug 2010 06:18 AM (UTC) by Nick Gammon

Message
You raise an interesting point about UTF-8.

I amended the plugin to test your utf-8 flag, and convert the supplied number into utf-8 (so it would be displayed correctly).

As for the code page, clearly since we are outputting to the output window, the character will be represented in whatever your current codepage is, or in the appropriate Unicode characters, if you have utf-8 enabled, and a Unicode font selected.

I note that some characters (like 0x80) don't seem to be defined in Unicode, and thus will appear as boxes or hyphens or something.

However it is still a useful tool for seeing, for your current font and code page, what each character will be displayed as.

Worstje said:

Or when using UTF8, they don't even exist as those bytes are what is used to implement other Unicode characters.


Well, a lot of them do, see:

http://en.wikipedia.org/wiki/List_of_Unicode_characters

For example, U+00BC is the "1/4" symbol named "Vulgar fraction one quarter". That displays correctly in MUSHclient with or without utf-8 enabled (eg. in Dina font).

Also, I wouldn't confuse the Unicode code-point (eg. U+00FF) with how it is represented in UTF-8 (0xC3BF)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #3 on Mon 02 Aug 2010 07:38 AM (UTC)
Message
Yeah, I know about the basic difference between codepoints and the way UTF-8 encodes them. I admit I didn't look up the exact specifics and claimed something without checking... so thanks for correcting me there. :)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


6,863 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]