| 0 |      1 | // Copyright (c) 1995-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 the License "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 | // f32\sfsrv\cl_parse.cpp
 | 
|  |     15 | // 
 | 
|  |     16 | //
 | 
|  |     17 | 
 | 
|  |     18 | #include "cl_std.h"
 | 
|  |     19 | 
 | 
|  |     20 | const TInt KLexComponents=4;
 | 
|  |     21 | const TInt KLexNames=3;
 | 
|  |     22 | 
 | 
|  |     23 | 
 | 
|  |     24 | 
 | 
|  |     25 | 
 | 
|  |     26 | EXPORT_C TParseBase::TParseBase()
 | 
|  |     27 | 	: iWild(0)
 | 
|  |     28 | /**
 | 
|  |     29 | Default constructor.
 | 
|  |     30 | */
 | 
|  |     31 | 	{
 | 
|  |     32 | 
 | 
|  |     33 | 	Mem::FillZ(&iField[0],sizeof(iField));
 | 
|  |     34 | 	}
 | 
|  |     35 | 
 | 
|  |     36 | 
 | 
|  |     37 | 
 | 
|  |     38 | 
 | 
|  |     39 | TInt TParseBase::ParseDrive(TLex& aName,TBool& aDone)
 | 
|  |     40 | //
 | 
|  |     41 | // Parse the drive name.
 | 
|  |     42 | //
 | 
|  |     43 | 	{
 | 
|  |     44 | 
 | 
|  |     45 | 	TPtrC d=aName.RemainderFromMark();
 | 
|  |     46 | 	if (d.Length()<2 || d[1]!=KDriveDelimiter)
 | 
|  |     47 | 		return(KErrNone);	//must be Drive delimeter and longer that tow to be valid drive
 | 
|  |     48 | 	TCharF c=d[0];
 | 
|  |     49 | 	if (!c.IsAlpha())		//must be alphaber letter 
 | 
|  |     50 | 		return(KErrBadName);
 | 
|  |     51 | 	if (!aDone)
 | 
|  |     52 | 		{
 | 
|  |     53 | 		if(iMod)
 | 
|  |     54 | 			NameBuf()+=d.Left(2);
 | 
|  |     55 | 		aDone=ETrue;
 | 
|  |     56 | 		}
 | 
|  |     57 | 	aName.SkipAndMark(2);
 | 
|  |     58 | 	return(KErrNone);
 | 
|  |     59 | 	}
 | 
|  |     60 | 
 | 
|  |     61 | TInt TParseBase::ParsePath(TLex& aName,TBool& aDone)
 | 
|  |     62 | //
 | 
|  |     63 | // Parse the path.
 | 
|  |     64 | //
 | 
|  |     65 | 	{
 | 
|  |     66 | 
 | 
|  |     67 | 	TPtrC d=aName.RemainderFromMark();
 | 
|  |     68 | 	if (d.Length() && d[0]!=KPathDelimiter)
 | 
|  |     69 | 		return(KErrNone); // Require first char of path to be a '\'
 | 
|  |     70 | 	TInt n=d.LocateReverse(KPathDelimiter)+1;
 | 
|  |     71 | 	if (n && !aDone)
 | 
|  |     72 | 		{
 | 
|  |     73 | 		if(iMod)
 | 
|  |     74 | 			{
 | 
|  |     75 | 			if (NameBuf().Length()+n>KMaxFileName)
 | 
|  |     76 | 				return(KErrBadName);
 | 
|  |     77 | 			NameBuf()+=d.Left(n);
 | 
|  |     78 | 			}
 | 
|  |     79 | 		aDone=ETrue;
 | 
|  |     80 | 		}
 | 
|  |     81 | 	aName.SkipAndMark(n);
 | 
|  |     82 | 	return(KErrNone);
 | 
|  |     83 | 	}
 | 
|  |     84 | 
 | 
|  |     85 | LOCAL_C TBool IsSpace(const TDesC& aDes)
 | 
|  |     86 | //
 | 
|  |     87 | // Returns ETrue if aDes only contains spaces or is zero length
 | 
|  |     88 | //
 | 
|  |     89 | 	{
 | 
|  |     90 | 
 | 
|  |     91 | 	TInt len=aDes.Length();
 | 
|  |     92 | 	for (TInt i=0;i<len;i++)
 | 
|  |     93 | 		{
 | 
|  |     94 | 		TChar txt=aDes[i];
 | 
|  |     95 | 		if (!txt.IsSpace())
 | 
|  |     96 | 			return(EFalse);
 | 
|  |     97 | 		}
 | 
|  |     98 | 	return(ETrue);
 | 
|  |     99 | 	}
 | 
|  |    100 | 
 | 
|  |    101 | TInt TParseBase::ParseName(TLex& aName,TBool& aDone)
 | 
|  |    102 | //
 | 
|  |    103 | // Parse the name.
 | 
|  |    104 | //
 | 
|  |    105 | 	{
 | 
|  |    106 | 
 | 
|  |    107 | 	TPtrC d=aName.RemainderFromMark();
 | 
|  |    108 | 	if (d.Locate(KPathDelimiter)!=KErrNotFound)
 | 
|  |    109 | 		return(KErrBadName); // Illegal name - filenames cannot contain a '\'
 | 
|  |    110 | 	TInt n=d.LocateReverse(KExtDelimiter);
 | 
|  |    111 | 	if (n==KErrNotFound)
 | 
|  |    112 | 		{
 | 
|  |    113 | 		n=d.Length();
 | 
|  |    114 | 		if (IsSpace(d.Left(n)))
 | 
|  |    115 | 			return(KErrNone);
 | 
|  |    116 | 		}
 | 
|  |    117 | 	TPtrC v=d.Left(n);
 | 
|  |    118 | 	if (n && !aDone)
 | 
|  |    119 | 		{
 | 
|  |    120 | 		if (v.Locate(KMatchOne)!=KErrNotFound)	//	Found ? in the name
 | 
|  |    121 | 			iWild|=(EWildName|EWildEither|EWildIsKMatchOne);		
 | 
|  |    122 | 		if (v.Locate(KMatchAny)!=KErrNotFound)	//	Found * in the name
 | 
|  |    123 | 			iWild|=(EWildName|EWildEither|EWildIsKMatchAny);		
 | 
|  |    124 | 		if(iMod)
 | 
|  |    125 | 			{
 | 
|  |    126 | 			if (NameBuf().Length()+n>KMaxFileName)	
 | 
|  |    127 | 				return(KErrBadName);
 | 
|  |    128 | 			NameBuf()+=v;
 | 
|  |    129 | 			if (n==d.Length())
 | 
|  |    130 | 				NameBuf().TrimRight();
 | 
|  |    131 | 			}
 | 
|  |    132 | 		aDone=ETrue;
 | 
|  |    133 | 		}
 | 
|  |    134 | 	aName.SkipAndMark(n);
 | 
|  |    135 | 	return(KErrNone);
 | 
|  |    136 | 	}
 | 
|  |    137 | 
 | 
|  |    138 | TInt TParseBase::ParseExt(TLex& aName,TBool& aDone)
 | 
|  |    139 | //
 | 
|  |    140 | // Parse the extension.
 | 
|  |    141 | //
 | 
|  |    142 | 	{
 | 
|  |    143 | 
 | 
|  |    144 | 	TPtrC d=aName.RemainderFromMark();
 | 
|  |    145 | 	if (d.Length() && !IsSpace(d) && !aDone)
 | 
|  |    146 | 		{
 | 
|  |    147 | 		if (d.Locate(KMatchOne)!=KErrNotFound) //	Found ? in the name
 | 
|  |    148 | 			iWild|=(EWildExt|EWildEither|EWildIsKMatchOne);
 | 
|  |    149 | 		if (d.Locate(KMatchAny)!=KErrNotFound) //	Found * in the name
 | 
|  |    150 | 			iWild|=(EWildExt|EWildEither|EWildIsKMatchAny);
 | 
|  |    151 | 		
 | 
|  |    152 | 		if(iMod)
 | 
|  |    153 | 			{
 | 
|  |    154 | 			if (NameBuf().Length()+d.Length()>KMaxFileName)
 | 
|  |    155 | 				return(KErrBadName);
 | 
|  |    156 | 			NameBuf()+=d;
 | 
|  |    157 | 			NameBuf().TrimRight();
 | 
|  |    158 | 			}
 | 
|  |    159 | 		else
 | 
|  |    160 | 			aName.SkipAndMark(d.Length());
 | 
|  |    161 | 		aDone=ETrue;
 | 
|  |    162 | 		}
 | 
|  |    163 | 	return(KErrNone);
 | 
|  |    164 | 	}
 | 
|  |    165 | 
 | 
|  |    166 | TInt TParseBase::Set(const TDesC* aName,const TDesC* aRelated,const TDesC* aDefault,TBool allowWild)
 | 
|  |    167 | //
 | 
|  |    168 | // Parse a name. Optionally allow wild cards.
 | 
|  |    169 | //
 | 
|  |    170 | 	{
 | 
|  |    171 | 
 | 
|  |    172 | 	TInt (TParseBase::*parse[KLexComponents])(TLex& aName,TBool& aDone);
 | 
|  |    173 | 	parse[0]=&TParseBase::ParseDrive;
 | 
|  |    174 | 	parse[1]=&TParseBase::ParsePath;
 | 
|  |    175 | 	parse[2]=&TParseBase::ParseName;
 | 
|  |    176 | 	parse[3]=&TParseBase::ParseExt;
 | 
|  |    177 | 	
 | 
|  |    178 | 	iWild=0;
 | 
|  |    179 | 
 | 
|  |    180 | 	Mem::FillZ(&iField[0],sizeof(iField));
 | 
|  |    181 | 	
 | 
|  |    182 | 	TLex name(*aName);
 | 
|  |    183 | 	TLex def;
 | 
|  |    184 | 	TLex rel;
 | 
|  |    185 | 	TInt lexnames;
 | 
|  |    186 | 	if(iMod)
 | 
|  |    187 | 		{
 | 
|  |    188 | 		if (aRelated)
 | 
|  |    189 | 			rel=(*aRelated);
 | 
|  |    190 | 		if (aDefault)
 | 
|  |    191 | 			def=(*aDefault);
 | 
|  |    192 | 		NameBuf().Zero();
 | 
|  |    193 | 		lexnames = KLexNames;
 | 
|  |    194 | 		}
 | 
|  |    195 | 	else
 | 
|  |    196 | 		{
 | 
|  |    197 | 		lexnames = 1;
 | 
|  |    198 | 		}
 | 
|  |    199 | 	
 | 
|  |    200 | 	TLex* lex[KLexNames];
 | 
|  |    201 | 	lex[0]=(&name);
 | 
|  |    202 | 	lex[1]=(&rel);
 | 
|  |    203 | 	lex[2]=(&def);
 | 
|  |    204 | 	
 | 
|  |    205 | 	name.Mark();
 | 
|  |    206 | 	rel.Mark();
 | 
|  |    207 | 	def.Mark();
 | 
|  |    208 | 	
 | 
|  |    209 | 	TInt r;
 | 
|  |    210 | 	TInt pos=0;
 | 
|  |    211 | 	
 | 
|  |    212 | 	for (TInt i=0;i<KLexComponents;i++)
 | 
|  |    213 | 		{
 | 
|  |    214 | 		TBool done=EFalse;
 | 
|  |    215 | 		for (TInt j=0;j<lexnames;j++)
 | 
|  |    216 | 			{
 | 
|  |    217 | 			if ((r=(this->*parse[i])(*lex[j],done))<KErrNone)
 | 
|  |    218 | 				return(r);
 | 
|  |    219 | 			if (j==0 && done)
 | 
|  |    220 | 				iField[i].present=ETrue;
 | 
|  |    221 | 			}
 | 
|  |    222 | 		TInt len;
 | 
|  |    223 | 		if(iMod)
 | 
|  |    224 | 			len=NameBuf().Length()-pos;
 | 
|  |    225 | 		else
 | 
|  |    226 | 			len=name.MarkedOffset()-pos;
 | 
|  |    227 | 		iField[i].len=(TUint8)len;
 | 
|  |    228 | 		iField[i].pos=(TUint8)pos;
 | 
|  |    229 | 		pos+=len;
 | 
|  |    230 | 		}
 | 
|  |    231 | 	if (!allowWild && iWild)
 | 
|  |    232 | 		return(KErrBadName);
 | 
|  |    233 | 	if (iField[EPath].len==1)
 | 
|  |    234 | 		iWild|=EIsRoot;
 | 
|  |    235 | 	return(KErrNone);
 | 
|  |    236 | 	}
 | 
|  |    237 | 
 | 
|  |    238 | 
 | 
|  |    239 | 
 | 
|  |    240 | 
 | 
|  |    241 | EXPORT_C TInt TParseBase::PopDir()
 | 
|  |    242 | /**
 | 
|  |    243 | Removes the last directory from the path in the fully parsed specification.
 | 
|  |    244 |  
 | 
|  |    245 | This function may be used to navigate up one level in a directory hierarchy.
 | 
|  |    246 | An error is returned if the specified directory is the root.
 | 
|  |    247 | 
 | 
|  |    248 | @return KErrNone if successful, otherwise one of the other system-wide error 
 | 
|  |    249 |         codes.
 | 
|  |    250 | */
 | 
|  |    251 | 	{
 | 
|  |    252 | 
 | 
|  |    253 | 	if (IsRoot())
 | 
|  |    254 | 		return(KErrGeneral);
 | 
|  |    255 | 	TInt len;
 | 
|  |    256 | 	if (iField[EName].pos==0 && NameBuf().Length()==256)
 | 
|  |    257 | 		len=256;
 | 
|  |    258 | 	else
 | 
|  |    259 | 		len=iField[EName].pos;
 | 
|  |    260 | 	TPtrC p(NameBuf().Ptr(),len-1);
 | 
|  |    261 | 	TInt pos=p.LocateReverse(KPathDelimiter)+1;
 | 
|  |    262 | 	len-=pos;
 | 
|  |    263 | 	NameBuf().Delete(pos,len);
 | 
|  |    264 | 	iField[EName].pos=(TUint8)(iField[EName].pos-len);
 | 
|  |    265 | 	iField[EExt].pos=(TUint8)(iField[EExt].pos-len);
 | 
|  |    266 | 	iField[EPath].len=(TUint8)(iField[EPath].len-len);
 | 
|  |    267 | 	if (iField[EPath].len==1)
 | 
|  |    268 | 		iWild|=EIsRoot;
 | 
|  |    269 | 	return(KErrNone);
 | 
|  |    270 | 	}
 | 
|  |    271 | 
 | 
|  |    272 | 
 | 
|  |    273 | 
 | 
|  |    274 | 
 | 
|  |    275 | EXPORT_C TInt TParseBase::AddDir(const TDesC& aName)
 | 
|  |    276 | /**
 | 
|  |    277 | Adds a single directory onto the end of the path in
 | 
|  |    278 | the fully parsed specification. 
 | 
|  |    279 | 
 | 
|  |    280 | The directory is inserted between the final directory, and the filename, if 
 | 
|  |    281 | there is one.
 | 
|  |    282 | 
 | 
|  |    283 | @param aName The directory to be added. It must not start with a \\ otherwise 
 | 
|  |    284 |              the function does not recognise it as a valid directory name
 | 
|  |    285 |              and an error is returned.
 | 
|  |    286 |              The directory name must not end with a \\ since the function 
 | 
|  |    287 |              adds this automatically. It must not exceed the maximum
 | 
|  |    288 |              filename length, KMaxFileName characters, otherwise  an error
 | 
|  |    289 |              is returned.
 | 
|  |    290 | 
 | 
|  |    291 | @return KErrNone if successful, otherwise another of the system-wide error 
 | 
|  |    292 |         codes.   
 | 
|  |    293 | @see KMaxFileName
 | 
|  |    294 | */
 | 
|  |    295 | 	{
 | 
|  |    296 | 
 | 
|  |    297 | 	if (aName.Length()==0)
 | 
|  |    298 | 		return(KErrNone);
 | 
|  |    299 | 	TInt len=aName.Length()+1;
 | 
|  |    300 | 	if ((len+NameBuf().Length())>NameBuf().MaxLength())
 | 
|  |    301 | 		return(KErrGeneral);
 | 
|  |    302 | 	TInt pos=aName.Locate(KPathDelimiter);
 | 
|  |    303 | 	if (pos!=KErrNotFound)
 | 
|  |    304 | 		return(KErrBadName);
 | 
|  |    305 | 	TFileName n=aName;
 | 
|  |    306 | 	n.Append(KPathDelimiter);
 | 
|  |    307 | 	NameBuf().Insert(iField[EName].pos,n);
 | 
|  |    308 | 	iField[EPath].len=(TUint8)(iField[EPath].len+len);
 | 
|  |    309 | 	iField[EName].pos=(TUint8)(iField[EName].pos+len);
 | 
|  |    310 | 	iField[EExt].pos=(TUint8)(len+iField[EExt].pos);
 | 
|  |    311 | 	if (IsRoot())
 | 
|  |    312 | 		iWild&=~EIsRoot;
 | 
|  |    313 | 	return(KErrNone);
 | 
|  |    314 | 	}
 | 
|  |    315 | 
 | 
|  |    316 | 
 | 
|  |    317 | 
 | 
|  |    318 | 
 | 
|  |    319 | EXPORT_C const TDesC& TParseBase::FullName() const
 | 
|  |    320 | /**
 | 
|  |    321 | Gets the complete file specification.
 | 
|  |    322 | 
 | 
|  |    323 | This is in the form:
 | 
|  |    324 | 
 | 
|  |    325 | drive-letter: \\path\\filename.extension
 | 
|  |    326 | 
 | 
|  |    327 | @return The fully parsed file specification.
 | 
|  |    328 | */
 | 
|  |    329 | 	{
 | 
|  |    330 | 
 | 
|  |    331 | 	return(NameBufC());
 | 
|  |    332 | 	}
 | 
|  |    333 | 
 | 
|  |    334 | 
 | 
|  |    335 | 
 | 
|  |    336 | 
 | 
|  |    337 | EXPORT_C TPtrC TParseBase::Drive() const
 | 
|  |    338 | /**
 | 
|  |    339 | Gets the drive letter.
 | 
|  |    340 | 
 | 
|  |    341 | The drive letter is in the form:
 | 
|  |    342 | 
 | 
|  |    343 | drive-letter:
 | 
|  |    344 | 
 | 
|  |    345 | Note that the drive letter is folded.
 | 
|  |    346 | 
 | 
|  |    347 | @return The drive letter and colon.
 | 
|  |    348 | */
 | 
|  |    349 | 	{
 | 
|  |    350 | 
 | 
|  |    351 | 	const SField& f=iField[EDrive];
 | 
|  |    352 | 	return(NameBufC().Mid(f.pos,f.len));
 | 
|  |    353 | 	}
 | 
|  |    354 | 
 | 
|  |    355 | 
 | 
|  |    356 | 
 | 
|  |    357 | 
 | 
|  |    358 | EXPORT_C TPtrC TParseBase::Path() const
 | 
|  |    359 | /**
 | 
|  |    360 | Gets the path.
 | 
|  |    361 | 
 | 
|  |    362 | The path is in the form:
 | 
|  |    363 | 
 | 
|  |    364 | \\path\\
 | 
|  |    365 | 
 | 
|  |    366 | @return The path. It always begins and ends in a backslash.
 | 
|  |    367 | */
 | 
|  |    368 | 	{
 | 
|  |    369 | 
 | 
|  |    370 | 	const SField& f=iField[EPath];
 | 
|  |    371 | 	return(NameBufC().Mid(f.pos,f.len));
 | 
|  |    372 | 	}
 | 
|  |    373 | 
 | 
|  |    374 | 
 | 
|  |    375 | 
 | 
|  |    376 | 
 | 
|  |    377 | EXPORT_C TPtrC TParseBase::DriveAndPath() const
 | 
|  |    378 | /**
 | 
|  |    379 | Gets the drive letter and path.
 | 
|  |    380 | 
 | 
|  |    381 | This is in the form
 | 
|  |    382 | 
 | 
|  |    383 | drive-letter:\\path\\
 | 
|  |    384 | 
 | 
|  |    385 | Note that the drive letter is folded
 | 
|  |    386 | 
 | 
|  |    387 | @return The drive and path.
 | 
|  |    388 | */
 | 
|  |    389 | 	{
 | 
|  |    390 | 
 | 
|  |    391 | 	const SField& f=iField[EDrive];
 | 
|  |    392 | 	return(NameBufC().Mid(f.pos,f.len+iField[EPath].len));
 | 
|  |    393 | 	}
 | 
|  |    394 | 
 | 
|  |    395 | 
 | 
|  |    396 | 
 | 
|  |    397 | 
 | 
|  |    398 | EXPORT_C TPtrC TParseBase::Name() const
 | 
|  |    399 | /**
 | 
|  |    400 | Gets the filename.
 | 
|  |    401 | 
 | 
|  |    402 | This is in the form
 | 
|  |    403 | 
 | 
|  |    404 | filename
 | 
|  |    405 | 
 | 
|  |    406 | @return The filename.
 | 
|  |    407 | */
 | 
|  |    408 | 	{
 | 
|  |    409 | 
 | 
|  |    410 | 	const SField& f=iField[EName];
 | 
|  |    411 | 	return(NameBufC().Mid(f.pos,f.len));
 | 
|  |    412 | 	}
 | 
|  |    413 | 
 | 
|  |    414 | 
 | 
|  |    415 | 
 | 
|  |    416 | 
 | 
|  |    417 | EXPORT_C TPtrC TParseBase::Ext() const
 | 
|  |    418 | /**
 | 
|  |    419 | Gets the extension.
 | 
|  |    420 | 
 | 
|  |    421 | This is in the form:
 | 
|  |    422 | 
 | 
|  |    423 | .extension
 | 
|  |    424 | 
 | 
|  |    425 | @return The extension and preceding dot.
 | 
|  |    426 | */
 | 
|  |    427 | 	{
 | 
|  |    428 | 
 | 
|  |    429 | 	const SField& f=iField[EExt];
 | 
|  |    430 | 	return(NameBufC().Mid(f.pos,f.len));
 | 
|  |    431 | 	}
 | 
|  |    432 | 
 | 
|  |    433 | 
 | 
|  |    434 | 
 | 
|  |    435 | 
 | 
|  |    436 | EXPORT_C TPtrC TParseBase::NameAndExt() const
 | 
|  |    437 | /**
 | 
|  |    438 | Gets the filename and extension.
 | 
|  |    439 | 
 | 
|  |    440 | This is in the form:
 | 
|  |    441 | 
 | 
|  |    442 | filename.ext
 | 
|  |    443 | 
 | 
|  |    444 | @return The filename and extension.
 | 
|  |    445 | */
 | 
|  |    446 | 	{
 | 
|  |    447 | 
 | 
|  |    448 | 	const SField& f=iField[EName];
 | 
|  |    449 | 	return(NameBufC().Mid(f.pos,f.len+iField[EExt].len));
 | 
|  |    450 | 	}
 | 
|  |    451 | 
 | 
|  |    452 | 
 | 
|  |    453 | 
 | 
|  |    454 | 
 | 
|  |    455 | EXPORT_C TBool TParseBase::DrivePresent() const
 | 
|  |    456 | /**
 | 
|  |    457 | Tests whether a drive is present.
 | 
|  |    458 | 
 | 
|  |    459 | Note that this function refers to a component 
 | 
|  |    460 | in the aName argument specified in calls to TParse::Set(), TParse::SetNoWild() 
 | 
|  |    461 | or RFs::Parse(), not to the resulting fully parsed file specification.
 | 
|  |    462 | 
 | 
|  |    463 | @return True if a drive present, false if not.
 | 
|  |    464 | 
 | 
|  |    465 | @see TParse
 | 
|  |    466 | @see RFs
 | 
|  |    467 | */
 | 
|  |    468 | 	{
 | 
|  |    469 | 
 | 
|  |    470 | 	return(iField[EDrive].present);
 | 
|  |    471 | 	}
 | 
|  |    472 | 
 | 
|  |    473 | 
 | 
|  |    474 | 
 | 
|  |    475 | 
 | 
|  |    476 | EXPORT_C TBool TParseBase::PathPresent() const
 | 
|  |    477 | /**
 | 
|  |    478 | Tests whether a path is present.
 | 
|  |    479 | 
 | 
|  |    480 | Note that this function refers to a component 
 | 
|  |    481 | in the aName argument specified in calls to TParse::Set(), TParse::SetNoWild() 
 | 
|  |    482 | or RFs::Parse(), not to the resulting fully parsed file specification.
 | 
|  |    483 | 
 | 
|  |    484 | @return True if a path present, false if not.
 | 
|  |    485 | 
 | 
|  |    486 | @see TParse
 | 
|  |    487 | @see RFs
 | 
|  |    488 | */
 | 
|  |    489 | 	{
 | 
|  |    490 | 
 | 
|  |    491 | 	return(iField[EPath].present);
 | 
|  |    492 | 	}
 | 
|  |    493 | 
 | 
|  |    494 | 
 | 
|  |    495 | 
 | 
|  |    496 | 
 | 
|  |    497 | EXPORT_C TBool TParseBase::NamePresent() const
 | 
|  |    498 | /**
 | 
|  |    499 | Tests whether a file name is present.
 | 
|  |    500 | 
 | 
|  |    501 | Note that this function refers to a component 
 | 
|  |    502 | in the aName argument specified in calls to TParse::Set(), TParse::SetNoWild() 
 | 
|  |    503 | or RFs::Parse(), not to the resulting fully parsed file specification.
 | 
|  |    504 | 
 | 
|  |    505 | This function returns true even if the filename specified in aName contains 
 | 
|  |    506 | only wildcards. It only returns false if nothing is specified.
 | 
|  |    507 | 
 | 
|  |    508 | @return True if a name present, false if not.
 | 
|  |    509 | */
 | 
|  |    510 | 	{
 | 
|  |    511 | 
 | 
|  |    512 | 	return(iField[EName].present);
 | 
|  |    513 | 	}
 | 
|  |    514 | 
 | 
|  |    515 | 
 | 
|  |    516 | 
 | 
|  |    517 | 
 | 
|  |    518 | EXPORT_C TBool TParseBase::ExtPresent() const
 | 
|  |    519 | /**
 | 
|  |    520 | Tests whether an extension is present.
 | 
|  |    521 | 
 | 
|  |    522 | Note that this function refers to a component
 | 
|  |    523 | in the aName argument specified in calls to TParse::Set(), TParse::SetNoWild() 
 | 
|  |    524 | or RFs::Parse(), not to the resulting fully parsed file specification.
 | 
|  |    525 | 
 | 
|  |    526 | This function returns true even if the extension contains only wildcards. 
 | 
|  |    527 | It only returns false if nothing is specified.
 | 
|  |    528 | 
 | 
|  |    529 | @return True if an extension present, false if not.
 | 
|  |    530 | */
 | 
|  |    531 | 	{
 | 
|  |    532 | 
 | 
|  |    533 | 	return(iField[EExt].present);
 | 
|  |    534 | 	}
 | 
|  |    535 | 
 | 
|  |    536 | 
 | 
|  |    537 | 
 | 
|  |    538 | 
 | 
|  |    539 | EXPORT_C TBool TParseBase::NameOrExtPresent() const
 | 
|  |    540 | /**
 | 
|  |    541 | Tests whether a filename or an extension are present.
 | 
|  |    542 | 
 | 
|  |    543 | Note that this function refers to a component in the aName argument
 | 
|  |    544 | specified in calls to TParse::Set(), TParse::SetNoWild() or RFs::Parse(), not
 | 
|  |    545 | to the resulting fully parsed file specification.
 | 
|  |    546 | 
 | 
|  |    547 | This function returns true even if the filename or extension specified in 
 | 
|  |    548 | aName contain only wildcards. It only returns false if nothing is specified.
 | 
|  |    549 | 
 | 
|  |    550 | @return True if either a name or an extension or both are present,
 | 
|  |    551 |         otherwise false.
 | 
|  |    552 | */
 | 
|  |    553 | 	{
 | 
|  |    554 | 
 | 
|  |    555 | 	return(iField[EName].present || iField[EExt].present);
 | 
|  |    556 | 	}
 | 
|  |    557 | 
 | 
|  |    558 | 
 | 
|  |    559 | 
 | 
|  |    560 | 
 | 
|  |    561 | 
 | 
|  |    562 | EXPORT_C TBool TParseBase::IsRoot() const
 | 
|  |    563 | /**
 | 
|  |    564 | Tests whether the path in the fully parsed specification is the root directory.
 | 
|  |    565 | 
 | 
|  |    566 | @return True if path is root, false if not.
 | 
|  |    567 | */
 | 
|  |    568 | 	{
 | 
|  |    569 | 
 | 
|  |    570 | 	return(iWild&EIsRoot);
 | 
|  |    571 | 	}
 | 
|  |    572 | 
 | 
|  |    573 | 
 | 
|  |    574 | 
 | 
|  |    575 | 
 | 
|  |    576 | EXPORT_C TBool TParseBase::IsWild() const
 | 
|  |    577 | /**
 | 
|  |    578 | Tests whether the filename or the extension in the fully parsed specification 
 | 
|  |    579 | contains one or more wildcard characters.
 | 
|  |    580 | 
 | 
|  |    581 | @return True if wildcards are present, false if not.
 | 
|  |    582 | */
 | 
|  |    583 | 	{
 | 
|  |    584 | 
 | 
|  |    585 | 	return(iWild&EWildEither);	
 | 
|  |    586 | 	}
 | 
|  |    587 | 
 | 
|  |    588 | 
 | 
|  |    589 | 
 | 
|  |    590 | 
 | 
|  |    591 | EXPORT_C TBool TParseBase::IsKMatchOne() const
 | 
|  |    592 | /**
 | 
|  |    593 | Tests whether the name or the extension contains a question mark wildcard.
 | 
|  |    594 | 
 | 
|  |    595 | @return True if either the name or extension has a ? wild card,
 | 
|  |    596 |         false otherwise.
 | 
|  |    597 | */
 | 
|  |    598 | 	{
 | 
|  |    599 | 
 | 
|  |    600 | 	return(iWild&EWildIsKMatchOne);	
 | 
|  |    601 | 	}
 | 
|  |    602 | 
 | 
|  |    603 | 
 | 
|  |    604 | 
 | 
|  |    605 | 
 | 
|  |    606 | EXPORT_C TBool TParseBase::IsKMatchAny() const
 | 
|  |    607 | /**
 | 
|  |    608 | Tests whether the name or the extension contains asterisk wildcards.
 | 
|  |    609 | 
 | 
|  |    610 | @return True if either the name or extension has a * wild card,
 | 
|  |    611 |         false otherwise.
 | 
|  |    612 | */
 | 
|  |    613 | 	{
 | 
|  |    614 | 
 | 
|  |    615 | 	return(iWild&EWildIsKMatchAny);	
 | 
|  |    616 | 	}
 | 
|  |    617 | 
 | 
|  |    618 | 
 | 
|  |    619 | 
 | 
|  |    620 | 
 | 
|  |    621 | EXPORT_C TBool TParseBase::IsNameWild() const
 | 
|  |    622 | /**
 | 
|  |    623 | Tests whether the filename in the fully parsed specification contains one or 
 | 
|  |    624 | more wildcard characters.
 | 
|  |    625 | 
 | 
|  |    626 | @return True if the filename contains wildcard characters, false if not.
 | 
|  |    627 | */
 | 
|  |    628 | 	{
 | 
|  |    629 | 
 | 
|  |    630 | 	return(iWild&EWildName);
 | 
|  |    631 | 	}
 | 
|  |    632 | 
 | 
|  |    633 | 
 | 
|  |    634 | 
 | 
|  |    635 | 
 | 
|  |    636 | EXPORT_C TBool TParseBase::IsExtWild() const
 | 
|  |    637 | /**
 | 
|  |    638 | Tests whether the extension in the fully parsed specification contains one 
 | 
|  |    639 | or more wildcard characters.
 | 
|  |    640 | 
 | 
|  |    641 | @return True if the extension contains wildcard characters, false if not.
 | 
|  |    642 | */
 | 
|  |    643 | 	{
 | 
|  |    644 | 
 | 
|  |    645 | 	return(iWild&EWildExt);
 | 
|  |    646 | 	}
 | 
|  |    647 | 
 | 
|  |    648 | 
 | 
|  |    649 | 
 | 
|  |    650 | 
 | 
|  |    651 | EXPORT_C TParse::TParse()
 | 
|  |    652 | /**
 | 
|  |    653 | Default constructor.
 | 
|  |    654 | */
 | 
|  |    655 | 	{
 | 
|  |    656 | 	iMod=1;
 | 
|  |    657 | 	}
 | 
|  |    658 | 
 | 
|  |    659 | 
 | 
|  |    660 | 
 | 
|  |    661 | 
 | 
|  |    662 | EXPORT_C TInt TParse::Set(const TDesC& aName,const TDesC* aRelated,const TDesC* aDefault)
 | 
|  |    663 | /**
 | 
|  |    664 | Parses a file specification, allowing wildcards in the filename and extension.
 | 
|  |    665 | 
 | 
|  |    666 | This function sets up the TParse object so that it can be used to provide 
 | 
|  |    667 | useful information.
 | 
|  |    668 | 
 | 
|  |    669 | @param aName    The file specification to be parsed.
 | 
|  |    670 | @param aRelated The related file specification. This is optional,
 | 
|  |    671 |                 set to NULL to  omit.
 | 
|  |    672 | @param aDefault The default file specification. This is optional,
 | 
|  |    673 |                 set to NULL to omit.
 | 
|  |    674 |                 
 | 
|  |    675 | @return KErrNone, if successful, otherwise one of the other system-wide error
 | 
|  |    676 |         codes.
 | 
|  |    677 | */
 | 
|  |    678 | 	{
 | 
|  |    679 | 
 | 
|  |    680 | 	return(TParseBase::Set(&aName,aRelated,aDefault,ETrue));
 | 
|  |    681 | 	}
 | 
|  |    682 | 
 | 
|  |    683 | 
 | 
|  |    684 | 
 | 
|  |    685 | 
 | 
|  |    686 | EXPORT_C TInt TParse::SetNoWild(const TDesC& aName,const TDesC* aRelated,const TDesC* aDefault)
 | 
|  |    687 | /**
 | 
|  |    688 | Parses a file specification; disallows wildcards in any part of the file name 
 | 
|  |    689 | or extension.
 | 
|  |    690 | 
 | 
|  |    691 | If you need to specify wildcards use Set(). Otherwise, this 
 | 
|  |    692 | function behaves in the same way as Set().
 | 
|  |    693 | 
 | 
|  |    694 | @param aName    The file specification to be parsed.
 | 
|  |    695 | @param aRelated The related file specification. This is optional,
 | 
|  |    696 |                 set to NULL to omit.
 | 
|  |    697 | @param aDefault The default file specification. This is optional,
 | 
|  |    698 |                 set to NULL to omit.
 | 
|  |    699 |                 
 | 
|  |    700 | @return KErrNone, if successful, otherwise one of the other system-wide error 
 | 
|  |    701 |         codes.
 | 
|  |    702 | 
 | 
|  |    703 | @see TParse::Set
 | 
|  |    704 | */
 | 
|  |    705 | 	{
 | 
|  |    706 | 
 | 
|  |    707 | 	return(TParseBase::Set(&aName,aRelated,aDefault,EFalse));
 | 
|  |    708 | 	}
 | 
|  |    709 | 
 | 
|  |    710 | 
 | 
|  |    711 | 
 | 
|  |    712 | 
 | 
|  |    713 | EXPORT_C TDes& TParse::NameBuf()
 | 
|  |    714 | /**
 | 
|  |    715 | Gets a reference to the descriptor containing the file specification passed to
 | 
|  |    716 | the constructor of this object. 
 | 
|  |    717 | 
 | 
|  |    718 | @return A reference to the descriptor containing the filename.
 | 
|  |    719 | */
 | 
|  |    720 | 	{
 | 
|  |    721 | 
 | 
|  |    722 | 	return(iNameBuf);
 | 
|  |    723 | 	}
 | 
|  |    724 | 
 | 
|  |    725 | 
 | 
|  |    726 | 
 | 
|  |    727 | 
 | 
|  |    728 | EXPORT_C const TDesC& TParse::NameBufC() const
 | 
|  |    729 | /**
 | 
|  |    730 | Gets a const reference to the descriptor containing the file specification
 | 
|  |    731 | passed to the constructor of this object. 
 | 
|  |    732 | 
 | 
|  |    733 | @return A const reference to the descriptor containing the file specification.
 | 
|  |    734 | */
 | 
|  |    735 | 	{
 | 
|  |    736 | 
 | 
|  |    737 | 	return(iNameBuf);
 | 
|  |    738 | 	}
 | 
|  |    739 | 
 | 
|  |    740 | 
 | 
|  |    741 | 
 | 
|  |    742 | 
 | 
|  |    743 | EXPORT_C TParsePtr::TParsePtr(TDes& aName)
 | 
|  |    744 | 	: iNameBuf((TText*)aName.Ptr(),aName.Length(),aName.MaxLength())
 | 
|  |    745 | /**
 | 
|  |    746 | Constructor taking a reference to a filename.
 | 
|  |    747 | 
 | 
|  |    748 | The specified filename is parsed and if this fails, a panic is raised.
 | 
|  |    749 | 
 | 
|  |    750 | @param aName Reference to the filename to be parsed. On return contains
 | 
|  |    751 |              the fully parsed path specification. If a filename and extension
 | 
|  |    752 |              are specified, they may both contain wildcards.
 | 
|  |    753 |              The maximum length is KMaxFileName characters.
 | 
|  |    754 |              
 | 
|  |    755 | @panic FSCLIENT 24 if the the specified name fails to parse.
 | 
|  |    756 |              
 | 
|  |    757 | @see KMaxFileName
 | 
|  |    758 | */
 | 
|  |    759 | 	{
 | 
|  |    760 | 	iMod=1;
 | 
|  |    761 | 	TInt r=TParseBase::Set(&aName,NULL,NULL,ETrue);
 | 
|  |    762 | 	__ASSERT_ALWAYS(r==KErrNone,Panic(EParsePtrBadDescriptor0));
 | 
|  |    763 | 	}
 | 
|  |    764 | 
 | 
|  |    765 | 
 | 
|  |    766 | 
 | 
|  |    767 | 
 | 
|  |    768 | EXPORT_C TDes& TParsePtr::NameBuf()
 | 
|  |    769 | /**
 | 
|  |    770 | Gets a reference to the descriptor containing the filename passed to
 | 
|  |    771 | the constructor of this object. 
 | 
|  |    772 | 
 | 
|  |    773 | @return A reference to the descriptor containing the filename.
 | 
|  |    774 | */
 | 
|  |    775 | 	{
 | 
|  |    776 | 
 | 
|  |    777 | 	return(iNameBuf);
 | 
|  |    778 | 	}
 | 
|  |    779 | 
 | 
|  |    780 | 
 | 
|  |    781 | 
 | 
|  |    782 | 
 | 
|  |    783 | EXPORT_C const TDesC& TParsePtr::NameBufC() const
 | 
|  |    784 | /**
 | 
|  |    785 | Gets a const reference to the descriptor containing the filename passed to
 | 
|  |    786 | the constructor of this object. 
 | 
|  |    787 | 
 | 
|  |    788 | @return A const reference to the descriptor containing the filename.
 | 
|  |    789 | */
 | 
|  |    790 | 	{
 | 
|  |    791 | 
 | 
|  |    792 | 	return(iNameBuf);
 | 
|  |    793 | 	}
 | 
|  |    794 | 
 | 
|  |    795 | 
 | 
|  |    796 | 
 | 
|  |    797 | 
 | 
|  |    798 | EXPORT_C TParsePtrC::TParsePtrC(const TDesC& aName)
 | 
|  |    799 | /**
 | 
|  |    800 | Constructor taking a constant reference to a filename.
 | 
|  |    801 | 
 | 
|  |    802 | The filename is parsed and if this fails, a panic is raised.
 | 
|  |    803 | Note that the filename cannot be modified using this class.
 | 
|  |    804 | 
 | 
|  |    805 | @param aName Constant reference to the filename to be parsed.
 | 
|  |    806 |              On return contains the fully parsed filename.
 | 
|  |    807 |              If a file and extension are specified, they may both
 | 
|  |    808 |              contain wildcards.
 | 
|  |    809 |              The maximum length is KMaxFileName characters.
 | 
|  |    810 |              
 | 
|  |    811 | @panic FSCLIENT 24 if the the specified name fails to parse.
 | 
|  |    812 | 
 | 
|  |    813 | @see KMaxFileName
 | 
|  |    814 | */
 | 
|  |    815 | 	{
 | 
|  |    816 | 	iMod=0;
 | 
|  |    817 | 	iNameBuf.Set(aName);
 | 
|  |    818 | 	TInt r = TParseBase::Set(&aName,NULL,NULL,ETrue);
 | 
|  |    819 | 	__ASSERT_ALWAYS(r==KErrNone,Panic(EParsePtrBadDescriptor0));
 | 
|  |    820 | 	}
 | 
|  |    821 | 
 | 
|  |    822 | 
 | 
|  |    823 | 
 | 
|  |    824 | 
 | 
|  |    825 | EXPORT_C TDes& TParsePtrC::NameBuf()
 | 
|  |    826 | /**
 | 
|  |    827 | Gets a reference to the descriptor containing the filename passed to
 | 
|  |    828 | the constructor of this object. 
 | 
|  |    829 | 
 | 
|  |    830 | @return A reference to the descriptor containing the filename.
 | 
|  |    831 | */
 | 
|  |    832 | 	{
 | 
|  |    833 | 
 | 
|  |    834 | 	Panic(EParsePtrCAccessError);
 | 
|  |    835 | 	return(*(TDes*)&iNameBuf);
 | 
|  |    836 | 	}
 | 
|  |    837 | 
 | 
|  |    838 | 
 | 
|  |    839 | 
 | 
|  |    840 | 
 | 
|  |    841 | EXPORT_C const TDesC& TParsePtrC::NameBufC() const
 | 
|  |    842 | /**
 | 
|  |    843 | Gets a const reference to the descriptor containing the filename passed to
 | 
|  |    844 | the constructor of this object. 
 | 
|  |    845 | 
 | 
|  |    846 | @return A const reference to the descriptor containing the filename.
 | 
|  |    847 | */
 | 
|  |    848 | 	{
 | 
|  |    849 | 
 | 
|  |    850 | 	return(iNameBuf);
 | 
|  |    851 | 	}
 | 
|  |    852 | 
 |