fopen.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 *I_fopen_group_file_new(const char *group, const char *file)
  14. {
  15. FILE *fd;
  16. fd = G_fopen_new_misc("group", file, group);
  17. if (!fd)
  18. G_warning(_("Unable to create file [%s] of group [%s in %s]"),
  19. file, group, G_mapset());
  20. return fd;
  21. }
  22. FILE *I_fopen_group_file_append(const char *group, const char *file)
  23. {
  24. FILE *fd;
  25. fd = G_fopen_append_misc("group", file, group);
  26. if (!fd)
  27. G_warning(_("Unable to open file [%s] of group [%s in %s]"),
  28. file, group, G_mapset());
  29. return fd;
  30. }
  31. FILE *I_fopen_group_file_old(const char *group, const char *file)
  32. {
  33. FILE *fd;
  34. /* find file first */
  35. if (!I_find_group_file(group, file)) {
  36. G_warning(_("Unable to find file [%s] of group [%s in %s]"),
  37. file, group, G_mapset());
  38. return ((FILE *) NULL);
  39. }
  40. fd = G_fopen_old_misc("group", file, group, G_mapset());
  41. if (!fd)
  42. G_warning(_("Unable to open file [%s] of group [%s in %s]"),
  43. file, group, G_mapset());
  44. return fd;
  45. }
  46. FILE *I_fopen_subgroup_file_new(const char *group,
  47. const char *subgroup, const char *file)
  48. {
  49. FILE *fd;
  50. char element[GNAME_MAX * 2];
  51. /* create subgroup directory */
  52. sprintf(element, "%s/subgroup/%s", group, subgroup);
  53. G__make_mapset_element_misc("group", element);
  54. /* get subgroup element name */
  55. sprintf(element, "subgroup/%s/%s", subgroup, file);
  56. fd = G_fopen_new_misc("group", element, group);
  57. if (!fd)
  58. G_warning(_("Unable to create file [%s] for subgroup [%s] of group [%s in %s]"),
  59. file, subgroup, group, G_mapset());
  60. return fd;
  61. }
  62. FILE *I_fopen_subgroup_file_append(const char *group,
  63. const char *subgroup, const char *file)
  64. {
  65. FILE *fd;
  66. char element[GNAME_MAX * 2];
  67. /* create subgroup directory */
  68. sprintf(element, "%s/subgroup/%s", group, subgroup);
  69. G__make_mapset_element_misc("group", element);
  70. /* get subgroup element name */
  71. sprintf(element, "subgroup/%s/%s", subgroup, file);
  72. fd = G_fopen_append_misc("group", element, group);
  73. if (!fd)
  74. G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
  75. file, subgroup, group, G_mapset());
  76. return fd;
  77. }
  78. FILE *I_fopen_subgroup_file_old(const char *group,
  79. const char *subgroup, const char *file)
  80. {
  81. FILE *fd;
  82. char element[GNAME_MAX * 2];
  83. /* find file first */
  84. if (!I_find_subgroup_file(group, subgroup, file)) {
  85. G_warning(_("Unable to find file [%s] for subgroup [%s] of group [%s in %s]"),
  86. file, subgroup, group, G_mapset());
  87. return ((FILE *) NULL);
  88. }
  89. /* get subgroup element name */
  90. sprintf(element, "subgroup/%s/%s", subgroup, file);
  91. fd = G_fopen_old_misc("group", element, group, G_mapset());
  92. if (!fd)
  93. G_warning(_("Unable to open file [%s] for subgroup [%s] of group [%s in %s]"),
  94. file, subgroup, group, G_mapset());
  95. return fd;
  96. }