1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
#ifndef LINT
/* @(#) prterror.c 2.8 88/01/31 18:48:17 */
static char sccsid[]="@(#) prterror.c 2.8 88/01/31 18:48:17";
#endif /* LINT */
/*
The contents of this file are hereby released to the public domain.
-- Rahul Dhesi 1986/11/14
*/
#include "options.h"
#ifndef OK_STDIO
#include <stdio.h>
#define OK_STDIO
#endif
#include "various.h"
#include "zooio.h"
#include "zoofns.h"
#ifdef NEEDCTYP
# include <ctype.h> /* for isdigit() */
#endif
#ifdef STDARG
# include <stdarg.h>
#else
# ifdef VARARGS
# include <varargs.h>
# else
# include "MUST DEFINE STDARG OR VARARGS"
# endif
#endif
#ifdef NEED_VPRINTF
static int zvfprintf();
#endif
/* General error handler. Input format:
parameter 1: 'w', 'e', or 'f'.
'm': message
'M': message without preceding identification
'w': WARNING
'e': ERROR
'f': FATAL
'F': FATAL but program doesn't exist immediately
All text printed is preceded by "Zoo: " or "Ooz: " depending
upon conditional compilation, except in the case of 'M' messages
which are printed without any text being added.
For messages, the text supplied is printed if and only if the global
variable "quiet" is zero. Control then returns to the caller.
For warnings, errors, and fatal errors, the variable "quiet" is used
as follows. Warning messages are suppressed if quiet > 1; error
messages are suppressed if quiet > 2. Fatal error messages are
never suppressed--doing so would be a bit risky.
For warnings and errors, the error message is preceded by the "WARNING:"
or "ERROR". The error message is printed and control returns to the
caller.
For fatal errors, the error message is preceded by "FATAL:" and an
error message is printed. If the option was 'f', the program exits with
a status of 1. If the option was 'F', control returns to the caller and
it is assumed that the caller will do any cleaning up necessary and then
exit with an error status.
parameter 2: The format control string for printf.
remining parameters: passed on to vprintf().
All messages, whether informative or error, are sent to standard
output via printf. It might be a good idea to eventually send 'e' and
'f' class messages to the standard error stream. Best would be
some way of telling if standard output and standard error are not
the same device, so that we could always send error messages to
standard error, and also duplicate them to standard output if
different from standard error. This is one thing that VMS seems
to be capable of doing. There seems to be no way of doing this
in the general case.
*/
extern int quiet;
/* These declarations must be equivalent to those in errors.i */
char no_match[] = "No files matched.\n";
char failed_consistency[] = "Archive header failed consistency check.\n";
char invalid_header[] = "Invalid or corrupted archive.\n";
char internal_error[]="Internal error.\n";
char disk_full[] = "I/O error or disk full.\n";
char bad_directory[] = "Directory entry in archive is invalid.\n";
char no_memory[] = "Ran out of memory.\n";
char too_many_files[] = "Some filenames ignored -- can only handle %d.\n";
char packfirst[] = "Old format archive -- please pack first with P command.\n";
char garbled[] = "Command is garbled.\n";
char start_ofs[] = "Starting at %ld (offset %ld)\n";
#ifndef OOZ
char wrong_version[]=
"Zoo %d.%d or later is needed to fully manipulate this archive.\n";
char cant_process[] =
"The rest of the archive (%lu bytes) cannot be processed.\n";
char option_ignored[] = "Ignoring option %c.\n";
char inv_option[] = "Option %c is invalid.\n";
char bad_crc[] = "\007Bad CRC, %s probably corrupted\n";
#endif
#ifdef OOZ
char could_not_open[] = "Could not open ";
#else
char could_not_open[] = "Could not open %s.\n";
#endif
#ifdef STDARG
void prterror(int level, char *format, ...)
#else
/*VARARGS*/
void prterror(va_alist)
va_dcl
#endif
{
va_list args;
char string[120]; /* local format string */
#ifdef VARARGS
int level;
char *format;
#endif
#ifdef STDARG
va_start(args, format);
#else
va_start(args);
level = va_arg(args, int);
format = va_arg(args, char *);
#endif
*string = '\0'; /* get a null string to begin with */
#ifdef OOZ
strcpy (string, "Ooz: ");
#else
strcpy (string, "Zoo: ");
#endif
switch (level) {
case 'M': *string = '\0'; /* fall through to 'm' */
case 'm': if (quiet) return; break;
case 'w':
if (quiet > 1) return;
strcat (string, "WARNING: "); break;
case 'e':
if (quiet > 2) return;
strcat (string, "ERROR: "); break;
case 'F':
case 'f': strcat (string, "FATAL: "); break;
default: prterror ('f', internal_error); /* slick recursive call */
}
strcat (string, format); /* just append supplied format string */
/* and print the whole thing */
#ifdef NEED_VPRINTF
(void) zvfprintf(stdout, string, args);
#else
(void) vprintf(string, args);
#endif
fflush (stdout);
if (level == 'f') /* and abort on fatal error 'f' but not 'F' */
zooexit (1);
}
#ifdef NEED_VPRINTF
/* Some systems don't have vprintf; if so, we roll our own. The following
has been adapted from a Usenet posting by Jef Poskanzer <jef@well.sf.ca.us>.
This is a portable mini-vfprintf that depends only on fprintf.
We don't call this routine vfprintf to avoid unexpected conflicts with any
library routine of the same name, notwithstanding the fact that we will
usually use it only when there is no conflict. Also, even though we only
need vprintf, the routine used here implements vfprintf. This will allow
future uses as needed when output is to be sent to a stream other than
stdout. */
/* Whether to support double. Better not to, because it may cause
math stuff to be linked in */
#undef NEED_DOUBLE
static int zvfprintf(stream, format, args)
FILE *stream;
char *format;
va_list args;
{
char *ep;
char fchar;
char tformat[512];
int do_long; /* whether to print as long (l format suffix) */
int do_star; /* * used in format => get width from argument */
int star_size; /* size arg corresponding to "*" format */
int i;
long l;
unsigned u;
unsigned long ul;
char *s;
#ifdef NEED_DOUBLE
double d;
#endif
while (*format != '\0') {
if (*format != '%') { /* Not special, just write out the char. */
putc(*format, stream);
++format;
} else {
do_star = 0;
do_long = 0;
ep = format + 1;
/* Skip over all the field width and precision junk. */
if (*ep == '-')
++ep;
if (*ep == '0')
++ep;
while (isdigit(*ep))
++ep;
if (*ep == '.') {
++ep;
while (isdigit(*ep))
++ep;
}
if (*ep == '#')
++ep;
if (*ep == '*') {
do_star = 1;
star_size = va_arg(args, int); /* get * argument */
++ep;
}
if (*ep == 'l') {
do_long = 1;
++ep;
}
/* Here's the field type. Extract it, and copy this format
** specifier to a temp string so we can add an end-of-string.
*/
fchar = *ep;
(void) strncpy(tformat, format, ep - format + 1);
tformat[ep - format + 1] = '\0';
/* Now do a one-argument printf with the format string we have
isolated. If the * format was used, we will also supply the
additional parameter star_size, which we have already obtained
from the variable argument list. */
switch (fchar) {
case 'd':
if (do_long) {
l = va_arg(args, long);
if (do_star)
(void) fprintf(stream, tformat, star_size, l);
else
(void) fprintf(stream, tformat, l);
} else {
i = va_arg(args, int);
if (do_star)
(void) fprintf(stream, tformat, star_size, i);
else
(void) fprintf(stream, tformat, i);
}
break;
case 'o':
case 'x':
case 'u':
if (do_long) {
ul = va_arg(args, unsigned long);
if (do_star)
(void) fprintf(stream, tformat, star_size, ul);
else
(void) fprintf(stream, tformat, ul);
} else {
u = va_arg(args, unsigned);
if (do_star)
(void) fprintf(stream, tformat, star_size, u);
else
(void) fprintf(stream, tformat, u);
}
break;
case 'c':
i = (char) va_arg(args, int);
if (do_star)
(void) fprintf(stream, tformat, star_size, i);
else
(void) fprintf(stream, tformat, i);
break;
case 's':
s = va_arg(args, char *);
if (do_star)
(void) fprintf(stream, tformat, star_size, s);
else
(void) fprintf(stream, tformat, s);
break;
#ifdef NEED_DOUBLE
case 'e':
case 'f':
case 'g':
d = va_arg(args, double);
if (do_star)
(void) fprintf(stream, tformat, star_size, d);
else
(void) fprintf(stream, tformat, d);
break;
#endif
case '%':
putc('%', stream);
break;
default:
return -1;
}
/* Resume formatting on the next character. */
format = ep + 1;
}
}
va_end(args);
return 0;
}
#endif /*NEED_VPRINTF*/
|