args.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/glocale.h>
  4. #include "local_proto.h"
  5. void parse_args(int argc, char **argv,
  6. struct _options *options, struct _flags* flags)
  7. {
  8. options->dsn = G_define_option();
  9. options->dsn->key = "dsn";
  10. options->dsn->type = TYPE_STRING;
  11. options->dsn->gisprompt = "old_file,file,dsn";
  12. options->dsn->label = _("OGR data source name");
  13. options->dsn->description = _("Examples:\n"
  14. "\t\tESRI Shapefile: directory containing shapefiles\n"
  15. "\t\tMapInfo File: directory containing mapinfo files\n"
  16. "\t\tPostGIS database: \"PG:dbname=<database>\"");
  17. options->dsn->guisection = _("Data source");
  18. options->layer = G_define_option();
  19. options->layer->key = "layer";
  20. options->layer->type = TYPE_STRING;
  21. options->layer->required = NO;
  22. options->layer->multiple = NO;
  23. options->layer->label = _("OGR layer name");
  24. options->layer->description = _("Examples:\n"
  25. "\t\tESRI Shapefile: shapefile name\n"
  26. "\t\tMapInfo File: mapinfo file name\n"
  27. "\t\tPostGIS database: table name");
  28. options->layer->guisection = _("Data source");
  29. options->output = G_define_standard_option(G_OPT_V_OUTPUT);
  30. options->output->required = NO;
  31. options->output->description = _("Name for GRASS vector map");
  32. flags->format = G_define_flag();
  33. flags->format->key = 'f';
  34. flags->format->description = _("List supported OGR formats and exit");
  35. flags->format->guisection = _("Print");
  36. flags->layer = G_define_flag();
  37. flags->layer->key = 'l';
  38. flags->layer->description = _("List available OGR layers in dsn and exit");
  39. flags->layer->guisection = _("Print");
  40. flags->topo = G_define_flag();
  41. flags->topo->key = 'b';
  42. flags->topo->description = _("Do not build topology");
  43. if (G_parser(argc, argv))
  44. exit(EXIT_FAILURE);
  45. }
  46. void get_args(const struct _options *options, const struct _flags *flags,
  47. char **dsn, char **layer, char **output,
  48. int *list_format, int *list_layers, int *topo)
  49. {
  50. *dsn = options->dsn->answer;
  51. *layer = options->layer->answer;
  52. *output = options->output->answer;
  53. *list_format = flags->format->answer ? 1 : 0;
  54. *list_layers = flags->layer->answer ? 1 : 0;
  55. *topo = flags->topo-> answer ? 1 : 0;
  56. }