posix_getopt.h 883 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. // implementation of posix getopt using last getopt for demonstration purposes
  3. #include "last_getopt.h"
  4. namespace NLastGetopt {
  5. extern char* optarg;
  6. extern int optind;
  7. extern int optopt;
  8. extern int opterr;
  9. extern int optreset;
  10. enum {
  11. no_argument = NO_ARGUMENT,
  12. required_argument = REQUIRED_ARGUMENT,
  13. optional_argument = OPTIONAL_ARGUMENT,
  14. };
  15. struct option {
  16. const char* name;
  17. int has_arg;
  18. int* flag;
  19. int val;
  20. };
  21. int getopt(int argc, char* const* argv, const char* optstring);
  22. int getopt_long(int argc, char* const* argv, const char* optstring,
  23. const struct option* longopts, int* longindex);
  24. int getopt_long_only(int argc, char* const* argv, const char* optstring,
  25. const struct option* longopts, int* longindex);
  26. }