GRASS Programmer's Manual  6.5.svn(2014)-r66266
 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, "%s", 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 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int Vect_hist_copy(struct Map_info *In, struct Map_info *Out)
Copy history from one map to another.
Definition: hist.c:125
tuple cmd
Definition: forms.py:2020
void Vect_hist_rewind(struct Map_info *Map)
Rewind history file.
Definition: hist.c:108
char * G_recreate_command(void)
Creates command to run non-interactive.
Definition: parser.c:2829
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
int Vect_hist_command(struct Map_info *Map)
Write command info to history file.
Definition: hist.c:33
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
Definition: getl.c:52
char * G_gisdbase(void)
Get name of top level database directory.
Definition: gisdbase.c:29
char * G_location(void)
Get current location name.
Definition: location.c:61
char * Vect_hist_read(char *s, int size, struct Map_info *Map)
Reads one line from history file without newline character.
Definition: hist.c:84
char * G_whoami(void)
Gets user&#39;s name.
Definition: gis/whoami.c:40
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
tuple Map
Definition: render.py:1310
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
char * G_date(void)
Current date and time.
Definition: date.c:30
int Vect_hist_write(struct Map_info *Map, const char *str)
Write string to history file.
Definition: hist.c:62