Source

psk31 / make-varicode

Full commit
#!/usr/bin/perl
use warnings;
use strict;

print "static const uint16_t varicode[256] = {\n";

my %varicode;

while (<DATA>)
{
	chomp;
	my ($bits,undef,undef,$hex,$name) = split / \|\| /;

	my $word = 0;
	die "$bits => $hex too long\n"
		if length $bits > 16;

	for my $bit (split //, $bits)
	{
		$word = ($word >> 1) | ($bit << 15);
	}

	$varicode{$hex} = [ $word, $bits, $name ];
}

for my $hex (sort keys %varicode)
{
	my ($word, $bits, $name) = @{$varicode{$hex}};

	printf "\t0x%04x, // 0x%02x =>  %s (%s)\n",
		$word,
		hex $hex,
		$bits,
		$name,
		;
}

print "};\n";
		
__DATA__
1010101011 || 000 || 0 || 00 || NUL || [[Null character]]
1011011011 || 001 || 1 || 01 || SOH || Start of Header
1011101101 || 002 || 2 || 02 || STX || Start of Text
1101110111 || 003 || 3 || 03 || ETX || End of Text
1011101011 || 004 || 4 || 04 || EOT || [[End-of-transmission character|End of Transmission]]
1101011111 || 005 || 5 || 05 || ENQ ||  Enquiry
1011101111 || 006 || 6 || 06 || ACK || [[Acknowledge character|Acknowledgment]]
1011111101 || 007 || 7 || 07 || BEL || [[Bell character|Bell]]
1011111111 || 010 || 8 || 08 || BS || [[Backspace]]
11101111 || 011 || 9 || 09 || HT || [[Tab key|Horizontal Tab]]
11101 || 012 || 10 || 0A || LF || [[Line feed]]
1101101111 || 013 || 11 || 0B || VT || Vertical Tab
1011011101 || 014 || 12 || 0C || FF || [[Form feed]]
11111 || 015 || 13 || 0D || CR || [[Carriage return]]
1101110101 || 016 || 14 || 0E || SO || [[Shift Out and Shift In characters|Shift Out]]
1110101011 || 017 || 15 || 0F || SI || [[Shift Out and Shift In characters|Shift In]]
1011110111 || 020 || 16 || 10 || DLE || Data Link Escape
1011110101 || 021 || 17 || 11 || DC1 || Device Control 1 (XON)
1110101101 || 022 || 18 || 12 || DC2 || Device Control 2
1110101111 || 023 || 19 || 13 || DC3 || Device Control 3 (XOFF)
1101011011 || 024 || 20 || 14 || DC4 || Device Control 4
1101101011 || 025 || 21 || 15 || NAK || [[Negative-acknowledge character|Negative Acknowledgement]]
1101101101 || 026 || 22 || 16 || SYN || Synchronous Idle
1101010111 || 027 || 23 || 17 || ETB || End of Trans. Block
1101111011 || 030 || 24 || 18 || CAN || [[Cancel character|Cancel]]
1101111101 || 031 || 25 || 19 || EM || End of Medium
1110110111 || 032 || 26 || 1A || SUB || [[Substitute character|Substitute]]
1101010101 || 033 || 27 || 1B || ESC || [[Escape character|Escape]]
1101011101 || 034 || 28 || 1C || FS || File Separator
1110111011 || 035 || 29 || 1D || GS || Group Separator
1011111011 || 036 || 30 || 1E || RS || Record Separator
1101111111 || 037 || 31 || 1F || US || Unit Separator
1 || 040 || 32 || 20 || [[Space (punctuation)|SP]]
111111111 || 041 || 33 || 21 || [[Exclamation mark|!]]
101011111 || 042 || 34 || 22 || [[Quotation mark|"]]
111110101 || 043 || 35 || 23 || [[Number sign|#]]
111011011 || 044 || 36 || 24 || [[Dollar sign|$]]
1011010101 || 045 || 37 || 25 || [[Percent sign|%]]
1010111011 || 046 || 38 || 26 || [[Ampersand|&]]
101111111 || 047 || 39 || 27 || [[Apostrophe (punctuation)|']]
11111011 || 050 || 40 || 28 || [[Bracket|(]]
11110111 || 051 || 41 || 29 || [[Bracket|)]]
101101111 || 052 || 42 || 2A || [[Asterisk|*]]
111011111 || 053 || 43 || 2B || [[Plus sign|+]]
1110101 || 054 || 44 || 2C || [[Comma (punctuation)|,]]
110101 || 055 || 45 || 2D || [[Hyphen|-]]
1010111 || 056 || 46 || 2E || [[Full stop|.]]
110101111 || 057 || 47 || 2F || [[Slash (punctuation)|/]]
10110111 || 060 || 48 || 30 || [[0 (number)|0]]
10111101 || 061 || 49 || 31 || [[1 (number)|1]]
11101101 || 062 || 50 || 32 || [[2 (number)|2]]
11111111 || 063 || 51 || 33 || [[3 (number)|3]]
101110111 || 064 || 52 || 34 || [[4 (number)|4]]
101011011 || 065 || 53 || 35 || [[5 (number)|5]]
101101011 || 066 || 54 || 36 || [[6 (number)|6]]
110101101 || 067 || 55 || 37 || [[7 (number)|7]]
110101011 || 070 || 56 || 38 || [[8 (number)|8]]
110110111 || 071 || 57 || 39 || [[9 (number)|9]]
11110101 || 072 || 58 || 3A || [[Colon (punctuation)|:]]
110111101 || 073 || 59 || 3B || [[Semicolon|;]]
111101101 || 074 || 60 || 3C || [[Less-than sign|<]]
1010101 || 075 || 61 || 3D || [[Equals sign|=]]
111010111 || 076 || 62 || 3E || [[Greater-than sign|>]]
1010101111 || 077 || 63 || 3F || [[Question mark|?]]
1010111101 || 100 || 64 || 40 || [[@]]
1111101 || 101 || 65 || 41 || [[A]]
11101011 || 102 || 66 || 42 || [[B]]
10101101 || 103 || 67 || 43 || [[C]]
10110101 || 104 || 68 || 44 || [[D]]
1110111 || 105 || 69 || 45 || [[E]]
11011011 || 106 || 70 || 46 || [[F]]
11111101 || 107 || 71 || 47 || [[G]]
101010101 || 110 || 72 || 48 || [[H]]
1111111 || 111 || 73 || 49 || [[I]]
111111101 || 112 || 74 || 4A || [[J]]
101111101 || 113 || 75 || 4B || [[K]]
11010111 || 114 || 76 || 4C || [[L]]
10111011 || 115 || 77 || 4D || [[M]]
11011101 || 116 || 78 || 4E || [[N]]
10101011 || 117 || 79 || 4F || [[O]]
11010101 || 120 || 80 || 50 || [[P]]
111011101 || 121 || 81 || 51 || [[Q]]
10101111 || 122 || 82 || 52 || [[R]]
1101111 || 123 || 83 || 53 || [[S]]
1101101 || 124 || 84 || 54 || [[T]]
101010111 || 125 || 85 || 55 || [[U]]
110110101 || 126 || 86 || 56 || [[V]]
101011101 || 127 || 87 || 57 || [[W]]
101110101 || 130 || 88 || 58 || [[X]]
101111011 || 131 || 89 || 59 || [[Y]]
1010101101 || 132 || 90 || 5A || [[Z]]
111110111 || 133 || 91 || 5B || [[Bracket|<nowiki>[</nowiki>]]
111101111 || 134 || 92 || 5C || [[Backslash|\]]
111111011 || 135 || 93 || 5D || [[Bracket|<nowiki>]</nowiki>]]
1010111111 || 136 || 94 || 5E || [[Caret|^]]
101101101 || 137 || 95 || 5F || [[Underscore|_]]
1011011111 || 140 || 96 || 60 || [[Grave accent|`]]
1011 || 141 || 97 || 61 || [[a]]
1011111 || 142 || 98 || 62 || [[b]]
101111 || 143 || 99 || 63 || [[c]]
101101 || 144 || 100 || 64 || [[d]]
11 || 145 || 101 || 65 || [[e]]
111101 || 146 || 102 || 66 || [[f]]
1011011 || 147 || 103 || 67 || [[g]]
101011 || 150 || 104 || 68 || [[h]]
1101 || 151 || 105 || 69 || [[i]]
111101011 || 152 || 106 || 6A || [[j]]
10111111 || 153 || 107 || 6B || [[k]]
11011 || 154 || 108 || 6C || [[l]]
111011 || 155 || 109 || 6D || [[m]]
1111 || 156 || 110 || 6E || [[n]]
111 || 157 || 111 || 6F || [[o]]
111111 || 160 || 112 || 70 || [[p]]
110111111 || 161 || 113 || 71 || [[q]]
10101 || 162 || 114 || 72 || [[r]]
10111 || 163 || 115 || 73 || [[s]]
101 || 164 || 116 || 74 || [[t]]
110111 || 165 || 117 || 75 || [[u]]
1111011 || 166 || 118 || 76 || [[v]]
1101011 || 167 || 119 || 77 || [[w]]
11011111 || 170 || 120 || 78 || [[x]]
1011101 || 171 || 121 || 79 || [[y]]
111010101 || 172 || 122 || 7A || [[z]]
1010110111 || 173 || 123 || 7B || [[Bracket|&#123;]]
110111011 || 174 || 124 || 7C || [[Vertical bar|&#124;]]
1010110101 || 175 || 125 || 7D || [[Bracket|&#125;]]
1011010111 || 176 || 126 || 7E || [[Tilde|~]]
1110110101 || 177 || 127 || 7F || DEL || Delete