瀏覽代碼

vlib: Vect_cat_get() now return num of found cats for given field

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47911 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 年之前
父節點
當前提交
476dfb31ee
共有 1 個文件被更改,包括 16 次插入13 次删除
  1. 16 13
      lib/vector/Vlib/cats.c

+ 16 - 13
lib/vector/Vlib/cats.c

@@ -140,39 +140,42 @@ int Vect_cat_set(struct line_cats *Cats, int field, int cat)
 /*!
    \brief Get first found category of given field.
 
-   <em>cat</em> is set to first category found or -1 if field was not found
+   <em>cat</em> is set to first category found or -1 if field was not
+   found
 
-   \param Cats line_cats structure
+   \param Cats pointer line_cats structure
    \param field layer number
    \param[out] cat pointer to variable where cat will be written (can be NULL)
 
-   \return 1 found
+   \return number of found cats for given field (first reported)
    \return 0 layer does not exist
  */
 int Vect_cat_get(const struct line_cats *Cats, int field, int *cat)
 {
-    int n;
+    int n, ret;
 
     /* check input value */
     /*
-       if (field < 1 || field > GV_FIELD_MAX)
-       return (0);
-     */
+      if (field < 1 || field > GV_FIELD_MAX)
+      return (0);
+    */
     
+    /* field was not found */    
+    ret = 0;
     if (cat)
 	*cat = -1;
-
+    
     /* go through cats and find if field exist */
     for (n = 0; n < Cats->n_cats; n++) {
 	if (Cats->field[n] == field) {
-	    if (cat)
+	    if (cat && ret == 0) {
 		*cat = Cats->cat[n];
-	    return 1;
+	    }
+	    ret++;
 	}
     }
-
-    /* field was not found */
-    return 0;
+    
+    return ret;
 }
 
 /*!