summaryrefslogtreecommitdiffstats
path: root/src/H5make_libsettings.c
blob: 1892806f08627f559229f20fc501cbc8c1b36f14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*keep this declaration near the top of this file -RPM*/
static const char *FileHeader = "\n\
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\
 * Copyright by The HDF Group.                                               *\n\
 * Copyright by the Board of Trustees of the University of Illinois.         *\n\
 * All rights reserved.                                                      *\n\
 *                                                                           *\n\
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *\n\
 * terms governing use, modification, and redistribution, is contained in    *\n\
 * the COPYING file, which can be found at the root of the source code       *\n\
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *\n\
 * If you do not have access to either file, you may request a copy from     *\n\
 * help@hdfgroup.org.                                                        *\n\
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *";
/*
 *
 * Created:	H5make_libsettings.c
 *		17 Mar 2010
 *		Quincey Koziol
 *
 * Purpose:	Generate the H5libsettings.c file from the
 *		libhdf5.settings file.
 *
 *-------------------------------------------------------------------------
 */

#include <stdio.h>
#include <time.h>
#include "H5private.h"

#define LIBSETTINGSFNAME "libhdf5.settings"


/*-------------------------------------------------------------------------
 * Function:	insert_libhdf5_settings
 *
 * Purpose:	insert the contents of libhdf5.settings into a file
 *		represented by flibinfo.
 *		Make it an empty string if H5_HAVE_EMBEDDED_LIBINFO is not
 *		defined, i.e., not enabled.
 *
 * Return:	void
 *
 * Programmer:	Albert Cheng
 *		Apr 20, 2009
 *
 *-------------------------------------------------------------------------
 */
static void
insert_libhdf5_settings(FILE *flibinfo)
{
#ifdef H5_HAVE_EMBEDDED_LIBINFO
    FILE *fsettings;	/* for files libhdf5.settings */
    int inchar;
    int	bol = 0;	/* indicates the beginning of a new line */

    if(NULL == (fsettings = HDfopen(LIBSETTINGSFNAME, "r"))) {
        HDperror(LIBSETTINGSFNAME);
        HDexit(1);
    } /* end if */

    /* print variable definition and the string */
    /* Do not use const else AIX strings does not show it. */
    fprintf(flibinfo, "char H5libhdf5_settings[]=\n");
    bol++;
    while(EOF != (inchar = HDgetc(fsettings))) {
	if(bol) {
	    /* Start a new line */
	    fprintf(flibinfo, "\t\"");
	    bol = 0;
	} /* end if */
	if(inchar == '\n') {
	    /* end of a line */
	    fprintf(flibinfo, "\\n\"\n");
	    bol++;
        } /* end if */
	else
	    HDputc(inchar, flibinfo);
    } /* end while */
    if(HDfeof(fsettings)) {
	/* wrap up */
	if(!bol)
	    /* EOF found without a new line */
	    fprintf(flibinfo, "\\n\"\n");
	fprintf(flibinfo, ";\n\n");
    } /* end if */
    else {
	fprintf(stderr, "Read errors encountered with %s\n", LIBSETTINGSFNAME);
	HDexit(1);
    } /* end else */
    if(0 != HDfclose(fsettings)) {
	HDperror(LIBSETTINGSFNAME);
	HDexit(1);
    } /* end if */
#else
    /* print variable definition and an empty string */
    /* Do not use const else AIX strings does not show it. */
    fprintf(flibinfo, "char H5libhdf5_settings[]=\"\";\n");
#endif
} /* insert_libhdf5_settings() */


/*-------------------------------------------------------------------------
 * Function:	make_libinfo
 *
 * Purpose:	Create the embedded library information definition.
 * 		This sets up for a potential extension that the declaration
 *		is printed to a file different from stdout.
 *
 * Return:	void
 *
 * Programmer:	Albert Cheng
 *		Sep 15, 2009
 *
 *-------------------------------------------------------------------------
 */
static void
make_libinfo(void)
{
    /* print variable definition and then the string as a macro. */
    insert_libhdf5_settings(stdout);
}


/*-------------------------------------------------------------------------
 * Function:	print_header
 *
 * Purpose:	Prints the header for the generated file.
 *
 * Return:	void
 *
 * Programmer:	Robb Matzke
 *		matzke@llnl.gov
 *		Mar 12 1997
 *
 *-------------------------------------------------------------------------
 */
static void
print_header(void)
{
    time_t		now = HDtime(NULL);
    struct tm		*tm = HDlocaltime(&now);
    char		real_name[30];
    char		host_name[256];
    int			i;
    const char		*s;
#ifdef H5_HAVE_GETPWUID
    struct passwd	*pwd = NULL;
#else
    int			pwd = 1;
#endif
    static const char	*month_name[] =
    {
	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    static const char	*purpose = "\
This machine-generated source code contains\n\
information about the library build configuration\n";

    /*
     * The real name is the first item from the passwd gecos field.
     */
#ifdef H5_HAVE_GETPWUID
    {
	size_t n;
	char *comma;

	if((pwd = HDgetpwuid(HDgetuid()))) {
	    if((comma = HDstrchr(pwd->pw_gecos, ','))) {
		n = MIN(sizeof(real_name) - 1, (unsigned)(comma - pwd->pw_gecos));
		HDstrncpy(real_name, pwd->pw_gecos, n);
		real_name[n] = '\0';
	    } /* end if */
            else {
		HDstrncpy(real_name, pwd->pw_gecos, sizeof(real_name));
		real_name[sizeof(real_name) - 1] = '\0';
	    } /* end else */
	} /* end if */
        else
	    real_name[0] = '\0';
    }
#else
    real_name[0] = '\0';
#endif

    /*
     * The FQDM of this host or the empty string.
     */
#ifdef H5_HAVE_GETHOSTNAME
    if(HDgethostname(host_name, sizeof(host_name)) < 0)
	host_name[0] = '\0';
#else
    host_name[0] = '\0';
#endif

    /*
     * The file header: warning, copyright notice, build information.
     */
    printf("/* Generated automatically by H5make_libsettings -- do not edit */\n\n\n");
    HDputs(FileHeader);		/*the copyright notice--see top of this file */

    printf(" *\n * Created:\t\t%s %2d, %4d\n",
	   month_name[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year);
    if(pwd || real_name[0] || host_name[0]) {
	printf(" *\t\t\t");
	if(real_name[0])
            printf("%s <", real_name);
#ifdef H5_HAVE_GETPWUID
	if(pwd)
            HDfputs(pwd->pw_name, stdout);
#endif
	if(host_name[0])
            printf("@%s", host_name);
	if(real_name[0])
            printf(">");
	HDputchar('\n');
    } /* end if */
    printf(" *\n * Purpose:\t\t");
    for(s = purpose; *s; s++) {
	HDputchar(*s);
	if('\n' == *s && s[1])
            printf(" *\t\t\t");
    } /* end for */

    printf(" *\n * Modifications:\n *\n");
    printf(" *\tDO NOT MAKE MODIFICATIONS TO THIS FILE!\n");
    printf(" *\tIt was generated by code in `H5make_libsettings.c'.\n");

    printf(" *\n *");
    for(i = 0; i < 73; i++)
        HDputchar('-');
    printf("\n */\n\n");
}


/*-------------------------------------------------------------------------
 * Function:	print_footer
 *
 * Purpose:	Prints the file footer for the generated file.
 *
 * Return:	void
 *
 * Programmer:	Quincey Koziol
 *		koziol@hdfgroup.org
 *		Mar 31 2010
 *
 *-------------------------------------------------------------------------
 */
static void
print_footer(void)
{
    /* nothing */
}


/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Main entry point.
 *
 * Return:	Success:	exit(0)
 *
 *		Failure:	exit(1)
 *
 * Programmer:	Albert Cheng
 *		2010/4/1
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    print_header();

    /* Generate embedded library information variable definition */
    make_libinfo();

    print_footer();

    HDexit(0);
}