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 
14 #include <string.h>
15 #include <grass/gis.h>
16 
17 static const char *name = "?";
18 static const char *original_name = "?";
19 
20 /*!
21  * \brief Return module name
22  *
23  * Routine returns the name of the module as set by the call to
24  * G_gisinit().
25  *
26  * \return pointer to string with program name
27  */
G_program_name(void)28 const char *G_program_name(void)
29 {
30     return name;
31 }
32 
33 /*!
34  * \brief Return original path of the executed program
35  *
36  * This function returns the name of the program as set by the call to
37  * G_gisinit().
38  *
39  * Unlike G_program_name() which returns name of the module
40  * this function return original path which was used to execute
41  * the program. For standard GRASS modules, it will be the same as
42  * the result from G_program_name() function.
43  *
44  * \return pointer to string with program name or full path
45  */
G_original_program_name(void)46 const char *G_original_program_name(void)
47 {
48     return original_name;
49 }
50 
51 /*!
52   \brief Set program name
53 
54   Program name set to name (name will be returned by
55   G_program_name*())
56 
57   Extension like .exe or .py is stripped from program name.
58 
59   \param s program name
60 */
G_set_program_name(const char * s)61 void G_set_program_name(const char *s)
62 {
63     int i;
64     char *temp;
65 
66     original_name = G_store(s);
67 
68     i = strlen(s);
69     while (--i >= 0) {
70 	if (G_is_dirsep(s[i])) {
71 	    s += i + 1;
72 	    break;
73 	}
74     }
75 
76     /* strip extension from program name */
77     temp = G_store(s);
78     G_basename(temp, "exe");
79     G_basename(temp, "py");
80     name = G_store(temp);
81 
82     G_debug(1, "G_set_program_name(): %s", name);
83 
84     G_free(temp);
85 }
86