Skip to content

Commit

Permalink
Add ranges to adapter's list.
Browse files Browse the repository at this point in the history
  • Loading branch information
matszpk committed Jun 11, 2016
1 parent 5668f62 commit 0a1f6aa
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions amdcovc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,42 @@ static void printAdaptersInfoVerbose(ADLMainControl& mainControl, int adaptersNu
}
}

static void parseAdaptersList(const char* string, std::vector<int>& adapters)
{
adapters.clear();
while (true)
{
char* endptr;
errno = 0;
int adapterIndex = strtol(string, &endptr, 10);
if (errno!=0 || endptr==string)
throw Error("Can't parse adapter index");

string = endptr;
if (*string == '-')
{ // if range
string++;
errno = 0;
int adapterIndexEnd = strtol(string, &endptr, 10);
if (errno!=0 || endptr==string)
throw Error("Can't parse adapter index");
string = endptr;
if (adapterIndex>adapterIndexEnd)
throw Error("Wrong range of adapter indices in adapter list");
for (int i = adapterIndex; i <= adapterIndexEnd; i++)
adapters.push_back(i);
}
else
adapters.push_back(adapterIndex);
if (*string==0)
break;
if (*string==',')
string++;
else
throw Error("Garbages at adapter list");
}
}

enum class OVCParamType
{
CORE_CLOCK,
Expand Down Expand Up @@ -903,27 +939,6 @@ static bool parseOVCParameter(const char* string, OVCParameter& param)
return true;
}

static void parseAdaptersList(const char* string, std::vector<int>& adapters)
{
adapters.clear();
while (true)
{
char* endptr;
errno = 0;
int adapterIndex = strtol(string, &endptr, 10);
if (errno!=0 || endptr==string)
throw Error("Can't parse adapter index");
adapters.push_back(adapterIndex);
string = endptr;
if (*string==0)
break;
if (*string==',')
string++;
else
throw Error("Garbages at adapter list");
}
}

struct FanSpeedSetup
{
double value;
Expand Down Expand Up @@ -1188,7 +1203,7 @@ static const char* helpAndUsageString =
"\n"
"List of options:\n"
" -a, --adapters=LIST print informations only for these adapters\n"
" List is comma-separated\n"
" List is comma-separated with ranges 'first-last'\n"
" -v, --verbose print verbose informations\n"
" --version print version\n"
" -?, --help print help\n"
Expand Down

0 comments on commit 0a1f6aa

Please sign in to comment.