fopen.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include <grass/imagery.h>
  4. #include <grass/glocale.h>
  5. /******************************************************
  6. * I_fopen_group_file_new()
  7. * I_fopen_group_file_append()
  8. * I_fopen_group_file_old()
  9. *
  10. * fopen new group files in the current mapset
  11. * fopen old group files anywhere
  12. *******************************************************/
  13. FILE *fopen_group_file_old(const char *group, const char *mapset, const char *file)
  14. {
  15. FILE *fd;
  16. if (mapset == NULL || *mapset == 0)
  17. mapset = G_mapset();
  18. /* find file first */
  19. if (!I_find_group_file2(group, mapset, file)) {
  20. G_warning(_("Unable to find file [%s] of group [%s in %s]"),
  21. file, group, mapset);
  22. return ((FILE *) NULL);
  23. }
  24. fd = G_fopen_old_misc("group", file, group, mapset);
  25. if (!fd)
  26. G_warning(_("Unable to open file [%s] of group [%s in %s]"),
  27. file, group, mapset);
  28. return fd;
  29. }
  30. FILE *fopen_subgroup_file_old(const char *group,
  31. const char *subgroup, const char *mapset,
  32. const char *file)
  33. {
  34. FILE *fd;
  35. char element[GNAME_MAX * 2];
  36. if (mapset == NULL || *mapset == 0)
  37. mapset = G_mapset();
  38. /* find file first */
  39. if (!I_find_subgroup_file2(group, subgroup, mapset, file)) {
  40. G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
  41. file, subgroup, group, mapset);
  42. return ((FILE *) NULL);
  43. }
  44. /* get subgroup element name */
  45. sprintf(element, "subgroup/%s/%s", subgroup, file);
  46. fd = G_fopen_old_misc("group", element, group, mapset);
  47. if (!fd)
  48. G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
  49. file, subgroup, group, mapset);
  50. return fd;
  51. }
  52. FILE *I_fopen_group_file_new(const char *group, const char *file)
  53. {
  54. FILE *fd;
  55. fd = G_fopen_new_misc("group", file, group);
  56. if (!fd)
  57. G_warning(_("Unable to create file [%s] of group [%s in %s]"),
  58. file, group, G_mapset());
  59. return fd;
  60. }
  61. FILE *I_fopen_group_file_append(const char *group, const char *file)
  62. {
  63. FILE *fd;
  64. fd = G_fopen_append_misc("group", file, group);
  65. if (!fd)
  66. G_warning(_("Unable to open file [%s] of group [%s in %s]"),
  67. file, group, G_mapset());
  68. return fd;
  69. }
  70. /*!
  71. * \brief Open group file for reading
  72. *
  73. * Internally uses G_fopen_old_misc
  74. *
  75. * \param group
  76. * \param file
  77. * \return FILE *
  78. */
  79. FILE *I_fopen_group_file_old(const char *group, const char *file)
  80. {
  81. return fopen_group_file_old(group, NULL, file);
  82. }
  83. /*!
  84. * \brief Open group file for reading
  85. *
  86. * Internally uses G_fopen_old_misc
  87. *
  88. * \param group
  89. * \param mapset
  90. * \param file
  91. * \return FILE *
  92. */
  93. FILE *I_fopen_group_file_old2(const char *group, const char *mapset, const char *file)
  94. {
  95. return fopen_group_file_old(group, mapset, file);
  96. }
  97. FILE *I_fopen_subgroup_file_new(const char *group,
  98. const char *subgroup, const char *file)
  99. {
  100. FILE *fd;
  101. char element[GNAME_MAX * 2];
  102. /* create subgroup directory */
  103. sprintf(element, "%s/subgroup/%s", group, subgroup);
  104. G__make_mapset_element_misc("group", element);
  105. /* get subgroup element name */
  106. sprintf(element, "subgroup/%s/%s", subgroup, file);
  107. fd = G_fopen_new_misc("group", element, group);
  108. if (!fd)
  109. G_warning(_("Unable to create file [%s] for subgroup [%s] of group [%s in %s]"),
  110. file, subgroup, group, G_mapset());
  111. return fd;
  112. }
  113. FILE *I_fopen_subgroup_file_append(const char *group,
  114. const char *subgroup, const char *file)
  115. {
  116. FILE *fd;
  117. char element[GNAME_MAX * 2];
  118. /* create subgroup directory */
  119. sprintf(element, "%s/subgroup/%s", group, subgroup);
  120. G__make_mapset_element_misc("group", element);
  121. /* get subgroup element name */
  122. sprintf(element, "subgroup/%s/%s", subgroup, file);
  123. fd = G_fopen_append_misc("group", element, group);
  124. if (!fd)
  125. G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
  126. file, subgroup, group, G_mapset());
  127. return fd;
  128. }
  129. FILE *I_fopen_subgroup_file_old(const char *group,
  130. const char *subgroup, const char *file)
  131. {
  132. return fopen_subgroup_file_old(group, subgroup, NULL, file);
  133. }
  134. FILE *I_fopen_subgroup_file_old2(const char *group,
  135. const char *subgroup, const char *mapset,
  136. const char *file)
  137. {
  138. return fopen_subgroup_file_old(group, subgroup, mapset, file);
  139. }