2222 * short, meaning that the data can be inserted after a whitespace
2323 * long, meaning that the data can be inserted after a space char
2424 *
25- * flags can be merged together, if they are flags (i.e: tar -xzvf ...) */
25+ * keys can be merged together, if they are flags (i.e: tar -xzvf ...) or,
26+ * if ARG_PARSE_MERGED is passed to the arg_parse function, merged key-value
27+ * arguments can be used (i.e objdump -Mintel ...) */
2628
2729
2830#ifndef __SL_ARGPARSE_H__
4244#define ARG_NMATCH -6
4345#define ARG_NVALUE -7
4446
45- typedef int p_arg_handler (void * data_ptr , size_t blksize , void * retval );
47+ /* Type for the return codes */
48+ typedef signed char arg_return ;
49+
50+ typedef arg_return p_arg_handler (void * data_ptr , size_t blksize , void * retval );
4651
4752/* The handler is the parser for the value of the argument
4853 * if NULL is passed instead of a valid handler function,
@@ -56,22 +61,24 @@ p_arg_handler arg_string_handler;
5661 * to the static buffer */
5762p_arg_handler arg_strcpy_handler ;
5863
59-
6064/* This flag tells the parser to set the flag argument value to 0 instead of 1 */
6165#define ARG_FLAG_UNSET 0x01
6266/* This flag tells the parser that the value for this argument is optional */
6367#define ARG_FLAG_OPTIONAL 0x04
6468/* This flag tells the parser to stop when the argument is met and parsed */
6569#define ARG_FLAG_HALT 0x08
6670
71+ /* Global parser flags */
72+ /* Defaults */
73+ #define ARG_PARSE_DEFAULT 0x0
74+ /* Allow merged arguments (i.e: objdump -Mintel ...) */
75+ #define ARG_PARSE_MERGED 0x01
76+
6777/* Flags define the behaviour of the arguments parser
6878 * As example, ARG_FLAG_HALT will cause parser to be stopped when
6979 * the specified argument is met. */
7080typedef unsigned char arg_flags ;
7181
72- /* Type for the return codes */
73- typedef signed char arg_return ;
74-
7582/* struct arg_argument
7683 * Contains a basic description of the argument list
7784 * char short_arg: a short variant of the argument's key (i.e: -r)
@@ -92,25 +99,33 @@ struct arg_argument {
9299typedef struct arg_argument arg_list [];
93100
94101/* char * arg_parse:
95- * IN int * argc: argument count
96- * IN char *** argv: arguments array
97- * IN arg_list list: list, defining the accepted arguments
98- * IN char ** not_keys: a buffer for random values
99- * IN size_t * not_keys_size: size of the not_keys buffer
100- * OUT arg_return * return_code: a return code of the status
101- * ARG_SUCCESS [0] if the parsing is done without failures
102+ * @param argc
103+ * argument count
104+ * @param argv
105+ * arguments array
106+ * @param list
107+ * list, defining the accepted arguments
108+ * @param not_keys
109+ * a buffer for random values
110+ * @param not_keys_size
111+ * size of the not_keys buffer
112+ * @param flags
113+ * flags, defining the behaviour of the parser
114+ * @param return_code
115+ * return code of the parser
116+ * NOTE: ARG_SUCCESS [0] is returned on success
102117 *
103118 * RETURN char * arg:
104119 * - NULL on a complete success.
105120 * - A pointer to the argv list's element which failed the parsing on
106121 * a failure.
107122 *
108123 * NOTES:
109- * 1 this function is reentrant , meaning, that if an error occured, you
124+ * 1 this function is re-entrant , meaning, that if an error occured, you
110125 * can call this function again with the same set of variables and
111126 * continue parsing.
112127 * 2 this function changes the addresses of the pointers, to save them
113128 * as they were, consider writing them into another set of variables. */
114- char * arg_parse (int * argc , char * * * argv , arg_list list , char * * not_keys , size_t * not_keys_size , arg_return * return_code );
129+ char * arg_parse (int * argc , char * * * argv , arg_list list , char * * not_keys , size_t * not_keys_size , arg_flags flags , arg_return * return_code );
115130
116131#endif
0 commit comments