/*****************************************************************/
/**                                                             **/
/**             (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_fhex_c[] = "@(#)fhex.c	1.2 10/20/92 08:41:50  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	8/13/90

*/

#include <stdio.h>

int global_byte_count = 0;	/* total number of bytes read */
int global_exit_flag = 0;	/* exit if EOF, else flag an error */

/*
	ROUTINE:	fgethex

PURPOSE:
	readds a hex byte from a file

IN:
	f - file to read from

OUT:
	RETURNs byte that was read (as an unsigned char).

CALLED ROUTINES:
	

	
MODIFICATION HISTORY:


*/
unsigned char fgethex(f)
   FILE *f;
{
   int temp;

   if (fscanf(f,"%x",&temp) != 1)
      if (global_exit_flag)
         exit(0);
      else
      {
         printf("Error reading file\n");
         exit(1);
      }
   global_exit_flag = 0;
   global_byte_count++;
   return((unsigned char)temp);
}

/*
	ROUTINE:	fputhex

PURPOSE:
	Writes a byte to a file in hex

IN:
	f - file to write to
	c - byte (as an 'int') to write

OUT:


CALLED ROUTINES:
	

	
MODIFICATION HISTORY:


*/
fputhex(f,c)
   FILE *f;
   int c;
{
   fprintf(f,"%2.2x\n",c);
}
