#include "all.h"
#include "edt.h"
#ifdef __TURBOC__
#define DASHCHAR 249
#include <alloc.h>
#include "bios.h"
#include "conio.h"
#include "dir.h"
#else
#define far
#define farcalloc calloc
#define DASHCHAR '.'
#include "vaxconio.h"
#endif
FILE *jouptr;
extern int in_recover,single_step;
init_logging(char *infile)
{
	FILE *jptr;
	unsigned char ccc;
	static char buff[80];
	if (in_recover) {
#ifdef unix
		jouptr = fopen("manip_.j1","r");
#else
		jouptr = fopen("manip_.j1","rb");
#endif
		if (jouptr==NULL) fner("Unable to open/read journal file manip_.j1");
		fread(&ccc,1,1,jouptr);
		fread(buff,1,ccc,jouptr);
		if (strlen(infile)==0) strcpy(infile,buff);
		return;
	}
	unlink("manip_.j3");
	rename("manip_.j2","manip_.j3");
	rename("manip_.j1","manip_.j2");
	jptr = fopen("manip_.j1","wb");
	fputc(strlen(infile),jptr);
	fwrite(infile,1,strlen(infile),jptr);
	if (jptr==NULL) fner("Unable to open journal file manip_.j1");
	fclose(jptr);
}
unsigned char mjl_buff[80];
mjl_key(int c)
{
	int s;
	if (in_recover) return;
	if (c==0) return;
	s = strlen(mjl_buff);
	mjl_buff[s] = c;
	mjl_buff[s+1] = 0;
	if (s>40) mjl_flush();
}
mjl_flush()
{
	FILE *jptr;
	if (in_recover) return;
	if (strlen(mjl_buff)<7) return;
	jptr = fopen("manip_.j1","ab");
	if (jptr==NULL) fner("Unable to append to journal file manip_.j1");
	fwrite(mjl_buff,1,strlen(mjl_buff),jptr);
	fclose(jptr);
	mjl_buff[0] = 0;
}

