2002-10-13 22:39:21 +08:00
|
|
|
#ifndef _H_ARGV_
|
|
|
|
#define _H_ARGV_
|
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-12-25 01:06:35 +08:00
|
|
|
* \file rpmio/argv.h
|
2014-05-11 08:27:26 +08:00
|
|
|
*
|
|
|
|
* Argument Manipulation API.
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
|
|
|
|
2008-01-28 19:43:32 +08:00
|
|
|
#include <stdio.h>
|
2010-09-21 16:10:14 +08:00
|
|
|
#include <rpm/rpmtypes.h>
|
2008-01-28 19:43:32 +08:00
|
|
|
|
2007-10-08 16:05:06 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-04-07 14:29:06 +08:00
|
|
|
typedef char ** ARGV_t;
|
2008-04-07 17:11:16 +08:00
|
|
|
typedef char * const *ARGV_const_t;
|
2002-10-14 22:52:45 +08:00
|
|
|
|
|
|
|
typedef int * ARGint_t;
|
|
|
|
struct ARGI_s {
|
|
|
|
unsigned nvals;
|
|
|
|
ARGint_t vals;
|
|
|
|
};
|
|
|
|
typedef struct ARGI_s * ARGI_t;
|
2008-04-07 17:34:07 +08:00
|
|
|
typedef struct ARGI_s const * const ARGI_const_t;
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Print argv array elements.
|
|
|
|
* @param msg output message prefix (or NULL)
|
|
|
|
* @param argv argv array
|
|
|
|
* @param fp output file handle (NULL uses stderr)
|
|
|
|
*/
|
2008-04-07 17:35:37 +08:00
|
|
|
void argvPrint(const char * msg, ARGV_const_t argv, FILE * fp);
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-14 22:52:45 +08:00
|
|
|
* Destroy an argi array.
|
|
|
|
* @param argi argi array
|
|
|
|
* @return NULL always
|
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
ARGI_t argiFree(ARGI_t argi);
|
2002-10-14 22:52:45 +08:00
|
|
|
|
2008-04-14 20:58:10 +08:00
|
|
|
|
|
|
|
/** \ingroup rpmargv
|
|
|
|
* Create an empty argv array.
|
|
|
|
* @return pointer to empty argv
|
|
|
|
*/
|
|
|
|
ARGV_t argvNew(void);
|
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Destroy an argv array.
|
|
|
|
* @param argv argv array
|
2002-10-14 22:52:45 +08:00
|
|
|
* @return NULL always
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
ARGV_t argvFree(ARGV_t argv);
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-20 06:48:25 +08:00
|
|
|
* Return no. of elements in argi array.
|
|
|
|
* @param argi argi array
|
2002-12-03 10:57:02 +08:00
|
|
|
* @return no. of elements
|
2002-10-20 06:48:25 +08:00
|
|
|
*/
|
2008-04-07 17:34:07 +08:00
|
|
|
int argiCount(ARGI_const_t argi);
|
2002-10-20 06:48:25 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-12-03 10:57:02 +08:00
|
|
|
* Return data from argi array.
|
|
|
|
* @param argi argi array
|
|
|
|
* @return argi array data address
|
|
|
|
*/
|
2008-04-07 17:34:07 +08:00
|
|
|
ARGint_t argiData(ARGI_const_t argi);
|
2002-12-03 10:57:02 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Return no. of elements in argv array.
|
|
|
|
* @param argv argv array
|
2002-12-03 10:57:02 +08:00
|
|
|
* @return no. of elements
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
2008-04-07 17:11:16 +08:00
|
|
|
int argvCount(ARGV_const_t argv);
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-12-03 10:57:02 +08:00
|
|
|
* Return data from argv array.
|
|
|
|
* @param argv argv array
|
|
|
|
* @return argv array data address
|
|
|
|
*/
|
2008-04-07 17:11:16 +08:00
|
|
|
ARGV_t argvData(ARGV_t argv);
|
2002-12-03 10:57:02 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Compare argv arrays (qsort/bsearch).
|
|
|
|
* @param a 1st instance address
|
|
|
|
* @param b 2nd instance address
|
|
|
|
* @return result of comparison
|
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
int argvCmp(const void * a, const void * b);
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Sort an argv array.
|
|
|
|
* @param argv argv array
|
2002-12-25 01:06:35 +08:00
|
|
|
* @param compar strcmp-like comparison function, or NULL for argvCmp()
|
|
|
|
* @return 0 always
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
int argvSort(ARGV_t argv, int (*compar)(const void *, const void *));
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Find an element in an argv array.
|
|
|
|
* @param argv argv array
|
2002-12-25 01:06:35 +08:00
|
|
|
* @param val string to find
|
|
|
|
* @param compar strcmp-like comparison function, or NULL for argvCmp()
|
|
|
|
* @return found string (NULL on failure)
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
2008-04-07 17:11:16 +08:00
|
|
|
ARGV_t argvSearch(ARGV_const_t argv, const char *val,
|
2007-09-11 22:48:54 +08:00
|
|
|
int (*compar)(const void *, const void *));
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-14 22:52:45 +08:00
|
|
|
* Add an int to an argi array.
|
|
|
|
* @retval *argip argi array
|
2002-12-25 01:06:35 +08:00
|
|
|
* @param ix argi array index (or -1 to append)
|
2002-10-14 22:52:45 +08:00
|
|
|
* @param val int arg to add
|
|
|
|
* @return 0 always
|
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
int argiAdd(ARGI_t * argip, int ix, int val);
|
2002-10-14 22:52:45 +08:00
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-14 22:52:45 +08:00
|
|
|
* Add a string to an argv array.
|
|
|
|
* @retval *argvp argv array
|
|
|
|
* @param val string arg to append
|
|
|
|
* @return 0 always
|
|
|
|
*/
|
2008-04-07 14:31:21 +08:00
|
|
|
int argvAdd(ARGV_t * argvp, const char *val);
|
2002-10-14 22:52:45 +08:00
|
|
|
|
2008-04-14 21:21:40 +08:00
|
|
|
/** \ingroup rpmargv
|
|
|
|
* Add a number to an argv array (converting to a string).
|
|
|
|
* @retval *argvp argv array
|
|
|
|
* @param val numeric arg to append
|
|
|
|
* @return 0 always
|
|
|
|
*/
|
|
|
|
int argvAddNum(ARGV_t * argvp, int val);
|
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-10-13 22:39:21 +08:00
|
|
|
* Append one argv array to another.
|
|
|
|
* @retval *argvp argv array
|
|
|
|
* @param av argv array to append
|
2002-10-14 22:52:45 +08:00
|
|
|
* @return 0 always
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
2008-04-07 17:11:16 +08:00
|
|
|
int argvAppend(ARGV_t * argvp, ARGV_const_t av);
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2010-09-21 16:10:14 +08:00
|
|
|
enum argvFlags_e {
|
2010-03-15 17:54:55 +08:00
|
|
|
ARGV_NONE = 0,
|
|
|
|
ARGV_SKIPEMPTY = (1 << 0), /* omit empty strings from result */
|
2010-09-21 16:10:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef rpmFlags argvFlags;
|
2010-03-15 17:54:55 +08:00
|
|
|
|
|
|
|
/** \ingroup rpmargv
|
|
|
|
* Split a string into an argv array.
|
|
|
|
* @param str string arg to split
|
2013-02-17 02:29:33 +08:00
|
|
|
* @param seps separator characters
|
2010-03-15 17:54:55 +08:00
|
|
|
* @param flags flags to control behavior
|
|
|
|
* @return argv array
|
|
|
|
*/
|
|
|
|
ARGV_t argvSplitString(const char * str, const char * seps, argvFlags flags);
|
|
|
|
|
2007-12-01 04:13:15 +08:00
|
|
|
/** \ingroup rpmargv
|
2002-12-25 01:06:35 +08:00
|
|
|
* Split a string into an argv array.
|
2002-10-13 22:39:21 +08:00
|
|
|
* @retval *argvp argv array
|
2002-12-25 01:06:35 +08:00
|
|
|
* @param str string arg to split
|
2013-02-17 02:29:33 +08:00
|
|
|
* @param seps separator characters
|
2002-12-25 01:06:35 +08:00
|
|
|
* @return 0 always
|
2002-10-13 22:39:21 +08:00
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
int argvSplit(ARGV_t * argvp, const char * str, const char * seps);
|
2002-10-13 22:39:21 +08:00
|
|
|
|
2008-04-18 17:36:02 +08:00
|
|
|
/** \ingroup rpmargv
|
|
|
|
* Join an argv array into a string.
|
|
|
|
* @param *argv argv array to join
|
2013-02-17 02:29:33 +08:00
|
|
|
* @param sep separator string to use
|
2008-04-18 17:36:02 +08:00
|
|
|
* @return malloc'ed string
|
|
|
|
*/
|
|
|
|
char *argvJoin(ARGV_const_t argv, const char *sep);
|
|
|
|
|
2002-10-13 22:39:21 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _H_ARGV_ */
|