|
Revision 626, 0.7 kB
(checked in by alo, 2 years ago)
|
--
|
| Line | |
|---|
| 1 |
import sys, string |
|---|
| 2 |
|
|---|
| 3 |
def is_letter(x): |
|---|
| 4 |
if ord(x) in range(71, 91) or ord(x) in range(103, 123): |
|---|
| 5 |
return True |
|---|
| 6 |
return False |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
def print_block(info, len): |
|---|
| 10 |
print 'ret = cherokee_buffer_add (buffer, \\\n' + info + ', ' + str(len) + ');' |
|---|
| 11 |
print 'if (ret < ret_ok) return ret;\n' |
|---|
| 12 |
|
|---|
| 13 |
file = open (sys.argv[1], "r") |
|---|
| 14 |
cont = file.read() |
|---|
| 15 |
file.close() |
|---|
| 16 |
|
|---|
| 17 |
s = "" |
|---|
| 18 |
siz = 0 |
|---|
| 19 |
lin = "" |
|---|
| 20 |
for c in cont: |
|---|
| 21 |
tmp = hex(ord(c)).replace("0x", "") |
|---|
| 22 |
if (len(tmp) < 2): tmp = "0"+tmp |
|---|
| 23 |
lin += "\\x"+ tmp |
|---|
| 24 |
|
|---|
| 25 |
siz += 1 |
|---|
| 26 |
|
|---|
| 27 |
if (len(lin) > 75): |
|---|
| 28 |
s += '"%s"\n' % (lin) |
|---|
| 29 |
lin = "" |
|---|
| 30 |
|
|---|
| 31 |
if (siz > 127): |
|---|
| 32 |
print_block (s, siz) |
|---|
| 33 |
s = "" |
|---|
| 34 |
siz = 0 |
|---|
| 35 |
|
|---|
| 36 |
s += '"%s"\n' % (lin) |
|---|
| 37 |
print_block (s, siz) |
|---|