//--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // r e s e t C o n t D a t a                                          //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Reset 'link' continuation data flags and values.                   //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void resetContData()
        {
            _contType    = PrnParseConstants.eContType.None;
            _prefixLen   = 0;
            _dataLen     = 0;
            _downloadRem = 0;
            _backTrack   = false;
            _prefixA     = 0x00;
            _prefixB     = 0x00;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // s e t C o n t i n u a t i o n                                      //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Set (non-backtracking) continuation data flags and values.         //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void setContinuation(PrnParseConstants.eContType contType)
        {
            _contType    = contType;
            _prefixLen   = 0;
            _dataLen     = 0;
            _downloadRem = 0;
            _backTrack   = false;
            _prefixA     = 0x20;
            _prefixB     = 0x20;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // s e t B a c k t r a c k                                            //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Set (backtracking) continuation data flags and values.             //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void setBacktrack(PrnParseConstants.eContType contType,
                                 Int32 dataLen)
        {
            _contType    = contType;
            _prefixLen   = 0;
            _dataLen     = dataLen;
            _downloadRem = 0;
            _backTrack   = true;
            _prefixA     = 0x20;
            _prefixB     = 0x20;
        }
        //--------------------------------------------------------------------//
        //                                              C o n s t r u c t o r //
        // P r n P a r s e L i n k D a t a                                    //
        //                                                                    //
        //--------------------------------------------------------------------//

        public PrnParseLinkData(
            PrnParse analysisOwner,
            Int32 analysisLevel,
            Int32 macroLevel,
            PCLXLOperators.eEmbedDataType pclxlEmbedType)
        {
            _analysisOwner  = analysisOwner;
            _analysisLevel  = analysisLevel;
            _macroLevel     = macroLevel;
            _pclxlEmbedType = pclxlEmbedType;

            _contType    = PrnParseConstants.eContType.None;
            _prefixLen   = 0;
            _dataLen     = 0;
            _downloadRem = 0;

            _entryCt  = 0;
            _entryNo  = 0;
            _entryRem = 0;
            _entrySz1 = 0;
            _entrySz2 = 0;

            _backTrack = false;
            _prefixA   = 0x00;
            _prefixB   = 0x00;

            _eof = false;

            _fileSize = 0;

            _makeOvlOffset      = 0;
            _makeOvlSkipBegin   = -1;
            _makeOvlSkipEnd     = -1;
            _makeOvlAct         = PrnParseConstants.eOvlAct.None;
            _makeOvlPos         = PrnParseConstants.eOvlPos.BeforeFirstPage;
            _makeOvlShow        = PrnParseConstants.eOvlShow.None;
            _makeOvlMacroId     = -1;
            _makeOvlStreamName  = "";
            _makeOvlPageMark    = false;
            _makeOvlXL          = false;
            _makeOvlEncapsulate = false;

            _pclComboStart    = -1;
            _pclComboSeq      = false;
            _pclComboFirst    = false;
            _pclComboLast     = false;
            _pclComboModified = false;

            _prescribeSCRC      = PrnParseConstants.prescribeSCRCDefault;
            _prescribeIntroRead = false;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // s e t C o n t D a t a                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Set continuation data flags and values.                            //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void setContData(PrnParseConstants.eContType contType,
                                Int32 prefixLen,
                                Int32 dataLen,
                                Int32 downloadRem,
                                Boolean backTrack,
                                Byte prefixA,
                                Byte prefixB)
        {
            _contType    = contType;
            _prefixLen   = prefixLen;
            _dataLen     = dataLen;
            _downloadRem = downloadRem;
            _backTrack   = backTrack;
            _prefixA     = prefixA;
            _prefixB     = prefixB;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // g e t C o n t D a t a                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Return continuation data flags and values.                         //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void getContData(ref PrnParseConstants.eContType contType,
                                ref Int32 prefixLen,
                                ref Int32 dataLen,
                                ref Int32 downloadRem,
                                ref Boolean backTrack,
                                ref Byte prefixA,
                                ref Byte prefixB)
        {
            contType    = _contType;
            prefixLen   = _prefixLen;
            dataLen     = _dataLen;
            downloadRem = _downloadRem;
            backTrack   = _backTrack;
            prefixA     = _prefixA;
            prefixB     = _prefixB;
        }
Beispiel #7
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // f i n d P J L T e r m i n a t o r                                  //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Search for PJL terminator 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).                                             //
        //                                                                    //
        //--------------------------------------------------------------------//

        private Boolean findPJLTerminator(
            Int32 bufRem,
            Int32 bufOffset,
            ref Int32 commandLen,
            ref Boolean continuation)
        {
            PrnParseConstants.eContType contType =
                PrnParseConstants.eContType.None;

            Byte crntByte;

            Int32 cmdLen,
                  rem,
                  offset;

            Boolean foundTerm,
                    foundLF;

            continuation = false;
            foundTerm    = false;
            foundLF      = false;

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

            //----------------------------------------------------------------//
            //                                                                //
            // Search for termination character.                              //
            //                                                                //
            //----------------------------------------------------------------//

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

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

            if ((!foundTerm) && (cmdLen != _maxPJLCmdLen))
            {
                //------------------------------------------------------------//
                //                                                            //
                // 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);

                commandLen = 0;
            }
            else
            {
                commandLen = cmdLen;
            }

            return(foundLF);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }