version 1.4, 2019/04/08 22:47:34 |
version 1.6, 2019/04/12 19:14:50 |
|
|
* The steering function of the docbook2mdoc(1) program. |
* The steering function of the docbook2mdoc(1) program. |
*/ |
*/ |
|
|
|
enum outt { |
|
OUTT_MDOC = 0, |
|
OUTT_TREE, |
|
OUTT_LINT |
|
}; |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
Line 36 main(int argc, char *argv[]) |
|
Line 42 main(int argc, char *argv[]) |
|
const char *progname; |
const char *progname; |
const char *fname; |
const char *fname; |
int ch, fd, rc, warn; |
int ch, fd, rc, warn; |
|
enum outt outtype; |
|
|
if ((progname = strrchr(argv[0], '/')) == NULL) |
if ((progname = strrchr(argv[0], '/')) == NULL) |
progname = argv[0]; |
progname = argv[0]; |
Line 43 main(int argc, char *argv[]) |
|
Line 50 main(int argc, char *argv[]) |
|
progname++; |
progname++; |
|
|
warn = 0; |
warn = 0; |
while ((ch = getopt(argc, argv, "W")) != -1) { |
outtype = OUTT_MDOC; |
|
while ((ch = getopt(argc, argv, "T:W")) != -1) { |
switch (ch) { |
switch (ch) { |
|
case 'T': |
|
if (strcmp(optarg, "mdoc") == 0) |
|
outtype = OUTT_MDOC; |
|
else if (strcmp(optarg, "tree") == 0) |
|
outtype = OUTT_TREE; |
|
else if (strcmp(optarg, "lint") == 0) |
|
outtype = OUTT_LINT; |
|
else { |
|
fprintf(stderr, "%s: Bad argument\n", |
|
optarg); |
|
goto usage; |
|
} |
|
break; |
case 'W': |
case 'W': |
warn = 1; |
warn = 1; |
break; |
break; |
Line 75 main(int argc, char *argv[]) |
|
Line 96 main(int argc, char *argv[]) |
|
|
|
if ((parser = parse_alloc(warn)) == NULL) { |
if ((parser = parse_alloc(warn)) == NULL) { |
perror(NULL); |
perror(NULL); |
return 1; |
return 6; |
} |
} |
tree = parse_file(parser, fd, fname); |
tree = parse_file(parser, fd, fname); |
rc = tree->flags & TREE_FAIL ? 1 : 0; |
rc = tree->flags & TREE_ERROR ? 3 : tree->flags & TREE_WARN ? 2 : 0; |
|
|
/* Format. */ |
/* Format. */ |
|
|
if (tree->root != NULL) { |
if (outtype != OUTT_LINT && tree->root != NULL) { |
if (rc) |
if (rc > 2) |
fputc('\n', stderr); |
fputc('\n', stderr); |
ptree_print(tree); |
if (outtype == OUTT_MDOC) |
if (rc) |
ptree_print_mdoc(tree); |
|
else |
|
ptree_print_tree(tree); |
|
if (rc > 2) |
fputs("\nThe output may be incomplete, see the " |
fputs("\nThe output may be incomplete, see the " |
"parse error reported above.\n\n", stderr); |
"parse error reported above.\n\n", stderr); |
} |
} |
Line 94 main(int argc, char *argv[]) |
|
Line 118 main(int argc, char *argv[]) |
|
return rc; |
return rc; |
|
|
usage: |
usage: |
fprintf(stderr, "usage: %s [-W] [input_filename]\n", progname); |
fprintf(stderr, "usage: %s [-W] [-T mdoc | tree | lint] " |
return 1; |
"[input_filename]\n", progname); |
|
return 5; |
} |
} |