Debian Codegraph @

texmf-dist/doc/fonts/gnu-freefont/tools/utility/hex_range.py

raw
1 #!/usr/bin/env python
2 __license__ = """
3 This file is part of Gnu FreeFont.
4
5 Gnu FreeFont is free software: you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation, either version 3 of the License, or (at your option) any later
8 version.
9
10 Gnu FreeFont is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 Gnu FreeFont. If not, see <http://www.gnu.org/licenses/>.
16 """
17 __author__ = "Stevan White"
18 __email__ = "[email protected]"
19 __copyright__ = "Copyright 2009, 2010, 2011 Stevan White"
20 __date__ = "$Date: 2011-09-13 13:05:59 +0200 (Tue, 13 Sep 2011) $"
21 __version__ = "$Revision: 1704 $"
22
23 __doc__ = """Sends to standard output a range of hex values formatted
24 for e.g. HTML.
25 Takes one or two numerical arguments. With one argument the output
26 is just the formatted value of the argument.
27 """
28
29 import sys
30
31 # Python Unicode prefix
32 prefix = '\\u'
33 postfix = ''
34 # General Unicode prefix
35 prefix = 'U+'
36 postfix = ''
37 # HTML Entity
38 prefix = '&#x'
39 postfix = ';'
40
41 def explain_error_and_quit( e ):
42 if e:
43 print 'Error: ', e
44 print "Usage:"
45 print " hex_range num1 [num2]"
46 exit( 1 )
47
48 def print_formatted_hex_value( n ):
49 print '%s%0.4x%s' %( prefix, n, postfix )
50
51 if len( sys.argv ) == 3:
52 try:
53 a = int( sys.argv[1], 0 )
54 b = int( sys.argv[2], 0 )
55 for i in xrange( a, b + 1 ):
56 print_formatted_hex_value( i )
57 except ValueError, e:
58 explain_error_and_quit( e )
59 elif len( sys.argv ) == 2:
60 try:
61 a = int( sys.argv[1], 0 )
62 print_formatted_hex_value( a )
63 except ValueError, e:
64 explain_error_and_quit( e )
65 else:
66 explain_error_and_quit()
67