Browse Source

Provide simple macros for the repeated use of checking the first value of the input char with strncasecmp.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
87708a6a0e
  1. 32
      adl.c
  2. 60
      cgminer.c
  3. 10
      driver-opencl.c
  4. 3
      miner.h

32
adl.c

@ -1198,34 +1198,34 @@ void change_autosettings(int gpu)
wlogprint("Toggle [F]an auto [G]PU auto\nChange [T]arget [O]verheat [C]utoff\n"); wlogprint("Toggle [F]an auto [G]PU auto\nChange [T]arget [O]verheat [C]utoff\n");
wlogprint("Or press any other key to continue\n"); wlogprint("Or press any other key to continue\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "f", 1)) { if (INPUTEQ(f)) {
ga->autofan ^= true; ga->autofan ^= true;
wlogprint("Fan autotune is now %s\n", ga->autofan ? "enabled" : "disabled"); wlogprint("Fan autotune is now %s\n", ga->autofan ? "enabled" : "disabled");
if (!ga->autofan) { if (!ga->autofan) {
wlogprint("Resetting fan to startup settings\n"); wlogprint("Resetting fan to startup settings\n");
set_defaultfan(gpu); set_defaultfan(gpu);
} }
} else if (!strncasecmp(&input, "g", 1)) { } else if (INPUTEQ(g)) {
ga->autoengine ^= true; ga->autoengine ^= true;
wlogprint("GPU engine clock autotune is now %s\n", ga->autoengine ? "enabled" : "disabled"); wlogprint("GPU engine clock autotune is now %s\n", ga->autoengine ? "enabled" : "disabled");
if (!ga->autoengine) { if (!ga->autoengine) {
wlogprint("Resetting GPU engine clock to startup settings\n"); wlogprint("Resetting GPU engine clock to startup settings\n");
set_defaultengine(gpu); set_defaultengine(gpu);
} }
} else if (!strncasecmp(&input, "t", 1)) { } else if (INPUTEQ(t)) {
val = curses_int("Enter target temperature for this GPU in C (0-200)"); val = curses_int("Enter target temperature for this GPU in C (0-200)");
if (val < 0 || val > 200) if (val < 0 || val > 200)
wlogprint("Invalid temperature"); wlogprint("Invalid temperature");
else else
ga->targettemp = val; ga->targettemp = val;
} else if (!strncasecmp(&input, "o", 1)) { } else if (INPUTEQ(o)) {
wlogprint("Enter overheat temperature for this GPU in C (%d+)", ga->targettemp); wlogprint("Enter overheat temperature for this GPU in C (%d+)", ga->targettemp);
val = curses_int(""); val = curses_int("");
if (val <= ga->targettemp || val > 200) if (val <= ga->targettemp || val > 200)
wlogprint("Invalid temperature"); wlogprint("Invalid temperature");
else else
ga->overtemp = val; ga->overtemp = val;
} else if (!strncasecmp(&input, "c", 1)) { } else if (INPUTEQ(c)) {
wlogprint("Enter cutoff temperature for this GPU in C (%d+)", ga->overtemp); wlogprint("Enter cutoff temperature for this GPU in C (%d+)", ga->overtemp);
val = curses_int(""); val = curses_int("");
if (val <= ga->overtemp || val > 200) if (val <= ga->overtemp || val > 200)
@ -1265,70 +1265,70 @@ updated:
wlogprint("Or press any other key to continue\n"); wlogprint("Or press any other key to continue\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "a", 1)) { if (INPUTEQ(a)) {
change_autosettings(gpu); change_autosettings(gpu);
} else if (!strncasecmp(&input, "e", 1)) { } else if (INPUTEQ(e)) {
get_enginerange(gpu, &imin, &imax); get_enginerange(gpu, &imin, &imax);
wlogprint("Enter GPU engine clock speed (%d - %d Mhz)", imin, imax); wlogprint("Enter GPU engine clock speed (%d - %d Mhz)", imin, imax);
val = curses_int(""); val = curses_int("");
if (val < imin || val > imax) { if (val < imin || val > imax) {
wlogprint("Value is outside safe range, are you sure?\n"); wlogprint("Value is outside safe range, are you sure?\n");
input = getch(); input = getch();
if (strncasecmp(&input, "y", 1)) if (INPUTNEQ(y))
return; return;
} }
if (!set_engineclock(gpu, val)) if (!set_engineclock(gpu, val))
wlogprint("Driver reports success but check values below\n"); wlogprint("Driver reports success but check values below\n");
else else
wlogprint("Failed to modify engine clock speed\n"); wlogprint("Failed to modify engine clock speed\n");
} else if (!strncasecmp(&input, "f", 1)) { } else if (INPUTEQ(f)) {
get_fanrange(gpu, &imin, &imax); get_fanrange(gpu, &imin, &imax);
wlogprint("Enter fan percentage (%d - %d %)", imin, imax); wlogprint("Enter fan percentage (%d - %d %)", imin, imax);
val = curses_int(""); val = curses_int("");
if (val < imin || val > imax) { if (val < imin || val > imax) {
wlogprint("Value is outside safe range, are you sure?\n"); wlogprint("Value is outside safe range, are you sure?\n");
input = getch(); input = getch();
if (strncasecmp(&input, "y", 1)) if (INPUTNEQ(y))
return; return;
} }
if (!set_fanspeed(gpu, val)) if (!set_fanspeed(gpu, val))
wlogprint("Driver reports success but check values below\n"); wlogprint("Driver reports success but check values below\n");
else else
wlogprint("Failed to modify fan speed\n"); wlogprint("Failed to modify fan speed\n");
} else if (!strncasecmp(&input, "m", 1)) { } else if (INPUTEQ(m)) {
get_memoryrange(gpu, &imin, &imax); get_memoryrange(gpu, &imin, &imax);
wlogprint("Enter GPU memory clock speed (%d - %d Mhz)", imin, imax); wlogprint("Enter GPU memory clock speed (%d - %d Mhz)", imin, imax);
val = curses_int(""); val = curses_int("");
if (val < imin || val > imax) { if (val < imin || val > imax) {
wlogprint("Value is outside safe range, are you sure?\n"); wlogprint("Value is outside safe range, are you sure?\n");
input = getch(); input = getch();
if (strncasecmp(&input, "y", 1)) if (INPUTNEQ(y))
return; return;
} }
if (!set_memoryclock(gpu, val)) if (!set_memoryclock(gpu, val))
wlogprint("Driver reports success but check values below\n"); wlogprint("Driver reports success but check values below\n");
else else
wlogprint("Failed to modify memory clock speed\n"); wlogprint("Failed to modify memory clock speed\n");
} else if (!strncasecmp(&input, "v", 1)) { } else if (INPUTEQ(v)) {
get_vddcrange(gpu, &fmin, &fmax); get_vddcrange(gpu, &fmin, &fmax);
wlogprint("Enter GPU voltage (%.3f - %.3f V)", fmin, fmax); wlogprint("Enter GPU voltage (%.3f - %.3f V)", fmin, fmax);
fval = curses_float(""); fval = curses_float("");
if (fval < fmin || fval > fmax) { if (fval < fmin || fval > fmax) {
wlogprint("Value is outside safe range, are you sure?\n"); wlogprint("Value is outside safe range, are you sure?\n");
input = getch(); input = getch();
if (strncasecmp(&input, "y", 1)) if (INPUTNEQ(y))
return; return;
} }
if (!set_vddc(gpu, fval)) if (!set_vddc(gpu, fval))
wlogprint("Driver reports success but check values below\n"); wlogprint("Driver reports success but check values below\n");
else else
wlogprint("Failed to modify voltage\n"); wlogprint("Failed to modify voltage\n");
} else if (!strncasecmp(&input, "p", 1)) { } else if (INPUTEQ(p)) {
val = curses_int("Enter powertune value (-20 - 20)"); val = curses_int("Enter powertune value (-20 - 20)");
if (val < -20 || val > 20) { if (val < -20 || val > 20) {
wlogprint("Value is outside safe range, are you sure?\n"); wlogprint("Value is outside safe range, are you sure?\n");
input = getch(); input = getch();
if (strncasecmp(&input, "y", 1)) if (INPUTNEQ(y))
return; return;
} }
if (!set_powertune(gpu, val)) if (!set_powertune(gpu, val))

60
cgminer.c

@ -2814,10 +2814,10 @@ retry:
wlogprint("Or press any other key to continue\n"); wlogprint("Or press any other key to continue\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "a", 1)) { if (INPUTEQ(a)) {
input_pool(true); input_pool(true);
goto updated; goto updated;
} else if (!strncasecmp(&input, "r", 1)) { } else if (INPUTEQ(r)) {
if (total_pools <= 1) { if (total_pools <= 1) {
wlogprint("Cannot remove last pool"); wlogprint("Cannot remove last pool");
goto retry; goto retry;
@ -2837,7 +2837,7 @@ retry:
pool->enabled = POOL_DISABLED; pool->enabled = POOL_DISABLED;
remove_pool(pool); remove_pool(pool);
goto updated; goto updated;
} else if (!strncasecmp(&input, "s", 1)) { } else if (INPUTEQ(s)) {
selected = curses_int("Select pool number"); selected = curses_int("Select pool number");
if (selected < 0 || selected >= total_pools) { if (selected < 0 || selected >= total_pools) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -2847,7 +2847,7 @@ retry:
pool->enabled = POOL_ENABLED; pool->enabled = POOL_ENABLED;
switch_pools(pool); switch_pools(pool);
goto updated; goto updated;
} else if (!strncasecmp(&input, "d", 1)) { } else if (INPUTEQ(d)) {
if (active_pools() <= 1) { if (active_pools() <= 1) {
wlogprint("Cannot disable last pool"); wlogprint("Cannot disable last pool");
goto retry; goto retry;
@ -2862,7 +2862,7 @@ retry:
if (pool == current_pool()) if (pool == current_pool())
switch_pools(NULL); switch_pools(NULL);
goto updated; goto updated;
} else if (!strncasecmp(&input, "e", 1)) { } else if (INPUTEQ(e)) {
selected = curses_int("Select pool number"); selected = curses_int("Select pool number");
if (selected < 0 || selected >= total_pools) { if (selected < 0 || selected >= total_pools) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -2873,7 +2873,7 @@ retry:
if (pool->prio < current_pool()->prio) if (pool->prio < current_pool()->prio)
switch_pools(pool); switch_pools(pool);
goto updated; goto updated;
} else if (!strncasecmp(&input, "c", 1)) { } else if (INPUTEQ(c)) {
for (i = 0; i <= TOP_STRATEGY; i++) for (i = 0; i <= TOP_STRATEGY; i++)
wlogprint("%d: %s\n", i, strategies[i]); wlogprint("%d: %s\n", i, strategies[i]);
selected = curses_int("Select strategy number type"); selected = curses_int("Select strategy number type");
@ -2893,7 +2893,7 @@ retry:
pool_strategy = selected; pool_strategy = selected;
switch_pools(NULL); switch_pools(NULL);
goto updated; goto updated;
} else if (!strncasecmp(&input, "i", 1)) { } else if (INPUTEQ(i)) {
selected = curses_int("Select pool number"); selected = curses_int("Select pool number");
if (selected < 0 || selected >= total_pools) { if (selected < 0 || selected >= total_pools) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -2928,17 +2928,17 @@ retry:
opt_log_interval); opt_log_interval);
wlogprint("Select an option or any other key to return\n"); wlogprint("Select an option or any other key to return\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "q", 1)) { if (INPUTEQ(q)) {
opt_quiet ^= true; opt_quiet ^= true;
wlogprint("Quiet mode %s\n", opt_quiet ? "enabled" : "disabled"); wlogprint("Quiet mode %s\n", opt_quiet ? "enabled" : "disabled");
goto retry; goto retry;
} else if (!strncasecmp(&input, "v", 1)) { } else if (INPUTEQ(v)) {
opt_log_output ^= true; opt_log_output ^= true;
if (opt_log_output) if (opt_log_output)
opt_quiet = false; opt_quiet = false;
wlogprint("Verbose mode %s\n", opt_log_output ? "enabled" : "disabled"); wlogprint("Verbose mode %s\n", opt_log_output ? "enabled" : "disabled");
goto retry; goto retry;
} else if (!strncasecmp(&input, "n", 1)) { } else if (INPUTEQ(n)) {
opt_log_output = false; opt_log_output = false;
opt_debug = false; opt_debug = false;
opt_quiet = false; opt_quiet = false;
@ -2946,27 +2946,27 @@ retry:
want_per_device_stats = false; want_per_device_stats = false;
wlogprint("Output mode reset to normal\n"); wlogprint("Output mode reset to normal\n");
goto retry; goto retry;
} else if (!strncasecmp(&input, "d", 1)) { } else if (INPUTEQ(d)) {
opt_debug ^= true; opt_debug ^= true;
opt_log_output = opt_debug; opt_log_output = opt_debug;
if (opt_debug) if (opt_debug)
opt_quiet = false; opt_quiet = false;
wlogprint("Debug mode %s\n", opt_debug ? "enabled" : "disabled"); wlogprint("Debug mode %s\n", opt_debug ? "enabled" : "disabled");
goto retry; goto retry;
} else if (!strncasecmp(&input, "p", 1)) { } else if (INPUTEQ(p)) {
want_per_device_stats ^= true; want_per_device_stats ^= true;
opt_log_output = want_per_device_stats; opt_log_output = want_per_device_stats;
wlogprint("Per-device stats %s\n", want_per_device_stats ? "enabled" : "disabled"); wlogprint("Per-device stats %s\n", want_per_device_stats ? "enabled" : "disabled");
goto retry; goto retry;
} else if (!strncasecmp(&input, "r", 1)) { } else if (INPUTEQ(r)) {
opt_protocol ^= true; opt_protocol ^= true;
if (opt_protocol) if (opt_protocol)
opt_quiet = false; opt_quiet = false;
wlogprint("RPC protocol debugging %s\n", opt_protocol ? "enabled" : "disabled"); wlogprint("RPC protocol debugging %s\n", opt_protocol ? "enabled" : "disabled");
goto retry; goto retry;
} else if (!strncasecmp(&input, "c", 1)) } else if (INPUTEQ(c))
clear_logwin(); clear_logwin();
else if (!strncasecmp(&input, "l", 1)) { else if (INPUTEQ(l)) {
selected = curses_int("Interval in seconds"); selected = curses_int("Interval in seconds");
if (selected < 0 || selected > 9999) { if (selected < 0 || selected > 9999) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -2975,7 +2975,7 @@ retry:
opt_log_interval = selected; opt_log_interval = selected;
wlogprint("Log interval set to %d seconds\n", opt_log_interval); wlogprint("Log interval set to %d seconds\n", opt_log_interval);
goto retry; goto retry;
} else if (!strncasecmp(&input, "s", 1)) { } else if (INPUTEQ(s)) {
opt_realquiet = true; opt_realquiet = true;
} else } else
clear_logwin(); clear_logwin();
@ -3001,7 +3001,7 @@ retry:
wlogprint("Select an option or any other key to return\n"); wlogprint("Select an option or any other key to return\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "q", 1)) { if (INPUTEQ(q)) {
selected = curses_int("Extra work items to queue"); selected = curses_int("Extra work items to queue");
if (selected < 0 || selected > 9999) { if (selected < 0 || selected > 9999) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -3009,7 +3009,7 @@ retry:
} }
opt_queue = selected; opt_queue = selected;
goto retry; goto retry;
} else if (!strncasecmp(&input, "s", 1)) { } else if (INPUTEQ(s)) {
selected = curses_int("Set scantime in seconds"); selected = curses_int("Set scantime in seconds");
if (selected < 0 || selected > 9999) { if (selected < 0 || selected > 9999) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -3017,7 +3017,7 @@ retry:
} }
opt_scantime = selected; opt_scantime = selected;
goto retry; goto retry;
} else if (!strncasecmp(&input, "e", 1)) { } else if (INPUTEQ(e)) {
selected = curses_int("Set expiry time in seconds"); selected = curses_int("Set expiry time in seconds");
if (selected < 0 || selected > 9999) { if (selected < 0 || selected > 9999) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -3025,7 +3025,7 @@ retry:
} }
opt_expiry = selected; opt_expiry = selected;
goto retry; goto retry;
} else if (!strncasecmp(&input, "r", 1)) { } else if (INPUTEQ(r)) {
selected = curses_int("Retries before failing (-1 infinite)"); selected = curses_int("Retries before failing (-1 infinite)");
if (selected < -1 || selected > 9999) { if (selected < -1 || selected > 9999) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -3033,7 +3033,7 @@ retry:
} }
opt_retries = selected; opt_retries = selected;
goto retry; goto retry;
} else if (!strncasecmp(&input, "p", 1)) { } else if (INPUTEQ(p)) {
selected = curses_int("Seconds to pause before network retries"); selected = curses_int("Seconds to pause before network retries");
if (selected < 1 || selected > 9999) { if (selected < 1 || selected > 9999) {
wlogprint("Invalid selection\n"); wlogprint("Invalid selection\n");
@ -3041,7 +3041,7 @@ retry:
} }
opt_fail_pause = selected; opt_fail_pause = selected;
goto retry; goto retry;
} else if (!strncasecmp(&input, "w", 1)) { } else if (INPUTEQ(w)) {
FILE *fcfg; FILE *fcfg;
char *str, filename[PATH_MAX], prompt[PATH_MAX + 50]; char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
@ -3067,7 +3067,7 @@ retry:
if (!stat(filename, &statbuf)) { if (!stat(filename, &statbuf)) {
wlogprint("File exists, overwrite?\n"); wlogprint("File exists, overwrite?\n");
input = getch(); input = getch();
if (strncasecmp(&input, "y", 1)) if (INPUTNEQ(y))
goto retry; goto retry;
} }
} }
@ -3080,10 +3080,10 @@ retry:
fclose(fcfg); fclose(fcfg);
goto retry; goto retry;
} else if (!strncasecmp(&input, "c", 1)) { } else if (INPUTEQ(c)) {
wlogprint("Are you sure?\n"); wlogprint("Are you sure?\n");
input = getch(); input = getch();
if (!strncasecmp(&input, "y", 1)) if (INPUTEQ(y))
app_restart(); app_restart();
else else
clear_logwin(); clear_logwin();
@ -3105,16 +3105,16 @@ static void *input_thread(void __maybe_unused *userdata)
char input; char input;
input = getch(); input = getch();
if (!strncasecmp(&input, "q", 1)) { if (INPUTEQ(q)) {
kill_work(); kill_work();
return NULL; return NULL;
} else if (!strncasecmp(&input, "d", 1)) } else if (INPUTEQ(d))
display_options(); display_options();
else if (!strncasecmp(&input, "p", 1)) else if (INPUTEQ(p))
display_pools(); display_pools();
else if (!strncasecmp(&input, "s", 1)) else if (INPUTEQ(s))
set_options(); set_options();
else if (have_opencl && !strncasecmp(&input, "g", 1)) else if (have_opencl && INPUTEQ(g))
manage_gpu(); manage_gpu();
if (opt_realquiet) { if (opt_realquiet) {
disable_curses(); disable_curses();

10
driver-opencl.c

@ -663,7 +663,7 @@ retry:
selected = 0; selected = 0;
else else
selected = -1; selected = -1;
if (!strncasecmp(&input, "e", 1)) { if (INPUTEQ(e)) {
struct cgpu_info *cgpu; struct cgpu_info *cgpu;
if (selected) if (selected)
@ -693,7 +693,7 @@ retry:
tq_push(thr->q, &ping); tq_push(thr->q, &ping);
} }
goto retry; goto retry;
} if (!strncasecmp(&input, "d", 1)) { } if (INPUTEQ(d)) {
if (selected) if (selected)
selected = curses_int("Select GPU to disable"); selected = curses_int("Select GPU to disable");
if (selected < 0 || selected >= nDevs) { if (selected < 0 || selected >= nDevs) {
@ -706,7 +706,7 @@ retry:
} }
gpus[selected].deven = DEV_DISABLED; gpus[selected].deven = DEV_DISABLED;
goto retry; goto retry;
} else if (!strncasecmp(&input, "i", 1)) { } else if (INPUTEQ(i)) {
int intensity; int intensity;
char *intvar; char *intvar;
@ -739,7 +739,7 @@ retry:
wlogprint("Intensity on gpu %d set to %d\n", selected, intensity); wlogprint("Intensity on gpu %d set to %d\n", selected, intensity);
pause_dynamic_threads(selected); pause_dynamic_threads(selected);
goto retry; goto retry;
} else if (!strncasecmp(&input, "r", 1)) { } else if (INPUTEQ(r)) {
if (selected) if (selected)
selected = curses_int("Select GPU to attempt to restart"); selected = curses_int("Select GPU to attempt to restart");
if (selected < 0 || selected >= nDevs) { if (selected < 0 || selected >= nDevs) {
@ -749,7 +749,7 @@ retry:
wlogprint("Attempting to restart threads of GPU %d\n", selected); wlogprint("Attempting to restart threads of GPU %d\n", selected);
reinit_device(&gpus[selected]); reinit_device(&gpus[selected]);
goto retry; goto retry;
} else if (adl_active && (!strncasecmp(&input, "c", 1))) { } else if (adl_active && (INPUTEQ(c))) {
if (selected) if (selected)
selected = curses_int("Select GPU to change settings on"); selected = curses_int("Select GPU to change settings on");
if (selected < 0 || selected >= nDevs) { if (selected < 0 || selected >= nDevs) {

3
miner.h

@ -130,6 +130,9 @@ void *alloca (size_t);
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif #endif
#define INPUTEQ(X) (!strncasecmp(&input, ("X"), 1))
#define INPUTNEQ(X) (strncasecmp(&input, ("X"), 1))
enum alive { enum alive {
LIFE_WELL, LIFE_WELL,
LIFE_SICK, LIFE_SICK,

Loading…
Cancel
Save