GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2001-2014 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Original author CERL
10 */
11
12#include <string.h>
13#include <grass/gis.h>
14
15static const char *name = "?";
16static const char *original_name = "?";
17
18/*!
19 * \brief Return module name
20 *
21 * Routine returns the name of the module as set by the call to
22 * G_gisinit().
23 *
24 * \return pointer to string with program name
25 */
26const char *G_program_name(void)
27{
28 return name;
29}
30
31/*!
32 * \brief Return original path of the executed program
33 *
34 * This function returns the name of the program as set by the call to
35 * G_gisinit().
36 *
37 * Unlike G_program_name() which returns name of the module
38 * this function return original path which was used to execute
39 * the program. For standard GRASS modules, it will be the same as
40 * the result from G_program_name() function.
41 *
42 * \return pointer to string with program name or full path
43 */
44const char *G_original_program_name(void)
45{
46 return original_name;
47}
48
49/*!
50 \brief Set program name
51
52 Program name set to name (name will be returned by
53 G_program_name*())
54
55 Extension like .exe or .py is stripped from program name.
56
57 \param s program name
58 */
59void G_set_program_name(const char *s)
60{
61 int i;
62 char *temp;
63
64 original_name = G_store(s);
65
66 i = strlen(s);
67 while (--i >= 0) {
68 if (G_is_dirsep(s[i])) {
69 s += i + 1;
70 break;
71 }
72 }
73
74 /* strip extension from program name */
75 temp = G_store(s);
76 G_basename(temp, "exe");
77 G_basename(temp, "py");
78 name = G_store(temp);
79
80 G_debug(1, "G_set_program_name(): %s", name);
81
82 G_free(temp);
83}
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
int G_is_dirsep(char)
Checks if a specified character is a valid directory separator character on the host system.
Definition paths.c:45
char * G_store(const char *)
Copy string to allocated memory.
Definition strings.c:85
char * G_basename(char *, const char *)
Truncates filename to the base part (before the last '.') if it matches the extension,...
Definition basename.c:34
int G_debug(int, const char *,...) __attribute__((format(printf
const char * name
Definition named_colr.c:6
const char * G_program_name(void)
Return module name.
Definition progrm_nme.c:26
void G_set_program_name(const char *s)
Set program name.
Definition progrm_nme.c:59
const char * G_original_program_name(void)
Return original path of the executed program.
Definition progrm_nme.c:44