| 259 | } |
| 260 | |
| 261 | int main(int argc, char *argv[]) |
| 262 | { |
| 263 | setup_locale(); |
| 264 | |
| 265 | struct bolt_file *bolts; |
| 266 | int i; |
| 267 | char *prefix = "BOLT"; |
| 268 | |
| 269 | err_set_progname(argv[0]); |
| 270 | |
| 271 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
| 272 | "<bolt-dir> <srcfile>...\n" |
| 273 | "A source checker for BOLT RFC references.", |
| 274 | "Print this message."); |
| 275 | opt_register_noarg("--verbose", opt_set_bool, &verbose, |
| 276 | "Print out files as we find them"); |
| 277 | opt_register_arg("--prefix", opt_set_charp, opt_show_charp, &prefix, |
| 278 | "Only check these markers"); |
| 279 | |
| 280 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 281 | if (argc < 2) |
| 282 | opt_usage_exit_fail("Expected a bolt directory"); |
| 283 | |
| 284 | bolts = get_bolt_files(argv[1]); |
| 285 | |
| 286 | for (i = 2; i < argc; i++) { |
| 287 | char *f = grab_file(NULL, argv[i]), *p, *bolt; |
| 288 | size_t len; |
| 289 | if (!f) |
| 290 | err(1, "Loading %s", argv[i]); |
| 291 | |
| 292 | if (verbose) |
| 293 | printf("Checking %s...\n", argv[i]); |
| 294 | |
| 295 | p = f; |
| 296 | while ((bolt = find_bolt_ref(prefix, &p, &len)) != NULL) { |
| 297 | char *pattern = code_to_regex(p, len, true); |
| 298 | struct bolt_file *b = find_bolt(bolt, bolts); |
| 299 | if (!b) |
| 300 | fail_nobolt(argv[i], f, p, bolt); |
| 301 | if (!tal_strreg(f, b->contents, pattern, NULL)) |
| 302 | fail_mismatch(argv[i], f, p, len, b); |
| 303 | |
| 304 | if (verbose) |
| 305 | printf(" Found %.10s... in %s\n", |
| 306 | p, b->prefix); |
| 307 | p += len; |
| 308 | } |
| 309 | tal_free(f); |
| 310 | } |
| 311 | return 0; |
| 312 | } |
nothing calls this directly
no test coverage detected