/* $Header:_log.c 12.0$ */
/* $ACIS:_log.c 12.0$ */
/* $Source: /ibm/acis/usr/src/usr.lib/libaed/RCS/_log.c,v $ */

#ifndef lint
static char *rcsid = "$Header:_log.c 12.0$";
#endif

#include "whim.h"

VI_Login(filename)
char *filename; 	      /* name of file to log commands into */
{
#include "whimdcl.h"
 char *malloc();
 if (saving) { JOURNL(ALLDONE);
	       close(savefile);
	     }

 saving = FALSE;
 if ((savefile = creat(filename,BWRITE)) > NULL) saving = TRUE;
 savefn = malloc(strlen(filename)+1);
 if (savefn != 0)
	{
	fprintf(stderr,"Heap full.\n");
	fprintf(stderr,"Trying to continue, VI_Login(%s) ignored.\n",filename);
	return(-1);
	}
 strcpy(savefn,filename);
 return(savefile);
}

VI_Logout()
{
#include "whimdcl.h"
 INT_PURE status = -2;

 if (saving)
	{
	JOURNL(ALLDONE);
	status = close(savefile);
	free(savefn);
	}
 saving = FALSE;
 savefn = NULL;
 savefile = NULL;
 return(status);
}

getstr(s,fd)
char *s;		/* string to be loaded */
INT_PURE fd;		/* file descriptor  */
{
#include "whimdcl.h"
 INT_PURE i = 0;
 while(i<80)
   { read(fd,s,1);
     i++;
     if (*s++ == '\0') return(i);
   }
 *--s = '\0';
 return(i);
}

strjour(s)
char *s;
{
#include "whimdcl.h"
 INT_PURE i=0;
 while(i<79)
   { write(savefile,s,1);
     i++;
     if (*s++ == '\0') return(i);
   }
 write(savefile,"\0",1);
 return(++i);
 }
