/*
 * $Id: snd_rcv.c,v 1.3.2.1 1999/02/08 03:11:10 yamasita Exp $
 */

/*
 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
 * This file is part of FreeWnn.
 * 
 * Copyright Kyoto University Research Institute for Mathematical Sciences
 *                 1987, 1988, 1989, 1990, 1991, 1992
 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
 *
 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Emacs; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Commentary:
 *
 * Change log:
 *
 * Last modified date: 8,Feb.1999
 *
 * Code:
 *
 */
/*	Version 4.0
 */
#include <stdio.h>
#include "de_header.h"

static int fmode;
 /* JS_FILE_SEND (server receives) */
int
fopen_read_cur(fn)
char *fn;
{
	fmode = 'r';
	return 1;
}

/* JS_FILE_RECEIVE (server sends) */
int
fopen_write_cur(fn)
char *fn;
{
	fmode = 'w';
/*
	puts_cur(fn);putc_purge();
	if(get4_cur()== -1) return NULL;
	else return 1;
*/
	return 1;
}

/* JS_FILE_SEND (server recieves) */
int
fread_cur(p, size, nitems)
char *p;
register int size,nitems;
{
 register int i,j,xx;
 for(i=0;i<nitems;i++){
     for(j=0;j<size;j++){
	*p++ = xx =  xgetc_cur();
	if(xx== -1) return i;
    }
 }
 return nitems;
}

static int store = -1;

int
xgetc_cur()
{register int x;
 if(store != -1){ x = store; store = -1; return(x);}
 if((x= getc_cur()) != 0xFF) return x;
 if(getc_cur() == 0xFF) return -1; /* EOF */
 return 0xFF;
}

void
xungetc_cur(x)			/* H.T. */
int x;
{
    store = x;
}

/* JS_FILE_SRECEIVE (server sends) */
void
fwrite_cur(p, size, nitems)
unsigned char *p;
int size, nitems;
{register int i,x;
 x= size*nitems;
 for(i=0;i<x;i++){
	xputc_cur(*p++);
 }
}

void
xputc_cur(x)
unsigned char x;/* H.T. */
{
 putc_cur(x);
 if(x==0xFF){ putc_cur(0x00); }
}

void
fclose_cur()
{
 if(fmode!='w') return;
 putc_cur(0xFF);
 putc_cur(0xFF); /* EOF */
}
