MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / next_word

Function next_word

tests/rotctl_parse.c:439–523  ·  view source on GitHub ↗

* function to get the next word from the command line or from stdin * until stdin exhausted. stdin is read if the special token '-' is * found on the command line. * * returns EOF when words exhausted * returns <0 is error number * returns >=0 when successful */

Source from the content-addressed store, hash-verified

437 * returns >=0 when successful
438 */
439static int next_word(char *buffer, int argc, const char **argv, int newline)
440{
441 int ret;
442 char c;
443 static int reading_stdin;
444
445 if (!reading_stdin)
446 {
447 if (optind >= argc)
448 {
449 return EOF;
450 }
451 else if (newline
452 && '-' == argv[optind][0]
453 && 1 == strlen(argv[optind]))
454 {
455
456 ++optind;
457 reading_stdin = 1;
458 }
459 }
460
461 if (reading_stdin)
462 {
463 do
464 {
465 do
466 {
467 ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]);
468 }
469 while (EINTR == ret);
470
471 if (ret > 0 && '#' == c)
472 {
473 do
474 {
475 ret = scanf("%*[^\n]");
476 }
477 while (EINTR == ret); /* consume comments */
478
479 ret = 0;
480 }
481 }
482 while (!ret);
483
484 if (EOF == ret)
485 {
486 reading_stdin = 0;
487 }
488 else if (ret < 0)
489 {
490 rig_debug(RIG_DEBUG_ERR, "scanf: %s\n", strerror(errno));
491 reading_stdin = 0;
492 }
493 else
494 {
495 buffer[0] = c;
496 buffer[1 == ret ? 1 : MAXARGSZ] = '\0';

Callers 1

rotctl_parseFunction · 0.70

Calls 1

rig_debugFunction · 0.85

Tested by

no test coverage detected