unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rar.cpp
Go to the documentation of this file.
1#include "rar.hpp"
2
3#if !defined(RARDLL)
4int main(int argc, char *argv[])
5{
6
7#ifdef _UNIX
8 setlocale(LC_ALL,"");
9#endif
10
13
14#ifdef SFX_MODULE
15 wchar ModuleName[NM];
16#ifdef _WIN_ALL
17 GetModuleFileName(NULL,ModuleName,ASIZE(ModuleName));
18#else
19 CharToWide(argv[0],ModuleName,ASIZE(ModuleName));
20#endif
21#endif
22
23#ifdef _WIN_ALL
24 SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT|SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
25
26
27#endif
28
29#if defined(_WIN_ALL) && !defined(SFX_MODULE)
30 // Must be initialized, normal initialization can be skipped in case of
31 // exception.
32 POWER_MODE ShutdownOnClose=POWERMODE_KEEP;
33#endif
34
35 try
36 {
37
38 CommandData *Cmd=new CommandData;
39#ifdef SFX_MODULE
40 wcsncpyz(Cmd->Command,L"X",ASIZE(Cmd->Command));
41 char *Switch=argc>1 ? argv[1]:NULL;
42 if (Switch!=NULL && Cmd->IsSwitch(Switch[0]))
43 {
44 int UpperCmd=etoupper(Switch[1]);
45 switch(UpperCmd)
46 {
47 case 'T':
48 case 'V':
49 Cmd->Command[0]=UpperCmd;
50 break;
51 case '?':
53 break;
54 }
55 }
56 Cmd->AddArcName(ModuleName);
57 Cmd->ParseDone();
58 Cmd->AbsoluteLinks=true; // If users runs SFX, he trusts an archive source.
59#else // !SFX_MODULE
60 Cmd->ParseCommandLine(true,argc,argv);
61 if (!Cmd->ConfigDisabled)
62 {
63 Cmd->ReadConfig();
64 Cmd->ParseEnvVar();
65 }
66 Cmd->ParseCommandLine(false,argc,argv);
67#endif
68
69#if defined(_WIN_ALL) && !defined(SFX_MODULE)
70 ShutdownOnClose=Cmd->Shutdown;
71 if (ShutdownOnClose)
73#endif
74
75 uiInit(Cmd->Sound);
78
79 Cmd->OutTitle();
80 Cmd->ProcessCommand();
81 delete Cmd;
82 }
83 catch (RAR_EXIT ErrCode)
84 {
85 ErrHandler.SetErrorCode(ErrCode);
86 }
87 catch (std::bad_alloc&)
88 {
91 }
92 catch (...)
93 {
95 }
96
97#if defined(_WIN_ALL) && !defined(SFX_MODULE)
98 if (ShutdownOnClose!=POWERMODE_KEEP && ErrHandler.IsShutdownEnabled() &&
100 Shutdown(ShutdownOnClose);
101#endif
102 ErrHandler.MainExit=true;
103 return ErrHandler.GetErrorCode();
104}
105#endif
106
107
ErrorHandler ErrHandler
void ReadConfig()
Definition: cmddata.cpp:227
void AddArcName(const wchar *Name)
Definition: cmddata.cpp:1006
void ParseCommandLine(bool Preprocess, int argc, char *argv[])
Definition: cmddata.cpp:51
void OutHelp(RAR_EXIT ExitCode)
Definition: cmdmix.cpp:51
void OutTitle()
Definition: cmdmix.cpp:1
wchar Command[NM+16]
Definition: cmddata.hpp:59
bool IsSwitch(int Ch)
Definition: cmddata.cpp:1018
void ParseEnvVar()
Definition: cmddata.cpp:178
void ParseDone()
Definition: cmddata.cpp:162
void ProcessCommand()
Definition: cmddata.cpp:935
void MemoryErrorMsg()
Definition: errhnd.cpp:157
bool MainExit
Definition: errhnd.hpp:71
void SetErrorCode(RAR_EXIT Code)
Definition: errhnd.cpp:243
void SetSignalHandlers(bool Enable)
Definition: errhnd.cpp:315
RAR_EXIT GetErrorCode()
Definition: errhnd.hpp:58
void SetSilent(bool Mode)
Definition: errhnd.hpp:62
bool IsShutdownEnabled()
Definition: errhnd.hpp:68
bool AbsoluteLinks
Definition: options.hpp:160
bool AllYes
Definition: options.hpp:152
SOUND_NOTIFY_MODE Sound
Definition: options.hpp:129
bool ConfigDisabled
Definition: options.hpp:111
POWER_MODE Shutdown
Definition: options.hpp:195
wchar LogName[NM]
Definition: options.hpp:127
MESSAGE_TYPE MsgStream
Definition: options.hpp:128
RAR_CHARSET ErrlogCharset
Definition: options.hpp:116
void InitConsole()
Definition: consio.cpp:22
RAR_EXIT
Definition: errhnd.hpp:5
@ RARX_MEMORY
Definition: errhnd.hpp:14
@ RARX_FATAL
Definition: errhnd.hpp:8
@ RARX_SUCCESS
Definition: errhnd.hpp:6
void InitLogOptions(const wchar *LogFileName, RAR_CHARSET CSet)
Definition: log.cpp:7
POWER_MODE
Definition: options.hpp:68
@ POWERMODE_KEEP
Definition: options.hpp:69
@ MSG_NULL
Definition: options.hpp:29
int main(int argc, char *argv[])
Definition: rar.cpp:4
#define ASIZE(x)
Definition: rardefs.hpp:10
wchar_t wchar
Definition: rartypes.hpp:13
void wcsncpyz(wchar *dest, const wchar *src, size_t maxlen)
Definition: strfn.cpp:275
bool ShutdownCheckAnother(bool Open)
void Shutdown(POWER_MODE Mode)
void uiInit(SOUND_NOTIFY_MODE Sound)
Definition: uicommon.cpp:3
bool CharToWide(const char *Src, wchar *Dest, size_t DestSize)
Definition: unicode.cpp:85