//--------------------------------------------------------------------// // M e t h o d // // r e s e t S t a t i s t i c s // //--------------------------------------------------------------------// // // // Reset analysis statisics counts. // // // //--------------------------------------------------------------------// public void resetStatistics() { btnStatistics.IsEnabled = false; txtRptSizeStatistics.Text = "0"; _tableStatistics.Clear(); PrescribeCommands.resetStatsCounts(); PJLCommands.resetStatsCounts(); PCLComplexSeqs.resetStatsCounts(); PCLSimpleSeqs.resetStatsCounts(); PCLControlCodes.resetStatsCounts(); HPGL2Commands.resetStatsCounts(); HPGL2ControlCodes.resetStatsCounts(); PCLXLDataTypes.resetStatsCounts(); // PCLXLAttrDefiners.resetStatsCounts (); PCLXLAttributes.resetStatsCounts(); PCLXLAttrEnums.resetStatsCounts(); // PCLXLEmbedDataDefs.resetStatsCounts (); PCLXLOperators.resetStatsCounts(); PCLXLWhitespaces.resetStatsCounts(); }
//--------------------------------------------------------------------// // 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); }
//--------------------------------------------------------------------// // M e t h o d // // b t n S t a t i s t i c s _ C l i c k // //--------------------------------------------------------------------// // // // Called when the 'Show Statistics' button is clicked. // // // //--------------------------------------------------------------------// private void btnStatistics_Click(object sender, RoutedEventArgs e) { if (_redoStatistics) { PrnParseConstants.eOptStatsLevel level = PrnParseConstants.eOptStatsLevel.ReferencedOnly; Boolean incUsedSeqsOnly = false; Boolean excUnusedObsPCLSeqs = false; Boolean excUnusedResPCLXLTags = false; _options.getOptStats(ref level, ref excUnusedObsPCLSeqs, ref excUnusedResPCLXLTags); _tableStatistics.Clear(); if (level == PrnParseConstants.eOptStatsLevel.ReferencedOnly) { incUsedSeqsOnly = true; } else { incUsedSeqsOnly = false; } PrescribeCommands.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); PJLCommands.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); PCLControlCodes.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); PCLSimpleSeqs.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedObsPCLSeqs); PCLComplexSeqs.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedObsPCLSeqs); HPGL2Commands.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); HPGL2ControlCodes.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); PCLXLDataTypes.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedResPCLXLTags); PCLXLAttrEnums.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedResPCLXLTags); PCLXLAttributes.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedResPCLXLTags); PCLXLOperators.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedResPCLXLTags); PCLXLWhitespaces.displayStatsCounts(_tableStatistics, incUsedSeqsOnly, excUnusedResPCLXLTags); PMLDataTypes.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); PMLActions.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); PMLOutcomes.displayStatsCounts(_tableStatistics, incUsedSeqsOnly); // TODO = remaining types // PCL XL Attribute Definers ?? // PCL XL Embedded Data Definers ?? _redoStatistics = false; } tabCtrl.SelectedItem = tabStatistics; /* * //----------------------------------------------------------------// * // // * // If we ever support the 'doWork' mechanism: // * // statusBar updates // * // // * //----------------------------------------------------------------// * * statusBar.Items[2] = dgStatistics.Items.Count; * txtRptSizeStatistics.Text = dgStatistics.Items.Count.ToString (); */ txtRptSizeStatistics.Text = _tableStatistics.Rows.Count.ToString(); btnSaveReport.Content = "Save Statistics Report ..."; }
//--------------------------------------------------------------------// // 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; Boolean continuation = false; Boolean langSwitch = false; Boolean badSeq = false; Boolean invalidSeqFound = false; continuation = false; startPos = _fileOffset + bufOffset; if (!_linkData.PrescribeIntroRead) { if ((_buf[bufOffset] == PrnParseConstants.prescribeSCRCDelimiter) && (_buf[bufOffset + 1] == _linkData.PrescribeSCRC) && (_buf[bufOffset + 2] == PrnParseConstants.prescribeSCRCDelimiter)) { String seq = _ascii.GetString(_buf, bufOffset, 3); // String desc = PrescribeCommands.getDescCmdIntro(); String desc = ""; PrescribeCommands.checkCmdIntro(ref desc, _analysisLevel); PrnParseCommon.addDataRow( PrnParseRowTypes.eType.PrescribeCommand, _table, PrnParseConstants.eOvlShow.Remove, _indxOffsetFormat, _fileOffset + bufOffset, _analysisLevel, "Prescribe", seq, desc); bufOffset += 3; bufRem -= 3; _linkData.PrescribeIntroRead = true; } else { // internal error ?? } } 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 // // Prescribe. // // // //--------------------------------------------------------// langSwitch = true; crntPDL = ToolCommonData.ePrintLang.PCL; } else { //--------------------------------------------------------// // // // Sequence does not start with an Escape character, so // // it should be a Prescribe command. // // // //--------------------------------------------------------// badSeq = processCommand(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); }