b9216348dd0c31c2eb20b502749cad240c27794e
[libquvi.git] / src / api / version.c
blobb9216348dd0c31c2eb20b502749cad240c27794e
1 /* libquvi
2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library 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 library 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 library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file version.c */
23 #include "config.h"
25 #include <string.h>
26 #include <glib.h>
28 #include "quvi.h"
29 /* -- */
30 #include "_quvi_s.h"
32 static void kval(GKeyFile *f, const gchar *k, gchar *dst,
33 const gsize dst_size)
35 gchar *r = g_key_file_get_string(f, "libquvi-scripts", k, NULL);
36 if (r != NULL)
38 gchar *s = g_strescape(g_strstrip(r), NULL);
39 g_snprintf(dst, dst_size, "%s", s);
40 g_free(s);
41 g_free(r);
45 struct scripts_version_s
47 gchar configuration[128];
48 gchar version[32];
51 typedef struct scripts_version_s *scripts_version_t;
53 static void scripts_version_read(scripts_version_t v)
55 GKeyFile *f = g_key_file_new();
56 v->configuration[0]= '\0';
57 v->version[0]= '\0';
58 if (g_key_file_load_from_file(f, VERSIONFILE, G_KEY_FILE_NONE, NULL)==TRUE)
60 kval(f, "configuration", v->configuration, sizeof(v->configuration));
61 kval(f, "version", v->version, sizeof(v->version));
63 g_key_file_free(f);
66 static struct scripts_version_s sv;
68 static const gchar *read_scripts_version(const QuviVersion qv)
70 scripts_version_read(&sv);
71 if (qv == QUVI_VERSION_SCRIPTS_CONFIGURATION)
72 return (sv.configuration);
73 else
74 return (sv.version);
77 static const gchar *_version[] =
79 #ifdef VN
81 #else
82 PACKAGE_VERSION
83 #endif
85 BUILD_OPTS,
86 CC ", " CFLAGS,
87 CANONICAL_TARGET,
88 BUILD_TIME
91 /** @return NULL-terminated version string
92 @note Do not attempt to free the returned string
93 @ingroup convenience
95 const char *quvi_version(QuviVersion version)
97 switch (version)
99 case QUVI_VERSION_SCRIPTS_CONFIGURATION:
100 case QUVI_VERSION_SCRIPTS:
101 return (read_scripts_version(version));
103 case QUVI_VERSION_CONFIGURATION:
104 case QUVI_VERSION_BUILD_CC_CFLAGS:
105 case QUVI_VERSION_BUILD_TARGET:
106 case QUVI_VERSION_BUILD_TIME:
107 return (_version[version]);
109 default:
110 break;
112 return (_version[QUVI_VERSION]);
115 /* vim: set ts=2 sw=2 tw=72 expandtab: */