Style police on api.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
diff --git a/api.c b/api.c
index b381393..2622b16 100644
--- a/api.c
+++ b/api.c
@@ -580,19 +580,19 @@ static char *escape_string(char *str, bool isjson)
count = 0;
for (ptr = str; *ptr; ptr++) {
switch (*ptr) {
- case ',':
- case '|':
- case '=':
- if (!isjson)
- count++;
- break;
- case '"':
- if (isjson)
+ case ',':
+ case '|':
+ case '=':
+ if (!isjson)
+ count++;
+ break;
+ case '"':
+ if (isjson)
+ count++;
+ break;
+ case '\\':
count++;
- break;
- case '\\':
- count++;
- break;
+ break;
}
}
@@ -606,25 +606,25 @@ static char *escape_string(char *str, bool isjson)
ptr = buf;
while (*str)
switch (*str) {
- case ',':
- case '|':
- case '=':
- if (!isjson)
- *(ptr++) = '\\';
- *(ptr++) = *(str++);
- break;
- case '"':
- if (isjson)
+ case ',':
+ case '|':
+ case '=':
+ if (!isjson)
+ *(ptr++) = '\\';
+ *(ptr++) = *(str++);
+ break;
+ case '"':
+ if (isjson)
+ *(ptr++) = '\\';
+ *(ptr++) = *(str++);
+ break;
+ case '\\':
*(ptr++) = '\\';
- *(ptr++) = *(str++);
- break;
- case '\\':
- *(ptr++) = '\\';
- *(ptr++) = *(str++);
- break;
- default:
- *(ptr++) = *(str++);
- break;
+ *(ptr++) = *(str++);
+ break;
+ default:
+ *(ptr++) = *(str++);
+ break;
}
*ptr = '\0';
@@ -636,8 +636,7 @@ static struct api_data *api_add_extra(struct api_data *root, struct api_data *ex
{
struct api_data *tmp;
- if (root)
- {
+ if (root) {
if (extra) {
// extra tail
tmp = extra->prev;
@@ -654,8 +653,7 @@ static struct api_data *api_add_extra(struct api_data *root, struct api_data *ex
// root prev = extra tail
root->prev = tmp;
}
- }
- else
+ } else
root = extra;
return root;
@@ -695,61 +693,61 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
api_data->data = data;
else
switch(type) {
- case API_ESCAPE:
- case API_STRING:
- case API_CONST:
- api_data->data = (void *)malloc(strlen((char *)data) + 1);
- strcpy((char*)(api_data->data), (char *)data);
- break;
- case API_INT:
- api_data->data = (void *)malloc(sizeof(int));
- *((int *)(api_data->data)) = *((int *)data);
- break;
- case API_UINT:
- api_data->data = (void *)malloc(sizeof(unsigned int));
- *((unsigned int *)(api_data->data)) = *((unsigned int *)data);
- break;
- case API_UINT32:
- api_data->data = (void *)malloc(sizeof(uint32_t));
- *((uint32_t *)(api_data->data)) = *((uint32_t *)data);
- break;
- case API_UINT64:
- api_data->data = (void *)malloc(sizeof(uint64_t));
- *((uint64_t *)(api_data->data)) = *((uint64_t *)data);
- break;
- case API_DOUBLE:
- case API_ELAPSED:
- case API_MHS:
- case API_MHTOTAL:
- case API_UTILITY:
- case API_FREQ:
- case API_HS:
- api_data->data = (void *)malloc(sizeof(double));
- *((double *)(api_data->data)) = *((double *)data);
- break;
- case API_BOOL:
- api_data->data = (void *)malloc(sizeof(bool));
- *((bool *)(api_data->data)) = *((bool *)data);
- break;
- case API_TIMEVAL:
- api_data->data = (void *)malloc(sizeof(struct timeval));
- memcpy(api_data->data, data, sizeof(struct timeval));
- break;
- case API_TIME:
- api_data->data = (void *)malloc(sizeof(time_t));
- *(time_t *)(api_data->data) = *((time_t *)data);
- break;
- case API_VOLTS:
- case API_TEMP:
- api_data->data = (void *)malloc(sizeof(float));
- *((float *)(api_data->data)) = *((float *)data);
- break;
- default:
- applog(LOG_ERR, "API: unknown1 data type %d ignored", type);
- api_data->type = API_STRING;
- api_data->data_was_malloc = false;
- api_data->data = (void *)UNKNOWN;
- break;
+ case API_ESCAPE:
+ case API_STRING:
+ case API_CONST:
+ api_data->data = (void *)malloc(strlen((char *)data) + 1);
+ strcpy((char*)(api_data->data), (char *)data);
+ break;
+ case API_INT:
+ api_data->data = (void *)malloc(sizeof(int));
+ *((int *)(api_data->data)) = *((int *)data);
+ break;
+ case API_UINT:
+ api_data->data = (void *)malloc(sizeof(unsigned int));
+ *((unsigned int *)(api_data->data)) = *((unsigned int *)data);
+ break;
+ case API_UINT32:
+ api_data->data = (void *)malloc(sizeof(uint32_t));
+ *((uint32_t *)(api_data->data)) = *((uint32_t *)data);
+ break;
+ case API_UINT64:
+ api_data->data = (void *)malloc(sizeof(uint64_t));
+ *((uint64_t *)(api_data->data)) = *((uint64_t *)data);
+ break;
+ case API_DOUBLE:
+ case API_ELAPSED:
+ case API_MHS:
+ case API_MHTOTAL:
+ case API_UTILITY:
+ case API_FREQ:
+ case API_HS:
+ api_data->data = (void *)malloc(sizeof(double));
+ *((double *)(api_data->data)) = *((double *)data);
+ break;
+ case API_BOOL:
+ api_data->data = (void *)malloc(sizeof(bool));
+ *((bool *)(api_data->data)) = *((bool *)data);
+ break;
+ case API_TIMEVAL:
+ api_data->data = (void *)malloc(sizeof(struct timeval));
+ memcpy(api_data->data, data, sizeof(struct timeval));
+ break;
+ case API_TIME:
+ api_data->data = (void *)malloc(sizeof(time_t));
+ *(time_t *)(api_data->data) = *((time_t *)data);
+ break;
+ case API_VOLTS:
+ case API_TEMP:
+ api_data->data = (void *)malloc(sizeof(float));
+ *((float *)(api_data->data)) = *((float *)data);
+ break;
+ default:
+ applog(LOG_ERR, "API: unknown1 data type %d ignored", type);
+ api_data->type = API_STRING;
+ api_data->data_was_malloc = false;
+ api_data->data = (void *)UNKNOWN;
+ break;
}
return root;
@@ -875,67 +873,67 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
buf = strchr(buf, '\0');
switch(root->type) {
- case API_STRING:
- case API_CONST:
- sprintf(buf, "%s%s%s", quote, (char *)(root->data), quote);
- break;
- case API_ESCAPE:
- original = (char *)(root->data);
- escape = escape_string((char *)(root->data), isjson);
- sprintf(buf, "%s%s%s", quote, escape, quote);
- if (escape != original)
- free(escape);
- break;
- case API_INT:
- sprintf(buf, "%d", *((int *)(root->data)));
- break;
- case API_UINT:
- sprintf(buf, "%u", *((unsigned int *)(root->data)));
- break;
- case API_UINT32:
- sprintf(buf, "%"PRIu32, *((uint32_t *)(root->data)));
- break;
- case API_UINT64:
- sprintf(buf, "%"PRIu64, *((uint64_t *)(root->data)));
- break;
- case API_TIME:
- sprintf(buf, "%lu", *((unsigned long *)(root->data)));
- break;
- case API_DOUBLE:
- sprintf(buf, "%f", *((double *)(root->data)));
- break;
- case API_ELAPSED:
- sprintf(buf, "%.0f", *((double *)(root->data)));
- break;
- case API_UTILITY:
- case API_FREQ:
- case API_MHS:
- sprintf(buf, "%.2f", *((double *)(root->data)));
- break;
- case API_VOLTS:
- sprintf(buf, "%.3f", *((float *)(root->data)));
- break;
- case API_MHTOTAL:
- sprintf(buf, "%.4f", *((double *)(root->data)));
- break;
- case API_HS:
- sprintf(buf, "%.15f", *((double *)(root->data)));
- break;
- case API_BOOL:
- sprintf(buf, "%s", *((bool *)(root->data)) ? "true" : "false");
- break;
- case API_TIMEVAL:
- sprintf(buf, "%ld.%06ld",
- ((struct timeval *)(root->data))->tv_sec,
- ((struct timeval *)(root->data))->tv_usec);
- break;
- case API_TEMP:
- sprintf(buf, "%.2f", *((float *)(root->data)));
- break;
- default:
- applog(LOG_ERR, "API: unknown2 data type %d ignored", root->type);
- sprintf(buf, "%s%s%s", quote, UNKNOWN, quote);
- break;
+ case API_STRING:
+ case API_CONST:
+ sprintf(buf, "%s%s%s", quote, (char *)(root->data), quote);
+ break;
+ case API_ESCAPE:
+ original = (char *)(root->data);
+ escape = escape_string((char *)(root->data), isjson);
+ sprintf(buf, "%s%s%s", quote, escape, quote);
+ if (escape != original)
+ free(escape);
+ break;
+ case API_INT:
+ sprintf(buf, "%d", *((int *)(root->data)));
+ break;
+ case API_UINT:
+ sprintf(buf, "%u", *((unsigned int *)(root->data)));
+ break;
+ case API_UINT32:
+ sprintf(buf, "%"PRIu32, *((uint32_t *)(root->data)));
+ break;
+ case API_UINT64:
+ sprintf(buf, "%"PRIu64, *((uint64_t *)(root->data)));
+ break;
+ case API_TIME:
+ sprintf(buf, "%lu", *((unsigned long *)(root->data)));
+ break;
+ case API_DOUBLE:
+ sprintf(buf, "%f", *((double *)(root->data)));
+ break;
+ case API_ELAPSED:
+ sprintf(buf, "%.0f", *((double *)(root->data)));
+ break;
+ case API_UTILITY:
+ case API_FREQ:
+ case API_MHS:
+ sprintf(buf, "%.2f", *((double *)(root->data)));
+ break;
+ case API_VOLTS:
+ sprintf(buf, "%.3f", *((float *)(root->data)));
+ break;
+ case API_MHTOTAL:
+ sprintf(buf, "%.4f", *((double *)(root->data)));
+ break;
+ case API_HS:
+ sprintf(buf, "%.15f", *((double *)(root->data)));
+ break;
+ case API_BOOL:
+ sprintf(buf, "%s", *((bool *)(root->data)) ? "true" : "false");
+ break;
+ case API_TIMEVAL:
+ sprintf(buf, "%ld.%06ld",
+ ((struct timeval *)(root->data))->tv_sec,
+ ((struct timeval *)(root->data))->tv_usec);
+ break;
+ case API_TEMP:
+ sprintf(buf, "%.2f", *((float *)(root->data)));
+ break;
+ default:
+ applog(LOG_ERR, "API: unknown2 data type %d ignored", root->type);
+ sprintf(buf, "%s%s%s", quote, UNKNOWN, quote);
+ break;
}
buf = strchr(buf, '\0');
@@ -1043,92 +1041,92 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
for (i = 0; codes[i].severity != SEVERITY_FAIL; i++) {
if (codes[i].code == messageid) {
switch (codes[i].severity) {
- case SEVERITY_WARN:
- severity[0] = 'W';
- break;
- case SEVERITY_INFO:
- severity[0] = 'I';
- break;
- case SEVERITY_SUCC:
- severity[0] = 'S';
- break;
- case SEVERITY_ERR:
- default:
- severity[0] = 'E';
- break;
+ case SEVERITY_WARN:
+ severity[0] = 'W';
+ break;
+ case SEVERITY_INFO:
+ severity[0] = 'I';
+ break;
+ case SEVERITY_SUCC:
+ severity[0] = 'S';
+ break;
+ case SEVERITY_ERR:
+ default:
+ severity[0] = 'E';
+ break;
}
severity[1] = '\0';
switch(codes[i].params) {
- case PARAM_GPU:
- case PARAM_PGA:
- case PARAM_CPU:
- sprintf(buf, codes[i].description, paramid);
- break;
- case PARAM_POOL:
- sprintf(buf, codes[i].description, paramid, pools[paramid]->rpc_url);
- break;
+ case PARAM_GPU:
+ case PARAM_PGA:
+ case PARAM_CPU:
+ sprintf(buf, codes[i].description, paramid);
+ break;
+ case PARAM_POOL:
+ sprintf(buf, codes[i].description, paramid, pools[paramid]->rpc_url);
+ break;
#ifdef HAVE_OPENCL
- case PARAM_GPUMAX:
- sprintf(buf, codes[i].description, paramid, nDevs - 1);
- break;
+ case PARAM_GPUMAX:
+ sprintf(buf, codes[i].description, paramid, nDevs - 1);
+ break;
#endif
#ifdef HAVE_AN_FPGA
- case PARAM_PGAMAX:
- pga = numpgas();
- sprintf(buf, codes[i].description, paramid, pga - 1);
- break;
+ case PARAM_PGAMAX:
+ pga = numpgas();
+ sprintf(buf, codes[i].description, paramid, pga - 1);
+ break;
#endif
#ifdef WANT_CPUMINE
- case PARAM_CPUMAX:
- if (opt_n_threads > 0)
- cpu = num_processors;
- else
- cpu = 0;
- sprintf(buf, codes[i].description, paramid, cpu - 1);
- break;
+ case PARAM_CPUMAX:
+ if (opt_n_threads > 0)
+ cpu = num_processors;
+ else
+ cpu = 0;
+ sprintf(buf, codes[i].description, paramid, cpu - 1);
+ break;
#endif
- case PARAM_PMAX:
- sprintf(buf, codes[i].description, total_pools);
- break;
- case PARAM_POOLMAX:
- sprintf(buf, codes[i].description, paramid, total_pools - 1);
- break;
- case PARAM_DMAX:
+ case PARAM_PMAX:
+ sprintf(buf, codes[i].description, total_pools);
+ break;
+ case PARAM_POOLMAX:
+ sprintf(buf, codes[i].description, paramid, total_pools - 1);
+ break;
+ case PARAM_DMAX:
#ifdef HAVE_AN_FPGA
- pga = numpgas();
+ pga = numpgas();
#endif
#ifdef WANT_CPUMINE
- if (opt_n_threads > 0)
- cpu = num_processors;
- else
- cpu = 0;
+ if (opt_n_threads > 0)
+ cpu = num_processors;
+ else
+ cpu = 0;
#endif
- sprintf(buf, codes[i].description
+ sprintf(buf, codes[i].description
#ifdef HAVE_OPENCL
- , nDevs
+ , nDevs
#endif
#ifdef HAVE_AN_FPGA
- , pga
+ , pga
#endif
#ifdef WANT_CPUMINE
- , cpu
+ , cpu
#endif
- );
- break;
- case PARAM_CMD:
- sprintf(buf, codes[i].description, JSON_COMMAND);
- break;
- case PARAM_STR:
- sprintf(buf, codes[i].description, param2);
- break;
- case PARAM_BOTH:
- sprintf(buf, codes[i].description, paramid, param2);
- break;
- case PARAM_NONE:
- default:
- strcpy(buf, codes[i].description);
+ );
+ break;
+ case PARAM_CMD:
+ sprintf(buf, codes[i].description, JSON_COMMAND);
+ break;
+ case PARAM_STR:
+ sprintf(buf, codes[i].description, param2);
+ break;
+ case PARAM_BOTH:
+ sprintf(buf, codes[i].description, paramid, param2);
+ break;
+ case PARAM_NONE:
+ default:
+ strcpy(buf, codes[i].description);
}
root = api_add_string(root, _STATUS, severity, false);
@@ -1464,7 +1462,7 @@ static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, b
}
#endif
#ifdef HAVE_AN_FPGA
- if (numpga > 0)
+ if (numpga > 0) {
for (i = 0; i < numpga; i++) {
if (isjson && devcount > 0)
strcat(io_buffer, COMMA);
@@ -1473,10 +1471,11 @@ static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, b
devcount++;
}
+ }
#endif
#ifdef WANT_CPUMINE
- if (opt_n_threads > 0)
+ if (opt_n_threads > 0) {
for (i = 0; i < num_processors; i++) {
if (isjson && devcount > 0)
strcat(io_buffer, COMMA);
@@ -1485,6 +1484,7 @@ static void devstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, b
devcount++;
}
+ }
#endif
if (isjson)
@@ -1714,21 +1714,21 @@ static void poolstatus(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
struct pool *pool = pools[i];
switch (pool->enabled) {
- case POOL_DISABLED:
- status = (char *)DISABLED;
- break;
- case POOL_REJECTING:
- status = (char *)REJECTING;
- break;
- case POOL_ENABLED:
- if (pool->idle)
- status = (char *)DEAD;
- else
- status = (char *)ALIVE;
- break;
- default:
- status = (char *)UNKNOWN;
- break;
+ case POOL_DISABLED:
+ status = (char *)DISABLED;
+ break;
+ case POOL_REJECTING:
+ status = (char *)REJECTING;
+ break;
+ case POOL_ENABLED:
+ if (pool->idle)
+ status = (char *)DEAD;
+ else
+ status = (char *)ALIVE;
+ break;
+ default:
+ status = (char *)UNKNOWN;
+ break;
}
if (pool->hdr_path)
@@ -2395,33 +2395,33 @@ void notifystatus(int device, struct cgpu_info *cgpu, bool isjson, __maybe_unuse
reason = REASON_NONE;
else
switch(cgpu->device_not_well_reason) {
- case REASON_THREAD_FAIL_INIT:
- reason = REASON_THREAD_FAIL_INIT_STR;
- break;
- case REASON_THREAD_ZERO_HASH:
- reason = REASON_THREAD_ZERO_HASH_STR;
- break;
- case REASON_THREAD_FAIL_QUEUE:
- reason = REASON_THREAD_FAIL_QUEUE_STR;
- break;
- case REASON_DEV_SICK_IDLE_60:
- reason = REASON_DEV_SICK_IDLE_60_STR;
- break;
- case REASON_DEV_DEAD_IDLE_600:
- reason = REASON_DEV_DEAD_IDLE_600_STR;
- break;
- case REASON_DEV_NOSTART:
- reason = REASON_DEV_NOSTART_STR;
- break;
- case REASON_DEV_OVER_HEAT:
- reason = REASON_DEV_OVER_HEAT_STR;
- break;
- case REASON_DEV_THERMAL_CUTOFF:
- reason = REASON_DEV_THERMAL_CUTOFF_STR;
- break;
- default:
- reason = REASON_UNKNOWN_STR;
- break;
+ case REASON_THREAD_FAIL_INIT:
+ reason = REASON_THREAD_FAIL_INIT_STR;
+ break;
+ case REASON_THREAD_ZERO_HASH:
+ reason = REASON_THREAD_ZERO_HASH_STR;
+ break;
+ case REASON_THREAD_FAIL_QUEUE:
+ reason = REASON_THREAD_FAIL_QUEUE_STR;
+ break;
+ case REASON_DEV_SICK_IDLE_60:
+ reason = REASON_DEV_SICK_IDLE_60_STR;
+ break;
+ case REASON_DEV_DEAD_IDLE_600:
+ reason = REASON_DEV_DEAD_IDLE_600_STR;
+ break;
+ case REASON_DEV_NOSTART:
+ reason = REASON_DEV_NOSTART_STR;
+ break;
+ case REASON_DEV_OVER_HEAT:
+ reason = REASON_DEV_OVER_HEAT_STR;
+ break;
+ case REASON_DEV_THERMAL_CUTOFF:
+ reason = REASON_DEV_THERMAL_CUTOFF_STR;
+ break;
+ default:
+ reason = REASON_UNKNOWN_STR;
+ break;
}
// ALL counters (and only counters) must start the name with a '*'