Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rle_error.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * rle_error.c - Error message stuff for URT.
20  *
21  * Author: Spencer W. Thomas
22  * EECS Dept.
23  * University of Michigan
24  * Date: Mon Mar 2 1992
25  * Copyright (c) 1992, University of Michigan
26  */
27 #ifndef lint
28 static char rcs_id[] = "$Header: /l/spencer/src/urt/lib/RCS/rle_error.c,v 3.0.1.1 1992/03/04 19:33:27 spencer Exp $";
29 #endif
30 
31 #include "rle.h"
32 
33 /*****************************************************************
34  * TAG( rle_alloc_error )
35  *
36  * Print memory allocation error message and exit.
37  * Inputs:
38  * pgm: Name of this program.
39  * name: Name of memory trying to be allocated.
40  * Outputs:
41  * Prints message and exits.
42  *
43  * Returns int because it's used in a conditional expression.
44  */
45 int
47 CONST_DECL char *pgm, *name;
48 {
49  if ( name )
50  fprintf( stderr, "%s: memory allocation failed.\n", pgm );
51  else
52  fprintf( stderr, "%s: memory allocation failed (no space for %s).\n",
53  pgm, name );
54 
55  exit( RLE_NO_SPACE );
56 
57  /* Will some compilers bitch about this because they know exit
58  * doesn't return??
59  */
60  return 0;
61 }
62 
63 /*****************************************************************
64  * TAG( rle_get_error )
65  *
66  * Print an error message for the return code from rle_get_setup
67  * Inputs:
68  * code: The return code from rle_get_setup.
69  * pgmname: Name of this program (argv[0]).
70  * fname: Name of the input file.
71  * Outputs:
72  * Prints an error message on standard output.
73  * Returns code.
74  */
75 int
77 int code;
78 CONST_DECL char *pgmname;
79 CONST_DECL char *fname;
80 {
81  if (! fname || strcmp( fname, "-" ) == 0 )
82  fname = "Standard Input";
83 
84  switch( code )
85  {
86  case RLE_SUCCESS: /* success */
87  break;
88 
89  case RLE_NOT_RLE: /* Not an RLE file */
90  fprintf( stderr, "%s: %s is not an RLE file\n",
91  pgmname, fname );
92  break;
93 
94  case RLE_NO_SPACE: /* malloc failed */
95  fprintf( stderr,
96  "%s: Malloc failed reading header of file %s\n",
97  pgmname, fname );
98  break;
99 
100  case RLE_EMPTY:
101  fprintf( stderr, "%s: %s is an empty file\n",
102  pgmname, fname );
103  break;
104 
105  case RLE_EOF:
106  fprintf( stderr,
107  "%s: RLE header of %s is incomplete (premature EOF)\n",
108  pgmname, fname );
109  break;
110 
111  default:
112  fprintf( stderr, "%s: Error encountered reading header of %s\n",
113  pgmname, fname );
114  break;
115  }
116  return code;
117 }
#define RLE_EMPTY
Definition: rle.h:73
#define RLE_SUCCESS
Definition: rle.h:70
#define RLE_NOT_RLE
Definition: rle.h:71
int rle_get_error(int code, const char *pgmname, const char *fname)
Definition: rle_error.c:76
#define RLE_NO_SPACE
Definition: rle.h:72
static char rcs_id[]
Definition: rle_error.c:28
#define RLE_EOF
Definition: rle.h:74
#define CONST_DECL
Definition: rle_config.h:42
int rle_alloc_error(char *pgm, char *name) const
Definition: rle_error.c:46