GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
hist.c
Go to the documentation of this file.
1
20
#include <stdlib.h>
21
#include <stdio.h>
22
#include <string.h>
23
#include <grass/Vect.h>
24
33
int
Vect_hist_command
(
struct
Map_info *Map)
34
{
35
char
*
cmd
, buf[2000];
36
37
G_debug
(3,
"Vect_hist_command()"
);
38
39
cmd =
G_recreate_command
();
40
41
Vect_hist_write
(Map,
"COMMAND: "
);
42
Vect_hist_write
(Map, cmd);
43
Vect_hist_write
(Map,
"\n"
);
44
45
sprintf(buf,
"GISDBASE: %s\n"
,
G_gisdbase
());
/* Needed ? */
46
Vect_hist_write
(Map, buf);
47
48
sprintf(buf,
"LOCATION: %s MAPSET: %s USER: %s DATE: %s\n"
,
G_location
(),
G_mapset
(),
G_whoami
(),
G_date
());
/* Needed ? */
49
Vect_hist_write
(Map, buf);
50
51
return
0;
52
}
53
62
int
Vect_hist_write
(
struct
Map_info *Map,
const
char
*str)
63
{
64
int
ret;
65
66
G_debug
(5,
"Vect_hist_write()"
);
67
ret = fprintf(Map->hist_fp, str);
68
fflush(Map->hist_fp);
69
70
return
(ret);
71
}
72
84
char
*
Vect_hist_read
(
char
*
s
,
int
size,
struct
Map_info *Map)
85
{
86
int
ret;
87
88
G_debug
(5,
"Vect_hist_read()"
);
89
90
if
(Map->hist_fp ==
NULL
)
91
return
NULL
;
/* OK for shapefile etc. */
92
93
ret =
G_getl2
(s, size, Map->hist_fp);
94
95
if
(ret == 1)
96
return
s
;
97
98
return
NULL
;
99
}
100
108
void
Vect_hist_rewind
(
struct
Map_info *Map)
109
{
110
G_debug
(3,
"Vect_hist_rewind()"
);
111
112
if
(Map->hist_fp !=
NULL
)
113
rewind(Map->hist_fp);
114
}
115
125
int
Vect_hist_copy
(
struct
Map_info *In,
struct
Map_info *Out)
126
{
127
size_t
red, ret;
128
char
buf[1000];
129
130
G_debug
(3,
"Vect_hist_copy()"
);
131
132
if
(In->hist_fp ==
NULL
)
133
return
0;
/* This is correct (old hist doesn't exist) */
134
if
(Out->hist_fp ==
NULL
)
135
return
-1;
136
137
fseek(Out->hist_fp, (
long
)0, SEEK_END);
138
rewind(In->hist_fp);
139
140
while
((red = fread(buf,
sizeof
(
char
),
sizeof
(
char
) * 1000, In->hist_fp))) {
141
if
(!(ret = fwrite(buf,
sizeof
(
char
), red, Out->hist_fp))) {
142
return
(-1);
143
}
144
fflush(Out->hist_fp);
145
}
146
147
/* In ends with \n ? */
148
fseek(In->hist_fp, (
long
)-1, SEEK_END);
149
if
(fread(buf,
sizeof
(
char
),
sizeof
(
char
), In->hist_fp) != 1) {
150
return
-1;
151
}
152
153
if
(buf[0] !=
'\n'
) {
154
Vect_hist_write
(Out,
"\n"
);
155
}
156
157
/* Separator */
158
Vect_hist_write
(Out,
159
"---------------------------------------------------------------------------------\n"
);
160
return
(0);
161
}
lib
vector
Vlib
hist.c
Generated on Sun Sep 9 2012 18:55:33 for GRASS Programmer's Manual by
1.8.1.2