progrm_nme.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * \file lib/gis/progrm_nme.c
  3. *
  4. * \brief GIS Library - Program name
  5. *
  6. * (C) 2001-2014 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author Original author CERL
  12. */
  13. #include <string.h>
  14. #include <grass/gis.h>
  15. static const char *name = "?";
  16. static const char *original_name = "?";
  17. /*!
  18. * \brief Return module name
  19. *
  20. * Routine returns the name of the module as set by the call to
  21. * G_gisinit().
  22. *
  23. * \return pointer to string with program name
  24. */
  25. const char *G_program_name(void)
  26. {
  27. return name;
  28. }
  29. /*!
  30. * \brief Return original path of the executed program
  31. *
  32. * This function returns the name of the program as set by the call to
  33. * G_gisinit().
  34. *
  35. * Unlike G_program_name() which returns name of the module
  36. * this function return original path which was used to execute
  37. * the program. For standard GRASS modules, it will be the same as
  38. * the result from G_program_name() function.
  39. *
  40. * \return pointer to string with program name or full path
  41. */
  42. const char *G_original_program_name(void)
  43. {
  44. return original_name;
  45. }
  46. /*!
  47. \brief Set program name
  48. Program name set to name (name will be returned by
  49. G_program_name*())
  50. Extension like .exe or .py is stripped from program name.
  51. \param s program name
  52. */
  53. void G_set_program_name(const char *s)
  54. {
  55. int i;
  56. char *temp;
  57. original_name = G_store(s);
  58. i = strlen(s);
  59. while (--i >= 0) {
  60. if (G_is_dirsep(s[i])) {
  61. s += i + 1;
  62. break;
  63. }
  64. }
  65. /* strip extension from program name */
  66. temp = G_store(s);
  67. G_basename(temp, "exe");
  68. G_basename(temp, "py");
  69. name = G_store(temp);
  70. G_debug(1, "G_set_program_name(): %s", name);
  71. G_free(temp);
  72. }