main.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /***************************************************************************
  2. *
  3. * MODULE: g.version
  4. * AUTHOR(S): Michael Shapiro, CERL
  5. * Andreas Lange - <andreas.lange rhein-main.de>
  6. * Justin Hickey - Thailand - jhickey hpcc.nectec.or.th
  7. * Extended info by Martin Landa <landa.martin gmail.com>
  8. * PURPOSE: Output GRASS version number, date and copyright message.
  9. *
  10. * COPYRIGHT: (C) 2000-2013 by the GRASS Development Team
  11. *
  12. * This program is free software under the GPL (>=v2)
  13. * Read the file COPYING that comes with GRASS for details.
  14. *****************************************************************************/
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <grass/gis.h>
  19. #include <grass/glocale.h>
  20. #include "local_proto.h"
  21. #include <proj_api.h>
  22. #ifdef HAVE_GDAL
  23. #include <gdal_version.h>
  24. #endif
  25. #ifdef HAVE_GEOS
  26. #include <geos_c.h>
  27. #endif
  28. #ifdef HAVE_SQLITE
  29. #include <sqlite3.h>
  30. #endif
  31. #ifndef GRASS_VERSION_UPDATE_PKG
  32. #define GRASS_VERSION_UPDATE_PKG "0.1"
  33. #endif
  34. static const char COPYING[] =
  35. #include <grass/copying.h>
  36. ;
  37. static const char GRASS_CONFIGURE_PARAMS[] =
  38. #include <grass/confparms.h>
  39. ;
  40. int main(int argc, char *argv[])
  41. {
  42. struct GModule *module;
  43. struct Flag *copyright, *build, *gish_rev, *shell, *extended;
  44. G_gisinit(argv[0]);
  45. module = G_define_module();
  46. G_add_keyword(_("general"));
  47. G_add_keyword(_("supporting"));
  48. module->label = _("Displays GRASS version info.");
  49. module->description = _("Optionally also print build or copyright information.");
  50. copyright = G_define_flag();
  51. copyright->key = 'c';
  52. copyright->description = _("Print also the copyright message");
  53. copyright->guisection = _("Additional info");
  54. build = G_define_flag();
  55. build->key = 'b';
  56. build->description = _("Print also the build information");
  57. build->guisection = _("Additional info");
  58. gish_rev = G_define_flag();
  59. gish_rev->key = 'r';
  60. gish_rev->description =
  61. _("Print also the GIS library revision number and date");
  62. gish_rev->guisection = _("Additional info");
  63. extended = G_define_flag();
  64. extended->key = 'e';
  65. extended->label = _("Print also extended info for additional libraries");
  66. extended->description = _("GDAL/OGR, PROJ.4, GEOS");
  67. extended->guisection = _("Additional info");
  68. shell = G_define_flag();
  69. shell->key = 'g';
  70. shell->description = _("Print info in shell script style (including SVN revision number)");
  71. shell->guisection = _("Shell");
  72. if (G_parser(argc, argv))
  73. exit(EXIT_FAILURE);
  74. if (shell->answer) {
  75. fprintf(stdout, "version=%s\n", GRASS_VERSION_NUMBER);
  76. fprintf(stdout, "date=%s\n", GRASS_VERSION_DATE);
  77. fprintf(stdout, "revision=%s\n", GRASS_VERSION_SVN);
  78. fprintf(stdout, "build_date=%d-%02d-%02d\n", YEAR, MONTH, DAY);
  79. }
  80. else {
  81. fprintf(stdout, "GRASS %s (%s)\n",
  82. GRASS_VERSION_NUMBER, GRASS_VERSION_DATE);
  83. }
  84. if (copyright->answer) {
  85. fprintf(stdout, "\n");
  86. fputs(COPYING, stdout);
  87. }
  88. if (build->answer) {
  89. fprintf(stdout, "\n");
  90. fputs(GRASS_CONFIGURE_PARAMS, stdout);
  91. fprintf(stdout, "\n");
  92. }
  93. if (gish_rev->answer) {
  94. /* fprintf(stdout, "%s\n%s\n", GIS_H_VERSION, GIS_H_DATE); */
  95. char **rev_ver = G_tokenize(GIS_H_VERSION, "$");
  96. char **rev_time = G_tokenize(GIS_H_DATE, "$");
  97. if (shell->answer) {
  98. fprintf(stdout, "libgis_revision=%s\n", strstr(rev_ver[1], " ") + 1);
  99. fprintf(stdout, "libgis_date=\"%s\"\n", strstr(rev_time[1], " ") + 1);
  100. }
  101. else {
  102. fprintf(stdout, "libgis %s\nlibgis %s\n", rev_ver[1], rev_time[1]);
  103. }
  104. G_free_tokens(rev_ver);
  105. G_free_tokens(rev_time);
  106. }
  107. if (extended->answer) {
  108. char *proj = NULL;
  109. G_asprintf(&proj, "%d", PJ_VERSION);
  110. if (strlen(proj) == 3) {
  111. if (shell->answer)
  112. fprintf(stdout, "proj4=%c.%c.%c\n", proj[0], proj[1], proj[2]);
  113. else
  114. fprintf(stdout, "PROJ.4: %c.%c.%c\n", proj[0], proj[1], proj[2]);
  115. }
  116. else {
  117. if (shell->answer)
  118. fprintf(stdout, "proj4=%s\n", proj);
  119. else
  120. fprintf(stdout, "PROJ.4: %s\n", proj);
  121. }
  122. #ifdef HAVE_GDAL
  123. if (shell->answer)
  124. fprintf(stdout, "gdal=%s\n", GDAL_RELEASE_NAME);
  125. else
  126. fprintf(stdout, "GDAL/OGR: %s\n", GDAL_RELEASE_NAME);
  127. #else
  128. if (shell->answer)
  129. fprintf(stdout, "gdal=\n");
  130. else
  131. fprintf(stdout, "%s\n", _("GRASS not compiled with GDAL/OGR support"));
  132. #endif
  133. #ifdef HAVE_GEOS
  134. if (shell->answer)
  135. fprintf(stdout, "geos=%s\n", GEOS_VERSION);
  136. else
  137. fprintf(stdout, "GEOS: %s\n", GEOS_VERSION);
  138. #else
  139. if (shell->answer)
  140. fprintf(stdout, "geos=\n");
  141. else
  142. fprintf(stdout, "%s\n", _("GRASS not compiled with GEOS support"));
  143. #endif
  144. #ifdef HAVE_SQLITE
  145. if (shell->answer)
  146. fprintf(stdout, "sqlite=%s\n", SQLITE_VERSION);
  147. else
  148. fprintf(stdout, "SQLite: %s\n", SQLITE_VERSION);
  149. #else
  150. if (shell->answer)
  151. fprintf(stdout, "sqlite=\n");
  152. else
  153. fprintf(stdout, "%s\n", _("GRASS not compiled with SQLite support"));
  154. #endif
  155. }
  156. return (EXIT_SUCCESS);
  157. }