|
1 // tenvarguments.cpp |
|
2 // |
|
3 // Copyright (c) 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 <fshell/ioutils.h> |
|
14 #include <fshell/common.mmh> |
|
15 |
|
16 using namespace IoUtils; |
|
17 |
|
18 class CCmdtenvarguments : public CCommandBase |
|
19 { |
|
20 public: |
|
21 static CCommandBase* NewLC(); |
|
22 ~CCmdtenvarguments(); |
|
23 private: |
|
24 CCmdtenvarguments(); |
|
25 private: // From CCommandBase. |
|
26 virtual const TDesC& Name() const; |
|
27 virtual const TDesC& Description() const; |
|
28 virtual void DoRunL(); |
|
29 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
30 virtual void OptionsL(RCommandOptionList& aOptions); |
|
31 private: |
|
32 HBufC* iStringArg; |
|
33 TInt iIntArg; |
|
34 TUint iUintArg; |
|
35 TBool iBoolOpt; |
|
36 TInt iIntOpt; |
|
37 TUint iUintOpt; |
|
38 HBufC* iStringOpt; |
|
39 }; |
|
40 |
|
41 EXE_BOILER_PLATE(CCmdtenvarguments) |
|
42 |
|
43 CCommandBase* CCmdtenvarguments::NewLC() |
|
44 { |
|
45 CCmdtenvarguments* self = new(ELeave) CCmdtenvarguments(); |
|
46 CleanupStack::PushL(self); |
|
47 self->BaseConstructL(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CCmdtenvarguments::~CCmdtenvarguments() |
|
52 { |
|
53 delete iStringArg; |
|
54 delete iStringOpt; |
|
55 } |
|
56 |
|
57 CCmdtenvarguments::CCmdtenvarguments() |
|
58 { |
|
59 } |
|
60 |
|
61 const TDesC& CCmdtenvarguments::Name() const |
|
62 { |
|
63 #ifdef USE_CIF |
|
64 _LIT(KName, "tenvarguments"); |
|
65 #else |
|
66 _LIT(KName, "tnoncifenvarguments"); |
|
67 #endif |
|
68 return KName; |
|
69 } |
|
70 |
|
71 const TDesC& CCmdtenvarguments::Description() const |
|
72 { |
|
73 #ifdef USE_CIF |
|
74 return CCommandBase::Description(); |
|
75 #else |
|
76 _LIT(KDescription, "Test for command-line arguments that get filled in from the environment."); |
|
77 return KDescription; |
|
78 #endif |
|
79 } |
|
80 |
|
81 void CCmdtenvarguments::ArgumentsL(RCommandArgumentList& aArguments) |
|
82 { |
|
83 #ifdef USE_CIF |
|
84 aArguments.AppendStringL(iStringArg, _L("stringarg")); |
|
85 aArguments.AppendIntL(iIntArg, _L("intarg")); |
|
86 aArguments.AppendUintL(iUintArg, _L("uintarg")); |
|
87 #else |
|
88 aArguments.AppendStringL(iStringArg, _L("stringarg"), _L("String argument."), 0, _L("STRINGARG")); |
|
89 aArguments.AppendIntL(iIntArg, _L("intarg"), _L("Int argument."), 0, _L("INTARG")); |
|
90 aArguments.AppendUintL(iUintArg, _L("uintarg"), _L("Uint argument."), 0, _L("UINTARG")); |
|
91 #endif |
|
92 } |
|
93 |
|
94 void CCmdtenvarguments::OptionsL(RCommandOptionList& aOptions) |
|
95 { |
|
96 #ifdef USE_CIF |
|
97 aOptions.AppendBoolL(iBoolOpt, _L("boolopt")); |
|
98 aOptions.AppendIntL(iIntOpt, _L("intopt")); |
|
99 aOptions.AppendUintL(iUintOpt, _L("uintopt")); |
|
100 aOptions.AppendStringL(iStringOpt, _L("stringopt")); |
|
101 #else |
|
102 aOptions.AppendBoolL(iBoolOpt, 'b', _L("boolopt"), _L("Bool option."), 0, _L("BOOLOPT")); |
|
103 aOptions.AppendIntL(iIntOpt, 'i', _L("intopt"), _L("Int option."), 0, _L("INTOPT")); |
|
104 aOptions.AppendUintL(iUintOpt, 'u', _L("uintopt"), _L("Uint option."), 0, _L("UINTOPT")); |
|
105 aOptions.AppendStringL(iStringOpt, 's', _L("stringopt"), _L("String option."), 0, _L("STRINGOPT")); |
|
106 #endif |
|
107 } |
|
108 |
|
109 #define CHECKINT(arg, val) if (arg != val) LeaveIfErr(KErrArgument, _L("%s is %d, expected %d"), L ## #arg , arg, (TInt)val) |
|
110 #define CHECKSTR(arg, val) if (!arg) LeaveIfErr(KErrArgument, _L("%s is null, should be %S"), L ## #arg, &val); else if (*arg != val) LeaveIfErr(KErrArgument, _L("%s is %S, expected %S"), L ## #arg , arg, &val) |
|
111 |
|
112 void CCmdtenvarguments::DoRunL() |
|
113 { |
|
114 _LIT(KStringArg, "StringArg"); |
|
115 _LIT(KStringOpt, "StringOpt"); |
|
116 |
|
117 CHECKINT(iIntArg, 1234); |
|
118 CHECKINT(iUintArg, 0x1234); |
|
119 CHECKSTR(iStringArg, KStringArg); |
|
120 CHECKINT(iBoolOpt, 1); |
|
121 CHECKINT(iIntOpt, 4321); |
|
122 CHECKINT(iUintOpt, 0x4321); |
|
123 CHECKSTR(iStringOpt, KStringOpt); |
|
124 } |