main.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /****************************************************************************
  2. *
  3. * MODULE: v.timestamp
  4. *
  5. * AUTHOR(S): Soeren Gebbert <soerengebbert googlemail.com>
  6. * based on r.timestamp from Michael Shapiro, CERL (original contributor)
  7. *
  8. * PURPOSE: Print/add/remove a timestamp for a vector map
  9. * COPYRIGHT: (C) 2012 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <grass/gis.h>
  20. #include <grass/glocale.h>
  21. int main(int argc, char *argv[])
  22. {
  23. struct GModule *module;
  24. struct Option *map, *layer, *date;
  25. struct TimeStamp ts;
  26. char *name;
  27. const char *mapset;
  28. int modify;
  29. G_gisinit(argv[0]);
  30. module = G_define_module();
  31. G_add_keyword(_("vector"));
  32. G_add_keyword(_("metadata"));
  33. G_add_keyword(_("timestamp"));
  34. G_add_keyword(_("time"));
  35. module->label = _("Modifies a timestamp for a vector map.");
  36. module->description = _("Print/add/remove a timestamp for a vector map.");
  37. map = G_define_standard_option(G_OPT_V_MAP);
  38. layer = G_define_standard_option(G_OPT_V_FIELD);
  39. date = G_define_option();
  40. date->key = "date";
  41. date->key_desc = "timestamp";
  42. date->required = NO;
  43. date->type = TYPE_STRING;
  44. date->label = _("Datetime, datetime1/datetime2, or 'none' to remove");
  45. date->description = _("Format: '15 jan 1994' (absolute) or '2 years' (relative)");
  46. if (G_parser(argc, argv))
  47. exit(EXIT_FAILURE);
  48. name = map->answer;
  49. modify = date->answer != NULL;
  50. if (modify)
  51. mapset = G_find_vector(name, G_mapset());
  52. else
  53. mapset = G_find_vector(name, "");
  54. if (mapset == NULL) {
  55. G_fatal_error(_("Vector map <%s> not found %s"), name,
  56. modify ? "in current mapset" : "");
  57. exit(EXIT_FAILURE);
  58. }
  59. if (!modify) {
  60. if (G_read_vector_timestamp(name, layer->answer, "", &ts) == 1) {
  61. G_write_timestamp(stdout, &ts);
  62. exit(EXIT_SUCCESS);
  63. }
  64. else
  65. exit(EXIT_FAILURE);
  66. }
  67. if (strcmp(date->answer, "none") == 0) {
  68. G_remove_vector_timestamp(name, layer->answer);
  69. exit(EXIT_SUCCESS);
  70. }
  71. if(G_scan_timestamp(&ts, date->answer) != 1)
  72. G_fatal_error("Timestamp format is invalid");
  73. G_write_vector_timestamp(name, layer->answer, &ts);
  74. exit(EXIT_SUCCESS);
  75. }