ntp_libopts.c revision d54cfbdce4a9878ef65216dea36b62cf6646b84b
15c5c254abs/*
286c1bdekleink * ntp_libopts.c
386c1bdekleink *
486c1bdekleink * Common code interfacing with Autogen's libopts command-line option
586c1bdekleink * processing.
686c1bdekleink */
786c1bdekleink#ifdef HAVE_CONFIG_H
886c1bdekleink# include <config.h>
986c1bdekleink#endif
1086c1bdekleink
1186c1bdekleink#include <stdio.h>
1286c1bdekleink#include <stddef.h>
1386c1bdekleink#include "ntp_libopts.h"
1486c1bdekleink#include "ntp_stdlib.h"
1586c1bdekleink
1686c1bdekleinkextern const char *Version;	/* version.c for each program */
1786c1bdekleink
1886c1bdekleink
1986c1bdekleink/*
2086c1bdekleink * ntpOptionProcess() is a clone of libopts' optionProcess which
2186c1bdekleink * overrides the --version output, appending detail from version.c
2286c1bdekleink * which was not available at Autogen time.
2386c1bdekleink */
2486c1bdekleinkint
2586c1bdekleinkntpOptionProcess(
2686c1bdekleink	tOptions *	pOpts,
2786c1bdekleink	int		argc,
2886c1bdekleink	char **		argv
2986c1bdekleink	)
3086c1bdekleink{
3186c1bdekleink	char *		pchOpts;
3286c1bdekleink	char **		ppzFullVersion;
3386c1bdekleink	char *		pzNewFV;
345c5c254abs	char *		pzAutogenFV;
3586c1bdekleink	size_t		octets;
3686c1bdekleink	int		rc;
3786c1bdekleink
3886c1bdekleink	pchOpts = (void *)pOpts;
3986c1bdekleink	ppzFullVersion = (char **)(pchOpts + offsetof(tOptions,
4086c1bdekleink						      pzFullVersion));
4186c1bdekleink	pzAutogenFV = *ppzFullVersion;
4286c1bdekleink	octets = strlen(pzAutogenFV) +
43e5dee3cmycroft		 1 +	/* '\n' */
4486c1bdekleink		 strlen(Version) +
4586c1bdekleink		 1;	/* '\0' */
4686c1bdekleink	pzNewFV = emalloc(octets);
4786c1bdekleink	snprintf(pzNewFV, octets, "%s\n%s", pzAutogenFV, Version);
485c5c254abs	*ppzFullVersion = pzNewFV;
4986c1bdekleink	rc = optionProcess(pOpts, argc, argv);
5086c1bdekleink	*ppzFullVersion = pzAutogenFV;
5186c1bdekleink	free(pzNewFV);
5286c1bdekleink
5386c1bdekleink	return rc;
5486c1bdekleink}
5586c1bdekleink