Skip to content

Commit

Permalink
Process --version, -h, --help.
Browse files Browse the repository at this point in the history
Closes #107
  • Loading branch information
kristapsdz committed Dec 21, 2024
1 parent 99a84fd commit 2c9db41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ IMAGES = screen-mandoc.png \
THUMBS = screen-mandoc.thumb.jpg \
screen-groff.thumb.jpg \
screen-term.thumb.jpg
CFLAGS += -DVERSION=\"$(VERSION)\"
# Because the objects will be compiled into a shared library:
CFLAGS += -fPIC
# To avoid exporting internal functions (lowdown.h has default visibility).
Expand Down
35 changes: 28 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ main(int argc, char *argv[])
*din = NULL;
const char *fnin = "<stdin>", *fnout = NULL,
*fndin = NULL, *extract = NULL, *er,
*mainopts = "LM:m:sT:t:o:X:",
*diffopts = "M:m:sT:t:o:",
*mainopts = "LM:m:sT:t:o:X:h",
*diffopts = "M:m:sT:t:o:h",
*templfn = NULL, *odtstylefn = NULL;
struct lowdown_opts_term topts;
struct lowdown_opts opts;
int c, diff = 0, status = 0, afl = 0,
int c, diff = 0, status = 1, afl = 0,
rfl = 0, aifl = 0, rifl = 0, list = 0;
char *ret = NULL, *cp, *templptr = NULL,
*nroffcodefn = NULL,
Expand Down Expand Up @@ -394,8 +394,9 @@ main(int argc, char *argv[])
{ "parse-callouts", no_argument, &aifl, LOWDOWN_CALLOUTS },
{ "parse-no-callouts", no_argument, &rifl, LOWDOWN_CALLOUTS },
{ "parse-maxdepth", required_argument, NULL, 5 },

{ "template", required_argument, NULL, 8 },
{ "version", no_argument, NULL, 10 },
{ "help", no_argument, NULL, 11 },

/* Deprecated "nroff" prefix. */

Expand Down Expand Up @@ -581,10 +582,30 @@ main(int argc, char *argv[])
if (er == NULL)
break;
errx(1, "--term-hpadding: %s", er);
case 10:
/*
* Print the version with --version.
*/
printf("lowdown %s\n", VERSION);
return 0;
case 'h':
/* FALLTHROUGH */
case 11:
/*
* Used by -h or --help to print the usage
* message and not exit with failure.
*/
status = 0;
goto usage;
default:
/*
* Bad argument: exit with failure.
*/
goto usage;
}

status = 0;

argc -= optind;
argv += optind;

Expand Down Expand Up @@ -756,15 +777,15 @@ main(int argc, char *argv[])
usage:
if (!diff) {
fprintf(stderr,
"usage: lowdown [-Ls] [input_options] "
"usage: lowdown [-hLs] [input_options] "
"[output_options] [-M metadata]\n"
" [-m metadata] "
"[-o output] [-t mode] [-X keyword] [file]\n");
} else
fprintf(stderr,
"usage: lowdown-diff [-s] [input_options] "
"usage: lowdown-diff [-hs] [input_options] "
"[output_options] [-M metadata]\n"
" [-m metadata] "
"[-o output] [-t mode] oldfile [newfile]\n");
return 1;
return status;
}

0 comments on commit 2c9db41

Please sign in to comment.