ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Options2.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/glucose2/Sort.h"
23
25
26using namespace Gluco2;
27
28void Gluco2::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 printUsageAndExit(argc, argv);
36 else if (match(str, "-verb"))
37 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 if (strict && match(argv[i], "-"))
49 fprintf(stderr, "ERROR! Unknown flag \"%s\". Use '--%shelp' for help.\n", argv[i], Option::getHelpPrefixString()), exit(1);
50 else
51 argv[j++] = argv[i];
52 }
53 }
54 }
55
56 argc -= (i - j);
57}
58
59
60void Gluco2::setUsageHelp (const char* str){ Option::getUsageString() = str; }
61void Gluco2::setHelpPrefixStr (const char* str){ Option::getHelpPrefixString() = str; }
62void Gluco2::printUsageAndExit (int argc, char** argv, bool verbose)
63{
64 const char* usage = Option::getUsageString();
65 if (usage != NULL)
66 fprintf(stderr, usage, argv[0]);
67
69
70 const char* prev_cat = NULL;
71 const char* prev_type = NULL;
72
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;
76
77 if (cat != prev_cat)
78 fprintf(stderr, "\n%s OPTIONS:\n\n", cat);
79 else if (type != prev_type)
80 fprintf(stderr, "\n");
81
82 Option::getOptionList()[i]->help(verbose);
83
84 prev_cat = Option::getOptionList()[i]->category;
85 prev_type = Option::getOptionList()[i]->type_name;
86 }
87
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");
92 exit(0);
93}
94
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
static const char *& getHelpPrefixString()
Definition Options.h:62
static const char *& getUsageString()
Definition Options.h:61
static vec< Option * > & getOptionList()
Definition Options.h:60
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
usage()
Definition main.c:626
Definition Alg.h:28
void setUsageHelp(const char *str)
Definition Options2.cpp:60
void sort(T *array, int size, LessThan lt)
Definition Sort.h:58
void setHelpPrefixStr(const char *str)
Definition Options2.cpp:61
void printUsageAndExit(int argc, char **argv, bool verbose=false)
Definition Options2.cpp:62
void parseOptions(int &argc, char **argv, bool strict=false)
Definition Options2.cpp:28
VOID_HACK exit()