aboutsummaryrefslogtreecommitdiff
path: root/src/kike.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-07-13 23:50:44 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-07-13 23:50:44 +0200
commit586ccd4e874496014d82012f478c516cc002b8ae (patch)
tree1f5af28d04472da06fe92ac691fd1075c09662e1 /src/kike.c
parentf52fab94485d0056d25cbe74340626265472beee (diff)
downloadxK-586ccd4e874496014d82012f478c516cc002b8ae.tar.gz
xK-586ccd4e874496014d82012f478c516cc002b8ae.tar.xz
xK-586ccd4e874496014d82012f478c516cc002b8ae.zip
Put a prolog at the top of configuration files
Later I'm going to put in there some more information about the format etc.
Diffstat (limited to 'src/kike.c')
-rw-r--r--src/kike.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/kike.c b/src/kike.c
index faea7b9..38e99ef 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -993,12 +993,30 @@ print_usage (const char *program_name)
program_name);
}
+static void
+call_write_default_config (const char *hint)
+{
+ static const char *prolog =
+ "# " PROGRAM_NAME " " PROGRAM_VERSION " configuration file\n"
+ "\n";
+
+ struct error *e = NULL;
+ char *filename = write_default_config (hint, prolog, g_config_table, &e);
+ if (!filename)
+ {
+ print_fatal ("%s", e->message);
+ error_free (e);
+ exit (EXIT_FAILURE);
+ }
+ print_status ("configuration written to `%s'", filename);
+ free (filename);
+}
+
int
main (int argc, char *argv[])
{
const char *invocation_name = argv[0];
- struct error *e = NULL;
static struct option opts[] =
{
{ "debug", no_argument, NULL, 'd' },
@@ -1028,18 +1046,8 @@ main (int argc, char *argv[])
printf (PROGRAM_NAME " " PROGRAM_VERSION "\n");
exit (EXIT_SUCCESS);
case 'w':
- {
- char *filename = write_default_config (optarg, g_config_table, &e);
- if (!filename)
- {
- print_fatal ("%s", e->message);
- error_free (e);
- exit (EXIT_FAILURE);
- }
- print_status ("configuration written to `%s'", filename);
- free (filename);
+ call_write_default_config (optarg);
exit (EXIT_SUCCESS);
- }
default:
print_fatal ("error in options");
exit (EXIT_FAILURE);
@@ -1058,6 +1066,7 @@ main (int argc, char *argv[])
struct server_context ctx;
server_context_init (&ctx);
+ struct error *e = NULL;
if (!read_config_file (&ctx.config, &e))
{
print_fatal ("error loading configuration: %s", e->message);