GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
file_name.c
Go to the documentation of this file.
1 
14 #include <string.h>
15 #include <grass/gis.h>
16 
17 #include "gis_local_proto.h"
18 
33 char *G_file_name(char *path,
34  const char *element, const char *name, const char *mapset)
35 {
36  char xname[GNAME_MAX];
37  char xmapset[GMAPSET_MAX];
38  const char *pname = name;
39  char *location = G__location_path();
40 
41  /*
42  * if a name is given, build a file name
43  * must split the name into name, mapset if it is
44  * in the name@mapset format
45  */
46  if (name && *name && G_name_is_fully_qualified(name, xname, xmapset)) {
47  pname = xname;
48  sprintf(path, "%s/%s", location, xmapset);
49  }
50  else if (mapset && *mapset)
51  sprintf(path, "%s/%s", location, mapset);
52  else
53  sprintf(path, "%s/%s", location, G_mapset());
54 
55  G_free(location);
56 
57  if (!element && !pname)
58  return path;
59 
60  if (element && *element) {
61  strcat(path, "/");
62  strcat(path, element);
63  }
64 
65  if (pname && *pname) {
66  strcat(path, "/");
67  strcat(path, pname);
68  }
69 
70  G_debug(2, "G_file_name(): path = %s", path);
71 
72  return path;
73 }
74 
75 char *G_file_name_misc(char *path,
76  const char *dir,
77  const char *element,
78  const char *name, const char *mapset)
79 {
80  char xname[GNAME_MAX];
81  char xmapset[GMAPSET_MAX];
82  const char *pname = name;
83  char *location = G__location_path();
84 
85  /*
86  * if a name is given, build a file name
87  * must split the name into name, mapset if it is
88  * in the name@mapset format
89  */
90  if (name && *name && G_name_is_fully_qualified(name, xname, xmapset)) {
91  pname = xname;
92  sprintf(path, "%s/%s", location, xmapset);
93  }
94  else if (mapset && *mapset)
95  sprintf(path, "%s/%s", location, mapset);
96  else
97  sprintf(path, "%s/%s", location, G_mapset());
98 
99  G_free(location);
100 
101  if (dir && *dir) {
102  strcat(path, "/");
103  strcat(path, dir);
104  }
105 
106  if (pname && *pname) {
107  strcat(path, "/");
108  strcat(path, pname);
109  }
110 
111  if (element && *element) {
112  strcat(path, "/");
113  strcat(path, element);
114  }
115 
116  return path;
117 }
const char * G_mapset(void)
Get current mapset name.
Definition: mapset.c:33
char * G__location_path(void)
Get current location UNIX-like path (internal use only)
Definition: location.c:78
Definition: lidar.h:89
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition: file_name.c:33
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
Definition: path.h:16
int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)
Definition: nme_in_mps.c:36
char * G_file_name_misc(char *path, const char *dir, const char *element, const char *name, const char *mapset)
Definition: file_name.c:75
const char * name
Definition: named_colr.c:7
void G_free(void *buf)
Free allocated memory.
Definition: alloc.c:149