commands/fed/src/main.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // main.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <e32base.h>
       
    14 #include <e32std.h>
       
    15 #include <e32cons.h>
       
    16 #include <BADESCA.H>
       
    17 #include <BACLINE.H>
       
    18 
       
    19 #include "fed.h"
       
    20 
       
    21 //  Constants
       
    22 _LIT(KTextConsoleTitle, "Fed editor");
       
    23 _LIT(KTextFailed, "\n failed, leave code = %d\n press any key to exit");
       
    24 
       
    25 //  Global Variables
       
    26 //CColorConsoleBase* console = NULL;  // write all messages to this
       
    27 CConsoleBase* console = NULL;
       
    28 CFed* gFed = NULL;
       
    29 
       
    30 LOCAL_C void DoStartL()
       
    31 	{
       
    32 	// Create active scheduler (to run active objects)
       
    33 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
       
    34 	CleanupStack::PushL(scheduler);
       
    35 	CActiveScheduler::Install(scheduler);
       
    36 
       
    37 	RFs fs;
       
    38 	User::LeaveIfError(fs.Connect());
       
    39 	CleanupClosePushL(fs);
       
    40 	CFed* fed = CFed::NewL(*console, fs);
       
    41 	CleanupStack::PushL(fed);
       
    42 	CDesC16ArrayFlat* argsBuf = new(ELeave) CDesC16ArrayFlat(4);
       
    43 	CleanupStack::PushL(argsBuf);
       
    44 	CCommandLineArguments* args = CCommandLineArguments::NewLC();
       
    45 	for (TInt i = 1; i < args->Count(); i++) // Start from 1 as arg zero is the exe name
       
    46 		{
       
    47 		// No attempt to be clever with arguments - this code is only used when building a raw non-fshell version - mainfshell has the nicer equivalent
       
    48 		TPtrC arg = args->Arg(i);
       
    49 		argsBuf->AppendL(arg);
       
    50 		}
       
    51 	CleanupStack::PopAndDestroy(args);
       
    52 	CleanupStack::Pop(argsBuf);
       
    53 	gFed = fed;
       
    54 	fed->StartL(argsBuf);
       
    55 	CActiveScheduler::Start();
       
    56 
       
    57 	// Delete active scheduler
       
    58 	CleanupStack::PopAndDestroy(3, scheduler); // fed, fs, scheduler
       
    59 	}
       
    60 
       
    61 //  Global Functions
       
    62 GLDEF_C TInt E32Main()
       
    63 	{
       
    64 	// Create cleanup stack
       
    65 	__UHEAP_MARK;
       
    66 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    67 
       
    68 	// Create output console
       
    69 	//TRAPD(createError, console = dynamic_cast<CColorConsoleBase*>(Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen))));
       
    70 	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
       
    71 	if (createError)
       
    72 		return createError;
       
    73 
       
    74 	// Run application code inside TRAP harness, wait keypress when terminated
       
    75 	TRAPD(mainError, DoStartL());
       
    76 	if (mainError)
       
    77 		{
       
    78 		console->Printf(KTextFailed, mainError);
       
    79 		console->Getch();
       
    80 		}
       
    81 	
       
    82 	delete console;
       
    83 	delete cleanup;
       
    84 	__UHEAP_MARKEND;
       
    85 	return KErrNone;
       
    86 	}
       
    87 
       
    88 class TSilentOverflow : public TDes8Overflow
       
    89 	{
       
    90 	void Overflow(TDes8& /*aDes*/) { /* Silently truncate */ }
       
    91 	};
       
    92 
       
    93 void AssertionFail(const char* aAssertion, const char* aFile, TInt aLine)
       
    94 	{
       
    95 	__DEBUGGER();
       
    96 	TBuf8<256> buf;
       
    97 	TSilentOverflow o;
       
    98 	buf.AppendFormat(_L8("Assertion failed: \"%s\" in %s:%i\n"), &o, aAssertion, aFile, aLine);
       
    99 	if (buf.Length()*2>buf.MaxLength()) buf.SetLength(buf.MaxLength()/2);
       
   100 	console->Write(buf.Expand());
       
   101 	User::Panic(_L("Fed"), aLine);
       
   102 	}
       
   103 
       
   104 extern TInt KConsoleWidthCorrection = -2;
       
   105 extern TInt KConsoleHeightCorrection = -2;
       
   106 
       
   107 TInt TabWidth()
       
   108 	{
       
   109 	return 4;
       
   110 	}
       
   111 
       
   112 _LIT(KHelpText, "\
       
   113 Fed Help\n\
       
   114 ========\n\
       
   115 Fed is a basic console text editor. Its interface is similar to pico/nano. It can handle ASCII, UTF-8 and UTF-16 format files, different line endings, very large files, copy and paste, and opening multiple files at once.\n\
       
   116 \n\
       
   117 The supported commands are given below. The control key is represented as a caret '^', so ^G means Control-G.\n\
       
   118 \n\
       
   119 Commands\n\
       
   120 ========\n\
       
   121 ^L, F1  Get help\n\
       
   122 ^N      New document\n\
       
   123 ^O      Open document\n\
       
   124 ^S      Save document\n\
       
   125 ^A      Save as\n\
       
   126 \n\
       
   127 ^U      Page up (alternative to PgUp key)\n\
       
   128 ^D      Page down (alternative to PgDn key)\n\
       
   129 ^T      Go to top of document\n\
       
   130 ^B      Go to bottom of document\n\
       
   131 \n\
       
   132 ^F      Find text\n\
       
   133 ^K      Delete current line\n\
       
   134 ^G      Go to line\n\
       
   135 ^R, F5  Redraw the screen\n\
       
   136 ^X      Cut (see below)\n\
       
   137 ^C      Copy (see below)\n\
       
   138 ^V      Paste\n\
       
   139 \n\
       
   140 ^P, F2  Switch to Previous view\n\
       
   141 ^], F3  Switch to Next view\n\
       
   142 ^W, Esc Close current doc\n\
       
   143 ^Q      Quit and close all docs\n\
       
   144 \n\
       
   145 Press ^W to close this window, or use ^P etc to cycle between the help and other documents.\n\
       
   146 \n\
       
   147 Clipboard support\n\
       
   148 =================\n\
       
   149 The standard Symbian clipboard is supported. You can use ^V to paste into the frontmost document. Cut and copy are two-stage operations, because of the limitations of the console:\n\
       
   150 \n\
       
   151 To begin a cut/copy operation, press ^X or ^C. Then move the cursor to the other end of the selection you want to make, and press ^X/^C again to confirm the cut/copy operation.\n\
       
   152 ");
       
   153 
       
   154 void ShowHelpL()
       
   155 	{
       
   156 	gFed->ShowHelpL(KHelpText().AllocL());
       
   157 	}
       
   158