gui: Rename cmd_task to exec_task.
[paraslash.git] / version.c
1 /*
2  * Copyright (C) 2013-2014 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file version.c Some helpers for printing version and copyright strings. */
8
9 #include "para.h"
10 #include "version.h"
11
12 /** \file version.h Macros for printing the version string. */
13
14 #include "git-version.h"
15
16 /**
17  * Get the raw git version string
18  *
19  * \return The string generated by the GIT-VERSION-GEN script. It is passed
20  * as a preprocessor define during compilation.
21  */
22 __a_const const char *version_git(void)
23 {
24         return GIT_VERSION;
25 }
26
27 /**
28  * Get the version string for an executable.
29  *
30  * \param pfx The program name (without the leading "para_").
31  *
32  * \return A statically allocated string which contains the program name and
33  * the git version. It must not be freed by the caller.
34  */
35 const char *version_single_line(const char *pfx)
36 {
37         static char buf[100];
38         snprintf(buf, sizeof(buf) - 1,
39                 "para_%s " GIT_VERSION, pfx);
40         return buf;
41 }
42
43 /**
44  * Get the full version text.
45  *
46  * \param pfx See \ref version_single_line().
47  *
48  * \return A string containing the same text as returned by \ref
49  * version_single_line(), augmented by additional build information, a
50  * copyright text and the email address of the author.
51  *
52  * Like \ref version_single_line(), this string is stored in a statically
53  * allocated buffer and must not be freed.
54  */
55 const char *version_text(const char *pfx)
56 {
57         static char buf[512];
58
59         snprintf(buf, sizeof(buf) - 1, "%s\n"
60                 "Copyright (C) 2014 Andre Noll\n"
61                 "This is free software with ABSOLUTELY NO WARRANTY."
62                 " See COPYING for details.\n"
63                 "Report bugs to <maan@systemlinux.org>.\n"
64                 "build date: " BUILD_DATE ",\n"
65                 "build system: " UNAME_RS ",\n"
66                 "compiler: " CC_VERSION ".\n",
67                 version_single_line(pfx)
68         );
69         return buf;
70 }
71
72 /**
73  * Print the version text and exit successfully.
74  *
75  * \param pfx See \ref version_single_line().
76  * \param flag Whether --version was given.
77  *
78  * If \a flag is false, this function does nothing. Otherwise it prints the
79  * full version text as returned by \ref version_text() and exits successfully.
80  */
81 void version_handle_flag(const char *pfx, bool flag)
82 {
83         if (!flag)
84                 return;
85         printf("%s", version_text(pfx));
86         exit(EXIT_SUCCESS);
87 }