[GRASS-SVN] r64424 - grass/trunk/display/d.info

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 3 06:44:31 PST 2015


Author: martinl
Date: 2015-02-03 06:44:31 -0800 (Tue, 03 Feb 2015)
New Revision: 64424

Modified:
   grass/trunk/display/d.info/main.c
Log:
d.info: implement -s flag to print monitor support files

Modified: grass/trunk/display/d.info/main.c
===================================================================
--- grass/trunk/display/d.info/main.c	2015-02-03 13:20:47 UTC (rev 64423)
+++ grass/trunk/display/d.info/main.c	2015-02-03 14:44:31 UTC (rev 64424)
@@ -14,6 +14,9 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <dirent.h>
+#include <string.h>
+
 #include <grass/gis.h>
 #include <grass/display.h>
 #include <grass/glocale.h>
@@ -21,7 +24,7 @@
 int main(int argc, char *argv[])
 {
     struct GModule *module;
-    struct Flag *rflag, *dflag, *fflag, *bflag, *gflag;
+    struct Flag *rflag, *dflag, *fflag, *bflag, *gflag, *sflag;
     double t, b, l, r;
     double n, s, e, w;
 
@@ -58,7 +61,12 @@
     gflag->description =
 	_("Display geographic coordinates and resolution of entire screen");
 
-    G_option_required(rflag, dflag, fflag, bflag, gflag, NULL);
+    sflag = G_define_flag();
+    sflag->key = 's';
+    sflag->description =
+	_("Print path to support files of currently selected monitor");
+
+    G_option_required(rflag, dflag, fflag, bflag, gflag, sflag, NULL);
     
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -106,6 +114,48 @@
 	fprintf(stdout, "nsres=%.15g\n", (n-s)/(b-t) );
     }
 
+    if (sflag->answer) {
+        const char *curr_mon;
+
+        curr_mon = G_getenv_nofatal("MONITOR");
+        if (!curr_mon) {
+            G_warning(_("No monitor is currently selected"));
+        }
+        else {
+            char *p;
+            char tmpdir[GPATH_MAX], mon_path[GPATH_MAX];
+            struct dirent *dp;
+            DIR *dirp;
+
+            G_temp_element(tmpdir);
+            strcat(tmpdir, "/");
+            strcat(tmpdir, "MONITORS");
+            strcat(tmpdir, "/");
+            strcat(tmpdir, curr_mon);
+
+            G_file_name(mon_path, tmpdir, NULL, G_mapset());
+
+            dirp = opendir(mon_path);
+            if (!dirp) {
+                G_warning(_("No support files found for monitor <%s>"), curr_mon);
+            }
+            else {
+                 while ((dp = readdir(dirp)) != NULL) {
+                     if (!dp->d_name || dp->d_type != DT_REG)
+                         continue;
+
+                     p = strrchr(dp->d_name, '.');
+                     if (!p)
+                         p = dp->d_name;
+                     else
+                         p++; /* skip '.' */
+                     
+                     fprintf(stdout, "%s=%s%c%s\n", p,
+                             mon_path, HOST_DIRSEP, dp->d_name);
+                 }
+            }
+        }
+    }
     
     D_close_driver();
 



More information about the grass-commit mailing list