os/textandloc/textrendering/texthandling/spml/T_PMLPAR.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "../incp/T_PMLPAR.H"
sl@0
    20
sl@0
    21
#define UNUSED_VAR(a) a = a
sl@0
    22
sl@0
    23
#define UNUSED_VAR(a) a = a
sl@0
    24
sl@0
    25
////////////////////////////////////////////
sl@0
    26
// CParser
sl@0
    27
////////////////////////////////////////////
sl@0
    28
sl@0
    29
CParser* CParser::NewL()
sl@0
    30
	{
sl@0
    31
	CParser* self=new(ELeave) CParser;
sl@0
    32
	CleanupStack::PushL(self);
sl@0
    33
	self->ConstructApplicationL();
sl@0
    34
	CleanupStack::Pop();
sl@0
    35
	return self;
sl@0
    36
	}
sl@0
    37
sl@0
    38
sl@0
    39
CParser::CParser()
sl@0
    40
	{
sl@0
    41
	// init variables
sl@0
    42
	iErrorLevel = ENoError;			
sl@0
    43
	iParagraphIsOpen = EFalse;	
sl@0
    44
	iLineNo = 1;
sl@0
    45
	iReadPos = 0;
sl@0
    46
	iDocInsertPos = 0;
sl@0
    47
	iDocParaLength = 0;
sl@0
    48
	iDocPhraseLength = 0;
sl@0
    49
	iBorderUsed = EFalse;
sl@0
    50
	iBulletUsed = EFalse;
sl@0
    51
	}
sl@0
    52
	 
sl@0
    53
sl@0
    54
void CParser::ConstructApplicationL()
sl@0
    55
	{ 
sl@0
    56
	// Construct Rich Text Doc
sl@0
    57
	// Make the global format layers and associated formats and masks
sl@0
    58
	iGlobalParaFormatLayer=CParaFormatLayer::NewL();
sl@0
    59
	iGlobalCharFormatLayer=CCharFormatLayer::NewL();
sl@0
    60
	iGlobalParaFormat=CParaFormat::NewL();	   	// initialised with factory settings
sl@0
    61
	iGlobalParaFormatMask.SetAll();
sl@0
    62
	iGlobalCharFormatMask.SetAll();
sl@0
    63
	
sl@0
    64
	// Set the global layers
sl@0
    65
	iGlobalParaFormatLayer->SetL(iGlobalParaFormat,iGlobalParaFormatMask);
sl@0
    66
	iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask);
sl@0
    67
sl@0
    68
	// Create the rich text document
sl@0
    69
	iRichTextDoc=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer);
sl@0
    70
sl@0
    71
	// Initialise the paragraph and character layers
sl@0
    72
	iParaFormatLayer = CParaFormatLayer::NewL();
sl@0
    73
	iCharFormatLayer = CCharFormatLayer::NewL();
sl@0
    74
	iParaFormat = CParaFormat::NewL();
sl@0
    75
sl@0
    76
	// Create temp alias' for compound attributes
sl@0
    77
	iBorder = new TParaBorder;
sl@0
    78
	User::LeaveIfNull(iBorder);
sl@0
    79
	iBullet = new (ELeave) TBullet;
sl@0
    80
	}
sl@0
    81
sl@0
    82
sl@0
    83
CParser::~CParser()
sl@0
    84
	{
sl@0
    85
	// destroy Rich Text Document
sl@0
    86
// 	delete iRichTextDoc;
sl@0
    87
//	delete iGlobalParaFormatLayer;
sl@0
    88
//	delete iGlobalCharFormatLayer;
sl@0
    89
	delete iGlobalParaFormat;
sl@0
    90
	delete iParaFormatLayer;
sl@0
    91
	delete iCharFormatLayer;
sl@0
    92
	delete iParaFormat;
sl@0
    93
	if (!iBorderUsed)
sl@0
    94
		delete(iBorder);
sl@0
    95
	if (!iBulletUsed)
sl@0
    96
		delete(iBullet);
sl@0
    97
	}
sl@0
    98
sl@0
    99
sl@0
   100
CRichText* CParser::ParseL(CConsoleBase* aConsole)
sl@0
   101
// version for parsing with console output and interactive file dialog
sl@0
   102
// primarily for debugging purposes (you can see what's going on!)
sl@0
   103
	{
sl@0
   104
	// set console
sl@0
   105
	iConsoleExists = ETrue;
sl@0
   106
	iConsole = aConsole;
sl@0
   107
sl@0
   108
	// Construct a CFileApp & load a file
sl@0
   109
	CFileApp* myFileApp=NULL;
sl@0
   110
	TRAPD(ret, myFileApp = CFileApp::NewL());
sl@0
   111
    UNUSED_VAR(ret);
sl@0
   112
	iTextBuf = myFileApp->LoadFileL(iConsole);
sl@0
   113
	iFileName = myFileApp->ReturnFileName();
sl@0
   114
sl@0
   115
	ParseTextBufL();	   			// parse the buffer
sl@0
   116
	delete myFileApp;	// destroy file app
sl@0
   117
sl@0
   118
	// Pause before returning
sl@0
   119
	WriteNewLine();
sl@0
   120
	WriteNewLine();
sl@0
   121
	OutputToScreen(_L("Press Space to continue\n"));
sl@0
   122
	TKeyCode keystroke = EKeyNull;
sl@0
   123
	while (keystroke != EKeySpace)
sl@0
   124
		keystroke = iConsole->Getch();
sl@0
   125
	return iRichTextDoc;
sl@0
   126
	}
sl@0
   127
sl@0
   128
CRichText* CParser::ParseL(const TFileName &aFileName)
sl@0
   129
// silent version of the parser
sl@0
   130
	{
sl@0
   131
	iConsoleExists = EFalse;
sl@0
   132
	// Construct a CFileApp & load a file
sl@0
   133
	CFileApp* myFileApp=NULL;
sl@0
   134
	TRAPD(ret, myFileApp = CFileApp::NewL());
sl@0
   135
    UNUSED_VAR(ret);
sl@0
   136
	iTextBuf = myFileApp->LoadFileL(aFileName);
sl@0
   137
	iFileName = myFileApp->ReturnFileName();
sl@0
   138
sl@0
   139
	ParseTextBufL();	   			// parse the buffer
sl@0
   140
	delete myFileApp;	// destroy file app
sl@0
   141
sl@0
   142
	return iRichTextDoc;
sl@0
   143
	}
sl@0
   144
sl@0
   145
sl@0
   146
void CParser::EmitErrorMessage()
sl@0
   147
	{
sl@0
   148
	TBuf<80> errorMessage;
sl@0
   149
	switch (iErrorLevel)
sl@0
   150
		{
sl@0
   151
		case EUnknownTagType:
sl@0
   152
			errorMessage.Format(_L("    Unknown tag type: Line %d"),iLineNo);
sl@0
   153
			break;
sl@0
   154
		case EUnparagraphedText:
sl@0
   155
			errorMessage.Format(_L("    Text not contained by paragraph: Line %d"),iLineNo);
sl@0
   156
			break;
sl@0
   157
		case EUnknownAttrib:
sl@0
   158
			errorMessage.Format(_L("    Unknown tag attribute: Line %d"),iLineNo);
sl@0
   159
			break;
sl@0
   160
		case ENoAttribValue:
sl@0
   161
			errorMessage.Format(_L("    Unknown attribute or no attribute value supplied: Line %d"),iLineNo);
sl@0
   162
			break;
sl@0
   163
		case EIllegalAttribValue:
sl@0
   164
			errorMessage.Format(_L("    Illegal attribute value: Line %d"),iLineNo);
sl@0
   165
			break;
sl@0
   166
		default:
sl@0
   167
			errorMessage.Format(_L("    Error: Line %d"),iLineNo);
sl@0
   168
			break;
sl@0
   169
		}
sl@0
   170
	OutputToScreen(_L(""));
sl@0
   171
	OutputToScreen(_L("*** Error!!\n"));
sl@0
   172
	OutputToScreen(errorMessage);
sl@0
   173
	}
sl@0
   174
sl@0
   175
sl@0
   176
void CParser::OutputToScreen(const TDesC& aMessageBuffer)
sl@0
   177
	{
sl@0
   178
	if (iConsoleExists)
sl@0
   179
		iConsole->Write(aMessageBuffer);  // output line to screen
sl@0
   180
	}
sl@0
   181
sl@0
   182
sl@0
   183
TBool CParser::Validate()
sl@0
   184
// Check that document starts with <G> tag - serves as file validation
sl@0
   185
//  - Read in characters sequentially
sl@0
   186
//  - if the first alphanumeric characters encountered are not "<G" then error
sl@0
   187
	{
sl@0
   188
	TBool fileFormatError = EFalse;
sl@0
   189
	TBool fileValidated = EFalse;
sl@0
   190
	TChar charToTest;
sl@0
   191
	while ((!fileFormatError)&&(!fileValidated))
sl@0
   192
		{					
sl@0
   193
		charToTest = ReadChar();
sl@0
   194
		if (charToTest == '<')
sl@0
   195
			{
sl@0
   196
			iReadPos+=KCharLength;
sl@0
   197
			charToTest = ReadTagChar();
sl@0
   198
			if (charToTest != 'G')			 // Not a style tag - error
sl@0
   199
				fileFormatError = ETrue;
sl@0
   200
			else
sl@0
   201
				fileValidated = ETrue;
sl@0
   202
			}
sl@0
   203
		else
sl@0
   204
			{
sl@0
   205
			if (charToTest.IsAlphaDigit())	 // Char is alphanumeric - error
sl@0
   206
				fileFormatError = ETrue;	 // (File must start with style tag)
sl@0
   207
			else
sl@0
   208
				iReadPos+=KCharLength;
sl@0
   209
			}
sl@0
   210
		}
sl@0
   211
	if (fileFormatError)
sl@0
   212
		{
sl@0
   213
		OutputToScreen(_L("File format error\n"));
sl@0
   214
		}
sl@0
   215
	iReadPos = 0;		// reset after validation
sl@0
   216
	iLineNo = 1;		// ...
sl@0
   217
	return fileValidated;
sl@0
   218
	}
sl@0
   219
sl@0
   220
sl@0
   221
void CParser::ParseTextBufL()
sl@0
   222
// Parses contents of iTextBuf
sl@0
   223
// Reads in chars sequentially.
sl@0
   224
// - If a char is a tag open ("<") process the following tag
sl@0
   225
// - otherwise add the char to the text of the rich text document
sl@0
   226
// Tidy up at the end of the document 
sl@0
   227
	{ 
sl@0
   228
	TChar charToTest;
sl@0
   229
	TUint textBufSize = iTextBuf->Size();
sl@0
   230
	if (Validate())
sl@0
   231
		{
sl@0
   232
		while ((iReadPos < textBufSize)&&(iErrorLevel == ENoError))
sl@0
   233
			{
sl@0
   234
			charToTest = ReadChar();
sl@0
   235
			if (charToTest == '<')
sl@0
   236
				ProcessTagL();
sl@0
   237
			else
sl@0
   238
				ProcessTextL(charToTest);
sl@0
   239
			iReadPos+=KCharLength;						
sl@0
   240
			}
sl@0
   241
		if ((iReadPos == textBufSize)&&(iReadPos>0)&&(iErrorLevel == ENoError))
sl@0
   242
			{
sl@0
   243
			// at end of document apply any outstanding formatting (if there is text to apply it to)
sl@0
   244
			if (iDocParaLength > 0)
sl@0
   245
				{
sl@0
   246
				iParaFormatLayer->SetL(iParaFormat, iParaFormatMask);
sl@0
   247
				iRichTextDoc->ApplyParaFormatL( iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength);
sl@0
   248
				}
sl@0
   249
			if (iDocPhraseLength > 0)
sl@0
   250
				{
sl@0
   251
				iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
sl@0
   252
				iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
sl@0
   253
				}
sl@0
   254
			}
sl@0
   255
		if (iErrorLevel != ENoError)
sl@0
   256
			EmitErrorMessage();
sl@0
   257
		}
sl@0
   258
	}
sl@0
   259
sl@0
   260
sl@0
   261
TChar CParser::ReadChar()
sl@0
   262
// Reads the next character from the text buffer
sl@0
   263
	{
sl@0
   264
// 	TChar charToTest;
sl@0
   265
	TText charToTest;
sl@0
   266
	iTextBuf->Read(iReadPos,&charToTest,KCharLength);
sl@0
   267
	if (charToTest == (TText)KLineFeed)
sl@0
   268
		iLineNo++;				   	// Info used only by error messages
sl@0
   269
	return charToTest;
sl@0
   270
	}
sl@0
   271
sl@0
   272
sl@0
   273
void CParser::ProcessTextL(TChar aChar)
sl@0
   274
// 1) Check text is in a paragraph
sl@0
   275
// 2) Check for escape characters
sl@0
   276
// 3) Check for tabs
sl@0
   277
// 4) Add to paragraph
sl@0
   278
	{
sl@0
   279
	if (!iParagraphIsOpen)
sl@0
   280
		{
sl@0
   281
		if (!(aChar.IsControl()))
sl@0
   282
			iErrorLevel = EUnparagraphedText;	// Text not contained by a paragraph - error!!
sl@0
   283
		}
sl@0
   284
	else
sl@0
   285
		{
sl@0
   286
		if (aChar == '/')	// Escape character for <
sl@0
   287
			{
sl@0
   288
			TChar tempChar;
sl@0
   289
			iTextBuf->Read(iReadPos+KCharLength,&tempChar,1);	// doesn't increment line counter
sl@0
   290
			if (tempChar == '<')
sl@0
   291
				{
sl@0
   292
				AddCharToParaL(tempChar);
sl@0
   293
				iReadPos+=2*KCharLength;				  	// Skip escape character
sl@0
   294
				}
sl@0
   295
			else
sl@0
   296
				AddCharToParaL(aChar);
sl@0
   297
			}
sl@0
   298
		else if (aChar == KTabChar)
sl@0
   299
			AddCharToParaL(aChar);
sl@0
   300
		else if (!(aChar.IsControl()))		// if it's not a control char add it 
sl@0
   301
			AddCharToParaL(aChar);			//		(this includes spaces)
sl@0
   302
		}
sl@0
   303
	}
sl@0
   304
sl@0
   305
sl@0
   306
void CParser::AddCharToParaL(TChar aChar)
sl@0
   307
	{ 
sl@0
   308
	// Add char to RichText doc...
sl@0
   309
	iRichTextDoc->InsertL(iDocInsertPos, aChar);
sl@0
   310
	iDocInsertPos++;
sl@0
   311
	iDocParaLength++;
sl@0
   312
	if (iPhraseOpen)
sl@0
   313
		iDocPhraseLength++;
sl@0
   314
	// and also write it to screen
sl@0
   315
	TBuf<4> screenBuf;				// Buffer for text to be written to console
sl@0
   316
	screenBuf.Append(aChar);		
sl@0
   317
	OutputToScreen(screenBuf);
sl@0
   318
	}
sl@0
   319
sl@0
   320
sl@0
   321
void CParser::ProcessTagL()
sl@0
   322
	{
sl@0
   323
	TChar tagChar;
sl@0
   324
	iReadPos+=KCharLength;
sl@0
   325
	tagChar = ReadTagChar();	  	// Read in tag type
sl@0
   326
	ClassifyTagL(tagChar);		  	
sl@0
   327
	if (iTagType == EError)
sl@0
   328
		iErrorLevel = EUnknownTagType;
sl@0
   329
	else
sl@0
   330
		{
sl@0
   331
		ClassifyArgumentsL();
sl@0
   332
		}
sl@0
   333
	}
sl@0
   334
sl@0
   335
sl@0
   336
TChar CParser::ReadTagChar()
sl@0
   337
	{ // Returns tag character capitalised - therefore case-insensitive
sl@0
   338
 	TChar charToTest;
sl@0
   339
	charToTest = ReadChar();
sl@0
   340
	charToTest.UpperCase();
sl@0
   341
	return charToTest;
sl@0
   342
	}
sl@0
   343
sl@0
   344
sl@0
   345
void CParser::ClassifyArgumentsL()
sl@0
   346
// reads tag one argument at a time, dealing with each arg as it is read
sl@0
   347
// If and argument is followed by a value (ie a=4) it is processed in two passes.
sl@0
   348
	{
sl@0
   349
	TChar tagChar(0);
sl@0
   350
	iArgStored = EFalse;
sl@0
   351
	iArgValueExpected = EFalse;		// Initialise
sl@0
   352
	iCancelArg = EFalse;
sl@0
   353
	while ((tagChar != '>')&&(iErrorLevel == ENoError))	// ">" is end of tag
sl@0
   354
		{
sl@0
   355
		iReadPos+=KCharLength;
sl@0
   356
		tagChar = ReadTagChar();	// Read in next bit of tag
sl@0
   357
		if (iTagType != EComment)	// text of comments is ignored
sl@0
   358
			{
sl@0
   359
			if (tagChar.IsSpace())	// spaces separate args
sl@0
   360
				ProcessArgBufL();
sl@0
   361
			if (tagChar == '=')
sl@0
   362
				{
sl@0
   363
				iArgValueExpected = ETrue;
sl@0
   364
				ProcessArgBufL();
sl@0
   365
				}
sl@0
   366
			if (tagChar == '!')
sl@0
   367
				{
sl@0
   368
				iCancelArg = ETrue;
sl@0
   369
				OutputToScreen(_L("!"));
sl@0
   370
				}
sl@0
   371
			if (tagChar == ',')
sl@0
   372
				AppendToArgBuf(tagChar);
sl@0
   373
			if (tagChar.IsAlphaDigit())
sl@0
   374
				{
sl@0
   375
				AppendToArgBuf(tagChar);
sl@0
   376
				}
sl@0
   377
			}
sl@0
   378
		}
sl@0
   379
	if (tagChar == '>')				// Is it end of tag?
sl@0
   380
		{
sl@0
   381
		if (iTagType != EComment)
sl@0
   382
			{
sl@0
   383
			ProcessArgBufL();
sl@0
   384
			if ((iTagType == EControl)||(iTagType == EGlobal))	// Control & global style formatting is applied "on the spot"
sl@0
   385
				SetFormatLayerL();								// While char & paragraph are applied retrospectively
sl@0
   386
			}
sl@0
   387
		}
sl@0
   388
	}
sl@0
   389
sl@0
   390
sl@0
   391
void CParser::AppendToArgBuf(TChar aTagChar)
sl@0
   392
	{
sl@0
   393
	iArgType.Append(aTagChar);	   	// assume it'll fit
sl@0
   394
	}
sl@0
   395
sl@0
   396
sl@0
   397
void CParser::ProcessArgBufL()
sl@0
   398
	{
sl@0
   399
	if (iArgValueExpected)
sl@0
   400
		{
sl@0
   401
		if (iArgStored)
sl@0
   402
			{
sl@0
   403
			TBuf<32> tempArgBuf;				// Swap the buffers	back as an arg and its value have been stored
sl@0
   404
			tempArgBuf = iArgType;
sl@0
   405
			EmptyBuffer(iArgType);
sl@0
   406
			iArgType = iArgValue;
sl@0
   407
			EmptyBuffer(iArgValue);
sl@0
   408
			iArgValue = tempArgBuf;
sl@0
   409
			TranslateTagArgL();				// Translate the tag argument
sl@0
   410
			iArgStored = EFalse;			// Reset the flags and buffers
sl@0
   411
			iArgValueExpected = EFalse;
sl@0
   412
			EmptyBuffer(iArgType);
sl@0
   413
			EmptyBuffer(iArgValue);
sl@0
   414
			}
sl@0
   415
		else
sl@0
   416
			{
sl@0
   417
			iArgValue = iArgType;		 	// Swap the buffers ready to store the value of the arg
sl@0
   418
			EmptyBuffer(iArgType);			// Empty buffer
sl@0
   419
			iArgStored = ETrue;
sl@0
   420
			}
sl@0
   421
		}
sl@0
   422
	else
sl@0
   423
		{
sl@0
   424
		TranslateTagArgL();			// match to list
sl@0
   425
		EmptyBuffer(iArgType);
sl@0
   426
		EmptyBuffer(iArgValue);
sl@0
   427
		}
sl@0
   428
	}
sl@0
   429
sl@0
   430
sl@0
   431
void CParser::EmptyBuffer(TDes &aBuf)
sl@0
   432
	{
sl@0
   433
	aBuf.SetLength(0);
sl@0
   434
	}
sl@0
   435
sl@0
   436
	 
sl@0
   437
void CParser::ClassifyTagL(TChar aTagChar)
sl@0
   438
	{
sl@0
   439
	switch (aTagChar)
sl@0
   440
		{
sl@0
   441
		case 'G':
sl@0
   442
			iTagType = EGlobal;
sl@0
   443
			break;
sl@0
   444
		case 'P':
sl@0
   445
			{
sl@0
   446
			iTagType = EParagraph;
sl@0
   447
			if (iParagraphIsOpen)
sl@0
   448
				{
sl@0
   449
				iRichTextDoc->InsertL(iDocInsertPos,CEditableText::EParagraphDelimiter);  // insert para delimiter
sl@0
   450
				WriteNewLine();				// Write new line to console
sl@0
   451
				iDocInsertPos++;			// Paragraph delimiters occupy 1 character space
sl@0
   452
				iDocParaLength++;
sl@0
   453
				if (iPhraseOpen)
sl@0
   454
					iDocPhraseLength++;
sl@0
   455
				SetFormatLayerL();			// apply formatting to old para before starting to fill new one
sl@0
   456
				}
sl@0
   457
			else
sl@0
   458
				iParagraphIsOpen = ETrue;
sl@0
   459
			break;
sl@0
   460
			}
sl@0
   461
		case 'C':
sl@0
   462
			{
sl@0
   463
			iTagType = ECharacter;
sl@0
   464
			if (iPhraseOpen)                                                      
sl@0
   465
				SetFormatLayerL();	// apply formatting to old phrase retrospectively 			    
sl@0
   466
			else 
sl@0
   467
				iPhraseOpen = ETrue;		
sl@0
   468
			break;
sl@0
   469
			}
sl@0
   470
		case 'X':
sl@0
   471
			iTagType = EControl;
sl@0
   472
			break;
sl@0
   473
		case '!':
sl@0
   474
			iTagType = EComment;
sl@0
   475
			break;
sl@0
   476
		default:
sl@0
   477
			iTagType = EError;
sl@0
   478
			break;
sl@0
   479
		}
sl@0
   480
	}
sl@0
   481
sl@0
   482
sl@0
   483
void CParser::SetFormatLayerL()
sl@0
   484
// Apply format & mask that have been set in the tag to a Layer
sl@0
   485
// Apply the layer to the RichText doc
sl@0
   486
	{
sl@0
   487
	if (iTagType == EGlobal)
sl@0
   488
		{
sl@0
   489
		iGlobalParaFormatLayer->SetL(iGlobalParaFormat, iGlobalParaFormatMask);
sl@0
   490
		iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask);
sl@0
   491
		iRichTextDoc->SetGlobalParaFormat(iGlobalParaFormatLayer);
sl@0
   492
		iRichTextDoc->SetGlobalCharFormat(iGlobalCharFormatLayer);
sl@0
   493
		WriteNewLine();
sl@0
   494
		}
sl@0
   495
	if (iTagType == EParagraph)
sl@0
   496
		{
sl@0
   497
		iParaFormatLayer->SetL(iParaFormat, iParaFormatMask);
sl@0
   498
		iRichTextDoc->ApplyParaFormatL(iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength);
sl@0
   499
		iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
sl@0
   500
		if (iDocPhraseLength > 0)
sl@0
   501
			iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
sl@0
   502
		iDocParaLength = 0;			// reset ready for new paragraph
sl@0
   503
		iDocPhraseLength = 0;
sl@0
   504
		}
sl@0
   505
	if (iTagType == ECharacter)
sl@0
   506
		{
sl@0
   507
		iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
sl@0
   508
		if (iDocPhraseLength > 0)
sl@0
   509
			iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
sl@0
   510
		iDocPhraseLength = 0;
sl@0
   511
		}
sl@0
   512
	}
sl@0
   513
sl@0
   514
sl@0
   515
TInt CParser::GetArgValue()
sl@0
   516
// converts numerals in iArgValue to a TInt, 
sl@0
   517
// first checking that the buffer is totally numeric in content
sl@0
   518
 	{
sl@0
   519
	TInt value = 0;
sl@0
   520
	if (BufIsNumeric(iArgValue))
sl@0
   521
		{
sl@0
   522
		TLex tmpLex(iArgValue);
sl@0
   523
		tmpLex.Val(value);
sl@0
   524
		}
sl@0
   525
	else iErrorLevel = EIllegalAttribValue;
sl@0
   526
	return value;
sl@0
   527
	}
sl@0
   528
sl@0
   529
sl@0
   530
TInt CParser::GetArgValue(const TDes &aBuf)
sl@0
   531
// converts numerals in aBuf to a TInt as above
sl@0
   532
	{ 
sl@0
   533
	TInt value = 0;
sl@0
   534
	if (BufIsNumeric(aBuf))
sl@0
   535
		{
sl@0
   536
		TLex tmpLex(aBuf);
sl@0
   537
		tmpLex.Val(value);
sl@0
   538
		}
sl@0
   539
	else iErrorLevel = EIllegalAttribValue;
sl@0
   540
	return value;
sl@0
   541
	}
sl@0
   542
sl@0
   543
sl@0
   544
TBool CParser::BufIsNumeric(const TDes &aBuffer)
sl@0
   545
// checks that aBuffer is totally numeric in content.
sl@0
   546
// checks all characters sequentially
sl@0
   547
	{
sl@0
   548
	TBool isNumeric = ETrue;
sl@0
   549
	TChar testChar;
sl@0
   550
	TUint bufLength = aBuffer.Length();
sl@0
   551
	for (TUint pos=0; ((pos<bufLength)&&(isNumeric)); pos++)
sl@0
   552
		{
sl@0
   553
		testChar = (aBuffer[pos]);
sl@0
   554
		if (!(testChar.IsDigit()&&isNumeric))
sl@0
   555
			isNumeric = EFalse;
sl@0
   556
		}
sl@0
   557
	return isNumeric;
sl@0
   558
	}
sl@0
   559
sl@0
   560
/* All the TransXxx.. functions translate arguments and their values and apply these 
sl@0
   561
	to RichText Formats and Masks */
sl@0
   562
sl@0
   563
sl@0
   564
void CParser::TranslateTagArgL()
sl@0
   565
	{
sl@0
   566
	switch (iTagType)
sl@0
   567
		{
sl@0
   568
		case EGlobal:
sl@0
   569
			TransGlobalArgL();
sl@0
   570
			break;
sl@0
   571
		case EParagraph:
sl@0
   572
			TransParagraphArgL(); 
sl@0
   573
			break;
sl@0
   574
		case ECharacter:
sl@0
   575
			TransCharArg();
sl@0
   576
			break;
sl@0
   577
		case EControl:
sl@0
   578
			TransControlArgL();
sl@0
   579
			break;
sl@0
   580
		case EError:
sl@0
   581
			break;
sl@0
   582
		}
sl@0
   583
	iCancelArg = EFalse;  // reset
sl@0
   584
	}
sl@0
   585
sl@0
   586
sl@0
   587
void CParser::TransControlArgL()
sl@0
   588
	{
sl@0
   589
	if (iArgType != _L(""))
sl@0
   590
		{
sl@0
   591
		if (iArgType == _L("TAB"))
sl@0
   592
			AddCharToParaL(KTabChar);	// TransTab();
sl@0
   593
		else
sl@0
   594
			iErrorLevel = EUnknownAttrib;
sl@0
   595
		}
sl@0
   596
	}
sl@0
   597
sl@0
   598
sl@0
   599
void CParser::TransGlobalArgL()
sl@0
   600
// Test for each possible arg in turn
sl@0
   601
// (a switch statement cannot be used)
sl@0
   602
	{
sl@0
   603
	if (iArgType != _L("")) 				// Is there an argument?
sl@0
   604
		{
sl@0
   605
		if (iArgType == _L("KEEPTOGETHER"))	
sl@0
   606
				TransParaKeepTogether();
sl@0
   607
		else if (iArgType == _L("KEEPWITHNEXT"))
sl@0
   608
				TransParaKeepWithNext();
sl@0
   609
		else if (iArgType == _L("STARTNEWPAGE"))	
sl@0
   610
				TransParaStartNewPage();
sl@0
   611
		else if (iArgType == _L("WIDOWORPHAN"))	 	
sl@0
   612
				TransParaWidowOrphan();
sl@0
   613
sl@0
   614
		if (iArgType == _L("ITALIC"))	
sl@0
   615
				TransCharPosture();
sl@0
   616
		else if (iArgType == _L("BOLD"))	
sl@0
   617
				TransCharStrokeWeight();
sl@0
   618
		else if (iArgType == _L("UNDERLINE"))	
sl@0
   619
				TransCharUnderline();
sl@0
   620
		else if (iArgType == _L("STRIKETHROUGH"))
sl@0
   621
				TransCharStrikethrough();
sl@0
   622
sl@0
   623
		else if (!iArgValueExpected)			// No argument value supplied when one is required for the
sl@0
   624
				iErrorLevel = ENoAttribValue;	// remaining options or an unknown argument supplied
sl@0
   625
sl@0
   626
		else if (iArgType == _L("PARALANGUAGE")) 
sl@0
   627
				OutputToScreen(_L("PARA LANGUAGE "));
sl@0
   628
		else if (iArgType == _L("LEFTMARGIN")) 	 	   
sl@0
   629
				TransParaArgLeftMargin();
sl@0
   630
		else if (iArgType == _L("RIGHTMARGIN"))  	
sl@0
   631
				TransParaArgRightMargin();
sl@0
   632
		else if (iArgType == _L("INDENT"))		 
sl@0
   633
				TransParaArgIndent();
sl@0
   634
		else if (iArgType == _L("ALIGNMENT"))	 
sl@0
   635
				TransParaArgAlignment();
sl@0
   636
		else if (iArgType == _L("LINESPACING"))	 
sl@0
   637
				TransParaLineSpacing();
sl@0
   638
		else if (iArgType == _L("LINESPACINGCONTROL"))   
sl@0
   639
				TransParaArgLineSpacingControl();
sl@0
   640
		else if (iArgType == _L("SPACEBEFORE"))	 	
sl@0
   641
				TransParaSpaceBefore();
sl@0
   642
		else if (iArgType == _L("SPACEAFTER"))	 
sl@0
   643
				TransParaSpaceAfter();
sl@0
   644
		else if (iArgType == _L("BORDERMARGIN"))	
sl@0
   645
				TransParaBorderMargin();
sl@0
   646
		else if (iArgType == _L("TOPBORDER"))	 	
sl@0
   647
				TransParaBorderL();
sl@0
   648
		else if (iArgType == _L("BOTTOMBORDER"))	
sl@0
   649
				TransParaBorderL();
sl@0
   650
		else if (iArgType == _L("LEFT BORDER"))	 
sl@0
   651
				TransParaBorderL();
sl@0
   652
		else if (iArgType == _L("RIGHTBORDER"))	 
sl@0
   653
				TransParaBorderL();
sl@0
   654
		else if (iArgType == _L("BULLET"))		 
sl@0
   655
				TransParaBullet();
sl@0
   656
		else if (iArgType == _L("DEFAULTTABWIDTH"))
sl@0
   657
				TransParaTabWidth();
sl@0
   658
		else if (iArgType == _L("TABSTOP"))
sl@0
   659
				TransParaTabStopL();
sl@0
   660
sl@0
   661
		else if (iArgType == _L("FONTHEIGHT"))	
sl@0
   662
				TransCharFontHeight();
sl@0
   663
		else if (iArgType == _L("PRINTPOS"))	
sl@0
   664
				TransCharPrintPos();
sl@0
   665
		else if (iArgType == _L("TYPEFACENAME"))
sl@0
   666
				TransCharTypefaceName();
sl@0
   667
		else if (iArgType == _L("TYPEFACEFLAGS"))	
sl@0
   668
				TransCharTypefaceFlags();
sl@0
   669
		else if (iArgType == _L("COLOR"))	 	 
sl@0
   670
				TransCharColor();
sl@0
   671
		else if (iArgType == _L("LANGUAGE"))	
sl@0
   672
				TransCharLanguage();
sl@0
   673
		else 
sl@0
   674
				iErrorLevel = EUnknownAttrib;
sl@0
   675
		}
sl@0
   676
	}
sl@0
   677
sl@0
   678
sl@0
   679
void CParser::TransParagraphArgL()
sl@0
   680
// Test for each possible arg in turn
sl@0
   681
// (a switch statement cannot be used)
sl@0
   682
	{
sl@0
   683
	if (iArgType != _L("")) 				// Is there an argument?
sl@0
   684
		{
sl@0
   685
		if (iArgType == _L("DEFAULT"))		
sl@0
   686
				TransParaDefault();
sl@0
   687
		else if (iArgType == _L("KEEPTOGETHER"))
sl@0
   688
				TransParaKeepTogether();
sl@0
   689
		else if (iArgType == _L("KEEPWITHNEXT"))
sl@0
   690
				TransParaKeepWithNext();
sl@0
   691
		else if (iArgType == _L("STARTNEWPAGE"))
sl@0
   692
				TransParaStartNewPage();
sl@0
   693
		else if (iArgType == _L("WIDOWORPHAN"))	 
sl@0
   694
				TransParaWidowOrphan();
sl@0
   695
		else if (!iArgValueExpected)			// No argument value supplied when one is required for the
sl@0
   696
				iErrorLevel = ENoAttribValue;	// remaining options or an unknown argument supplied
sl@0
   697
		else if (iArgType == _L("PARALANGUAGE")) 
sl@0
   698
				OutputToScreen(_L("PARA LANGUAGE "));
sl@0
   699
		else if (iArgType == _L("LEFTMARGIN")) 				   
sl@0
   700
				TransParaArgLeftMargin();
sl@0
   701
		else if (iArgType == _L("RIGHTMARGIN"))  
sl@0
   702
				TransParaArgRightMargin();
sl@0
   703
		else if (iArgType == _L("INDENT"))		 
sl@0
   704
				TransParaArgIndent();
sl@0
   705
		else if (iArgType == _L("ALIGNMENT"))	 
sl@0
   706
				TransParaArgAlignment();
sl@0
   707
		else if (iArgType == _L("LINESPACING"))	 
sl@0
   708
				TransParaLineSpacing();
sl@0
   709
		else if (iArgType == _L("LINESPACINGCONTROL"))  
sl@0
   710
				TransParaArgLineSpacingControl();
sl@0
   711
		else if (iArgType == _L("SPACEBEFORE"))	 
sl@0
   712
				TransParaSpaceBefore();
sl@0
   713
		else if (iArgType == _L("SPACEAFTER"))	 
sl@0
   714
				TransParaSpaceAfter();
sl@0
   715
		else if (iArgType == _L("BORDERMARGIN"))	
sl@0
   716
				TransParaBorderMargin();
sl@0
   717
		else if (iArgType == _L("TOPBORDER"))	 
sl@0
   718
				TransParaBorderL();
sl@0
   719
		else if (iArgType == _L("BOTTOMBORDER"))
sl@0
   720
				TransParaBorderL();
sl@0
   721
		else if (iArgType == _L("LEFT BORDER"))	 
sl@0
   722
				TransParaBorderL();
sl@0
   723
		else if (iArgType == _L("RIGHTBORDER"))	 
sl@0
   724
				TransParaBorderL();
sl@0
   725
		else if (iArgType == _L("BULLET"))		 
sl@0
   726
				TransParaBullet();
sl@0
   727
		else if (iArgType == _L("DEFAULTTABWIDTH")) 
sl@0
   728
				TransParaTabWidth();
sl@0
   729
		else if (iArgType == _L("TABSTOP"))
sl@0
   730
				TransParaTabStopL();
sl@0
   731
		else 
sl@0
   732
				iErrorLevel = EUnknownAttrib;
sl@0
   733
		}
sl@0
   734
	}
sl@0
   735
sl@0
   736
sl@0
   737
void CParser::TransParaDefault()
sl@0
   738
// turns off all applied para formatting - reverts to global
sl@0
   739
	{
sl@0
   740
	iParaFormatMask.ClearAll();
sl@0
   741
	OutputToScreen(_L("<PARA-DEFAULT>"));
sl@0
   742
	}
sl@0
   743
sl@0
   744
sl@0
   745
void CParser::TransParaArgLeftMargin()
sl@0
   746
	{
sl@0
   747
	TInt32 margin = GetArgValue();
sl@0
   748
	switch (iTagType)
sl@0
   749
		{
sl@0
   750
		case EParagraph:		 
sl@0
   751
			iParaFormat->iLeftMarginInTwips = margin;
sl@0
   752
			iParaFormatMask.SetAttrib(EAttLeftMargin);
sl@0
   753
			break;
sl@0
   754
		case EGlobal:
sl@0
   755
			iGlobalParaFormat->iLeftMarginInTwips = margin;
sl@0
   756
			iGlobalParaFormatMask.SetAttrib(EAttLeftMargin);
sl@0
   757
			break;
sl@0
   758
		}
sl@0
   759
	// screen output
sl@0
   760
	TBuf<80> outputBuf;
sl@0
   761
	outputBuf.Format(_L("<LEFT MARGIN = %d>"),margin);
sl@0
   762
	OutputToScreen(outputBuf);
sl@0
   763
	}
sl@0
   764
sl@0
   765
void CParser::TransParaArgRightMargin()
sl@0
   766
	{
sl@0
   767
	TInt32 margin = GetArgValue();		
sl@0
   768
	switch (iTagType)
sl@0
   769
		{
sl@0
   770
		case EParagraph:		 
sl@0
   771
			iParaFormat->iRightMarginInTwips = margin;
sl@0
   772
			iParaFormatMask.SetAttrib(EAttRightMargin);
sl@0
   773
			break;
sl@0
   774
		case EGlobal:
sl@0
   775
			iGlobalParaFormat->iRightMarginInTwips = margin;
sl@0
   776
			iGlobalParaFormatMask.SetAttrib(EAttRightMargin);
sl@0
   777
			break;
sl@0
   778
		}
sl@0
   779
	// screen output
sl@0
   780
	TBuf<80> outputBuf;
sl@0
   781
	outputBuf.Format(_L("<RIGHT MARGIN = %d>"),margin);
sl@0
   782
	OutputToScreen(outputBuf);
sl@0
   783
	}
sl@0
   784
sl@0
   785
void CParser::TransParaArgIndent()
sl@0
   786
	{
sl@0
   787
	TInt32 indent = GetArgValue();
sl@0
   788
	switch (iTagType)
sl@0
   789
		{
sl@0
   790
		case EParagraph:		 
sl@0
   791
			iParaFormat->iIndentInTwips = indent;
sl@0
   792
			iParaFormatMask.SetAttrib(EAttIndent);
sl@0
   793
			break;
sl@0
   794
		case EGlobal:
sl@0
   795
			iGlobalParaFormat->iIndentInTwips = indent;
sl@0
   796
			iGlobalParaFormatMask.SetAttrib(EAttIndent);
sl@0
   797
			break;
sl@0
   798
		}
sl@0
   799
	// screen output
sl@0
   800
	TBuf<80> outputBuf;
sl@0
   801
	outputBuf.Format(_L("<INDENT = %d>"),indent);
sl@0
   802
	OutputToScreen(outputBuf);
sl@0
   803
	}
sl@0
   804
sl@0
   805
void CParser::TransParaLineSpacing()
sl@0
   806
	{
sl@0
   807
	TInt32 lineSpacing = GetArgValue();		  
sl@0
   808
	switch (iTagType)
sl@0
   809
		{
sl@0
   810
		case EParagraph:		 
sl@0
   811
			iParaFormat->iLineSpacingInTwips = lineSpacing;
sl@0
   812
			iParaFormatMask.SetAttrib(EAttLineSpacing);
sl@0
   813
			break;
sl@0
   814
		case EGlobal:
sl@0
   815
			iGlobalParaFormat->iLineSpacingInTwips = lineSpacing;
sl@0
   816
			iGlobalParaFormatMask.SetAttrib(EAttLineSpacing);
sl@0
   817
			break;
sl@0
   818
		}
sl@0
   819
	// screen output
sl@0
   820
	TBuf<80> outputBuf;
sl@0
   821
	outputBuf.Format(_L("<LINESPACING = %d>"),lineSpacing);
sl@0
   822
	OutputToScreen(outputBuf);
sl@0
   823
	}
sl@0
   824
sl@0
   825
void CParser::TransParaArgLineSpacingControl()
sl@0
   826
	{
sl@0
   827
	if (iArgValue == _L("ATLEAST"))
sl@0
   828
		{
sl@0
   829
		switch (iTagType)
sl@0
   830
			{
sl@0
   831
			case EParagraph:		 
sl@0
   832
				iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips;
sl@0
   833
				iParaFormatMask.SetAttrib(EAttLineSpacingControl);
sl@0
   834
				break;
sl@0
   835
			case EGlobal:
sl@0
   836
				iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips;
sl@0
   837
				iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl);
sl@0
   838
				break;
sl@0
   839
			}
sl@0
   840
		OutputToScreen(_L("<Line spacing control Atleast>"));
sl@0
   841
		}
sl@0
   842
	else if (iArgValue == _L("EXACTLY"))
sl@0
   843
		{
sl@0
   844
		switch (iTagType)
sl@0
   845
			{
sl@0
   846
			case EParagraph:		 
sl@0
   847
				iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
sl@0
   848
				iParaFormatMask.SetAttrib(EAttLineSpacingControl);
sl@0
   849
				break;
sl@0
   850
			case EGlobal:
sl@0
   851
				iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
sl@0
   852
				iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl);
sl@0
   853
				break;
sl@0
   854
			}
sl@0
   855
		OutputToScreen(_L("<Line spacing control Exactly>"));
sl@0
   856
		}
sl@0
   857
	else
sl@0
   858
		iErrorLevel = EIllegalAttribValue;
sl@0
   859
	}
sl@0
   860
sl@0
   861
void CParser::TransParaSpaceBefore()
sl@0
   862
	{
sl@0
   863
	TInt32 spaceBefore = GetArgValue();		  
sl@0
   864
	switch (iTagType)
sl@0
   865
		{
sl@0
   866
		case EParagraph:		 
sl@0
   867
			iParaFormat->iSpaceBeforeInTwips = spaceBefore;
sl@0
   868
			iParaFormatMask.SetAttrib(EAttSpaceBefore);
sl@0
   869
			break;
sl@0
   870
		case EGlobal:
sl@0
   871
			iGlobalParaFormat->iSpaceBeforeInTwips = spaceBefore;
sl@0
   872
			iGlobalParaFormatMask.SetAttrib(EAttSpaceBefore);
sl@0
   873
			break;
sl@0
   874
		}
sl@0
   875
	// screen output
sl@0
   876
	TBuf<80> outputBuf;
sl@0
   877
	outputBuf.Format(_L("<SPACE BEFORE = %d>"),spaceBefore);
sl@0
   878
	OutputToScreen(outputBuf);
sl@0
   879
	}
sl@0
   880
sl@0
   881
void CParser::TransParaSpaceAfter()
sl@0
   882
	{
sl@0
   883
	TInt32 spaceAfter = GetArgValue();		  
sl@0
   884
	switch (iTagType)
sl@0
   885
		{
sl@0
   886
		case EParagraph:		 
sl@0
   887
			iParaFormat->iSpaceAfterInTwips = spaceAfter;
sl@0
   888
			iParaFormatMask.SetAttrib(EAttSpaceAfter);
sl@0
   889
			break;
sl@0
   890
		case EGlobal:
sl@0
   891
			iGlobalParaFormat->iSpaceAfterInTwips = spaceAfter;
sl@0
   892
			iGlobalParaFormatMask.SetAttrib(EAttSpaceAfter);
sl@0
   893
			break;
sl@0
   894
		}
sl@0
   895
	// screen output
sl@0
   896
	TBuf<80> outputBuf;
sl@0
   897
	outputBuf.Format(_L("<SPACE AFTER = %d>"),spaceAfter);
sl@0
   898
	OutputToScreen(outputBuf);
sl@0
   899
	}
sl@0
   900
sl@0
   901
void CParser::TransParaBorderMargin()
sl@0
   902
	{
sl@0
   903
	TInt32 borderMargin = GetArgValue();		  
sl@0
   904
	switch (iTagType)
sl@0
   905
		{
sl@0
   906
		case EParagraph:		 
sl@0
   907
			iParaFormat->iBorderMarginInTwips = borderMargin;
sl@0
   908
			iParaFormatMask.SetAttrib(EAttBorderMargin);
sl@0
   909
			break;
sl@0
   910
		case EGlobal:
sl@0
   911
			iGlobalParaFormat->iBorderMarginInTwips = borderMargin;
sl@0
   912
			iGlobalParaFormatMask.SetAttrib(EAttBorderMargin);
sl@0
   913
			break;
sl@0
   914
		}
sl@0
   915
	// screen output
sl@0
   916
	TBuf<80> outputBuf;
sl@0
   917
	outputBuf.Format(_L("<BORDER MARGIN = %d>"),borderMargin);
sl@0
   918
	OutputToScreen(outputBuf);
sl@0
   919
	}
sl@0
   920
sl@0
   921
void CParser::TransParaKeepTogether()
sl@0
   922
	{
sl@0
   923
	switch (iTagType)
sl@0
   924
		{
sl@0
   925
		case EParagraph:		 
sl@0
   926
			if (iCancelArg)
sl@0
   927
				iParaFormat->iKeepTogether = EFalse;
sl@0
   928
			else
sl@0
   929
				iParaFormat->iKeepTogether = ETrue;
sl@0
   930
			iParaFormatMask.SetAttrib(EAttKeepTogether);
sl@0
   931
			break;
sl@0
   932
		case EGlobal:
sl@0
   933
			if (iCancelArg)
sl@0
   934
				iGlobalParaFormat->iKeepTogether = EFalse;
sl@0
   935
			else
sl@0
   936
				iGlobalParaFormat->iKeepTogether = ETrue;
sl@0
   937
			iGlobalParaFormatMask.SetAttrib(EAttKeepTogether);
sl@0
   938
			break;
sl@0
   939
		}
sl@0
   940
	// screen output
sl@0
   941
	OutputToScreen(_L("<KEEP TOGETHER>"));
sl@0
   942
	}
sl@0
   943
sl@0
   944
void CParser::TransParaKeepWithNext()
sl@0
   945
	{
sl@0
   946
	switch (iTagType)
sl@0
   947
		{
sl@0
   948
		case EParagraph:		 
sl@0
   949
			if (iCancelArg)
sl@0
   950
				iParaFormat->iKeepWithNext = EFalse;
sl@0
   951
			else
sl@0
   952
				iParaFormat->iKeepWithNext = ETrue;
sl@0
   953
			iParaFormatMask.SetAttrib(EAttKeepWithNext);
sl@0
   954
			break;
sl@0
   955
		case EGlobal:
sl@0
   956
			if (iCancelArg)
sl@0
   957
				iGlobalParaFormat->iKeepWithNext = EFalse;
sl@0
   958
			else
sl@0
   959
				iGlobalParaFormat->iKeepWithNext = ETrue;
sl@0
   960
			iGlobalParaFormatMask.SetAttrib(EAttKeepWithNext);
sl@0
   961
			break;
sl@0
   962
		}
sl@0
   963
	// screen output
sl@0
   964
	OutputToScreen(_L("<KEEP WITH NEXT>"));
sl@0
   965
	}
sl@0
   966
sl@0
   967
void CParser::TransParaStartNewPage()
sl@0
   968
	{
sl@0
   969
	switch (iTagType)
sl@0
   970
		{
sl@0
   971
		case EParagraph:		 
sl@0
   972
			if (iCancelArg)
sl@0
   973
				iParaFormat->iStartNewPage = EFalse;
sl@0
   974
			else
sl@0
   975
				iParaFormat->iStartNewPage = ETrue;
sl@0
   976
			iParaFormatMask.SetAttrib(EAttStartNewPage);
sl@0
   977
			break;
sl@0
   978
		case EGlobal:
sl@0
   979
			if (iCancelArg)
sl@0
   980
				iGlobalParaFormat->iStartNewPage = EFalse;
sl@0
   981
			else
sl@0
   982
				iGlobalParaFormat->iStartNewPage = ETrue;
sl@0
   983
			iGlobalParaFormatMask.SetAttrib(EAttStartNewPage);
sl@0
   984
			break;
sl@0
   985
		}
sl@0
   986
	// screen output
sl@0
   987
	OutputToScreen(_L("<START NEW PAGE>"));
sl@0
   988
	}
sl@0
   989
sl@0
   990
void CParser::TransParaWidowOrphan()
sl@0
   991
	{
sl@0
   992
	switch (iTagType)
sl@0
   993
		{
sl@0
   994
		case EParagraph:		 
sl@0
   995
			if (iCancelArg)
sl@0
   996
				iParaFormat->iWidowOrphan = EFalse;
sl@0
   997
			else
sl@0
   998
				iParaFormat->iWidowOrphan = ETrue;
sl@0
   999
			iParaFormatMask.SetAttrib(EAttWidowOrphan);
sl@0
  1000
			break;
sl@0
  1001
		case EGlobal:
sl@0
  1002
			if (iCancelArg)
sl@0
  1003
				iGlobalParaFormat->iWidowOrphan = EFalse;
sl@0
  1004
			else
sl@0
  1005
				iGlobalParaFormat->iWidowOrphan = ETrue;
sl@0
  1006
			iGlobalParaFormatMask.SetAttrib(EAttWidowOrphan);
sl@0
  1007
			break;
sl@0
  1008
		}
sl@0
  1009
	// screen output
sl@0
  1010
	OutputToScreen(_L("<WIDOWS & ORPHANS>"));
sl@0
  1011
	}
sl@0
  1012
sl@0
  1013
void CParser::TransParaArgAlignment()
sl@0
  1014
	{
sl@0
  1015
	// parse argValue
sl@0
  1016
	if (iArgValue == _L("LEFT"))
sl@0
  1017
		{
sl@0
  1018
		switch (iTagType)
sl@0
  1019
			{
sl@0
  1020
			case EParagraph:		 
sl@0
  1021
				iParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
sl@0
  1022
				iParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1023
				break;
sl@0
  1024
			case EGlobal:
sl@0
  1025
				iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
sl@0
  1026
				iGlobalParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1027
				break;
sl@0
  1028
			}
sl@0
  1029
		OutputToScreen(_L("<ALIGNMENT LEFT>"));
sl@0
  1030
		}
sl@0
  1031
	else if (iArgValue == _L("RIGHT"))
sl@0
  1032
		{
sl@0
  1033
		switch (iTagType)
sl@0
  1034
			{
sl@0
  1035
			case EParagraph:		 
sl@0
  1036
				iParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
sl@0
  1037
				iParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1038
				break;
sl@0
  1039
			case EGlobal:
sl@0
  1040
				iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
sl@0
  1041
				iGlobalParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1042
				break;
sl@0
  1043
			}
sl@0
  1044
		OutputToScreen(_L("<ALIGNMENT RIGHT>"));
sl@0
  1045
		}
sl@0
  1046
	else if (iArgValue == _L("CENTER"))
sl@0
  1047
		{
sl@0
  1048
		switch (iTagType)
sl@0
  1049
			{
sl@0
  1050
			case EParagraph:		 
sl@0
  1051
				iParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
sl@0
  1052
				iParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1053
				break;
sl@0
  1054
			case EGlobal:
sl@0
  1055
				iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
sl@0
  1056
				iGlobalParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1057
				break;
sl@0
  1058
			}
sl@0
  1059
		OutputToScreen(_L("<ALIGNMENT CENTER>"));
sl@0
  1060
		}
sl@0
  1061
	else if (iArgValue == _L("JUSTIFIED"))
sl@0
  1062
		{
sl@0
  1063
		switch (iTagType)
sl@0
  1064
			{
sl@0
  1065
			case EParagraph:		 
sl@0
  1066
				iParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign;
sl@0
  1067
				iParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1068
				break;
sl@0
  1069
			case EGlobal:
sl@0
  1070
				iGlobalParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign;
sl@0
  1071
				iGlobalParaFormatMask.SetAttrib(EAttAlignment);
sl@0
  1072
				break;
sl@0
  1073
			}
sl@0
  1074
		OutputToScreen(_L("<ALIGNMENT JUSTIFIED>"));
sl@0
  1075
		}
sl@0
  1076
	else
sl@0
  1077
		iErrorLevel = EIllegalAttribValue;
sl@0
  1078
	}
sl@0
  1079
sl@0
  1080
sl@0
  1081
void CParser::TransParaBullet()
sl@0
  1082
	{
sl@0
  1083
	TInt characterCode = 0x2022;
sl@0
  1084
	TUint32 heightInTwips=0;
sl@0
  1085
	TUint32 flags=0;
sl@0
  1086
	TBuf<KMaxTypefaceNameLength> name;
sl@0
  1087
	TBuf<128> component;
sl@0
  1088
sl@0
  1089
	// set first component (character code)
sl@0
  1090
	TInt commaPos = iArgValue.Locate(KComma);	 // find pos of first comma
sl@0
  1091
	component = iArgValue.Left(commaPos);
sl@0
  1092
	if (component != _L(""))					// only third arg remains
sl@0
  1093
		{
sl@0
  1094
		if (BufIsNumeric(component))
sl@0
  1095
			{
sl@0
  1096
			TLex tmpLex(component);
sl@0
  1097
			// TUint value;
sl@0
  1098
			tmpLex.Val(characterCode);
sl@0
  1099
			}
sl@0
  1100
		else 
sl@0
  1101
			iErrorLevel = EIllegalAttribValue;
sl@0
  1102
		}
sl@0
  1103
	else
sl@0
  1104
		iErrorLevel = EIllegalAttribValue;
sl@0
  1105
sl@0
  1106
	// set second component (bullet height)
sl@0
  1107
	iArgValue.Delete(0,commaPos+1);				// delete previous component & trailing comma 
sl@0
  1108
	commaPos = iArgValue.Locate(KComma);	// find pos of first comma
sl@0
  1109
	component = iArgValue.Left(commaPos);
sl@0
  1110
	if (component != _L(""))					// only third arg remains
sl@0
  1111
		{
sl@0
  1112
		if (BufIsNumeric(component))
sl@0
  1113
			{
sl@0
  1114
			TLex tmpLex(component);
sl@0
  1115
			TUint value;
sl@0
  1116
			tmpLex.Val(value);
sl@0
  1117
			heightInTwips = value;
sl@0
  1118
			}
sl@0
  1119
		else 
sl@0
  1120
			iErrorLevel = EIllegalAttribValue;
sl@0
  1121
		}
sl@0
  1122
	else
sl@0
  1123
		iErrorLevel = EIllegalAttribValue;
sl@0
  1124
sl@0
  1125
	// set third component (typeface flags)
sl@0
  1126
	iArgValue.Delete(0,commaPos+1);				// delete previous component & trailing comma 
sl@0
  1127
	commaPos = iArgValue.Locate(KComma);		// find pos of first comma
sl@0
  1128
	component = iArgValue.Left(commaPos);
sl@0
  1129
	if (component != _L(""))					// only third arg remains
sl@0
  1130
		{
sl@0
  1131
		flags = GetArgValue(component);
sl@0
  1132
		if (flags>2)
sl@0
  1133
			iErrorLevel=EIllegalAttribValue;	// only values 0,1,2 valid for flag
sl@0
  1134
		}
sl@0
  1135
	else
sl@0
  1136
		iErrorLevel = EIllegalAttribValue;
sl@0
  1137
sl@0
  1138
	// set fourth component (typeface name)
sl@0
  1139
	iArgValue.Delete(0,commaPos+1);				// delete previous component & trailing comma 
sl@0
  1140
	if (iArgValue != _L(""))					// only third arg remains
sl@0
  1141
		{
sl@0
  1142
		name.Copy(iArgValue);		
sl@0
  1143
//		name = SquashBuf(iArgValue);
sl@0
  1144
		}
sl@0
  1145
	else
sl@0
  1146
		iErrorLevel = EIllegalAttribValue;
sl@0
  1147
sl@0
  1148
	// apply
sl@0
  1149
	if (iErrorLevel == ENoError)
sl@0
  1150
		{
sl@0
  1151
		iBulletUsed = ETrue;
sl@0
  1152
		iBullet->iCharacterCode = (TText)characterCode;
sl@0
  1153
		iBullet->iHeightInTwips = heightInTwips;
sl@0
  1154
		if (flags>=1)
sl@0
  1155
			iBullet->iTypeface.SetIsProportional(ETrue);
sl@0
  1156
		if (flags>=3)
sl@0
  1157
			iBullet->iTypeface.SetIsSerif(ETrue);
sl@0
  1158
		iBullet->iTypeface.iName = name;
sl@0
  1159
		switch (iTagType)
sl@0
  1160
			{
sl@0
  1161
			case EParagraph:
sl@0
  1162
				iParaFormat->iBullet = iBullet;  
sl@0
  1163
				iParaFormatMask.SetAttrib(EAttBullet);
sl@0
  1164
				break;
sl@0
  1165
			case EGlobal:
sl@0
  1166
				iGlobalParaFormat->iBullet = iBullet;
sl@0
  1167
				iGlobalParaFormatMask.SetAttrib(EAttBullet);
sl@0
  1168
				break;
sl@0
  1169
			}
sl@0
  1170
		OutputToScreen(_L("<BULLET>"));
sl@0
  1171
		}
sl@0
  1172
	}
sl@0
  1173
sl@0
  1174
TBuf8<512> CParser::SquashBuf(TDes aBuffer)
sl@0
  1175
	//
sl@0
  1176
	// Input 8/16 bit buffer to be returned as an 8-bit version
sl@0
  1177
	// Used for unicode compatability
sl@0
  1178
	//
sl@0
  1179
	{
sl@0
  1180
	TText16 textPointer;
sl@0
  1181
sl@0
  1182
	TBuf8<512> returnBuf;
sl@0
  1183
sl@0
  1184
	for ( TInt pos=0 ; pos<aBuffer.Length() ; pos++ )
sl@0
  1185
		{
sl@0
  1186
		textPointer = aBuffer[pos];
sl@0
  1187
#pragma warning ( disable : 4244 )
sl@0
  1188
		returnBuf[pos] = textPointer; // conversion from unsigned short to unsigned char (16 bit to 8 bit) in unicode
sl@0
  1189
#pragma warning ( default : 4244 )
sl@0
  1190
		}
sl@0
  1191
	return returnBuf;
sl@0
  1192
	}
sl@0
  1193
sl@0
  1194
sl@0
  1195
sl@0
  1196
void CParser::TransParaBorderL()
sl@0
  1197
	{
sl@0
  1198
	TParaBorder::TLineStyle lineStyle=TParaBorder::ENullLineStyle;
sl@0
  1199
	TBool autoColor=EFalse;
sl@0
  1200
	TRgb color;
sl@0
  1201
	TBuf<128> component;
sl@0
  1202
sl@0
  1203
	// set first component
sl@0
  1204
	TInt commaPos = iArgValue.Locate(KComma);	 // find pos of first comma
sl@0
  1205
	component = iArgValue.Left(commaPos);
sl@0
  1206
	if (component != _L(""))
sl@0
  1207
		{
sl@0
  1208
		if (component == _L("NULL"))
sl@0
  1209
			lineStyle = TParaBorder::ENullLineStyle;
sl@0
  1210
		else if (component == _L("SOLID"))
sl@0
  1211
			lineStyle = TParaBorder::ESolid;
sl@0
  1212
		else if (component == _L("DOUBLE"))
sl@0
  1213
			lineStyle = TParaBorder::EDouble;
sl@0
  1214
		else if (component == _L("DOTTED"))
sl@0
  1215
			lineStyle = TParaBorder::EDotted;
sl@0
  1216
		else if (component == _L("DASHED"))
sl@0
  1217
			lineStyle = TParaBorder::EDashed;
sl@0
  1218
		else if (component == _L("DOTDASH"))
sl@0
  1219
			lineStyle = TParaBorder::EDotDash;
sl@0
  1220
		else if (component == _L("DOTDOTDASH"))
sl@0
  1221
			lineStyle = TParaBorder::EDotDotDash;
sl@0
  1222
		else
sl@0
  1223
			iErrorLevel = EIllegalAttribValue; 
sl@0
  1224
		}
sl@0
  1225
	else
sl@0
  1226
		iErrorLevel = EIllegalAttribValue;
sl@0
  1227
	
sl@0
  1228
	// set second component
sl@0
  1229
	iArgValue.Delete(0,commaPos+1);				// delete first component & trailing comma 
sl@0
  1230
	commaPos = iArgValue.Locate(KComma);	 	// find pos of first comma
sl@0
  1231
	component = iArgValue.Left(commaPos);
sl@0
  1232
	if (component != _L(""))
sl@0
  1233
		{
sl@0
  1234
		if (component == _L("ON"))
sl@0
  1235
			autoColor = ETrue;
sl@0
  1236
		else if (component == _L("OFF"))
sl@0
  1237
			autoColor = EFalse;
sl@0
  1238
		else
sl@0
  1239
			iErrorLevel = EIllegalAttribValue; 
sl@0
  1240
		}
sl@0
  1241
	else
sl@0
  1242
		iErrorLevel = EIllegalAttribValue;
sl@0
  1243
sl@0
  1244
	// set third component
sl@0
  1245
	iArgValue.Delete(0,commaPos+1);				// delete second component & trailing comma 
sl@0
  1246
	if (component != _L(""))					// only third arg remains
sl@0
  1247
		{
sl@0
  1248
		if (BufIsNumeric(iArgValue))
sl@0
  1249
			{
sl@0
  1250
			TLex tmpLex(iArgValue);
sl@0
  1251
			TUint value;
sl@0
  1252
			tmpLex.Val(value);
sl@0
  1253
			color=TRgb((TUint32)value);
sl@0
  1254
			}
sl@0
  1255
		else 
sl@0
  1256
			iErrorLevel = EIllegalAttribValue;
sl@0
  1257
		}
sl@0
  1258
sl@0
  1259
	// apply
sl@0
  1260
	if (iErrorLevel == ENoError)
sl@0
  1261
		{
sl@0
  1262
		iBorderUsed = ETrue;
sl@0
  1263
		iBorder->iLineStyle = lineStyle;
sl@0
  1264
		iBorder->iAutoColor = autoColor;
sl@0
  1265
		iBorder->iColor = color;
sl@0
  1266
		if (iArgType == _L("TOPBORDER"))
sl@0
  1267
			{
sl@0
  1268
			switch (iTagType)
sl@0
  1269
				{
sl@0
  1270
				case EParagraph:
sl@0
  1271
					iParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder);
sl@0
  1272
					iParaFormatMask.SetAttrib(EAttTopBorder);
sl@0
  1273
					break;
sl@0
  1274
				case EGlobal:
sl@0
  1275
					iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder);
sl@0
  1276
					iGlobalParaFormatMask.SetAttrib(EAttTopBorder);
sl@0
  1277
					break;
sl@0
  1278
				}
sl@0
  1279
			}
sl@0
  1280
		if (iArgType == _L("BOTTOMBORDER"))
sl@0
  1281
			{
sl@0
  1282
			switch (iTagType)
sl@0
  1283
				{
sl@0
  1284
				case EParagraph:
sl@0
  1285
					iParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder);
sl@0
  1286
					iParaFormatMask.SetAttrib(EAttBottomBorder);
sl@0
  1287
					break;
sl@0
  1288
				case EGlobal:
sl@0
  1289
					iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder);
sl@0
  1290
					iGlobalParaFormatMask.SetAttrib(EAttBottomBorder);
sl@0
  1291
					break;
sl@0
  1292
				}
sl@0
  1293
			}
sl@0
  1294
		if (iArgType == _L("LEFTBORDER"))
sl@0
  1295
			{
sl@0
  1296
			switch (iTagType)
sl@0
  1297
				{
sl@0
  1298
				case EParagraph:
sl@0
  1299
					iParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder);
sl@0
  1300
					iParaFormatMask.SetAttrib(EAttLeftBorder);
sl@0
  1301
					break;
sl@0
  1302
				case EGlobal:
sl@0
  1303
					iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder);
sl@0
  1304
					iGlobalParaFormatMask.SetAttrib(EAttLeftBorder);
sl@0
  1305
					break;
sl@0
  1306
				}
sl@0
  1307
			}
sl@0
  1308
		if (iArgType == _L("RIGHTBORDER"))
sl@0
  1309
			{
sl@0
  1310
			switch (iTagType)
sl@0
  1311
				{
sl@0
  1312
				case EParagraph:
sl@0
  1313
					iParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder);
sl@0
  1314
					iParaFormatMask.SetAttrib(EAttRightBorder);
sl@0
  1315
					break;
sl@0
  1316
				case EGlobal:
sl@0
  1317
					iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder);
sl@0
  1318
					iGlobalParaFormatMask.SetAttrib(EAttRightBorder);
sl@0
  1319
					break;
sl@0
  1320
				}
sl@0
  1321
			}
sl@0
  1322
		OutputToScreen(_L("<PARA BORDER>"));
sl@0
  1323
		}
sl@0
  1324
	}
sl@0
  1325
sl@0
  1326
void CParser::TransParaTabWidth()
sl@0
  1327
	{
sl@0
  1328
	TInt32 tabWidth = GetArgValue();
sl@0
  1329
	switch (iTagType)
sl@0
  1330
		{
sl@0
  1331
		case EParagraph:		 
sl@0
  1332
			iParaFormat->iDefaultTabWidthInTwips = tabWidth;
sl@0
  1333
			iParaFormatMask.SetAttrib(EAttDefaultTabWidth);
sl@0
  1334
			break;
sl@0
  1335
		case EGlobal:
sl@0
  1336
			iGlobalParaFormat->iDefaultTabWidthInTwips = tabWidth;
sl@0
  1337
			iGlobalParaFormatMask.SetAttrib(EAttDefaultTabWidth);
sl@0
  1338
			break;
sl@0
  1339
		}
sl@0
  1340
	// screen output
sl@0
  1341
	TBuf<80> outputBuf;
sl@0
  1342
	outputBuf.Format(_L("<DEFAULT TAB WIDTH = %d>"),tabWidth);
sl@0
  1343
	OutputToScreen(outputBuf);
sl@0
  1344
	}
sl@0
  1345
sl@0
  1346
sl@0
  1347
void CParser::TransParaTabStopL()
sl@0
  1348
// This arg has a compound value of the form Tabstop=value,type
sl@0
  1349
// It also accepts !Tabstop=value to delete an existing tabstop
sl@0
  1350
	{
sl@0
  1351
	TTabStop tabStop;
sl@0
  1352
	TBuf<128> component;
sl@0
  1353
	TBuf<6> outputBuf;
sl@0
  1354
sl@0
  1355
	// get first component (tab type)
sl@0
  1356
	TInt commaPos = iArgValue.Locate(KComma);	 // find pos of first comma (returns -1 if no comma)
sl@0
  1357
	if (commaPos > 0)	// comma & first component exist
sl@0
  1358
		{
sl@0
  1359
		component = iArgValue.Left(commaPos);	// take part to the left of the comma
sl@0
  1360
		if (component != _L(""))				
sl@0
  1361
			tabStop.iTwipsPosition = GetArgValue(component);
sl@0
  1362
		else
sl@0
  1363
			iErrorLevel = EIllegalAttribValue;
sl@0
  1364
		}
sl@0
  1365
	else if ((iCancelArg)&&(commaPos == -1))	// no comma but only one component required (position)
sl@0
  1366
		{
sl@0
  1367
		if (iArgValue != _L(""))				
sl@0
  1368
			tabStop.iTwipsPosition = GetArgValue(iArgValue);
sl@0
  1369
		else
sl@0
  1370
			iErrorLevel = EIllegalAttribValue;
sl@0
  1371
		}
sl@0
  1372
sl@0
  1373
	if (iErrorLevel == ENoError)
sl@0
  1374
		{
sl@0
  1375
		if (iCancelArg)
sl@0
  1376
			// insert a null tab
sl@0
  1377
			{
sl@0
  1378
			if ((iParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound)
sl@0
  1379
				||(iGlobalParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound))
sl@0
  1380
					{
sl@0
  1381
					tabStop.iType = TTabStop::ENullTab;	// null tab "deletes" existing tab
sl@0
  1382
					outputBuf = _L("<!TAB>");
sl@0
  1383
					}
sl@0
  1384
			else
sl@0
  1385
				iErrorLevel = EIllegalAttribValue;
sl@0
  1386
			}
sl@0
  1387
		else
sl@0
  1388
			{
sl@0
  1389
			// set second component (tab position in twips)
sl@0
  1390
			iArgValue.Delete(0,commaPos+1);				// delete previous component & trailing comma 
sl@0
  1391
			if (iArgValue != _L(""))				
sl@0
  1392
				{
sl@0
  1393
				outputBuf = _L("<TAB>");
sl@0
  1394
				if (iArgValue == _L("NULL"))
sl@0
  1395
					tabStop.iType = TTabStop::ENullTab;
sl@0
  1396
				else if (iArgValue == _L("LEFT"))
sl@0
  1397
					tabStop.iType = TTabStop::ELeftTab;
sl@0
  1398
				else if (iArgValue == _L("CENTERED"))
sl@0
  1399
					tabStop.iType = TTabStop::ECenteredTab;
sl@0
  1400
				else if (iArgValue == _L("RIGHT"))
sl@0
  1401
					tabStop.iType = TTabStop::ERightTab;
sl@0
  1402
				else 
sl@0
  1403
					iErrorLevel = EIllegalAttribValue;
sl@0
  1404
				}
sl@0
  1405
			else
sl@0
  1406
				iErrorLevel = EIllegalAttribValue;
sl@0
  1407
			}
sl@0
  1408
		}
sl@0
  1409
sl@0
  1410
 	// Insert the tab
sl@0
  1411
	if (iErrorLevel == ENoError)
sl@0
  1412
		{
sl@0
  1413
		switch (iTagType)
sl@0
  1414
			{
sl@0
  1415
			case EParagraph:
sl@0
  1416
				iParaFormat->StoreTabL(tabStop);
sl@0
  1417
				iParaFormatMask.SetAttrib(EAttTabStop);
sl@0
  1418
				break;
sl@0
  1419
			case EGlobal:
sl@0
  1420
				iGlobalParaFormat->StoreTabL(tabStop);
sl@0
  1421
				iGlobalParaFormatMask.SetAttrib(EAttTabStop);
sl@0
  1422
				break;
sl@0
  1423
			}
sl@0
  1424
		// output to screen
sl@0
  1425
		OutputToScreen(outputBuf);
sl@0
  1426
		}
sl@0
  1427
	}
sl@0
  1428
sl@0
  1429
 
sl@0
  1430
void CParser::TransCharArg()
sl@0
  1431
	{
sl@0
  1432
	if (iArgType != _L("")) 				// Is there an argument?
sl@0
  1433
		{
sl@0
  1434
		if (iArgType == _L("DEFAULT"))
sl@0
  1435
				TransCharDefault();
sl@0
  1436
		else if (iArgType == _L("ITALIC"))	
sl@0
  1437
				TransCharPosture();
sl@0
  1438
		else if (iArgType == _L("BOLD"))	
sl@0
  1439
				TransCharStrokeWeight();
sl@0
  1440
		else if (iArgType == _L("UNDERLINE"))	
sl@0
  1441
				TransCharUnderline();
sl@0
  1442
		else if (iArgType == _L("STRIKETHROUGH"))
sl@0
  1443
				TransCharStrikethrough();
sl@0
  1444
		else if (!iArgValueExpected)			// No argument value supplied when one is required for the
sl@0
  1445
				iErrorLevel = ENoAttribValue;	// remaining options or an unknown argument supplied
sl@0
  1446
		else if (iArgType == _L("FONTHEIGHT"))	
sl@0
  1447
				TransCharFontHeight();
sl@0
  1448
		else if (iArgType == _L("PRINTPOS"))	
sl@0
  1449
				TransCharPrintPos();
sl@0
  1450
		else if (iArgType == _L("TYPEFACENAME"))
sl@0
  1451
				TransCharTypefaceName();
sl@0
  1452
		else if (iArgType == _L("TYPEFACEFLAGS"))	
sl@0
  1453
				TransCharTypefaceFlags();
sl@0
  1454
		else if (iArgType == _L("COLOR"))	 	 
sl@0
  1455
				TransCharColor();
sl@0
  1456
		else if (iArgType == _L("LANGUAGE"))	
sl@0
  1457
				TransCharLanguage();
sl@0
  1458
		else 
sl@0
  1459
				iErrorLevel = EUnknownAttrib;
sl@0
  1460
		}
sl@0
  1461
	}
sl@0
  1462
sl@0
  1463
sl@0
  1464
void CParser::TransCharDefault()
sl@0
  1465
// turns off all applied Char formatting - reverts to global
sl@0
  1466
	{
sl@0
  1467
	iCharFormatMask.ClearAll();
sl@0
  1468
	OutputToScreen(_L("<CHAR-DEFAULT>"));
sl@0
  1469
	}
sl@0
  1470
sl@0
  1471
sl@0
  1472
void CParser::TransCharPosture()
sl@0
  1473
	{
sl@0
  1474
	switch (iTagType)
sl@0
  1475
		{
sl@0
  1476
		case ECharacter:		 
sl@0
  1477
			if (iCancelArg)
sl@0
  1478
				iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright);
sl@0
  1479
			else
sl@0
  1480
				iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
sl@0
  1481
			iCharFormatMask.SetAttrib(EAttFontPosture);
sl@0
  1482
			break;
sl@0
  1483
		case EGlobal:
sl@0
  1484
			if (iCancelArg)
sl@0
  1485
				iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright);
sl@0
  1486
			else
sl@0
  1487
				iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
sl@0
  1488
			iGlobalCharFormatMask.SetAttrib(EAttFontPosture);
sl@0
  1489
			break;
sl@0
  1490
		}
sl@0
  1491
	// screen output
sl@0
  1492
	OutputToScreen(_L("<ITALIC>"));
sl@0
  1493
	}
sl@0
  1494
sl@0
  1495
sl@0
  1496
void CParser::TransCharStrokeWeight()
sl@0
  1497
	{
sl@0
  1498
	switch (iTagType)
sl@0
  1499
		{
sl@0
  1500
		case ECharacter:		 
sl@0
  1501
			if (iCancelArg)
sl@0
  1502
				iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
sl@0
  1503
			else
sl@0
  1504
				iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
sl@0
  1505
			iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
sl@0
  1506
			break;
sl@0
  1507
		case EGlobal:
sl@0
  1508
			if (iCancelArg)
sl@0
  1509
				iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
sl@0
  1510
			else
sl@0
  1511
				iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
sl@0
  1512
			iGlobalCharFormatMask.SetAttrib(EAttFontStrokeWeight);
sl@0
  1513
			break;
sl@0
  1514
		}
sl@0
  1515
	// screen output
sl@0
  1516
	OutputToScreen(_L("<BOLD>"));
sl@0
  1517
	}
sl@0
  1518
sl@0
  1519
sl@0
  1520
void CParser::TransCharUnderline()
sl@0
  1521
	{
sl@0
  1522
	switch (iTagType)
sl@0
  1523
		{
sl@0
  1524
		case ECharacter:		 
sl@0
  1525
			if (iCancelArg)
sl@0
  1526
				iCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
sl@0
  1527
			else
sl@0
  1528
				iCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
sl@0
  1529
			iCharFormatMask.SetAttrib(EAttFontUnderline);
sl@0
  1530
			break;
sl@0
  1531
		case EGlobal:
sl@0
  1532
			if (iCancelArg)
sl@0
  1533
				iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
sl@0
  1534
			else
sl@0
  1535
				iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
sl@0
  1536
			iGlobalCharFormatMask.SetAttrib(EAttFontUnderline);
sl@0
  1537
			break;
sl@0
  1538
		}
sl@0
  1539
	// screen output
sl@0
  1540
	OutputToScreen(_L("<UNDERLINE>"));
sl@0
  1541
	}
sl@0
  1542
sl@0
  1543
sl@0
  1544
void CParser::TransCharStrikethrough()
sl@0
  1545
	{
sl@0
  1546
	switch (iTagType)
sl@0
  1547
		{
sl@0
  1548
		case ECharacter:		 
sl@0
  1549
			if (iCancelArg)
sl@0
  1550
				iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff;
sl@0
  1551
			else
sl@0
  1552
				iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;
sl@0
  1553
			iCharFormatMask.SetAttrib(EAttFontStrikethrough);
sl@0
  1554
			break;
sl@0
  1555
		case EGlobal:
sl@0
  1556
			if (iCancelArg)
sl@0
  1557
				iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff;
sl@0
  1558
			else
sl@0
  1559
				iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;
sl@0
  1560
			iGlobalCharFormatMask.SetAttrib(EAttFontStrikethrough);
sl@0
  1561
			break;
sl@0
  1562
		}
sl@0
  1563
	// screen output
sl@0
  1564
	OutputToScreen(_L("<STRIKETHROUGH>"));
sl@0
  1565
	}
sl@0
  1566
sl@0
  1567
sl@0
  1568
void CParser::TransCharFontHeight()
sl@0
  1569
	{
sl@0
  1570
	TInt32 fontHeight = GetArgValue();		  
sl@0
  1571
	switch (iTagType)
sl@0
  1572
		{
sl@0
  1573
		case ECharacter:		 
sl@0
  1574
			iCharFormat.iFontSpec.iHeight = fontHeight;
sl@0
  1575
			iCharFormatMask.SetAttrib(EAttFontHeight);
sl@0
  1576
			break;
sl@0
  1577
		case EGlobal:
sl@0
  1578
			iGlobalCharFormat.iFontSpec.iHeight = fontHeight;
sl@0
  1579
			iGlobalCharFormatMask.SetAttrib(EAttFontHeight);
sl@0
  1580
			break;
sl@0
  1581
		}
sl@0
  1582
	// screen output
sl@0
  1583
	TBuf<80> outputBuf;
sl@0
  1584
	outputBuf.Format(_L("<FONTHEIGHT = %d>"),fontHeight);
sl@0
  1585
	OutputToScreen(outputBuf);
sl@0
  1586
	}
sl@0
  1587
sl@0
  1588
void CParser::TransCharPrintPos()
sl@0
  1589
	{
sl@0
  1590
	if (iArgValue == _L("NORMAL"))
sl@0
  1591
		{
sl@0
  1592
		switch (iTagType)
sl@0
  1593
			{
sl@0
  1594
			case ECharacter:		 
sl@0
  1595
				iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal);
sl@0
  1596
				iCharFormatMask.SetAttrib(EAttFontPrintPos);
sl@0
  1597
				break;
sl@0
  1598
			case EGlobal:
sl@0
  1599
				iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal);
sl@0
  1600
				iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
sl@0
  1601
				break;
sl@0
  1602
			}
sl@0
  1603
		OutputToScreen(_L("<PRINT POSITION NORMAL>"));
sl@0
  1604
		}
sl@0
  1605
	else if (iArgValue == _L("SUPERSCRIPT"))
sl@0
  1606
		{
sl@0
  1607
		switch (iTagType)
sl@0
  1608
			{
sl@0
  1609
			case ECharacter:		 
sl@0
  1610
				iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
sl@0
  1611
				iCharFormatMask.SetAttrib(EAttFontPrintPos);
sl@0
  1612
				break;
sl@0
  1613
			case EGlobal:
sl@0
  1614
				iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
sl@0
  1615
				iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
sl@0
  1616
				break;
sl@0
  1617
			}
sl@0
  1618
		OutputToScreen(_L("<SUPERSCRIPT>"));
sl@0
  1619
		}
sl@0
  1620
	else if (iArgValue == _L("SUBSCRIPT"))
sl@0
  1621
		{
sl@0
  1622
		switch (iTagType)
sl@0
  1623
			{
sl@0
  1624
			case ECharacter:		 
sl@0
  1625
				iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
sl@0
  1626
				iCharFormatMask.SetAttrib(EAttFontPrintPos);
sl@0
  1627
				break;
sl@0
  1628
			case EGlobal:
sl@0
  1629
				iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
sl@0
  1630
				iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
sl@0
  1631
				break;
sl@0
  1632
			}
sl@0
  1633
		OutputToScreen(_L("<SUBSCRIPT>"));
sl@0
  1634
		}
sl@0
  1635
	else
sl@0
  1636
		iErrorLevel = EIllegalAttribValue;
sl@0
  1637
	}
sl@0
  1638
sl@0
  1639
sl@0
  1640
void CParser::TransCharTypefaceFlags()
sl@0
  1641
	{
sl@0
  1642
	TUint flags = GetArgValue();
sl@0
  1643
	if (flags>2)
sl@0
  1644
		iErrorLevel=EIllegalAttribValue;	// only values 0,1,2 valid for flag
sl@0
  1645
	if (iErrorLevel==ENoError)
sl@0
  1646
		{
sl@0
  1647
		switch (iTagType)
sl@0
  1648
			{
sl@0
  1649
			case ECharacter:		 
sl@0
  1650
				if (flags>=1)
sl@0
  1651
					iCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue);
sl@0
  1652
				if (flags>=3)
sl@0
  1653
					iCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue);
sl@0
  1654
				iCharFormatMask.SetAttrib(EAttFontTypeface);
sl@0
  1655
				break;
sl@0
  1656
			case EGlobal:
sl@0
  1657
				if (flags>=1)
sl@0
  1658
					iGlobalCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue);
sl@0
  1659
				if (flags>=3)
sl@0
  1660
					iGlobalCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue);
sl@0
  1661
				iGlobalCharFormatMask.SetAttrib(EAttFontTypeface);
sl@0
  1662
				break;
sl@0
  1663
			}
sl@0
  1664
		// screen output
sl@0
  1665
		TBuf<80> outputBuf;
sl@0
  1666
		outputBuf.Format(_L("<TYPEFACE FLAGS = %d>"),flags);
sl@0
  1667
		OutputToScreen(outputBuf);
sl@0
  1668
		}
sl@0
  1669
	}
sl@0
  1670
sl@0
  1671
sl@0
  1672
void CParser::TransCharTypefaceName()
sl@0
  1673
	{
sl@0
  1674
	switch (iTagType)
sl@0
  1675
		{
sl@0
  1676
		case ECharacter:
sl@0
  1677
			iCharFormat.iFontSpec.iTypeface.iName=iArgValue;
sl@0
  1678
			iCharFormatMask.SetAttrib(EAttFontTypeface);
sl@0
  1679
			break;
sl@0
  1680
		case EGlobal:
sl@0
  1681
			iGlobalCharFormat.iFontSpec.iTypeface.iName=iArgValue;
sl@0
  1682
			iGlobalCharFormatMask.SetAttrib(EAttFontTypeface);
sl@0
  1683
			break;
sl@0
  1684
		}
sl@0
  1685
	// screen output
sl@0
  1686
	TBuf<80> outputBuf;
sl@0
  1687
	outputBuf.Format(_L("<TYPEFACE NAME = %S>"),&iArgValue);
sl@0
  1688
	OutputToScreen(outputBuf);
sl@0
  1689
	}
sl@0
  1690
sl@0
  1691
sl@0
  1692
void CParser::TransCharColor()
sl@0
  1693
	{
sl@0
  1694
	TUint value = GetArgValue();
sl@0
  1695
	if (iErrorLevel==ENoError)
sl@0
  1696
		{
sl@0
  1697
		TRgb color;
sl@0
  1698
		color=TRgb((TUint32)value);
sl@0
  1699
		switch (iTagType)
sl@0
  1700
			{
sl@0
  1701
			case ECharacter:		 
sl@0
  1702
				iCharFormat.iFontPresentation.iTextColor = color;
sl@0
  1703
				iCharFormatMask.SetAttrib(EAttColor);
sl@0
  1704
				break;
sl@0
  1705
			case EGlobal:
sl@0
  1706
				iGlobalCharFormat.iFontPresentation.iTextColor = color;
sl@0
  1707
				iGlobalCharFormatMask.SetAttrib(EAttColor);
sl@0
  1708
				break;
sl@0
  1709
			}
sl@0
  1710
		// screen output
sl@0
  1711
		TBuf<80> outputBuf;
sl@0
  1712
		outputBuf.Format(_L("<COLOR = %d>"),value);
sl@0
  1713
		OutputToScreen(outputBuf);
sl@0
  1714
		}
sl@0
  1715
	}
sl@0
  1716
sl@0
  1717
sl@0
  1718
void CParser::TransCharLanguage()
sl@0
  1719
// Assumes languages are integer coded - will have to change in time
sl@0
  1720
	{
sl@0
  1721
	TUint value = GetArgValue();
sl@0
  1722
	if (iErrorLevel==ENoError)
sl@0
  1723
		{
sl@0
  1724
		switch (iTagType)
sl@0
  1725
			{
sl@0
  1726
			case ECharacter:		 
sl@0
  1727
				iCharFormat.iLanguage = value;
sl@0
  1728
				iCharFormatMask.SetAttrib(EAttCharLanguage);
sl@0
  1729
				break;
sl@0
  1730
			case EGlobal:
sl@0
  1731
				iGlobalCharFormat.iLanguage = value;
sl@0
  1732
				iGlobalCharFormatMask.SetAttrib(EAttCharLanguage);
sl@0
  1733
				break;
sl@0
  1734
			}
sl@0
  1735
		// screen output
sl@0
  1736
		TBuf<80> outputBuf;
sl@0
  1737
		outputBuf.Format(_L("<LANGUAGE = %d>"),value);
sl@0
  1738
		OutputToScreen(outputBuf);
sl@0
  1739
		}
sl@0
  1740
	}
sl@0
  1741
sl@0
  1742
sl@0
  1743
sl@0
  1744
////////////////////////////////
sl@0
  1745
// CFileApp
sl@0
  1746
////////////////////////////////
sl@0
  1747
sl@0
  1748
sl@0
  1749
CFileApp* CFileApp::NewL()
sl@0
  1750
	{
sl@0
  1751
	CFileApp* self=new(ELeave) CFileApp;
sl@0
  1752
	CleanupStack::PushL(self);
sl@0
  1753
	self->ConstructApplicationL();
sl@0
  1754
	CleanupStack::Pop();
sl@0
  1755
	return self;
sl@0
  1756
	}
sl@0
  1757
sl@0
  1758
sl@0
  1759
CFileApp::CFileApp()
sl@0
  1760
	{
sl@0
  1761
	// init variables
sl@0
  1762
	iConsoleExists = EFalse;
sl@0
  1763
	iFilePos = 0;
sl@0
  1764
	}
sl@0
  1765
	 
sl@0
  1766
sl@0
  1767
void CFileApp::ConstructApplicationL()
sl@0
  1768
	{
sl@0
  1769
	iTextBuf = CBufSeg::NewL(64);  // Granularity of 64 bytes
sl@0
  1770
	}
sl@0
  1771
sl@0
  1772
sl@0
  1773
CFileApp::~CFileApp()
sl@0
  1774
	{
sl@0
  1775
	delete iTextBuf;
sl@0
  1776
	}
sl@0
  1777
sl@0
  1778
sl@0
  1779
CBufSeg* CFileApp::LoadFileL(CConsoleBase* aConsoleWin)
sl@0
  1780
// Asks for file name, then loads file into text buffer.
sl@0
  1781
	{ 
sl@0
  1782
	iConsoleExists = ETrue;
sl@0
  1783
	iConsole = aConsoleWin;			// grab console handle
sl@0
  1784
	GetFileName();
sl@0
  1785
	FileHandlingL();					// load file & store it
sl@0
  1786
	return iTextBuf;
sl@0
  1787
	}
sl@0
  1788
sl@0
  1789
CBufSeg* CFileApp::LoadFileL(const TFileName &aFileName)
sl@0
  1790
// uses supplied FileName to load file into CBufSeg
sl@0
  1791
	{ 
sl@0
  1792
	iFileName = aFileName;
sl@0
  1793
	FileHandlingL();					// load file & store it
sl@0
  1794
	return iTextBuf;
sl@0
  1795
	}
sl@0
  1796
sl@0
  1797
sl@0
  1798
void CFileApp::OutputToScreen(const TDesC& aMessageBuffer)
sl@0
  1799
	{
sl@0
  1800
	if (iConsoleExists)
sl@0
  1801
		iConsole->Write(aMessageBuffer);  // output line to screen
sl@0
  1802
	}
sl@0
  1803
sl@0
  1804
sl@0
  1805
TInt CFileApp::SaveFile(CBufSeg* aTextBuf, TFileName aFileName)
sl@0
  1806
// saves supplied buffer to disc, making the new filename a varient of the PML source filename supplied
sl@0
  1807
	{
sl@0
  1808
	// set filename to be saved as
sl@0
  1809
	TInt length = aFileName.Length();
sl@0
  1810
	aFileName.Delete(length-1,1);
sl@0
  1811
	aFileName.Append(_L("G")); // generated filenames end in G
sl@0
  1812
sl@0
  1813
	// create fileserver client and save.
sl@0
  1814
	RFs fsClient;
sl@0
  1815
	RFile theFile;
sl@0
  1816
	TInt err = fsClient.Connect();
sl@0
  1817
	if (err == 0)
sl@0
  1818
		err = theFile.Replace(fsClient, aFileName, EFileStream|EFileRead|EFileWrite);
sl@0
  1819
	if (err == 0)
sl@0
  1820
		{
sl@0
  1821
		TInt readWritePos = 0;
sl@0
  1822
		TBuf8<80> insertBuf;
sl@0
  1823
		TInt readLength=0;
sl@0
  1824
		FOREVER
sl@0
  1825
			{
sl@0
  1826
			// read from TextBuf into insertBuf
sl@0
  1827
			readLength=Min(aTextBuf->Size()-readWritePos,insertBuf.MaxLength());
sl@0
  1828
			insertBuf.SetLength(0); 				// empty buffer
sl@0
  1829
			aTextBuf->Read(readWritePos,insertBuf,readLength);
sl@0
  1830
			// insert buf into file
sl@0
  1831
			theFile.Write(readWritePos, insertBuf);
sl@0
  1832
			readWritePos += insertBuf.Length();
sl@0
  1833
			if (readWritePos >= aTextBuf->Size())
sl@0
  1834
				break;
sl@0
  1835
			}
sl@0
  1836
	  	theFile.Close();
sl@0
  1837
		}
sl@0
  1838
	return err;
sl@0
  1839
	}
sl@0
  1840
sl@0
  1841
void CFileApp::GetFileName()
sl@0
  1842
// read FileName synchronously from console
sl@0
  1843
	{ 
sl@0
  1844
	TKeyCode keystroke = EKeyNull;
sl@0
  1845
	iFileName.SetLength(0);
sl@0
  1846
sl@0
  1847
	//Debuging cheat to hardwire filename
sl@0
  1848
	//iFileName=_L("d:\\etext\\incp\\dunk.pml");
sl@0
  1849
	//return;
sl@0
  1850
sl@0
  1851
	OutputToScreen(_L("Enter file to be parsed: "));
sl@0
  1852
	keystroke = iConsole->Getch();
sl@0
  1853
	while (keystroke != EKeyEnter)
sl@0
  1854
		{
sl@0
  1855
		TBuf<1> uniBuf; // used to ease unicode build
sl@0
  1856
		uniBuf.Append(keystroke);
sl@0
  1857
sl@0
  1858
		iConsole->Write(uniBuf);
sl@0
  1859
		iFileName.Append(uniBuf);
sl@0
  1860
		keystroke = iConsole->Getch();
sl@0
  1861
		}
sl@0
  1862
	WriteNewLine();
sl@0
  1863
	}
sl@0
  1864
sl@0
  1865
void CFileApp::FileHandlingL()
sl@0
  1866
// Open a file, read contents into buffer, then close file again
sl@0
  1867
	{
sl@0
  1868
	// open file
sl@0
  1869
    RFile textFile;
sl@0
  1870
	RFs fsClient;
sl@0
  1871
	TInt err = 1;
sl@0
  1872
	while (err)
sl@0
  1873
		{
sl@0
  1874
		err = fsClient.Connect();
sl@0
  1875
		if (!err)
sl@0
  1876
    		err = textFile.Open(fsClient,iFileName,EFileStream|EFileRead|EFileShareReadersOnly);
sl@0
  1877
    	if (err)
sl@0
  1878
			return;
sl@0
  1879
/******GA
sl@0
  1880
			{
sl@0
  1881
    		OutputToScreen(_L("Error in file open\n\n"));
sl@0
  1882
    		GetFileName();
sl@0
  1883
    		}
sl@0
  1884
******/
sl@0
  1885
    	}   	
sl@0
  1886
    
sl@0
  1887
	OutputToScreen(_L("Parsing "));
sl@0
  1888
	OutputToScreen(iFileName);
sl@0
  1889
	WriteNewLine();
sl@0
  1890
	WriteNewLine();
sl@0
  1891
sl@0
  1892
	// Read file into segmented buffer
sl@0
  1893
	TUint insertPos = 0;
sl@0
  1894
sl@0
  1895
	TInt max = sizeof(TText) * KFileBufSize;
sl@0
  1896
sl@0
  1897
	FOREVER
sl@0
  1898
		{
sl@0
  1899
		iFileBuf.SetLength(0);
sl@0
  1900
		ReadChunkOfFileContents(textFile);
sl@0
  1901
		iTextBuf->/*Do*/InsertL(insertPos,iFileBuf.Ptr(),iFileBuf.Size());
sl@0
  1902
		insertPos += iFileBuf.Size();			// in bytes
sl@0
  1903
		if (iFileBuf.Size() < max)
sl@0
  1904
			break;
sl@0
  1905
		}
sl@0
  1906
sl@0
  1907
	// finish up
sl@0
  1908
 	textFile.Close();
sl@0
  1909
	iFilePos = 0; // reset
sl@0
  1910
	}
sl@0
  1911
sl@0
  1912
void CFileApp::ReadChunkOfFileContents(RFile &aFile)
sl@0
  1913
    {
sl@0
  1914
	TBuf8<KFileBufSize> readBuf;
sl@0
  1915
	aFile.Read(iFilePos,readBuf);
sl@0
  1916
	// read into iFileBuf (8/16 bit); 
sl@0
  1917
	TText textPointer;
sl@0
  1918
	for ( TInt pos=0 ; pos<readBuf.Length() ; pos++ )
sl@0
  1919
		{
sl@0
  1920
		textPointer = readBuf[pos];
sl@0
  1921
		iFileBuf.Append(textPointer);
sl@0
  1922
		}
sl@0
  1923
    //TInt ret=aFile.Read(iFilePos,iFileBuf);
sl@0
  1924
	iFilePos += KFileBufSize;
sl@0
  1925
    }
sl@0
  1926
sl@0
  1927
void CFileApp::WriteNewLine()
sl@0
  1928
//
sl@0
  1929
	{
sl@0
  1930
	TBuf<1> buf(_L("\n"));
sl@0
  1931
	OutputToScreen(buf);
sl@0
  1932
	}
sl@0
  1933