0
0
Fork 0
mirror of https://git.code.sf.net/p/quake/quakeforge synced 2025-03-21 18:01:15 +00:00

Create an idquake character encoding.

It just does a 1:1 charmap conversion of quake text, purely to allow python
to read arbitrary qc code.
This commit is contained in:
Bill Currie 2012-09-13 12:19:26 +09:00
parent b764cad483
commit 225cb4b364
2 changed files with 48 additions and 1 deletions

View file

@ -22,6 +22,7 @@
import os
from .script import Script
from .qfplist import pldata
from . import quakechr
MAX_FLAGS = 8
@ -129,7 +130,7 @@ class EntityClassDict:
self.path = ""
self.entity_classes = {}
def scan_source(self, fname):
text = open(fname, "rt").read()
text = open(fname, "rt", encoding="idquake").read()
line = 1
pos = 0
while pos < len(text):

View file

@ -0,0 +1,46 @@
# vim:ts=4:et
import codecs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
def search_function(encoding):
if encoding != "idquake":
return None
return codecs.CodecInfo(
name='idquake',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
decoding_table = [None]*256
for i in range(256):
decoding_table[i] = i
decoding_table = tuple(decoding_table)
encoding_map = codecs.make_identity_dict(range(256))
codecs.register(search_function)