ask_cell.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. *************************************************************************
  3. * char *
  4. * G_ask_cell_new(prompt, name))
  5. * asks user to input name of a new cell file
  6. *
  7. * char *
  8. * G_ask_cell_old(prompt, name)
  9. * asks user to input name of an existing cell file
  10. *
  11. * char *
  12. * G_ask_cell_in_mapset(prompt, name)
  13. * asks user to input name of an existing cell file in current mapset
  14. *
  15. * char *
  16. * G_ask_cell_any(prompt, name)
  17. * asks user to input name of a new or existing cell file in
  18. * the current mapset. Warns user about (possible) overwrite
  19. * if cell file already exists
  20. *
  21. * parms:
  22. * const char *prompt optional prompt for user
  23. * char *name buffer to hold name of map found
  24. *
  25. * returns:
  26. * char *pointer to a string with name of mapset
  27. * where file was found, or NULL if not found
  28. *
  29. * note:
  30. * rejects all names that begin with .
  31. **********************************************************************/
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <grass/gis.h>
  35. #include <grass/glocale.h>
  36. static int lister(char *, char *, char *);
  37. /*!
  38. * \brief prompt for new raster map
  39. *
  40. * Asks the user to enter a name for a raster map which does not
  41. * exist in the current mapset.
  42. *
  43. * \param prompt
  44. * \param name
  45. * \return char *
  46. */
  47. char *G_ask_cell_new(const char *prompt, char *name)
  48. {
  49. return G_ask_new_ext(prompt, name, "cell", "raster", _("with titles"),
  50. lister);
  51. }
  52. /*!
  53. * \brief prompt for existing raster map
  54. *
  55. * Asks the user to enter the name of an existing raster
  56. * file in any mapset in the database.
  57. *
  58. * \param prompt
  59. * \param name
  60. * \return char *
  61. */
  62. char *G_ask_cell_old(const char *prompt, char *name)
  63. {
  64. return G_ask_old_ext(prompt, name, "cell", "raster", _("with titles"),
  65. lister);
  66. }
  67. /*!
  68. * \brief prompt for existing raster map
  69. *
  70. * Asks the user to enter the name of an existing raster
  71. * file in the current mapset.
  72. *
  73. * \param prompt
  74. * \param name
  75. * \return char *
  76. */
  77. char *G_ask_cell_in_mapset(const char *prompt, char *name)
  78. {
  79. return G_ask_in_mapset_ext(prompt, name, "cell", "raster",
  80. _("with titles"), lister);
  81. }
  82. char *G_ask_cell_any(const char *prompt, char *name)
  83. {
  84. return G_ask_any_ext(prompt, name, "cell", "raster", 1, _("with titles"),
  85. lister);
  86. }
  87. static int lister(char *name, char *mapset, char *buf)
  88. {
  89. char *title;
  90. *buf = 0;
  91. if (*name == 0)
  92. return 0;
  93. strcpy(buf, title = G_get_cell_title(name, mapset));
  94. if (*buf == 0)
  95. strcpy(buf, _("(no title)"));
  96. G_free(title);
  97. return 0;
  98. }