main.c 7.0 KB

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