Go to the documentation of this file.00001
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <grass/Vect.h>
00024
00033 int Vect_hist_command(struct Map_info *Map)
00034 {
00035 char *cmd, buf[2000];
00036
00037 G_debug(3, "Vect_hist_command()");
00038
00039 cmd = G_recreate_command();
00040
00041 Vect_hist_write(Map, "COMMAND: ");
00042 Vect_hist_write(Map, cmd);
00043 Vect_hist_write(Map, "\n");
00044
00045 sprintf(buf, "GISDBASE: %s\n", G_gisdbase());
00046 Vect_hist_write(Map, buf);
00047
00048 sprintf(buf, "LOCATION: %s MAPSET: %s USER: %s DATE: %s\n", G_location(), G_mapset(), G_whoami(), G_date());
00049 Vect_hist_write(Map, buf);
00050
00051 return 0;
00052 }
00053
00062 int Vect_hist_write(struct Map_info *Map, const char *str)
00063 {
00064 int ret;
00065
00066 G_debug(5, "Vect_hist_write()");
00067 ret = fprintf(Map->hist_fp, str);
00068 fflush(Map->hist_fp);
00069
00070 return (ret);
00071 }
00072
00084 char *Vect_hist_read(char *s, int size, struct Map_info *Map)
00085 {
00086 int ret;
00087
00088 G_debug(5, "Vect_hist_read()");
00089
00090 if (Map->hist_fp == NULL)
00091 return NULL;
00092
00093 ret = G_getl2(s, size, Map->hist_fp);
00094
00095 if (ret == 1)
00096 return s;
00097
00098 return NULL;
00099 }
00100
00108 void Vect_hist_rewind(struct Map_info *Map)
00109 {
00110 G_debug(3, "Vect_hist_rewind()");
00111
00112 if (Map->hist_fp != NULL)
00113 rewind(Map->hist_fp);
00114 }
00115
00125 int Vect_hist_copy(struct Map_info *In, struct Map_info *Out)
00126 {
00127 size_t red, ret;
00128 char buf[1000];
00129
00130 G_debug(3, "Vect_hist_copy()");
00131
00132 if (In->hist_fp == NULL)
00133 return 0;
00134 if (Out->hist_fp == NULL)
00135 return -1;
00136
00137 fseek(Out->hist_fp, (long)0, SEEK_END);
00138 rewind(In->hist_fp);
00139
00140 while ((red = fread(buf, sizeof(char), sizeof(char) * 1000, In->hist_fp))) {
00141 if (!(ret = fwrite(buf, sizeof(char), red, Out->hist_fp))) {
00142 return (-1);
00143 }
00144 fflush(Out->hist_fp);
00145 }
00146
00147
00148 fseek(In->hist_fp, (long)-1, SEEK_END);
00149 if (fread(buf, sizeof(char), sizeof(char), In->hist_fp) != 1) {
00150 return -1;
00151 }
00152
00153 if (buf[0] != '\n') {
00154 Vect_hist_write(Out, "\n");
00155 }
00156
00157
00158 Vect_hist_write(Out,
00159 "---------------------------------------------------------------------------------\n");
00160 return (0);
00161 }