2014-09-03 07:07:26 -04:00
|
|
|
#ifndef __HELPER_H__
|
|
|
|
#define __HELPER_H__
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param string The input string.
|
|
|
|
* @param output Pointer to 2 dimensional array with parsed string.
|
|
|
|
* @param length Length of 2 dimensional array.
|
|
|
|
* @param ... Key, value parse. Replaces the string Key with value.
|
|
|
|
*
|
|
|
|
* Parses a string into arguments. While replacing keys with values.
|
|
|
|
*
|
|
|
|
* @returns TRUE when successful, FALSE when failed.
|
2014-11-24 14:35:28 -05:00
|
|
|
*/
|
2014-11-24 14:22:44 -05:00
|
|
|
int helper_parse_setup ( char * string, char ***output, int *length, ... );
|
2014-09-03 07:07:26 -04:00
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* Implementation of fgets with custom separator.
|
|
|
|
*/
|
2014-10-19 13:42:02 -04:00
|
|
|
char* fgets_s ( char* s, int n, FILE *iop, char sep );
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param input The input string.
|
|
|
|
*
|
|
|
|
* Tokenize the string on spaces.
|
|
|
|
*
|
|
|
|
* @returns a newly allocated 2 dimensional array of strings.
|
|
|
|
*/
|
2014-11-15 10:26:55 -05:00
|
|
|
char **tokenize ( const char *input );
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param argc Number of arguments.
|
|
|
|
* @param argv 2 dimensional array of arguments.
|
|
|
|
* @param key The key to search for
|
|
|
|
* @param val Pointer to the string to set to the key value (if found)
|
|
|
|
*
|
|
|
|
* Parse command line argument 'key' to character.
|
|
|
|
* This one supports character escaping.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns TRUE if key was found and val was set.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-11-15 10:26:55 -05:00
|
|
|
int find_arg_char ( const int argc, char * const argv[], const char * const key, char *val );
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param argc Number of arguments.
|
|
|
|
* @param argv 2 dimensional array of arguments.
|
|
|
|
* @param key The key to search for
|
|
|
|
* @param val Pointer to the string to set to the key value (if found)
|
|
|
|
*
|
|
|
|
* Parse command line argument 'key' to unsigned int.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns TRUE if key was found and val was set.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-11-15 10:26:55 -05:00
|
|
|
int find_arg_uint ( const int argc, char * const argv[], const char * const key, unsigned int *val );
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param argc Number of arguments.
|
|
|
|
* @param argv 2 dimensional array of arguments.
|
|
|
|
* @param key The key to search for
|
|
|
|
* @param val Pointer to the string to set to the key value (if found)
|
|
|
|
*
|
|
|
|
* Parse command line argument 'key' to int.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns TRUE if key was found and val was set.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-11-15 10:26:55 -05:00
|
|
|
int find_arg_int ( const int argc, char * const argv[], const char * const key, int *val );
|
|
|
|
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param argc Number of arguments.
|
|
|
|
* @param argv 2 dimensional array of arguments.
|
|
|
|
* @param key The key to search for
|
|
|
|
* @param val Pointer to the string to set to the key value (if found)
|
|
|
|
*
|
|
|
|
* Parse command line argument 'key' to string.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns TRUE if key was found and val was set.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-11-15 10:26:55 -05:00
|
|
|
int find_arg_str ( const int argc, char * const argv[], const char * const key, char** val );
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param argc Number of arguments.
|
|
|
|
* @param argv 2 dimensional array of arguments.
|
|
|
|
* @param key The key to search for
|
|
|
|
*
|
|
|
|
* Check if key is passed as argument.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns return position of string or -1 if not found.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-11-15 10:26:55 -05:00
|
|
|
int find_arg ( const int argc, char * const argv[], const char * const key );
|
|
|
|
|
2014-09-03 07:07:26 -04:00
|
|
|
#endif // __HELPER_H__
|