find.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**************************************************************
  2. * I_find_group (group)
  3. *
  4. * Find the a group in the current mapset
  5. **************************************************************/
  6. #include <grass/imagery.h>
  7. #include <grass/gis.h>
  8. /*!
  9. * \brief does group exist?
  10. *
  11. * Returns 1 if the
  12. * specified <b>group</b> exists in the current mapset; 0 otherwise.
  13. * Use I_find_group2 to search in all or a specific mapset.
  14. *
  15. * \param group
  16. * \return int 1 if group was found, 0 otherwise
  17. */
  18. int I_find_group(const char *group)
  19. {
  20. if (group == NULL || *group == 0)
  21. return 0;
  22. return G_find_file2("group", group, G_mapset()) != NULL;
  23. }
  24. /*!
  25. * \brief Does the group exists?
  26. *
  27. * Finds a group in specified mapset or any mapset if mapset is not set.
  28. * Internally uses G_find_file2().
  29. *
  30. * \param group
  31. * \param mapset
  32. * \return int 1 if group was found, 0 otherwise
  33. */
  34. int I_find_group2(const char *group, const char *mapset)
  35. {
  36. return G_find_file2("group", group, mapset) != NULL;
  37. }
  38. /*!
  39. * \brief Searches for a group file in the current mapset
  40. *
  41. * \param group
  42. * \param file
  43. * \return int 1 if file was found, 0 otherwise
  44. */
  45. int I_find_group_file(const char *group, const char *file)
  46. {
  47. if (!I_find_group(group))
  48. return 0;
  49. if (file == NULL || *file == 0)
  50. return 0;
  51. return G_find_file2_misc("group", file, group, G_mapset()) != NULL;
  52. }
  53. /*!
  54. * \brief Searches for a group file in the specified mapset
  55. *
  56. * \param group
  57. * \param file
  58. * \return int 1 if file was found, 0 otherwise
  59. */
  60. int I_find_group_file2(const char *group, const char *mapset, const char *file)
  61. {
  62. if (!I_find_group2(group, mapset))
  63. return 0;
  64. if (file == NULL || *file == 0)
  65. return 0;
  66. return G_find_file2_misc("group", file, group, mapset) != NULL;
  67. }
  68. /*!
  69. * \brief Searches for a subgroup in the current mapset
  70. *
  71. * \param group
  72. * \param subgroup
  73. * \return int 1 if subgroup was found, 0 otherwise
  74. */
  75. int I_find_subgroup(const char *group, const char *subgroup)
  76. {
  77. char element[GNAME_MAX];
  78. if (!I_find_group(group))
  79. return 0;
  80. if (subgroup == NULL || *subgroup == 0)
  81. return 0;
  82. sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
  83. G_debug(5, "I_find_subgroup() element: %s", element);
  84. return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
  85. }
  86. /*!
  87. * \brief Searches for a subgroup in specified mapset or any mapset if mapset is not set
  88. *
  89. * \param group
  90. * \param subgroup
  91. * \param mapset
  92. * \return int 1 if subrgoup was found, 0 otherwise
  93. */
  94. int I_find_subgroup2(const char *group, const char *subgroup, const char *mapset)
  95. {
  96. char element[GNAME_MAX];
  97. if (!I_find_group2(group, mapset))
  98. return 0;
  99. if (subgroup == NULL || *subgroup == 0)
  100. return 0;
  101. sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
  102. G_debug(5, "I_find_subgroup2() element: %s", element);
  103. return G_find_file2_misc("group", element, group, mapset) != NULL;
  104. }
  105. /*!
  106. * \brief Searches for a subgroup file in the current mapset
  107. *
  108. * \param group
  109. * \param subgroup
  110. * \param file
  111. * \return int 1 if file was found, 0 otherwise
  112. */
  113. int I_find_subgroup_file(const char *group, const char *subgroup,
  114. const char *file)
  115. {
  116. char element[GNAME_MAX * 2];
  117. if (!I_find_group(group))
  118. return 0;
  119. if (subgroup == NULL || *subgroup == 0)
  120. return 0;
  121. if (file == NULL || *file == 0)
  122. return 0;
  123. sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, file);
  124. G_debug(5, "I_find_subgroup_file() element: %s", element);
  125. return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
  126. }
  127. /*!
  128. * \brief Searches for a subgroup file in the specified mapset
  129. *
  130. * \param group
  131. * \param subgroup
  132. * \param mapset
  133. * \param file
  134. * \return int 1 if file was found, 0 otherwise
  135. */
  136. int I_find_subgroup_file2(const char *group, const char *subgroup,
  137. const char *mapset, const char *file)
  138. {
  139. char element[GNAME_MAX * 2];
  140. if (!I_find_group2(group, mapset))
  141. return 0;
  142. if (subgroup == NULL || *subgroup == 0)
  143. return 0;
  144. if (file == NULL || *file == 0)
  145. return 0;
  146. sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, file);
  147. G_debug(5, "I_find_subgroup_file2() element: %s", element);
  148. return G_find_file2_misc("group", element, group, mapset) != NULL;
  149. }
  150. /*!
  151. * \brief does signature file exists?
  152. *
  153. * Returns 1 if the
  154. * specified <b>signature</b> exists in the specified subgroup; 0 otherwise.
  155. *
  156. * Should be used to check if signature file exists after G_parser run
  157. * when generating new signature file.
  158. *
  159. * \param group - group where to search
  160. * \param subgroup - subgroup containing signatures
  161. * \param type - type of signature ("sig" or "sigset")
  162. * \param file - name of signature file
  163. * \return int
  164. */
  165. int I_find_signature_file(const char *group, const char *subgroup,
  166. const char *type, const char *file)
  167. {
  168. char element[GNAME_MAX * 2];
  169. if (!I_find_group(group))
  170. return 0;
  171. if (subgroup == NULL || *subgroup == 0)
  172. return 0;
  173. if (type == NULL || *type == 0)
  174. return 0;
  175. if (file == NULL || *file == 0)
  176. return 0;
  177. sprintf(element, "subgroup%c%s%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, type, HOST_DIRSEP, file);
  178. G_debug(5, "I_find_signature_file() element: %s", element);
  179. return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
  180. }