summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 14:33:45 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 14:33:45 (EDT)
commiteb7115b77e55fb049edd5582b114eefb246edf40 (patch)
tree1f448cb37f0e81866dc53c27671c74204fa25694
parent1a91764c1692ebdcd14ee8de1b12a2161be2194e (diff)
main(): Print usage
-rw-r--r--src/main.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 6825179..411902c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,18 @@
#include "image.h"
#include "text.h"
+static void
+usage(FILE *stream, const char *program_name)
+{
+ fprintf(stream, _("Usage: %s [-f <font>] [-w <width>] [-h <height>] "
+ "<text-input> <png-output>\n"), program_name);
+ fputs(_(" -f <font> name of font face, or \"list\" to list "
+ "available font face names\n"), stream);
+ fputs(_(" -w <width> width of image in character columns\n"),
+ stream);
+ fputs(_(" -h <height> height of image in character rows\n"), stream);
+}
+
int
main(int argc, char **argv)
{
@@ -50,31 +62,37 @@ main(int argc, char **argv)
case 'f':
font = font_find(optarg);
if (!font) {
- printf(_("Font \"%s\" not found\n"),
+ fprintf(stderr, _("Font \"%s\" not "
+ "found\n"),
optarg);
+ usage(stderr, argv[0]);
return 1;
}
break;
case 'w':
w = strtol(optarg, &end, 10);
if (*optarg == '\0' || *end != '\0' || w <= 0) {
- printf(_("Width must be an integer "
+ fprintf(stderr, _("Width must be an "
+ "integer "
"greater than "
"0\n"));
+ usage(stderr, argv[0]);
return 1;
}
break;
case 'h':
h = strtol(optarg, &end, 10);
if (*optarg == '\0' || *end != '\0' || h <= 0) {
- printf(_("Height must be an integer "
+ fprintf(stderr, _("Height must be an "
+ "integer "
"greater than "
"0\n"));
+ usage(stderr, argv[0]);
return 1;
}
break;
default:
- printf(_("Invalid option\n"));
+ usage(stderr, argv[0]);
return 1;
}
}
@@ -91,8 +109,8 @@ main(int argc, char **argv)
if (strcmp(input, "-") != 0) {
fp = fopen(input, "r");
if (!fp) {
- printf(_("Error: Cannot open \"%s\" for reading\n"),
- input);
+ fprintf(stderr, _("Error: Cannot open \"%s\" for "
+ "reading\n"), input);
return 1;
}
} else {