GRASS Programmer's Manual 6.4.1(2011)
file_name.c
Go to the documentation of this file.
00001 
00016 #include <string.h>
00017 #include <grass/gis.h>
00018 
00033 char *G__file_name(char *path,
00034                    const char *element, const char *name, const char *mapset)
00035 {
00036     char xname[GNAME_MAX];
00037     char xmapset[GMAPSET_MAX];
00038     const char *pname = name;
00039     char *location = G__location_path();
00040 
00041     /*
00042      * if a name is given, build a file name
00043      * must split the name into name, mapset if it is
00044      * in the name@mapset format
00045      */
00046     if (name && *name && G__name_is_fully_qualified(name, xname, xmapset)) {
00047         pname = xname;
00048         sprintf(path, "%s/%s", location, xmapset);
00049     }
00050     else if (mapset && *mapset)
00051         sprintf(path, "%s/%s", location, mapset);
00052     else
00053         sprintf(path, "%s/%s", location, G_mapset());
00054 
00055     G_free(location);
00056 
00057     if (element && *element) {
00058         strcat(path, "/");
00059         strcat(path, element);
00060     }
00061 
00062     if (pname && *pname) {
00063         strcat(path, "/");
00064         strcat(path, pname);
00065     }
00066 
00067     return path;
00068 }
00069 
00070 char *G__file_name_misc(char *path,
00071                         const char *dir,
00072                         const char *element,
00073                         const char *name, const char *mapset)
00074 {
00075     char xname[GNAME_MAX];
00076     char xmapset[GMAPSET_MAX];
00077     const char *pname = name;
00078     char *location = G__location_path();
00079 
00080     /*
00081      * if a name is given, build a file name
00082      * must split the name into name, mapset if it is
00083      * in the name@mapset format
00084      */
00085     if (name && *name && G__name_is_fully_qualified(name, xname, xmapset)) {
00086         pname = xname;
00087         sprintf(path, "%s/%s", location, xmapset);
00088     }
00089     else if (mapset && *mapset)
00090         sprintf(path, "%s/%s", location, mapset);
00091     else
00092         sprintf(path, "%s/%s", location, G_mapset());
00093 
00094     G_free(location);
00095 
00096     if (dir && *dir) {
00097         strcat(path, "/");
00098         strcat(path, dir);
00099     }
00100 
00101     if (pname && *pname) {
00102         strcat(path, "/");
00103         strcat(path, pname);
00104     }
00105 
00106     if (element && *element) {
00107         strcat(path, "/");
00108         strcat(path, element);
00109     }
00110 
00111     return path;
00112 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines