find.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. *
  14. * \param group
  15. * \return int
  16. */
  17. int I_find_group(const char *group)
  18. {
  19. if (group == NULL || *group == 0)
  20. return 0;
  21. return G_find_file2("group", group, G_mapset()) != NULL;
  22. }
  23. int I_find_group_file(const char *group, const char *file)
  24. {
  25. if (!I_find_group(group))
  26. return 0;
  27. if (file == NULL || *file == 0)
  28. return 0;
  29. return G_find_file2_misc("group", file, group, G_mapset()) != NULL;
  30. }
  31. int I_find_subgroup(const char *group, const char *subgroup)
  32. {
  33. char element[GNAME_MAX];
  34. if (!I_find_group(group))
  35. return 0;
  36. if (subgroup == NULL || *subgroup == 0)
  37. return 0;
  38. sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
  39. G_debug(5, "I_find_subgroup() element: %s", element);
  40. return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
  41. }
  42. int I_find_subgroup_file(const char *group, const char *subgroup,
  43. const char *file)
  44. {
  45. char element[GNAME_MAX * 2];
  46. if (!I_find_group(group))
  47. return 0;
  48. if (subgroup == NULL || *subgroup == 0)
  49. return 0;
  50. if (file == NULL || *file == 0)
  51. return 0;
  52. sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, file);
  53. G_debug(5, "I_find_subgroup_file() element: %s", element);
  54. return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
  55. }
  56. /*!
  57. * \brief does signature file exists?
  58. *
  59. * Returns 1 if the
  60. * specified <b>signature</b> exists in the specified subgroup; 0 otherwise.
  61. *
  62. * Should be used to check if signature file exists after G_parser run
  63. * when generating new signature file.
  64. *
  65. * \param group - group where to search
  66. * \param subgroup - subgroup containing signatures
  67. * \param type - type of signature ("sig" or "sigset")
  68. * \param file - name of signature file
  69. * \return int
  70. */
  71. int I_find_signature_file(const char *group, const char *subgroup,
  72. const char *type, const char *file)
  73. {
  74. char element[GNAME_MAX * 2];
  75. if (!I_find_group(group))
  76. return 0;
  77. if (subgroup == NULL || *subgroup == 0)
  78. return 0;
  79. if (type == NULL || *type == 0)
  80. return 0;
  81. if (file == NULL || *file == 0)
  82. return 0;
  83. sprintf(element, "subgroup%c%s%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, type, HOST_DIRSEP, file);
  84. G_debug(5, "I_find_signature_file() element: %s", element);
  85. return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
  86. }