00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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 }