Automatically set parent family in individual, when adding child to the family.
[familia.git] / src / commandline.c
1 /****************************************************************************
2  *  Familia Lignum - Genealogical program                                   *
3  *  Copyright (C) 2011-2012 Rafał Długołęcki <rafal@dlugolecki.net.pl>      *
4  *                                                                          *
5  *  This program is free software; you can redistribute it and/or modify    *
6  *  it under the terms of the GNU General Public License as published by    *
7  *  the Free Software Foundation; version 2 of the License.                 *
8  *                                                                          *
9  *  This program is distributed in the hope that it will be useful,         *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
12  *  GNU General Public License for more details.                            *
13  *                                                                          *
14  *  You should have received a copy of the GNU General Public License along *
15  *  with this program; if not, write to the Free Software Foundation, Inc., *
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             *
17  *                                                                          *
18  ****************************************************************************/
19
20 #include <gtk/gtk.h>
21 #include <stdlib.h>
22
23 #include "../config.h"
24 #include "i18n.h"
25 #include "debug.h"
26
27 #include "commandline.h"
28 #include "about.h"
29
30 static gboolean commandline_copyright;
31
32 static gchar **commandline_files = NULL;
33
34 static GOptionEntry program_options[] = {
35         { "copyright", 'c', 0, G_OPTION_ARG_NONE,
36                         &commandline_copyright, "Show copyright", NULL},
37
38         { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
39                         &commandline_files, "Files", "[file1] [file2]..." },
40         { NULL }
41 };
42
43 /*
44  * @return True if program should continue. False otherwise.
45  */
46 gboolean commandline_parse(int *argc, char ***argv)
47 {
48         GError *error = NULL;
49         GOptionContext *context = NULL;
50
51         context = g_option_context_new("- genealogical program");
52         g_option_context_set_summary(context, 
53                 "Report bugs to " PACKAGE_BUGREPORT ".\n" \
54                 PACKAGE_NAME " home page: <" PACKAGE_URL ">\n" \
55                 "If you like this program, please send me a postcard. :)");
56
57         g_option_context_add_main_entries(context, program_options, NULL);
58         g_option_context_add_group(context, gtk_get_option_group(TRUE));
59
60         if(!g_option_context_parse(context, argc, argv, &error)) {
61                 g_printerr("%s\n", error->message);
62                 g_error_free(error);
63                 g_option_context_free(context);
64                 return FALSE;
65         }
66
67         if(commandline_copyright) {
68                 g_print("%s\n", PACKAGE_STRING);
69                 g_print("%s\n\n", COPYRIGHT);
70                 g_print("%s\n", "License GPLv2: GNU GPL version 2 "
71                                 "<http://www.gnu.org/licenses/gpl-2.0.html>");
72                 g_print("%s\n\n", LICENSE_SHORT);
73                 return FALSE;
74         }
75
76         if(commandline_files != NULL) {
77                 GSList * slist = NULL;
78                 guint i;
79                 for(i = 0; commandline_files[i] != NULL; i++) {
80                         g_print("Parsing %s\n", commandline_files[i]);
81                         slist = g_slist_prepend(slist, 
82                                 g_strdup(commandline_files[i]));
83                 }
84                 commandline_files = g_slist_reverse(slist);
85         }
86
87         g_strfreev(commandline_files);
88         g_option_context_free(context);
89         return TRUE;
90 }