GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
history.c File Reference
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for history.c:

Go to the source code of this file.

Functions

int G_read_history (const char *name, const char *mapset, struct History *hist)
 read raster history file More...
 
int G_write_history (const char *name, struct History *hist)
 write raster history file More...
 
int G_short_history (const char *name, const char *type, struct History *hist)
 initialize history structure More...
 
int G_command_history (struct History *hist)
 Save command line to raster history structure. More...
 

Function Documentation

int G_command_history ( struct History *  hist)

Save command line to raster history structure.

This routine takes an existing (run G_short_history first) history structure and adds the command line to the end of the comments array, as cleaned & expanded by the parser.

History file is limited to [80]x[50], as defined in include/gis.h

  • First version had for loops of [i][j] character assignments and ending nulls, but using the string libraries is cleaner and less bug prone.
  • Second version had white space detection, intelligent wrapping, and indentation of continued lines, but this proved a pain in the neck for things like r.patch which can have long strings without any parser-acceptable breaks.
  • This is MK-III, simplified, but that's good: it's cut & paste-able.

    NOTE: use G_write_history() to write the structure.

Sample Usage:

struct History history; G_short_history(rasterfile, "raster", &history); G_command_history(&history); G_write_history(rasterfile, &history);

Returns: 0 success 1 failure (history file full, no change) 2 failure (history file full, added as much as we could)

Parameters
history
Returns
int

Definition at line 254 of file history.c.

References G_recreate_command(), G_warning(), and sprintf().

Referenced by IL_output_2d().

int G_read_history ( const char *  name,
const char *  mapset,
struct History *  hist 
)

read raster history file

This routine reads the history file for the raster map name in mapset into the history structure. A diagnostic message is printed and -1 is returned if there is an error reading the history file. Otherwise, 0 is returned.

Parameters
name
mapset
history
Returns
int

Definition at line 75 of file history.c.

References fclose(), fd, G_ascii_check(), G_fopen_old(), G_getl(), G_warning(), G_zero(), and NULL.

int G_short_history ( const char *  name,
const char *  type,
struct History *  hist 
)

initialize history structure

This routine initializes the history structure, recording the date, user, module name and the raster map name structure. The type is an anachronism from earlier versions of GRASS and should be specified as "raster". Note. This routine only initializes the data structure. It does not write the history file.

Parameters
name
type
history
Returns
int

Definition at line 202 of file history.c.

References G_date(), G_mapset(), G_program_name(), G_whoami(), and sprintf().

Referenced by IL_output_2d(), and IL_resample_output_2d().

int G_write_history ( const char *  name,
struct History *  hist 
)

write raster history file

This routine writes the history file for the raster map name in the current mapset from the history structure. A diagnostic message is printed and -1 is returned if there is an error writing the history file. Otherwise, 0 is returned. Note. The history structure should first be initialized using G_short_history.

Parameters
name
history
Returns
int

Definition at line 153 of file history.c.

References fclose(), fd, G_fopen_new(), and G_warning().

Referenced by IL_output_2d(), and IL_resample_output_2d().