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 */
32 static void kval(GKeyFile
*f
, const gchar
*k
, gchar
*dst
,
35 gchar
*r
= g_key_file_get_string(f
, "libquvi-scripts", k
, NULL
);
38 gchar
*s
= g_strescape(g_strstrip(r
), NULL
);
39 g_snprintf(dst
, dst_size
, "%s", s
);
45 struct scripts_version_s
47 gchar configuration
[128];
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';
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
));
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
);
77 static const gchar
*_version
[] =
91 /** @return NULL-terminated version string
92 @note Do not attempt to free the returned string
95 const char *quvi_version(QuviVersion 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
]);
112 return (_version
[QUVI_VERSION
]);
115 /* vim: set ts=2 sw=2 tw=72 expandtab: */