main.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /* TODO: remove this style of include */
  35. static const char COPYING[] =
  36. #include <grass/copying.h>
  37. ;
  38. static const char CITING[] =
  39. #include <grass/citing.h>
  40. ;
  41. static const char GRASS_CONFIGURE_PARAMS[] =
  42. #include <grass/confparms.h>
  43. ;
  44. int main(int argc, char *argv[])
  45. {
  46. struct GModule *module;
  47. struct Flag *copyright, *build, *gish_rev, *cite_flag, *shell, *extended;
  48. G_gisinit(argv[0]);
  49. module = G_define_module();
  50. G_add_keyword(_("general"));
  51. G_add_keyword(_("support"));
  52. G_add_keyword(_("citing"));
  53. G_add_keyword(_("copyright"));
  54. G_add_keyword(_("version"));
  55. G_add_keyword(_("license"));
  56. module->label = _("Displays GRASS GIS version info.");
  57. module->description = _("Optionally also prints build or copyright information.");
  58. copyright = G_define_flag();
  59. copyright->key = 'c';
  60. copyright->description = _("Print also the copyright message");
  61. copyright->guisection = _("Additional info");
  62. cite_flag = G_define_flag();
  63. cite_flag->key = 'x';
  64. cite_flag->description = _("Print also the citation options");
  65. cite_flag->guisection = _("Additional info");
  66. build = G_define_flag();
  67. build->key = 'b';
  68. build->description = _("Print also the build information");
  69. build->guisection = _("Additional info");
  70. gish_rev = G_define_flag();
  71. gish_rev->key = 'r';
  72. gish_rev->description =
  73. _("Print also the GIS library revision number and date");
  74. gish_rev->guisection = _("Additional info");
  75. extended = G_define_flag();
  76. extended->key = 'e';
  77. extended->label = _("Print also extended info for additional libraries");
  78. extended->description = _("GDAL/OGR, PROJ.4, GEOS");
  79. extended->guisection = _("Additional info");
  80. shell = G_define_flag();
  81. shell->key = 'g';
  82. shell->description = _("Print info in shell script style (including SVN revision number)");
  83. shell->guisection = _("Shell");
  84. if (G_parser(argc, argv))
  85. exit(EXIT_FAILURE);
  86. if (shell->answer) {
  87. fprintf(stdout, "version=%s\n", GRASS_VERSION_NUMBER);
  88. fprintf(stdout, "date=%s\n", GRASS_VERSION_DATE);
  89. fprintf(stdout, "revision=%s\n", GRASS_VERSION_SVN);
  90. fprintf(stdout, "build_date=%d-%02d-%02d\n", YEAR, MONTH, DAY);
  91. fprintf(stdout, "build_platform=%s\n", ARCH);
  92. }
  93. else {
  94. fprintf(stdout, "GRASS %s (%s)\n",
  95. GRASS_VERSION_NUMBER, GRASS_VERSION_DATE);
  96. }
  97. if (copyright->answer) {
  98. fprintf(stdout, "\n");
  99. fputs(COPYING, stdout);
  100. }
  101. if (cite_flag->answer) {
  102. fprintf(stdout, "\n");
  103. fputs(CITING, stdout);
  104. }
  105. if (build->answer) {
  106. fprintf(stdout, "\n");
  107. fputs(GRASS_CONFIGURE_PARAMS, stdout);
  108. fprintf(stdout, "\n");
  109. }
  110. if (gish_rev->answer) {
  111. char **rev_ver = G_tokenize(GIS_H_VERSION, "$");
  112. char **rev_time = G_tokenize(GIS_H_DATE, "$");
  113. const int tokens_expected = 3;
  114. int no_libgis = FALSE;
  115. /* if number of tokes is right, print it */
  116. if (G_number_of_tokens(rev_ver) == tokens_expected &&
  117. G_number_of_tokens(rev_time) == tokens_expected) {
  118. if (shell->answer) {
  119. const char *p;
  120. p = strstr(rev_ver[1], " ");
  121. fprintf(stdout, "libgis_revision=%s\n",
  122. p ? p + 1 : "00000");
  123. p = strstr(rev_time[1], " ");
  124. fprintf(stdout, "libgis_date=\"%s\"\n",
  125. p ? p + 1 : "?");
  126. }
  127. else {
  128. fprintf(stdout, "libgis %s\nlibgis %s\n", rev_ver[1],
  129. rev_time[1]);
  130. }
  131. }
  132. else {
  133. no_libgis = TRUE;
  134. if (shell->answer) {
  135. fprintf(stdout, "libgis_revision=\n");
  136. fprintf(stdout, "libgis_date=\n");
  137. G_warning("GRASS GIS libgis version and date number not available");
  138. /* this can be alternatively fatal error or it can cause
  139. fatal error later */
  140. }
  141. else {
  142. fprintf(stdout,
  143. _("Cannot determine GRASS libgis version and date number."
  144. " The GRASS build might be broken."
  145. " Report this to developers or packagers.\n"));
  146. }
  147. }
  148. if (no_libgis) {
  149. G_debug(1,
  150. _("GRASS GIS libgis version and date number don't have the expected format."
  151. " Trying to print the original strings..."));
  152. G_debug(1, _("GIS_H_VERSION=\"%s\""), GIS_H_VERSION);
  153. G_debug(1, _("GIS_H_DATE=\"%s\""), GIS_H_DATE);
  154. }
  155. G_free_tokens(rev_ver);
  156. G_free_tokens(rev_time);
  157. }
  158. if (extended->answer) {
  159. char *proj = NULL;
  160. G_asprintf(&proj, "%d", PJ_VERSION);
  161. if (strlen(proj) == 3) {
  162. if (shell->answer)
  163. fprintf(stdout, "proj4=%c.%c.%c\n", proj[0], proj[1], proj[2]);
  164. else
  165. fprintf(stdout, "PROJ.4: %c.%c.%c\n", proj[0], proj[1], proj[2]);
  166. }
  167. else {
  168. if (shell->answer)
  169. fprintf(stdout, "proj4=%s\n", proj);
  170. else
  171. fprintf(stdout, "PROJ.4: %s\n", proj);
  172. }
  173. #ifdef HAVE_GDAL
  174. if (shell->answer)
  175. fprintf(stdout, "gdal=%s\n", GDAL_RELEASE_NAME);
  176. else
  177. fprintf(stdout, "GDAL/OGR: %s\n", GDAL_RELEASE_NAME);
  178. #else
  179. if (shell->answer)
  180. fprintf(stdout, "gdal=\n");
  181. else
  182. fprintf(stdout, "%s\n", _("GRASS not compiled with GDAL/OGR support"));
  183. #endif
  184. #ifdef HAVE_GEOS
  185. if (shell->answer)
  186. fprintf(stdout, "geos=%s\n", GEOS_VERSION);
  187. else
  188. fprintf(stdout, "GEOS: %s\n", GEOS_VERSION);
  189. #else
  190. if (shell->answer)
  191. fprintf(stdout, "geos=\n");
  192. else
  193. fprintf(stdout, "%s\n", _("GRASS not compiled with GEOS support"));
  194. #endif
  195. #ifdef HAVE_SQLITE
  196. if (shell->answer)
  197. fprintf(stdout, "sqlite=%s\n", SQLITE_VERSION);
  198. else
  199. fprintf(stdout, "SQLite: %s\n", SQLITE_VERSION);
  200. #else
  201. if (shell->answer)
  202. fprintf(stdout, "sqlite=\n");
  203. else
  204. fprintf(stdout, "%s\n", _("GRASS not compiled with SQLite support"));
  205. #endif
  206. }
  207. return (EXIT_SUCCESS);
  208. }