1 #define __STDC_FORMAT_MACROS
2 #define __STDC_LIMIT_MACROS
3 /**************************************************************************************[Options.cc]
4 Copyright (c) 2008-2010, Niklas Sorensson
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7 associated documentation files (the "Software"), to deal in the Software without restriction,
8 including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in all copies or
13 substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
19 OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 **************************************************************************************************/
24 #include "ParseUtils.h"
26 using namespace Minisat
;
28 void Minisat::parseOptions(int& argc
, char** argv
, bool strict
)
31 for (i
= j
= 1; i
< argc
; i
++){
32 const char* str
= argv
[i
];
33 if (match(str
, "--") && match(str
, Option::getHelpPrefixString()) && match(str
, "help")){
35 printUsageAndExit(argc
, argv
);
36 else if (match(str
, "-verb"))
37 printUsageAndExit(argc
, argv
, true);
39 bool parsed_ok
= false;
41 for (int k
= 0; !parsed_ok
&& k
< Option::getOptionList().size(); k
++){
42 parsed_ok
= Option::getOptionList()[k
]->parse(argv
[i
]);
44 // fprintf(stderr, "checking %d: %s against flag <%s> (%s)\n", i, argv[i], Option::getOptionList()[k]->name, parsed_ok ? "ok" : "skip");
48 if (strict
&& match(argv
[i
], "-"))
49 fprintf(stderr
, "ERROR! Unknown flag \"%s\". Use '--%shelp' for help.\n", argv
[i
], Option::getHelpPrefixString()), exit(1);
60 void Minisat::setUsageHelp (const char* str
){ Option::getUsageString() = str
; }
61 void Minisat::setHelpPrefixStr (const char* str
){ Option::getHelpPrefixString() = str
; }
62 void Minisat::printUsageAndExit (int /*argc*/, char** argv
, bool verbose
)
64 const char* usage
= Option::getUsageString();
66 fprintf(stderr
, usage
, argv
[0]);
68 sort(Option::getOptionList(), Option::OptionLt());
70 const char* prev_cat
= NULL
;
71 const char* prev_type
= NULL
;
73 for (int i
= 0; i
< Option::getOptionList().size(); i
++){
74 const char* cat
= Option::getOptionList()[i
]->category
;
75 const char* type
= Option::getOptionList()[i
]->type_name
;
78 fprintf(stderr
, "\n%s OPTIONS:\n\n", cat
);
79 else if (type
!= prev_type
)
80 fprintf(stderr
, "\n");
82 Option::getOptionList()[i
]->help(verbose
);
84 prev_cat
= Option::getOptionList()[i
]->category
;
85 prev_type
= Option::getOptionList()[i
]->type_name
;
88 fprintf(stderr
, "\nHELP OPTIONS:\n\n");
89 fprintf(stderr
, " --%shelp Print help message.\n", Option::getHelpPrefixString());
90 fprintf(stderr
, " --%shelp-verb Print verbose help message.\n", Option::getHelpPrefixString());
91 fprintf(stderr
, "\n");