aboutsummaryrefslogtreecommitdiff
path: root/neetdraw.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-05-22 05:47:03 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-05-22 05:47:03 +0200
commitdd71ce5ca02bcdcbcc42f21f75413de5616eae1a (patch)
treefe90d8067c92c56745f26b003bdf4c17a9a0c754 /neetdraw.c
parente08c63fe899018a38c72c8bf91e9912404a8fab5 (diff)
downloadneetdraw-dd71ce5ca02bcdcbcc42f21f75413de5616eae1a.tar.gz
neetdraw-dd71ce5ca02bcdcbcc42f21f75413de5616eae1a.tar.xz
neetdraw-dd71ce5ca02bcdcbcc42f21f75413de5616eae1a.zip
Allow passing drawings to open on the command line
The UI deserves an overhaul.
Diffstat (limited to 'neetdraw.c')
-rw-r--r--neetdraw.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/neetdraw.c b/neetdraw.c
index ab80477..6bbaa2a 100644
--- a/neetdraw.c
+++ b/neetdraw.c
@@ -1,7 +1,7 @@
/*
* neetdraw.c: terminal drawing application with multiplayer support
*
- * Copyright (c) 2014, Přemysl Eric Janouch <p@janouch.name>
+ * Copyright (c) 2014 - 2023, Přemysl Eric Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -766,7 +766,7 @@ export_irc (struct app_context *app)
// --- Loading, saving ---------------------------------------------------------
static void
-load (struct app_context *app)
+load (struct app_context *app, const char *filename)
{
// Client cannot load at all, the server would have send the new bitmap out
if (app->mode != NETWORK_MODE_STANDALONE)
@@ -776,7 +776,7 @@ load (struct app_context *app)
return;
}
- FILE *fp = fopen ("drawing.bin", "rb");
+ FILE *fp = fopen (filename, "rb");
if (!fp)
{
display ("Error opening file for reading.");
@@ -830,9 +830,9 @@ error:
}
static void
-save (struct app_context *app)
+save (struct app_context *app, const char *filename)
{
- FILE *fp = fopen ("drawing.bin", "wb");
+ FILE *fp = fopen (filename, "wb");
if (!fp)
{
display ("Error opening file for writing.");
@@ -952,8 +952,8 @@ on_key (struct app_context *app, termo_key_t *key)
if (key->modifiers)
return true;
- if (key->code.codepoint == 'l') load (app);
- if (key->code.codepoint == 's') save (app);
+ if (key->code.codepoint == 'l') load (app, "drawing.bin");
+ if (key->code.codepoint == 's') save (app, "drawing.bin");
if (key->code.codepoint == 'e') export_ansi (app);
if (key->code.codepoint == 'E') export_irc (app);
return true;
@@ -1342,6 +1342,7 @@ struct app_options
struct addrinfo *client_address; ///< Address to connect to
struct addrinfo *server_address; ///< Address to listen at
bool no_wait; ///< Don't wait for server confirmations
+ const char *filename; ///< A filename to preload
};
static void
@@ -1414,8 +1415,8 @@ parse_program_arguments (struct app_options *options, int argc, char **argv)
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh = opt_handler_make (argc, argv, opts,
- NULL, "Terminal drawing application with multiplayer support");
+ struct opt_handler oh = opt_handler_make (argc, argv, opts, "[drawing.bin]",
+ "Terminal drawing application with multiplayer support");
int c;
while ((c = opt_handler_get (&oh)) != -1)
@@ -1454,7 +1455,8 @@ parse_program_arguments (struct app_options *options, int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc)
+ options->filename = argv[0];
+ if (argc > 1)
{
opt_handler_usage (&oh, stderr);
exit (EXIT_FAILURE);
@@ -1598,6 +1600,9 @@ main (int argc, char *argv[])
redraw (&app);
redraw_canvas (&app);
+ if (options.filename)
+ load (&app, options.filename);
+
ev_run (loop, 0);
endwin ();