| 101 | } |
| 102 | |
| 103 | int main(int, char **) { |
| 104 | std::setlocale(LC_NUMERIC, "C"); |
| 105 | |
| 106 | for (const auto & md : md_files) { |
| 107 | std::ifstream infile(md.fname); |
| 108 | if (!infile.is_open()) { |
| 109 | fprintf(stderr, "failed to open file '%s' for reading\n", md.fname.c_str()); |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | std::ostringstream ss; |
| 114 | ss << infile.rdbuf(); |
| 115 | infile.close(); |
| 116 | |
| 117 | std::string content = ss.str(); |
| 118 | |
| 119 | size_t help_start = content.find(HELP_START_MARKER); |
| 120 | size_t help_end = content.find(HELP_END_MARKER); |
| 121 | |
| 122 | if (help_start == std::string::npos || help_end == std::string::npos || help_end <= help_start) { |
| 123 | fprintf(stderr, "failed to find help markers in file '%s'\n", md.fname.c_str()); |
| 124 | return 1; |
| 125 | } |
| 126 | |
| 127 | std::ostringstream new_help_ss; |
| 128 | write_help(new_help_ss, md); |
| 129 | std::string new_help = new_help_ss.str(); |
| 130 | |
| 131 | content = content.substr(0, help_start) + new_help + content.substr(help_end + strlen(HELP_END_MARKER)); |
| 132 | |
| 133 | std::ofstream outfile(md.fname); |
| 134 | if (!outfile.is_open()) { |
| 135 | fprintf(stderr, "failed to open file '%s' for writing\n", md.fname.c_str()); |
| 136 | return 1; |
| 137 | } |
| 138 | outfile << content; |
| 139 | outfile.close(); |
| 140 | |
| 141 | printf("Updated help in '%s'\n", md.fname.c_str()); |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
nothing calls this directly
no test coverage detected