* parse_assignment * * Parse the string 'arg' (which supposedly represents an assignment) into a * NAME and a VALUE. If 'arg' does not conform to the proper assignment * syntax, exit with a usage message. Otherwise, on return, 'arg' is broken * into substrings representing NAME and VALUE, and *name and *value are set * to point to these two substrings. ************************************
| 693 | * to point to these two substrings. |
| 694 | ****************************************************************************/ |
| 695 | static void parse_assignment(char arg[], const char **name, const char **value) |
| 696 | { |
| 697 | static const size_t N_MATCHES = 4; |
| 698 | regmatch_t match[N_MATCHES]; |
| 699 | regex_t assignment; |
| 700 | |
| 701 | compile_reg_expr(REG_EXTENDED | REG_NEWLINE, assignment_regex, &assignment); |
| 702 | |
| 703 | /* Does 'arg' conform to proper assignment syntax? If not, exit with a |
| 704 | * usage message. |
| 705 | */ |
| 706 | if (regexec(&assignment, arg, N_MATCHES, match, 0)) |
| 707 | usage(stderr); |
| 708 | |
| 709 | /* Ok, we found a valid assignment. Break it into two strings |
| 710 | * representing NAME and VALUE. |
| 711 | */ |
| 712 | arg[match[1].rm_eo] = '\0'; |
| 713 | arg[match[2].rm_eo] = '\0'; |
| 714 | *name = &arg[match[1].rm_so]; |
| 715 | *value = &arg[match[2].rm_so]; |
| 716 | |
| 717 | regfree(&assignment); |
| 718 | } |
| 719 | |
| 720 | /**************************************************************************** |
| 721 | * list_cmos_entry |
no test coverage detected