1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "LogCommandLineHandler.h"
9 #include "mozilla/Tokenizer.h"
14 void LoggingHandleCommandLineArgs(
15 int argc
, char const* const* argv
,
16 std::function
<void(nsACString
const&)> const& consumer
) {
17 // Keeps the name of a pending env var (MOZ_LOG or MOZ_LOG_FILE) that
18 // we expect to get a value for in the next iterated arg.
19 // Used for the `-MOZ_LOG <modules>` form of argument.
22 auto const names
= {"MOZ_LOG"_ns
, "MOZ_LOG_FILE"_ns
};
24 for (int arg
= 1; arg
< argc
; ++arg
) {
25 Tokenizer
p(argv
[arg
]);
27 if (!env
.IsEmpty() && p
.CheckChar('-')) {
29 "Expects value after -MOZ_LOG(_FILE) argument, but another argument "
32 // We only expect values for the pending env var, start over
38 if (!p
.CheckChar('-')) {
41 // We accept `-MOZ_LOG` as well as `--MOZ_LOG`.
42 Unused
<< p
.CheckChar('-');
44 for (auto const& name
: names
) {
45 if (!p
.CheckWord(name
)) {
55 // An unknonwn argument, ignore.
59 // We accept `-MOZ_LOG <modules>` as well as `-MOZ_LOG=<modules>`.
62 // We have a lone `-MOZ_LOG` arg, the next arg is expected to be
63 // the value, |env| is now prepared as `MOZ_LOG=`.
67 if (!p
.CheckChar('=')) {
68 // There is a character after the arg name and it's not '=',
69 // ignore this argument.
70 NS_WARNING("-MOZ_LOG(_FILE) argument not in a proper form");
77 // This can be non-empty from previous iteration or in this iteration.
79 nsDependentCSubstring value
;
80 Unused
<< p
.ReadUntil(Tokenizer::Token::EndOfFile(), value
);
90 } // namespace mozilla