history.c

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  *  G_read_history (name, mapset, phist)
00004  *      char *name                   name of map
00005  *      char *mapset                 mapset that map belongs to
00006  *      struct History *phist        structure to hold history info
00007  *
00008  *  Reads the history information associated with map layer "map"
00009  *  in mapset "mapset" into the structure "phist".
00010  *
00011  *   returns:    0  if successful
00012  *              -1  on fail
00013  *
00014  *  note:   a warning message is printed if the file is incorrect
00015  *
00016  **********************************************************************
00017  *
00018  *  G_write_history (name, phist)
00019  *      char *name                   name of map
00020  *      struct History *phist        structure holding history info
00021  *
00022  *  Writes the history information associated with map layer "map"
00023  *  into current from the structure "phist".
00024  *
00025  *   returns:    0  if successful
00026  *              -1  on fail
00027  ***********************************************************************
00028  *
00029  *  G_short_history (name, type, hist)
00030  *     char *name             name of cell file
00031  *     char *type             type of cell file
00032  *     struct History *hist   History structure to be filled in
00033  *
00034  *  Puts local information like time and date, user's name, map name,
00035  *  and current mapset name into the hist structure
00036  *
00037  *  NOTE: use G_write_history() to write the structure.
00038  **********************************************************************/
00039 
00040 #include <string.h>
00041 #include "gis.h"
00042 #include "glocale.h"
00043 
00044 
00060 int G_read_history (
00061     char *name,
00062     char *mapset,
00063     struct History *hist)
00064 {
00065     FILE *fd;
00066 
00067     G_zero (hist, sizeof (struct History));
00068     fd = G_fopen_old ("hist", name, mapset);
00069     if (!fd)
00070         goto error;
00071 
00072 
00073     if (!G_getl(hist->mapid, sizeof(hist->mapid), fd))
00074         goto error;
00075     G_ascii_check(hist->mapid) ;
00076 
00077     if (!G_getl(hist->title, sizeof(hist->title), fd))
00078         goto error;
00079     G_ascii_check(hist->title) ;
00080 
00081     if (!G_getl(hist->mapset, sizeof(hist->mapset), fd))
00082         goto error;
00083     G_ascii_check(hist->mapset) ;
00084 
00085     if (!G_getl(hist->creator, sizeof(hist->creator), fd))
00086         goto error;
00087     G_ascii_check(hist->creator) ;
00088 
00089     if (!G_getl(hist->maptype, sizeof(hist->maptype), fd))
00090         goto error;
00091     G_ascii_check(hist->maptype) ;
00092 
00093     if (!G_getl(hist->datsrc_1, sizeof(hist->datsrc_1), fd))
00094         goto error;
00095     G_ascii_check(hist->datsrc_1) ;
00096 
00097     if (!G_getl(hist->datsrc_2, sizeof(hist->datsrc_2), fd))
00098         goto error;
00099     G_ascii_check(hist->datsrc_2) ;
00100 
00101     if (!G_getl(hist->keywrd, sizeof(hist->keywrd), fd))
00102         goto error;
00103     G_ascii_check(hist->keywrd) ;
00104 
00105     hist->edlinecnt = 0;
00106     while ((hist->edlinecnt < MAXEDLINES) &&
00107         (G_getl( hist->edhist[hist->edlinecnt], sizeof (hist->edhist[0]), fd)))
00108     {
00109         G_ascii_check( hist->edhist[hist->edlinecnt]) ;
00110         hist->edlinecnt++;
00111     }
00112 
00113 
00114     fclose(fd) ;
00115     return 0;
00116 
00117 error:
00118     if (fd != NULL)
00119         fclose(fd) ;
00120     G_warning (_("can't get history information for [%s] in mapset [%s]"),
00121             name, mapset);
00122     return -1;
00123 }
00124 
00125 
00141 int G_write_history (
00142     char *name,
00143     struct History *hist)
00144 {
00145     FILE *fd;
00146     int i;
00147 
00148     fd = G_fopen_new ("hist", name);
00149     if (!fd)
00150             goto error;
00151 
00152     fprintf (fd, "%s\n", hist->mapid)    ; 
00153     fprintf (fd, "%s\n", hist->title)    ; 
00154     fprintf (fd, "%s\n", hist->mapset)  ; 
00155     fprintf (fd, "%s\n", hist->creator)  ; 
00156     fprintf (fd, "%s\n", hist->maptype)  ; 
00157     fprintf (fd, "%s\n", hist->datsrc_1) ; 
00158     fprintf (fd, "%s\n", hist->datsrc_2) ; 
00159     fprintf (fd, "%s\n", hist->keywrd)   ; 
00160 
00161     for(i=0; i < hist->edlinecnt; i++) 
00162             fprintf (fd, "%s\n", hist->edhist[i]) ;
00163 
00164     fclose (fd) ;
00165     return 0;
00166 
00167 error:
00168     if (fd)
00169             fclose(fd) ;
00170     G_warning (_("can't write history information for [%s]"), name);
00171     return -1;
00172 }
00173 
00174 
00175 
00192 int G_short_history (
00193     char *name,
00194     char *type,
00195     struct History *hist)
00196 {
00197     strcpy(hist->mapid,G_date());
00198     strcpy(hist->title,name);
00199     strcpy(hist->mapset,G_mapset());
00200     strcpy(hist->creator,G_whoami());
00201     strcpy(hist->maptype,type);
00202 
00203     sprintf(hist->keywrd, "generated by %s", G_program_name());
00204     strcpy(hist->datsrc_1,"");
00205     strcpy(hist->datsrc_2,"");
00206     hist->edlinecnt = 0;
00207 
00208     return 1;
00209 }

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