1919 * check whether or not the argument belongs in line
2020 * check if its long or short type
2121 * parse accordingly:
22- * short, meaning that the data can be inserted after the argument key or after a space
23- * long, meaning that the data can be inserted after a space or after a '=' char
24- * The ordering plays some role */
22+ * short, meaning that the data can be inserted after a whitespace
23+ * long, meaning that the data can be inserted after a space char
24+ *
25+ * flags can be merged together, if they are flags (i.e: tar -xzvf ...) */
2526
2627
2728#ifndef __SL_ARGPARSE_H__
2829#define __SL_ARGPARSE_H__
2930
30- #include <malloc.h>
31-
3231/* A simple implementation of some important "string.h" functions */
3332#ifdef ARG_STANDALONE
3433# define ARG_ASSERT (x )
@@ -58,7 +57,6 @@ static void * arg_memcpy (void * dest, void * src, size_t n) {
5857 return dest ;
5958}
6059
61-
6260#else
6361# include <string.h>
6462# include <assert.h>
@@ -84,9 +82,8 @@ static void * arg_memcpy (void * dest, void * src, size_t n) {
8482#define ARG_NMATCH -6
8583#define ARG_NVALUE -7
8684
87- #define ARG_ORDER 0x0001
88-
89-
85+ /* If you want to make this work, you have to recompile the library
86+ * with -DARG_TRUE_EQ_ONE (makes successful returns equal to 1) */
9087#ifndef ARG_TRUE_EQ_ONE
9188# define ARG_SUCCESS 0
9289#else
@@ -95,11 +92,11 @@ static void * arg_memcpy (void * dest, void * src, size_t n) {
9592
9693#define ARG_STREQ (a , b ) (arg_strcmp(a, b) == 0)
9794
98- /* A slightly altered strcmp(), will return 0 even if the strings
99- * don't match after the first one ended (i.e: abc = abcde, but
100- * abc != abdc)
95+ /* A slightly altered strcmp(), will move the pointer of the second
96+ * string, but will restore it to the former state, if strings don't
97+ * match
10198 * IN char * f: first string
102- * IN char * f: second string
99+ * IN char ** f: second string
103100 *
104101 * RETURN int:
105102 * non-zero, if the strings don't match */
@@ -118,7 +115,6 @@ static int arg_strcmp (char * f, char ** s) {
118115 return diff ;
119116}
120117
121- typedef int arg_callback ();
122118typedef int p_arg_handler (void * data_ptr , size_t blksize , void * retval );
123119
124120/* The handler is the parser for the value of the argument
@@ -129,10 +125,6 @@ typedef p_arg_handler * arg_handler;
129125
130126/* A handler for a generic string. */
131127static p_arg_handler arg_string_handler ;
132- /* A handler for a raw data, meaning that the raw byte
133- * data will be stored inside a pointer. Acts almost the
134- * same way as the arg_string_handler does. */
135- static p_arg_handler arg_raw_handler ;
136128
137129static int arg_string_handler (void * data_ptr , size_t blksize , void * retval ) {
138130 if (blksize == 0 ) {
@@ -143,19 +135,10 @@ static int arg_string_handler (void * data_ptr, size_t blksize, void * retval) {
143135 return 0 ;
144136}
145137
146- static int arg_raw_handler (void * data_ptr , size_t blksize , void * retval ) {
147- if (blksize == 0 ) {
148- retval = NULL ;
149- return 0 ;
150- }
151- ARG_MEMCPY (retval , data_ptr , blksize );
152- return 0 ;
153- }
154-
155138/* Flags define the behaviour of the arguments parser
156139 * As example, ARG_FLAG_HALT will cause parser to be stopped when
157140 * the specified argument is met. */
158- typedef unsigned char arg_flags ;
141+ typedef unsigned char arg_flags ; /* NOT IMPLEMENTED YET */
159142
160143/* Type for the return codes */
161144typedef signed char arg_return ;
@@ -197,7 +180,7 @@ typedef struct arg_argument arg_list[];
197180 *
198181 * NOTE:
199182 * this function changes the addresses of the pointers, to save them
200- * as they were, consider writing them into another set of variables.*/
183+ * as they were, consider writing them into another set of variables. */
201184char * * arg_parse (int argc , char * * argv , arg_list list , char * * not_keys , size_t * not_keys_size , arg_return * return_code );
202185
203186#endif
0 commit comments