file_name.c

Go to the documentation of this file.
00001 /**********************************************************************
00002  *  char *
00003  *  G__file_name (path, element, name, maps)
00004  *      char path[]       buffer to hold resultant full path to file.
00005  *      char *element     database element (eg, "cell", "cellhd", etc)
00006  *      char *name        name of file to build path to
00007  *      char *maps        mapset name
00008  *   
00009  *      builds full path names to GIS data files
00010  *
00011  *  returns:
00012  *         pointer to 'path'
00013  *
00014  *   note:
00015  *      if name is of the form nnn@ppp then path is set
00016  *      as if name had been nnn and mapset had been ppp
00017  *      (mapset parameter itself is ignored in this case)
00018  *********************************************************************/
00019 
00020 #include <string.h>
00021 #include "gis.h"
00022 
00023 char *G__file_name ( 
00024         char *path,
00025         char *element,
00026         char *name,
00027         char *mapset)
00028 {
00029         char xname[512];
00030         char xmapset[512];
00031         char *location = G__location_path();
00032 
00033 /*
00034  * if a name is given, build a file name
00035  * must split the name into name, mapset if it is
00036  * in the name@mapset format
00037  */
00038         if (name && *name && G__name_is_fully_qualified(name, xname, xmapset))
00039         {
00040                 strcpy(name, xname);
00041                 sprintf(path,"%s/%s", location, xmapset);
00042         }
00043         else if (mapset && *mapset)
00044                 sprintf(path,"%s/%s", location, mapset);
00045         else
00046                 sprintf(path,"%s/%s", location, G_mapset());
00047 
00048         G_free (location);
00049         
00050         if (element && *element)
00051         {
00052                 strcat (path, "/");
00053                 strcat (path, element);
00054         }
00055 
00056         if (name && *name)
00057         {
00058                 strcat (path, "/");
00059                 strcat (path, name);
00060         }
00061 
00062 /*
00063  * return pointer to users 'path' buffer
00064  */
00065         return path;
00066 }

Generated on Wed Aug 23 17:49:22 2006 for GRASS by  doxygen 1.4.7