diff options
-rw-r--r-- | src/main.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -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 { |