[GRASS-SVN] r42695 - in grass/trunk: imagery/i.maxlik imagery/i.pca imagery/i.rectify imagery/i.smap include lib/g3d lib/raster lib/rst/interp_float raster/r.buffer raster/r.carve raster/r.horizon raster/r.in.xyz raster/r.info raster/r.mapcalc raster/r.param.scale raster/r.random raster/r.reclass raster/r.recode raster/r.resamp.filter raster/r.resamp.interp raster/r.resamp.stats raster/r.slope.aspect raster/r.sun raster/r.sunmask raster/r.support raster/r.topidx raster/r.watershed/front raster/simwe/simlib raster3d/r3.in.ascii raster3d/r3.info raster3d/r3.to.rast vector/v.to.rast vector/v.vol.rst

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 2 11:45:16 EDT 2010


Author: glynn
Date: 2010-07-02 15:45:16 +0000 (Fri, 02 Jul 2010)
New Revision: 42695

Modified:
   grass/trunk/imagery/i.maxlik/hist.c
   grass/trunk/imagery/i.pca/support.c
   grass/trunk/imagery/i.rectify/exec.c
   grass/trunk/imagery/i.smap/history.c
   grass/trunk/include/raster.h
   grass/trunk/include/rasterdefs.h
   grass/trunk/lib/g3d/g3dhistory.c
   grass/trunk/lib/raster/history.c
   grass/trunk/lib/rst/interp_float/output2d.c
   grass/trunk/lib/rst/interp_float/resout2d.c
   grass/trunk/raster/r.buffer/main.c
   grass/trunk/raster/r.carve/support.c
   grass/trunk/raster/r.horizon/main.c
   grass/trunk/raster/r.in.xyz/main.c
   grass/trunk/raster/r.info/main.c
   grass/trunk/raster/r.mapcalc/map.c
   grass/trunk/raster/r.param.scale/close_down.c
   grass/trunk/raster/r.random/support.c
   grass/trunk/raster/r.reclass/reclass.c
   grass/trunk/raster/r.recode/recode.c
   grass/trunk/raster/r.resamp.filter/main.c
   grass/trunk/raster/r.resamp.interp/main.c
   grass/trunk/raster/r.resamp.stats/main.c
   grass/trunk/raster/r.slope.aspect/main.c
   grass/trunk/raster/r.sun/main.c
   grass/trunk/raster/r.sunmask/main.c
   grass/trunk/raster/r.support/main.c
   grass/trunk/raster/r.topidx/file_io.c
   grass/trunk/raster/r.watershed/front/main.c
   grass/trunk/raster/simwe/simlib/output.c
   grass/trunk/raster3d/r3.in.ascii/main.c
   grass/trunk/raster3d/r3.info/r3.info.main.c
   grass/trunk/raster3d/r3.to.rast/main.c
   grass/trunk/vector/v.to.rast/support.c
   grass/trunk/vector/v.vol.rst/main.c
Log:
Re-write raster history implementation
 All fields are dynamically allocated: no limits on line count or line lengths
 Provide/use set/get functions instead of direct structure access



Modified: grass/trunk/imagery/i.maxlik/hist.c
===================================================================
--- grass/trunk/imagery/i.maxlik/hist.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/imagery/i.maxlik/hist.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -5,8 +5,8 @@
     struct History hist;
 
     if (Rast_read_history(name, G_mapset(), &hist) >= 0) {
-	sprintf(hist.datsrc_1, "Group/subgroup: %s/%s", group, subgroup);
-	sprintf(hist.datsrc_2, "Signature file: %s", sigfile);
+	Rast_format_history(&hist, HIST_DATSRC_1, "Group/subgroup: %s/%s", group, subgroup);
+	Rast_format_history(&hist, HIST_DATSRC_2, "Signature file: %s", sigfile);
 	Rast_write_history(name, &hist);
     }
 

Modified: grass/trunk/imagery/i.pca/support.c
===================================================================
--- grass/trunk/imagery/i.pca/support.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/imagery/i.pca/support.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -38,7 +38,7 @@
     double eigval_total = 0.0;
 
     Rast_short_history(outname, "raster", &hist);
-    sprintf(hist.edhist[0], "Eigen values, (vectors), and [percent importance]:");
+    Rast_append_history(&hist, "Eigen values, (vectors), and [percent importance]:");
 
     if(first_map)
 	G_message(_("Eigen values, (vectors), and [percent importance]:"));
@@ -63,14 +63,13 @@
 	sprintf(tmpa, "[%5.2f%%]", eigval[i] * 100/eigval_total);
 	strcat(tmpeigen, tmpa);
 
-	sprintf(hist.edhist[i + 1], tmpeigen);
+	Rast_append_history(&hist, tmpeigen);
 
 	/* write eigen values to screen */
 	if(first_map)
 	    G_message("%s", tmpeigen);
     }
 
-    hist.edlinecnt = i + 1;
     Rast_command_history(&hist);
 
     /* only write to stderr the first time (this fn runs for every output map) */

Modified: grass/trunk/imagery/i.rectify/exec.c
===================================================================
--- grass/trunk/imagery/i.rectify/exec.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/imagery/i.rectify/exec.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -87,11 +87,10 @@
 		}
 
 		/* Write out History Structure History */
-		sprintf(hist.title, "%s", result);
-		sprintf(hist.datsrc_1, "%s", name);
-		sprintf(hist.edhist[0], "Created from: i.rectify");
-		sprintf(hist.edhist[1], "Transformation order = %d", order);
-		hist.edlinecnt = 2;
+		Rast_set_history(&hist, HIST_TITLE, result);
+		Rast_set_history(&hist, HIST_DATSRC_1, name);
+		Rast_append_history(&hist, "Created from: i.rectify");
+		Rast_append_format_history(&hist, "Transformation order = %d", order);
 		Rast_write_history(result, &hist);
 
 		select_current_env();

Modified: grass/trunk/imagery/i.smap/history.c
===================================================================
--- grass/trunk/imagery/i.smap/history.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/imagery/i.smap/history.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -6,8 +6,8 @@
     struct History hist;
 
     if (Rast_read_history(name, G_mapset(), &hist) >= 0) {
-	sprintf(hist.datsrc_1, "Group/subgroup: %s/%s", group, subgroup);
-	sprintf(hist.datsrc_2, "Sigset file: %s", sigfile);
+	Rast_format_history(&hist, HIST_DATSRC_1, "Group/subgroup: %s/%s", group, subgroup);
+	Rast_format_history(&hist, HIST_DATSRC_2, "Sigset file: %s", sigfile);
 	Rast_write_history(name, &hist);
     }
 }

Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/include/raster.h	2010-07-02 15:45:16 UTC (rev 42695)
@@ -10,10 +10,6 @@
 #define FCELL_TYPE 1
 #define DCELL_TYPE 2
 
-/* History */
-#define RECORD_LEN  80
-#define MAXEDLINES  50
-
 /* for G_get_raster_sample(), INTERP_TYPE */
 #define UNKNOWN	  0
 #define NEAREST   1		/* nearest neighbor interpolation  */
@@ -153,18 +149,25 @@
     /* label, and quant rules are never reordered. Olga apr,95 */
 };
 
+enum History_field
+{
+    HIST_MAPID,
+    HIST_TITLE,
+    HIST_MAPSET,
+    HIST_CREATOR,
+    HIST_MAPTYPE,
+    HIST_DATSRC_1,
+    HIST_DATSRC_2,
+    HIST_KEYWRD,
+
+    HIST_NUM_FIELDS,
+};
+
 struct History
 {
-    char mapid[RECORD_LEN];
-    char title[RECORD_LEN];
-    char mapset[RECORD_LEN];
-    char creator[RECORD_LEN];
-    char maptype[RECORD_LEN];
-    char datsrc_1[RECORD_LEN];
-    char datsrc_2[RECORD_LEN];
-    char keywrd[RECORD_LEN];
-    int edlinecnt;
-    char edhist[MAXEDLINES][RECORD_LEN];
+    char *fields[HIST_NUM_FIELDS];
+    int nlines;
+    char **lines;
 };
 
 struct Cell_stats

Modified: grass/trunk/include/rasterdefs.h
===================================================================
--- grass/trunk/include/rasterdefs.h	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/include/rasterdefs.h	2010-07-02 15:45:16 UTC (rev 42695)
@@ -338,10 +338,23 @@
 void Rast_zero_histogram(struct Histogram *);
 
 /* history.c */
+int Rast__read_history(struct History *, FILE *);
 int Rast_read_history(const char *, const char *, struct History *);
+void Rast__write_history(struct History *, FILE *);
 void Rast_write_history(const char *, struct History *);
 void Rast_short_history(const char *, const char *, struct History *);
 int Rast_command_history(struct History *);
+void Rast_append_history(struct History *, const char *);
+void Rast_append_format_history(struct History *, const char *, ...)
+    __attribute__ ((format(printf, 2, 3)));
+const char *Rast_get_history(struct History *, int);
+void Rast_set_history(struct History *, int, const char *);
+void Rast_format_history(struct History *, int, const char *, ...)
+    __attribute__ ((format(printf, 3, 4)));
+void Rast_clear_history(struct History *);
+void Rast_free_history(struct History *);
+int Rast_history_length(struct History *);
+const char *Rast_history_line(struct History *, int);
 
 /* init.c */
 void Rast_init(void);

Modified: grass/trunk/lib/g3d/g3dhistory.c
===================================================================
--- grass/trunk/lib/g3d/g3dhistory.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/lib/g3d/g3dhistory.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <grass/glocale.h>
 #include "G3d_intern.h"
+#include <grass/raster.h>
 
 /*simple error message */
 void SimpleErrorMessage(FILE * fd, const char *name, const char *mapset)
@@ -61,74 +62,20 @@
  */
 
 int G3d_readHistory(const char *name, const char *mapset, struct History *hist)
-/* This function is adapted from Rast_read_history */
 {
-    FILE *fd;
+    FILE *fp;
 
-    G_zero(hist, sizeof(struct History));
+    G_zero(&hist, sizeof(struct History));
 
-    fd = G_fopen_old_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name, mapset);
-    if (!fd)
+    fp = G_fopen_old_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name, mapset);
+    if (!fp)
 	return -2;
 
-    if (!G_getl(hist->mapid, sizeof(hist->mapid), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->mapid);
+    if (Rast__read_history(hist, fp) == 0)
+	return 0;
 
-    if (!G_getl(hist->title, sizeof(hist->title), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->title);
-
-    if (!G_getl(hist->mapset, sizeof(hist->mapset), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->mapset);
-
-    if (!G_getl(hist->creator, sizeof(hist->creator), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->creator);
-
-    if (!G_getl(hist->maptype, sizeof(hist->maptype), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->maptype);
-
-    if (!G_getl(hist->datsrc_1, sizeof(hist->datsrc_1), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->datsrc_1);
-
-    if (!G_getl(hist->datsrc_2, sizeof(hist->datsrc_2), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->datsrc_2);
-
-    if (!G_getl(hist->keywrd, sizeof(hist->keywrd), fd)) {
-	SimpleErrorMessage(fd, name, mapset);
-	return -1;
-    }
-    G_ascii_check(hist->keywrd);
-
-    hist->edlinecnt = 0;
-    while ((hist->edlinecnt < MAXEDLINES) &&
-	   (G_getl
-	    (hist->edhist[hist->edlinecnt], sizeof(hist->edhist[0]), fd))) {
-	G_ascii_check(hist->edhist[hist->edlinecnt]);
-	hist->edlinecnt++;
-    }
-
-    fclose(fd);
-    return 0;
+    SimpleErrorMessage(fp, name, mapset);
+    return -1;
 }
 
 
@@ -150,25 +97,10 @@
 int G3d_writeHistory(const char *name, struct History *hist)
 /* This function is adapted from Rast_write_history */
 {
-    FILE *fd;
-    int i;
-
-    fd = G_fopen_new_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name);
-    if (!fd)
+    FILE *fp = G_fopen_new_misc(G3D_DIRECTORY, G3D_HISTORY_ELEMENT, name);
+    if (!fp)
 	return -1;
 
-    fprintf(fd, "%s\n", hist->mapid);
-    fprintf(fd, "%s\n", hist->title);
-    fprintf(fd, "%s\n", hist->mapset);
-    fprintf(fd, "%s\n", hist->creator);
-    fprintf(fd, "%s\n", hist->maptype);
-    fprintf(fd, "%s\n", hist->datsrc_1);
-    fprintf(fd, "%s\n", hist->datsrc_2);
-    fprintf(fd, "%s\n", hist->keywrd);
-
-    for (i = 0; i < hist->edlinecnt; i++)
-	fprintf(fd, "%s\n", hist->edhist[i]);
-
-    fclose(fd);
+    Rast__write_history(hist, fp);
     return 0;
 }

Modified: grass/trunk/lib/raster/history.c
===================================================================
--- grass/trunk/lib/raster/history.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/lib/raster/history.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -11,13 +11,63 @@
  * \author Original author CERL
  */
 
+#include <stdarg.h>
 #include <string.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-static void print_history_error(const char *, const char *, FILE *);
+void Rast_append_history(struct History *hist, const char *str)
+{
+    hist->lines = G_realloc(hist->lines, (hist->nlines + 1) * sizeof(char *));
+    hist->lines[hist->nlines++] = G_store(str);
+}
 
+void Rast_append_format_history(struct History *hist, const char *fmt, ...)
+{
+    va_list ap;
+    char *str;
+
+    hist->lines = G_realloc(hist->lines, (hist->nlines + 1) * sizeof(char *));
+
+    va_start(ap, fmt);
+    G_vasprintf(&str, fmt, ap);
+    va_end(ap);
+
+    hist->lines[hist->nlines++] = str;
+}
+
+int Rast__read_history(struct History *hist, FILE *fp)
+{
+    int i;
+
+    for (i = 0; i < HIST_NUM_FIELDS; i++) {
+	char buf[4096];
+
+	if (!G_getl(buf, sizeof(buf), fp)) {
+	    fclose(fp);
+	    return -1;
+	}
+
+	G_ascii_check(buf);
+
+	hist->fields[i] = G_store(buf);
+    }
+
+    hist->nlines = 0;
+
+    for (;;) {
+	char buf[4096];
+	if (!G_getl(buf, sizeof(buf), fp))
+	    break;
+	Rast_append_history(hist, buf);
+    }
+
+    fclose(fp);
+
+    return 0;
+}
+
 /*!
  * \brief Read raster history file
  *
@@ -37,85 +87,38 @@
 int Rast_read_history(const char *name, const char *mapset,
 		      struct History *hist)
 {
-    FILE *fd;
+    FILE *fp;
 
     G_zero(hist, sizeof(struct History));
-    fd = G_fopen_old("hist", name, mapset);
-    if (!fd) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
 
-    if (!G_getl(hist->mapid, sizeof(hist->mapid), fd)) {
-	print_history_error(name, mapset, fd);
+    fp = G_fopen_old("hist", name, mapset);
+    if (!fp) {
+	G_warning(_("Unable to get history information for <%s@%s>"),
+		  name, mapset);
 	return -1;
     }
-    G_ascii_check(hist->mapid);
 
-    if (!G_getl(hist->title, sizeof(hist->title), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->title);
+    if (Rast__read_history(hist, fp) == 0)
+	return 0;
 
-    if (!G_getl(hist->mapset, sizeof(hist->mapset), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->mapset);
+    G_warning(_("Unable to get history information for <%s@%s>"),
+	      name, mapset);
+    return -1;
+}
 
-    if (!G_getl(hist->creator, sizeof(hist->creator), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->creator);
+void Rast__write_history(struct History *hist, FILE *fp)
+{
+    int i;
 
-    if (!G_getl(hist->maptype, sizeof(hist->maptype), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->maptype);
+    for (i = 0; i < HIST_NUM_FIELDS; i++)
+	fprintf(fp, "%s\n", hist->fields[i] ? hist->fields[i] : "");
 
-    if (!G_getl(hist->datsrc_1, sizeof(hist->datsrc_1), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->datsrc_1);
+    for (i = 0; i < hist->nlines; i++)
+	fprintf(fp, "%s\n", hist->lines[i]);
 
-    if (!G_getl(hist->datsrc_2, sizeof(hist->datsrc_2), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->datsrc_2);
-
-    if (!G_getl(hist->keywrd, sizeof(hist->keywrd), fd)) {
-	print_history_error(name, mapset, fd);
-	return -1;
-    }
-    G_ascii_check(hist->keywrd);
-
-    hist->edlinecnt = 0;
-    while ((hist->edlinecnt < MAXEDLINES) &&
-	   (G_getl
-	    (hist->edhist[hist->edlinecnt], sizeof(hist->edhist[0]), fd))) {
-	G_ascii_check(hist->edhist[hist->edlinecnt]);
-	hist->edlinecnt++;
-    }
-
-    fclose(fd);
-
-    return 0;
+    fclose(fp);
 }
 
-static void print_history_error(const char *name, const char *mapset, FILE *fp)
-{
-    if (fp)
-	fclose(fp);
-
-    G_warning(_("Unable to get history information for <%s@%s>"),
-	      name, mapset);
-}
-
 /*!
  * \brief Write raster history file
  *
@@ -135,28 +138,37 @@
  */
 void Rast_write_history(const char *name, struct History *hist)
 {
-    FILE *fp;
-    int i;
-
-    fp = G_fopen_new("hist", name);
+    FILE *fp = G_fopen_new("hist", name);
     if (!fp)
 	G_fatal_error(_("Unable to write history information for <%s>"), name);
 
-    fprintf(fp, "%s\n", hist->mapid);
-    fprintf(fp, "%s\n", hist->title);
-    fprintf(fp, "%s\n", hist->mapset);
-    fprintf(fp, "%s\n", hist->creator);
-    fprintf(fp, "%s\n", hist->maptype);
-    fprintf(fp, "%s\n", hist->datsrc_1);
-    fprintf(fp, "%s\n", hist->datsrc_2);
-    fprintf(fp, "%s\n", hist->keywrd);
+    Rast__write_history(hist, fp);
+}
 
-    for (i = 0; i < hist->edlinecnt; i++)
-	fprintf(fp, "%s\n", hist->edhist[i]);
+const char *Rast_get_history(struct History *hist, int field)
+{
+    return hist->fields[field];
+}
 
-    fclose(fp);
+void Rast_set_history(struct History *hist, int field, const char *str)
+{
+    if (hist->fields[field])
+	G_free(hist->fields[field]);
+    hist->fields[field] = str ? G_store(str) : NULL;
 }
 
+void Rast_format_history(struct History *hist, int field, const char *fmt, ...)
+{
+    va_list ap;
+
+    if (hist->fields[field])
+	G_free(hist->fields[field]);
+
+    va_start(ap, fmt);
+    G_vasprintf(&hist->fields[field], fmt, ap);
+    va_end(ap);
+}
+
 /*!
  * \brief Initialize history structure
  *
@@ -175,16 +187,16 @@
 void Rast_short_history(const char *name, const char *type,
 			struct History *hist)
 {
-    strncpy(hist->mapid, G_date(), RECORD_LEN);
-    strncpy(hist->title, name, RECORD_LEN);
-    strncpy(hist->mapset, G_mapset(), RECORD_LEN);
-    strncpy(hist->creator, G_whoami(), RECORD_LEN);
-    strncpy(hist->maptype, type, RECORD_LEN);
-
-    sprintf(hist->keywrd, _("generated by %s"), G_program_name());
-    strcpy(hist->datsrc_1, "");
-    strcpy(hist->datsrc_2, "");
-    hist->edlinecnt = 0;
+    G_zero(hist, sizeof(struct History));
+    Rast_set_history(hist, HIST_MAPID, G_date());
+    Rast_set_history(hist, HIST_TITLE, name);
+    Rast_set_history(hist, HIST_MAPSET, G_mapset());
+    Rast_set_history(hist, HIST_CREATOR, G_whoami());
+    Rast_set_history(hist, HIST_MAPTYPE, type);
+    Rast_format_history(hist, HIST_KEYWRD, _("generated by %s"), G_program_name());
+    Rast_set_history(hist, HIST_DATSRC_1, "");
+    Rast_set_history(hist, HIST_DATSRC_2, "");
+    hist->nlines = 0;
 }
 
 /*!
@@ -222,43 +234,68 @@
  */
 int Rast_command_history(struct History *hist)
 {
-    int j, cmdlen;
     char *cmdlin;
+    int cmdlen;
 
     cmdlin = G_recreate_command();
     cmdlen = strlen(cmdlin);
 
-    if (hist->edlinecnt > MAXEDLINES - 2) {
-	G_warning(_("Not enough room in history file to record command line"));
-	return 1;
-    }
+    if (hist->nlines > 0)	/* add a blank line if preceding history exists */
+	Rast_append_history(hist, "");
 
-    if (hist->edlinecnt > 0) {	/* add a blank line if preceding history exists */
-	strcpy(hist->edhist[hist->edlinecnt], "");
-	hist->edlinecnt++;
-    }
-
-    if (cmdlen < 70) {		/* ie if it will fit on a single line */
-	sprintf(hist->edhist[hist->edlinecnt], G_recreate_command());
-	hist->edlinecnt++;
-    }
+    if (cmdlen < 70)		/* ie if it will fit on a single line */
+	Rast_append_history(hist, cmdlin);
     else {			/* multi-line required */
-	j = 0;			/* j is the current position in the command line string */
-	while ((cmdlen - j) > 70) {
-	    strncpy(hist->edhist[hist->edlinecnt], &cmdlin[j], 68);
-	    hist->edhist[hist->edlinecnt][68] = '\0';
-	    strcat(hist->edhist[hist->edlinecnt], "\\");
-	    j += 68;
-	    hist->edlinecnt++;
-	    if (hist->edlinecnt > MAXEDLINES - 2) {
-		G_warning(_("Not enough room in history file for command line (truncated)"));
-		return 2;
-	    }
+	int j;			/* j is the current position in the command line string */
+	for (j = 0; cmdlen - j > 70; j += 68) {
+	    char buf[80];
+	    memcpy(buf, &cmdlin[j], 68);
+	    buf[68] = '\\';
+	    buf[69] = '\0';
+	    Rast_append_history(hist, buf);
 	}
-	if ((cmdlen - j) > 0) {	/* ie anything left */
-	    strcpy(hist->edhist[hist->edlinecnt], &cmdlin[j]);
-	    hist->edlinecnt++;
-	}
+	if (cmdlen - j > 0)	/* ie anything left */
+	    Rast_append_history(hist, &cmdlin[j]);
     }
+
     return 0;
 }
+
+void Rast_clear_history(struct History *hist)
+{
+    int i;
+
+    for (i = 0; i < hist->nlines; i++)
+	G_free(hist->lines[i]);
+
+    if (hist->lines)
+	G_free(hist->lines);
+
+    hist->nlines = 0;
+}
+
+void Rast_free_history(struct History *hist)
+{
+    int i;
+
+    for (i = 0; i < HIST_NUM_FIELDS; i++)
+	if (hist->fields[i]) {
+	    G_free(hist->fields[i]);
+	    hist->fields[i] = NULL;
+	}
+
+    Rast_clear_history(hist);
+}
+
+int Rast_history_length(struct History *hist)
+{
+    return hist->nlines;
+}
+
+const char *Rast_history_line(struct History *hist, int line)
+{
+    if (line < 0 || line >= hist->nlines)
+	return "";
+    return hist->lines[line];
+}
+

Modified: grass/trunk/lib/rst/interp_float/output2d.c
===================================================================
--- grass/trunk/lib/rst/interp_float/output2d.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/lib/rst/interp_float/output2d.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -25,7 +25,27 @@
 
 #define MULT 100000
 
+static void do_history(const char *name, int vect, const char *input,
+		       const struct interp_params *params)
+{
+    struct History hist;
 
+    Rast_short_history(name, "raster", &hist);
+    if (params->elev)
+	Rast_append_format_history(&hist, "The elevation map is %s",
+				   params->elev);
+    Rast_format_history(&hist, HIST_DATSRC_1, "%s %s",
+			vect ? "vector map" : "site file",
+			input);
+
+    Rast_command_history(&hist);
+    Rast_write_history(name, &hist);
+    if (params->ts)
+	G_write_raster_timestamp(name, params->ts);
+
+    Rast_free_history(&hist);
+}
+
 int IL_output_2d(struct interp_params *params, struct Cell_head *cellhd,	/* current region */
 		 double zmin, double zmax,	/* min,max input z-values */
 		 double zminac, double zmaxac, double c1min, double c1max,	/* min,max interpolated values */
@@ -45,7 +65,7 @@
     double zstep;
     FCELL data1, data2;
     struct Colors colors;
-    struct History hist, hist1, hist2, hist3, hist4, hist5;
+    struct History hist;
     char *type;
     const char *mapset = NULL;
     int cond1, cond2;
@@ -312,22 +332,7 @@
 	    Rast_write_colors(params->slope, mapset, &colors);
 	    Rast_quantize_fp_map_range(params->slope, mapset, 0., 90., 0, 90);
 
-	    type = "raster";
-	    Rast_short_history(params->slope, type, &hist1);
-	    if (params->elev != NULL)
-		sprintf(hist1.edhist[0], "The elevation map is %s",
-			params->elev);
-	    if (vect)
-		sprintf(hist1.datsrc_1, "vector map %s", input);
-	    else
-		sprintf(hist1.datsrc_1, "site file %s", input);
-	    hist1.edlinecnt = 1;
-
-	    Rast_command_history(&hist1);
-	    Rast_write_history(params->slope, &hist1);
-	    if (params->ts)
-		G_write_raster_timestamp(params->slope, params->ts);
-
+	    do_history(params->slope, vect, input, params);
 	}
 
 	/* colortable for aspect */
@@ -396,21 +401,7 @@
 	    Rast_write_colors(params->aspect, mapset, &colors);
 	    Rast_quantize_fp_map_range(params->aspect, mapset, 0., 360., 0, 360);
 
-	    type = "raster";
-	    Rast_short_history(params->aspect, type, &hist2);
-	    if (params->elev != NULL)
-		sprintf(hist2.edhist[0], "The elevation map is %s",
-			params->elev);
-	    if (vect)
-		sprintf(hist2.datsrc_1, "vector map %s", input);
-	    else
-		sprintf(hist2.datsrc_1, "site file %s", input);
-	    hist2.edlinecnt = 1;
-
-	    Rast_command_history(&hist2);
-	    Rast_write_history(params->aspect, &hist2);
-	    if (params->ts)
-		G_write_raster_timestamp(params->aspect, params->ts);
+	    do_history(params->aspect, vect, input, params);
 	}
 
 	/* colortable for curvatures */
@@ -462,21 +453,7 @@
 					(CELL) (dat1 * MULT),
 					(CELL) (dat2 * MULT));
 
-		type = "raster";
-		Rast_short_history(params->pcurv, type, &hist3);
-		if (params->elev != NULL)
-		    sprintf(hist3.edhist[0], "The elevation map is %s",
-			    params->elev);
-		if (vect)
-		    sprintf(hist3.datsrc_1, "vector map %s", input);
-		else
-		    sprintf(hist3.datsrc_1, "site file %s", input);
-		hist3.edlinecnt = 1;
-
-		Rast_command_history(&hist3);
-		Rast_write_history(params->pcurv, &hist3);
-		if (params->ts)
-		    G_write_raster_timestamp(params->pcurv, params->ts);
+		do_history(params->pcurv, vect, input, params);
 	    }
 
 	    if (params->tcurv != NULL) {
@@ -490,21 +467,7 @@
 					(CELL) (dat1 * MULT),
 					(CELL) (dat2 * MULT));
 
-		type = "raster";
-		Rast_short_history(params->tcurv, type, &hist4);
-		if (params->elev != NULL)
-		    sprintf(hist4.edhist[0], "The elevation map is %s",
-			    params->elev);
-		if (vect)
-		    sprintf(hist4.datsrc_1, "vector map %s", input);
-		else
-		    sprintf(hist4.datsrc_1, "site file %s", input);
-		hist4.edlinecnt = 1;
-
-		Rast_command_history(&hist4);
-		Rast_write_history(params->tcurv, &hist4);
-		if (params->ts)
-		    G_write_raster_timestamp(params->tcurv, params->ts);
+		do_history(params->tcurv, vect, input, params);
 	    }
 
 	    if (params->mcurv != NULL) {
@@ -518,21 +481,7 @@
 					(CELL) (dat1 * MULT),
 					(CELL) (dat2 * MULT));
 
-		type = "raster";
-		Rast_short_history(params->mcurv, type, &hist5);
-		if (params->elev != NULL)
-		    sprintf(hist5.edhist[0], "The elevation map is %s",
-			    params->elev);
-		if (vect)
-		    sprintf(hist5.datsrc_1, "vector map %s", input);
-		else
-		    sprintf(hist5.datsrc_1, "site file %s", input);
-		hist5.edlinecnt = 1;
-
-		Rast_command_history(&hist5);
-		Rast_write_history(params->mcurv, &hist5);
-		if (params->ts)
-		    G_write_raster_timestamp(params->mcurv, params->ts);
+		do_history(params->mcurv, vect, input, params);
 	    }
 	}
     }
@@ -555,23 +504,28 @@
 
 	if (dtens) {
 	    if (params->rsm == -1)
-		sprintf(hist.edhist[0], "giventension=%f, smoothing att=%d",
-			params->fi * 1000. / dnorm, params->smatt);
+		Rast_append_format_history(
+		    &hist, "giventension=%f, smoothing att=%d",
+		    params->fi * 1000. / dnorm, params->smatt);
 	    else
-		sprintf(hist.edhist[0], "giventension=%f, smoothing=%f",
-			params->fi * 1000. / dnorm, params->rsm);
+		Rast_append_format_history(
+		    &hist, "giventension=%f, smoothing=%f",
+		    params->fi * 1000. / dnorm, params->rsm);
 	}
 	else {
 	    if (params->rsm == -1)
-		sprintf(hist.edhist[0], "tension=%f, smoothing att=%d",
-			params->fi * 1000. / dnorm, params->smatt);
+		Rast_append_format_history(
+		    &hist, "tension=%f, smoothing att=%d",
+		    params->fi * 1000. / dnorm, params->smatt);
 	    else
-		sprintf(hist.edhist[0], "tension=%f, smoothing=%f",
-			params->fi, params->rsm);
+		Rast_append_format_history(
+		    &hist, "tension=%f, smoothing=%f",
+		    params->fi, params->rsm);
 	}
 
-	sprintf(hist.edhist[1], "dnorm=%f, dmin=%f, zmult=%f",
-		dnorm, params->dmin, params->zmult);
+	Rast_append_format_history(
+	    &hist, "dnorm=%f, dmin=%f, zmult=%f",
+	    dnorm, params->dmin, params->zmult);
 	/*
 	 * sprintf(hist.edhist[2], "segmax=%d, npmin=%d, errtotal=%f",
 	 * params->kmax,params->kmin,ertot);
@@ -581,29 +535,30 @@
 	 * params->kmax, params->kmin, sqrt (ertot) / n_points);
 	 */
 
-	sprintf(hist.edhist[2], "segmax=%d, npmin=%d, rmsdevi=%f",
-		params->kmax, params->kmin, sqrt(ertot / n_points));
+	Rast_append_format_history(
+	    &hist, "segmax=%d, npmin=%d, rmsdevi=%f",
+	    params->kmax, params->kmin, sqrt(ertot / n_points));
 
-	sprintf(hist.edhist[3], "zmin_data=%f, zmax_data=%f", zmin, zmax);
-	sprintf(hist.edhist[4], "zmin_int=%f, zmax_int=%f", zminac, zmaxac);
+	Rast_append_format_history(
+	    &hist, "zmin_data=%f, zmax_data=%f", zmin, zmax);
+	Rast_append_format_history(
+	    &hist, "zmin_int=%f, zmax_int=%f", zminac, zmaxac);
 
-	if ((params->theta) && (params->scalex)) {
-	    sprintf(hist.edhist[5], "theta=%f, scalex=%f", params->theta,
-		    params->scalex);
-	    hist.edlinecnt = 6;
-	}
-	else
-	    hist.edlinecnt = 5;
+	if ((params->theta) && (params->scalex))
+	    Rast_append_format_history(
+		&hist, "theta=%f, scalex=%f", params->theta,
+		params->scalex);
 
-	if (vect)
-	    sprintf(hist.datsrc_1, "vector map %s", input);
-	else
-	    sprintf(hist.datsrc_1, "site file %s", input);
+	Rast_format_history(&hist, HIST_DATSRC_1, "%s %s",
+			    vect ? "vector map" : "site file",
+			    input);
 
 	Rast_command_history(&hist);
 	Rast_write_history(params->elev, &hist);
 	if (params->ts)
 	    G_write_raster_timestamp(params->elev, params->ts);
+
+	Rast_free_history(&hist);
     }
 
     /*

Modified: grass/trunk/lib/rst/interp_float/resout2d.c
===================================================================
--- grass/trunk/lib/rst/interp_float/resout2d.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/lib/rst/interp_float/resout2d.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -25,6 +25,23 @@
 
 /* output cell maps for elevation, aspect, slope and curvatures */
 
+static void do_history(const char *name, const char *input,
+		       const struct interp_params *params)
+{
+    struct History hist;
+
+    Rast_short_history(name, "raster", &hist);
+    if (params->elev)
+	Rast_append_format_history(&hist, "The elevation map is %s",
+				   params->elev);
+
+    Rast_format_history(&hist, HIST_DATSRC_1, "raster map %s", input);
+
+    Rast_write_history(name, &hist);
+
+    Rast_free_history(&hist);
+}
+
 int IL_resample_output_2d(struct interp_params *params, double zmin, double zmax,	/* min,max input z-values */
 			  double zminac, double zmaxac,	/* min,max interpolated values */
 			  double c1min, double c1max, double c2min, double c2max, double gmin, double gmax, double ertot,	/* total interplating func. error */
@@ -46,9 +63,9 @@
     float dat1, dat2;
     struct Colors colors, colors2;
     double value1, value2;
-    struct History hist, hist1, hist2, hist3, hist4, hist5;
+    struct History hist;
     struct _Color_Rule_ *rule;
-    const char *maps, *type;
+    const char *maps;
     int cond1, cond2;
     CELL val1, val2;
     
@@ -282,16 +299,7 @@
 	    Rast_write_colors(params->slope, maps, &colors);
 	    Rast_quantize_fp_map_range(params->slope, mapset, 0., 90., 0, 90);
 
-	    type = "raster";
-	    Rast_short_history(params->slope, type, &hist1);
-	    if (params->elev != NULL)
-		sprintf(hist1.edhist[0], "The elevation map is %s",
-			params->elev);
-
-	    sprintf(hist1.datsrc_1, "raster map %s", input);
-	    hist1.edlinecnt = 1;
-
-	    Rast_write_history(params->slope, &hist1);
+	    do_history(params->slope, input, params);
 	}
 
 	/* colortable for aspect */
@@ -322,16 +330,7 @@
 	    Rast_write_colors(params->aspect, maps, &colors);
 	    Rast_quantize_fp_map_range(params->aspect, mapset, 0., 360., 0, 360);
 
-	    type = "raster";
-	    Rast_short_history(params->aspect, type, &hist2);
-	    if (params->elev != NULL)
-		sprintf(hist2.edhist[0], "The elevation map is %s",
-			params->elev);
-
-	    sprintf(hist2.datsrc_1, "raster map %s", input);
-	    hist2.edlinecnt = 1;
-
-	    Rast_write_history(params->aspect, &hist2);
+	    do_history(params->aspect, input, params);
 	}
 
 	/* colortable for curvatures */
@@ -386,16 +385,7 @@
 					dat1, dat2,
 					(CELL) (dat1 * MULT),
 					(CELL) (dat2 * MULT));
-		type = "raster";
-		Rast_short_history(params->pcurv, type, &hist3);
-		if (params->elev != NULL)
-		    sprintf(hist3.edhist[0], "The elevation map is %s",
-			    params->elev);
-
-		sprintf(hist3.datsrc_1, "raster map %s", input);
-		hist3.edlinecnt = 1;
-
-		Rast_write_history(params->pcurv, &hist3);
+		do_history(params->pcurv, input, params);
 	    }
 
 	    if (params->tcurv != NULL) {
@@ -410,16 +400,7 @@
 					dat1, dat2, (CELL) (dat1 * MULT),
 					(CELL) (dat2 * MULT));
 
-		type = "raster";
-		Rast_short_history(params->tcurv, type, &hist4);
-		if (params->elev != NULL)
-		    sprintf(hist4.edhist[0], "The elevation map is %s",
-			    params->elev);
-
-		sprintf(hist4.datsrc_1, "raster map %s", input);
-		hist4.edlinecnt = 1;
-
-		Rast_write_history(params->tcurv, &hist4);
+		do_history(params->tcurv, input, params);
 	    }
 
 	    if (params->mcurv != NULL) {
@@ -435,45 +416,42 @@
 					(CELL) (dat1 * MULT),
 					(CELL) (dat2 * MULT));
 
-		type = "raster";
-		Rast_short_history(params->mcurv, type, &hist5);
-		if (params->elev != NULL)
-		    sprintf(hist5.edhist[0], "The elevation map is %s",
-			    params->elev);
-
-		sprintf(hist5.datsrc_1, "raster map %s", input);
-		hist5.edlinecnt = 1;
-
-		Rast_write_history(params->mcurv, &hist5);
+		do_history(params->mcurv, input, params);
 	    }
 	}
     }
 
     if (params->elev != NULL) {
-	maps = G_find_file("cell", params->elev, "");
-	if (maps == NULL) {
+	if (!G_find_file2("cell", params->elev, "")) {
 	    G_warning(_("Raster map <%s> not found"), params->elev);
 	    return -1;
 	}
+
 	Rast_short_history(params->elev, "raster", &hist);
 
 	if (smooth != NULL)
-	    sprintf(hist.edhist[0], "tension=%f, smoothing=%s",
-		    params->fi * 1000. / (*dnorm), smooth);
+	    Rast_append_format_history(
+		&hist, "tension=%f, smoothing=%s",
+		params->fi * 1000. / (*dnorm), smooth);
 	else
-	    sprintf(hist.edhist[0], "tension=%f",
-		    params->fi * 1000. / (*dnorm));
-	sprintf(hist.edhist[1], "dnorm=%f, zmult=%f", *dnorm, params->zmult);
-	sprintf(hist.edhist[2], "KMAX=%d, KMIN=%d, errtotal=%f", params->kmax,
-		params->kmin, sqrt(ertot / n_points));
-	sprintf(hist.edhist[3], "zmin_data=%f, zmax_data=%f", zmin, zmax);
-	sprintf(hist.edhist[4], "zmin_int=%f, zmax_int=%f", zminac, zmaxac);
+	    Rast_append_format_history(
+		&hist, "tension=%f", params->fi * 1000. / (*dnorm));
 
-	sprintf(hist.datsrc_1, "raster map %s", input);
+	Rast_append_format_history(
+	    &hist, "dnorm=%f, zmult=%f", *dnorm, params->zmult);
+	Rast_append_format_history(
+	    &hist, "KMAX=%d, KMIN=%d, errtotal=%f", params->kmax,
+	    params->kmin, sqrt(ertot / n_points));
+	Rast_append_format_history(
+	    &hist, "zmin_data=%f, zmax_data=%f", zmin, zmax);
+	Rast_append_format_history(
+	    &hist, "zmin_int=%f, zmax_int=%f", zminac, zmaxac);
 
-	hist.edlinecnt = 5;
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster map %s", input);
 
 	Rast_write_history(params->elev, &hist);
+
+	Rast_free_history(&hist);
     }
 
 /* change region to initial region */

Modified: grass/trunk/raster/r.buffer/main.c
===================================================================
--- grass/trunk/raster/r.buffer/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.buffer/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -163,12 +163,9 @@
 
     /* write map history (meta data) */
     Rast_short_history(output, "raster", &hist);
-    sprintf(hist.datsrc_1, "%s", input);
-    if (strlen(opt3->answer) < (RECORD_LEN - 14)) {
-	sprintf(hist.edhist[0], "Buffer distance%s:", ndist > 1 ? "s" : "");
-	sprintf(hist.edhist[1], " %s %s", opt3->answer, units);
-	hist.edlinecnt = 2;
-    }
+    Rast_set_history(&hist, HIST_DATSRC_1, input);
+    Rast_append_format_history(&hist, "Buffer distance%s:", ndist > 1 ? "s" : "");
+    Rast_append_format_history(&hist, " %s %s", opt3->answer, units);
     Rast_command_history(&hist);
     Rast_write_history(output, &hist);
 

Modified: grass/trunk/raster/r.carve/support.c
===================================================================
--- grass/trunk/raster/r.carve/support.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.carve/support.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -35,11 +35,10 @@
 
     /* write command line to history */
     Rast_short_history(parm->outrast->answer, "raster", &hist);
-    sprintf(hist.edhist[0], "%s version %.2f", G_program_name(), APP_VERSION);
-    sprintf(hist.edhist[1], "stream width: %.2f", parm->swidth * 2);
-    sprintf(hist.datsrc_1, "raster elevation file: %s", parm->inrast->answer);
-    sprintf(hist.datsrc_2, "vector stream file: %s", parm->invect->answer);
-    hist.edlinecnt = 2;
+    Rast_append_format_history(&hist, "%s version %.2f", G_program_name(), APP_VERSION);
+    Rast_append_format_history(&hist, "stream width: %.2f", parm->swidth * 2);
+    Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file: %s", parm->inrast->answer);
+    Rast_format_history(&hist, HIST_DATSRC_2, "vector stream file: %s", parm->invect->answer);
     Rast_command_history(&hist);
     Rast_write_history(parm->outrast->answer, &hist);
 }

Modified: grass/trunk/raster/r.horizon/main.c
===================================================================
--- grass/trunk/raster/r.horizon/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.horizon/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -1243,14 +1243,12 @@
 	    Rast_command_history(&history);
 
 	    /* insert a blank line */
-	    history.edhist[history.edlinecnt][0] = '\0';
-	    history.edlinecnt++;
+	    Rast_append_history(&history, "");
 
-	    sprintf(msg_buff,
-		    "Horizon view from azimuth angle %.2f degrees CCW from East",
-		    angle * rad2deg);
-	    strcpy(history.edhist[history.edlinecnt], msg_buff);
-	    history.edlinecnt++;
+	    Rast_append_format_history(
+		&history,
+		"Horizon view from azimuth angle %.2f degrees CCW from East",
+		angle * rad2deg);
 
 	    Rast_write_history(shad_filename, &history);
 	}

Modified: grass/trunk/raster/r.in.xyz/main.c
===================================================================
--- grass/trunk/raster/r.in.xyz/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.in.xyz/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -1052,8 +1052,7 @@
 
     Rast_short_history(outmap, "raster", &history);
     Rast_command_history(&history);
-    strncpy(history.datsrc_1, infile, RECORD_LEN);
-    history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+    Rast_set_history(&history, HIST_DATSRC_1, infile);
     Rast_write_history(outmap, &history);
 
 

Modified: grass/trunk/raster/r.info/main.c
===================================================================
--- grass/trunk/raster/r.info/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.info/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -151,14 +151,14 @@
 	divider('+');
 
 	compose_line(out, "Layer:    %-29.29s  Date: %s", name,
-		     hist_ok ? hist.mapid : "??");
+		     hist_ok ? Rast_get_history(&hist, HIST_MAPID) : "??");
 	compose_line(out, "Mapset:   %-29.29s  Login of Creator: %s",
-		     mapset, hist_ok ? hist.creator : "??");
+		     mapset, hist_ok ? Rast_get_history(&hist, HIST_CREATOR) : "??");
 	compose_line(out, "Location: %s", G_location());
 	compose_line(out, "DataBase: %s", G_gisdbase());
 	compose_line(out, "Title:    %s ( %s )",
 		     cats_ok ? cats.title : "??",
-		     hist_ok ? hist.title : "??");
+		     hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??");
 
 	/*This shows the TimeStamp */
 	if (time_ok && (first_time_ok || second_time_ok)) {
@@ -177,7 +177,7 @@
 
 	compose_line(out,
 		     "  Type of Map:  %-20.20s Number of Categories: %-9s",
-		     hist_ok ? hist.maptype : "??", cats_ok ? tmp1 : "??");
+		     hist_ok ? Rast_get_history(&hist, HIST_MAPTYPE) : "??", cats_ok ? tmp1 : "??");
 
 	compose_line(out, "  Data Type:    %s",
 		     (data_type == CELL_TYPE ? "CELL" :
@@ -249,23 +249,23 @@
 	printline("");
 
 	if (hist_ok) {
-	    if (hist.datsrc_1[0] != '\0' || hist.datsrc_2[0] != '\0') {
+	    if (Rast_get_history(&hist, HIST_DATSRC_1)[0] != '\0' ||
+		Rast_get_history(&hist, HIST_DATSRC_2)[0] != '\0') {
 		printline("  Data Source:");
-		compose_line(out, "   %s", hist.datsrc_1);
-		compose_line(out, "   %s", hist.datsrc_2);
+		compose_line(out, "   %s", Rast_get_history(&hist, HIST_DATSRC_1));
+		compose_line(out, "   %s", Rast_get_history(&hist, HIST_DATSRC_2));
 		printline("");
 	    }
 
 	    printline("  Data Description:");
-	    compose_line(out, "   %s", hist.keywrd);
+	    compose_line(out, "   %s", Rast_get_history(&hist, HIST_KEYWRD));
 
 	    printline("");
-	    if (hist.edlinecnt) {
+	    if (Rast_history_length(&hist)) {
 		printline("  Comments:  ");
 
-		for (i = 0; i < hist.edlinecnt; i++) {
-		    compose_line(out, "   %s", hist.edhist[i]);
-		}
+		for (i = 0; i < Rast_history_length(&hist); i++)
+		    compose_line(out, "   %s", Rast_history_line(&hist, i));
 	    }
 
 	    printline("");
@@ -373,7 +373,7 @@
 
 	if (mflag->answer) {
 	    fprintf(out, "title=%s (%s)\n", cats_ok ? cats.title :
-		    "??", hist_ok ? hist.title : "??");
+		    "??", hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??");
 	}
 
 	if (timestampflag->answer) {
@@ -398,14 +398,14 @@
 	if (hflag->answer) {
 	    if (hist_ok) {
 		fprintf(out, "Data Source:\n");
-		fprintf(out, "   %s\n", hist.datsrc_1);
-		fprintf(out, "   %s\n", hist.datsrc_2);
+		fprintf(out, "   %s\n", Rast_get_history(&hist, HIST_DATSRC_1));
+		fprintf(out, "   %s\n", Rast_get_history(&hist, HIST_DATSRC_2));
 		fprintf(out, "Data Description:\n");
-		fprintf(out, "   %s\n", hist.keywrd);
-		if (hist.edlinecnt) {
+		fprintf(out, "   %s\n", Rast_get_history(&hist, HIST_KEYWRD));
+		if (Rast_history_length(&hist)) {
 		    fprintf(out, "Comments:\n");
-		    for (i = 0; i < hist.edlinecnt; i++)
-			fprintf(out, "   %s\n", hist.edhist[i]);
+		    for (i = 0; i < Rast_history_length(&hist); i++)
+			fprintf(out, "   %s\n", Rast_history_line(&hist, i));
 		}
 	    }
 	}

Modified: grass/trunk/raster/r.mapcalc/map.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.mapcalc/map.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -707,16 +707,18 @@
 
 void create_history(const char *dst, expression * e)
 {
-    static int WIDTH = RECORD_LEN - 12;
+    int RECORD_LEN = 80;
+    int WIDTH = RECORD_LEN - 12;
     struct History hist;
     char *expr = format_expression(e);
     char *p = expr;
     int len = strlen(expr);
     int i;
 
-    Rast_short_history((char *)dst, "raster", &hist);
+    Rast_short_history(dst, "raster", &hist);
 
-    for (i = 0; i < MAXEDLINES; i++) {
+    for (i = 0; ; i++) {
+	char buf[RECORD_LEN];
 	int n;
 
 	if (!len)
@@ -733,17 +735,16 @@
 	else
 	    n = len;
 
-	memcpy(hist.edhist[i], p, n);
-	hist.edhist[i][n] = '\0';
+	memcpy(buf, p, n);
+	buf[n] = '\0';
+	Rast_append_history(&hist, buf);
 
 	p += n;
 	len -= n;
     }
 
-    hist.edlinecnt = i;
+    Rast_write_history(dst, &hist);
 
-    Rast_write_history((char *)dst, &hist);
-
     G_free(expr);
 }
 

Modified: grass/trunk/raster/r.param.scale/close_down.c
===================================================================
--- grass/trunk/raster/r.param.scale/close_down.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.param.scale/close_down.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -15,7 +15,7 @@
 void close_down(void)
 {
     struct History history;
-    char map_title[RECORD_LEN], map_type[32];
+    char map_title[80], map_type[32];
 
     /* Close connection with existing input raster. */
     Rast_unopen(fd_in);
@@ -26,8 +26,7 @@
     /* write out map metadata */
     Rast_short_history(rast_out_name, "raster", &history);
 
-    strncpy(history.datsrc_1, rast_in_name, RECORD_LEN-1);
-    history.datsrc_1[RECORD_LEN-1] = '\0';
+    Rast_set_history(&history, HIST_DATSRC_1, rast_in_name);
 
     switch (mparam) {
 
@@ -39,78 +38,85 @@
 	strcpy(map_type, "Magnitude of maximum gradient");
 	Rast_write_units(rast_out_name, "degrees");
 
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Slope is given for steepest slope angle and measured in degrees.");
-	history.edlinecnt = 1;
 	break;
 
     case ASPECT:
 	strcpy(map_type, "Direction of maximum gradient");
 	Rast_write_units(rast_out_name, "degrees");
 
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Flow direction (aspect): W=0, E=180, N=+90, S=-90 degrees");
-	history.edlinecnt = 1;
 	break;
 
     case PROFC:
 	strcpy(map_type, "Profile curvature");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Curvature intersecting with the plane defined by the Z axis and");
-	strcpy(history.edhist[1],
+	Rast_append_history(
+	    &history,
 	    "maximum gradient direction. Positive values describe convex profile");
-	strcpy(history.edhist[2], "curvature, negative values concave profile.");
-	history.edlinecnt = 3;
+	Rast_append_history(
+	    &history,
+	    "curvature, negative values concave profile.");
 	break;
 
     case PLANC:
 	strcpy(map_type, "Plan curvature");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Plan curvature is the horizontal curvature, intersecting with");
-	strcpy(history.edhist[1],
+	Rast_append_history(
+	    &history,
 	    "the XY plane.");
-	history.edlinecnt = 2;
 	break;
 
     case LONGC:
 	strcpy(map_type, "Longitudinal curvature");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Longitudinal curvature is the profile curvature intersecting with the");
-	strcpy(history.edhist[1],
+	Rast_append_history(
+	    &history,
 	    "plane defined by the surfacenormal and maximum gradient direction.");
-	history.edlinecnt = 2;
 	break;
 
     case CROSC:
 	strcpy(map_type, "Cross-sectional curvature");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Cross-sectional curvature is the tangential curvature intersecting");
-	strcpy(history.edhist[1],
+	Rast_append_history(
+	    &history,
 	    "with the plane defined by the surface normal and a tangent to the");
-	strcpy(history.edhist[2],
+	Rast_append_history(
+	    &history,
 	    "contour - perpendicular to maximum gradient direction.");
-	history.edlinecnt = 3;
 	break;
 
     case MINIC:
 	strcpy(map_type, "Minimum curvature");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Measured in direction perpendicular to the direction of of maximum curvature.");
-	history.edlinecnt = 1;
 	break;
 
     case MAXIC:
 	strcpy(map_type, "Maximum curvature");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "The maximum curvature is measured in any direction");
-	history.edlinecnt = 1;
 	break;
 
     case FEATURE:
 	strcpy(map_type, "Morphometric features");
-	strcpy(history.edhist[0],
+	Rast_append_history(
+	    &history,
 	    "Morphometric features: peaks, ridges, passes, channels, pits and planes");
-	history.edlinecnt = 1;
 	break;
 
     default:

Modified: grass/trunk/raster/r.random/support.c
===================================================================
--- grass/trunk/raster/r.random/support.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.random/support.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -38,15 +38,17 @@
     /* write history for output raster */
     if (Rast_read_history(theState->outraster, G_mapset(), &hist) >= 0) {
 	Rast_short_history(theState->outraster, "raster", &hist);
-	sprintf(hist.datsrc_1, "Based on map <%s>", inraster);
+	Rast_format_history(&hist, HIST_DATSRC_1, "Based on map <%s>", inraster);
 	if (percent)
-	    sprintf(hist.datsrc_2,
-		    "Random points over %.2f percent of the base map <%s>",
-		    percentage, inraster);
+	    Rast_format_history(
+		&hist, HIST_DATSRC_2,
+		"Random points over %.2f percent of the base map <%s>",
+		percentage, inraster);
 	else
-	    sprintf(hist.datsrc_2,
-		    "%ld random points on the base map <%s>",
-		    theState->nRand, theState->inraster);
+	    Rast_format_history(
+		&hist, HIST_DATSRC_2,
+		"%ld random points on the base map <%s>",
+		theState->nRand, theState->inraster);
 	Rast_write_history(theState->outraster, &hist);
 
     }

Modified: grass/trunk/raster/r.reclass/reclass.c
===================================================================
--- grass/trunk/raster/r.reclass/reclass.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.reclass/reclass.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -246,8 +246,9 @@
     Rast_free_cats(cats);
 
     Rast_short_history(new_name, "reclass", &hist);
-    strcpy(hist.datsrc_1, "Reclassified map based on:");
-    sprintf(hist.datsrc_2, "  Map [%s] in mapset [%s]", new.name, new.mapset);
+    Rast_set_history(&hist, HIST_DATSRC_1, "Reclassified map based on:");
+    Rast_format_history(&hist, HIST_DATSRC_2, "  Map [%s] in mapset [%s]",
+			new.name, new.mapset);
     Rast_write_history(new_name, &hist);
 
     new_range(new_name, &new);

Modified: grass/trunk/raster/r.recode/recode.c
===================================================================
--- grass/trunk/raster/r.recode/recode.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.recode/recode.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -57,18 +57,14 @@
 
     /* writing history file */
     Rast_short_history(result, "raster", &hist);
-    sprintf(hist.edhist[0], "recode of raster map %s", name);
+    Rast_append_format_history(&hist, "recode of raster map %s", name);
     /* if there are more rules than history lines allocated, write only 
        MAXEDLINES-1 rules , and "...." as a last rule */
-    for (i = 0; (i < nrules) && (i < MAXEDLINES - 2); i++)
-	sprintf(hist.edhist[i + 1], "%s", rules[i]);
-    if (nrules > MAXEDLINES - 1) {
-	sprintf(hist.edhist[MAXEDLINES - 1], "...");
-	hist.edlinecnt = MAXEDLINES;
-    }
-    else
-	hist.edlinecnt = nrules + 1;
-    sprintf(hist.datsrc_1, "raster map %s", name);
+    for (i = 0; i < nrules && i < 50; i++)
+	Rast_append_history(&hist, rules[i]);
+    if (nrules > 50)
+	Rast_append_history(&hist, "...");
+    Rast_format_history(&hist, HIST_DATSRC_1, "raster map %s", name);
     Rast_write_history(result, &hist);
 
     return 0;

Modified: grass/trunk/raster/r.resamp.filter/main.c
===================================================================
--- grass/trunk/raster/r.resamp.filter/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.resamp.filter/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -541,12 +541,12 @@
 	char buf_nsres[100], buf_ewres[100];
 
 	Rast_short_history(parm.rastout->answer, "raster", &history);
-	strncpy(history.datsrc_1, parm.rastin->answer, RECORD_LEN);
-	history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+	Rast_set_history(&history, HIST_DATSRC_1, parm.rastin->answer);
 	G_format_resolution(src_w.ns_res, buf_nsres, src_w.proj);
 	G_format_resolution(src_w.ew_res, buf_ewres, src_w.proj);
-	sprintf(history.datsrc_2, "Source map NS res: %s   EW res: %s", buf_nsres,
-		buf_ewres);
+	Rast_format_history(&history, HIST_DATSRC_2,
+			    "Source map NS res: %s   EW res: %s",
+			    buf_nsres, buf_ewres);
 	Rast_command_history(&history);
 	Rast_write_history(parm.rastout->answer, &history);
     }

Modified: grass/trunk/raster/r.resamp.interp/main.c
===================================================================
--- grass/trunk/raster/r.resamp.interp/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.resamp.interp/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -299,12 +299,12 @@
     Rast_put_cell_title(rastout->answer, title);
 
     Rast_short_history(rastout->answer, "raster", &history);
-    strncpy(history.datsrc_1, rastin->answer, RECORD_LEN);
-    history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+    Rast_set_history(&history, HIST_DATSRC_1, rastin->answer);
     G_format_resolution(src_w.ns_res, buf_nsres, src_w.proj);
     G_format_resolution(src_w.ew_res, buf_ewres, src_w.proj);
-    sprintf(history.datsrc_2, "Source map NS res: %s   EW res: %s", buf_nsres,
-	    buf_ewres);
+    Rast_format_history(&history, HIST_DATSRC_2,
+			"Source map NS res: %s   EW res: %s",
+			buf_nsres, buf_ewres);
     Rast_command_history(&history);
     Rast_write_history(rastout->answer, &history);
 

Modified: grass/trunk/raster/r.resamp.stats/main.c
===================================================================
--- grass/trunk/raster/r.resamp.stats/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.resamp.stats/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -366,12 +366,12 @@
     Rast_put_cell_title(parm.rastout->answer, title);
 
     Rast_short_history(parm.rastout->answer, "raster", &history);
-    strncpy(history.datsrc_1, parm.rastin->answer, RECORD_LEN);
-    history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+    Rast_set_history(&history, HIST_DATSRC_1, parm.rastin->answer);
     G_format_resolution(src_w.ns_res, buf_nsres, src_w.proj);
     G_format_resolution(src_w.ew_res, buf_ewres, src_w.proj);
-    sprintf(history.datsrc_2, "Source map NS res: %s   EW res: %s", buf_nsres,
-	    buf_ewres);
+    Rast_format_history(&history, HIST_DATSRC_2,
+			"Source map NS res: %s   EW res: %s",
+			buf_nsres, buf_ewres);
     Rast_command_history(&history);
     Rast_write_history(parm.rastout->answer, &history);
 

Modified: grass/trunk/raster/r.slope.aspect/main.c
===================================================================
--- grass/trunk/raster/r.slope.aspect/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.slope.aspect/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -1041,11 +1041,10 @@
 
 	/* writing history file */
 	Rast_short_history(aspect_name, "raster", &hist);
-	sprintf(hist.edhist[0], "aspect map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "aspect map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(aspect_name, &hist);
 
 	G_message(_("Aspect raster map <%s> complete"), aspect_name);
@@ -1150,12 +1149,11 @@
 
 	/* writing history file */
 	Rast_short_history(slope_name, "raster", &hist);
-	sprintf(hist.edhist[0], "slope map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f format = %s", zfactor,
+	Rast_append_format_history(&hist, "slope map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f format = %s", zfactor,
 		parm.slope_fmt->answer);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(slope_name, &hist);
 
 	G_message(_("Slope raster map <%s> complete"), slope_name);
@@ -1223,11 +1221,10 @@
 
 	/* writing history file */
 	Rast_short_history(pcurv_name, "raster", &hist);
-	sprintf(hist.edhist[0], "profile curve map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "profile curve map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(pcurv_name, &hist);
 
 	G_message(_("Profile curve raster map <%s> complete"), pcurv_name);
@@ -1250,11 +1247,10 @@
 
 	/* writing history file */
 	Rast_short_history(tcurv_name, "raster", &hist);
-	sprintf(hist.edhist[0], "tangential curve map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "tangential curve map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(tcurv_name, &hist);
 
 	G_message(_("Tangential curve raster map <%s> complete"), tcurv_name);
@@ -1275,11 +1271,10 @@
 
 	/* writing history file */
 	Rast_short_history(dx_name, "raster", &hist);
-	sprintf(hist.edhist[0], "E-W slope map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "E-W slope map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(dx_name, &hist);
 
 	G_message(_("E-W slope raster map <%s> complete"), dx_name);
@@ -1300,11 +1295,10 @@
 
 	/* writing history file */
 	Rast_short_history(dy_name, "raster", &hist);
-	sprintf(hist.edhist[0], "N-S slope map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "N-S slope map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(dy_name, &hist);
 
 	G_message(_("N-S slope raster map <%s> complete"), dy_name);
@@ -1325,11 +1319,10 @@
 
 	/* writing history file */
 	Rast_short_history(dxx_name, "raster", &hist);
-	sprintf(hist.edhist[0], "DXX map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "DXX map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(dxx_name, &hist);
 
 	G_message(_("Dxx raster map <%s> complete"), dxx_name);
@@ -1350,11 +1343,10 @@
 
 	/* writing history file */
 	Rast_short_history(dyy_name, "raster", &hist);
-	sprintf(hist.edhist[0], "DYY map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "DYY map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(dyy_name, &hist);
 
 	G_message(_("Dyy raster map <%s> complete"), dyy_name);
@@ -1375,11 +1367,10 @@
 
 	/* writing history file */
 	Rast_short_history(dxy_name, "raster", &hist);
-	sprintf(hist.edhist[0], "DXY map elev = %s", elev_name);
-	sprintf(hist.edhist[1], "zfactor = %.2f", zfactor);
-	sprintf(hist.edhist[2], "min_slp_allowed = %f", min_slp_allowed);
-	sprintf(hist.datsrc_1, "raster elevation file %s", elev_name);
-	hist.edlinecnt = 3;
+	Rast_append_format_history(&hist, "DXY map elev = %s", elev_name);
+	Rast_append_format_history(&hist, "zfactor = %.2f", zfactor);
+	Rast_append_format_history(&hist, "min_slp_allowed = %f", min_slp_allowed);
+	Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", elev_name);
 	Rast_write_history(dxy_name, &hist);
 
 	G_message(_("Dxy raster map <%s> complete"), dxy_name);

Modified: grass/trunk/raster/r.sun/main.c
===================================================================
--- grass/trunk/raster/r.sun/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.sun/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -1938,88 +1938,99 @@
 	G_fatal_error
 	    ("Failed to init map history: no output maps requested!");
 
-    sprintf(hist.edhist[0],
-	    " ----------------------------------------------------------------");
-    sprintf(hist.edhist[1], " Day [1-365]:                              %d",
-	    day);
-    hist.edlinecnt = 2;
+    Rast_append_format_history(
+	&hist,
+	" ----------------------------------------------------------------");
+    Rast_append_format_history(
+	&hist,
+	" Day [1-365]:                              %d",
+	day);
 
-    if (ttime != NULL) {
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Local (solar) time (decimal hr.):         %.4f", timo);
-	hist.edlinecnt++;
-    }
+    if (ttime != NULL)
+	Rast_append_format_history(
+	    &hist,
+	    " Local (solar) time (decimal hr.):         %.4f", timo);
 
-    sprintf(hist.edhist[hist.edlinecnt],
-	    " Solar constant (W/m^2):                   1367");
-    sprintf(hist.edhist[hist.edlinecnt + 1],
-	    " Extraterrestrial irradiance (W/m^2):      %f",
-	    sunRadVar.G_norm_extra);
-    sprintf(hist.edhist[hist.edlinecnt + 2],
-	    " Declination (rad):                        %f", -declination);
-    hist.edlinecnt += 3;
+    Rast_append_format_history(
+	&hist,
+	" Solar constant (W/m^2):                   1367");
+    Rast_append_format_history(
+	&hist,
+	" Extraterrestrial irradiance (W/m^2):      %f",
+	sunRadVar.G_norm_extra);
+    Rast_append_format_history(
+	&hist,
+	" Declination (rad):                        %f", -declination);
 
-    sprintf(hist.edhist[hist.edlinecnt],
-	    " Latitude min-max(deg):                    %.4f - %.4f",
-	    lat_min, lat_max);
-    hist.edlinecnt++;
+    Rast_append_format_history(
+	&hist,
+	" Latitude min-max(deg):                    %.4f - %.4f",
+	lat_min, lat_max);
 
     if (ttime != NULL) {
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Sunrise time (hr.):                       %.2f",
-		sunGeom.sunrise_time);
-	sprintf(hist.edhist[hist.edlinecnt + 1],
-		" Sunset time (hr.):                        %.2f",
-		sunGeom.sunset_time);
-	sprintf(hist.edhist[hist.edlinecnt + 2],
-		" Daylight time (hr.):                      %.2f",
-		sunGeom.sunset_time - sunGeom.sunrise_time);
+	Rast_append_format_history(
+	    &hist,
+	    " Sunrise time (hr.):                       %.2f",
+	    sunGeom.sunrise_time);
+	Rast_append_format_history(
+	    &hist,
+	    " Sunset time (hr.):                        %.2f",
+	    sunGeom.sunset_time);
+	Rast_append_format_history(
+	    &hist,
+	    " Daylight time (hr.):                      %.2f",
+	    sunGeom.sunset_time - sunGeom.sunrise_time);
     }
     else {
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Sunrise time min-max (hr.):               %.2f - %.2f",
-		sunrise_min, sunrise_max);
-	sprintf(hist.edhist[hist.edlinecnt + 1],
-		" Sunset time min-max (hr.):                %.2f - %.2f",
-		sunset_min, sunset_max);
-	sprintf(hist.edhist[hist.edlinecnt + 2],
-		" Time step (hr.):                          %.4f", step);
+	Rast_append_format_history(
+	    &hist,
+	    " Sunrise time min-max (hr.):               %.2f - %.2f",
+	    sunrise_min, sunrise_max);
+	Rast_append_format_history(
+	    &hist,
+	    " Sunset time min-max (hr.):                %.2f - %.2f",
+	    sunset_min, sunset_max);
+	Rast_append_format_history(
+	    &hist,
+	    " Time step (hr.):                          %.4f", step);
     }
-    hist.edlinecnt += 3;
 
     if (incidout != NULL || ttime != NULL) {
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Solar altitude (deg):                     %.4f",
-		sunVarGeom.solarAltitude * rad2deg);
-	sprintf(hist.edhist[hist.edlinecnt + 1],
-		" Solar azimuth (deg):                      %.4f",
-		sunVarGeom.solarAzimuth * rad2deg);
-	hist.edlinecnt += 2;
+	Rast_append_format_history(
+	    &hist,
+	    " Solar altitude (deg):                     %.4f",
+	    sunVarGeom.solarAltitude * rad2deg);
+	Rast_append_format_history(
+	    &hist,
+	    " Solar azimuth (deg):                      %.4f",
+	    sunVarGeom.solarAzimuth * rad2deg);
     }
 
     if (linkein == NULL)
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Linke turbidity factor:                   %.1f",
-		sunRadVar.linke);
+	Rast_append_format_history(
+	    &hist,
+	    " Linke turbidity factor:                   %.1f",
+	    sunRadVar.linke);
     else
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Linke turbidity factor min-max:           %.1f-%.1f",
-		linke_min, linke_max);
-    hist.edlinecnt++;
+	Rast_append_format_history(
+	    &hist,
+	    " Linke turbidity factor min-max:           %.1f-%.1f",
+	    linke_min, linke_max);
 
     if (albedo == NULL)
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Ground albedo:                            %.3f",
-		sunRadVar.alb);
+	Rast_append_format_history(
+	    &hist,
+	    " Ground albedo:                            %.3f",
+	    sunRadVar.alb);
     else
-	sprintf(hist.edhist[hist.edlinecnt],
-		" Ground albedo min-max:                    %.3f-%.3f",
-		albedo_min, albedo_max);
-    hist.edlinecnt++;
+	Rast_append_format_history(
+	    &hist,
+	    " Ground albedo min-max:                    %.3f-%.3f",
+	    albedo_min, albedo_max);
 
-    sprintf(hist.edhist[hist.edlinecnt],
-	    " -----------------------------------------------------------------");
-    hist.edlinecnt++;
+    Rast_append_format_history(
+	&hist,
+	" -----------------------------------------------------------------");
 
     Rast_command_history(&hist);
     /* don't call Rast_write_history() until after Rast_close() or it just gets overwritten */

Modified: grass/trunk/raster/r.sunmask/main.c
===================================================================
--- grass/trunk/raster/r.sunmask/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.sunmask/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -530,11 +530,9 @@
 
     /* writing history file */
     Rast_short_history(outname, "raster", &hist);
-    sprintf(hist.edhist[0], "%s", *argv);
-    sprintf(hist.datsrc_1, "raster elevation file %s", name);
-    /* bug: long lines are truncated */
-    sprintf(hist.datsrc_2, "%s", G_recreate_command());
-    hist.edlinecnt = 3;
+    Rast_append_history(&hist, argv[0]);
+    Rast_format_history(&hist, HIST_DATSRC_1, "raster elevation file %s", name);
+    Rast_set_history(&hist, HIST_DATSRC_2, G_recreate_command());
     Rast_write_history(outname, &hist);
 
     G_done_msg(" ");

Modified: grass/trunk/raster/r.support/main.c
===================================================================
--- grass/trunk/raster/r.support/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.support/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -45,7 +45,7 @@
     struct Flag *stats_flag, *null_flag, *del_flag;
     int is_reclass;		/* Is raster reclass? */
     const char *infile;
-    char title[MAX_TITLE_LEN + 1], datasrc[RECORD_LEN + 1];
+    char title[MAX_TITLE_LEN + 1];
     struct History hist;
 
     /* Initialize GIS engine */
@@ -167,75 +167,54 @@
 
 	Rast_read_history(raster->answer, "", &hist);
 
-	for (i = 0; i < hist.edlinecnt; i++)
-	    fprintf(fp, "%s\n", hist.edhist[i]);
+	for (i = 0; i < Rast_history_length(&hist); i++)
+	    fprintf(fp, "%s\n", Rast_history_line(&hist, i));
 
 	fclose(fp);
     }
 
     if (load_opt->answer) {
 	FILE *fp = fopen(load_opt->answer, "r");
-	int i;
 
 	if (!fp)
 	    G_fatal_error(_("Unable to open input file <%s>"), load_opt->answer);
 
 	Rast_read_history(raster->answer, "", &hist);
 
-	for (i = 0; ; i++) {
-	    if (i >= MAXEDLINES) {
-		G_warning(_("Not enough room in history file"));
+	Rast_clear_history(&hist);
+
+	for (;;) {
+	    char buf[80];
+	    if (!G_getl2(buf, sizeof(buf), fp))
 		break;
-	    }
-	    if (!G_getl2(hist.edhist[i], RECORD_LEN - 2, fp))
-		break;
+	    Rast_append_history(&hist, buf);
 	}
 
 	fclose(fp);
 
-	hist.edlinecnt = i;
-
 	Rast_write_history(raster->answer, &hist);
     }
 
     if (history_opt->answer) {
 	Rast_read_history(raster->answer, "", &hist);
 
-	if (hist.edlinecnt >= MAXEDLINES)
-	    G_fatal_error(_("Not enough room in history file"));
-
 	/* two less than defined as if only one less a newline gets appended in the hist file. bug? */
 	/* Should be RECORD_LEN, but r.info truncates at > 71 chars */
 	if (strlen(history_opt->answer) > 71) {
 	    int i;
 
 	    for (i = 0; i < strlen(history_opt->answer); i += 71) {
-		char *tmp = &history_opt->answer[i];
+		char buf[72];
 
-		strncpy(hist.edhist[hist.edlinecnt], tmp, 71);
+		strncpy(buf, &history_opt->answer[i], sizeof(buf)-1);
+		buf[sizeof(buf)-1] = '\0';
 
-		/* strncpy doesn't null terminate oversized input */
-		hist.edhist[hist.edlinecnt][RECORD_LEN - 2] = '\0';
-		hist.edlinecnt++;
-
-		G_debug(3, "new history line= [%s] (%d chars)",
-			hist.edhist[hist.edlinecnt],
-			strlen(hist.edhist[hist.edlinecnt]));
+		Rast_append_history(&hist, buf);
 	    }
 	}
-	else {
-	    strncpy(hist.edhist[hist.edlinecnt], history_opt->answer,
-		    RECORD_LEN - 2);
+	else
+	    Rast_append_history(&hist, history_opt->answer);
 
-	    /* strncpy doesn't null terminate oversized input */
-	    hist.edhist[hist.edlinecnt][RECORD_LEN - 2] = '\0';
-	    hist.edlinecnt++;
-
-	    G_debug(3, "new history line= [%s] (%d chars)",
-		    hist.edhist[hist.edlinecnt],
-		    strlen(hist.edhist[hist.edlinecnt]));
-	}
-
 	Rast_write_history(raster->answer, &hist);
     }
 
@@ -248,32 +227,15 @@
     if (datasrc1_opt->answer || datasrc2_opt->answer || datadesc_opt->answer) {
 	Rast_read_history(raster->answer, "", &hist);
 
-	if (datasrc1_opt->answer) {
-	    strncpy(datasrc, datasrc1_opt->answer, RECORD_LEN);
-	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	    G_strip(datasrc);
-	    G_debug(3, "map datasrc1= [%s]  (%d chars)", datasrc,
-		    strlen(datasrc));
-	    strncpy(hist.datsrc_1, datasrc, RECORD_LEN);
-	}
-	if (datasrc2_opt->answer) {
-	    strncpy(datasrc, datasrc2_opt->answer, RECORD_LEN);
-	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	    G_strip(datasrc);
-	    G_debug(3, "map datasrc2= [%s]  (%d chars)", datasrc,
-		    strlen(datasrc));
-	    strncpy(hist.datsrc_2, datasrc, RECORD_LEN);
-	}
+	if (datasrc1_opt->answer)
+	    Rast_set_history(&hist, HIST_DATSRC_1, datasrc1_opt->answer);
 
-	if (datadesc_opt->answer) {
-	    strncpy(datasrc, datadesc_opt->answer, RECORD_LEN);
-	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	    G_strip(datasrc);
-	    G_debug(3, "map datadesc= [%s]  (%d chars)", datasrc,
-		    strlen(datasrc));
-	    strncpy(hist.keywrd, datasrc, RECORD_LEN);
-	}
+	if (datasrc2_opt->answer)
+	    Rast_set_history(&hist, HIST_DATSRC_2, datasrc2_opt->answer);
 
+	if (datadesc_opt->answer)
+	    Rast_set_history(&hist, HIST_KEYWRD, datadesc_opt->answer);
+
 	Rast_write_history(raster->answer, &hist);
     }
 

Modified: grass/trunk/raster/r.topidx/file_io.c
===================================================================
--- grass/trunk/raster/r.topidx/file_io.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.topidx/file_io.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -85,7 +85,6 @@
     Rast_close(fd);
 
     Rast_short_history(oname, "raster", &history);
-    strncpy(history.datsrc_1, iname, RECORD_LEN);
-    history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+    Rast_set_history(&history, HIST_DATSRC_1, iname);
     Rast_write_history(oname, &history);
 }

Modified: grass/trunk/raster/r.watershed/front/main.c
===================================================================
--- grass/trunk/raster/r.watershed/front/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/r.watershed/front/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -347,13 +347,11 @@
     Rast_put_cell_title(map_name, title);
 
     Rast_short_history(map_name, "raster", &history);
-    strncpy(history.datsrc_1, source_name, RECORD_LEN);
-    history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
-    sprintf(history.edhist[0],
-	    "Processing mode: %s", sfd ? "SFD (D8)" : "MFD");
-    sprintf(history.edhist[1],
-	    "Memory mode: %s", mode ? "Segmented" : "All in RAM");
-    history.edlinecnt = 2;
+    Rast_set_history(&history, HIST_DATSRC_1, source_name);
+    Rast_append_format_history(
+	&history, "Processing mode: %s", sfd ? "SFD (D8)" : "MFD");
+    Rast_append_format_history(
+	&history, "Memory mode: %s", mode ? "Segmented" : "All in RAM");
     Rast_command_history(&history);
 
     Rast_write_history(map_name, &history);

Modified: grass/trunk/raster/simwe/simlib/output.c
===================================================================
--- grass/trunk/raster/simwe/simlib/output.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster/simwe/simlib/output.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -430,8 +430,8 @@
 
 	    type = "raster";
 	    Rast_short_history(erdep0, type, &hist1);
-	    sprintf(hist1.edhist[0], "The sediment flux file is %s", flux0);
-	    hist1.edlinecnt = 1;
+	    Rast_append_format_history(
+		&hist1, "The sediment flux file is %s", flux0);
 	    Rast_write_history(erdep0, &hist1);
 	}
 	else {
@@ -446,8 +446,8 @@
 
 	    type = "raster";
 	    Rast_short_history(erdep, type, &hist1);
-	    sprintf(hist1.edhist[0], "The sediment flux file is %s", flux);
-	    hist1.edlinecnt = 1;
+	    Rast_append_format_history(
+		&hist1, "The sediment flux file is %s", flux);
 	    Rast_write_history(erdep, &hist1);
 	}
     }
@@ -470,22 +470,24 @@
 	/*    fprintf (stdout, "\n history initiated\n");
 	   fflush(stdout); */
 
-	sprintf(hist.edhist[0],
-		"init.walk=%d, maxwalk=%d, remaining walkers=%d", nwalk,
-		maxwa, nwalka);
-	sprintf(hist.edhist[1], "duration (sec.)=%d, time-serie iteration=%d",
-		timesec, tt);
+	Rast_append_format_history(
+	    &hist, "init.walk=%d, maxwalk=%d, remaining walkers=%d",
+	    nwalk, maxwa, nwalka);
+	Rast_append_format_history(
+	    &hist, "duration (sec.)=%d, time-serie iteration=%d",
+	    timesec, tt);
+	Rast_append_format_history(
+	    &hist, "written walkers=%d, deltap=%f, mean vel.=%f",
+	    lwwfin, deltap, vmean);
+	Rast_append_format_history(
+	    &hist, "mean source (si)=%e, mean infil=%e",
+	    si0, infmean);
 
-	sprintf(hist.edhist[2], "written walkers=%d, deltap=%f, mean vel.=%f",
-		lwwfin, deltap, vmean);
+	Rast_format_history(&hist, HIST_DATSRC_1, "input files: %s %s %s",
+			    elevin, dxin, dyin);
+	Rast_format_history(&hist, HIST_DATSRC_2, "input files: %s %s %s",
+			    rain, infil, manin);
 
-	sprintf(hist.edhist[3], "mean source (si)=%e, mean infil=%e", si0,
-		infmean);
-
-	sprintf(hist.datsrc_1, "input files: %s %s %s", elevin, dxin, dyin);
-	sprintf(hist.datsrc_2, "input files: %s %s %s", rain, infil, manin);
-	hist.edlinecnt = 4;
-
 	Rast_command_history(&hist);
 
 	if (ts == 1)
@@ -508,22 +510,24 @@
 	/*    fprintf (stdout, "\n history initiated\n");
 	   fflush(stdout); */
 
-	sprintf(hist.edhist[0],
-		"init.walkers=%d, maxwalk=%d, rem. walkers=%d", nwalk, maxwa,
-		nwalka);
-	sprintf(hist.edhist[1], "duration (sec.)=%d, time-serie iteration=%d",
-		timesec, tt);
+	Rast_append_format_history(
+	    &hist,"init.walkers=%d, maxwalk=%d, rem. walkers=%d",
+	    nwalk, maxwa, nwalka);
+	Rast_append_format_history(
+	    &hist, "duration (sec.)=%d, time-serie iteration=%d",
+	    timesec, tt);
+	Rast_append_format_history(
+	    &hist, "written walkers=%d, deltap=%f, mean vel.=%f",
+	    lwwfin, deltap, vmean);
+	Rast_append_format_history(
+	    &hist, "mean source (si)=%e, mean infil=%e",
+	    si0, infmean);
 
-	sprintf(hist.edhist[2], "written walkers=%d, deltap=%f, mean vel.=%f",
-		lwwfin, deltap, vmean);
+	Rast_format_history(&hist, HIST_DATSRC_1, "input files: %s %s %s",
+			    elevin, dxin, dyin);
+	Rast_format_history(&hist, HIST_DATSRC_2, "input files: %s %s %s",
+			    rain, infil, manin);
 
-	sprintf(hist.edhist[3], "mean source (si)=%e, mean infil=%e", si0,
-		infmean);
-
-	sprintf(hist.datsrc_1, "input files: %s %s %s", elevin, dxin, dyin);
-	sprintf(hist.datsrc_2, "input files: %s %s %s", rain, infil, manin);
-	hist.edlinecnt = 4;
-
 	Rast_command_history(&hist);
 
 	if (ts == 1)
@@ -546,23 +550,23 @@
 	/*    fprintf (stdout, "\n history initiated\n");
 	   fflush(stdout); */
 
-	sprintf(hist.edhist[0],
-		"init.walk=%d, maxwalk=%d, remaining walkers=%d", nwalk,
-		maxwa, nwalka);
-	sprintf(hist.edhist[1], "duration (sec.)=%d, time-serie iteration=%d",
-		timesec, tt);
+	Rast_append_format_history(
+	    &hist, "init.walk=%d, maxwalk=%d, remaining walkers=%d",
+	    nwalk, maxwa, nwalka);
+	Rast_append_format_history(
+	    &hist, "duration (sec.)=%d, time-serie iteration=%d",
+	    timesec, tt);
+	Rast_append_format_history(
+	    &hist, "written walkers=%d, deltap=%f, mean vel.=%f",
+	    lwwfin, deltap, vmean);
+	Rast_append_format_history(
+	    &hist, "mean source (si)=%f", si0);
 
-	sprintf(hist.edhist[2], "written walkers=%d, deltap=%f, mean vel.=%f",
-		lwwfin, deltap, vmean);
+	Rast_format_history(&hist, HIST_DATSRC_1, "input files: %s %s %s",
+			    wdepth, dxin, dyin);
+	Rast_format_history(&hist, HIST_DATSRC_2, "input files: %s %s %s %s",
+			    manin, detin, tranin, tauin);
 
-	sprintf(hist.edhist[3], "mean source (si)=%f", si0);
-
-	sprintf(hist.datsrc_1, "input files: %s %s %s", wdepth, dxin, dyin);
-	sprintf(hist.datsrc_2, "input files: %s %s %s %s", manin, detin,
-		tranin, tauin);
-
-	hist.edlinecnt = 4;
-
 	Rast_command_history(&hist);
 
 	if (ts == 1)

Modified: grass/trunk/raster3d/r3.in.ascii/main.c
===================================================================
--- grass/trunk/raster3d/r3.in.ascii/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster3d/r3.in.ascii/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -277,8 +277,7 @@
 
     /* write input name to map history */
     G3d_readHistory(output, G_mapset(), &history);
-    strncpy(history.datsrc_1, input, RECORD_LEN);
-    history.datsrc_1[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+    Rast_set_history(&history, HIST_DATSRC_1, input);
     G3d_writeHistory(output, &history);
 
     map = NULL;

Modified: grass/trunk/raster3d/r3.info/r3.info.main.c
===================================================================
--- grass/trunk/raster3d/r3.info/r3.info.main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster3d/r3.info/r3.info.main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -151,17 +151,15 @@
 	&& !timestampflag->answer && !hflag->answer) {
 	divider('+');
 
-	if (G_asprintf
-	    (&line, "Layer:    %-29.29s  Date: %s", name,
-	     hist_ok ? hist.mapid : "??") > 0)
+	if (G_asprintf(&line, "Layer:    %-29.29s  Date: %s", name,
+		       hist_ok ? Rast_get_history(&hist, HIST_MAPID) : "??") > 0)
 	    printline(line);
 	else
 	    G_fatal_error(_("Cannot allocate memory for string"));
 
 
-	if (G_asprintf
-	    (&line, "Mapset:   %-29.29s  Login of Creator: %s", mapset,
-	     hist_ok ? hist.creator : "??") > 0)
+	if (G_asprintf(&line, "Mapset:   %-29.29s  Login of Creator: %s", mapset,
+	     hist_ok ? Rast_get_history(&hist, HIST_CREATOR) : "??") > 0)
 	    printline(line);
 	else
 	    G_fatal_error(_("Cannot allocate memory for string"));
@@ -177,9 +175,8 @@
 	else
 	    G_fatal_error(_("Cannot allocate memory for string"));
 
-	if (G_asprintf
-	    (&line, "Title:    %s ( %s )", cats_ok ? cats.title : "??",
-	     hist_ok ? hist.title : "??") > 0)
+	if (G_asprintf(&line, "Title:    %s ( %s )", cats_ok ? cats.title : "??",
+	     hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??") > 0)
 	    printline(line);
 	else
 	    G_fatal_error(_("Cannot allocate memory for string"));
@@ -210,8 +207,7 @@
 	    format_double((double)cats.num, tmp1);
 	}
 
-	if (G_asprintf
-	    (&line, "  Type of Map:  %-20.20s Number of Categories: %-9s",
+	if (G_asprintf(&line, "  Type of Map:  %-20.20s Number of Categories: %-9s",
 	     "3d cell", cats_ok ? tmp1 : "??") > 0)
 	    printline(line);
 	else
@@ -303,12 +299,12 @@
 
 	if (hist_ok) {
 	    printline("  Data Source:");
-	    if (G_asprintf(&line, "   %s", hist.datsrc_1) > 0)
+	    if (G_asprintf(&line, "   %s", Rast_get_history(&hist, HIST_DATSRC_1)) > 0)
 		printline(line);
 	    else
 		G_fatal_error(_("Cannot allocate memory for string"));
 
-	    if (G_asprintf(&line, "   %s", hist.datsrc_2) > 0)
+	    if (G_asprintf(&line, "   %s", Rast_get_history(&hist, HIST_DATSRC_2)) > 0)
 		printline(line);
 	    else
 		G_fatal_error(_("Cannot allocate memory for string"));
@@ -316,20 +312,20 @@
 	    printline("");
 
 	    printline("  Data Description:");
-	    if (G_asprintf(&line, "   %s", hist.keywrd) > 0)
+	    if (G_asprintf(&line, "   %s", Rast_get_history(&hist, HIST_KEYWRD)) > 0)
 		printline(line);
 	    else
 		G_fatal_error(_("Cannot allocate memory for string"));
 
 	    printline("");
-	    if (hist.edlinecnt) {
+	    if (Rast_history_length(&hist)) {
 		printline("  Comments:  ");
 
-		for (i = 0; i < hist.edlinecnt; i++)
+		for (i = 0; i < Rast_history_length(&hist); i++)
 
 	    /**************************************/
 		{
-		    if (G_asprintf(&line, "   %s", hist.edhist[i]) > 0)
+		    if (G_asprintf(&line, "   %s", Rast_history_line(&hist, i)) > 0)
 			printline(line);
 		    else
 			G_fatal_error(_("Cannot allocate memory for string"));
@@ -383,22 +379,22 @@
 	}			/*Datatype */
 	else if (tflag->answer) {
 	    fprintf(out, "datatype=\"%s\"\n",
-		    (data_type ==
-		     FCELL_TYPE ? "float" : (data_type ==
-					     DCELL_TYPE ? "double" : "??")));
+		    data_type == FCELL_TYPE ? "float" :
+		    data_type == DCELL_TYPE ? "double" :
+		    "??");
 
 	}			/*History output */
 	else if (hflag->answer) {
 	    if (hist_ok) {
 		fprintf(out, "Data Source:\n");
-		fprintf(out, "   %s\n", hist.datsrc_1);
-		fprintf(out, "   %s\n", hist.datsrc_2);
+		fprintf(out, "   %s\n", Rast_get_history(&hist, HIST_DATSRC_1));
+		fprintf(out, "   %s\n", Rast_get_history(&hist, HIST_DATSRC_2));
 		fprintf(out, "Data Description:\n");
-		fprintf(out, "   %s\n", hist.keywrd);
-		if (hist.edlinecnt) {
+		fprintf(out, "   %s\n", Rast_get_history(&hist, HIST_KEYWRD));
+		if (Rast_history_length(&hist)) {
 		    fprintf(out, "Comments:\n");
-		    for (i = 0; i < hist.edlinecnt; i++)
-			fprintf(out, "   %s\n", hist.edhist[i]);
+		    for (i = 0; i < Rast_history_length(&hist); i++)
+			fprintf(out, "   %s\n", Rast_history_line(&hist, i));
 		}
 	    }
 	    else {

Modified: grass/trunk/raster3d/r3.to.rast/main.c
===================================================================
--- grass/trunk/raster3d/r3.to.rast/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/raster3d/r3.to.rast/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -328,26 +328,24 @@
 	G_debug(4, "Raster map %d Filename: %s", i + 1, RasterFileName);
 	Rast_short_history(RasterFileName, "raster", &history);
 
-	sprintf(history.datsrc_1, "3D Raster map:");
-	strncpy(history.datsrc_2, param.input->answer, RECORD_LEN);
-	history.datsrc_2[RECORD_LEN - 1] = '\0';	/* strncpy() doesn't null terminate if maxfill */
+	Rast_set_history(&history, HIST_DATSRC_1, "3D Raster map:");
+	Rast_set_history(&history, HIST_DATSRC_2, param.input->answer);
 
-	sprintf(history.edhist[0], "Level %d of %d", i + 1, region.depths);
-	sprintf(history.edhist[1], "Level z-range: %f to %f",
+	Rast_append_format_history(&history, "Level %d of %d", i + 1, region.depths);
+	Rast_append_format_history(&history, "Level z-range: %f to %f",
 		region.bottom + (i * region.tb_res),
 		region.bottom + (i + 1 * region.tb_res));
 
-	sprintf(history.edhist[3], "Input map full z-range: %f to %f",
+	Rast_append_format_history(&history, "Input map full z-range: %f to %f",
 		inputmap_bounds.bottom, inputmap_bounds.top);
-	sprintf(history.edhist[4], "Input map z-resolution: %f",
+	Rast_append_format_history(&history, "Input map z-resolution: %f",
 		inputmap_bounds.tb_res);
-	history.edlinecnt = 5;
+
 	if (!param.res->answer) {
-	    sprintf(history.edhist[6], "GIS region full z-range: %f to %f",
+	    Rast_append_format_history(&history, "GIS region full z-range: %f to %f",
 		    region.bottom, region.top);
-	    sprintf(history.edhist[7], "GIS region z-resolution: %f",
+	    Rast_append_format_history(&history, "GIS region z-resolution: %f",
 		    region.tb_res);
-	    history.edlinecnt = 8;
 	}
 
 	Rast_command_history(&history);

Modified: grass/trunk/vector/v.to.rast/support.c
===================================================================
--- grass/trunk/vector/v.to.rast/support.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/vector/v.to.rast/support.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -26,11 +26,11 @@
     if (Rast_read_history(raster_name, G_mapset(), &hist) < 0)
 	return -1;
 
-    strcpy(hist.title, raster_name);
+    Rast_set_history(&hist, HIST_TITLE, raster_name);
 
     /* store information from digit file into history */
-    sprintf(hist.datsrc_1, "Vector Map: %s", vector_name);
-    sprintf(hist.datsrc_2, "Original scale from vector map: 1:%ld", scale);	/* 4.0 */
+    Rast_format_history(&hist, HIST_DATSRC_1, "Vector Map: %s", vector_name);
+    Rast_format_history(&hist, HIST_DATSRC_2, "Original scale from vector map: 1:%ld", scale);	/* 4.0 */
 
     /* store command line options */
     Rast_command_history(&hist);

Modified: grass/trunk/vector/v.vol.rst/main.c
===================================================================
--- grass/trunk/vector/v.vol.rst/main.c	2010-07-02 15:41:54 UTC (rev 42694)
+++ grass/trunk/vector/v.vol.rst/main.c	2010-07-02 15:45:16 UTC (rev 42695)
@@ -843,17 +843,17 @@
 		if ((cellout != NULL)) {
 		    Rast_short_history(cellout, "raster", &hist);
 		    /* TODO: next lines need to be verified! */
-		    sprintf(hist.edhist[0], "tension=%f, smoothing=%f", fi,
-			    rsm);
-		    sprintf(hist.edhist[1],
-			    "dnorm=%f, dmin=%f, wmult=%f, zmult=%f", dnorm,
-			    atof(parm.dmin1->answer), wmult, zmult);
-		    sprintf(hist.edhist[2], "segmax=%d, npmin=%d, npmax=%d, rmsdevi=%f",
-			    KMAX, npmin, KMAXPOINTS, sqrt(ertot / KMAX2));
-		    sprintf(hist.edhist[3], "wmin_data=%f, wmax_data=%f",
-			    wmin, wmax);
+		    Rast_append_format_history(
+			&hist, "tension=%f, smoothing=%f", fi, rsm);
+		    Rast_append_format_history(
+			&hist, "dnorm=%f, dmin=%f, wmult=%f, zmult=%f", dnorm,
+			atof(parm.dmin1->answer), wmult, zmult);
+		    Rast_append_format_history(
+			&hist, "segmax=%d, npmin=%d, npmax=%d, rmsdevi=%f",
+			KMAX, npmin, KMAXPOINTS, sqrt(ertot / KMAX2));
+		    Rast_append_format_history(
+			&hist, "wmin_data=%f, wmax_data=%f", wmin, wmax);
 		    /* ? sprintf (hist.edhist[4], "wmin_int=%f, wmax_int=%f", wminac, wmaxac); */
-		    hist.edlinecnt = 5;
 
 		    Rast_command_history(&hist);
 		    Rast_write_history(cellout, &hist);



More information about the grass-commit mailing list