Add builtin/get.c
[quvi-tool.git] / src / opts / print.c
blob5b194137118d94ba180ea22783b8c85f8f5c0dac
1 /* quvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of quvi <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <glib/gi18n.h>
25 #include "lopts.h"
27 void lopts_print_config_values(lopts_t lopts)
29 const GOptionEntry *p;
31 g_assert(lopts != NULL);
32 g_assert(lopts->entries != NULL);
34 g_print(_("# Value of all configuration options\n"));
35 g_print("#\n");
37 p = lopts->entries;
38 while (p->long_name != NULL)
40 if (g_strcmp0(p->long_name, G_OPTION_REMAINING) != 0)
42 switch (p->arg)
44 case G_OPTION_ARG_FILENAME_ARRAY:
45 case G_OPTION_ARG_STRING_ARRAY:
47 gchar **sv = *(gchar***) p->arg_data;
48 if (sv != NULL)
50 gchar *s = g_strjoinv(",", sv);
51 g_print("%s=%s\n", p->long_name, s);
52 g_free(s);
54 else
55 g_print(_("%s is unset\n"), p->long_name);
57 break;
59 case G_OPTION_ARG_FILENAME:
60 case G_OPTION_ARG_STRING:
62 const gchar *s = *(const gchar**) p->arg_data;
63 if (s != NULL)
64 g_print("%s=%s\n", p->long_name, s);
65 else
66 g_print(_("%s is unset\n"), p->long_name);
68 break;
70 case G_OPTION_ARG_DOUBLE:
71 g_print("%s=%g\n", p->long_name, *(gdouble*) p->arg_data);
72 break;
74 case G_OPTION_ARG_INT64:
75 g_print("%s=%"G_GINT64_FORMAT"\n",
76 p->long_name, *(gint64*) p->arg_data);
77 break;
79 case G_OPTION_ARG_NONE:
81 const gboolean r = (*(gboolean*) p->arg_data);
82 if (r == TRUE)
83 g_print(_("%s is set\n"), p->long_name);
84 else
85 g_print(_("%s is unset\n"), p->long_name);
87 break;
89 case G_OPTION_ARG_INT:
90 g_print("%s=%d\n", p->long_name, *(gint*) p->arg_data);
91 break;
93 case G_OPTION_ARG_CALLBACK:
94 default:
95 break;
98 ++p;
102 extern gchar **search_dirs();
104 void lopts_print_config_paths(lopts_t lopts)
106 gchar *rcpath, **dirs, *p;
107 gint i;
109 g_print(_("# Search paths for the configuration file\n#\n"));
111 rcpath = g_build_path(G_DIR_SEPARATOR_S, "quvi", "quvirc", NULL);
112 dirs = search_dirs();
114 i = 0;
115 while (dirs[i] != NULL)
117 p = g_build_path(G_DIR_SEPARATOR_S, dirs[i++], rcpath, NULL);
118 g_print("%s\n", p);
119 g_free(p);
121 g_strfreev(dirs);
122 g_free(rcpath);
125 /* vim: set ts=2 sw=2 tw=72 expandtab: */