=================================================================== RCS file: /cvs/docbook2mdoc/main.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -p -r1.3 -r1.4 --- docbook2mdoc/main.c 2019/03/28 12:21:10 1.3 +++ docbook2mdoc/main.c 2019/04/08 22:47:34 1.4 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.3 2019/03/28 12:21:10 schwarze Exp $ */ +/* $Id: main.c,v 1.4 2019/04/08 22:47:34 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -15,7 +15,6 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include #include #include @@ -64,40 +63,34 @@ main(int argc, char *argv[]) if (argc > 1) { fprintf(stderr, "%s: Too many arguments\n", argv[1]); goto usage; - } else - fname = argc > 0 ? argv[0] : "-"; + } else if (argc == 1) { + fname = argv[0]; + fd = -1; + } else { + fname = ""; + fd = STDIN_FILENO; + } - fd = strcmp(fname, "-") == 0 ? - STDIN_FILENO : open(fname, O_RDONLY, 0); + /* Parse. */ - if (fd == -1) { - perror(fname); + if ((parser = parse_alloc(warn)) == NULL) { + perror(NULL); return 1; } + tree = parse_file(parser, fd, fname); + rc = tree->flags & TREE_FAIL ? 1 : 0; - /* Parse and format. */ + /* Format. */ - rc = 1; - if ((parser = parse_alloc(warn)) != NULL) { - if ((tree = parse_file(parser, fd, fname)) != NULL) { - if (tree->flags & TREE_FAIL) - fputc('\n', stderr); - else - rc = 0; - ptree_print(tree); - if (tree->flags & TREE_FAIL) - fputs("\nThe output may be incomplete, see" - " the parse error reported above.\n\n", - stderr); - pnode_unlink(tree->root); - tree->root = NULL; - } - parse_free(parser); - } else - perror(NULL); - - if (fd != STDIN_FILENO) - close(fd); + if (tree->root != NULL) { + if (rc) + fputc('\n', stderr); + ptree_print(tree); + if (rc) + fputs("\nThe output may be incomplete, see the " + "parse error reported above.\n\n", stderr); + } + parse_free(parser); return rc; usage: