/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

static char sccsid_Bind_file[] = "@(#)STDbind_file.c	1.31 11/13/92 10:50:31 LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	6/28/90

	ROUTINE:	Bind_file
	Version:	__ROr_STDBind_file

PURPOSE:

IN:
	instance - valid pointer filled by STDinit_instance.
	rules - asn_1
	infilename - filename for reading 
	outfilename - filename for writing

OUT:
	instance - All fields are initialized and ready for
		communication


CALLED ROUTINES:
	

	
MODIFICATION HISTORY:


*/

#include <elros/instance.h>
#include <elros/binds.h>

#include <elros/specifics.h>


int __ROr_STDBind_file(instance,rules,infilename,outfilename)

	__RO_Instance_Record *instance;
	__RO_Presentation_rules rules;
	char *infilename;
	char *outfilename;

{

	/* log "addresses" a level 6 */
   if (__ROr_Logging7on(instance))
   {
      char buffer[512];

      sprintf(buffer,"BIND: platform=FILE, infile='%s', outfile='%s'",
		infilename ? infilename : "",
		outfilename ? infilename : "");
      if (__ROr_log6comment(instance,buffer))
         return(EXCEPTION);
   }

   if (infilename)
   {
      instance->subsystem->specific.file.infile = (void *)fopen(infilename,"r");
      if (!instance->subsystem->specific.file.infile)
         __RO_RETURN_RUNTIME(instance,__ROx_BIND_CANTOPENIFILE);
   }
   else
      instance->subsystem->specific.file.infile = NULL;

   if (outfilename)
   {
      instance->subsystem->specific.file.outfile = (void *)fopen(outfilename,"w");
      if (!instance->subsystem->specific.file.outfile)
         __RO_RETURN_RUNTIME(instance,__ROx_BIND_CANTOPENOFILE);
   }
   else
      instance->subsystem->specific.file.outfile = NULL;

   instance->subsystem->platform = __ROm_platform_FILE;

   if (__ROr_STDinit_bind(instance,rules,__ROr_FILEsend_data,__ROr_FILEreceive_data))
      return(EXCEPTION);

   return(SUCCESS);
}


