Changeset 318 for pkpgcounter/trunk

Show
Ignore:
Timestamp:
02/10/06 00:30:17 (18 years ago)
Author:
jerome
Message:

Fixed handling of the undocumented 0x46 tag, hopefully for good...

Location:
pkpgcounter/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/man/pkpgcounter.1

    r314 r318  
    1 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.36. 
     1.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.35. 
    22.TH PKPGCOUNTER "1" "February 2006" "C@LL - Conseil Internet & Logiciels Libres" "User Commands" 
    33.SH NAME 
    4 pkpgcounter \- manual page for pkpgcounter 1.76 
     4pkpgcounter \- manual page for pkpgcounter 1.77 
    55.SH DESCRIPTION 
    6 pkpgcounter v1.76 (c) 2003, 2004, 2005, 2006 Jerome Alet 
     6pkpgcounter v1.77 (c) 2003, 2004, 2005, 2006 Jerome Alet 
    77.PP 
    88pkpgcounter is a generic Page Description Language parser. 
  • pkpgcounter/trunk/NEWS

    r314 r318  
    2222pkpgcounter News : 
    2323 
     24  * 1.77 :  
     25   
     26    - Fixed some problems with the code introduced in 1.76. 
     27     
     28    - Improved PCLXL parser's speed by almost 10%. 
     29     
    2430  * 1.76 : 
    2531   
  • pkpgcounter/trunk/pkpgpdls/pclxl.py

    r317 r318  
    8888            return 0 
    8989             
    90     def beginPage(self, prevpos) : 
     90    def beginPage(self, nextpos) : 
    9191        """Indicates the beginning of a new page, and extracts media information.""" 
    9292        self.pagecount += 1 
     
    102102        # this saves time because we don't need a complete parser ! 
    103103        minfile = self.minfile 
    104         pos = prevpos - 2 
     104        pos = nextpos - 2 
    105105        while pos > 0 : # safety check : don't go back to far ! 
    106106            val = ord(minfile[pos]) 
     
    174174        return 0 
    175175         
    176     def endPage(self, prevpos) :     
     176    def endPage(self, nextpos) :     
    177177        """Indicates the end of a page.""" 
    178         pos3 = prevpos - 3 
     178        pos3 = nextpos - 3 
    179179        minfile = self.minfile 
    180         if minfile[pos3:prevpos-1] == self.setNumberOfCopies : 
     180        if minfile[pos3:nextpos-1] == self.setNumberOfCopies : 
    181181            # The EndPage operator may be preceded by a PageCopies attribute 
    182182            # So set number of copies for current page. 
     
    189189        return 0 
    190190         
    191     def setColorSpace(self, prevpos) :     
     191    def setColorSpace(self, nextpos) :     
    192192        """Changes the color space.""" 
    193         if self.minfile[prevpos-4:prevpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases ! 
     193        if self.minfile[nextpos-4:nextpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases ! 
    194194            self.iscolor = 1 
    195195        return 0 
    196196             
    197     def array_Generic(self, prevpos, size) : 
     197    def array_Generic(self, nextpos, size) : 
    198198        """Handles all arrays.""" 
    199         pos = prevpos 
     199        pos = nextpos 
    200200        datatype = ord(self.minfile[pos]) 
    201201        pos += 1 
     
    203203        if callable(length) : 
    204204            length = length(pos) 
    205         posl = pos + length 
    206         if length == 1 :     
    207             return 1 + length + size * unpack("B", self.minfile[pos:posl])[0] 
    208         elif length == 2 :     
    209             return 1 + length + size * unpack(self.unpackShort, self.minfile[pos:posl])[0] 
    210         elif length == 4 :     
    211             return 1 + length + size * unpack(self.unpackLong, self.minfile[pos:posl])[0] 
    212         else :     
    213             raise pdlparser.PDLParserError, "Error on array size at %x" % prevpos 
    214              
    215     def array_8(self, prevpos) :     
     205        try : 
     206            return 1 + length + size * unpack(self.unpackType[length], self.minfile[pos:pos+length])[0] 
     207        except KeyError : 
     208            raise pdlparser.PDLParserError, "Error on array size at %x" % nextpos 
     209             
     210    def array_8(self, nextpos) :     
    216211        """Handles byte arrays.""" 
    217         return self.array_Generic(prevpos, 1) 
    218          
    219     def array_16(self, prevpos) : 
     212        return self.array_Generic(nextpos, 1) 
     213         
     214    def array_16(self, nextpos) : 
    220215        """Handles byte arrays.""" 
    221         return self.array_Generic(prevpos, 2) 
    222          
    223     def array_32(self, prevpos) : 
     216        return self.array_Generic(nextpos, 2) 
     217         
     218    def array_32(self, nextpos) : 
    224219        """Handles byte arrays.""" 
    225         return self.array_Generic(prevpos, 4) 
    226          
    227     def embeddedDataSmall(self, prevpos) : 
     220        return self.array_Generic(nextpos, 4) 
     221         
     222    def embeddedDataSmall(self, nextpos) : 
    228223        """Handle small amounts of data.""" 
    229         return 1 + ord(self.minfile[prevpos]) 
    230          
    231     def embeddedData(self, prevpos) : 
     224        return 1 + ord(self.minfile[nextpos]) 
     225         
     226    def embeddedData(self, nextpos) : 
    232227        """Handle normal amounts of data.""" 
    233         return 4 + unpack(self.unpackLong, self.minfile[prevpos:prevpos+4])[0] 
    234          
    235     def littleEndian(self, prevpos) : 
     228        return 4 + unpack(self.unpackLong, self.minfile[nextpos:nextpos+4])[0] 
     229         
     230    def littleEndian(self, nextpos) : 
    236231        """Toggles to little endianness.""" 
    237         self.unpackShort = "<H" 
    238         self.unpackLong = "<I" 
     232        self.unpackType = { 1 : "B", 2 : "<H", 4 : "<I" } 
     233        self.unpackShort = self.unpackType[2] 
     234        self.unpackLong = self.unpackType[4] 
    239235        return 0 
    240236         
    241     def bigEndian(self, prevpos) : 
     237    def bigEndian(self, nextpos) : 
    242238        """Toggles to big endianness.""" 
    243         self.unpackShort = ">H" 
    244         self.unpackLong = ">I" 
     239        self.unpackType = { 1 : "B", 2 : ">H", 4 : ">I" } 
     240        self.unpackShort = self.unpackType[2] 
     241        self.unpackLong = self.unpackType[4] 
    245242        return 0 
    246243     
    247     def reservedForFutureUse(self, prevpos) : 
     244    def reservedForFutureUse(self, nextpos) : 
    248245        """Outputs something when a reserved byte is encountered.""" 
    249         self.logdebug("Byte at %x is out of the PCLXL Protocol Class 2.0 Specification" % prevpos) 
     246        self.logdebug("Byte at %x is out of the PCLXL Protocol Class 2.0 Specification" % nextpos) 
    250247        return 0     
    251248         
    252     def x46_class3(self, prevpos) : 
     249    def x46_class3(self, nextpos) : 
    253250        """Undocumented tag 0x46 in class 3.0 streams.""" 
    254         pos = prevpos 
     251        pos = nextpos - 3 
    255252        minfile = self.minfile 
    256         while pos > 0 : # safety check : don't go back to far ! 
     253        val = ord(minfile[pos]) 
     254        while val == 0xf8 : 
     255            funcid = ord(minfile[pos+1]) 
     256            try : 
     257                offset = self.x46_functions[funcid] 
     258            except KeyError :     
     259                self.logdebug("Unexpected subfunction 0x%02x for undocumented tag 0x46 at %x" % (funcid, nextpos)) 
     260                break 
     261            else :     
     262                length = self.tags[ord(self.minfile[pos-offset])] 
     263                if callable(length) : 
     264                    length = length(pos-offset+1) 
     265                pos -= offset     
     266                if funcid == 0x92 :     
     267                    try : 
     268                        return unpack(self.unpackType[length], self.minfile[pos+1:pos+length+1])[0] 
     269                    except KeyError : 
     270                        raise pdlparser.PDLParserError, "Error on size '%s' at %x" % (length, pos+1) 
    257271            val = ord(minfile[pos]) 
    258             if (val == 0xf8) and (ord(minfile[pos+1]) in (0x95, 0x96)) : 
    259                 pos += 2 
    260                 datatype = ord(self.minfile[pos]) 
    261                 if datatype == 0x46 : 
    262                     break 
    263                 pos += 1 
    264                 length = self.tags[datatype] 
    265                 posl = pos + length 
    266                 if length == 1 :     
    267                     return unpack("B", self.minfile[pos:posl])[0] 
    268                 elif length == 2 :     
    269                     return unpack(self.unpackShort, self.minfile[pos:posl])[0] 
    270                 elif length == 4 :     
    271                     return unpack(self.unpackLong, self.minfile[pos:posl])[0] 
    272                 else :     
    273                     raise pdlparser.PDLParserError, "Error on size at %x" % prevpos 
    274             else :     
    275                 pos -= 1 
    276272        return 0     
    277273         
    278     def escape(self, prevpos) :     
     274    def escape(self, nextpos) :     
    279275        """Handles the ESC code.""" 
    280         pos = endpos = prevpos 
     276        pos = endpos = nextpos 
    281277        minfile = self.minfile 
    282278        if minfile[pos : pos+8] == r"%-12345X" : 
     
    298294        return endpos - pos 
    299295         
    300     def skipKyoceraPrescribe(self, prevpos) : 
     296    def skipKyoceraPrescribe(self, nextpos) : 
    301297        """Skips Kyocera Prescribe commands.""" 
    302         pos = prevpos - 1 
     298        pos = nextpos - 1 
    303299        minfile = self.minfile 
    304300        if minfile[pos:pos+3] == "!R!" : 
    305             while (pos - prevpos) < 1024 :   # This is a realistic upper bound, to avoid infinite loops 
     301            while (pos - nextpos) < 1024 :   # This is a realistic upper bound, to avoid infinite loops 
    306302                if (minfile[pos] == ";") and (minfile[pos-4:pos] == "EXIT") : 
    307303                    pos += 1 
    308304                    prescribe = self.prescribeStuff.setdefault(self.pagecount, []) 
    309                     prescribe.append(minfile[prevpos-1:pos]) 
    310                     self.logdebug("Prescribe commands : [%s]" % repr(minfile[prevpos-1:pos])) 
    311                     return (pos - prevpos) 
     305                    prescribe.append(minfile[nextpos-1:pos]) 
     306                    self.logdebug("Prescribe commands : [%s]" % repr(minfile[nextpos-1:pos])) 
     307                    return (pos - nextpos) 
    312308                pos += 1     
    313309        else : 
     
    509505        self.setNumberOfCopies = "".join([chr(0xf8), chr(0x31)])  
    510506         
     507        # subcodes for undocumented tag 0x46 and the negative 
     508        # offset to grab the value from. 
     509        self.x46_functions = { 0x91 : 5, 
     510                               0x92 : 5, 
     511                               0x93 : 3, 
     512                               0x94 : 3, 
     513                               0x95 : 5, 
     514                               0x96 : 2, 
     515                               0x97 : 2, 
     516                               0x98 : 2, 
     517                             } 
     518                              
    511519        infileno = self.infile.fileno() 
    512520        self.pages = { 0 : { "copies" : 1,  
  • pkpgcounter/trunk/pkpgpdls/version.py

    r316 r318  
    2020# 
    2121 
    22 __version__ = "1.77beta" 
     22__version__ = "1.77" 
    2323 
    2424__doc__ = """pkpgcounter : a generic Page Description Languages parser."""