656 char value[256];
657 if (sscanf(line, "%*[ \t]%255[a-zA-Z]%n", value, &bytes_read) == 1) {
658 if (strcmp(value, "true") == 0) {
659 total_bytes_read += bytes_read;
660 return add_option_string(c_name, c_match, m_name, m_match, signature, flag, true);
661 } else if (strcmp(value, "false") == 0) {
662 total_bytes_read += bytes_read;
663 return add_option_string(c_name, c_match, m_name, m_match, signature, flag, false);
664 } else {
665 jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
666 }
667 } else {
668 jio_snprintf(errorbuf, sizeof(errorbuf), " Value cannot be read for flag %s of type %s", flag, type);
669 }
670 } else if (strcmp(type, "double") == 0) {
671 char buffer[2][256];
672 // Decimal separator '.' has been replaced with ' ' or '/' earlier,
673 // so read integer and fraction part of double value separately.
674 if (sscanf(line, "%*[ \t]%255[0-9]%*[ /\t]%255[0-9]%n", buffer[0], buffer[1], &bytes_read) == 2) {
675 char value[512] = "";
676 strncat(value, buffer[0], 255);
677 strcat(value, ".");
678 strncat(value, buffer[1], 255);
679 total_bytes_read += bytes_read;
680 return add_option_string(c_name, c_match, m_name, m_match, signature, flag, atof(value));
681 } else {
682 jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
683 }
684 } else {
685 jio_snprintf(errorbuf, sizeof(errorbuf), " Type %s not supported ", type);
686 }
687 } else {
688 jio_snprintf(errorbuf, sizeof(errorbuf), " Flag name for type %s should be alphanumeric ", type);
689 }
690 return NULL;
691 }
692
693 int skip_whitespace(char* line) {
694 // Skip any leading spaces
695 int whitespace_read = 0;
696 sscanf(line, "%*[ \t]%n", &whitespace_read);
697 return whitespace_read;
698 }
|
656 char value[256];
657 if (sscanf(line, "%*[ \t]%255[a-zA-Z]%n", value, &bytes_read) == 1) {
658 if (strcmp(value, "true") == 0) {
659 total_bytes_read += bytes_read;
660 return add_option_string(c_name, c_match, m_name, m_match, signature, flag, true);
661 } else if (strcmp(value, "false") == 0) {
662 total_bytes_read += bytes_read;
663 return add_option_string(c_name, c_match, m_name, m_match, signature, flag, false);
664 } else {
665 jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
666 }
667 } else {
668 jio_snprintf(errorbuf, sizeof(errorbuf), " Value cannot be read for flag %s of type %s", flag, type);
669 }
670 } else if (strcmp(type, "double") == 0) {
671 char buffer[2][256];
672 // Decimal separator '.' has been replaced with ' ' or '/' earlier,
673 // so read integer and fraction part of double value separately.
674 if (sscanf(line, "%*[ \t]%255[0-9]%*[ /\t]%255[0-9]%n", buffer[0], buffer[1], &bytes_read) == 2) {
675 char value[512] = "";
676 jio_snprintf(value, sizeof(value), "%s.%s", buffer[0], buffer[1]);
677 total_bytes_read += bytes_read;
678 return add_option_string(c_name, c_match, m_name, m_match, signature, flag, atof(value));
679 } else {
680 jio_snprintf(errorbuf, buf_size, " Value cannot be read for flag %s of type %s", flag, type);
681 }
682 } else {
683 jio_snprintf(errorbuf, sizeof(errorbuf), " Type %s not supported ", type);
684 }
685 } else {
686 jio_snprintf(errorbuf, sizeof(errorbuf), " Flag name for type %s should be alphanumeric ", type);
687 }
688 return NULL;
689 }
690
691 int skip_whitespace(char* line) {
692 // Skip any leading spaces
693 int whitespace_read = 0;
694 sscanf(line, "%*[ \t]%n", &whitespace_read);
695 return whitespace_read;
696 }
|