#!/usr/bin/python1# -*- coding: utf-8 -*-2#3# Copyright (c) 2010 Kungliga Tekniska Högskolan4# (Royal Institute of Technology, Stockholm, Sweden).5# All rights reserved.6#7# Redistribution and use in source and binary forms, with or without8# modification, are permitted provided that the following conditions9# are met:10#11# 1. Redistributions of source code must retain the above copyright12# notice, this list of conditions and the following disclaimer.13#14# 2. Redistributions in binary form must reproduce the above copyright15# notice, this list of conditions and the following disclaimer in the16# documentation and/or other materials provided with the distribution.17#18# 3. Neither the name of the Institute nor the names of its contributors19# may be used to endorse or promote products derived from this software20# without specific prior written permission.21#22# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32# SUCH DAMAGE.33#3435CONTROL_CHAR = 136PRINTABLE = 237RFC2253_QUOTE_FIRST = 438RFC2253_QUOTE_LAST = 839RFC2253_QUOTE = 1640RFC2253_HEX = 324142chars = []4344for i in range(0, 256):45chars.append(0);4647for i in range(0, 256):48if (i < 32 or i > 126):49chars[i] |= CONTROL_CHAR | RFC2253_HEX;5051for i in range(ord("A"), ord("Z") + 1):52chars[i] |= PRINTABLE53for i in range(ord("a"), ord("z") + 1):54chars[i] |= PRINTABLE55for i in range(ord("0"), ord("9") + 1):56chars[i] |= PRINTABLE5758chars[ord(' ')] |= PRINTABLE59chars[ord('+')] |= PRINTABLE60chars[ord(',')] |= PRINTABLE61chars[ord('-')] |= PRINTABLE62chars[ord('.')] |= PRINTABLE63chars[ord('/')] |= PRINTABLE64chars[ord(':')] |= PRINTABLE65chars[ord('=')] |= PRINTABLE66chars[ord('?')] |= PRINTABLE6768chars[ord(' ')] |= RFC2253_QUOTE_FIRST | RFC2253_QUOTE_FIRST6970chars[ord(',')] |= RFC2253_QUOTE71chars[ord('=')] |= RFC2253_QUOTE72chars[ord('+')] |= RFC2253_QUOTE73chars[ord('<')] |= RFC2253_QUOTE74chars[ord('>')] |= RFC2253_QUOTE75chars[ord('#')] |= RFC2253_QUOTE76chars[ord(';')] |= RFC2253_QUOTE7778print "#define Q_CONTROL_CHAR 1"79print "#define Q_PRINTABLE 2"80print "#define Q_RFC2253_QUOTE_FIRST 4"81print "#define Q_RFC2253_QUOTE_LAST 8"82print "#define Q_RFC2253_QUOTE 16"83print "#define Q_RFC2253_HEX 32"84print ""85print "#define Q_RFC2253 (Q_RFC2253_QUOTE_FIRST|Q_RFC2253_QUOTE_LAST|Q_RFC2253_QUOTE|Q_RFC2253_HEX)"86print "\n" * 28788899091print "unsigned char char_map[] = {\n\t",92for x in range(0, 256):93if (x % 8) == 0 and x != 0:94print "\n\t",95print "0x%(char)02x" % { 'char' : chars[x] },96if x < 255:97print ", ",98else:99print ""100print "};"101102103