1
/*****************************************************************
2
* Unipro UGENE - Integrated Bioinformatics Suite
3
* Copyright (C) 2008 Unipro, Russia (http://ugene.unipro.ru)
6
* This source code is distributed under the terms of the
7
* GNU General Public License. See the files COPYING and LICENSE
9
*****************************************************************/
13
#include "muscle_context.h"
14
typedef MuscleContext::options_struct::VALUE_OPT VALUE_OPT;
15
typedef MuscleContext::options_struct::FLAG_OPT FLAG_OPT;
17
static bool TestSetFlagOpt(const char *Arg)
19
MuscleContext *ctx = getMuscleContext();
20
int &FlagOptCount = ctx->options.FlagOptCount;
21
FLAG_OPT *FlagOpts = ctx->options.FlagOpts;
22
for (int i = 0; i < FlagOptCount; ++i)
23
if (!stricmp(Arg, FlagOpts[i].m_pstrName))
25
FlagOpts[i].m_bSet = true;
31
static bool TestSetValueOpt(const char *Arg, const char *Value)
33
MuscleContext *ctx = getMuscleContext();
34
VALUE_OPT *ValueOpts = ctx->options.ValueOpts;
35
int &ValueOptCount = ctx->options.ValueOptCount;
36
for (int i = 0; i < ValueOptCount; ++i)
37
if (!stricmp(Arg, ValueOpts[i].m_pstrName))
41
fprintf(stderr, "Option -%s must have value\n", Arg);
42
exit(EXIT_NotStarted);
44
ValueOpts[i].m_pstrValue = strsave(Value);
50
bool FlagOpt(const char *Name)
52
MuscleContext *ctx = getMuscleContext();
53
int &FlagOptCount = ctx->options.FlagOptCount;
54
FLAG_OPT *FlagOpts = ctx->options.FlagOpts;
55
for (int i = 0; i < FlagOptCount; ++i)
56
if (!stricmp(Name, FlagOpts[i].m_pstrName))
57
return FlagOpts[i].m_bSet;
58
Quit("FlagOpt(%s) invalid", Name);
62
const char *ValueOpt(const char *Name)
64
MuscleContext *ctx = getMuscleContext();
65
VALUE_OPT *ValueOpts = ctx->options.ValueOpts;
66
int &ValueOptCount = ctx->options.ValueOptCount;
67
for (int i = 0; i < ValueOptCount; ++i)
68
if (!stricmp(Name, ValueOpts[i].m_pstrName))
69
return ValueOpts[i].m_pstrValue;
70
Quit("ValueOpt(%s) invalid", Name);
74
void ProcessArgVect(int argc, char *argv[])
76
for (int iArgIndex = 0; iArgIndex < argc; )
78
const char *Arg = argv[iArgIndex];
81
fprintf(stderr, "Command-line option \"%s\" must start with '-'\n", Arg);
82
exit(EXIT_NotStarted);
84
const char *ArgName = Arg + 1;
85
if (TestSetFlagOpt(ArgName))
92
if (iArgIndex < argc - 1)
93
Value = argv[iArgIndex+1];
94
if (TestSetValueOpt(ArgName, Value))
99
fprintf(stderr, "Invalid command line option \"%s\"\n", ArgName);
101
exit(EXIT_NotStarted);
105
void ProcessArgStr(const char *ArgStr)
107
const int MAX_ARGS = 64;
108
char *argv[MAX_ARGS];
114
char *StrCopy = strsave(ArgStr);
119
while (char c = *Str)
129
if (argc >= MAX_ARGS)
130
Quit("Too many args in MUSCLE_CMDLINE");
135
ProcessArgVect(argc, argv);
141
MuscleContext *ctx = getMuscleContext();
142
int &FlagOptCount = ctx->options.FlagOptCount;
143
FLAG_OPT *FlagOpts = ctx->options.FlagOpts;
144
for (int i = 0; i < FlagOptCount; ++i)
145
Log("%s %d\n", FlagOpts[i].m_pstrName, FlagOpts[i].m_bSet);