1 #include "options.h"
2 #include <gtk/gtk.h> //for gtk_get_option_group
3
4 OreganoOptions opts = {
5 .debug = {.wires = FALSE, .boxes = FALSE, .dots = FALSE, .directions = FALSE, .all = FALSE}};
6
7 GOptionEntry entries[] = {
8 {"version", 0, 0, G_OPTION_ARG_NONE, &(opts.version),
9 "Print the version and quit.", NULL},
10 {"debug-wires", 0, 0, G_OPTION_ARG_NONE, &(opts.debug.wires),
11 "Give them randomly alternating colors.", NULL},
12 {"debug-boundingboxes", 0, 0, G_OPTION_ARG_NONE, &(opts.debug.boxes),
13 "Draw them in semi transparent purple.", NULL},
14 {"debug-dots", 0, 0, G_OPTION_ARG_NONE, &(opts.debug.dots),
15 "Draw an extra color circle around dots which are always shown.", NULL},
16 {"debug-directions", 0, 0, G_OPTION_ARG_NONE, &(opts.debug.directions),
17 "Draw fancy direction arrows top left edge of the sheet.", NULL},
18 {"debug-all", 0, 0, G_OPTION_ARG_NONE, &(opts.debug.all), "Enable all debug-* options.", NULL},
19 {NULL}};
20
21 /**
22 * parse the commandline options for gtk args and oregano recognized ones
23 * results will be written to a global Options struct (opts)
24 * @param argc pointer to argc from main
25 * @param argv pointer to argv from main
26 * @param e a GError ptr ptr which will be filled in case of an error
27 */
oregano_options_parse(int * argc,char ** argv[],GError ** e)28 gboolean oregano_options_parse (int *argc, char **argv[], GError **e)
29 {
30 GError *error = NULL;
31 gboolean r = FALSE;
32 GOptionContext *context;
33 context = g_option_context_new ("- electrical engineering tool");
34 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
35 g_option_context_add_group (context, gtk_get_option_group (TRUE));
36 r = g_option_context_parse (context, argc, argv, &error);
37 if (error) {
38 if (e)
39 *e = g_error_copy (error);
40 g_error_free (error);
41 error = NULL;
42 }
43 g_option_context_free (context);
44 return r;
45 }
46
47
oregano_options_version()48 inline gboolean oregano_options_version () { return opts.version; }
49
oregano_options_debug_wires()50 inline gboolean oregano_options_debug_wires () { return opts.debug.wires || opts.debug.all; }
51
oregano_options_debug_boxes()52 inline gboolean oregano_options_debug_boxes () { return opts.debug.boxes || opts.debug.all; }
53
oregano_options_debug_dots()54 inline gboolean oregano_options_debug_dots () { return opts.debug.dots || opts.debug.all; }
55
oregano_options_debug_directions()56 inline gboolean oregano_options_debug_directions ()
57 {
58 return opts.debug.directions || opts.debug.all;
59 }
60