示例#1
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // p r o c e s s F o n t H e a d e r                                  //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Provide an interpretation of the contents of the initial part of   //
        // the font header.                                                   //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void processFontHeader(ref Int32 bufLen,
                                       ref Int32 bufOffset)
        {
            Char c;

            Int32 ix1,
                  ix2,
                  ix3;

            Int32 indxSymSet;

            String itemDesc;

            //----------------------------------------------------------------//
            //                                                                //
            // Show size and (optionally) data.                               //
            //                                                                //
            //----------------------------------------------------------------//

            PrnParseCommon.addDataRow(
                PrnParseRowTypes.eType.DataBinary,
                _table,
                PrnParseConstants.eOvlShow.None,
                _indxOffsetFormat,
                _fileOffset + bufOffset,
                _analysisLevel,
                "PCLXL Binary",
                "[ " + _cHddrDescLen.ToString() + " bytes ]",
                "Font header");

            if (_showBinData)
            {
                PrnParseData.processBinary(
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    _buf,
                    _fileOffset,
                    bufOffset,
                    _cHddrDescLen,
                    "",
                    _showBinData,
                    false,
                    true,
                    _indxOffsetFormat,
                    _analysisLevel);
            }

            //----------------------------------------------------------------//
            //                                                                //
            // Determine the Header Format, and from this determine the       //
            // position and size of parts of the header following the         //
            // Descriptor.                                                    //
            //                                                                //
            //----------------------------------------------------------------//

            _hddrFormat = (ePCLXLFontFormat)_buf[bufOffset];

            if (_hddrFormat == ePCLXLFontFormat.Download)
            {
                //------------------------------------------------------------//
                //                                                            //
                // Format 0 - Only format supported (as at v3.0).             //
                //                                                            //
                //------------------------------------------------------------//

                _hddrDataLen = _hddrLen - _cHddrDescLen;
                _hddrDataRem = _hddrDataLen;
            }
            else
            {
                //------------------------------------------------------------//
                //                                                            //
                // Unknown format.                                            //
                //                                                            //
                //------------------------------------------------------------//

                _validHddr = false;

                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.MsgWarning,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "*** Warning ***",
                    "",
                    "Header format (" + _hddrFormat + ") is not recognised");
            }

            if (!_validHddr)
            {
                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.MsgWarning,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "*** Warning ***",
                    "",
                    "Processing of Font Header abandoned");
            }
            else
            {
                //------------------------------------------------------------//
                //                                                            //
                // Header format (byte 0).                                    //
                //                                                            //
                //------------------------------------------------------------//

                switch (_hddrFormat)
                {
                case ePCLXLFontFormat.Download:
                    itemDesc = "0: PCLXL Download";
                    break;

                default:
                    itemDesc = _hddrFormat + ": Unknown";
                    break;
                }

                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.PCLXLFontHddr,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "Header Format:",
                    "",
                    itemDesc);

                //------------------------------------------------------------//
                //                                                            //
                // Orientation (byte 1).                                      //
                //                                                            //
                //    0 = Portrait                                            //
                //    1 = Landscape                                           //
                //    2 = Reverse Portrait                                    //
                //    3 = Reverse Landscape                                   //
                //                                                            //
                //------------------------------------------------------------//

                ix1 = _buf[bufOffset + 1];

                switch (ix1)
                {
                case 0:
                    itemDesc = "0: Portrait";
                    break;

                case 1:
                    itemDesc = "1: Landscape";
                    break;

                case 2:
                    itemDesc = "2: Reverse Portrait";
                    break;

                case 3:
                    itemDesc = "3: Reverse Landscape";
                    break;

                default:
                    itemDesc = ix1 + ": Unknown";
                    break;
                }

                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.PCLXLFontHddr,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "Orientation:",
                    "",
                    itemDesc);

                //------------------------------------------------------------//
                //                                                            //
                // Mapping (bytes 2-3).                                       //
                //                                                            //
                // Two part: 11-bit number (binary).                          //
                //            5-bit letter-code: add 64 to this to obtain the //
                //                  (ASCII) character-code of the letter.     //
                //                                                            //
                // e.g. value of  0x000E --> 0N                               //
                //                0x0115 --> 8U                               //
                //                0x0155 --> 10U                              //
                //                0x01F1 --> 15Q                              //
                //                                                            //
                // Symbol sets where the letter part equates to 'Q' are       //
                // reserved for 'Specials'.                                   //
                //                                                            //
                //------------------------------------------------------------//

                ix1 = (_buf[bufOffset + 2] * 256) + _buf[bufOffset + 3];

                ix2 = ix1 >> 5;
                ix3 = (ix1 & 0x1f) + 64;
                c   = (Char)ix3;

                indxSymSet =
                    PCLSymbolSets.getIndexForId((UInt16)ix1);

                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.PCLXLFontHddr,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "Mapping:",
                    "Kind1 value:",
                    ix1.ToString() + " (0x" + ix1.ToString("x2") + ")");

                if ((indxSymSet) == -1)
                {
                    PrnParseCommon.addTextRow(
                        PrnParseRowTypes.eType.PCLXLFontHddr,
                        _table,
                        PrnParseConstants.eOvlShow.None,
                        "",
                        "     ---->",
                        "Identifier:",
                        ix2.ToString() + c);
                }
                else
                {
                    PrnParseCommon.addTextRow(
                        PrnParseRowTypes.eType.PCLXLFontHddr,
                        _table,
                        PrnParseConstants.eOvlShow.None,
                        "",
                        "     ---->",
                        "Identifier:",
                        ix2.ToString() + c +
                        " (" + PCLSymbolSets.getName(indxSymSet) + ")");
                }

                //------------------------------------------------------------//
                //                                                            //
                // Scaling Technology (byte 4).                               //
                //         Variety    (byte 5).    Expected to be zero.       //
                //                                                            //
                //------------------------------------------------------------//

                ePCLXLFontTechnology scaling =
                    (ePCLXLFontTechnology)_buf[bufOffset + 4];
                ix2 = _buf[bufOffset + 5];

                switch (scaling)
                {
                case ePCLXLFontTechnology.TrueType:
                    itemDesc = "1: TrueType";
                    break;

                case ePCLXLFontTechnology.Bitmap:
                    itemDesc = "254: Bitmap";
                    break;

                default:
                    itemDesc = scaling.ToString() + ": Unknown";
                    break;
                }

                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.PCLXLFontHddr,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "Scaling:",
                    "Technology:",
                    itemDesc);


                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.PCLXLFontHddr,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "",
                    "Variety:",
                    ix2.ToString());

                //----------------------------------------------------------------------//
                //                                                                      //
                // Number of Characters (bytes 6-7).                                    //
                //                                                                      //
                //----------------------------------------------------------------------//

                ix1 = (_buf[bufOffset + 6] * 256) + _buf[bufOffset + 7];


                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.PCLXLFontHddr,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "Character Count:",
                    "",
                    ix1.ToString());
            }
        }
示例#2
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // a n a l y s e F o n t H d d r                                      //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Provide an interpretation of the contents of a PCL XL soft font    //
        // header.                                                            //
        //                                                                    //
        //--------------------------------------------------------------------//

        public Boolean analyseFontHddr(Int32 hddrLen,
                                       Byte []          buf,
                                       Int32 fileOffset,
                                       ref Int32 bufRem,
                                       ref Int32 bufOffset,
                                       PrnParseLinkData linkData,
                                       PrnParseOptions options,
                                       DataTable table)
        {
            Int32   binDataLen;
            Boolean validSegs = false;

            PrnParseConstants.eContType contType;

            Boolean continuation = false;

            //----------------------------------------------------------------//
            //                                                                //
            // Initialise.                                                    //
            //                                                                //
            //----------------------------------------------------------------//

            _table      = table;
            _buf        = buf;
            _fileOffset = fileOffset;

            _analysisLevel = linkData.AnalysisLevel;

            _options = options;

            contType = linkData.getContType();

            _indxOffsetFormat = _options.IndxGenOffsetFormat;

            _showBinData = _options.FlagPCLXLMiscBinData;

            //----------------------------------------------------------------//

            if (contType == PrnParseConstants.eContType.None)
            {
                _nextStage = eStage.Start;
                _validHddr = true;
                _firstSeg  = true;

                _hddrLen = hddrLen;
                _hddrRem = hddrLen;
                _hddrPos = fileOffset + bufOffset;
            }
            else
            {
                contType = PrnParseConstants.eContType.None;
                linkData.resetContData();
            }

            //----------------------------------------------------------------//

            if (_nextStage == eStage.Start)
            {
                if (bufRem < _cHddrDescLen)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Font header descriptor is not all in buffer.           //
                    // Initiate continuation.                                 //
                    //                                                        //
                    //--------------------------------------------------------//

                    contType = PrnParseConstants.eContType.PCLXLFontHddr;

                    linkData.setBacktrack(contType, -bufRem);
                }
                else
                {
                    _nextStage = eStage.ShowHddr;
                }
            }

            if (_nextStage == eStage.ShowHddr)
            {
                //------------------------------------------------------------//
                //                                                            //
                // Process font header.                                       //
                //                                                            //
                //------------------------------------------------------------//

                processFontHeader(ref bufRem,
                                  ref bufOffset);

                bufRem    = bufRem - _cHddrDescLen;
                _hddrRem  = _hddrRem - _cHddrDescLen;
                bufOffset = bufOffset + _cHddrDescLen;

                if (_validHddr)
                {
                    _nextStage = eStage.ShowData;
                }
                else
                {
                    _nextStage = eStage.BadSeqA;
                }
            }

            if (_nextStage == eStage.ShowData)
            {
                //------------------------------------------------------------//
                //                                                            //
                // Output details of segmented data:                          //
                //                                                            //
                //------------------------------------------------------------//

                Int32 dummy = 0;

                continuation = _parseSegs.processSegData(_buf,
                                                         _fileOffset,
                                                         false,
                                                         _firstSeg,
                                                         true,
                                                         ref bufRem,
                                                         ref bufOffset,
                                                         ref _hddrDataRem,
                                                         ref _hddrRem,
                                                         ref dummy,
                                                         ref validSegs,
                                                         linkData,
                                                         _options,
                                                         _table);

                _firstSeg = false;
            }

            if (_nextStage == eStage.EndOK)
            {
                //------------------------------------------------------------//
                //                                                            //
                // End of processing of valid header.                         //
                //                                                            //
                //------------------------------------------------------------//

                return(_validHddr);
            }

            if (_nextStage == eStage.BadSeqA)
            {
                //------------------------------------------------------------//
                //                                                            //
                // Inconsistency found.                                       //
                //                                                            //
                //------------------------------------------------------------//

                _nextStage = eStage.BadSeqB;

                PrnParseCommon.addTextRow(
                    PrnParseRowTypes.eType.MsgError,
                    _table,
                    PrnParseConstants.eOvlShow.None,
                    "",
                    "",
                    "",
                    "Processing of header abandoned!");
            }

            if ((_nextStage == eStage.BadSeqB) && (_hddrRem != 0))
            {
                //------------------------------------------------------------//
                //                                                            //
                // Header does not appear to be valid.                        //
                // Treat remainder of header as a binary sequence without     //
                // interpretation.                                            //
                // Check if remainder of download sequence is within the      //
                // buffer.                                                    //
                //                                                            //
                //------------------------------------------------------------//

                if (_hddrRem > bufRem)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Remainder of sequence is not in buffer.                //
                    // Initiate continuation.                                 //
                    //                                                        //
                    //--------------------------------------------------------//

                    contType = PrnParseConstants.eContType.PCLXLFontHddr;

                    binDataLen = bufRem;
                    _hddrRem   = _hddrRem - bufRem;

                    linkData.setContinuation(contType);
                }
                else
                {
                    contType = PrnParseConstants.eContType.None;
                    linkData.resetContData();

                    binDataLen = _hddrRem;
                    _hddrRem   = 0;
                }

                if ((binDataLen) != 0)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Some, or all, of the download data is contained within //
                    // the current 'block'.                                   //
                    //                                                        //
                    //--------------------------------------------------------//

                    PrnParseData.processBinary(
                        _table,
                        PrnParseConstants.eOvlShow.None,
                        buf,
                        fileOffset,
                        bufOffset,
                        binDataLen,
                        "PCLXL Binary",
                        _showBinData,
                        false,
                        true,
                        _indxOffsetFormat,
                        _analysisLevel);

                    bufRem    = bufRem - binDataLen;
                    bufOffset = bufOffset + binDataLen;
                }
            }

            return(_validHddr);
        }
示例#3
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // p a r s e S e q u e n c e s                                        //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Process sequences until end-point reached.                         //
        //                                                                    //
        //--------------------------------------------------------------------//

        private Boolean parseSequences(
            ref Int32 bufRem,
            ref Int32 bufOffset,
            ref ToolCommonData.ePrintLang crntPDL,
            ref Boolean endReached)
        {
            Int64 startPos;

            PrnParseConstants.eContType contType =
                PrnParseConstants.eContType.None;

            Boolean continuation    = false;
            Boolean langSwitch      = false;
            Boolean badSeq          = false;
            Boolean invalidSeqFound = false;
            Boolean dummyBool       = false;

            continuation = false;
            startPos     = _fileOffset + bufOffset;

            while (!continuation && !langSwitch &&
                   !endReached && (bufRem > 0))
            {
                //------------------------------------------------------------//
                //                                                            //
                // Process data until language-switch or end of buffer, or    //
                // specified end point.                                       //
                //                                                            //
                //------------------------------------------------------------//

                if ((_endOffset != -1) &&
                    ((_fileOffset + bufOffset) > _endOffset))
                {
                    endReached = true;
                }
                else if (_buf[bufOffset] == PrnParseConstants.asciiEsc)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Escape character found.                                //
                    // Switch to PCL language processing.                     //
                    //                                                        //
                    // Note that, in theory, only a few escape sequences are  //
                    // expected:                                              //
                    //      <Esc>E          Printer Reset                     //
                    //      <Esc>%-12345X   Universal Exit Language           //
                    // but if we find an escape sequence, it's certainly not  //
                    // PJL.                                                   //
                    //                                                        //
                    //--------------------------------------------------------//

                    langSwitch = true;

                    crntPDL = ToolCommonData.ePrintLang.PCL;
                }
                else if (_buf[bufOffset] != PrnParseConstants.asciiAtSign)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Next character is NOT an @ symbol, so it can't be a    //
                    // PJL command.                                           //
                    // Switch to PCL language processing.                     //
                    //                                                        //
                    //--------------------------------------------------------//

                    langSwitch = true;

                    crntPDL = ToolCommonData.ePrintLang.PCL;
                }
                else
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Sequence does not start with an Escape character, so   //
                    // it should be a PJL command.                            //
                    // PJL commands should start with @PJL and end with a     //
                    // LineFeed (0x0a) character.                             //
                    //                                                        //
                    //--------------------------------------------------------//

                    if (bufRem < 5)
                    {
                        //----------------------------------------------------//
                        //                                                    //
                        // Insufficient characters remain in buffer to        //
                        // identify the sequence as PJL, so initiate a        //
                        // continuation action.                               //
                        //                                                    //
                        //----------------------------------------------------//

                        continuation = true;

                        contType = PrnParseConstants.eContType.PJL;

                        _linkData.setBacktrack(contType, -bufRem);
                    }
                    else if (_ascii.GetString(_buf, bufOffset, _lenPJLIntro)
                             != "@PJL")
                    {
                        //----------------------------------------------------//
                        //                                                    //
                        // Not a PJL sequence.                                //
                        // Display the unexpected sequence up to the next     //
                        // Escape character.                                  //
                        //                                                    //
                        //----------------------------------------------------//

                        invalidSeqFound = true;

                        PrnParseCommon.addTextRow(
                            PrnParseRowTypes.eType.MsgWarning,
                            _table,
                            PrnParseConstants.eOvlShow.None,
                            "",
                            "*** Warning ***",
                            "",
                            "Unexpected sequence found");

                        PrnParseData.processLines(
                            _table,
                            PrnParseConstants.eOvlShow.None,
                            _linkData,
                            ToolCommonData.ePrintLang.PJL,
                            _buf,
                            _fileOffset,
                            bufRem,
                            ref bufRem,
                            ref bufOffset,
                            ref dummyBool,
                            true,
                            true,
                            false,
                            PrnParseConstants.asciiEsc,
                            "Data",
                            0,
                            _indxCharSetSubAct,
                            (Byte)_valCharSetSubCode,
                            _indxCharSetName,
                            _indxOffsetFormat,
                            _analysisLevel);
                    }
                    else
                    {
                        //-------------------------------------------------------------//
                        //                                                             //
                        // PJL sequence detected.                                      //
                        //                                                             //
                        //-------------------------------------------------------------//

                        badSeq = processPJLCommand(ref bufRem,
                                                   ref bufOffset,
                                                   ref continuation,
                                                   ref langSwitch,
                                                   ref crntPDL);

                        if (badSeq)
                        {
                            invalidSeqFound = true;
                        }
                    }
                }
            }

            _linkData.MakeOvlAct       = PrnParseConstants.eOvlAct.Remove;
            _linkData.MakeOvlSkipBegin = startPos;
            _linkData.MakeOvlSkipEnd   = _fileOffset + bufOffset;

            return(invalidSeqFound);
        }
示例#4
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // p r o c e s s P J L C o m m a n d                                  //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Process current PJL command in buffer.                             //
        // Command format is one of:                                          //
        //                                                                    //
        //    @PJL [<CR>]<LF>                                                 //
        //                                                                    //
        //    Can be used to separate real commands, and add clarity to long  //
        //    sets of commands.                                               //
        //                                                                    //
        //    @PJL command [<words>] [<CR>}<LF>                               //
        //                                                                    //
        //    For the COMMENT and ECHO commands only.                         //
        //    <words>               Any string of printable characters        //
        //                          (range 0x21-0xff) or whitespace           //
        //                          (space (0x20) or horizontal tab (0x09)),  //
        //                          starting with a printable character.      //
        //                          The string may be enclosed in quote       //
        //                          characters (0x22), in which case it       //
        //                          cannot include a quote character.         //
        //                                                                    //
        //    @PJL command [modifier : value] [option [= value]] [<CR>}<LF>   //
        //                                                                    //
        //    command               One of the defined set of command names.  //
        //    modifier:value        is present for some commands to indicate  //
        //                          particular personality, or port, etc.     //
        //    option                Present for most commands.                //
        //    value                 Associated with 'option' name or (if      //
        //                          that is not present, the command).        //
        //                          There may be more than one option=value   //
        //                          pair.                                     //
        //                                                                    //
        // Whitespace (space or horizontal tab) characters MUST be present    //
        // between the @PJL introducer and the 'command', and between the     //
        // command and modifier names, and between the modifier value and the //
        // option name.                                                       //
        //                                                                    //
        // Interrupt process if an <Esc> character is encountered.            //
        // Long lines are split into shorter slices.                          //
        //                                                                    //
        //--------------------------------------------------------------------//

        private Boolean processPJLCommand(
            ref Int32 bufRem,
            ref Int32 bufOffset,
            ref Boolean continuation,
            ref Boolean langSwitch,
            ref ToolCommonData.ePrintLang crntPDL)
        {
            PrnParseConstants.eContType contType =
                PrnParseConstants.eContType.None;

            Byte crntByte;

            Char crntChar,
                 normChar;

            Int32 len,
                  cmdLen,
                  cmdRem,
                  langLen,
                  offset,
                  lineStart,
                  seqLen = 0;

            Int32 quoteStart = 0,
                  quoteEnd   = 0;

            Boolean invalidSeqFound,
                    endLoop,
                    foundTerm,
                    firstLine;

            Boolean foundStartQuote;
            Boolean seqKnown     = false;
            Boolean noWhitespace = false;

            String lang,
                   commandName,
                   commandParams,
                   line,
                   showChar,
                   desc = "";

            StringBuilder seq = new StringBuilder();

            StringBuilder cmd = new StringBuilder();

            StringBuilder cmdPart1 = new StringBuilder();
            StringBuilder cmdPart2 = new StringBuilder();

            cmdPart1.Append("@PJL");

            invalidSeqFound = false;
            foundStartQuote = false;
            foundTerm       = false;
            firstLine       = true;
            langSwitch      = false;

            lineStart = bufOffset;
            foundTerm = false;

            len    = bufRem;
            offset = bufOffset;

            continuation = false;
            foundTerm    = false;

            cmdRem = bufRem - _lenPJLIntro;
            offset = bufOffset + _lenPJLIntro;
            cmdLen = _lenPJLIntro;

            //----------------------------------------------------------------//
            //                                                                //
            // Search for termination character.                              //
            // This should be a LineFeed (<LF>, 0x0a) character, but may be   //
            // an Escape character (<Esc>, 0x1b) signalling return to PCL.    //
            //                                                                //
            // This is to make sure that the termination character is in the  //
            // buffer before processing the command, so that we don't have to //
            // cater for doing a 'continuation' read part way through         //
            // processing the command.                                        //
            //                                                                //
            // Initiate continuation action if terminator is not found in     //
            // buffer, subject to a maximum command length (to prevent        //
            // recursive continuation actions).                               //
            //                                                                //
            //----------------------------------------------------------------//

            while ((!foundTerm) && (cmdRem > 0) && (cmdLen < _maxPJLCmdLen))
            {
                crntByte = _buf[offset];

                if (crntByte == PrnParseConstants.asciiLF)
                {
                    foundTerm = true;
                    offset++;
                    cmdLen++;
                    cmdRem--;
                }
                else if (crntByte == PrnParseConstants.asciiEsc)
                {
                    foundTerm = true;
                }
                else
                {
                    offset++;
                    cmdLen++;
                    cmdRem--;
                }
            }

            if ((!foundTerm) && (cmdLen != _maxPJLCmdLen))              // ***** Should this be < rather than != ? ***** //
            {
                //------------------------------------------------------------//
                //                                                            //
                // Termination character not found before buffer exhausted,   //
                // or maximum command length exceeded.                        //
                // Initiate (backtracking) continuation action.               //
                //                                                            //
                //------------------------------------------------------------//

                continuation = true;

                contType = PrnParseConstants.eContType.PJL;

                _linkData.setBacktrack(contType, -bufRem);
            }
            else
            {
                //------------------------------------------------------------//
                //                                                            //
                // Process command.                                           //
                // At this point, we have in the buffer one of:               //
                //  - characters terminated by <LF> (counted in length).      //
                //  - characters terminated by <Esc> (not counted in length). //
                //  - characters not terminated, but maxmimum length.         //
                //                                                            //
                //------------------------------------------------------------//

                cmdRem = cmdLen - _lenPJLIntro;
                offset = bufOffset + _lenPJLIntro;

                //------------------------------------------------------------//
                //                                                            //
                // Stage 1: look for & skip past whitespace.                  //
                //                                                            //
                //------------------------------------------------------------//

                endLoop = false;

                while ((!endLoop) && (cmdRem > 0))
                {
                    crntByte = _buf[offset];

                    if ((crntByte == PrnParseConstants.asciiSpace)
                        ||
                        (crntByte == PrnParseConstants.asciiHT))
                    {
                        showChar = PrnParseData.processByte(
                            crntByte,
                            _indxCharSetSubAct,
                            (Byte)_valCharSetSubCode,
                            _indxCharSetName);

                        cmdPart1.Append(showChar);

                        offset++;
                        cmdRem--;
                    }
                    else
                    {
                        endLoop = true;
                    }
                }

                //------------------------------------------------------------//
                //                                                            //
                // Stage 2: look for command name.                            //
                //                                                            //
                //------------------------------------------------------------//

                endLoop = false;

                while ((!endLoop) && (cmdRem > 0))
                {
                    crntByte = _buf[offset];

                    //--------------------------------------------------------//
                    //                                                        //
                    // Check for special characters first.                    //
                    //                                                        //
                    //--------------------------------------------------------//

                    if ((crntByte == PrnParseConstants.asciiSpace)
                        ||
                        (crntByte == PrnParseConstants.asciiHT))
                    {
                        // nextstage = Whitespace;
                        endLoop = true;
                    }
                    else if ((cmdRem == 2) &&
                             (crntByte == PrnParseConstants.asciiCR))

                    {
                        // nextstage = Terminator;
                        endLoop = true;
                    }
                    else if ((cmdRem == 1) &&
                             (crntByte == PrnParseConstants.asciiLF))

                    {
                        // nextstage = Terminator;
                        endLoop = true;
                    }
                    else if (crntByte == PrnParseConstants.asciiEquals)

                    {
                        // nextstage = Part2;
                        endLoop      = true;
                        noWhitespace = true;
                    }
                    else
                    {
                        crntChar = (Char)crntByte;
                        normChar = Char.ToUpper(crntChar);
                        cmd.Append(normChar);

                        showChar = PrnParseData.processByte(
                            crntByte,
                            _indxCharSetSubAct,
                            (Byte)_valCharSetSubCode,
                            _indxCharSetName);

                        cmdPart1.Append(showChar);

                        offset++;
                        cmdRem--;
                    }
                }

                //------------------------------------------------------------//
                //                                                            //
                // Check whether command name known.                          //
                //                                                            //
                //------------------------------------------------------------//

                commandName = cmd.ToString();

                if (commandName == "")
                {
                    seqKnown = PJLCommands.checkCmd(PJLCommands.nullCmdKey,
                                                    ref desc,
                                                    _analysisLevel);
                }
                else
                {
                    seqKnown = PJLCommands.checkCmd(cmd.ToString(),
                                                    ref desc,
                                                    _analysisLevel);
                }

                //------------------------------------------------------------//
                //                                                            //
                // Stage 3: look for command remainder.                       //
                //          TODO : split this up into component parts?        //
                //                                                            //
                //------------------------------------------------------------//

                endLoop = false;

                while ((!endLoop) && (cmdRem > 0))
                {
                    crntByte = _buf[offset];

                    if (crntByte == PrnParseConstants.asciiQuote)
                    {
                        if (!foundStartQuote)
                        {
                            foundStartQuote = true;
                            quoteStart      = offset;
                        }
                        else
                        {
                            quoteEnd = offset;
                        }
                    }

                    crntChar = (Char)crntByte;
                    normChar = Char.ToUpper(crntChar);

                    showChar = PrnParseData.processByte(
                        crntByte,
                        _indxCharSetSubAct,
                        (Byte)_valCharSetSubCode,
                        _indxCharSetName);

                    cmdPart2.Append(showChar);

                    if ((crntByte == PrnParseConstants.asciiSpace)
                        ||
                        (crntByte == PrnParseConstants.asciiHT))
                    {
                    }
                    else if ((crntByte == PrnParseConstants.asciiDEL)
                             ||
                             (crntByte < PrnParseConstants.asciiSpace))
                    {
                        seq.Append((Char)PrnParseConstants.asciiPeriod);
                    }
                    else
                    {
                        seq.Append(normChar);
                    }

                    offset++;
                    cmdRem--;
                }

                //--------------------------------------------------------//
                //                                                        //
                // Stage 4: Output details of sequence.                   //
                //                                                        //
                //--------------------------------------------------------//

                commandParams = cmdPart2.ToString();

                len       = commandParams.Length;
                lineStart = 0;

                while ((firstLine) || (len > 0))
                {
                    if (len > _maxPJLLineLen)
                    {
                        line = commandParams.Substring(lineStart,
                                                       _maxPJLLineLen);
                        len       -= _maxPJLLineLen;
                        lineStart += _maxPJLLineLen;
                    }
                    else
                    {
                        line = commandParams.Substring(lineStart,
                                                       len);
                        len = 0;
                    }

                    if (firstLine)
                    {
                        firstLine = false;

                        if (!seqKnown)
                        {
                            PrnParseCommon.addTextRow(
                                PrnParseRowTypes.eType.MsgWarning,
                                _table,
                                PrnParseConstants.eOvlShow.None,
                                "",
                                "*** Warning ***",
                                "",
                                "Following PJL commmand name not recognised:");
                        }

                        if (noWhitespace)
                        {
                            PrnParseCommon.addTextRow(
                                PrnParseRowTypes.eType.MsgWarning,
                                _table,
                                PrnParseConstants.eOvlShow.None,
                                "",
                                "*** Warning ***",
                                "",
                                "Following PJL command name not terminated" +
                                " by space or tab character:");
                        }

                        PrnParseCommon.addDataRow(
                            PrnParseRowTypes.eType.PJLCommand,
                            _table,
                            PrnParseConstants.eOvlShow.Remove,
                            _indxOffsetFormat,
                            _fileOffset + bufOffset,
                            _analysisLevel,
                            "PJL Command",
                            cmdPart1.ToString(),
                            line);
                    }
                    else
                    {
                        PrnParseCommon.addTextRow(
                            PrnParseRowTypes.eType.PJLCommand,
                            _table,
                            PrnParseConstants.eOvlShow.Remove,
                            "",
                            "",
                            "",
                            line);
                    }
                }

                //--------------------------------------------------------//
                //                                                        //
                // Stage 5: Do any special processing.                    //
                //                                                        //
                //--------------------------------------------------------//

                commandParams = seq.ToString();

                if ((commandName.Length == 5)
                    &&
                    (commandName.Substring(0, 5) == "ENTER")
                    &&
                    (commandParams.Length > 9)
                    &&
                    (commandParams.Substring(0, 9) == "LANGUAGE="))
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Enter Language command encountered.                    //
                    //                                                        //
                    //--------------------------------------------------------//

                    langSwitch = true;

                    seqLen = seq.Length;

                    lang = commandParams.Substring(9, seqLen - 9);

                    langLen = lang.Length;

                    if ((langLen >= 5) &&
                        (lang.Substring(0, 5) == "PCLXL"))
                    {
                        crntPDL = ToolCommonData.ePrintLang.PCLXL;
                    }
                    else if ((langLen >= 7) &&
                             (lang.Substring(0, 7) == "PCL3GUI"))
                    {
                        crntPDL = ToolCommonData.ePrintLang.PCL3GUI;
                    }
                    else if ((langLen >= 3) &&
                             (lang.Substring(0, 3) == "PCL"))
                    {
                        crntPDL = ToolCommonData.ePrintLang.PCL;
                    }
                    else if ((langLen >= 10) &&
                             (lang.Substring(0, 10) == "POSTSCRIPT"))
                    {
                        crntPDL = ToolCommonData.ePrintLang.PostScript;
                    }
                    else if ((langLen >= 4) &&
                             (lang.Substring(0, 4) == "HPGL"))
                    {
                        crntPDL = ToolCommonData.ePrintLang.HPGL2;
                    }
                    else if ((langLen >= 5) &&
                             (lang.Substring(0, 5) == "XL2HB"))
                    {
                        crntPDL = ToolCommonData.ePrintLang.XL2HB;
                    }
                    else
                    {
                        crntPDL = ToolCommonData.ePrintLang.Unknown;
                    }
                }
                else if ((_showPML) &&
                         (((commandName.Length == 5)
                           &&
                           (commandName.Substring(0, 5) == "DMCMD"))
                          ||
                          ((commandName.Length == 6)
                           &&
                           (commandName.Substring(0, 6) == "DMINFO"))))
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // PML Device Management                                  //
                    //                                                        //
                    //--------------------------------------------------------//

                    if ((commandParams.Length > 9)
                        &&
                        (commandParams.Substring(0, 9) == "ASCIIHEX="))
                    {
                        //----------------------------------------------------//
                        //                                                    //
                        // PML sequence; encoded as ASCII HEX.                //
                        // Expected to be enclosed in " quotes and followed   //
                        // by <CR><LF> or <LF> PJL terminator characters.     //
                        // Note that the normalised sequence will have "."    //
                        // characters in place of the <CR> and <LF> control   //
                        // codes.                                             //
                        //                                                    //
                        //----------------------------------------------------//

                        PrnParsePML parsePML = new PrnParsePML();

                        seqLen = quoteEnd - quoteStart - 1;

                        if (seqLen > 0)
                        {
                            invalidSeqFound =
                                parsePML.processPMLASCIIHex(_buf,
                                                            _fileOffset,
                                                            seqLen,
                                                            quoteStart + 1,
                                                            _linkData,
                                                            _options,
                                                            _table);
                        }
                    }
                }

                bufOffset = offset;
                bufRem   -= cmdLen;
            }

            return(invalidSeqFound);
        }
示例#5
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // p r o c e s s C o m m a n d                                        //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Process current Prescribe command in buffer.                       //
        //                                                                    //
        // Interrupt process if an <Esc> character is encountered.            //
        // Long commands are split into shorter slices.                       //
        //                                                                    //
        //--------------------------------------------------------------------//

        private Boolean processCommand(
            ref Int32 bufRem,
            ref Int32 bufOffset,
            ref Boolean continuation,
            ref Boolean langSwitch,
            ref ToolCommonData.ePrintLang crntPDL)
        {
            PrnParseConstants.eContType contType =
                PrnParseConstants.eContType.None;

            Byte crntByte,
                 cmdParaByte1 = 0x3f;

            Char crntChar,
                 normChar;

            Int32 len,
                  cmdLen,
                  cmdRem,
                  cmdStart,
                  offset,
                  lineStart;

            Int32 quoteStart = 0,
                  quoteEnd   = 0;

            Boolean invalidSeqFound,
                    cmdParaByte1Found,
                    endLoop,
                    foundTerm;

            //  Boolean flagWithinQuote;
            Boolean flagWithinQuoteDouble;
            Boolean flagWithinQuoteSingle;
            Boolean cmdKnown      = false;
            Boolean flagCmdExit   = false;
            Boolean flagCmdSetCRC = false;

            String command,
                   commandName,
                   commandDesc = "";

            StringBuilder cmd = new StringBuilder();

            invalidSeqFound = false;
            foundTerm       = false;
            langSwitch      = false;

            lineStart = bufOffset;
            foundTerm = false;

            len    = bufRem;
            offset = bufOffset;

            continuation = false;
            foundTerm    = false;

            cmdRem   = bufRem;
            cmdStart = offset;
            cmdLen   = 0;

            //----------------------------------------------------------------//
            //                                                                //
            // Search for termination character.                              //
            // This should be a Semi-colon (0x3b) character.                  //
            // But we may encounter an Escape character (<Esc>, 0x1b)         //
            // signalling return to PCL?                                      //
            //                                                                //
            // This is to make sure that the termination character is in the  //
            // buffer before processing the command, so that we don't have to //
            // cater for doing a 'continuation' read part way through         //
            // processing the command.                                        //
            //                                                                //
            // Initiate continuation action if terminator is not found in     //
            // buffer, subject to a maximum command length (to prevent        //
            // recursive continuation actions).                               //
            //                                                                //
            //----------------------------------------------------------------//

            //  flagWithinQuote = false;
            flagWithinQuoteDouble = false;
            flagWithinQuoteSingle = false;

            while ((!foundTerm) && (cmdRem > 0) && (cmdLen < _maxCmdLen))
            {
                crntByte = _buf[offset];

                if (crntByte == PrnParseConstants.asciiEsc)
                {
                    foundTerm = true;
                }
                else
                {
                    if (flagWithinQuoteDouble)
                    {
                        if (crntByte == PrnParseConstants.asciiQuote)
                        {
                            flagWithinQuoteDouble = false;
                            //  flagWithinQuote = false;
                            quoteEnd = offset;
                        }
                    }
                    else if (flagWithinQuoteSingle)
                    {
                        if (crntByte == PrnParseConstants.asciiApostrophe)
                        {
                            flagWithinQuoteSingle = false;
                            //  flagWithinQuote = false;
                            quoteEnd = offset;
                        }
                    }
                    else if (crntByte == PrnParseConstants.asciiQuote)
                    {
                        flagWithinQuoteDouble = true;
                        //  flagWithinQuote = true;
                        quoteStart = offset;
                    }
                    else if (crntByte == PrnParseConstants.asciiApostrophe)
                    {
                        flagWithinQuoteSingle = true;
                        //  flagWithinQuote = true;
                        quoteStart = offset;
                    }
                    else if (crntByte == PrnParseConstants.asciiSemiColon)
                    {
                        foundTerm = true;
                    }

                    offset++;
                    cmdLen++;
                    cmdRem--;
                }
            }

            if ((!foundTerm) && (cmdLen < _maxCmdLen))
            {
                //------------------------------------------------------------//
                //                                                            //
                // Termination character not found before buffer exhausted,   //
                // or maximum command length exceeded.                        //
                // Initiate (backtracking) continuation action.               //
                //                                                            //
                //------------------------------------------------------------//

                continuation = true;

                contType = PrnParseConstants.eContType.Prescribe;

                _linkData.setBacktrack(contType, -bufRem);
            }
            else
            {
                //------------------------------------------------------------//
                //                                                            //
                // Process command.                                           //
                // At this point, we have in the buffer one of:               //
                //  - characters terminated by <semi-colon> (counted in       //
                //    length).                                                //
                //  - characters terminated by <Esc> (not counted in length). //
                //  - characters not terminated, but maxmimum length.         //
                //                                                            //
                //------------------------------------------------------------//

                cmdRem = cmdLen;
                offset = bufOffset;

                //------------------------------------------------------------//
                //                                                            //
                // Stage 1: look for & skip past whitespace.                  //
                //                                                            //
                //------------------------------------------------------------//

                endLoop = false;

                while ((!endLoop) && (cmdRem > 0))
                {
                    crntByte = _buf[offset];

                    if ((crntByte == PrnParseConstants.asciiSpace)
                        ||
                        (crntByte == PrnParseConstants.asciiHT))
                    {
                        offset++;
                        cmdRem--;
                    }
                    else if ((crntByte == PrnParseConstants.asciiCR)
                             ||
                             (crntByte == PrnParseConstants.asciiLF))
                    {
                        offset++;
                        cmdRem--;
                    }
                    else
                    {
                        endLoop = true;
                    }
                }

                //------------------------------------------------------------//
                //                                                            //
                // Stage 2: look for command name.                            //
                //                                                            //
                //------------------------------------------------------------//

                endLoop = false;

                while ((!endLoop) && (cmdRem > 0))
                {
                    crntByte = _buf[offset];

                    //--------------------------------------------------------//
                    //                                                        //
                    // Check for special characters first.                    //
                    //                                                        //
                    //--------------------------------------------------------//

                    if ((cmdRem == 1) &&
                        (crntByte == PrnParseConstants.asciiSemiColon))

                    {
                        // nextstage = Parameters or Terminator;
                        endLoop = true;
                    }
                    else if (((crntByte >= PrnParseConstants.asciiAlphaUCMin)
                              &&
                              (crntByte <= PrnParseConstants.asciiAlphaUCMax))
                             ||
                             ((crntByte >= PrnParseConstants.asciiAlphaLCMin)
                              &&
                              (crntByte <= PrnParseConstants.asciiAlphaLCMax)))
                    {
                        crntChar = (Char)crntByte;
                        normChar = Char.ToUpper(crntChar);
                        cmd.Append(normChar);

                        offset++;
                        cmdRem--;
                    }
                    else
                    {
                        // nextstage = Parameters or Terminator;
                        endLoop = true;
                    }
                }

                //------------------------------------------------------------//
                //                                                            //
                // Check whether command name known.                          //
                //                                                            //
                //------------------------------------------------------------//

                commandName = cmd.ToString();

                cmdKnown = PrescribeCommands.checkCmd(cmd.ToString(),
                                                      ref commandDesc,
                                                      ref flagCmdExit,
                                                      ref flagCmdSetCRC,
                                                      _analysisLevel);

                //------------------------------------------------------------//
                //                                                            //
                // Stage 3: look for command remainder parameters, or the     //
                // terminator character.                                      //
                //                                                            //
                //------------------------------------------------------------//

                endLoop           = false;
                cmdParaByte1Found = false;

                while ((!endLoop) && (cmdRem > 0))
                {
                    crntByte = _buf[offset];

                    if (!cmdParaByte1Found)
                    {
                        if ((crntByte != PrnParseConstants.asciiSpace)
                            &&
                            (crntByte != PrnParseConstants.asciiHT))
                        {
                            cmdParaByte1      = crntByte;
                            cmdParaByte1Found = true;
                        }
                    }

                    offset++;
                    cmdRem--;
                }

                //------------------------------------------------------------//
                //                                                            //
                // Stage 4: Output details of command.                        //
                // Display sequence (in slices if necessary).                 //
                //                                                            //
                //------------------------------------------------------------//

                command = Encoding.ASCII.GetString(_buf, cmdStart, cmdLen);

                const Int32 indent = 2;

                lineStart = 0;
                len       = cmdLen; // or length of string? //

                Int32 sliceLen,
                      sliceLenMax,
                      sliceStart,
                      sliceOffset,
                      ccAdjust;

                Boolean firstSlice;

                String seq = "";

                Byte[] seqBuf = new Byte[PrnParseConstants.cRptA_colMax_Seq];

                firstSlice  = true;
                sliceOffset = 0;

                if (firstSlice)
                {
                    sliceLenMax = PrnParseConstants.cRptA_colMax_Seq;
                }
                else
                {
                    sliceLenMax = PrnParseConstants.cRptA_colMax_Seq - indent;
                }

                sliceStart = bufOffset + sliceOffset;

                while (len > sliceLenMax)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Sequence is too large to fit on one output line.       //
                    //                                                        //
                    //--------------------------------------------------------//

                    sliceLen = sliceLenMax;
                    ccAdjust = 0;

                    if (firstSlice)
                    {
                        seq = command.Substring(sliceOffset, sliceLen);

                        PrnParseCommon.addDataRow(
                            PrnParseRowTypes.eType.PrescribeCommand,
                            _table,
                            PrnParseConstants.eOvlShow.Remove,
                            _indxOffsetFormat,
                            _fileOffset + bufOffset + sliceOffset,
                            _analysisLevel,
                            "Prescribe command",
                            seq.ToString(),
                            "");
                    }
                    else
                    {
                        seq = "  " + // indent number of spaces
                              command.Substring(sliceOffset, sliceLen);

                        PrnParseCommon.addDataRow(
                            PrnParseRowTypes.eType.PrescribeCommand,
                            _table,
                            PrnParseConstants.eOvlShow.Remove,
                            _indxOffsetFormat,
                            _fileOffset + bufOffset + sliceOffset,
                            _analysisLevel,
                            "",
                            seq.ToString(),
                            "");
                    }

                    len         = len - sliceLen - ccAdjust;
                    sliceOffset = sliceOffset + sliceLen + ccAdjust;
                    sliceStart += (sliceLen + ccAdjust);
                    sliceLenMax = PrnParseConstants.cRptA_colMax_Seq - indent;

                    firstSlice = false;
                }

                //------------------------------------------------------------//
                //                                                            //
                // Display last (or only) slice of sequence.                  //
                //                                                            //
                //------------------------------------------------------------//

                sliceLen = len;
                ccAdjust = 0;

                if (len > 0)
                {
                    if (firstSlice)
                    {
                        seq = command.Substring(sliceOffset, sliceLen);

                        PrnParseCommon.addDataRow(
                            PrnParseRowTypes.eType.PrescribeCommand,
                            _table,
                            PrnParseConstants.eOvlShow.Remove,
                            _indxOffsetFormat,
                            _fileOffset + bufOffset + sliceOffset,
                            _analysisLevel,
                            "Prescribe Command",
                            seq,
                            commandDesc);
                    }
                    else
                    {
                        seq = "  " + // indent number of spaces
                              command.Substring(sliceOffset, sliceLen);

                        PrnParseCommon.addDataRow(
                            PrnParseRowTypes.eType.PrescribeCommand,
                            _table,
                            PrnParseConstants.eOvlShow.Remove,
                            _indxOffsetFormat,
                            _fileOffset + bufOffset + sliceOffset,
                            _analysisLevel,
                            "",
                            seq,
                            commandDesc);
                    }
                }

                //------------------------------------------------------------//
                //                                                            //
                // Stage 5: Do any special processing.                        //
                //                                                            //
                //------------------------------------------------------------//

                bufOffset = offset;
                bufRem   -= cmdLen;

                if (flagCmdExit)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Exit command found and processed.                      //
                    //                                                        //
                    //--------------------------------------------------------//

                    langSwitch = true;

                    crntPDL = _linkData.PrescribeCallerPDL;
                    _linkData.PrescribeIntroRead = false;
                }
                else if (flagCmdSetCRC)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Set Command Recognition Character command found and    //
                    // processed.                                             //
                    //                                                        //
                    //--------------------------------------------------------//

                    _linkData.PrescribeSCRC = cmdParaByte1;

                    PrnParseCommon.addTextRow(
                        PrnParseRowTypes.eType.MsgComment,
                        _table,
                        PrnParseConstants.eOvlShow.None,
                        "",
                        "Comment",
                        "",
                        "Set Prescribe CRC = " + (Char)cmdParaByte1);
                }
            }

            return(invalidSeqFound);
        }