[GRASS-dev] [GRASS GIS] #132: Extend GRASS-command history (at least to 1000) by default

Glynn Clements glynn at gclements.plus.com
Sat Apr 19 00:28:53 EDT 2008


GRASS GIS wrote:

> #132: Extend GRASS-command history (at least to 1000) by default
> -------------------------+--------------------------------------------------
>  Reporter:  nikos        |       Owner:  grass-dev at lists.osgeo.org
>      Type:  enhancement  |      Status:  new                      
>  Priority:  major        |   Milestone:  6.4.0                    
> Component:  default      |     Version:  unspecified              
>  Keywords:               |  
> -------------------------+--------------------------------------------------
>  Why not extend the command-history by default?

Are you talking about the shell's command history or a map's history?

For the latter, one problem is that the History structure uses
fixed-sized fields:

	#define MAXEDLINES  50
	#define RECORD_LEN  80
	
	...
	
	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];
	};

Increasing MAXLINES to 1000 could be a significant waste of memory for
modules which have a lot of maps open.

The I/O code only writes as many characters per line and as many lines
as are actually used, so disk space isn't a factor:

	    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]) ;

It probably wouldn't be particularly hard to replace all of the arrays
with pointers, i.e.:

	struct History
	{
	    char    *mapid;
	    char    *title;
	    char    *mapset;
	    char    *creator;
	    char    *maptype;
	    char    *datsrc_1;
	    char    *datsrc_2;
	    char    *keywrd;
	    int     edlinecnt;
	    char    **edhist;
	};

The main issue is that any modules which fill in the history fields
themselves (rather than simply calling e.g. G_short_history()) would
need to use e.g.:

	hist.datasrc_1 = G_store(src);

instead of:

	strcpy(hist.datasrc_1, src);

Tracking down all such cases might take a while.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list