1 /* Definitions to support options processing. 2 Copyright 2001 Brian R. Gaeke. 3 4 This file is part of VMIPS. 5 6 VMIPS is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by the 8 Free Software Foundation; either version 2 of the License, or (at your 9 option) any later version. 10 11 VMIPS is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 for more details. 15 16 You should have received a copy of the GNU General Public License along 17 with VMIPS; if not, write to the Free Software Foundation, Inc., 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 20 #ifndef _OPTIONS_H_ 21 #define _OPTIONS_H_ 22 23 #include "types.h" 24 #include <map> 25 #include <string> 26 27 /* This defines the name of the system default configuration file. */ 28 #define SYSTEM_CONFIG_FILE SYSCONFDIR"/vmipsrc" 29 30 /* option types */ 31 enum { 32 FLAG = 1, 33 NUM, 34 STR 35 }; 36 37 union OptionValue { 38 char *str; 39 bool flag; 40 uint32 num; 41 }; 42 43 typedef struct { 44 const char *name; 45 int type; 46 union OptionValue value; 47 } Option; 48 49 /* The total number of options must not be greater than TABLESIZE, and 50 * TABLESIZE should be the smallest power of 2 greater than the number 51 * of options that allows the hash function to perform well. 52 */ 53 #define TABLESIZE 256 54 55 class Options { 56 protected: 57 typedef std::map<std::string, Option> OptionMap; 58 OptionMap table; 59 60 void process_defaults(void); 61 void process_one_option(const char *const option); 62 int process_first_option(char **bufptr, int lineno = 0, 63 const char *fn = NULL); 64 int process_options_from_file(const char *filename); 65 int tilde_expand(char *filename); 66 virtual void usage(char *argv0); 67 void set_str_option(const char *key, const char *value); 68 void set_num_option(const char *key, uint32 value); 69 void set_flag_option(const char *key, bool value); 70 const char *strprefix(const char *crack_smoker, const char *crack); 71 int find_option_type(const char *option); 72 Option *optstruct(const char *name, bool install = false); 73 void print_package_version(const char *toolname, const char *version); 74 void print_config_info(void); 75 public: Options()76 Options () { } ~Options()77 virtual ~Options () { } 78 virtual void process_options(int argc, char **argv); 79 union OptionValue *option(const char *name); 80 }; 81 82 #endif /* _OPTIONS_H_ */ 83