parse.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. const char *answer;
  12. struct Option *input_opt, *field_opt, *print_opt;
  13. struct Flag *hist_flag, *col_flag;
  14. input_opt = G_define_standard_option(G_OPT_V_MAP);
  15. field_opt = G_define_standard_option(G_OPT_V_FIELD);
  16. print_opt = G_define_option();
  17. print_opt->key = "shell";
  18. print_opt->multiple = YES;
  19. print_opt->options = "basic,region,topo";
  20. print_opt->label = _("Print info in shell script style");
  21. print_opt->description = _("Ignored if -h or -c flags are given");
  22. print_opt->descriptions = _("basic;basic info only;"
  23. "region;map region;"
  24. "topo;topology information");
  25. print_opt->guisection = _("Print");
  26. hist_flag = G_define_flag();
  27. hist_flag->key = 'h';
  28. hist_flag->description = _("Print history instead of info and exit");
  29. hist_flag->guisection = _("Print");
  30. col_flag = G_define_flag();
  31. col_flag->key = 'c';
  32. col_flag->description =
  33. _("Print types/names of table columns for specified layer instead of info and exit");
  34. col_flag->guisection = _("Print");
  35. if (G_parser(argc, argv))
  36. exit(EXIT_FAILURE);
  37. *input = G_store(input_opt->answer);
  38. *field = G_store(field_opt->answer);
  39. *history = hist_flag->answer ? TRUE : FALSE;
  40. *columns = col_flag->answer ? TRUE : FALSE;
  41. i = 0;
  42. *shell = NO_INFO;
  43. if (print_opt->answer) {
  44. while(print_opt->answers[i]) {
  45. answer = print_opt->answers[i++];
  46. if (strcmp(answer, "basic") == 0)
  47. *shell |= BASIC_INFO;
  48. else if (strcmp(answer, "region") == 0)
  49. *shell |= REGION_INFO;
  50. else if (strcmp(answer, "topo") == 0)
  51. *shell |= TOPO_INFO;
  52. }
  53. }
  54. }