LAL 7.7.1.1-3ba1904
LALVCSInfoType.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014, 2016 Karl Wette
3 * Copyright (C) 2009-2013 Adam Mercer
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with with program; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301 USA
19 */
20
21#include <string.h>
22
23#include <lal/LALStdlib.h>
24#include <lal/LALString.h>
25#include <lal/LALVCSInfoType.h>
26
27char *XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
28{
29
30 /* check input */
31 XLAL_CHECK_NULL( vcs_list != NULL, XLAL_EFAULT );
32
33 /* generate VCS and build information string */
34 char *str = NULL;
35 for ( size_t i = 0; vcs_list[i] != NULL; ++i ) {
36 if ( verbose ) {
37 str = XLALStringAppendFmt( str,
38 "%s-Version: %s\n"
39 "%s-Id: %s\n"
40 "%s-Date: %s\n"
41 "%s-Branch: %s\n"
42 "%s-Tag: %s\n"
43 "%s-Status: %s\n"
44 "%s-Configure-Args: %s\n"
45 "%s-Configure-Date: %s\n"
46 "%s-Build-Date: %s\n",
47 vcs_list[i]->name, vcs_list[i]->version,
48 vcs_list[i]->name, vcs_list[i]->vcsId,
49 vcs_list[i]->name, vcs_list[i]->vcsDate,
50 vcs_list[i]->name, vcs_list[i]->vcsBranch,
51 vcs_list[i]->name, vcs_list[i]->vcsTag,
52 vcs_list[i]->name, vcs_list[i]->vcsStatus,
53 vcs_list[i]->name, vcs_list[i]->configureArgs,
54 vcs_list[i]->name, vcs_list[i]->configureDate,
55 vcs_list[i]->name, vcs_list[i]->buildDate
56 );
57 } else {
58 str = XLALStringAppendFmt( str,
59 "%s: %s (%s %s)\n",
60 vcs_list[i]->name,
61 vcs_list[i]->version,
62 vcs_list[i]->vcsClean,
63 vcs_list[i]->vcsId
64 );
65 }
66 XLAL_CHECK_NULL( str != NULL, XLAL_EFUNC );
67 }
68
69 /* add prefix */
70 if ( prefix != NULL ) {
71 char *new_str = NULL;
72 char *ptr = str;
73 char *line = XLALStringToken( &ptr, "\n", 0 );
74 while ( line != NULL ) {
75 new_str = XLALStringAppendFmt( new_str, "%s%s\n", prefix, line );
76 XLAL_CHECK_NULL( new_str != NULL, XLAL_EFUNC );
77 line = XLALStringToken( &ptr, "\n", 0 );
78 }
79 XLALFree( str );
80 str = new_str;
81 }
82
83 return str;
84
85}
86
87int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
88{
89
90 /* check input */
91 XLAL_CHECK( fp != NULL, XLAL_EFAULT );
92
93 /* generate VCS and build information string */
94 char *str = XLALVCSInfoString( vcs_list, verbose, prefix );
95 XLAL_CHECK( str != NULL, XLAL_EFUNC );
96
97 /* output string */
98 XLAL_CHECK( fprintf( fp, "%s", str ) >= 0, XLAL_ESYS );
99
100 XLALFree( str );
101
102 return XLAL_SUCCESS;
103
104}
static const size_t prefix
Definition: LALMalloc.c:256
char * XLALStringAppendFmt(char *s, const char *fmt,...)
Append the formatted string 'fmt' to the string 's', which is reallocated with XLALRealloc() to the r...
Definition: LALString.c:69
#define fprintf
const char *const name
type name
Definition: UserInput.c:198
#define XLALFree(p)
Definition: LALMalloc.h:47
char * XLALStringToken(char **s, const char *delim, int empty)
Return the next token delimited by any character in 'delim' from the string 's', which is updated to ...
Definition: LALString.c:292
char * XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
Generate a multi-line string containing VCS and build information for a library and its dependencies,...
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
Output VCS and build information, as generated by XLALVCSInfoString(), to a file pointer fp.
const LALVCSInfo *const LALVCSInfoList[16]
NULL-terminated list of VCS and build information structures
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
Definition: XLALError.h:810
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
Definition: XLALError.h:825
@ XLAL_SUCCESS
Success return value (not an error number)
Definition: XLALError.h:401
@ XLAL_EFAULT
Invalid pointer.
Definition: XLALError.h:408
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
@ XLAL_ESYS
System error.
Definition: XLALError.h:442
int verbose
Definition: tconvert.c:103
FILE * fp
Definition: tconvert.c:105