list_gp.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*!
  2. \file list_gp.c
  3. \brief Imagery Library - List group
  4. (C) 2001-2008 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author USA CERL
  8. */
  9. #include <string.h>
  10. #include <grass/imagery.h>
  11. #include <grass/glocale.h>
  12. /*!
  13. * \brief Prints maps in a group (fancy version)
  14. *
  15. * \param group group name
  16. * \param ref group reference (set with I_get_group_ref())
  17. * \param fd where to print (typically stdout)
  18. * \return 0
  19. */
  20. int I_list_group(const char *group, const struct Ref *ref, FILE * fd)
  21. {
  22. char buf[80];
  23. int i;
  24. int len, tot_len;
  25. int max;
  26. if (ref->nfiles <= 0) {
  27. fprintf(fd, _("group <%s> is empty\n"), group);
  28. return 0;
  29. }
  30. max = 0;
  31. for (i = 0; i < ref->nfiles; i++) {
  32. sprintf(buf, "<%s@%s>", ref->file[i].name, ref->file[i].mapset);
  33. len = strlen(buf) + 4;
  34. if (len > max)
  35. max = len;
  36. }
  37. fprintf(fd, _("group <%s> references the following raster maps\n"), group);
  38. fprintf(fd, "-------------\n");
  39. tot_len = 0;
  40. for (i = 0; i < ref->nfiles; i++) {
  41. sprintf(buf, "<%s@%s>", ref->file[i].name, ref->file[i].mapset);
  42. tot_len += max;
  43. if (tot_len > 78) {
  44. fprintf(fd, "\n");
  45. tot_len = max;
  46. }
  47. fprintf(fd, "%-*s", max, buf);
  48. }
  49. if (tot_len)
  50. fprintf(fd, "\n");
  51. fprintf(fd, "-------------\n");
  52. return 0;
  53. }
  54. /*!
  55. * \brief Prints maps in a group (simple version)
  56. *
  57. * Same as I_list_group(), but without all the fancy stuff.
  58. * Prints one map per line in map@mapset form.
  59. *
  60. * \param ref group reference (set with I_get_group_ref())
  61. * \param fd where to print (typically stdout)
  62. * \return 0
  63. */
  64. int I_list_group_simple(const struct Ref *ref, FILE * fd)
  65. {
  66. int i;
  67. if (ref->nfiles <= 0)
  68. return 0;
  69. for (i = 0; i < ref->nfiles; i++)
  70. fprintf(fd, "%s@%s\n", ref->file[i].name, ref->file[i].mapset);
  71. return 0;
  72. }