examples/Base/FileServer/Filenames/Filenames.cpp

00001 /*
00002 Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 
00032 #include <f32file.h>
00033 #include "CommonFramework.h"
00034         
00035 static RFs fsSession;
00036 
00037 // example functions
00038 void CreatePathsL(); // sets up the paths to parse
00039 void ParseNamesL(const TDesC& aFullName); // does the parsing
00040 
00041 void WaitForKey()
00042         {
00043         _LIT(KMessage,"Press any key to continue\n\n");
00044         console->Printf(KMessage);
00045         console->Getch();
00046         }
00047 
00048 static void doExampleL()
00049     {
00050         // Connect to file server
00051         User::LeaveIfError(fsSession.Connect()); // Start session
00052         CreatePathsL();
00053         fsSession.Close(); // close session
00054         }
00055 
00056 void CreatePathsL()
00057         {
00058         // Define descriptor constants using the _LIT macro 
00059         _LIT(KFuncName,"\nDoParsing()\n");
00060         _LIT(KParse1,"d:\\path\\fn.ext");
00061         _LIT(KParse2,"autoexec.bat");
00062         _LIT(KParse3,"\\readme");
00063         _LIT(KParse4,"\\include\\stdio.h");
00064         _LIT(KParse5,".profile");
00065         _LIT(KParse6,"autoexec.*");
00066         console->Printf(KFuncName);
00067         // Parse a full path, then paths with various components missing 
00068         // to show the results of using a default path and related path
00069         // to fill in missing path components.
00070         ParseNamesL(KParse1);
00071         WaitForKey();
00072         ParseNamesL(KParse2);
00073         WaitForKey();
00074         ParseNamesL(KParse3);
00075         WaitForKey();
00076         ParseNamesL(KParse4);
00077         WaitForKey();
00078         ParseNamesL(KParse5);
00079         WaitForKey();
00080         ParseNamesL(KParse6);
00081         WaitForKey();
00082         }
00083 
00084 void ParseNamesL(const TDesC& aFullName)
00085         {
00086         _LIT(KFullName,"Full name=%S\n");
00087         _LIT(KPathComponents,"Drive=%S  path=%S  name=%S  ext=%S\n");
00088         _LIT(KFullNameText,"Full name against session path=%S\n");
00089         _LIT(KExtension,".txt");
00090         _LIT(KParsedPath,"Full name against session path and default extension=%S\n");
00091 
00092         // Set up parse using TParse::Set(). Print whole path, then each path
00093         // component in turn.
00094         // Parse path using the default session path, using RFs::Parse 
00095         // then additionally with a related path.
00096         TParse p;
00097         // do isolated parse
00098         User::LeaveIfError(p.Set(aFullName,NULL,NULL));
00099         console->Printf(KFullName, &p.FullName());
00100         TFileName drivename(p.Drive());
00101         TFileName pathname(p.Path());
00102         TFileName filename(p.Name());
00103         TFileName extension(p.Ext());
00104         console->Printf(KPathComponents,&drivename,&pathname,&filename,&extension);
00105         // do parse including session path
00106         User::LeaveIfError(fsSession.Parse(aFullName,p));
00107         console->Printf(KFullNameText,&(p.FullName()));
00108         // add default extension
00109         User::LeaveIfError(fsSession.Parse(aFullName,KExtension,p));
00110         console->Printf(KParsedPath,&(p.FullName()));
00111         }
00112 
00113 
00114 
00115 

Generated by  doxygen 1.6.2