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