aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE2
-rw-r--r--neetdraw.c25
2 files changed, 16 insertions, 11 deletions
diff --git a/LICENSE b/LICENSE
index 8193f83..0610bbd 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-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.
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 ();