[GRASS-SVN] r61683 - grass/branches/releasebranch_7_0/general/g.version

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 18 13:20:49 PDT 2014


Author: wenzeslaus
Date: 2014-08-18 13:20:48 -0700 (Mon, 18 Aug 2014)
New Revision: 61683

Modified:
   grass/branches/releasebranch_7_0/general/g.version/main.c
Log:
g.version: more robust way of reporting libgis version (ticket #2351, backport r61589)

Modified: grass/branches/releasebranch_7_0/general/g.version/main.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.version/main.c	2014-08-18 20:13:41 UTC (rev 61682)
+++ grass/branches/releasebranch_7_0/general/g.version/main.c	2014-08-18 20:20:48 UTC (rev 61683)
@@ -41,6 +41,7 @@
 #define GRASS_VERSION_UPDATE_PKG "0.1"
 #endif
 
+/* TODO: remove this style of include */
 static const char COPYING[] =
 #include <grass/copying.h>
 ;
@@ -116,16 +117,47 @@
     }
 
     if (gish_rev->answer) {
-	/* fprintf(stdout, "%s\n%s\n", GIS_H_VERSION, GIS_H_DATE); */
 	char **rev_ver = G_tokenize(GIS_H_VERSION, "$");
 	char **rev_time = G_tokenize(GIS_H_DATE, "$");
-	if (shell->answer) {
-	    fprintf(stdout, "libgis_revision=%s\n", strstr(rev_ver[1], " ") + 1);
-	    fprintf(stdout, "libgis_date=\"%s\"\n", strstr(rev_time[1], " ") + 1);
+	const int tokens_expected = 2;
+	int no_libgis = FALSE;
+	/* if number of tokes is right, print it */
+	if (G_number_of_tokens(rev_ver) == tokens_expected &&
+	    G_number_of_tokens(rev_time) == tokens_expected) {
+	    if (shell->answer) {
+		fprintf(stdout, "libgis_revision=%s\n",
+			strstr(rev_ver[1], " ") + 1);
+		fprintf(stdout, "libgis_date=\"%s\"\n",
+			strstr(rev_time[1], " ") + 1);
+	    }
+	    else {
+		fprintf(stdout, "libgis %s\nlibgis %s\n", rev_ver[1],
+			rev_time[1]);
+	    }
 	}
 	else {
-	    fprintf(stdout, "libgis %s\nlibgis %s\n", rev_ver[1], rev_time[1]);
+	    no_libgis = TRUE;
+	    if (shell->answer) {
+		fprintf(stdout, "libgis_revision=\n");
+		fprintf(stdout, "libgis_date=\n");
+		G_warning("GRASS GIS libgis version and date number not available");
+		/* this can be alternatively fatal error or it can cause
+		   fatal error later */
+	    }
+	    else {
+		fprintf(stdout,
+			_("Cannot determine GRASS libgis version and date number."
+			 " The GRASS build might be broken."
+			 " Report this to developers or packagers.\n"));
+	    }
 	}
+	if (no_libgis) {
+	    G_debug(1,
+		    _("GRASS GIS libgis version and date number don't have the expected format."
+		     " Trying to print the original strings..."));
+	    G_debug(1, _("GIS_H_VERSION=\"%s\""), GIS_H_VERSION);
+	    G_debug(1, _("GIS_H_DATE=\"%s\""), GIS_H_DATE);
+	}
 	G_free_tokens(rev_ver);
 	G_free_tokens(rev_time);
     }



More information about the grass-commit mailing list