main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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-2012 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 <proj_api.h>
  21. #ifdef HAVE_GDAL
  22. #include <gdal_version.h>
  23. #endif
  24. #ifdef HAVE_GEOS
  25. #include <geos_c.h>
  26. #endif
  27. #ifdef HAVE_SQLITE
  28. #include <sqlite3.h>
  29. #endif
  30. #ifndef GRASS_VERSION_UPDATE_PKG
  31. #define GRASS_VERSION_UPDATE_PKG "0.1"
  32. #endif
  33. static const char COPYING[] =
  34. #include <grass/copying.h>
  35. ;
  36. static const char GRASS_CONFIGURE_PARAMS[] =
  37. #include <grass/confparms.h>
  38. ;
  39. int main(int argc, char *argv[])
  40. {
  41. struct GModule *module;
  42. struct Flag *copyright, *build, *gish_rev, *shell, *extended;
  43. G_gisinit(argv[0]);
  44. module = G_define_module();
  45. G_add_keyword(_("general"));
  46. G_add_keyword(_("version"));
  47. module->description = _("Displays GRASS version and copyright information.");
  48. copyright = G_define_flag();
  49. copyright->key = 'c';
  50. copyright->description = _("Print also the copyright message");
  51. copyright->guisection = _("Additional info");
  52. build = G_define_flag();
  53. build->key = 'b';
  54. build->description = _("Print also the GRASS build information");
  55. build->guisection = _("Additional info");
  56. gish_rev = G_define_flag();
  57. gish_rev->key = 'r';
  58. gish_rev->description =
  59. _("Print also the GIS library revision number and time");
  60. gish_rev->guisection = _("Additional info");
  61. extended = G_define_flag();
  62. extended->key = 'e';
  63. extended->label = _("Print also extended info for additional libraries");
  64. extended->description = _("GDAL/OGR, PROJ.4, GEOS");
  65. extended->guisection = _("Additional info");
  66. shell = G_define_flag();
  67. shell->key = 'g';
  68. shell->description = _("Print info in shell script style (including SVN revision number)");
  69. shell->guisection = _("Shell");
  70. if (G_parser(argc, argv))
  71. exit(EXIT_FAILURE);
  72. if (shell->answer) {
  73. fprintf(stdout, "version=%s\n", GRASS_VERSION_NUMBER);
  74. fprintf(stdout, "revision=%s\n", GRASS_VERSION_SVN);
  75. fprintf(stdout, "date=%s\n", GRASS_VERSION_DATE);
  76. }
  77. else {
  78. fprintf(stdout, "GRASS %s (%s)\n",
  79. GRASS_VERSION_NUMBER, GRASS_VERSION_DATE);
  80. }
  81. if (copyright->answer) {
  82. fprintf(stdout, "\n");
  83. fputs(COPYING, stdout);
  84. }
  85. if (build->answer) {
  86. fprintf(stdout, "\n");
  87. fputs(GRASS_CONFIGURE_PARAMS, stdout);
  88. fprintf(stdout, "\n");
  89. }
  90. if (gish_rev->answer) {
  91. /* fprintf(stdout, "%s\n%s\n", GIS_H_VERSION, GIS_H_DATE); */
  92. char **rev_ver = G_tokenize(GIS_H_VERSION, "$");
  93. char **rev_time = G_tokenize(GIS_H_DATE, "$");
  94. if (shell->answer) {
  95. fprintf(stdout, "libgis_revision=%s\n", strstr(rev_ver[1], " ") + 1);
  96. fprintf(stdout, "libgis_date=\"%s\"\n", strstr(rev_time[1], " ") + 1);
  97. }
  98. else {
  99. fprintf(stdout, "libgis %s\nlibgis %s\n", rev_ver[1], rev_time[1]);
  100. }
  101. G_free_tokens(rev_ver);
  102. G_free_tokens(rev_time);
  103. }
  104. if (extended->answer) {
  105. char *proj = NULL;
  106. G_asprintf(&proj, "%d", PJ_VERSION);
  107. if (strlen(proj) == 3) {
  108. if (shell->answer)
  109. fprintf(stdout, "proj4=%c.%c.%c\n", proj[0], proj[1], proj[2]);
  110. else
  111. fprintf(stdout, "PROJ.4: %c.%c.%c\n", proj[0], proj[1], proj[2]);
  112. }
  113. else {
  114. if (shell->answer)
  115. fprintf(stdout, "proj4=%s\n", proj);
  116. else
  117. fprintf(stdout, "PROJ.4: %s\n", proj);
  118. }
  119. #ifdef HAVE_GDAL
  120. if (shell->answer)
  121. fprintf(stdout, "gdal=%s\n", GDAL_RELEASE_NAME);
  122. else
  123. fprintf(stdout, "GDAL/OGR: %s\n", GDAL_RELEASE_NAME);
  124. #else
  125. if (shell->answer)
  126. fprintf(stdout, "gdal=\n");
  127. else
  128. fprintf(stdout, "%s\n", _("GRASS not compiled with GDAL/OGR support"));
  129. #endif
  130. #ifdef HAVE_GEOS
  131. if (shell->answer)
  132. fprintf(stdout, "geos=%s\n", GEOS_VERSION);
  133. else
  134. fprintf(stdout, "GEOS: %s\n", GEOS_VERSION);
  135. #else
  136. if (shell->answer)
  137. fprintf(stdout, "geos=\n");
  138. else
  139. fprintf(stdout, "%s\n", _("GRASS not compiled with GEOS support"));
  140. #endif
  141. #ifdef HAVE_SQLITE
  142. if (shell->answer)
  143. fprintf(stdout, "sqlite=%s\n", SQLITE_VERSION);
  144. else
  145. fprintf(stdout, "SQLite: %s\n", SQLITE_VERSION);
  146. #else
  147. if (shell->answer)
  148. fprintf(stdout, "sqlite=\n");
  149. else
  150. fprintf(stdout, "%s\n", _("GRASS not compiled with SQLite support"));
  151. #endif
  152. }
  153. return (EXIT_SUCCESS);
  154. }