Changeset 409 for pkpgcounter/trunk/pkpgpdls
- Timestamp:
- 09/13/06 10:45:42 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/spl1.py
r408 r409 63 63 def escape(self, nextpos) : 64 64 """Handles the ESC code.""" 65 self.isbitmap = False 65 66 pos = endpos = nextpos 66 67 minfile = self.minfile … … 83 84 # NB : First time will be at page 0 (i.e. **before** page 1) ! 84 85 stuff = self.escapedStuff.setdefault(self.pagecount, []) 85 stuff.append(minfile[pos-1 : endpos]) 86 self.logdebug("Escaped datas : [%s]" % repr(minfile[pos : endpos])) 86 datas = minfile[pos-1 : endpos] 87 stuff.append(datas) 88 if datas.endswith("$PJL BITMAP START\r\n") : 89 self.isbitmap = True 90 self.logdebug("Escaped datas : [%s]" % repr(datas)) 87 91 return endpos - pos + 1 88 92 … … 93 97 """ 94 98 infileno = self.infile.fileno() 95 self.minfile = m map.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED)99 self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 96 100 self.pagecount = 0 97 101 self.escapedStuff = {} # For escaped datas, mostly PJL commands 98 102 self.bigEndian() 99 103 104 self.isbitmap = False 100 105 pos = 0 101 tags = self.tags102 106 try : 103 107 try : 104 108 while 1 : 105 tag = self.minfile[pos]109 tag = minfile[pos] 106 110 if tag in ESCAPECHARS : 107 111 pos += self.escape(pos+1) 108 112 else : 109 offset = unpack(self.unpackLong, self.minfile[pos:pos+4])[0] 110 sequencenum = unpack(self.unpackShort, self.minfile[pos+4:pos+6])[0] 111 codesop = " ".join([ "%02x" % ord(v) for v in self.minfile[pos+6:pos+12]]) 112 self.logdebug("Sequence Number : %04x" % sequencenum) 113 self.logdebug("%08x ====> %s" % (pos+6, codesop)) 113 if not self.isbitmap : 114 raise pdlparser.PDLParserError, "Unfortunately this file format is incompletely recognized. Parsing aborted." 115 offset = unpack(self.unpackLong, minfile[pos:pos+4])[0] 116 sequencenum = unpack(self.unpackShort, minfile[pos+4:pos+6])[0] 117 codesop = " ".join([ "%02x" % ord(v) for v in minfile[pos+6:pos+12]]) 118 if codesop != "06 00 00 80 13 40" : 119 raise pdlparser.PDLParserError, "Unfortunately this file format is incompletely recognized. Parsing aborted." 120 self.logdebug("%08x ==> %04x ==> %s" % (pos, sequencenum, codesop)) 121 if not sequencenum : 122 self.pagecount += 1 114 123 pos += 4 + offset 115 self.logdebug("New position : %08x" % pos)116 124 except IndexError : # EOF ? 117 125 pass 118 126 finally : 119 self.minfile.close()127 minfile.close() 120 128 return self.pagecount 121 129