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