version 1.4, 2019/04/08 22:47:34 |
version 1.10, 2019/05/01 09:02:25 |
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#include <getopt.h> |
#include <getopt.h> |
|
#include <libgen.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "node.h" |
#include "node.h" |
#include "parse.h" |
#include "parse.h" |
|
#include "reorg.h" |
#include "format.h" |
#include "format.h" |
|
|
/* |
/* |
* 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[]) |
{ |
{ |
struct parse *parser; |
struct parse *parser; |
struct ptree *tree; |
struct ptree *tree; |
const char *progname; |
const char *progname; |
const char *fname; |
const char *bname, *fname, *sec; |
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]; |
else |
else |
progname++; |
progname++; |
|
|
|
sec = NULL; |
warn = 0; |
warn = 0; |
while ((ch = getopt(argc, argv, "W")) != -1) { |
outtype = OUTT_MDOC; |
|
while ((ch = getopt(argc, argv, "s:T:W")) != -1) { |
switch (ch) { |
switch (ch) { |
|
case 's': |
|
sec = optarg; |
|
break; |
|
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 73 main(int argc, char *argv[]) |
|
Line 100 main(int argc, char *argv[]) |
|
|
|
/* Parse. */ |
/* Parse. */ |
|
|
if ((parser = parse_alloc(warn)) == NULL) { |
parser = parse_alloc(warn); |
perror(NULL); |
|
return 1; |
|
} |
|
tree = parse_file(parser, fd, fname); |
tree = parse_file(parser, fd, fname); |
rc = tree->flags & TREE_FAIL ? 1 : 0; |
ptree_reorg(tree, sec); |
|
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) |
if (fd == -1 && (bname = basename(fname)) != NULL) |
|
printf(".\\\" automatically generated " |
|
"with %s %s\n", progname, bname); |
|
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 125 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] [-s section] " |
return 1; |
"[-T mdoc | tree | lint] [input_filename]\n", progname); |
|
return 5; |
} |
} |