Blame urt/rle_error.c

Packit 78deda
/*
Packit 78deda
 * This software is copyrighted as noted below.  It may be freely copied,
Packit 78deda
 * modified, and redistributed, provided that the copyright notice is 
Packit 78deda
 * preserved on all copies.
Packit 78deda
 * 
Packit 78deda
 * There is no warranty or other guarantee of fitness for this software,
Packit 78deda
 * it is provided solely "as is".  Bug reports or fixes may be sent
Packit 78deda
 * to the author, who may or may not act on them as he desires.
Packit 78deda
 *
Packit 78deda
 * You may not include this software in a program or other software product
Packit 78deda
 * without supplying the source, or without informing the end-user that the 
Packit 78deda
 * source is available for no extra charge.
Packit 78deda
 *
Packit 78deda
 * If you modify this software, you should include a notice giving the
Packit 78deda
 * name of the person performing the modification, the date of modification,
Packit 78deda
 * and the reason for such modification.
Packit 78deda
 */
Packit 78deda
/* 
Packit 78deda
 * rle_error.c - Error message stuff for URT.
Packit 78deda
 * 
Packit 78deda
 * Author:	Spencer W. Thomas
Packit 78deda
 * 		EECS Dept.
Packit 78deda
 * 		University of Michigan
Packit 78deda
 * Date:	Mon Mar  2 1992
Packit 78deda
 * Copyright (c) 1992, University of Michigan
Packit 78deda
 */
Packit 78deda
Packit 78deda
#include <string.h>
Packit 78deda
Packit 78deda
#include "rle_config.h"
Packit 78deda
#include "rle.h"
Packit 78deda
Packit 78deda
/*****************************************************************
Packit 78deda
 * TAG( rle_alloc_error )
Packit 78deda
 * 
Packit 78deda
 * Print memory allocation error message and exit.
Packit 78deda
 * Inputs:
Packit 78deda
 * 	pgm:		Name of this program.
Packit 78deda
 * 	name:		Name of memory trying to be allocated.
Packit 78deda
 * Outputs:
Packit 78deda
 * 	Prints message and exits.
Packit 78deda
 *
Packit 78deda
 * Returns int because it's used in a conditional expression.
Packit 78deda
 */
Packit 78deda
int
Packit 78deda
rle_alloc_error( pgm, name )
Packit 78deda
CONST_DECL char *pgm, *name;
Packit 78deda
{
Packit 78deda
    if ( name )
Packit 78deda
	fprintf( stderr, "%s: memory allocation failed.\n", pgm );
Packit 78deda
    else
Packit 78deda
	fprintf( stderr, "%s: memory allocation failed (no space for %s).\n",
Packit 78deda
		 pgm, name );
Packit 78deda
Packit 78deda
    exit( RLE_NO_SPACE );
Packit 78deda
Packit 78deda
    /* Will some compilers bitch about this because they know exit
Packit 78deda
     * doesn't return??
Packit 78deda
     */
Packit 78deda
    return 0;
Packit 78deda
}
Packit 78deda
Packit 78deda
/*****************************************************************
Packit 78deda
 * TAG( rle_get_error )
Packit 78deda
 * 
Packit 78deda
 * Print an error message for the return code from rle_get_setup
Packit 78deda
 * Inputs:
Packit 78deda
 * 	code:		The return code from rle_get_setup.
Packit 78deda
 *	pgmname:	Name of this program (argv[0]).
Packit 78deda
 *	fname:		Name of the input file.
Packit 78deda
 * Outputs:
Packit 78deda
 * 	Prints an error message on standard output.
Packit 78deda
 *	Returns code.
Packit 78deda
 */
Packit 78deda
int
Packit 78deda
rle_get_error( code, pgmname, fname )
Packit 78deda
int code;
Packit 78deda
CONST_DECL char *pgmname;
Packit 78deda
CONST_DECL char *fname;
Packit 78deda
{
Packit 78deda
    if (! fname || strcmp( fname, "-" ) == 0 )
Packit 78deda
	fname = "Standard Input";
Packit 78deda
Packit 78deda
    switch( code )
Packit 78deda
    {
Packit 78deda
    case RLE_SUCCESS:		/* success */
Packit 78deda
	break;
Packit 78deda
Packit 78deda
    case RLE_NOT_RLE:		/* Not an RLE file */
Packit 78deda
	fprintf( stderr, "%s: %s is not an RLE file\n",
Packit 78deda
		 pgmname, fname );
Packit 78deda
	break;
Packit 78deda
Packit 78deda
    case RLE_NO_SPACE:			/* malloc failed */
Packit 78deda
	fprintf( stderr,
Packit 78deda
		 "%s: Malloc failed reading header of file %s\n",
Packit 78deda
		 pgmname, fname );
Packit 78deda
	break;
Packit 78deda
Packit 78deda
    case RLE_EMPTY:
Packit 78deda
	fprintf( stderr, "%s: %s is an empty file\n",
Packit 78deda
		 pgmname, fname );
Packit 78deda
	break;
Packit 78deda
Packit 78deda
    case RLE_EOF:
Packit 78deda
	fprintf( stderr,
Packit 78deda
		 "%s: RLE header of %s is incomplete (premature EOF)\n",
Packit 78deda
		 pgmname, fname );
Packit 78deda
	break;
Packit 78deda
Packit 78deda
    default:
Packit 78deda
	fprintf( stderr, "%s: Error encountered reading header of %s\n",
Packit 78deda
		 pgmname, fname );
Packit 78deda
	break;
Packit 78deda
    }
Packit 78deda
    return code;
Packit 78deda
}
Packit 78deda
Packit 78deda