1 // Options.cpp: implementation of the COptions class.
3 //////////////////////////////////////////////////////////////////////
9 //---------------------------------------------------------------------------
10 #include "LeakWatcher.h"
15 static char THIS_FILE
[] = __FILE__
;
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
22 // TODO: replace the complete COptions class with a better design
25 : m_bIntegrityCheck (false),
26 m_bIncludeLabels (true),
27 m_bOnlyLabels (false),
28 m_bIncludeDeleted (false),
29 m_bOnlyDeleted (false),
30 m_bIncludeFiles (true),
33 m_bAllRecords (false),
34 m_pVersionFilter (NULL
),
36 m_bForceOverwrite (false),
44 COptions::~COptions ()
46 DELETE (m_pVersionFilter
);
49 void COptions::PrintUsage ()
51 std::cout
<< "ssrep v0.8:" << std::endl
;
52 std::cout
<< std::endl
;
53 std::cout
<< "usage:" << std::endl
;
54 std::cout
<< "general options: " << std::endl
;
55 std::cout
<< " -Y user,password" << std::endl
;
56 std::cout
<< " -d include deleted files" << std::endl
;
57 std::cout
<< " -d+ only deleted files" << std::endl
;
58 std::cout
<< " -f include files (default)" << std::endl
;
59 std::cout
<< " -f+ only files" << std::endl
;
60 std::cout
<< " -f- only projects" << std::endl
;
61 std::cout
<< " -v# specific version number" << std::endl
;
62 std::cout
<< std::endl
;
63 std::cout
<< std::endl
;
64 std::cout
<< "ssrep dir [file] displays directory information about the project" << std::endl
;
65 // std::cout << "ssrep info [file] displays basic information about the item" << std::endl;
66 // std::cout << "options: " << std::endl;
67 // std::cout << " -a process all records within the file" << std::endl;
68 // std::cout << "ssrep history [item] displays the history of the specific item" << std::endl;
69 // std::cout << "options: " << std::endl;
70 // std::cout << " -L<-|+> Filter versions by labels (-) all versions without labels" << std::endl;
71 // std::cout << " (+) only versions that have labels" << std::endl;
72 // std::cout << " --del include dead records" << std::endl;
73 // std::cout << std::endl;
74 // std::cout << "ssrep get [item] [target] retrieve a specific version of the item" << std::endl;
75 // std::cout << "options: " << std::endl;
76 // std::cout << " -f force overwrite of target file" << std::endl;
77 // std::cout << " -v# specifies the version to get" << std::endl;
78 std::cout
<< std::endl
;
79 std::cout
<< " -h --help print help text" << std::endl
;
82 void COptions::ParseCommandLine (int argc
, char* argv
[])
84 for (int i
= 1; i
< argc
; ++i
)
86 if (argv
[i
][0] == '-')
88 if (IsArgChar (argv
[i
][1], '?'))
92 else if (IsArgChar (argv
[i
][1], 'a') || IsLongArgument (&argv
[i
][1], "all"))
96 else if (IsArgChar (argv
[i
][1], 'd'))
98 m_bIncludeDeleted
= true;
99 m_bOnlyDeleted
= ToBool (argv
[i
][2], m_bOnlyDeleted
);
101 else if (IsArgChar (argv
[i
][1], 'e'))
105 else if (IsArgChar (argv
[i
][1], 'f'))
107 m_bIncludeFiles
= true;
108 m_bOnlyFiles
= ToBool (argv
[i
][2], m_bIncludeFiles
);
110 else if (IsLongArgument (&argv
[i
][1], "force"))
112 m_bForceOverwrite
= true;
114 else if (IsArgChar (argv
[i
][1], 'h') || IsLongArgument (&argv
[i
][1], "help"))
118 else if (IsArgChar (argv
[i
][1], 'i'))
120 // Ignore: Do not ask for input under any circumstances.
122 // m_bIgnore = ToBool (argv[i][2], m_bIgnore);
124 else if (IsArgChar (argv
[i
][1], 'l'))
126 m_bOnlyLabels
= true;
127 m_bIncludeLabels
= ToBool (argv
[i
][2], m_bOnlyLabels
);
129 else if (IsArgChar (argv
[i
][1], 'n') || IsLongArgument (&argv
[i
][1], "names"))
132 m_NamesDat
= argv
[i
];
134 else if (IsArgChar (argv
[i
][1], 'o'))
136 m_LogFile
= &argv
[i
][2];
138 else if (IsArgChar (argv
[i
][1], 'p'))
141 m_bPhys
= ToBool (argv
[i
][2], m_bPhys
);
144 else if (IsArgChar (argv
[i
][1], 'r') || IsLongArgument (&argv
[i
][1], "recursive"))
147 m_bRecursive
= ToBool (argv
[i
][2], m_bRecursive
);
149 else if (IsArgChar (argv
[i
][1], 's'))
151 m_SrcSafeIniPath
= &argv
[i
][2];
153 else if (IsArgChar (argv
[i
][1], 'v') || IsLongArgument (&argv
[i
][1], "version"))
156 if (IsArgChar (argv
[i
][1], 'v'))
157 filter
= &argv
[i
][2];
163 std::istrstream
ist (filter
.c_str (), filter
.length());
169 DELETE (m_pVersionFilter
);
170 m_pVersionFilter
= new CVersionRangeFilter (end
, start
);
173 m_VersionDate
= filter
;
175 else if (IsArgChar (argv
[i
][1], 'y'))
177 std::string userpw
= &argv
[i
][2];
178 m_User
= userpw
.substr(0, userpw
.find (','));
179 m_Password
= userpw
.substr(userpw
.find (',')+1);
184 if (m_Command
.empty ())
187 // TODO: tolower bekommt ein (int) als parameter, std::string ist aber ein uchar --> Probleme mit negativen chars
188 std::transform (m_Command
.begin(), m_Command
.end(), m_Command
.begin(), tolower
);
191 m_Items
.push_back (argv
[i
]);
195 if (m_Command
== "get" && m_Items
.size () > 1)
197 m_Dest
= m_Items
.back();
203 bool COptions::IsLongArgument (const char* ch
, const char* arg
)
208 std::string str
= (ch
[0] == '-') ? &ch
[1] : &ch
[0];
215 bool COptions::IsArgChar (const char ch
, const char arg
)
221 else if (tolower(ch
) == arg
)
223 else if (toupper(ch
) == arg
)
228 bool COptions::ToBool (const char ch
, bool& val
)