aboutsummaryrefslogtreecommitdiff
path: root/autistdraw.c
diff options
context:
space:
mode:
Diffstat (limited to 'autistdraw.c')
-rw-r--r--autistdraw.c68
1 files changed, 51 insertions, 17 deletions
diff --git a/autistdraw.c b/autistdraw.c
index 191570a..c42f9bd 100644
--- a/autistdraw.c
+++ b/autistdraw.c
@@ -32,6 +32,7 @@
#include "termo.h"
#include "config.h"
+#include "utils.c"
#define PALETTE_WIDTH 9 ///< Width of the palette
#define TOP_BAR_CUTOFF 3 ///< Height of the top bar
@@ -226,7 +227,7 @@ make_place_for_point (app_context_t *app, int x, int y)
while (new_bitmap_y + new_bitmap_h <= y)
new_bitmap_h += BITMAP_BLOCK_SIZE;
- uint8_t *new_bitmap = calloc (new_bitmap_w * new_bitmap_h,
+ uint8_t *new_bitmap = xcalloc (new_bitmap_w * new_bitmap_h,
sizeof *new_bitmap);
if (app->bitmap)
{
@@ -539,15 +540,6 @@ on_key (app_context_t *app, termo_key_t *key)
return true;
}
-static bool
-xstrtoul (unsigned long *out, const char *s, int base)
-{
- char *end;
- errno = 0;
- *out = strtoul (s, &end, base);
- return errno == 0 && !*end && end != s;
-}
-
static void
on_winch (uv_signal_t *handle, int signum)
{
@@ -609,15 +601,60 @@ on_tty_readable (uv_poll_t *handle, int status, int events)
on_key_timer, termo_get_waittime (app->tk), 0);
}
+static void
+parse_program_arguments (app_context_t *app, int argc, char **argv)
+{
+ (void) app;
+
+ static const struct opt opts[] =
+ {
+ { 'h', "help", NULL, 0, "display this help and exit" },
+ { 'V', "version", NULL, 0, "output version information and exit" },
+ { 0, NULL, NULL, 0, NULL }
+ };
+
+ struct opt_handler oh;
+ opt_handler_init (&oh, argc, argv, opts,
+ NULL, "Terminal drawing for NEET autists.");
+
+ int c;
+ while ((c = opt_handler_get (&oh)) != -1)
+ switch (c)
+ {
+ case 'h':
+ opt_handler_usage (&oh, stdout);
+ exit (EXIT_SUCCESS);
+ case 'V':
+ printf (PROJECT_NAME " " PROJECT_VERSION "\n");
+ exit (EXIT_SUCCESS);
+ default:
+ fprintf (stderr, "%s: %s", "error", "wrong options");
+ opt_handler_usage (&oh, stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc)
+ {
+ opt_handler_usage (&oh, stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ opt_handler_free (&oh);
+}
+
int
main (int argc, char *argv[])
{
- (void) argc;
- (void) argv;
-
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
+ app_context_t app;
+ app_init (&app);
+ parse_program_arguments (&app, argc, argv);
+
termo_t *tk = termo_new (STDIN_FILENO, NULL, 0);
if (!tk)
{
@@ -625,6 +662,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
+ app.tk = tk;
termo_set_mouse_proto (tk, termo_guess_mouse_proto (tk));
termo_set_mouse_tracking_mode (tk, TERMO_MOUSE_TRACKING_DRAG);
@@ -635,10 +673,6 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- app_context_t app;
- app_init (&app);
- app.tk = tk;
-
uv_loop_t *loop = uv_default_loop ();
loop->data = &app;