opts.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #define ZPL_IMPLEMENTATION
  2. #define ZPL_STATIC
  3. #include <zpl.h>
  4. int main(int argc, char **argv)
  5. {
  6. zpl_opts opts={0};
  7. zpl_opts_init(&opts, zpl_heap(), argv[0]);
  8. zpl_opts_add(&opts, "?", "help", "the HELP section", ZPL_OPTS_FLAG);
  9. zpl_opts_add(&opts, "f", "foo", "the test *foo* entry.", ZPL_OPTS_STRING);
  10. zpl_opts_add(&opts, "p", "pi", "PI Value Redefined !!!", ZPL_OPTS_FLOAT);
  11. zpl_opts_add(&opts, "4", "4pay", "hmmmm", ZPL_OPTS_INT);
  12. zpl_opts_add(&opts, "E", "enablegfx", "Enables HD resource pack", ZPL_OPTS_FLAG);
  13. zpl_opts_positional_add(&opts, "4pay");
  14. b32 ok=zpl_opts_compile(&opts, argc, argv);
  15. if (ok && zpl_opts_positionals_filled(&opts)) {
  16. b32 help=zpl_opts_has_arg(&opts, "help");
  17. if (help) {
  18. zpl_opts_print_help(&opts);
  19. return 0;
  20. }
  21. zpl_string foo=zpl_opts_string(&opts, "foo", "WRONG!");
  22. f64 some_num=zpl_opts_real(&opts, "pi", 0.0);
  23. i32 right=zpl_opts_integer(&opts, "4pay", 42);
  24. zpl_printf("The arg is %s\nPI value is: %f\nright: %d?\n", foo, some_num,
  25. right);
  26. b32 gfx=zpl_opts_has_arg(&opts, "enablegfx");
  27. if (gfx) {
  28. zpl_printf("You wanted HD graphics? Here:\n\n");
  29. for (int i=0; i<5; ++i) {
  30. zpl_printf("iiiii\n");
  31. }
  32. }
  33. }
  34. else {
  35. zpl_opts_print_errors(&opts);
  36. zpl_opts_print_help(&opts);
  37. }
  38. return 0;
  39. }