diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2010-03-12 19:41:30 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2010-03-12 19:41:30 +0100 |
commit | 2bb255740bf18b5e0524fe833523303abb5c9051 (patch) | |
tree | 5a27be689c8c2d980928eabb8f3f7df422e67432 /apt-pkg/contrib/cmndline.cc | |
parent | 3a4477a4241bcfbc9db541cf34cc75c1f1111b78 (diff) |
* apt-pkg/deb/dpkgpm.cc:
- if available store the Commandline in the history
* apt-pkg/contrib/cmndline.cc:
- save Commandline in Commandline::AsString for logging
Diffstat (limited to 'apt-pkg/contrib/cmndline.cc')
-rw-r--r-- | apt-pkg/contrib/cmndline.cc | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index bfd53695e..0b16bf51a 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -135,7 +135,9 @@ bool CommandLine::Parse(int argc,const char **argv) for (; I != argc; I++) *Files++ = argv[I]; *Files = 0; - + + SaveInConfig(argc, argv); + return true; } /*}}}*/ @@ -351,3 +353,41 @@ bool CommandLine::DispatchArg(Dispatch *Map,bool NoMatch) return false; } /*}}}*/ +// CommandLine::SaveInConfig - for output later in a logfile or so /*{{{*/ +// --------------------------------------------------------------------- +/* We save the commandline here to have it around later for e.g. logging. + It feels a bit like a hack here and isn't bulletproof, but it is better + than nothing after all. */ +void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * const argv) +{ + char cmdline[300]; + unsigned int length = 0; + bool lastWasOption = false; + bool closeQuote = false; + for (unsigned int i = 0; i < argc; ++i, ++length) + { + for (unsigned int j = 0; argv[i][j] != '\0' && length < sizeof(cmdline)-1; ++j, ++length) + { + cmdline[length] = argv[i][j]; + if (lastWasOption == true && argv[i][j] == '=') + { + // That is possibly an option: Quote it if it includes spaces, + // the benefit is that this will eliminate also most false positives + const char* c = &argv[i][j+1]; + for (; *c != '\0' && *c != ' '; ++c); + if (*c == '\0') continue; + cmdline[++length] = '"'; + closeQuote = true; + } + } + if (closeQuote == true) + cmdline[length++] = '"'; + // Problem: detects also --hello + if (cmdline[length-1] == 'o') + lastWasOption = true; + cmdline[length] = ' '; + } + cmdline[--length] = '\0'; + _config->Set("CommandLine::AsString", cmdline); +} + /*}}}*/ |