int fd;
size_t len;
char *file;
+ struct text section = {NULL, 0};
struct section *table, *s, *prev;
errs = 0;
- if (argc != 2) {
- fprintf(stderr, "Usage: mdcode file.mdc\n");
+ if (argc != 2 && argc != 3) {
+ fprintf(stderr, "Usage: mdcode file.mdc [section]\n");
exit(2);
}
+ if (argc == 3) {
+ section.txt = argv[2];
+ section.len = strlen(argv[2]);
+ }
+
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
fprintf(stderr, "mdcode: cannot open %s: %s\n",
char fname[1024];
char *spc = strnchr(s->section.txt, s->section.len, ' ');
- if (spc > s->section.txt && spc[-1] == ':' &&
- strncmp(s->section.txt, "File: ", 6) != 0)
- /* Ignore this section */
- continue;
- if (strncmp(s->section.txt, "File: ", 6) != 0) {
+ if (spc > s->section.txt && spc[-1] == ':') {
+ if (strncmp(s->section.txt, "File: ", 6) != 0 &&
+ (section.txt == NULL ||
+ text_cmp(s->section, section) != 0))
+ /* Ignore this section */
+ continue;
+ } else {
fprintf(stderr, "Code in unreferenced section that is not ignored or a file name: %.*s\n",
s->section.len, s->section.txt);
errs++;
continue;
}
+ if (section.txt) {
+ if (text_cmp(s->section, section) == 0)
+ code_node_print(stdout, s->code, argv[1]);
+ break;
+ }
copy_fname(fname, sizeof(fname), s->section);
if (fname[0] == 0) {
fprintf(stderr, "Missing file name at:%.*s\n",
}
exit(!!errs);
}
-