]> git.draconx.ca Git - rrace.git/blob - src/version.c
Implement the about dialog.
[rrace.git] / src / version.c
1 #include <config.h>
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include <striconv.h>
5 #include <localcharset.h>
6
7 #include "version.h"
8
9 const char *init_copysign(char **alloc)
10 {
11         *alloc = NULL;
12
13         if (ENABLE_NLS) {
14                 char *buf = str_iconv("\xc2\xa9", "UTF-8", locale_charset());
15                 if (buf)
16                         return *alloc = buf;
17         }
18
19         return "(C)";
20 }
21
22 #define VERSION_HEAD_FMT "%s (RRace) %s\nCopyright %s 2022 Nick Bowler"
23 #define VERSION_HEAD_ARGS progname, PACKAGE_VERSION, copysign
24
25 void version_print_head(const char *progname, FILE *f)
26 {
27         const char *copysign;
28         char *copybuf;
29
30         copysign = init_copysign(&copybuf);
31
32         printf(VERSION_HEAD_FMT, VERSION_HEAD_ARGS);
33         putc('\n', f);
34
35         free(copybuf);
36 }
37
38 char *version_format_head(const char *progname)
39 {
40         const char *copysign;
41         char *copybuf, *ret;
42
43         copysign = init_copysign(&copybuf);
44
45         ret = malloc(sizeof VERSION_HEAD_FMT + 100);
46         if (ret)
47                 sprintf(ret, VERSION_HEAD_FMT, VERSION_HEAD_ARGS);
48
49         free(copybuf);
50         return ret;
51 }