parse.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <grass/gis.h>
  4. #include <grass/glocale.h>
  5. #include "local_proto.h"
  6. void parse_args(int argc, char** argv,
  7. char** input, char** field,
  8. int* history, int* columns, int *shell)
  9. {
  10. int i;
  11. struct Option *input_opt, *field_opt;
  12. struct Flag *hist_flag, *col_flag, *shell_flag, *region_flag, *topo_flag;
  13. input_opt = G_define_standard_option(G_OPT_V_MAP);
  14. field_opt = G_define_standard_option(G_OPT_V_FIELD);
  15. hist_flag = G_define_flag();
  16. hist_flag->key = 'h';
  17. hist_flag->description = _("Print history instead of info and exit");
  18. hist_flag->guisection = _("Print");
  19. col_flag = G_define_flag();
  20. col_flag->key = 'c';
  21. col_flag->description =
  22. _("Print types/names of table columns for specified layer instead of info and exit");
  23. col_flag->guisection = _("Print");
  24. region_flag = G_define_flag();
  25. region_flag->key = 'g';
  26. region_flag->description = _("Print region info in shell script style");
  27. region_flag->guisection = _("Print");
  28. shell_flag = G_define_flag();
  29. shell_flag->key = 'e';
  30. shell_flag->description = _("Print extended metadata info in shell script style");
  31. shell_flag->guisection = _("Print");
  32. topo_flag = G_define_flag();
  33. topo_flag->key = 't';
  34. topo_flag->description = _("Print topology info in shell script style");
  35. topo_flag->guisection = _("Print");
  36. if (G_parser(argc, argv))
  37. exit(EXIT_FAILURE);
  38. *input = G_store(input_opt->answer);
  39. *field = G_store(field_opt->answer);
  40. *history = hist_flag->answer ? TRUE : FALSE;
  41. *columns = col_flag->answer ? TRUE : FALSE;
  42. i = 0;
  43. *shell = SHELL_NO;
  44. if (shell_flag->answer)
  45. *shell |= SHELL_BASIC;
  46. if (region_flag->answer)
  47. *shell |= SHELL_REGION;
  48. if (topo_flag->answer)
  49. *shell |= SHELL_TOPO;
  50. }