GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
file_name.c
Go to the documentation of this file.
1 
16 #include <string.h>
17 #include <grass/gis.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 && *element) {
58  strcat(path, "/");
59  strcat(path, element);
60  }
61 
62  if (pname && *pname) {
63  strcat(path, "/");
64  strcat(path, pname);
65  }
66 
67  return path;
68 }
69 
70 char *G__file_name_misc(char *path,
71  const char *dir,
72  const char *element,
73  const char *name, const char *mapset)
74 {
75  char xname[GNAME_MAX];
76  char xmapset[GMAPSET_MAX];
77  const char *pname = name;
78  char *location = G__location_path();
79 
80  /*
81  * if a name is given, build a file name
82  * must split the name into name, mapset if it is
83  * in the name@mapset format
84  */
85  if (name && *name && G__name_is_fully_qualified(name, xname, xmapset)) {
86  pname = xname;
87  sprintf(path, "%s/%s", location, xmapset);
88  }
89  else if (mapset && *mapset)
90  sprintf(path, "%s/%s", location, mapset);
91  else
92  sprintf(path, "%s/%s", location, G_mapset());
93 
94  G_free(location);
95 
96  if (dir && *dir) {
97  strcat(path, "/");
98  strcat(path, dir);
99  }
100 
101  if (pname && *pname) {
102  strcat(path, "/");
103  strcat(path, pname);
104  }
105 
106  if (element && *element) {
107  strcat(path, "/");
108  strcat(path, element);
109  }
110 
111  return path;
112 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
char xmapset[512]
Definition: g3dcats.c:89
char * G__file_name_misc(char *path, const char *dir, const char *element, const char *name, const char *mapset)
Definition: file_name.c:70
string name
Definition: render.py:1314
char * G__location_path(void)
Get current location path.
Definition: location.c:72
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
char xname[512]
Definition: g3dcats.c:89
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:57