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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include <string.h>
00055 #include <grass/gis.h>
00056 #include <grass/glocale.h>
00057
00058
00074 int G_read_history (
00075 char *name,
00076 char *mapset,
00077 struct History *hist)
00078 {
00079 FILE *fd;
00080
00081 G_zero (hist, sizeof (struct History));
00082 fd = G_fopen_old ("hist", name, mapset);
00083 if (!fd)
00084 goto error;
00085
00086
00087 if (!G_getl(hist->mapid, sizeof(hist->mapid), fd))
00088 goto error;
00089 G_ascii_check(hist->mapid) ;
00090
00091 if (!G_getl(hist->title, sizeof(hist->title), fd))
00092 goto error;
00093 G_ascii_check(hist->title) ;
00094
00095 if (!G_getl(hist->mapset, sizeof(hist->mapset), fd))
00096 goto error;
00097 G_ascii_check(hist->mapset) ;
00098
00099 if (!G_getl(hist->creator, sizeof(hist->creator), fd))
00100 goto error;
00101 G_ascii_check(hist->creator) ;
00102
00103 if (!G_getl(hist->maptype, sizeof(hist->maptype), fd))
00104 goto error;
00105 G_ascii_check(hist->maptype) ;
00106
00107 if (!G_getl(hist->datsrc_1, sizeof(hist->datsrc_1), fd))
00108 goto error;
00109 G_ascii_check(hist->datsrc_1) ;
00110
00111 if (!G_getl(hist->datsrc_2, sizeof(hist->datsrc_2), fd))
00112 goto error;
00113 G_ascii_check(hist->datsrc_2) ;
00114
00115 if (!G_getl(hist->keywrd, sizeof(hist->keywrd), fd))
00116 goto error;
00117 G_ascii_check(hist->keywrd) ;
00118
00119 hist->edlinecnt = 0;
00120 while ((hist->edlinecnt < MAXEDLINES) &&
00121 (G_getl( hist->edhist[hist->edlinecnt], sizeof (hist->edhist[0]), fd)))
00122 {
00123 G_ascii_check( hist->edhist[hist->edlinecnt]) ;
00124 hist->edlinecnt++;
00125 }
00126
00127
00128 fclose(fd) ;
00129 return 0;
00130
00131 error:
00132 if (fd != NULL)
00133 fclose(fd) ;
00134 G_warning (_("can't get history information for [%s] in mapset [%s]"),
00135 name, mapset);
00136 return -1;
00137 }
00138
00139
00155 int G_write_history (
00156 char *name,
00157 struct History *hist)
00158 {
00159 FILE *fd;
00160 int i;
00161
00162 fd = G_fopen_new ("hist", name);
00163 if (!fd)
00164 goto error;
00165
00166 fprintf (fd, "%s\n", hist->mapid) ;
00167 fprintf (fd, "%s\n", hist->title) ;
00168 fprintf (fd, "%s\n", hist->mapset) ;
00169 fprintf (fd, "%s\n", hist->creator) ;
00170 fprintf (fd, "%s\n", hist->maptype) ;
00171 fprintf (fd, "%s\n", hist->datsrc_1) ;
00172 fprintf (fd, "%s\n", hist->datsrc_2) ;
00173 fprintf (fd, "%s\n", hist->keywrd) ;
00174
00175 for(i=0; i < hist->edlinecnt; i++)
00176 fprintf (fd, "%s\n", hist->edhist[i]) ;
00177
00178 fclose (fd) ;
00179 return 0;
00180
00181 error:
00182 if (fd)
00183 fclose(fd) ;
00184 G_warning (_("can't write history information for [%s]"), name);
00185 return -1;
00186 }
00187
00188
00189
00206 int G_short_history (
00207 char *name,
00208 char *type,
00209 struct History *hist)
00210 {
00211 strncpy(hist->mapid, G_date(), RECORD_LEN);
00212 strncpy(hist->title, name, RECORD_LEN);
00213 strncpy(hist->mapset, G_mapset(), RECORD_LEN);
00214 strncpy(hist->creator, G_whoami(), RECORD_LEN);
00215 strncpy(hist->maptype, type, RECORD_LEN);
00216
00217 sprintf(hist->keywrd, "generated by %s", G_program_name());
00218 strcpy(hist->datsrc_1, "");
00219 strcpy(hist->datsrc_2, "");
00220 hist->edlinecnt = 0;
00221
00222 return 1;
00223 }
00224
00261 int G_command_history(struct History *hist) {
00262 int j, cmdlen;
00263 char *cmdlin;
00264
00265 cmdlin = G_recreate_command();
00266 cmdlen = strlen(cmdlin);
00267
00268 if(hist->edlinecnt > MAXEDLINES -2) {
00269 G_warning(_("Not enough room in history file to record command line."));
00270 return 1;
00271 }
00272
00273 if(hist->edlinecnt > 0) {
00274 strcpy(hist->edhist[hist->edlinecnt], "");
00275 hist->edlinecnt++;
00276 }
00277
00278 if(cmdlen < 70) {
00279 sprintf(hist->edhist[hist->edlinecnt], G_recreate_command());
00280 hist->edlinecnt++;
00281 }
00282 else {
00283 j = 0;
00284 while((cmdlen - j) > 70) {
00285 strncpy(hist->edhist[hist->edlinecnt], &cmdlin[j], 68);
00286 hist->edhist[hist->edlinecnt][68] = '\0';
00287 strcat(hist->edhist[hist->edlinecnt], "\\");
00288 j+=68;
00289 hist->edlinecnt++;
00290 if(hist->edlinecnt > MAXEDLINES -2) {
00291 G_warning(_("Not enough room in history file for command line (truncated)."));
00292 return 2;
00293 }
00294 }
00295 if((cmdlen - j) > 0) {
00296 strcpy(hist->edhist[hist->edlinecnt], &cmdlin[j]);
00297 hist->edlinecnt++;
00298 }
00299 }
00300 return 0;
00301 }