Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.4 KiB

  1. /*
  2. * ISC-License
  3. *
  4. * Copyright 2004-2017 Christoph Lohmann <20h@r-36.net>
  5. * Copyright 2017-2018 Laslo Hunhold <dev@frign.de>
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef ARG_H
  20. #define ARG_H
  21. extern char *argv0;
  22. /* int main(int argc, char *argv[]) */
  23. #define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
  24. *argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
  25. int i_, argused_; \
  26. if ((*argv)[1] == '-' && !(*argv)[2]) { \
  27. argc--, argv++; \
  28. break; \
  29. } \
  30. for (i_ = 1, argused_ = 0; (*argv)[i_]; i_++) { \
  31. switch((*argv)[i_])
  32. #define ARGEND if (argused_) { \
  33. if ((*argv)[i_ + 1]) { \
  34. break; \
  35. } else { \
  36. argc--, argv++; \
  37. break; \
  38. } \
  39. } \
  40. } \
  41. }
  42. #define ARGC() ((*argv)[i_])
  43. #define ARGF_(x) (((*argv)[i_ + 1]) ? (argused_ = 1, &((*argv)[i_ + 1])) : \
  44. (*(argv + 1)) ? (argused_ = 1, *(argv + 1)) : (x))
  45. #define EARGF(x) ARGF_(((x), exit(1), (char *)0))
  46. #define ARGF() ARGF_((char *)0)
  47. #endif