static char resid[]="$Header: /cvs/grass/src.related/LTPlus4.11/source/in/put_di
ary.c,v 1.1 1995/03/20 22:45:06 jasr Exp $"; 
/*******************************************************************************
*       put_diary       (see manual, Internal Functions)                <in>   *
*                       This program appends the diary with who/what/when      *
*                       and the input string.                                  *
*                                                                              *
*                       The diary file is changed.                             *
*                                                                              *
*                       Returns zero upon normal end-of-job (EOJ).             *
*                       returns 1 upon failure.                                *
*                      j.dabritz  8/11/89                                      *
*                      
*                      move entry to temp buffer before modifying it
*				CFA 11/27/98
*******************************************************************************/

#include "../../incl/globals.h"  /*  <stdio.h> & all LTP defines & globals  */
#include <string.h>
#include <time.h>

long put_diary(diary_entry)
char *diary_entry;
{
	int fp;
	char string[256];
	char filepath[256];
	char entry_buf[1024];   /* temporary entry buffer */
	char *std_header();
	
	strcpy (entry_buf,diary_entry);
        /* move string to a local var before modifying it
           this was causing memory faults 
           CFA 11/27/98     */
           
        #ifdef DEBUG
           printf("put_diary.c: entering Put_diary()\n with entry \"%s\"\n for m
ap \"%d\"\n",entry_buf,job_stats[0]);
        #endif
		/************** check for map loaded ***************************/
	if(!job_stats[0])
	{	message("cannot make diary entry unless a map is loaded.");
		return(1);
	}

	#ifdef DEBUG
	  printf("put_diary.c: trimming entry\n");
	#endif
		/************** check & trim diary entry parameter *************/
	trim(entry_buf);
	if(!*entry_buf)
	{	message("diary entry is blank, nothing written.");
		return(1);
	}
	
	#ifdef DEBUG
	  printf("put_diary.c: open diary %s \n",filepath);
	#endif
		/************** open diary file ********************************/
	sprintf(filepath, "%s/%s", temp_map_path, "diary" );
	if( (fp = openf( filepath, APPEND)) == -1 )
		return(1);

	#ifdef DEBUG
	  printf("put_diary.c: info string %s into diary\n",string);
	#endif
		/************** write info_data string *************************/
	if( 0 > writea( std_header(string), fp) )
		return(1);

	#ifdef DEBUG
	  printf("put_diary.c: entry string %s into diary\n",diary_entry);
	#endif
		/************** write input diary_entry string *****************/
	sprintf(string,"  > %s\n\n",entry_buf);
	if( 0 > writea( string, fp) )
		return(1);

	#ifdef DEBUG
	  printf("put_diary.c: closing diary\n");
	#endif
		/************** close file *************************************/
	closef( fp );

	#ifdef DEBUG
	  printf("put_diary.c: leaving put_diary\n");
	#endif
		/************** return *****************************************/
	return(0);
}

