ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Options.cpp
Go to the documentation of this file.
1/**************************************************************************************[Options.cc]
2Copyright (c) 2008-2010, Niklas Sorensson
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5associated documentation files (the "Software"), to deal in the Software without restriction,
6including without limitation the rights to use, copy, modify, merge, publish, distribute,
7sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8furnished to do so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all copies or
11substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
17OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18**************************************************************************************************/
19
20#include "sat/bsat2/Sort.h"
21#include "sat/bsat2/Options.h"
23
25
26using namespace Minisat;
27
28int Minisat::parseOptions(int& argc, char** argv, bool strict)
29{
30 int i, j;
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")){
34 if (*str == '\0')
35 return printUsageAndExit(argc, argv);
36 else if (match(str, "-verb"))
37 return printUsageAndExit(argc, argv, true);
38 } else {
39 bool parsed_ok = false;
40
41 for (int k = 0; !parsed_ok && k < Option::getOptionList().size(); k++){
42 parsed_ok = Option::getOptionList()[k]->parse(argv[i]);
43
44 // fprintf(stderr, "checking %d: %s against flag <%s> (%s)\n", i, argv[i], Option::getOptionList()[k]->name, parsed_ok ? "ok" : "skip");
45 }
46
47 if (!parsed_ok)
48 {
49 if (strict && match(argv[i], "-"))
50 { fprintf(stderr, "ERROR! Unknown flag \"%s\". Use '--%shelp' for help.\n", argv[i], Option::getHelpPrefixString()); return 0; } // exit(0);
51 else
52 argv[j++] = argv[i];
53 }
54 }
55 }
56
57 argc -= (i - j);
58 return 1;
59}
60
61
62void Minisat::setUsageHelp (const char* str){ Option::getUsageString() = str; }
64int Minisat::printUsageAndExit (int argc, char** argv, bool verbose)
65{
66 const char* usage = Option::getUsageString();
67 if (usage != NULL)
68 fprintf(stderr, usage, argv[0]);
69
71
72 const char* prev_cat = NULL;
73 const char* prev_type = NULL;
74
75 for (int i = 0; i < Option::getOptionList().size(); i++){
76 const char* cat = Option::getOptionList()[i]->category;
77 const char* type = Option::getOptionList()[i]->type_name;
78
79 if (cat != prev_cat)
80 fprintf(stderr, "\n%s OPTIONS:\n\n", cat);
81 else if (type != prev_type)
82 fprintf(stderr, "\n");
83
84 Option::getOptionList()[i]->help(verbose);
85
86 prev_cat = Option::getOptionList()[i]->category;
87 prev_type = Option::getOptionList()[i]->type_name;
88 }
89
90 fprintf(stderr, "\nHELP OPTIONS:\n\n");
91 fprintf(stderr, " --%shelp Print help message.\n", Option::getHelpPrefixString());
92 fprintf(stderr, " --%shelp-verb Print verbose help message.\n", Option::getHelpPrefixString());
93 fprintf(stderr, "\n");
94// exit(0);
95 return 0;
96}
97
98
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
static const char *& getUsageString()
Definition Options.h:59
static const char *& getHelpPrefixString()
Definition Options.h:60
static vec< Option * > & getOptionList()
Definition Options.h:58
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
usage()
Definition main.c:626
Definition Alg.h:28
void sort(T *array, int size, LessThan lt)
Definition Sort.h:58
void setUsageHelp(const char *str)
Definition Options.cpp:62
int printUsageAndExit(int argc, char **argv, bool verbose=false)
Definition Options.cpp:64
void setHelpPrefixStr(const char *str)
Definition Options.cpp:63
int parseOptions(int &argc, char **argv, bool strict=false)
Definition Options.cpp:28