GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
progrm_nme.c
Go to the documentation of this file.
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  */
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  */
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 */
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 }
const char * G_original_program_name(void)
Return original path of the executed program.
Definition: progrm_nme.c:46
char * G_basename(char *, const char *)
Truncates filename to the base part (before the last &#39;.&#39;) if it matches the extension, otherwise leaves it unchanged.
Definition: basename.c:38
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
void G_set_program_name(const char *s)
Set program name.
Definition: progrm_nme.c:61
int G_is_dirsep(char)
Checks if a specified character is a valid directory separator character on the host system...
Definition: paths.c:45
const char * G_program_name(void)
Return module name.
Definition: progrm_nme.c:28
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
const char * name
Definition: named_colr.c:7
int G_debug(int, const char *,...) __attribute__((format(printf