telephonyprotocols/csdagt/script/SCOMMAND.CPP
changeset 0 3553901f7fa8
child 19 630d2f34d719
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // NetDial Script Commands
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file Scommand.cpp 
       
    20 */
       
    21 
       
    22 #include "SSCRREAD.H"
       
    23 #include "SSCREXEC.H"
       
    24 #include "SIO.H"
       
    25 #include "SLOGGER.H"
       
    26 
       
    27 // Command names
       
    28 
       
    29 _LIT(KSetCommand,"SET");
       
    30 _LIT(KSendCommand,"SEND");
       
    31 _LIT(KWaitCommand,"WAIT");
       
    32 _LIT(KLoopCommand,"LOOP");
       
    33 _LIT(KGotoCommand,"GOTO");
       
    34 _LIT(KExitCommand,"EXIT");
       
    35 _LIT(KDTRCommand,"DTR");
       
    36 _LIT(KDropDTRCommand,"RAISE");
       
    37 _LIT(KRaiseDTRCommand,"DROP");
       
    38 _LIT(KReadCommand,"READ");
       
    39 _LIT(KCharmapCommand,"CHARMAP");
       
    40 _LIT(KTempVarName,"$$TMPVAR$$%d");	//< Temporary variable name
       
    41 
       
    42 // Characters used in scripts
       
    43 
       
    44 const TText KCommentChar='!';	
       
    45 const TText KPlusChar='+';
       
    46 const TText KQuoteChar='\"';
       
    47 const TText KOpenChevronChar='<';
       
    48 const TText KCloseChevronChar='>';
       
    49 const TText KOpenExprChar='{';
       
    50 const TText KCloseExprChar='}';
       
    51 const TText KEqualsChar='=';
       
    52 const TText KTabChar='\t';
       
    53 const TText KSpaceChar=' ';
       
    54 const TText KColonChar=':';
       
    55 const TText KOpenSquareBracketChar='[';
       
    56 const TText KCloseSquareBracketChar=']';
       
    57 const TInt KLabelArrayGranularity=5;
       
    58 const TInt32 KMinScriptInteger=0;
       
    59 const TInt32 KMaxScriptInteger=500000;
       
    60 const TReal KMinScriptReal=0.0;
       
    61 const TReal KMaxScriptReal=500000.0;
       
    62 const TInt KMinLoopCounter=1;
       
    63 const TInt KMaxLoopCounter=10000;
       
    64 
       
    65 //
       
    66 // Glossary
       
    67 // ========
       
    68 // String				- a text string enclosed in ".."
       
    69 // Character			- a single character expressed numnerically enclosed in <..>
       
    70 // Variable				- named variable (preset or set in script) ending in $
       
    71 // Expression			- any one of the three above
       
    72 // Compound expression	- a number of expressions concatenated with +
       
    73 // Token				- an expression, compound expression, label or command
       
    74 //
       
    75 
       
    76 //
       
    77 // CScriptCommandBase definitions
       
    78 //
       
    79 
       
    80 CScriptCommandBase::CScriptCommandBase(TScriptStatus& aStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
    81 	: iScriptReader(aScriptReader), iVarMan(aVarMan), iCharConv(aCharConv), iTempVarNum(0), iStatus(aStatus)
       
    82 /**
       
    83 Constructor for CScriptCharacterConverter.
       
    84 */
       
    85 	{}
       
    86 
       
    87 CScriptCommandBase::~CScriptCommandBase()
       
    88 /**
       
    89 Destructor.
       
    90 */
       
    91 	{}
       
    92 
       
    93 void CScriptCommandBase::ConstructL()
       
    94 /**
       
    95 Instantiates member variables.
       
    96 */
       
    97 	{}
       
    98 
       
    99 void CScriptCommandBase::Cleanup()
       
   100 /**
       
   101 Cleanup.
       
   102 */
       
   103 	{}
       
   104 
       
   105 TPtrC CScriptCommandBase::ParseCompoundExpressionL(TInt& aOffset)
       
   106 /**
       
   107 Parses a compound string expression starting at aOffset into a single string
       
   108 constant and returns it.
       
   109 */
       
   110 	{
       
   111 	TPtrC wholeExpr;
       
   112 	wholeExpr.Set(ParseExpressionL(aOffset));
       
   113 	TBuf<KMaxVarNameLength> varName;
       
   114 	varName.Format(KTempVarName,iTempVarNum++);
       
   115 	iVarMan->AddVariableL(varName,wholeExpr);
       
   116 	HBufC* val=NULL;
       
   117 	HBufC* oldVal=NULL;
       
   118 	
       
   119 	FOREVER
       
   120 		{
       
   121 		EatSpaces(aOffset);
       
   122 		if (aOffset>=iStatus.iLine.Length())
       
   123 			break;
       
   124 		if (iStatus.iLine[aOffset]!=KPlusChar)
       
   125 			break;
       
   126 		TPtrC nextExpr;
       
   127 		nextExpr.Set(ParseExpressionL(++aOffset));
       
   128 		val=HBufC::NewLC(wholeExpr.Length()+nextExpr.Length());
       
   129 		TPtr currentExpr(val->Des());
       
   130 		currentExpr.Append(wholeExpr);
       
   131 		currentExpr.Append(nextExpr);
       
   132 		varName.Format(KTempVarName,iTempVarNum++);
       
   133 		iVarMan->AddVariableL(varName,val->Des());
       
   134 		CleanupStack::Pop();
       
   135 		wholeExpr.Set(val->Des());
       
   136 		delete oldVal;
       
   137 		oldVal=val;
       
   138 		}
       
   139 
       
   140 	delete val;
       
   141 	User::LeaveIfError(iVarMan->FindVariable(varName,wholeExpr));
       
   142 	return wholeExpr;
       
   143 	}
       
   144 
       
   145 TPtrC CScriptCommandBase::ParseExpressionL(TInt& aOffset)
       
   146 /**
       
   147 Parses string expression starting at aOffset according to starting character
       
   148 and returns value.
       
   149 */
       
   150 	{
       
   151 	EatSpaces(aOffset);
       
   152 	if(iStatus.iLine.Length()<=aOffset)
       
   153 		User::Leave(KErrNoExpression);
       
   154 
       
   155 	switch(iStatus.iLine[aOffset])		//switch(iLine[aOffset+1])
       
   156 		{
       
   157 	case KQuoteChar:
       
   158 		aOffset++;							// skip quote char
       
   159 		return ParseStringL(aOffset);
       
   160 	case KOpenChevronChar:
       
   161 		aOffset++;							// skip chevron char
       
   162 		return ParseCharacterL(aOffset);
       
   163 	default:
       
   164 		return ParseVariableL(aOffset);
       
   165 		}
       
   166 	}
       
   167 
       
   168 TPtrC CScriptCommandBase::ParseStringL(TInt& aOffset)
       
   169 /**
       
   170 Parses a string constant enclosed in "" and returns its value.
       
   171 */
       
   172 	{
       
   173 	return ParseEnclosedStringL(aOffset,KQuoteChar,KErrMissingQuote);
       
   174 	}
       
   175 
       
   176 TPtrC CScriptCommandBase::ParseCharacterL(TInt& aOffset)
       
   177 /**
       
   178 Parses a character enclosed in <> and returns its value.
       
   179 */
       
   180 	{
       
   181 	TPtrC charString=ParseEnclosedStringL(aOffset,KCloseChevronChar,KErrMissingChevron);
       
   182 	TRadix radix=EDecimal;
       
   183 	TInt len=charString.Length();
       
   184 	if (len>2)
       
   185 		{
       
   186 		if(charString[0]=='0')
       
   187 			{
       
   188 			switch(charString[1])
       
   189 				{
       
   190 			case 'x':
       
   191 			case 'X':
       
   192 				len-=2;
       
   193 				radix=EHex;
       
   194 				break;
       
   195 			case 'd':
       
   196 			case 'D':
       
   197 				len-=2;
       
   198 				radix=EDecimal;
       
   199 				break;
       
   200 			case 'o':
       
   201 			case 'O':
       
   202 				len-=2;
       
   203 				radix=EOctal;
       
   204 				break;
       
   205 			case 'b':
       
   206 			case 'B':
       
   207 				len-=2;
       
   208 				radix=EBinary;
       
   209 				break;
       
   210 			default:
       
   211 				break;
       
   212 				}
       
   213 			}
       
   214 		}
       
   215 
       
   216 	TLex lex(charString.Right(len));
       
   217 	TUint val=0;
       
   218 	if (lex.Val(val,radix)!=KErrNone)
       
   219 		User::Leave(KErrInvalidNumber);
       
   220 	TBuf<1> character=(TText*)&val;
       
   221 	TBuf<KMaxVarNameLength> varName;
       
   222 	varName.Format(KTempVarName,iTempVarNum++);
       
   223 	iVarMan->AddVariableL(varName,character);
       
   224 	TPtrC temp;
       
   225 	iVarMan->FindVariable(varName,temp);
       
   226 	return temp;
       
   227 	}
       
   228 
       
   229 TPtrC CScriptCommandBase::ParseVariableL(TInt& aOffset)
       
   230 /**
       
   231 Parses a variable and returns its value.
       
   232 */
       
   233 	{
       
   234 	TInt end=FindTokenEnd(aOffset);
       
   235 	TPtrC varName=iStatus.iLine.Mid(aOffset,end-aOffset);
       
   236 	aOffset=end;
       
   237 	TPtrC varValue;
       
   238 	if (iVarMan->FindVariable(varName,varValue)==KErrNotFound)
       
   239 		{
       
   240 		if(!iStatus.iSkip)
       
   241 			User::Leave(KErrVariableNotFound);
       
   242 		return TPtrC();
       
   243 		}
       
   244 	return varValue;
       
   245 	}
       
   246 
       
   247 TInt32 CScriptCommandBase::ParseIntegerL(TInt& aOffset)
       
   248 /**
       
   249 Parses an integer and returns its value.
       
   250 */
       
   251 	{
       
   252 	EatSpaces(aOffset);
       
   253 	TLex lex(iStatus.iLine);
       
   254 	lex.Inc(aOffset);
       
   255 	TInt32 val=0;
       
   256 	
       
   257 	if (lex.Val(val)!=KErrNone)
       
   258 		{
       
   259 		User::Leave(KErrInvalidNumber);
       
   260 		return KMinScriptInteger;
       
   261 		}
       
   262 
       
   263 	if ((val<KMinScriptInteger) || (val>KMaxScriptInteger))
       
   264 		{
       
   265 		User::Leave(KErrNumberOutOfRange);
       
   266 		return KMinScriptInteger;
       
   267 		}
       
   268 
       
   269 	aOffset=lex.Offset();
       
   270 	return val;
       
   271 	}
       
   272 
       
   273 TReal CScriptCommandBase::ParseRealL(TInt& aOffset)
       
   274 /**
       
   275 Parses a real number and returns its value.
       
   276 */
       
   277 	{
       
   278 	EatSpaces(aOffset);
       
   279 	TLex lex(iStatus.iLine);
       
   280 	lex.Inc(aOffset);
       
   281 	TReal val=0.0;
       
   282 
       
   283 	if (lex.Val(val)!=KErrNone)
       
   284 		{	
       
   285 		User::Leave(KErrInvalidNumber);
       
   286 		return KMinScriptReal;
       
   287 		}
       
   288 	if ((val<KMinScriptReal) || (val>KMaxScriptReal))
       
   289 		{
       
   290 		User::Leave(KErrNumberOutOfRange);
       
   291 		return KMinScriptReal;
       
   292 		}
       
   293 
       
   294 	aOffset=lex.Offset();
       
   295 	return val;
       
   296 	}
       
   297 
       
   298 TPtrC CScriptCommandBase::ParseCharacterTypeL(TInt& aOffset)
       
   299 /**
       
   300 Parses character type.
       
   301 */
       
   302 	{
       
   303 	EatSpaces(aOffset);
       
   304 
       
   305 	if(iStatus.iLine.Length()<=aOffset)		// nothing specified so assume default
       
   306 		return TPtrC();
       
   307 
       
   308 	TInt startChar=aOffset;
       
   309 	if (iStatus.iLine[startChar++]!=KOpenSquareBracketChar)
       
   310 		return TPtrC();				// No open bracket so assume default
       
   311 
       
   312 	aOffset=startChar;
       
   313 	return ParseEnclosedStringL(aOffset,KCloseSquareBracketChar,KErrMissingBracket);
       
   314 	}
       
   315 
       
   316 HBufC8* CScriptCommandBase::ConvertLC(const TDesC& aString,TInt& aOffset)
       
   317 /**
       
   318 Converts to correct character set.
       
   319 */
       
   320 	{
       
   321 	TBuf<KMaxCharacterTypeLength> type=ParseCharacterTypeL(aOffset);
       
   322 	return iCharConv->ConvertLC(aString,type);
       
   323 	}
       
   324 
       
   325 TInt CScriptCommandBase::FindTokenEnd(TInt aOffset)
       
   326 /**
       
   327 Finds end of string beginning at aOffset and returns length.
       
   328 */
       
   329 	{
       
   330 	__ASSERT_DEBUG(aOffset<=iStatus.iLine.Length(), NetDialPanic(EOffsetExceedsLineLength));
       
   331 
       
   332 	if(aOffset==iStatus.iLine.Length())
       
   333 		return aOffset;
       
   334 
       
   335 	TInt end;
       
   336 	for (end=aOffset; IsValidChar(iStatus.iLine[end]); end++)
       
   337 		{
       
   338 		if (end>=(iStatus.iLine.Length()-1))
       
   339 			{
       
   340 			end++;
       
   341 			break;
       
   342 			}
       
   343 		}
       
   344 	return end;
       
   345 	}
       
   346 
       
   347 TBool CScriptCommandBase::IsValidChar(const TText& aChar)
       
   348 /**
       
   349 Checks if aChar is a valid character in a script command.
       
   350 */
       
   351 	{
       
   352 	return TChar(aChar).IsAlphaDigit() || (aChar==KDollarChar) || (aChar==KUnderscoreChar) || (aChar==KCommentChar);
       
   353 	}
       
   354 
       
   355 void CScriptCommandBase::EatSpaces(TInt& aOffset)
       
   356 /**
       
   357 Ignores spaces, tabs, line feeds and carriage returns and sets aOffset to 
       
   358 next non-blank character, or end of line
       
   359 */
       
   360 	{
       
   361 	if(aOffset>=iStatus.iLine.Length())
       
   362 		return;
       
   363 
       
   364 	while((iStatus.iLine[aOffset]==KSpaceChar) || (iStatus.iLine[aOffset]==KTabChar) || (iStatus.iLine[aOffset]==KLineFeed) || (iStatus.iLine[aOffset]==KCarriageReturn))
       
   365 		{
       
   366 		aOffset++;
       
   367 		if(aOffset>=iStatus.iLine.Length())
       
   368 			break;
       
   369 		}
       
   370 	}
       
   371 
       
   372 void CScriptCommandBase::EatSpacesAndLinesL()
       
   373 /**
       
   374 Ignores spaces and empty lines and sets aOffset to next non-blank character.
       
   375 */
       
   376 	{
       
   377 	EatSpaces(iStatus.iOffset);
       
   378 	while(iStatus.iOffset>=iStatus.iLine.Length())
       
   379 		{
       
   380 		User::LeaveIfError(iScriptReader->GetNextLine());		// This also resets iStatus.iOffset
       
   381 		EatSpaces(iStatus.iOffset);
       
   382 		}	
       
   383 	}
       
   384 
       
   385 void CScriptCommandBase::EatSpacesAndLinesAndCommentsL()
       
   386 /**
       
   387 Ignores spaces, empty lines and comments and sets aOffset to next non-blank or 
       
   388 non-comment character
       
   389 */
       
   390 	{
       
   391 	EatSpacesAndLinesL();
       
   392 	while (iStatus.iLine[iStatus.iOffset]==KCommentChar)
       
   393 		{
       
   394 		iStatus.iOffset=iStatus.iLine.Length();
       
   395 		EatSpacesAndLinesL();		// this will reset iStatus.iOffset if necessary
       
   396 		}
       
   397 	}	
       
   398 
       
   399 TPtrC CScriptCommandBase::ParseEnclosedStringL(TInt& aOffset,TText aChar,TInt aError)
       
   400 /**
       
   401 Parses enclosed string
       
   402 */
       
   403 	{
       
   404 	if(aOffset>=iStatus.iLine.Length())
       
   405 		User::Leave(aError);			// no end character before EOL
       
   406 	
       
   407 	TInt end=aOffset;
       
   408 	while (end<iStatus.iLine.Length())
       
   409 		{
       
   410 		if (iStatus.iLine[end]==aChar)
       
   411 			break;
       
   412 		end++;
       
   413 		}
       
   414 
       
   415 	if (end>=iStatus.iLine.Length())
       
   416 		User::Leave(aError);			// no end character before EOL
       
   417 
       
   418 	TInt start=aOffset;
       
   419 	aOffset=end+1;
       
   420 	return iStatus.iLine.Mid(start,end-start);
       
   421 	}
       
   422 
       
   423 //
       
   424 // CSetCommand definitions
       
   425 //
       
   426 
       
   427 CSetCommand* CSetCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
   428 /**
       
   429 2 phased constructor for CSetCommand, first phase.
       
   430 
       
   431 @param aScriptStatus is script status.
       
   432 @param aScriptReader a pointer to script reader.
       
   433 @param aVarMan a pointer to variable manager.
       
   434 @param aCharConv a pointer to script character converter.
       
   435 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
   436 @return a new CSetCommand object.
       
   437 */
       
   438 	{
       
   439 	CSetCommand* c=new(ELeave) CSetCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv);
       
   440 	CleanupStack::PushL(c);
       
   441 	c->ConstructL();
       
   442 	CleanupStack::Pop();
       
   443 	return c;
       
   444 	}
       
   445 
       
   446 CSetCommand::CSetCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
   447 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv)
       
   448 /**
       
   449 Constructor for CSetCommand, used in the first phase of construction.
       
   450 
       
   451 @param aScriptStatus is script status.
       
   452 @param aScriptReader a pointer to script reader.
       
   453 @param aVarMan a pointer to variable manager.
       
   454 @param aCharConv a pointer to script character converter.
       
   455 */
       
   456 	{}
       
   457 
       
   458 CSetCommand::~CSetCommand()
       
   459 /**
       
   460 Destructor.
       
   461 */
       
   462 	{}
       
   463 
       
   464 TBool CSetCommand::ParseL()
       
   465 /**
       
   466 Parses a SET command. Determines variable name and value and adds to variable list.
       
   467 */
       
   468 	{
       
   469 	EatSpacesAndLinesAndCommentsL();
       
   470 	TInt end=FindTokenEnd(iStatus.iOffset);
       
   471 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KSetCommand)==KErrNone)
       
   472 		{
       
   473 		if (!iStatus.iSkip)
       
   474 			{
       
   475 			__FLOG_STMT(_LIT8(KLogStringExecutingSet,"Script:\tExecuting Set");)
       
   476 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),KLogStringExecutingSet());
       
   477 			}
       
   478 		iStatus.iOffset=end;
       
   479 		EatSpaces(iStatus.iOffset);
       
   480 		end=FindTokenEnd(iStatus.iOffset);
       
   481 		TPtrC varName=iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset);
       
   482 		EatSpaces(end);
       
   483 		if (iStatus.iLine[end++]!=KEqualsChar)
       
   484 			User::Leave(KErrNoEquals);
       
   485 		EatSpaces(end);
       
   486 		TPtrC value=ParseCompoundExpressionL(end);
       
   487 		if (!iStatus.iSkip)
       
   488 			{
       
   489 			iVarMan->AddVariableL(varName,value);
       
   490 			__FLOG_STMT(_LIT(KLogStringSetVar,"Script:\tSet Var: %S  To %S"));
       
   491 			__FLOG_STATIC2(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(KLogStringSetVar()),&varName,&value);
       
   492 			}
       
   493 		iStatus.iOffset=end;
       
   494 		return ETrue;		// Consumed
       
   495 		}
       
   496 	return EFalse;			// Not Consumed
       
   497 	}
       
   498 
       
   499 //
       
   500 // CSendCommand definitions
       
   501 //
       
   502 
       
   503 CSendCommand* CSendCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptIO* aScriptIO)
       
   504 /**
       
   505 2 phased constructor for CSendCommand, first phase.
       
   506 
       
   507 @param aScriptStatus is script status.
       
   508 @param aScriptReader a pointer to script reader.
       
   509 @param aVarMan a pointer to variable manager.
       
   510 @param aCharConv a pointer to script character converter.
       
   511 @param aScriptIO a pointer to serial comms I/O handler.
       
   512 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
   513 @return a new CSendCommand object.
       
   514 */
       
   515 	{
       
   516 	CSendCommand* c=new(ELeave) CSendCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv,aScriptIO);
       
   517 	CleanupStack::PushL(c);
       
   518 	c->ConstructL();
       
   519 	CleanupStack::Pop();
       
   520 	return c;
       
   521 	}
       
   522 
       
   523 CSendCommand::CSendCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptIO* aScriptIO)
       
   524 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv), iScriptIO(aScriptIO)
       
   525 /**
       
   526 Constructor for CSendCommand, used in the first phase of construction.
       
   527 
       
   528 @param aScriptStatus is script status.
       
   529 @param aScriptReader a pointer to script reader.
       
   530 @param aVarMan a pointer to variable manager.
       
   531 @param aCharConv a pointer to script character converter.
       
   532 @param aScriptIO a pointer to serial comms I/O handler.
       
   533 */
       
   534 	{}
       
   535 
       
   536 CSendCommand::~CSendCommand()
       
   537 /**
       
   538 Destructor.
       
   539 */
       
   540 	{}
       
   541 
       
   542 TBool CSendCommand::ParseL()
       
   543 /**
       
   544 Parses SEND command.  Parses expression to send and sends it.
       
   545 */
       
   546 	{
       
   547 	EatSpacesAndLinesAndCommentsL();
       
   548 	TInt end=FindTokenEnd(iStatus.iOffset);
       
   549 	if(iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KSendCommand)==0)
       
   550 		{
       
   551 		if(!iStatus.iSkip)
       
   552 			{
       
   553 			__FLOG_STMT(_LIT8(KLogStringExecutingSend,"Script:\tExecuting Send");)
       
   554 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),KLogStringExecutingSend());
       
   555 			}
       
   556 		iStatus.iOffset=end;
       
   557 		EatSpaces(iStatus.iOffset);
       
   558 		TPtrC temp;
       
   559 		temp.Set(ParseCompoundExpressionL(iStatus.iOffset));
       
   560 		HBufC8* buf=ConvertLC(temp,iStatus.iOffset);
       
   561 		iSendString.Set(buf->Des());
       
   562 		if(!iStatus.iSkip)
       
   563 			{
       
   564 			iScriptIO->Write(iSendString);
       
   565 #ifdef __FLOG_ACTIVE
       
   566 			_LIT(KLogStringSending,"Script:\tSending %S");
       
   567 			TBuf16<KLogBufferSize> temp;
       
   568 			temp.Copy(iSendString.Left(Min(iSendString.Length(),KLogBufferSize)));
       
   569 			__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(KLogStringSending()),&temp);
       
   570 #endif
       
   571 			}
       
   572 		CleanupStack::PopAndDestroy();
       
   573 		return ETrue;		// Consumed
       
   574 		}
       
   575 	return EFalse;			// Not Consumed
       
   576 	}
       
   577 
       
   578 //
       
   579 // CLabelSearch definitions
       
   580 //
       
   581 
       
   582 CLabelSearch* CLabelSearch::NewLC(const TDesC& aLabelName)
       
   583 /**
       
   584 2 phased constructor for CLabelSearch, first phase.
       
   585 
       
   586 @param aLabelName is label name.
       
   587 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
   588 @return a new CLabelSearch object.
       
   589 */
       
   590 	{
       
   591 	CLabelSearch* label=new(ELeave) CLabelSearch();
       
   592 	CleanupStack::PushL(label);
       
   593 	label->ConstructL(aLabelName);
       
   594 	return label;
       
   595 	}
       
   596 
       
   597 CLabelSearch::CLabelSearch()
       
   598 	: iStatus(ENotFound), iPosition()
       
   599 /**
       
   600 Constructor for CLabelSearch, used in the first phase of construction.
       
   601 */
       
   602 	{}
       
   603 
       
   604 void CLabelSearch::ConstructL(const TDesC& aLabelName)
       
   605 /**
       
   606 Instantiates member variables.
       
   607 */
       
   608 	{
       
   609 	iChatString=NULL;
       
   610 	iLabelName=HBufC::NewL(aLabelName.Length());
       
   611 	(*iLabelName)=aLabelName;
       
   612 	}
       
   613 
       
   614 CLabelSearch::~CLabelSearch()
       
   615 /**
       
   616 Destructor.
       
   617 Don't delete iChatString - that is dealt with by CScriptIO.
       
   618 */
       
   619 	{
       
   620 	delete iLabelName;
       
   621 	}
       
   622 
       
   623 void CLabelSearch::CreateCommChatStringL(const TDesC8& aDes,TBool aIsFolded)
       
   624 /**
       
   625 Creates CCommChatString object.
       
   626 */
       
   627 	{
       
   628 	iChatString=CCommChatString::NewL(aDes,aIsFolded);
       
   629 	}
       
   630 
       
   631 //
       
   632 // CWaitCommand definitions
       
   633 //
       
   634 
       
   635 CWaitCommand* CWaitCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptIO* aScriptIO,CScriptLabelMan* aLabelMan, CScriptExecutor* aScriptExec)
       
   636 /**
       
   637 2 phased constructor for CWaitCommand, first phase.
       
   638 
       
   639 @param aScriptStatus is script status.
       
   640 @param aScriptReader a pointer to script reader.
       
   641 @param aVarMan a pointer to variable manager.
       
   642 @param aCharConv a pointer to script character converter.
       
   643 @param aScriptIO a pointer to serial comms I/O handler.
       
   644 @param aLabelMan a pointer to label manager.
       
   645 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
   646 @return a new CWaitCommand object.
       
   647 */
       
   648 	{
       
   649 	CWaitCommand* c=new(ELeave) CWaitCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv,aScriptIO,aLabelMan,aScriptExec);
       
   650 	CleanupStack::PushL(c);
       
   651 	c->ConstructL();
       
   652 	CleanupStack::Pop();
       
   653 	return c;
       
   654 	}
       
   655 
       
   656 CWaitCommand::CWaitCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptIO* aScriptIO,CScriptLabelMan* aLabelMan, CScriptExecutor* aScriptExec)
       
   657 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv), iScriptIO(aScriptIO), iLabelMan(aLabelMan), iScriptExec(aScriptExec)
       
   658 /**
       
   659 Constructor for CWaitCommand, used in the first phase of construction.
       
   660 
       
   661 @param aScriptStatus is script status.
       
   662 @param aScriptReader a pointer to script reader.
       
   663 @param aVarMan a pointer to variable manager.
       
   664 @param aCharConv a pointer to script character converter.
       
   665 @param aScriptIO a pointer to serial comms I/O handler.
       
   666 @param aLabelMan a pointer to label manager.
       
   667 */
       
   668 	{}
       
   669 
       
   670 CWaitCommand::~CWaitCommand()
       
   671 /**
       
   672 Destructor.
       
   673 Clears label array.
       
   674 */
       
   675 	{
       
   676 	DeleteLabelArray();
       
   677 	}
       
   678 
       
   679 TBool CWaitCommand::ParseL()
       
   680 /**
       
   681 Parses WAIT command. Parse according to whether in skip mode or not.
       
   682 */
       
   683 	{
       
   684 	EatSpacesAndLinesAndCommentsL();
       
   685 	TInt end=FindTokenEnd(iStatus.iOffset);
       
   686 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KWaitCommand)==KErrNone)
       
   687 		{
       
   688 		iStatus.iOffset=end;
       
   689 		if (iStatus.iSkip)
       
   690 			ParseSkipL();
       
   691 		else
       
   692 			ParseActionL();
       
   693 		return ETrue;				// Consumed
       
   694 		}
       
   695 	return EFalse;					// Not Consumed
       
   696 	}
       
   697 
       
   698 void CWaitCommand::Cleanup()
       
   699 /**
       
   700 Cancels the read and clears out the labels
       
   701 */
       
   702 	{
       
   703 	if (!iStatus.iSkip)
       
   704 		{
       
   705 		iScriptIO->Cancel();
       
   706 		DeleteLabelArray();
       
   707 		iLabelArray=NULL;
       
   708 		}
       
   709 	}
       
   710 
       
   711 void CWaitCommand::ParseActionL()
       
   712 /**
       
   713 Parses WAIT command when not in skip mode.  Parses wait period, strings and labels and 
       
   714 queue a read.
       
   715 */
       
   716 	{
       
   717 	__FLOG_STMT(_LIT8(KLogStringExecutingWait,"Script:\tExecuting Wait");)
       
   718 	__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),KLogStringExecutingWait());
       
   719 	EatSpaces(iStatus.iOffset);
       
   720 	TReal waitPeriod=ParseRealL(iStatus.iOffset);
       
   721 	EatSpacesAndLinesAndCommentsL();
       
   722 	if (iStatus.iLine[iStatus.iOffset++]!=KOpenExprChar)
       
   723 		User::Leave(KErrNoOpenExpression);
       
   724 
       
   725 	iLabelArray=new(ELeave) CLabelSearchArray(KLabelArrayGranularity);
       
   726 	TBool completed=EFalse;
       
   727 	while(!completed)
       
   728 		{
       
   729 		EatSpacesAndLinesAndCommentsL();
       
   730 		if (iStatus.iLine[iStatus.iOffset]==KCloseExprChar)
       
   731 			{
       
   732 			completed=ETrue;
       
   733 			iStatus.iOffset++;
       
   734 			}
       
   735 		else
       
   736 			{
       
   737 			TPtrC temp=ParseCompoundExpressionL(iStatus.iOffset);
       
   738 			HBufC8* buf=ConvertLC(temp,iStatus.iOffset);
       
   739 			CLabelSearch* label=ParseLabelLC();
       
   740 			TPtrC8 waitString(buf->Des());	
       
   741 			label->CreateCommChatStringL(waitString,EFalse);
       
   742 			iLabelArray->AppendL(label);
       
   743 			// for logging
       
   744 			TBuf<KLogBufferSize> labelName;
       
   745 			labelName.Copy(label->LabelName().Left(Min(KLogBufferSize,label->LabelName().Length())));
       
   746 			//
       
   747 #ifdef __FLOG_ACTIVE
       
   748 			_LIT(KLogStringGog,"Script:\tIf %S is found, Goto %S");
       
   749 			TBuf16<KLogBufferSize> string;
       
   750 			string.Copy(waitString.Left(Min(waitString.Length(),KLogBufferSize)));
       
   751 			__FLOG_STATIC2(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(KLogStringGog()),&string,&labelName);
       
   752 #endif
       
   753 			CleanupStack::Pop();			// label - will be deleted from array
       
   754 			CleanupStack::PopAndDestroy();	// buf - will have been copied into label array
       
   755 			}			
       
   756 		}
       
   757 	// Tell the script executor how long we are going to wait since it
       
   758 	// may need to force the server to resend the login prompt and will
       
   759 	// need to know how long to wait the second time around
       
   760 	iScriptExec->SetRetransmittedLoginTimeout(waitPeriod);
       
   761 	iScriptIO->Read(iLabelArray,waitPeriod);
       
   762 	}
       
   763 
       
   764 void CWaitCommand::ParseSkipL()
       
   765 /**
       
   766 Parses a WAIT command when in skip mode. Parses expressions and labels but do not queue read.
       
   767 */
       
   768 	{
       
   769 	EatSpaces(iStatus.iOffset);
       
   770 	ParseRealL(iStatus.iOffset);					// ignore the actual value returned
       
   771 	EatSpacesAndLinesAndCommentsL();
       
   772 	if (iStatus.iLine[iStatus.iOffset++]!=KOpenExprChar)
       
   773 		User::Leave(KErrNoOpenExpression);
       
   774 
       
   775 	TBool completed=EFalse;
       
   776 	while (!completed)
       
   777 		{
       
   778 		EatSpacesAndLinesAndCommentsL();
       
   779 		if (iStatus.iLine[iStatus.iOffset]==KCloseExprChar)
       
   780 			{
       
   781 			completed=ETrue;
       
   782 			iStatus.iOffset++;
       
   783 			}
       
   784 		else
       
   785 			{
       
   786 			ParseCompoundExpressionL(iStatus.iOffset);			// ignore the return value in skip mode
       
   787 			ParseLabelLC();
       
   788 			CleanupStack::PopAndDestroy();				// ignore the label returned
       
   789 			}
       
   790 		}
       
   791 	}
       
   792 
       
   793 CLabelSearch* CWaitCommand::ParseLabelLC()
       
   794 /**
       
   795 Parses label.  Parses label name and looks for it in the label list.
       
   796 Returns results of search.
       
   797 */
       
   798 	{
       
   799 	EatSpaces(iStatus.iOffset);
       
   800 	TInt start=iStatus.iOffset;
       
   801 	iStatus.iOffset=FindTokenEnd(start);
       
   802 	TPtrC var=iStatus.iLine.Mid(start,iStatus.iOffset-start);
       
   803 	CLabelSearch* labelSearch=CLabelSearch::NewLC(var);
       
   804 	TLinePosition pos;
       
   805 	if(iLabelMan->FindLabel(var,pos)==KErrNotFound)
       
   806 		{
       
   807 		pos.Reset();
       
   808 		labelSearch->Set(CLabelSearch::ENotFound,pos);
       
   809 		}
       
   810 	else
       
   811 		labelSearch->Set(CLabelSearch::EResolved,pos);
       
   812 	return labelSearch;
       
   813 	}
       
   814 
       
   815 TPtrC CWaitCommand::LabelFromIndexL(TInt aIndex)
       
   816 /**
       
   817 Gets label from array by index.
       
   818 */
       
   819 	{
       
   820 	if ((aIndex<0) && (aIndex>iLabelArray->Count()))
       
   821 		User::Leave(KErrIllegalWaitLabelIndex);
       
   822 	return (*iLabelArray)[aIndex]->LabelName();
       
   823 	}
       
   824 
       
   825 void CWaitCommand::DeleteLabelArray()
       
   826 /**
       
   827 Deletes label array.
       
   828 */
       
   829 	{
       
   830 	if (iLabelArray!=NULL)
       
   831 		{
       
   832 		TInt count=iLabelArray->Count();
       
   833 		for(TInt i=0; i<count; i++)
       
   834 			{
       
   835 			delete (*iLabelArray)[i];
       
   836 			}
       
   837 		iLabelArray->Delete(0,count);
       
   838 		delete iLabelArray;
       
   839 		}
       
   840 	}
       
   841 	
       
   842 //
       
   843 // CLoopCommand definitions
       
   844 //
       
   845 
       
   846 CLoopCommand* CLoopCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
   847 /**
       
   848 2 phased constructor for CLoopCommand, first phase.
       
   849 
       
   850 @param aScriptStatus is script status.
       
   851 @param aScriptReader a pointer to script reader.
       
   852 @param aVarMan a pointer to variable manager.
       
   853 @param aCharConv a pointer to script character converter.
       
   854 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
   855 @return a new CLoopCommand object.
       
   856 */
       
   857 	{
       
   858 	CLoopCommand* c=new(ELeave) CLoopCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv);
       
   859 	CleanupStack::PushL(c);
       
   860 	c->ConstructL();
       
   861 	CleanupStack::Pop();
       
   862 	return c;
       
   863 	}
       
   864 
       
   865 CLoopCommand::CLoopCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
   866 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv), iLoop(EFalse)
       
   867 /**
       
   868 Constructor for CLoopCommand, used in the first phase of construction.
       
   869 
       
   870 @param aScriptStatus is script status.
       
   871 @param aScriptReader a pointer to script reader.
       
   872 @param aVarMan a pointer to variable manager.
       
   873 @param aCharConv a pointer to script character converter.
       
   874 */
       
   875 	{}
       
   876 
       
   877 CLoopCommand::~CLoopCommand()
       
   878 /**
       
   879 Destructor.
       
   880 */
       
   881 	{}
       
   882 
       
   883 TBool CLoopCommand::ParseL()
       
   884 /**
       
   885 Parses LOOP command. Checks how many times to loop and records position of beginning of loop.
       
   886 */
       
   887 	{
       
   888 	EatSpacesAndLinesAndCommentsL();
       
   889 	TInt end=FindTokenEnd(iStatus.iOffset);
       
   890 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KLoopCommand)==KErrNone)
       
   891 		{
       
   892 		if (iLoop)
       
   893 			User::Leave(KErrNestedLoop);
       
   894 		if (!iStatus.iSkip)
       
   895 			{
       
   896 			__FLOG_STMT(_LIT8(KLogStringExecutingLoop,"Script:\tExecuting Loop");)
       
   897 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),KLogStringExecutingLoop());
       
   898 			}
       
   899 		iStatus.iOffset=end;
       
   900 		EatSpaces(iStatus.iOffset);
       
   901 		iLoopCounter=ParseIntegerL(iStatus.iOffset);
       
   902 		if ((iLoopCounter<KMinLoopCounter) || (iLoopCounter>KMaxLoopCounter))
       
   903 			User::Leave(KErrLoopCounterOutOfRange);
       
   904 		EatSpacesAndLinesAndCommentsL();
       
   905 		if (iStatus.iLine[iStatus.iOffset++]!=KOpenExprChar)
       
   906 			User::Leave(KErrNoOpenExpression);
       
   907 		iLoop=ETrue;
       
   908 		iScriptReader->CurrentPos(iLoopPosition,iStatus.iOffset);
       
   909 		if (!iStatus.iSkip)
       
   910 			{
       
   911 			__FLOG_STMT(_LIT(KLogStringLoopCounter,"Script:\tLoop Counter %d");)
       
   912 			__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),KLogStringLoopCounter(),iLoopCounter);
       
   913 			}
       
   914 		return ETrue;		// Consumed
       
   915 		}
       
   916 	return EFalse;			// Not Consumed
       
   917 	}
       
   918 
       
   919 TBool CLoopCommand::CheckLoopL()
       
   920 /**
       
   921 Checks how many times loop has been executed and returns to beginning if necessary.
       
   922 */
       
   923 	{
       
   924 	if (iLoop)
       
   925 		{
       
   926 		EatSpacesAndLinesAndCommentsL();
       
   927 		if(iStatus.iLine[iStatus.iOffset]==KCloseExprChar)
       
   928 			{
       
   929 			if((--iLoopCounter==0) || (iStatus.iSkip))
       
   930 				{
       
   931 				iLoop=EFalse;
       
   932 				iStatus.iOffset++;
       
   933 				}
       
   934 			else
       
   935 				{
       
   936 				iScriptReader->SetCurrentPos(iLoopPosition);
       
   937 				__FLOG_STMT(_LIT8(logString1,"Script:\tRepeat Loop");)
       
   938 				__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString1());
       
   939 				__FLOG_STMT(_LIT8(logString2,"Script:\tLoop Counter %d");)
       
   940 				__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),logString2(),iLoopCounter);
       
   941 				}
       
   942 			return ETrue;				// Consumed Something
       
   943 			}
       
   944 		}
       
   945 	return EFalse;						// Nothing doing...
       
   946 	}
       
   947 
       
   948 //
       
   949 // CGotoCommand definitions
       
   950 //
       
   951 
       
   952 CGotoCommand* CGotoCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptLabelMan* aLabelMan)
       
   953 /**
       
   954 2 phased constructor for CGotoCommand, first phase.
       
   955 
       
   956 @param aScriptStatus is script status.
       
   957 @param aScriptReader a pointer to script reader.
       
   958 @param aVarMan a pointer to variable manager.
       
   959 @param aCharConv a pointer to script character converter.
       
   960 @param aLabelMan a pointer to label manager.
       
   961 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
   962 @return a new CGotoCommand object.
       
   963 */	
       
   964 	{
       
   965 	CGotoCommand* c=new(ELeave) CGotoCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv,aLabelMan);
       
   966 	CleanupStack::PushL(c);
       
   967 	c->ConstructL();
       
   968 	CleanupStack::Pop();
       
   969 	return c;
       
   970 	}
       
   971 
       
   972 CGotoCommand::CGotoCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptLabelMan* aLabelMan)
       
   973 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv), iLabelMan(aLabelMan)
       
   974 /**
       
   975 Constructor for CGotoCommand, used in the first phase of construction.
       
   976 
       
   977 @param aScriptStatus is script status.
       
   978 @param aScriptReader a pointer to script reader.
       
   979 @param aVarMan a pointer to variable manager.
       
   980 @param aCharConv a pointer to script character converter.
       
   981 @param aLabelMan a pointer to label manager.
       
   982 */
       
   983 	{}
       
   984 
       
   985 CGotoCommand::~CGotoCommand()
       
   986 /**
       
   987 Destructor.
       
   988 */
       
   989 	{}
       
   990 
       
   991 TBool CGotoCommand::ParseL()
       
   992 /**
       
   993 Parses GOTO command. Parses label and goto label.
       
   994 */
       
   995 	{
       
   996 	EatSpacesAndLinesAndCommentsL();
       
   997 	TInt end=FindTokenEnd(iStatus.iOffset);
       
   998 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KGotoCommand)==KErrNone)
       
   999 		{
       
  1000 		if(!iStatus.iSkip)
       
  1001 			{
       
  1002 			__FLOG_STMT(_LIT8(logString,"Script:\tExecuting Goto");)
       
  1003 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
  1004 			}
       
  1005 		iStatus.iOffset=end;
       
  1006 		EatSpaces(iStatus.iOffset);
       
  1007 		end=FindTokenEnd(iStatus.iOffset);
       
  1008 		TPtrC var=iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset);
       
  1009 	//	HBufC* labelName=HBufC::NewLC(var.Length());
       
  1010 	//	(*labelName)=var;
       
  1011 	//	GotoL(labelName->Des());
       
  1012 	//	CleanupStack::PopAndDestroy();
       
  1013 		Goto(var);
       
  1014 		iStatus.iOffset=end;
       
  1015 		return ETrue;		// Consumed
       
  1016 		}
       
  1017 	return EFalse;			// Not Consumed
       
  1018 	}
       
  1019 
       
  1020 void CGotoCommand::Goto(const TDesC& aLabelName)
       
  1021 /**
       
  1022 Finds label in those passed already, or skip lines until it is found.
       
  1023 */
       
  1024 	{
       
  1025 	TLinePosition pos;
       
  1026 	if(!iStatus.iSkip)
       
  1027 		{
       
  1028 		if (iLabelMan->FindLabel(aLabelName,pos)==KErrNotFound)
       
  1029 			{
       
  1030 			iSearchName.Copy(aLabelName);
       
  1031 			iStatus.iSkipModeToggleReq=ETrue;
       
  1032 			__FLOG_STMT(_LIT(logString1,"Script:\tSearching for Label %S");)
       
  1033 			__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC>(logString1()),&aLabelName);
       
  1034 			__FLOG_STMT(_LIT8(logString2,"Script:\tEntering Skip Mode");)
       
  1035 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString2());
       
  1036 			}
       
  1037 		else
       
  1038 			iScriptReader->SetCurrentPos(pos);
       
  1039 		}
       
  1040 	}
       
  1041 
       
  1042 TBool CGotoCommand::ParseLabelL()
       
  1043 /**
       
  1044 Parses label and adds it to label list. Compares label against one to be found.
       
  1045 */
       
  1046 	{
       
  1047 	EatSpacesAndLinesAndCommentsL();
       
  1048 	TInt start=iStatus.iOffset;
       
  1049 	TInt end=FindTokenEnd(start);
       
  1050 	if ((iStatus.iLine.Length()>=(end+1)) && (iStatus.iLine[end]==KColonChar))
       
  1051 		{
       
  1052 		TLinePosition pos;
       
  1053 		iScriptReader->CurrentPos(pos,end+1);
       
  1054 		iLabelMan->AddLabelL(iStatus.iLine.Mid(start,end-start),pos);
       
  1055 		iStatus.iOffset=++end;
       
  1056 		TLinePosition dummyPos;
       
  1057 		if (iStatus.iSkip && (iLabelMan->FindLabel(iSearchName,dummyPos)==KErrNone))
       
  1058 			{
       
  1059 			iStatus.iSkipModeToggleReq=ETrue;
       
  1060 			__FLOG_STMT(_LIT8(logString,"Script:\tExiting Skip Mode");)
       
  1061 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
  1062 			}
       
  1063 		return ETrue;
       
  1064 		}
       
  1065 	return EFalse;
       
  1066 	}
       
  1067 
       
  1068 void CGotoCommand::ServiceSkipReqs()
       
  1069 /**
       
  1070 Toggles skip mode.
       
  1071 */
       
  1072 	{
       
  1073 	if(iStatus.iSkipModeToggleReq)
       
  1074 		{
       
  1075 		iStatus.iSkipModeToggleReq=EFalse;
       
  1076 		iStatus.iSkip=!iStatus.iSkip;
       
  1077 		}
       
  1078 	}
       
  1079 
       
  1080 //
       
  1081 // CDTRCommand definitions
       
  1082 //
       
  1083 
       
  1084 CDTRCommand* CDTRCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptIO* aScriptIO)
       
  1085 /**
       
  1086 2 phased constructor for CDTRCommand, first phase.
       
  1087 
       
  1088 @param aScriptStatus is script status.
       
  1089 @param aScriptReader a pointer to script reader.
       
  1090 @param aVarMan a pointer to variable manager.
       
  1091 @param aCharConv a pointer to script character converter.
       
  1092 @param aScriptIO a pointer to serial comms I/O handler.
       
  1093 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
  1094 @return a new CDTRCommand object.
       
  1095 */
       
  1096 	{
       
  1097 	CDTRCommand* c=new(ELeave) CDTRCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv,aScriptIO);
       
  1098 	CleanupStack::PushL(c);
       
  1099 	c->ConstructL();
       
  1100 	CleanupStack::Pop();
       
  1101 	return c;
       
  1102 	}
       
  1103 
       
  1104 CDTRCommand::CDTRCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptIO* aScriptIO)
       
  1105 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv), iScriptIO(aScriptIO)
       
  1106 /**
       
  1107 Constructor for CDTRCommand, used in the first phase of construction.
       
  1108 
       
  1109 @param aScriptStatus is script status.
       
  1110 @param aScriptReader a pointer to script reader.
       
  1111 @param aVarMan a pointer to variable manager.
       
  1112 @param aCharConv a pointer to script character converter.
       
  1113 @param aScriptIO a pointer to serial comms I/O handler.
       
  1114 */
       
  1115 	{}
       
  1116 
       
  1117 CDTRCommand::~CDTRCommand()
       
  1118 /**
       
  1119 Destructor.
       
  1120 */
       
  1121 	{}
       
  1122 
       
  1123 TBool CDTRCommand::ParseL()
       
  1124 /**
       
  1125 Parses DTR command. Drops or raises appropriately.
       
  1126 */
       
  1127 	{
       
  1128 	EatSpacesAndLinesAndCommentsL();
       
  1129 	TInt end=FindTokenEnd(iStatus.iOffset);
       
  1130 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KDTRCommand)==KErrNone)
       
  1131 		{
       
  1132 		if(!iStatus.iSkip)
       
  1133 			{
       
  1134 			__FLOG_STMT(_LIT8(logString1,"Script:\tExecuting DTR");)
       
  1135 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString1());
       
  1136 			}
       
  1137 		iStatus.iOffset=end;
       
  1138 		EatSpaces(iStatus.iOffset);
       
  1139 		end=FindTokenEnd(iStatus.iOffset);
       
  1140 		if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KRaiseDTRCommand)==KErrNone)
       
  1141 			{
       
  1142 			if(!iStatus.iSkip)
       
  1143 				{
       
  1144 				__FLOG_STMT(_LIT8(logString2,"Script:\tRaising DTR");)
       
  1145 				__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString2());
       
  1146 				iScriptIO->RaiseDTR(NULL);
       
  1147 				}	
       
  1148 			}
       
  1149 		else if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KDropDTRCommand)==KErrNone)
       
  1150 			{
       
  1151 			if(!iStatus.iSkip)
       
  1152 				{
       
  1153 				__FLOG_STMT(_LIT8(logString3,"Script:\tDropping DTR");)
       
  1154 				__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString3());
       
  1155 				iScriptIO->DropDTR(NULL);
       
  1156 				}	
       
  1157 			}
       
  1158 		else
       
  1159 			User::Leave(KErrNoDropOrRaise);
       
  1160 		iStatus.iOffset=end;
       
  1161 		return ETrue;		// Consumed
       
  1162 		}
       
  1163 	return EFalse;			// Not Consumed
       
  1164 	}
       
  1165 
       
  1166 //
       
  1167 // CReadPCTCommand definitions
       
  1168 //
       
  1169 
       
  1170 CReadPCTCommand* CReadPCTCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptExecutor* aScriptExec)
       
  1171 /**
       
  1172 2 phased constructor for CReadPCTCommand, first phase.
       
  1173 
       
  1174 @param aScriptStatus is script status.
       
  1175 @param aScriptReader a pointer to script reader.
       
  1176 @param aVarMan a pointer to variable manager.
       
  1177 @param aCharConv a pointer to script character converter.
       
  1178 @param aScriptExec a pointer to script executioner.
       
  1179 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
  1180 @return a new CReadPCTCommand object.
       
  1181 */
       
  1182 	{
       
  1183 	CReadPCTCommand* c=new(ELeave) CReadPCTCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv,aScriptExec);
       
  1184 	CleanupStack::PushL(c);
       
  1185 	c->ConstructL();
       
  1186 	CleanupStack::Pop();
       
  1187 	return c;
       
  1188 	}
       
  1189 
       
  1190 CReadPCTCommand::CReadPCTCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv,CScriptExecutor* aScriptExec)
       
  1191 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv), iScriptExec(aScriptExec)
       
  1192 /**
       
  1193 Constructor for CDTRCommand, used in the first phase of construction.
       
  1194 
       
  1195 @param aScriptStatus is script status.
       
  1196 @param aScriptReader a pointer to script reader.
       
  1197 @param aVarMan a pointer to variable manager.
       
  1198 @param aCharConv a pointer to script character converter.
       
  1199 @param aScriptExec a pointer to script executioner.
       
  1200 */
       
  1201 	{}
       
  1202 
       
  1203 CReadPCTCommand::~CReadPCTCommand()
       
  1204 /**
       
  1205 Destructor.
       
  1206 */
       
  1207 	{}
       
  1208 
       
  1209 TBool CReadPCTCommand::ParseL()
       
  1210 /**
       
  1211 Parses Read command.
       
  1212 */
       
  1213 	{
       
  1214 	EatSpacesAndLinesAndCommentsL();
       
  1215 	TInt end=FindTokenEnd(iStatus.iOffset);
       
  1216 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KReadCommand)==KErrNone)
       
  1217 		{
       
  1218 		if (!iStatus.iSkip)
       
  1219 			{
       
  1220 			__FLOG_STMT(_LIT8(logString,"Script:\tExecuting Read");)
       
  1221 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString());
       
  1222 			iCharSet=ParseCharacterTypeL(iStatus.iOffset);
       
  1223 			iScriptExec->ReadPct();
       
  1224 			}
       
  1225 		iStatus.iOffset=end;
       
  1226 		return ETrue;		// Consumed
       
  1227 		}
       
  1228 	return EFalse;			// Not Consumed
       
  1229 	}
       
  1230 
       
  1231 TBool CReadPCTCommand::CheckReadL()
       
  1232 /**
       
  1233 Checks Read.
       
  1234 */
       
  1235 	{
       
  1236 	EatSpacesAndLinesAndCommentsL();
       
  1237 	TInt end=FindTokenEnd(iStatus.iOffset);
       
  1238 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KReadCommand)==KErrNone)
       
  1239 		return ETrue;
       
  1240 	else
       
  1241 		return EFalse;
       
  1242 	}
       
  1243 
       
  1244 TPtrC CReadPCTCommand::CharSet()
       
  1245 /**
       
  1246 Returns used character set.
       
  1247 */
       
  1248 	{
       
  1249 	return iCharSet;
       
  1250 	}
       
  1251 
       
  1252 //
       
  1253 // CCharMapCommand definitions
       
  1254 //
       
  1255 
       
  1256 CCharMapCommand* CCharMapCommand::NewL(TScriptStatus& aScriptStatus, CScriptReader* aScriptReader, CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
  1257 /**
       
  1258 2 phased constructor for CCharMapCommand, first phase.
       
  1259 
       
  1260 @param aScriptStatus is script status.
       
  1261 @param aScriptReader a pointer to script reader.
       
  1262 @param aVarMan a pointer to variable manager.
       
  1263 @param aCharConv a pointer to script character converter.
       
  1264 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
  1265 @return a new CCharMapCommand object.
       
  1266 */
       
  1267 	{
       
  1268 	CCharMapCommand* c=new(ELeave) CCharMapCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv);
       
  1269 	CleanupStack::PushL(c);
       
  1270 	c->ConstructL();
       
  1271 	CleanupStack::Pop();
       
  1272 	return c;
       
  1273 	}
       
  1274 
       
  1275 CCharMapCommand::CCharMapCommand(TScriptStatus& aScriptStatus, CScriptReader* aScriptReader, CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
  1276 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv)
       
  1277 /**
       
  1278 Constructor for CCharMapCommand, used in the first phase of construction.
       
  1279 
       
  1280 @param aScriptStatus is script status.
       
  1281 @param aScriptReader a pointer to script reader.
       
  1282 @param aVarMan a pointer to variable manager.
       
  1283 @param aCharConv a pointer to script character converter.
       
  1284 */
       
  1285 	{}
       
  1286 
       
  1287 CCharMapCommand::~CCharMapCommand()
       
  1288 /**
       
  1289 Destructor.
       
  1290 */
       
  1291 	{}	
       
  1292 
       
  1293 TBool CCharMapCommand::ParseL()
       
  1294 /**
       
  1295 Parse.
       
  1296 */
       
  1297 	{
       
  1298 	EatSpacesAndLinesAndCommentsL();
       
  1299 	TInt end=FindTokenEnd(iStatus.iOffset);
       
  1300 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KCharmapCommand)==KErrNone)
       
  1301 		{
       
  1302 		iStatus.iOffset=end;
       
  1303 		if (!iStatus.iSkip)
       
  1304 			{
       
  1305 			iCharConv->SetDefaultCharSet(ParseCharacterTypeL(iStatus.iOffset));
       
  1306 			}
       
  1307 		return ETrue;		// Consumed
       
  1308 		}
       
  1309 	return EFalse;			// Not Consumed
       
  1310 	}
       
  1311 
       
  1312 //
       
  1313 // CExitCommand definiton
       
  1314 //
       
  1315 
       
  1316 CExitCommand* CExitCommand::NewL(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
  1317 /**
       
  1318 2 phased constructor for CExitCommand, first phase.
       
  1319 
       
  1320 @param aScriptStatus is script status.
       
  1321 @param aScriptReader a pointer to script reader.
       
  1322 @param aVarMan a pointer to variable manager.
       
  1323 @param aCharConv a pointer to script character converter.
       
  1324 @exception Leaves if ConstructL() leaves, or not enough memory is available.
       
  1325 @return a new CExitCommand object.
       
  1326 */
       
  1327 	{
       
  1328 	CExitCommand* c=new(ELeave) CExitCommand(aScriptStatus,aScriptReader,aVarMan,aCharConv);
       
  1329 	CleanupStack::PushL(c);
       
  1330 	c->ConstructL();
       
  1331 	CleanupStack::Pop();
       
  1332 	return c;
       
  1333 	}
       
  1334 
       
  1335 CExitCommand::CExitCommand(TScriptStatus& aScriptStatus,CScriptReader* aScriptReader,CScriptVarMan* aVarMan,CScriptCharacterConverter* aCharConv)
       
  1336 	: CScriptCommandBase(aScriptStatus,aScriptReader,aVarMan,aCharConv)
       
  1337 /**
       
  1338 Constructor for CExitCommand, used in the first phase of construction.
       
  1339 
       
  1340 @param aScriptStatus is script status.
       
  1341 @param aScriptReader a pointer to script reader.
       
  1342 @param aVarMan a pointer to variable manager.
       
  1343 @param aCharConv a pointer to script character converter.
       
  1344 */
       
  1345 	{}
       
  1346 
       
  1347 CExitCommand::~CExitCommand()
       
  1348 /**
       
  1349 Destructor.
       
  1350 */
       
  1351 	{}
       
  1352 
       
  1353 TBool CExitCommand::ParseL()
       
  1354 /**
       
  1355 Parses EXIT command. Parses number or variable and leaves with the appropriate value.
       
  1356 */
       
  1357 	{
       
  1358 	EatSpacesAndLinesAndCommentsL();
       
  1359 	TInt end=FindTokenEnd(iStatus.iOffset);
       
  1360 	if (iStatus.iLine.Mid(iStatus.iOffset,end-iStatus.iOffset).CompareF(KExitCommand)==KErrNone)
       
  1361 		{
       
  1362 		if (!iStatus.iSkip)
       
  1363 			{
       
  1364 			__FLOG_STMT(_LIT8(logString1,"Script:\tExecuting Exit");)
       
  1365 			__FLOG_STATIC(KNetDialLogFolder(),KNetDialLogFile(),logString1());
       
  1366 			}
       
  1367 		iStatus.iOffset=end;
       
  1368 		EatSpaces(iStatus.iOffset);
       
  1369 		TPtrC exitStatus;
       
  1370 		TRAPD(ret,(exitStatus.Set(ParseCompoundExpressionL(iStatus.iOffset))));
       
  1371 		if (!iStatus.iSkip)
       
  1372 			{
       
  1373 			if (ret==KErrNone)
       
  1374 				{
       
  1375 				TInt32 val;
       
  1376 				TLex lex(exitStatus);
       
  1377 				if(lex.Val(val)!=KErrNone)
       
  1378 					User::Leave(KErrInvalidNumber);
       
  1379 				if(val>0)
       
  1380 					User::Leave(KErrNumberOutOfRange);
       
  1381 				if(val==0)
       
  1382 					val=(TInt32)KErrScriptCompleted;
       
  1383 				User::Leave(val);
       
  1384 				}
       
  1385 			else if (ret==KErrNoExpression)
       
  1386 				User::Leave(KErrScriptCompleted);
       
  1387 			else
       
  1388 				{
       
  1389 				__FLOG_STMT(_LIT8(logString2,"Script:\tExit With Error %d");)
       
  1390 				__FLOG_STATIC1(KNetDialLogFolder(),KNetDialLogFile(),TRefByValue<const TDesC8>(logString2()),ret);
       
  1391 				User::Leave(ret);
       
  1392 				}
       
  1393 			}
       
  1394 		return ETrue;		// Consumed
       
  1395 		}
       
  1396 	return EFalse;			// Not Consumed
       
  1397 	}