Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "../incp/T_PMLPAR.H"
21 #define UNUSED_VAR(a) a = a
23 #define UNUSED_VAR(a) a = a
25 ////////////////////////////////////////////
27 ////////////////////////////////////////////
29 CParser* CParser::NewL()
31 CParser* self=new(ELeave) CParser;
32 CleanupStack::PushL(self);
33 self->ConstructApplicationL();
42 iErrorLevel = ENoError;
43 iParagraphIsOpen = EFalse;
54 void CParser::ConstructApplicationL()
56 // Construct Rich Text Doc
57 // Make the global format layers and associated formats and masks
58 iGlobalParaFormatLayer=CParaFormatLayer::NewL();
59 iGlobalCharFormatLayer=CCharFormatLayer::NewL();
60 iGlobalParaFormat=CParaFormat::NewL(); // initialised with factory settings
61 iGlobalParaFormatMask.SetAll();
62 iGlobalCharFormatMask.SetAll();
64 // Set the global layers
65 iGlobalParaFormatLayer->SetL(iGlobalParaFormat,iGlobalParaFormatMask);
66 iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask);
68 // Create the rich text document
69 iRichTextDoc=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer);
71 // Initialise the paragraph and character layers
72 iParaFormatLayer = CParaFormatLayer::NewL();
73 iCharFormatLayer = CCharFormatLayer::NewL();
74 iParaFormat = CParaFormat::NewL();
76 // Create temp alias' for compound attributes
77 iBorder = new TParaBorder;
78 User::LeaveIfNull(iBorder);
79 iBullet = new (ELeave) TBullet;
85 // destroy Rich Text Document
86 // delete iRichTextDoc;
87 // delete iGlobalParaFormatLayer;
88 // delete iGlobalCharFormatLayer;
89 delete iGlobalParaFormat;
90 delete iParaFormatLayer;
91 delete iCharFormatLayer;
100 CRichText* CParser::ParseL(CConsoleBase* aConsole)
101 // version for parsing with console output and interactive file dialog
102 // primarily for debugging purposes (you can see what's going on!)
105 iConsoleExists = ETrue;
108 // Construct a CFileApp & load a file
109 CFileApp* myFileApp=NULL;
110 TRAPD(ret, myFileApp = CFileApp::NewL());
112 iTextBuf = myFileApp->LoadFileL(iConsole);
113 iFileName = myFileApp->ReturnFileName();
115 ParseTextBufL(); // parse the buffer
116 delete myFileApp; // destroy file app
118 // Pause before returning
121 OutputToScreen(_L("Press Space to continue\n"));
122 TKeyCode keystroke = EKeyNull;
123 while (keystroke != EKeySpace)
124 keystroke = iConsole->Getch();
128 CRichText* CParser::ParseL(const TFileName &aFileName)
129 // silent version of the parser
131 iConsoleExists = EFalse;
132 // Construct a CFileApp & load a file
133 CFileApp* myFileApp=NULL;
134 TRAPD(ret, myFileApp = CFileApp::NewL());
136 iTextBuf = myFileApp->LoadFileL(aFileName);
137 iFileName = myFileApp->ReturnFileName();
139 ParseTextBufL(); // parse the buffer
140 delete myFileApp; // destroy file app
146 void CParser::EmitErrorMessage()
148 TBuf<80> errorMessage;
151 case EUnknownTagType:
152 errorMessage.Format(_L(" Unknown tag type: Line %d"),iLineNo);
154 case EUnparagraphedText:
155 errorMessage.Format(_L(" Text not contained by paragraph: Line %d"),iLineNo);
158 errorMessage.Format(_L(" Unknown tag attribute: Line %d"),iLineNo);
161 errorMessage.Format(_L(" Unknown attribute or no attribute value supplied: Line %d"),iLineNo);
163 case EIllegalAttribValue:
164 errorMessage.Format(_L(" Illegal attribute value: Line %d"),iLineNo);
167 errorMessage.Format(_L(" Error: Line %d"),iLineNo);
170 OutputToScreen(_L(""));
171 OutputToScreen(_L("*** Error!!\n"));
172 OutputToScreen(errorMessage);
176 void CParser::OutputToScreen(const TDesC& aMessageBuffer)
179 iConsole->Write(aMessageBuffer); // output line to screen
183 TBool CParser::Validate()
184 // Check that document starts with <G> tag - serves as file validation
185 // - Read in characters sequentially
186 // - if the first alphanumeric characters encountered are not "<G" then error
188 TBool fileFormatError = EFalse;
189 TBool fileValidated = EFalse;
191 while ((!fileFormatError)&&(!fileValidated))
193 charToTest = ReadChar();
194 if (charToTest == '<')
196 iReadPos+=KCharLength;
197 charToTest = ReadTagChar();
198 if (charToTest != 'G') // Not a style tag - error
199 fileFormatError = ETrue;
201 fileValidated = ETrue;
205 if (charToTest.IsAlphaDigit()) // Char is alphanumeric - error
206 fileFormatError = ETrue; // (File must start with style tag)
208 iReadPos+=KCharLength;
213 OutputToScreen(_L("File format error\n"));
215 iReadPos = 0; // reset after validation
217 return fileValidated;
221 void CParser::ParseTextBufL()
222 // Parses contents of iTextBuf
223 // Reads in chars sequentially.
224 // - If a char is a tag open ("<") process the following tag
225 // - otherwise add the char to the text of the rich text document
226 // Tidy up at the end of the document
229 TUint textBufSize = iTextBuf->Size();
232 while ((iReadPos < textBufSize)&&(iErrorLevel == ENoError))
234 charToTest = ReadChar();
235 if (charToTest == '<')
238 ProcessTextL(charToTest);
239 iReadPos+=KCharLength;
241 if ((iReadPos == textBufSize)&&(iReadPos>0)&&(iErrorLevel == ENoError))
243 // at end of document apply any outstanding formatting (if there is text to apply it to)
244 if (iDocParaLength > 0)
246 iParaFormatLayer->SetL(iParaFormat, iParaFormatMask);
247 iRichTextDoc->ApplyParaFormatL( iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength);
249 if (iDocPhraseLength > 0)
251 iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
252 iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
255 if (iErrorLevel != ENoError)
261 TChar CParser::ReadChar()
262 // Reads the next character from the text buffer
266 iTextBuf->Read(iReadPos,&charToTest,KCharLength);
267 if (charToTest == (TText)KLineFeed)
268 iLineNo++; // Info used only by error messages
273 void CParser::ProcessTextL(TChar aChar)
274 // 1) Check text is in a paragraph
275 // 2) Check for escape characters
277 // 4) Add to paragraph
279 if (!iParagraphIsOpen)
281 if (!(aChar.IsControl()))
282 iErrorLevel = EUnparagraphedText; // Text not contained by a paragraph - error!!
286 if (aChar == '/') // Escape character for <
289 iTextBuf->Read(iReadPos+KCharLength,&tempChar,1); // doesn't increment line counter
292 AddCharToParaL(tempChar);
293 iReadPos+=2*KCharLength; // Skip escape character
296 AddCharToParaL(aChar);
298 else if (aChar == KTabChar)
299 AddCharToParaL(aChar);
300 else if (!(aChar.IsControl())) // if it's not a control char add it
301 AddCharToParaL(aChar); // (this includes spaces)
306 void CParser::AddCharToParaL(TChar aChar)
308 // Add char to RichText doc...
309 iRichTextDoc->InsertL(iDocInsertPos, aChar);
314 // and also write it to screen
315 TBuf<4> screenBuf; // Buffer for text to be written to console
316 screenBuf.Append(aChar);
317 OutputToScreen(screenBuf);
321 void CParser::ProcessTagL()
324 iReadPos+=KCharLength;
325 tagChar = ReadTagChar(); // Read in tag type
326 ClassifyTagL(tagChar);
327 if (iTagType == EError)
328 iErrorLevel = EUnknownTagType;
331 ClassifyArgumentsL();
336 TChar CParser::ReadTagChar()
337 { // Returns tag character capitalised - therefore case-insensitive
339 charToTest = ReadChar();
340 charToTest.UpperCase();
345 void CParser::ClassifyArgumentsL()
346 // reads tag one argument at a time, dealing with each arg as it is read
347 // If and argument is followed by a value (ie a=4) it is processed in two passes.
351 iArgValueExpected = EFalse; // Initialise
353 while ((tagChar != '>')&&(iErrorLevel == ENoError)) // ">" is end of tag
355 iReadPos+=KCharLength;
356 tagChar = ReadTagChar(); // Read in next bit of tag
357 if (iTagType != EComment) // text of comments is ignored
359 if (tagChar.IsSpace()) // spaces separate args
363 iArgValueExpected = ETrue;
369 OutputToScreen(_L("!"));
372 AppendToArgBuf(tagChar);
373 if (tagChar.IsAlphaDigit())
375 AppendToArgBuf(tagChar);
379 if (tagChar == '>') // Is it end of tag?
381 if (iTagType != EComment)
384 if ((iTagType == EControl)||(iTagType == EGlobal)) // Control & global style formatting is applied "on the spot"
385 SetFormatLayerL(); // While char & paragraph are applied retrospectively
391 void CParser::AppendToArgBuf(TChar aTagChar)
393 iArgType.Append(aTagChar); // assume it'll fit
397 void CParser::ProcessArgBufL()
399 if (iArgValueExpected)
403 TBuf<32> tempArgBuf; // Swap the buffers back as an arg and its value have been stored
404 tempArgBuf = iArgType;
405 EmptyBuffer(iArgType);
406 iArgType = iArgValue;
407 EmptyBuffer(iArgValue);
408 iArgValue = tempArgBuf;
409 TranslateTagArgL(); // Translate the tag argument
410 iArgStored = EFalse; // Reset the flags and buffers
411 iArgValueExpected = EFalse;
412 EmptyBuffer(iArgType);
413 EmptyBuffer(iArgValue);
417 iArgValue = iArgType; // Swap the buffers ready to store the value of the arg
418 EmptyBuffer(iArgType); // Empty buffer
424 TranslateTagArgL(); // match to list
425 EmptyBuffer(iArgType);
426 EmptyBuffer(iArgValue);
431 void CParser::EmptyBuffer(TDes &aBuf)
437 void CParser::ClassifyTagL(TChar aTagChar)
446 iTagType = EParagraph;
447 if (iParagraphIsOpen)
449 iRichTextDoc->InsertL(iDocInsertPos,CEditableText::EParagraphDelimiter); // insert para delimiter
450 WriteNewLine(); // Write new line to console
451 iDocInsertPos++; // Paragraph delimiters occupy 1 character space
455 SetFormatLayerL(); // apply formatting to old para before starting to fill new one
458 iParagraphIsOpen = ETrue;
463 iTagType = ECharacter;
465 SetFormatLayerL(); // apply formatting to old phrase retrospectively
483 void CParser::SetFormatLayerL()
484 // Apply format & mask that have been set in the tag to a Layer
485 // Apply the layer to the RichText doc
487 if (iTagType == EGlobal)
489 iGlobalParaFormatLayer->SetL(iGlobalParaFormat, iGlobalParaFormatMask);
490 iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask);
491 iRichTextDoc->SetGlobalParaFormat(iGlobalParaFormatLayer);
492 iRichTextDoc->SetGlobalCharFormat(iGlobalCharFormatLayer);
495 if (iTagType == EParagraph)
497 iParaFormatLayer->SetL(iParaFormat, iParaFormatMask);
498 iRichTextDoc->ApplyParaFormatL(iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength);
499 iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
500 if (iDocPhraseLength > 0)
501 iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
502 iDocParaLength = 0; // reset ready for new paragraph
503 iDocPhraseLength = 0;
505 if (iTagType == ECharacter)
507 iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
508 if (iDocPhraseLength > 0)
509 iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
510 iDocPhraseLength = 0;
515 TInt CParser::GetArgValue()
516 // converts numerals in iArgValue to a TInt,
517 // first checking that the buffer is totally numeric in content
520 if (BufIsNumeric(iArgValue))
522 TLex tmpLex(iArgValue);
525 else iErrorLevel = EIllegalAttribValue;
530 TInt CParser::GetArgValue(const TDes &aBuf)
531 // converts numerals in aBuf to a TInt as above
534 if (BufIsNumeric(aBuf))
539 else iErrorLevel = EIllegalAttribValue;
544 TBool CParser::BufIsNumeric(const TDes &aBuffer)
545 // checks that aBuffer is totally numeric in content.
546 // checks all characters sequentially
548 TBool isNumeric = ETrue;
550 TUint bufLength = aBuffer.Length();
551 for (TUint pos=0; ((pos<bufLength)&&(isNumeric)); pos++)
553 testChar = (aBuffer[pos]);
554 if (!(testChar.IsDigit()&&isNumeric))
560 /* All the TransXxx.. functions translate arguments and their values and apply these
561 to RichText Formats and Masks */
564 void CParser::TranslateTagArgL()
572 TransParagraphArgL();
583 iCancelArg = EFalse; // reset
587 void CParser::TransControlArgL()
589 if (iArgType != _L(""))
591 if (iArgType == _L("TAB"))
592 AddCharToParaL(KTabChar); // TransTab();
594 iErrorLevel = EUnknownAttrib;
599 void CParser::TransGlobalArgL()
600 // Test for each possible arg in turn
601 // (a switch statement cannot be used)
603 if (iArgType != _L("")) // Is there an argument?
605 if (iArgType == _L("KEEPTOGETHER"))
606 TransParaKeepTogether();
607 else if (iArgType == _L("KEEPWITHNEXT"))
608 TransParaKeepWithNext();
609 else if (iArgType == _L("STARTNEWPAGE"))
610 TransParaStartNewPage();
611 else if (iArgType == _L("WIDOWORPHAN"))
612 TransParaWidowOrphan();
614 if (iArgType == _L("ITALIC"))
616 else if (iArgType == _L("BOLD"))
617 TransCharStrokeWeight();
618 else if (iArgType == _L("UNDERLINE"))
619 TransCharUnderline();
620 else if (iArgType == _L("STRIKETHROUGH"))
621 TransCharStrikethrough();
623 else if (!iArgValueExpected) // No argument value supplied when one is required for the
624 iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied
626 else if (iArgType == _L("PARALANGUAGE"))
627 OutputToScreen(_L("PARA LANGUAGE "));
628 else if (iArgType == _L("LEFTMARGIN"))
629 TransParaArgLeftMargin();
630 else if (iArgType == _L("RIGHTMARGIN"))
631 TransParaArgRightMargin();
632 else if (iArgType == _L("INDENT"))
633 TransParaArgIndent();
634 else if (iArgType == _L("ALIGNMENT"))
635 TransParaArgAlignment();
636 else if (iArgType == _L("LINESPACING"))
637 TransParaLineSpacing();
638 else if (iArgType == _L("LINESPACINGCONTROL"))
639 TransParaArgLineSpacingControl();
640 else if (iArgType == _L("SPACEBEFORE"))
641 TransParaSpaceBefore();
642 else if (iArgType == _L("SPACEAFTER"))
643 TransParaSpaceAfter();
644 else if (iArgType == _L("BORDERMARGIN"))
645 TransParaBorderMargin();
646 else if (iArgType == _L("TOPBORDER"))
648 else if (iArgType == _L("BOTTOMBORDER"))
650 else if (iArgType == _L("LEFT BORDER"))
652 else if (iArgType == _L("RIGHTBORDER"))
654 else if (iArgType == _L("BULLET"))
656 else if (iArgType == _L("DEFAULTTABWIDTH"))
658 else if (iArgType == _L("TABSTOP"))
661 else if (iArgType == _L("FONTHEIGHT"))
662 TransCharFontHeight();
663 else if (iArgType == _L("PRINTPOS"))
665 else if (iArgType == _L("TYPEFACENAME"))
666 TransCharTypefaceName();
667 else if (iArgType == _L("TYPEFACEFLAGS"))
668 TransCharTypefaceFlags();
669 else if (iArgType == _L("COLOR"))
671 else if (iArgType == _L("LANGUAGE"))
674 iErrorLevel = EUnknownAttrib;
679 void CParser::TransParagraphArgL()
680 // Test for each possible arg in turn
681 // (a switch statement cannot be used)
683 if (iArgType != _L("")) // Is there an argument?
685 if (iArgType == _L("DEFAULT"))
687 else if (iArgType == _L("KEEPTOGETHER"))
688 TransParaKeepTogether();
689 else if (iArgType == _L("KEEPWITHNEXT"))
690 TransParaKeepWithNext();
691 else if (iArgType == _L("STARTNEWPAGE"))
692 TransParaStartNewPage();
693 else if (iArgType == _L("WIDOWORPHAN"))
694 TransParaWidowOrphan();
695 else if (!iArgValueExpected) // No argument value supplied when one is required for the
696 iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied
697 else if (iArgType == _L("PARALANGUAGE"))
698 OutputToScreen(_L("PARA LANGUAGE "));
699 else if (iArgType == _L("LEFTMARGIN"))
700 TransParaArgLeftMargin();
701 else if (iArgType == _L("RIGHTMARGIN"))
702 TransParaArgRightMargin();
703 else if (iArgType == _L("INDENT"))
704 TransParaArgIndent();
705 else if (iArgType == _L("ALIGNMENT"))
706 TransParaArgAlignment();
707 else if (iArgType == _L("LINESPACING"))
708 TransParaLineSpacing();
709 else if (iArgType == _L("LINESPACINGCONTROL"))
710 TransParaArgLineSpacingControl();
711 else if (iArgType == _L("SPACEBEFORE"))
712 TransParaSpaceBefore();
713 else if (iArgType == _L("SPACEAFTER"))
714 TransParaSpaceAfter();
715 else if (iArgType == _L("BORDERMARGIN"))
716 TransParaBorderMargin();
717 else if (iArgType == _L("TOPBORDER"))
719 else if (iArgType == _L("BOTTOMBORDER"))
721 else if (iArgType == _L("LEFT BORDER"))
723 else if (iArgType == _L("RIGHTBORDER"))
725 else if (iArgType == _L("BULLET"))
727 else if (iArgType == _L("DEFAULTTABWIDTH"))
729 else if (iArgType == _L("TABSTOP"))
732 iErrorLevel = EUnknownAttrib;
737 void CParser::TransParaDefault()
738 // turns off all applied para formatting - reverts to global
740 iParaFormatMask.ClearAll();
741 OutputToScreen(_L("<PARA-DEFAULT>"));
745 void CParser::TransParaArgLeftMargin()
747 TInt32 margin = GetArgValue();
751 iParaFormat->iLeftMarginInTwips = margin;
752 iParaFormatMask.SetAttrib(EAttLeftMargin);
755 iGlobalParaFormat->iLeftMarginInTwips = margin;
756 iGlobalParaFormatMask.SetAttrib(EAttLeftMargin);
761 outputBuf.Format(_L("<LEFT MARGIN = %d>"),margin);
762 OutputToScreen(outputBuf);
765 void CParser::TransParaArgRightMargin()
767 TInt32 margin = GetArgValue();
771 iParaFormat->iRightMarginInTwips = margin;
772 iParaFormatMask.SetAttrib(EAttRightMargin);
775 iGlobalParaFormat->iRightMarginInTwips = margin;
776 iGlobalParaFormatMask.SetAttrib(EAttRightMargin);
781 outputBuf.Format(_L("<RIGHT MARGIN = %d>"),margin);
782 OutputToScreen(outputBuf);
785 void CParser::TransParaArgIndent()
787 TInt32 indent = GetArgValue();
791 iParaFormat->iIndentInTwips = indent;
792 iParaFormatMask.SetAttrib(EAttIndent);
795 iGlobalParaFormat->iIndentInTwips = indent;
796 iGlobalParaFormatMask.SetAttrib(EAttIndent);
801 outputBuf.Format(_L("<INDENT = %d>"),indent);
802 OutputToScreen(outputBuf);
805 void CParser::TransParaLineSpacing()
807 TInt32 lineSpacing = GetArgValue();
811 iParaFormat->iLineSpacingInTwips = lineSpacing;
812 iParaFormatMask.SetAttrib(EAttLineSpacing);
815 iGlobalParaFormat->iLineSpacingInTwips = lineSpacing;
816 iGlobalParaFormatMask.SetAttrib(EAttLineSpacing);
821 outputBuf.Format(_L("<LINESPACING = %d>"),lineSpacing);
822 OutputToScreen(outputBuf);
825 void CParser::TransParaArgLineSpacingControl()
827 if (iArgValue == _L("ATLEAST"))
832 iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips;
833 iParaFormatMask.SetAttrib(EAttLineSpacingControl);
836 iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips;
837 iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl);
840 OutputToScreen(_L("<Line spacing control Atleast>"));
842 else if (iArgValue == _L("EXACTLY"))
847 iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
848 iParaFormatMask.SetAttrib(EAttLineSpacingControl);
851 iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
852 iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl);
855 OutputToScreen(_L("<Line spacing control Exactly>"));
858 iErrorLevel = EIllegalAttribValue;
861 void CParser::TransParaSpaceBefore()
863 TInt32 spaceBefore = GetArgValue();
867 iParaFormat->iSpaceBeforeInTwips = spaceBefore;
868 iParaFormatMask.SetAttrib(EAttSpaceBefore);
871 iGlobalParaFormat->iSpaceBeforeInTwips = spaceBefore;
872 iGlobalParaFormatMask.SetAttrib(EAttSpaceBefore);
877 outputBuf.Format(_L("<SPACE BEFORE = %d>"),spaceBefore);
878 OutputToScreen(outputBuf);
881 void CParser::TransParaSpaceAfter()
883 TInt32 spaceAfter = GetArgValue();
887 iParaFormat->iSpaceAfterInTwips = spaceAfter;
888 iParaFormatMask.SetAttrib(EAttSpaceAfter);
891 iGlobalParaFormat->iSpaceAfterInTwips = spaceAfter;
892 iGlobalParaFormatMask.SetAttrib(EAttSpaceAfter);
897 outputBuf.Format(_L("<SPACE AFTER = %d>"),spaceAfter);
898 OutputToScreen(outputBuf);
901 void CParser::TransParaBorderMargin()
903 TInt32 borderMargin = GetArgValue();
907 iParaFormat->iBorderMarginInTwips = borderMargin;
908 iParaFormatMask.SetAttrib(EAttBorderMargin);
911 iGlobalParaFormat->iBorderMarginInTwips = borderMargin;
912 iGlobalParaFormatMask.SetAttrib(EAttBorderMargin);
917 outputBuf.Format(_L("<BORDER MARGIN = %d>"),borderMargin);
918 OutputToScreen(outputBuf);
921 void CParser::TransParaKeepTogether()
927 iParaFormat->iKeepTogether = EFalse;
929 iParaFormat->iKeepTogether = ETrue;
930 iParaFormatMask.SetAttrib(EAttKeepTogether);
934 iGlobalParaFormat->iKeepTogether = EFalse;
936 iGlobalParaFormat->iKeepTogether = ETrue;
937 iGlobalParaFormatMask.SetAttrib(EAttKeepTogether);
941 OutputToScreen(_L("<KEEP TOGETHER>"));
944 void CParser::TransParaKeepWithNext()
950 iParaFormat->iKeepWithNext = EFalse;
952 iParaFormat->iKeepWithNext = ETrue;
953 iParaFormatMask.SetAttrib(EAttKeepWithNext);
957 iGlobalParaFormat->iKeepWithNext = EFalse;
959 iGlobalParaFormat->iKeepWithNext = ETrue;
960 iGlobalParaFormatMask.SetAttrib(EAttKeepWithNext);
964 OutputToScreen(_L("<KEEP WITH NEXT>"));
967 void CParser::TransParaStartNewPage()
973 iParaFormat->iStartNewPage = EFalse;
975 iParaFormat->iStartNewPage = ETrue;
976 iParaFormatMask.SetAttrib(EAttStartNewPage);
980 iGlobalParaFormat->iStartNewPage = EFalse;
982 iGlobalParaFormat->iStartNewPage = ETrue;
983 iGlobalParaFormatMask.SetAttrib(EAttStartNewPage);
987 OutputToScreen(_L("<START NEW PAGE>"));
990 void CParser::TransParaWidowOrphan()
996 iParaFormat->iWidowOrphan = EFalse;
998 iParaFormat->iWidowOrphan = ETrue;
999 iParaFormatMask.SetAttrib(EAttWidowOrphan);
1003 iGlobalParaFormat->iWidowOrphan = EFalse;
1005 iGlobalParaFormat->iWidowOrphan = ETrue;
1006 iGlobalParaFormatMask.SetAttrib(EAttWidowOrphan);
1010 OutputToScreen(_L("<WIDOWS & ORPHANS>"));
1013 void CParser::TransParaArgAlignment()
1016 if (iArgValue == _L("LEFT"))
1021 iParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
1022 iParaFormatMask.SetAttrib(EAttAlignment);
1025 iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
1026 iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1029 OutputToScreen(_L("<ALIGNMENT LEFT>"));
1031 else if (iArgValue == _L("RIGHT"))
1036 iParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
1037 iParaFormatMask.SetAttrib(EAttAlignment);
1040 iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
1041 iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1044 OutputToScreen(_L("<ALIGNMENT RIGHT>"));
1046 else if (iArgValue == _L("CENTER"))
1051 iParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
1052 iParaFormatMask.SetAttrib(EAttAlignment);
1055 iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
1056 iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1059 OutputToScreen(_L("<ALIGNMENT CENTER>"));
1061 else if (iArgValue == _L("JUSTIFIED"))
1066 iParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign;
1067 iParaFormatMask.SetAttrib(EAttAlignment);
1070 iGlobalParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign;
1071 iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1074 OutputToScreen(_L("<ALIGNMENT JUSTIFIED>"));
1077 iErrorLevel = EIllegalAttribValue;
1081 void CParser::TransParaBullet()
1083 TInt characterCode = 0x2022;
1084 TUint32 heightInTwips=0;
1086 TBuf<KMaxTypefaceNameLength> name;
1087 TBuf<128> component;
1089 // set first component (character code)
1090 TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma
1091 component = iArgValue.Left(commaPos);
1092 if (component != _L("")) // only third arg remains
1094 if (BufIsNumeric(component))
1096 TLex tmpLex(component);
1098 tmpLex.Val(characterCode);
1101 iErrorLevel = EIllegalAttribValue;
1104 iErrorLevel = EIllegalAttribValue;
1106 // set second component (bullet height)
1107 iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1108 commaPos = iArgValue.Locate(KComma); // find pos of first comma
1109 component = iArgValue.Left(commaPos);
1110 if (component != _L("")) // only third arg remains
1112 if (BufIsNumeric(component))
1114 TLex tmpLex(component);
1117 heightInTwips = value;
1120 iErrorLevel = EIllegalAttribValue;
1123 iErrorLevel = EIllegalAttribValue;
1125 // set third component (typeface flags)
1126 iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1127 commaPos = iArgValue.Locate(KComma); // find pos of first comma
1128 component = iArgValue.Left(commaPos);
1129 if (component != _L("")) // only third arg remains
1131 flags = GetArgValue(component);
1133 iErrorLevel=EIllegalAttribValue; // only values 0,1,2 valid for flag
1136 iErrorLevel = EIllegalAttribValue;
1138 // set fourth component (typeface name)
1139 iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1140 if (iArgValue != _L("")) // only third arg remains
1142 name.Copy(iArgValue);
1143 // name = SquashBuf(iArgValue);
1146 iErrorLevel = EIllegalAttribValue;
1149 if (iErrorLevel == ENoError)
1151 iBulletUsed = ETrue;
1152 iBullet->iCharacterCode = (TText)characterCode;
1153 iBullet->iHeightInTwips = heightInTwips;
1155 iBullet->iTypeface.SetIsProportional(ETrue);
1157 iBullet->iTypeface.SetIsSerif(ETrue);
1158 iBullet->iTypeface.iName = name;
1162 iParaFormat->iBullet = iBullet;
1163 iParaFormatMask.SetAttrib(EAttBullet);
1166 iGlobalParaFormat->iBullet = iBullet;
1167 iGlobalParaFormatMask.SetAttrib(EAttBullet);
1170 OutputToScreen(_L("<BULLET>"));
1174 TBuf8<512> CParser::SquashBuf(TDes aBuffer)
1176 // Input 8/16 bit buffer to be returned as an 8-bit version
1177 // Used for unicode compatability
1180 TText16 textPointer;
1182 TBuf8<512> returnBuf;
1184 for ( TInt pos=0 ; pos<aBuffer.Length() ; pos++ )
1186 textPointer = aBuffer[pos];
1187 #pragma warning ( disable : 4244 )
1188 returnBuf[pos] = textPointer; // conversion from unsigned short to unsigned char (16 bit to 8 bit) in unicode
1189 #pragma warning ( default : 4244 )
1196 void CParser::TransParaBorderL()
1198 TParaBorder::TLineStyle lineStyle=TParaBorder::ENullLineStyle;
1199 TBool autoColor=EFalse;
1201 TBuf<128> component;
1203 // set first component
1204 TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma
1205 component = iArgValue.Left(commaPos);
1206 if (component != _L(""))
1208 if (component == _L("NULL"))
1209 lineStyle = TParaBorder::ENullLineStyle;
1210 else if (component == _L("SOLID"))
1211 lineStyle = TParaBorder::ESolid;
1212 else if (component == _L("DOUBLE"))
1213 lineStyle = TParaBorder::EDouble;
1214 else if (component == _L("DOTTED"))
1215 lineStyle = TParaBorder::EDotted;
1216 else if (component == _L("DASHED"))
1217 lineStyle = TParaBorder::EDashed;
1218 else if (component == _L("DOTDASH"))
1219 lineStyle = TParaBorder::EDotDash;
1220 else if (component == _L("DOTDOTDASH"))
1221 lineStyle = TParaBorder::EDotDotDash;
1223 iErrorLevel = EIllegalAttribValue;
1226 iErrorLevel = EIllegalAttribValue;
1228 // set second component
1229 iArgValue.Delete(0,commaPos+1); // delete first component & trailing comma
1230 commaPos = iArgValue.Locate(KComma); // find pos of first comma
1231 component = iArgValue.Left(commaPos);
1232 if (component != _L(""))
1234 if (component == _L("ON"))
1236 else if (component == _L("OFF"))
1239 iErrorLevel = EIllegalAttribValue;
1242 iErrorLevel = EIllegalAttribValue;
1244 // set third component
1245 iArgValue.Delete(0,commaPos+1); // delete second component & trailing comma
1246 if (component != _L("")) // only third arg remains
1248 if (BufIsNumeric(iArgValue))
1250 TLex tmpLex(iArgValue);
1253 color=TRgb((TUint32)value);
1256 iErrorLevel = EIllegalAttribValue;
1260 if (iErrorLevel == ENoError)
1262 iBorderUsed = ETrue;
1263 iBorder->iLineStyle = lineStyle;
1264 iBorder->iAutoColor = autoColor;
1265 iBorder->iColor = color;
1266 if (iArgType == _L("TOPBORDER"))
1271 iParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder);
1272 iParaFormatMask.SetAttrib(EAttTopBorder);
1275 iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder);
1276 iGlobalParaFormatMask.SetAttrib(EAttTopBorder);
1280 if (iArgType == _L("BOTTOMBORDER"))
1285 iParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder);
1286 iParaFormatMask.SetAttrib(EAttBottomBorder);
1289 iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder);
1290 iGlobalParaFormatMask.SetAttrib(EAttBottomBorder);
1294 if (iArgType == _L("LEFTBORDER"))
1299 iParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder);
1300 iParaFormatMask.SetAttrib(EAttLeftBorder);
1303 iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder);
1304 iGlobalParaFormatMask.SetAttrib(EAttLeftBorder);
1308 if (iArgType == _L("RIGHTBORDER"))
1313 iParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder);
1314 iParaFormatMask.SetAttrib(EAttRightBorder);
1317 iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder);
1318 iGlobalParaFormatMask.SetAttrib(EAttRightBorder);
1322 OutputToScreen(_L("<PARA BORDER>"));
1326 void CParser::TransParaTabWidth()
1328 TInt32 tabWidth = GetArgValue();
1332 iParaFormat->iDefaultTabWidthInTwips = tabWidth;
1333 iParaFormatMask.SetAttrib(EAttDefaultTabWidth);
1336 iGlobalParaFormat->iDefaultTabWidthInTwips = tabWidth;
1337 iGlobalParaFormatMask.SetAttrib(EAttDefaultTabWidth);
1342 outputBuf.Format(_L("<DEFAULT TAB WIDTH = %d>"),tabWidth);
1343 OutputToScreen(outputBuf);
1347 void CParser::TransParaTabStopL()
1348 // This arg has a compound value of the form Tabstop=value,type
1349 // It also accepts !Tabstop=value to delete an existing tabstop
1352 TBuf<128> component;
1355 // get first component (tab type)
1356 TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma (returns -1 if no comma)
1357 if (commaPos > 0) // comma & first component exist
1359 component = iArgValue.Left(commaPos); // take part to the left of the comma
1360 if (component != _L(""))
1361 tabStop.iTwipsPosition = GetArgValue(component);
1363 iErrorLevel = EIllegalAttribValue;
1365 else if ((iCancelArg)&&(commaPos == -1)) // no comma but only one component required (position)
1367 if (iArgValue != _L(""))
1368 tabStop.iTwipsPosition = GetArgValue(iArgValue);
1370 iErrorLevel = EIllegalAttribValue;
1373 if (iErrorLevel == ENoError)
1376 // insert a null tab
1378 if ((iParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound)
1379 ||(iGlobalParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound))
1381 tabStop.iType = TTabStop::ENullTab; // null tab "deletes" existing tab
1382 outputBuf = _L("<!TAB>");
1385 iErrorLevel = EIllegalAttribValue;
1389 // set second component (tab position in twips)
1390 iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1391 if (iArgValue != _L(""))
1393 outputBuf = _L("<TAB>");
1394 if (iArgValue == _L("NULL"))
1395 tabStop.iType = TTabStop::ENullTab;
1396 else if (iArgValue == _L("LEFT"))
1397 tabStop.iType = TTabStop::ELeftTab;
1398 else if (iArgValue == _L("CENTERED"))
1399 tabStop.iType = TTabStop::ECenteredTab;
1400 else if (iArgValue == _L("RIGHT"))
1401 tabStop.iType = TTabStop::ERightTab;
1403 iErrorLevel = EIllegalAttribValue;
1406 iErrorLevel = EIllegalAttribValue;
1411 if (iErrorLevel == ENoError)
1416 iParaFormat->StoreTabL(tabStop);
1417 iParaFormatMask.SetAttrib(EAttTabStop);
1420 iGlobalParaFormat->StoreTabL(tabStop);
1421 iGlobalParaFormatMask.SetAttrib(EAttTabStop);
1425 OutputToScreen(outputBuf);
1430 void CParser::TransCharArg()
1432 if (iArgType != _L("")) // Is there an argument?
1434 if (iArgType == _L("DEFAULT"))
1436 else if (iArgType == _L("ITALIC"))
1438 else if (iArgType == _L("BOLD"))
1439 TransCharStrokeWeight();
1440 else if (iArgType == _L("UNDERLINE"))
1441 TransCharUnderline();
1442 else if (iArgType == _L("STRIKETHROUGH"))
1443 TransCharStrikethrough();
1444 else if (!iArgValueExpected) // No argument value supplied when one is required for the
1445 iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied
1446 else if (iArgType == _L("FONTHEIGHT"))
1447 TransCharFontHeight();
1448 else if (iArgType == _L("PRINTPOS"))
1449 TransCharPrintPos();
1450 else if (iArgType == _L("TYPEFACENAME"))
1451 TransCharTypefaceName();
1452 else if (iArgType == _L("TYPEFACEFLAGS"))
1453 TransCharTypefaceFlags();
1454 else if (iArgType == _L("COLOR"))
1456 else if (iArgType == _L("LANGUAGE"))
1457 TransCharLanguage();
1459 iErrorLevel = EUnknownAttrib;
1464 void CParser::TransCharDefault()
1465 // turns off all applied Char formatting - reverts to global
1467 iCharFormatMask.ClearAll();
1468 OutputToScreen(_L("<CHAR-DEFAULT>"));
1472 void CParser::TransCharPosture()
1478 iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright);
1480 iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
1481 iCharFormatMask.SetAttrib(EAttFontPosture);
1485 iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright);
1487 iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
1488 iGlobalCharFormatMask.SetAttrib(EAttFontPosture);
1492 OutputToScreen(_L("<ITALIC>"));
1496 void CParser::TransCharStrokeWeight()
1502 iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
1504 iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
1505 iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
1509 iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
1511 iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
1512 iGlobalCharFormatMask.SetAttrib(EAttFontStrokeWeight);
1516 OutputToScreen(_L("<BOLD>"));
1520 void CParser::TransCharUnderline()
1526 iCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
1528 iCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
1529 iCharFormatMask.SetAttrib(EAttFontUnderline);
1533 iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
1535 iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
1536 iGlobalCharFormatMask.SetAttrib(EAttFontUnderline);
1540 OutputToScreen(_L("<UNDERLINE>"));
1544 void CParser::TransCharStrikethrough()
1550 iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff;
1552 iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;
1553 iCharFormatMask.SetAttrib(EAttFontStrikethrough);
1557 iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff;
1559 iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;
1560 iGlobalCharFormatMask.SetAttrib(EAttFontStrikethrough);
1564 OutputToScreen(_L("<STRIKETHROUGH>"));
1568 void CParser::TransCharFontHeight()
1570 TInt32 fontHeight = GetArgValue();
1574 iCharFormat.iFontSpec.iHeight = fontHeight;
1575 iCharFormatMask.SetAttrib(EAttFontHeight);
1578 iGlobalCharFormat.iFontSpec.iHeight = fontHeight;
1579 iGlobalCharFormatMask.SetAttrib(EAttFontHeight);
1584 outputBuf.Format(_L("<FONTHEIGHT = %d>"),fontHeight);
1585 OutputToScreen(outputBuf);
1588 void CParser::TransCharPrintPos()
1590 if (iArgValue == _L("NORMAL"))
1595 iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal);
1596 iCharFormatMask.SetAttrib(EAttFontPrintPos);
1599 iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal);
1600 iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
1603 OutputToScreen(_L("<PRINT POSITION NORMAL>"));
1605 else if (iArgValue == _L("SUPERSCRIPT"))
1610 iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
1611 iCharFormatMask.SetAttrib(EAttFontPrintPos);
1614 iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
1615 iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
1618 OutputToScreen(_L("<SUPERSCRIPT>"));
1620 else if (iArgValue == _L("SUBSCRIPT"))
1625 iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
1626 iCharFormatMask.SetAttrib(EAttFontPrintPos);
1629 iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
1630 iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
1633 OutputToScreen(_L("<SUBSCRIPT>"));
1636 iErrorLevel = EIllegalAttribValue;
1640 void CParser::TransCharTypefaceFlags()
1642 TUint flags = GetArgValue();
1644 iErrorLevel=EIllegalAttribValue; // only values 0,1,2 valid for flag
1645 if (iErrorLevel==ENoError)
1651 iCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue);
1653 iCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue);
1654 iCharFormatMask.SetAttrib(EAttFontTypeface);
1658 iGlobalCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue);
1660 iGlobalCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue);
1661 iGlobalCharFormatMask.SetAttrib(EAttFontTypeface);
1666 outputBuf.Format(_L("<TYPEFACE FLAGS = %d>"),flags);
1667 OutputToScreen(outputBuf);
1672 void CParser::TransCharTypefaceName()
1677 iCharFormat.iFontSpec.iTypeface.iName=iArgValue;
1678 iCharFormatMask.SetAttrib(EAttFontTypeface);
1681 iGlobalCharFormat.iFontSpec.iTypeface.iName=iArgValue;
1682 iGlobalCharFormatMask.SetAttrib(EAttFontTypeface);
1687 outputBuf.Format(_L("<TYPEFACE NAME = %S>"),&iArgValue);
1688 OutputToScreen(outputBuf);
1692 void CParser::TransCharColor()
1694 TUint value = GetArgValue();
1695 if (iErrorLevel==ENoError)
1698 color=TRgb((TUint32)value);
1702 iCharFormat.iFontPresentation.iTextColor = color;
1703 iCharFormatMask.SetAttrib(EAttColor);
1706 iGlobalCharFormat.iFontPresentation.iTextColor = color;
1707 iGlobalCharFormatMask.SetAttrib(EAttColor);
1712 outputBuf.Format(_L("<COLOR = %d>"),value);
1713 OutputToScreen(outputBuf);
1718 void CParser::TransCharLanguage()
1719 // Assumes languages are integer coded - will have to change in time
1721 TUint value = GetArgValue();
1722 if (iErrorLevel==ENoError)
1727 iCharFormat.iLanguage = value;
1728 iCharFormatMask.SetAttrib(EAttCharLanguage);
1731 iGlobalCharFormat.iLanguage = value;
1732 iGlobalCharFormatMask.SetAttrib(EAttCharLanguage);
1737 outputBuf.Format(_L("<LANGUAGE = %d>"),value);
1738 OutputToScreen(outputBuf);
1744 ////////////////////////////////
1746 ////////////////////////////////
1749 CFileApp* CFileApp::NewL()
1751 CFileApp* self=new(ELeave) CFileApp;
1752 CleanupStack::PushL(self);
1753 self->ConstructApplicationL();
1754 CleanupStack::Pop();
1759 CFileApp::CFileApp()
1762 iConsoleExists = EFalse;
1767 void CFileApp::ConstructApplicationL()
1769 iTextBuf = CBufSeg::NewL(64); // Granularity of 64 bytes
1773 CFileApp::~CFileApp()
1779 CBufSeg* CFileApp::LoadFileL(CConsoleBase* aConsoleWin)
1780 // Asks for file name, then loads file into text buffer.
1782 iConsoleExists = ETrue;
1783 iConsole = aConsoleWin; // grab console handle
1785 FileHandlingL(); // load file & store it
1789 CBufSeg* CFileApp::LoadFileL(const TFileName &aFileName)
1790 // uses supplied FileName to load file into CBufSeg
1792 iFileName = aFileName;
1793 FileHandlingL(); // load file & store it
1798 void CFileApp::OutputToScreen(const TDesC& aMessageBuffer)
1801 iConsole->Write(aMessageBuffer); // output line to screen
1805 TInt CFileApp::SaveFile(CBufSeg* aTextBuf, TFileName aFileName)
1806 // saves supplied buffer to disc, making the new filename a varient of the PML source filename supplied
1808 // set filename to be saved as
1809 TInt length = aFileName.Length();
1810 aFileName.Delete(length-1,1);
1811 aFileName.Append(_L("G")); // generated filenames end in G
1813 // create fileserver client and save.
1816 TInt err = fsClient.Connect();
1818 err = theFile.Replace(fsClient, aFileName, EFileStream|EFileRead|EFileWrite);
1821 TInt readWritePos = 0;
1822 TBuf8<80> insertBuf;
1826 // read from TextBuf into insertBuf
1827 readLength=Min(aTextBuf->Size()-readWritePos,insertBuf.MaxLength());
1828 insertBuf.SetLength(0); // empty buffer
1829 aTextBuf->Read(readWritePos,insertBuf,readLength);
1830 // insert buf into file
1831 theFile.Write(readWritePos, insertBuf);
1832 readWritePos += insertBuf.Length();
1833 if (readWritePos >= aTextBuf->Size())
1841 void CFileApp::GetFileName()
1842 // read FileName synchronously from console
1844 TKeyCode keystroke = EKeyNull;
1845 iFileName.SetLength(0);
1847 //Debuging cheat to hardwire filename
1848 //iFileName=_L("d:\\etext\\incp\\dunk.pml");
1851 OutputToScreen(_L("Enter file to be parsed: "));
1852 keystroke = iConsole->Getch();
1853 while (keystroke != EKeyEnter)
1855 TBuf<1> uniBuf; // used to ease unicode build
1856 uniBuf.Append(keystroke);
1858 iConsole->Write(uniBuf);
1859 iFileName.Append(uniBuf);
1860 keystroke = iConsole->Getch();
1865 void CFileApp::FileHandlingL()
1866 // Open a file, read contents into buffer, then close file again
1874 err = fsClient.Connect();
1876 err = textFile.Open(fsClient,iFileName,EFileStream|EFileRead|EFileShareReadersOnly);
1881 OutputToScreen(_L("Error in file open\n\n"));
1887 OutputToScreen(_L("Parsing "));
1888 OutputToScreen(iFileName);
1892 // Read file into segmented buffer
1893 TUint insertPos = 0;
1895 TInt max = sizeof(TText) * KFileBufSize;
1899 iFileBuf.SetLength(0);
1900 ReadChunkOfFileContents(textFile);
1901 iTextBuf->/*Do*/InsertL(insertPos,iFileBuf.Ptr(),iFileBuf.Size());
1902 insertPos += iFileBuf.Size(); // in bytes
1903 if (iFileBuf.Size() < max)
1909 iFilePos = 0; // reset
1912 void CFileApp::ReadChunkOfFileContents(RFile &aFile)
1914 TBuf8<KFileBufSize> readBuf;
1915 aFile.Read(iFilePos,readBuf);
1916 // read into iFileBuf (8/16 bit);
1918 for ( TInt pos=0 ; pos<readBuf.Length() ; pos++ )
1920 textPointer = readBuf[pos];
1921 iFileBuf.Append(textPointer);
1923 //TInt ret=aFile.Read(iFilePos,iFileBuf);
1924 iFilePos += KFileBufSize;
1927 void CFileApp::WriteNewLine()
1930 TBuf<1> buf(_L("\n"));
1931 OutputToScreen(buf);