17e2b1538SKostya Kortchinsky //===-- flags_parser.h ------------------------------------------*- C++ -*-===// 27e2b1538SKostya Kortchinsky // 37e2b1538SKostya Kortchinsky // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 47e2b1538SKostya Kortchinsky // See https://llvm.org/LICENSE.txt for license information. 57e2b1538SKostya Kortchinsky // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 67e2b1538SKostya Kortchinsky // 77e2b1538SKostya Kortchinsky //===----------------------------------------------------------------------===// 87e2b1538SKostya Kortchinsky 97e2b1538SKostya Kortchinsky #ifndef SCUDO_FLAGS_PARSER_H_ 107e2b1538SKostya Kortchinsky #define SCUDO_FLAGS_PARSER_H_ 117e2b1538SKostya Kortchinsky 127e2b1538SKostya Kortchinsky #include "report.h" 137e2b1538SKostya Kortchinsky #include "string_utils.h" 147e2b1538SKostya Kortchinsky 157e2b1538SKostya Kortchinsky #include <stddef.h> 167e2b1538SKostya Kortchinsky 177e2b1538SKostya Kortchinsky namespace scudo { 187e2b1538SKostya Kortchinsky 197e2b1538SKostya Kortchinsky enum class FlagType : u8 { 207e2b1538SKostya Kortchinsky FT_bool, 217e2b1538SKostya Kortchinsky FT_int, 227e2b1538SKostya Kortchinsky }; 237e2b1538SKostya Kortchinsky 247e2b1538SKostya Kortchinsky class FlagParser { 257e2b1538SKostya Kortchinsky public: 267e2b1538SKostya Kortchinsky void registerFlag(const char *Name, const char *Desc, FlagType Type, 277e2b1538SKostya Kortchinsky void *Var); 287e2b1538SKostya Kortchinsky void parseString(const char *S); 297e2b1538SKostya Kortchinsky void printFlagDescriptions(); 30*d1168df2SFlorian Mayer void parseStringPair(const char *Name, const char *Value); 317e2b1538SKostya Kortchinsky 327e2b1538SKostya Kortchinsky private: 33ba379fe5SKostya Kortchinsky static const u32 MaxFlags = 20; 347e2b1538SKostya Kortchinsky struct Flag { 357e2b1538SKostya Kortchinsky const char *Name; 367e2b1538SKostya Kortchinsky const char *Desc; 377e2b1538SKostya Kortchinsky FlagType Type; 387e2b1538SKostya Kortchinsky void *Var; 397e2b1538SKostya Kortchinsky } Flags[MaxFlags]; 407e2b1538SKostya Kortchinsky 417e2b1538SKostya Kortchinsky u32 NumberOfFlags = 0; 427e2b1538SKostya Kortchinsky const char *Buffer = nullptr; 437e2b1538SKostya Kortchinsky uptr Pos = 0; 447e2b1538SKostya Kortchinsky 457e2b1538SKostya Kortchinsky void reportFatalError(const char *Error); 467e2b1538SKostya Kortchinsky void skipWhitespace(); 477e2b1538SKostya Kortchinsky void parseFlags(); 487e2b1538SKostya Kortchinsky void parseFlag(); 49*d1168df2SFlorian Mayer bool runHandler(const char *Name, const char *Value, char Sep); 507e2b1538SKostya Kortchinsky }; 517e2b1538SKostya Kortchinsky 527e2b1538SKostya Kortchinsky void reportUnrecognizedFlags(); 537e2b1538SKostya Kortchinsky 547e2b1538SKostya Kortchinsky } // namespace scudo 557e2b1538SKostya Kortchinsky 567e2b1538SKostya Kortchinsky #endif // SCUDO_FLAGS_PARSER_H_ 57