Fix Ticket #46, invalid commandline. (Also added -h and --help parameters)

This commit is contained in:
Reijo Tomperi 2009-01-22 20:26:04 +00:00
parent 67e4ea10c9
commit 5de5eab9fe
2 changed files with 26 additions and 3 deletions

View File

@ -103,11 +103,12 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<cmdsynopsis>
<command>&dhpackage;</command>
<arg choice="opt"><option>--all</option></arg>
<arg choice="opt"><option>--quiet</option></arg>
<arg choice="opt"><option>--force</option></arg>
<arg choice="opt"><option>--help</option></arg>
<arg choice="opt"><option>-Idir</option></arg>
<arg choice="opt"><option>--quiet</option></arg>
<arg choice="opt"><option>--style</option></arg>
<arg choice="opt"><option>--verbose</option></arg>
<arg choice="opt"><option>--force</option></arg>
<arg choice="opt"><option>file or path</option></arg>
<arg choice="plain"><option>...</option></arg>
</cmdsynopsis>
@ -142,6 +143,13 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
default.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option></term>
<term><option>--help</option></term>
<listitem>
<para>Print help text.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-I <dir></option></term>
<listitem>

View File

@ -95,6 +95,14 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--force") == 0)
_settings._force = true;
// Print help
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
pathnames.clear();
_filenames.clear();
break;
}
// Include paths
else if (strcmp(argv[i], "-I") == 0 || strncmp(argv[i], "-I", 2) == 0)
{
@ -124,6 +132,11 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
_includePaths.push_back(path);
}
else if (strncmp(argv[i], "-", 1) == 0 || strncmp(argv[i], "--", 2) == 0)
{
return "cppcheck: error: unrecognized command line option \"" + std::string(argv[i]) + "\"\n";
}
else
pathnames.push_back(argv[i]);
}
@ -144,7 +157,8 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
"A tool for static C/C++ code analysis\n"
"\n"
"Syntax:\n"
" cppcheck [--all] [--force] [-Idir] [--quiet] [--style] [--verbose] [file or path1] [file or path]\n"
" cppcheck [--all] [--force] [--help] [-Idir] [--quiet] [--style]\n"
" [--verbose] [file or path1] [file or path]\n"
"\n"
"If path is given instead of filename, *.cpp, *.cxx, *.cc, *.c++ and *.c files\n"
"are checked recursively from given directory.\n\n"
@ -152,6 +166,7 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
" -a, --all Make the checking more sensitive. More bugs are detected,\n"
" but there are also more false positives\n"
" -f, --force Force checking on files that have \"too many\" configurations\n"
" -h, --help Print this help\n"
" -I <dir> Give include path. Give several -I parameters to give several\n"
" paths. First given path is checked first. If paths are\n"
" relative to source files, this is not needed.\n"