From 0905160cbdec9602335b4e485b9e6fa90c253bed Mon Sep 17 00:00:00 2001 From: jbj Date: Fri, 19 Dec 2008 20:43:38 +0000 Subject: - add poptInit/poptFini/poptReadConfigFiles/poptSaneFile routines. --- popt.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 9 deletions(-) (limited to 'popt.h') diff --git a/popt.h b/popt.h index 1d6163f..c6762f5 100644 --- a/popt.h +++ b/popt.h @@ -98,6 +98,7 @@ #define POPT_ERROR_BADOPERATION -19 /*!< mutually exclusive logical operations requested */ #define POPT_ERROR_NULLARG -20 /*!< opt->arg should not be NULL */ #define POPT_ERROR_MALLOC -21 /*!< memory allocation failed */ +#define POPT_ERROR_BADCONFIG -22 /*!< config file failed sanity test */ /*@}*/ /** \ingroup popt @@ -236,6 +237,15 @@ typedef void (*poptCallbackType) (poptContext con, /*@globals internalState @*/ /*@modifies internalState @*/; +/** \ingroup popt + * Destroy context. + * @param con context + * @return NULL always + */ +/*@null@*/ +poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con) + /*@modifies con @*/; + /** \ingroup popt * Initialize popt context. * @param name context name (usually argv[0] program name) @@ -254,6 +264,31 @@ poptContext poptGetContext( /*@globals internalState @*/ /*@modifies internalState @*/; +/** \ingroup popt + * Destroy context (alternative implementation). + * @param con context + * @return NULL always + */ +/*@null@*/ +poptContext poptFini( /*@only@*/ /*@null@*/ poptContext con) + /*@modifies con @*/; + +/** \ingroup popt + * Initialize popt context (alternative implementation). + * This routine does poptGetContext() and then poptReadConfigFiles(). + * @param argc no. of arguments + * @param argv argument array + * @param options address of popt option table + * @param configPaths colon separated file path(s) to read. + * @return initialized popt context (NULL on error). + */ +/*@only@*/ /*@null@*/ /*@unused@*/ +poptContext poptInit(int argc, /*@dependent@*/ /*@keep@*/ const char ** argv, + /*@dependent@*/ /*@keep@*/ const struct poptOption * options, + /*@null@*/ const char * configPaths) + /*@globals fileSystem, internalState @*/ + /*@modifies fileSystem, internalState @*/; + /** \ingroup popt * Reinitialize popt context. * @param con context @@ -317,15 +352,6 @@ const char ** poptGetArgs(/*@null@*/poptContext con) const char * poptBadOption(/*@null@*/poptContext con, unsigned int flags) /*@*/; -/** \ingroup popt - * Destroy context. - * @param con context - * @return NULL always - */ -/*@null@*/ -poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con) - /*@modifies con @*/; - /** \ingroup popt * Add arguments to context. * @param con context @@ -370,6 +396,29 @@ int poptReadConfigFile(poptContext con, const char * fn) /*@modifies con->execs, con->numExecs, errno, fileSystem, internalState @*/; +/** \ingroup popt + * Perform sanity checks on a file path. + * @param fn file path + * @return 0 on OK, 1 on NOTOK. + */ +int poptSaneFile(const char * fn) + /*@globals errno, internalState @*/ + /*@modifies errno, internalState @*/; + +/** \ingroup popt + * Read configuration file(s). + * Colon separated files to read, looping over poptReadConfigFile(). + * Note that an '@' character preceeding a path in the list will + * also perform additional sanity checks on the file before reading. + * @param con context + * @param paths colon separated file name(s) to read + * @return 0 on success, POPT_ERROR_BADCONFIG on failure + */ +int poptReadConfigFiles(poptContext con, /*@null@*/ const char * paths) + /*@globals errno, fileSystem, internalState @*/ + /*@modifies con->execs, con->numExecs, + errno, fileSystem, internalState @*/; + /** \ingroup popt * Read default configuration from /etc/popt and $HOME/.popt. * @param con context -- cgit v1.2.1