Advertisement
Guest User

gopt.h

a guest
Dec 31st, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.57 KB | None | 0 0
  1. /* gopt.h version 8.1: tom.viza@gmail.com PUBLIC DOMAIN 2003-8 */
  2. /*
  3. I, Tom Vajzovic, am the author of this software and its documentation and
  4. permanently abandon all copyright and other intellectual property rights in
  5. them, including the right to be identified as the author.
  6.  
  7. I am fairly certain that this software does what the documentation says it
  8. does, but I cannot guarantee that it does, or that it does what you think it
  9. should, and I cannot guarantee that it will not have undesirable side effects.
  10.  
  11. You are free to use, modify and distribute this software as you please, but
  12. you do so at your own risk.  If you remove or hide this warning then you are
  13. responsible for any problems encountered by people that you make the software
  14. available to.
  15.  
  16. Before modifying or distributing this software I ask that you would please
  17. read http://www.purposeful.co.uk/tfl/
  18. */
  19.  
  20. #ifndef GOPT_H_INCLUDED
  21. #define GOPT_H_INCLUDED
  22.  
  23. #define GOPT_ONCE   0
  24. #define GOPT_REPEAT 1
  25. #define GOPT_NOARG  0
  26. #define GOPT_ARG    2
  27.  
  28. #define gopt_start(...)  (const void*)( const struct { int k; int f; const char *s; const char*const*l; }[]){ __VA_ARGS__, {0}}
  29. #define gopt_option(k,f,s,l)    { k, f, s, l }
  30. #define gopt_shorts( ... )      (const char*)(const char[]){ __VA_ARGS__, 0 }
  31. #define gopt_longs( ... )       (const char**)(const char*[]){ __VA_ARGS__, NULL }
  32.  
  33.  
  34. void *gopt_sort( int *argc, const char **argv, const void *opt_specs );
  35. /* returns a pointer for use in the following calls
  36.  * prints to stderr and call exit() on error
  37.  */
  38. size_t gopt( const void *opts, int key );
  39. /* returns the number of times the option was specified
  40.  * which will be 0 or 1 unless GOPT_REPEAT was used
  41.  */
  42. size_t gopt_arg( const void *opts, int key, const char **arg );
  43. /* returns the number of times the option was specified
  44.  * writes a pointer to the option argument from the first (or only) occurance to *arg
  45.  */
  46. const char *gopt_arg_i( const void *opts, int key, size_t i );
  47. /* returns a pointer to the ith (starting at zero) occurance
  48.  * of the option, or NULL if it was not specified that many times
  49.  */
  50. size_t gopt_args( const void *opts, int key, const char **args, size_t args_len );
  51. /* returns the number of times the option was specified
  52.  * writes pointers to the option arguments in the order of occurance to args[].
  53.  * writes at most args_len pointers
  54.  * if the return value is less than args_len, also writes a null pointer
  55.  */
  56. void gopt_free( void *opts );
  57. /* releases memory allocated in the corresponding call to gopt_sort()
  58.  * opts can no longer be used
  59.  */
  60. #endif /* GOPT_H_INCLUDED */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement