[GRASS-SVN] r57703 - in grass/trunk: include/defs lib/imagery

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Sep 16 06:47:51 PDT 2013


Author: turek
Date: 2013-09-16 06:47:51 -0700 (Mon, 16 Sep 2013)
New Revision: 57703

Modified:
   grass/trunk/include/defs/imagery.h
   grass/trunk/lib/imagery/list_subgp.c
Log:
adding I_list_subgroups fucntion for getting list of subgroups in a group

Modified: grass/trunk/include/defs/imagery.h
===================================================================
--- grass/trunk/include/defs/imagery.h	2013-09-16 13:24:55 UTC (rev 57702)
+++ grass/trunk/include/defs/imagery.h	2013-09-16 13:47:51 UTC (rev 57703)
@@ -92,6 +92,7 @@
 int I_list_group_simple(const struct Ref *, FILE *);
 
 /* list_subgp.c */
+char ** I_list_subgroups(const char *, int *);
 int I_list_subgroup(const char *, const char *, const struct Ref *, FILE *);
 int I_list_subgroup_simple(const struct Ref *, FILE *);
 

Modified: grass/trunk/lib/imagery/list_subgp.c
===================================================================
--- grass/trunk/lib/imagery/list_subgp.c	2013-09-16 13:24:55 UTC (rev 57702)
+++ grass/trunk/lib/imagery/list_subgp.c	2013-09-16 13:47:51 UTC (rev 57703)
@@ -1,21 +1,57 @@
 /*!
    \file list_subgp.c
-   
+
    \brief Imagery Library - List subgroup
- 
-   (C) 2001-2008 by the GRASS Development Team
-   
+
+   (C) 2001-2008,2013 by the GRASS Development Team
+
    This program is free software under the GNU General Public License
    (>=v2). Read the file COPYING that comes with GRASS for details.
-   
+
    \author USA CERL
-*/
+ */
 
 #include <string.h>
 #include <grass/imagery.h>
 #include <grass/glocale.h>
 
 /*!
+ * \brief Get list of subgroups which a group contatins.
+ *  
+ * \param group group name
+ * \param[out] subgs_num number of subgroups which the group contains
+ * \return array of subgroup names
+ */
+
+char **I_list_subgroups(const char *group, int *subgs_num)
+{
+    /* Unlike I_list_subgroup and I_list_subgroup_simple this function 
+       returns array of subgroup names, it does not use fprintf. 
+       This approach should make the function usable in more cases. */
+
+    char **subgs;
+    char *path[GPATH_MAX];
+    char *buf[GPATH_MAX];
+    const char *mapset;
+    struct stat sb;
+
+    *subgs_num = 0;
+
+    if (I_find_group(group) == 0)
+	return NULL;
+
+    mapset = G_mapset();
+    sprintf(buf, "group/%s/subgroup", group);
+    G_file_name(path, buf, "", mapset);
+
+    if (!G_lstat(path, &sb) == 0 || !S_ISDIR(sb.st_mode))
+	return NULL;
+
+    subgs = G__ls(path, subgs_num);
+    return subgs;
+}
+
+/*!
  * \brief Prints maps in a subgroup (fancy version)
  *
  * \param group group name
@@ -45,7 +81,8 @@
 	    max = len;
     }
     fprintf(fd,
-	    _("subgroup <%s> of group <%s> references the following raster maps\n"),
+	    _
+	    ("subgroup <%s> of group <%s> references the following raster maps\n"),
 	    subgroup, group);
     fprintf(fd, "-------------\n");
     tot_len = 0;



More information about the grass-commit mailing list