48
49
ERROR_MSG ("no " << __what << " given for `" << __name << "'")
51
// -A<PREDICATE>(<ANSWER>) // Assert a preprocessor predicate.
52
// -D<NAME>[=<BODY>] // Define a preprocessor macro.
53
// -U<NAME> // Undefine a preprocessor macro.
54
// -I<PATH> // Add a new include path.
55
//OLD: -p|--path <SRC> [<DEST>] // Add a new source dest paths pair.
56
// -p|--path <SRC> // Add a new source path.
57
// -d|--dest <DEST> // Add a new dest path.
58
// -w|--write-protected <PATH_PATTERN> // Add a new write protected path.
59
// -s|--suffix <SUFFIX> // Set the file save suffix.
60
// -e|--extension <EXTENSION> // Set the extension for source files.
61
// --save-overwrite|rename-old|new-suffix // set the file save mode
62
// --lang-c|ec++|c++|ac++ // set the source code language
63
// --skip-bodies-all // skip parsing function bodies
64
// --skip-bodies-tpl // skip parsing function bodies of templates
65
// --skip-bodies-non-prj // skip parsing non-project function bodies
66
// --skip-bodies-non-prim // skip parsing function bodies in non-primary files
67
// --match-expr // parse match expressions
68
// --vc // support MS Visual C++ extensions
69
// --gnu // support gnu extensions
73
// --gnu-condition-scope
79
// --gnu-extended-expr
83
// --gnu-fct-attribute
86
52
OptsParser::Option pumaOpts[] = {
87
53
{Config::PRE_ASSERT, "A", NULL, "Assert a preprocessor predicate", OptsParser::AT_MANDATORY},
88
54
{Config::PRE_DEFINE, "D", NULL, "Define a preprocessor macro", OptsParser::AT_MANDATORY},
89
55
{Config::PRE_UNDEFINE, "U", NULL, "Undefine a preprocessor macro", OptsParser::AT_MANDATORY},
90
{Config::PRE_LOCK_MACRO, 0, "lock-macro", "Define an unchangeable preprocessor macro", OptsParser::AT_MANDATORY},
91
{Config::PRE_INCLUDE, "I", NULL, "Add new include path", OptsParser::AT_MANDATORY},
92
{Config::PROJ_PATH, "p", "path", "Path to project source", OptsParser::AT_MANDATORY},
93
{Config::PROJ_DESTINATION, "d", "dest", "Path to destination for modified sources", OptsParser::AT_MANDATORY},
94
{Config::SET_SUFFIX, "s", "suffix", "Set file save suffix", OptsParser::AT_MANDATORY},
56
{Config::PRE_LOCK_MACRO, NULL, "lock-macro", "Define an immutable preprocessor macro", OptsParser::AT_MANDATORY},
57
{Config::SET_OPTION_ARG, NULL, "inhibit-macro", "Add the name of a macro whose definition will be ignored", OptsParser::AT_MANDATORY},
58
{Config::PRE_INCLUDE, "I", NULL, "Add an include directory", OptsParser::AT_MANDATORY},
59
{Config::PROJ_PATH, "p", "path", "Add a project source directory", OptsParser::AT_MANDATORY},
60
{Config::PROJ_DESTINATION, "d", "dest", "Add a destination folder for modified sources", OptsParser::AT_MANDATORY},
61
{Config::SET_SUFFIX, "s", "suffix", "Set the suffix for output files", OptsParser::AT_MANDATORY},
95
62
{Config::SET_EXTENSION, "e", "extension", "Set the extension for source files", OptsParser::AT_MANDATORY},
96
{Config::SET_WRITE_PROTECTED, "w", "write-protected", "Add a new write protected path", OptsParser::AT_MANDATORY},
97
{Config::CFG_FILE, NULL, "config", "Full path to a config file", OptsParser::AT_MANDATORY},
98
{Config::SET_OPTION, NULL, "save-overwrite", "Overwrite old files", OptsParser::AT_NONE},
99
{Config::SET_OPTION, NULL, "rename-old", "Rename old files", OptsParser::AT_NONE},
100
{Config::SET_OPTION, NULL, "new-suffix", "Append new suffix on old files", OptsParser::AT_NONE},
101
{Config::SET_OPTION, NULL, "lang-c", "Input language is C", OptsParser::AT_NONE},
102
{Config::SET_OPTION, NULL, "lang-ec++", "Input language is EC++", OptsParser::AT_NONE},
103
{Config::SET_OPTION, NULL, "lang-c++", "Input language is C++", OptsParser::AT_NONE},
104
{Config::SET_OPTION, NULL, "lang-ac++", "Input language is AC++", OptsParser::AT_NONE},
63
{Config::SET_WRITE_PROTECTED, "w", "write-protected", "Add a write protected project directory", OptsParser::AT_MANDATORY},
64
{Config::CFG_FILE, NULL, "config", "Load configuration options from a file", OptsParser::AT_MANDATORY},
65
{Config::SET_OPTION, NULL, "save-overwrite", "Overwrite existing files when saving", OptsParser::AT_NONE},
66
{Config::SET_OPTION, NULL, "rename-old", "Rename existing files when saving", OptsParser::AT_NONE},
67
{Config::SET_OPTION, NULL, "new-suffix", "Append new suffix on existing files when saving", OptsParser::AT_NONE},
68
{Config::SET_OPTION, NULL, "lang-c", "Set input language to C", OptsParser::AT_NONE},
69
{Config::SET_OPTION, NULL, "lang-ec++", "Set input language to EC++", OptsParser::AT_NONE},
70
{Config::SET_OPTION, NULL, "lang-c++", "Set input language to C++", OptsParser::AT_NONE},
71
{Config::SET_OPTION, NULL, "lang-ac++", "Set input language to AC++", OptsParser::AT_NONE},
72
{Config::SET_OPTION, NULL, "vc", "Enable Visual C++ extensions", OptsParser::AT_NONE},
73
{Config::GNU, NULL, "gnu", "Enable GNU extensions", OptsParser::AT_OPTIONAL},
74
{Config::SET_OPTION, NULL, "gnu-nested-fct", "Enable GNU nested functions extension", OptsParser::AT_NONE},
75
{Config::SET_OPTION, NULL, "gnu-condition-scope", "Enable GNU condition scope extension", OptsParser::AT_NONE},
76
{Config::SET_OPTION, NULL, "gnu-param-decl", "Enable GNU parameter declaration extension", OptsParser::AT_NONE},
77
{Config::SET_OPTION, NULL, "gnu-fct-decl", "Enable GNU function declaration extension", OptsParser::AT_NONE},
78
{Config::SET_OPTION, NULL, "gnu-param-scope", "Enable GNU parameter scope extension", OptsParser::AT_NONE},
79
{Config::SET_OPTION, NULL, "gnu-default-args", "Enable GNU default arguments extension", OptsParser::AT_NONE},
80
{Config::SET_OPTION, NULL, "gnu-extended-asm", "Enable GNU extended asm declaration extension", OptsParser::AT_NONE},
81
{Config::SET_OPTION, NULL, "gnu-extended-expr", "Enable GNU extended expression extension", OptsParser::AT_NONE},
82
{Config::SET_OPTION, NULL, "gnu-long-long", "Enable GNU type long long extension", OptsParser::AT_NONE},
83
{Config::SET_OPTION, NULL, "gnu-name-scope", "Enable GNU name scope extension", OptsParser::AT_NONE},
84
{Config::SET_OPTION, NULL, "gnu-implicit-int", "Enable GNU implicit int extension", OptsParser::AT_NONE},
85
{Config::SET_OPTION, NULL, "gnu-fct-attribute", "Enable GNU function attributes extension", OptsParser::AT_NONE},
86
{Config::SET_OPTION, NULL, "gnu-if-then-expr", "Enable GNU if-then expression extension", OptsParser::AT_NONE},
87
{Config::SET_OPTION, NULL, "gnu-std-hack", "Enable GNU std namespace extension", OptsParser::AT_NONE},
88
{Config::SET_OPTION, NULL, "gnu-friend-injection", "Enable GNU friend injection extension", OptsParser::AT_NONE},
89
{Config::SET_OPTION, NULL, "builtin-type-traits", "Enable built-in type traits", OptsParser::AT_NONE},
105
90
{Config::SET_OPTION, NULL, "skip-bodies-all", "Skip parsing function bodies", OptsParser::AT_NONE},
106
91
{Config::SET_OPTION, NULL, "skip-bodies-tpl", "Skip parsing function bodies of templates", OptsParser::AT_NONE},
107
92
{Config::SET_OPTION, NULL, "skip-bodies-non-prj", "Skip parsing non-project function bodies", OptsParser::AT_NONE},
108
93
{Config::SET_OPTION, NULL, "skip-bodies-non-prim", "Skip parsing function bodies in non-primary files", OptsParser::AT_NONE},
109
{Config::SET_OPTION, NULL, "real-instances", "Do real template instantiation", OptsParser::AT_NONE},
110
{Config::SET_OPTION, NULL, "match-expr", "Parse match expression", OptsParser::AT_NONE},
111
{Config::SET_OPTION, NULL, "gnu-nested-fct", "", OptsParser::AT_NONE},
112
{Config::SET_OPTION, NULL, "gnu-condition-scope", "", OptsParser::AT_NONE},
113
{Config::SET_OPTION, NULL, "gnu-param-decl", "", OptsParser::AT_NONE},
114
{Config::SET_OPTION, NULL, "gnu-fct-decl", "", OptsParser::AT_NONE},
115
{Config::SET_OPTION, NULL, "gnu-param-scope", "", OptsParser::AT_NONE},
116
{Config::SET_OPTION, NULL, "gnu-default-args", "", OptsParser::AT_NONE},
117
{Config::SET_OPTION, NULL, "gnu-extended-asm", "", OptsParser::AT_NONE},
118
{Config::SET_OPTION, NULL, "gnu-extended-expr", "", OptsParser::AT_NONE},
119
{Config::SET_OPTION, NULL, "gnu-long-long", "", OptsParser::AT_NONE},
120
{Config::SET_OPTION, NULL, "gnu-name-scope", "", OptsParser::AT_NONE},
121
{Config::SET_OPTION, NULL, "gnu-implicit-int", "", OptsParser::AT_NONE},
122
{Config::SET_OPTION, NULL, "gnu-fct-attribute", "", OptsParser::AT_NONE},
123
{Config::SET_OPTION, NULL, "gnu-if-then-expr", "", OptsParser::AT_NONE},
124
{Config::SET_OPTION, NULL, "gnu-std-hack", "", OptsParser::AT_NONE},
125
{Config::SET_OPTION, NULL, "gnu", "Support gnu extensions", OptsParser::AT_NONE},
126
{Config::SET_OPTION, NULL, "gnu-2.95", "Support gnu extensions for g++ 2.95", OptsParser::AT_NONE},
127
{Config::SET_OPTION, NULL, "vc", "Support Visual C++ extensions", OptsParser::AT_NONE},
128
{Config::SET_OPTION_ARG, NULL, "import-handler", "Handler for #import directives", OptsParser::AT_MANDATORY},
129
{Config::SET_OPTION_ARG, NULL, "include", "Always include file", OptsParser::AT_MANDATORY},
130
{Config::SET_OPTION_ARG, NULL, "size-type", "Internal type for size_t", OptsParser::AT_MANDATORY},
131
{Config::SET_OPTION_ARG, NULL, "ptrdiff-type", "Internal type for ptrdiff_t", OptsParser::AT_MANDATORY},
132
{Config::SET_OPTION_ARG, NULL, "inhibit-macro", "Prevent a preprocessor macro for being defined", OptsParser::AT_MANDATORY},
94
{Config::SET_OPTION, NULL, "real-instances", "Enable template instantiation", OptsParser::AT_NONE},
95
{Config::SET_OPTION_ARG, NULL, "template-depth", "Set the maximum instantiation depth for templates", OptsParser::AT_MANDATORY},
96
{Config::SET_OPTION, NULL, "match-expr", "Enable parsing match expressions", OptsParser::AT_NONE},
97
{Config::SET_OPTION_ARG, NULL, "import-handler", "Set handler for Visual C++ #import directives", OptsParser::AT_MANDATORY},
98
{Config::SET_OPTION_ARG, NULL, "include", "Add file to be included at the beginning of every source file", OptsParser::AT_MANDATORY},
99
{Config::SET_OPTION_ARG, NULL, "size-type", "Set type for size_t", OptsParser::AT_MANDATORY},
100
{Config::SET_OPTION_ARG, NULL, "ptrdiff-type", "Set type for ptrdiff_t", OptsParser::AT_MANDATORY},
133
101
{0, 0, 0, 0, OptsParser::AT_NONE}
106
void Config::PrintOptions(std::ostream& os) const {
107
// first print short options with description
108
for (int i = 0; pumaOpts[i].number > 0; i++) {
109
if (pumaOpts[i].shortName && pumaOpts[i].desc && strlen(pumaOpts[i].desc)) {
110
PrintOption(pumaOpts[i], os);
113
// then print long options with description
114
for (int i = 0; pumaOpts[i].number > 0; i++) {
115
if (! pumaOpts[i].shortName && pumaOpts[i].desc && strlen(pumaOpts[i].desc)) {
116
PrintOption(pumaOpts[i], os);
119
// then print options without description
120
for (int i = 0; pumaOpts[i].number > 0; i++) {
121
if (! pumaOpts[i].desc || strlen(pumaOpts[i].desc)==0) {
122
PrintOption(pumaOpts[i], os);
128
// print a single option
129
void Config::PrintOption(OptsParser::Option& o, std::ostream& os) const {
131
os << " -" << o.shortName;
139
os << "--" << o.longName;
141
if (o.argType == OptsParser::AT_MANDATORY) {
144
if (o.argType == OptsParser::AT_OPTIONAL) {
148
os << "\033[35G" << o.desc;
137
154
void Config::Read (const char *file) {
142
155
// file not given, read from $PUMA_CONFIG or /etc/puma.config
156
bool default_loc = false;
144
file = getenv ("PUMA_CONFIG");
147
if ((fp = SysCall::fopen (file, "r")) == NULL) {
148
ERROR_MSG ("cannot open config file `" << file << "'");
158
file = getenv("PUMA_CONFIG");
152
160
file = "/etc/puma.config"; // default location
153
if ((fp = SysCall::fopen (file, "r")) == NULL) {
158
while (fgets (buffer, 4000, fp)) {
159
// skip comments and newlines
160
if (buffer[0] != '#' || buffer[0] != '\n') {
166
SysCall::fclose (fp, &_err);
168
OptsParser optp (optstr, pumaOpts);
164
std::ifstream in(file);
167
ERROR_MSG("cannot open config file `" << file << "'");
172
std::ostringstream optstr;
175
std::getline(in, line);
176
// skip comments and empty lines
177
if (! line.empty() && line[0] != '#') {
178
ReplaceEnvVars(line);
179
optstr << " " << line;
184
OptsParser optp(optstr.str(), pumaOpts);
170
186
// process the given options
171
187
while (optp.getOption () != OptsParser::FINISH) {
172
Process (optp, true);