[GRASS-SVN] r61589 - grass/trunk/general/g.version

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 12 11:54:47 PDT 2014


Author: wenzeslaus
Date: 2014-08-12 11:54:46 -0700 (Tue, 12 Aug 2014)
New Revision: 61589

Modified:
   grass/trunk/general/g.version/main.c
Log:
g.version: more robust way of reporting libgis version (good for partially broken distributions, #2351)

Modified: grass/trunk/general/g.version/main.c
===================================================================
--- grass/trunk/general/g.version/main.c	2014-08-12 18:14:32 UTC (rev 61588)
+++ grass/trunk/general/g.version/main.c	2014-08-12 18:54:46 UTC (rev 61589)
@@ -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