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