home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / compress / zoosrc20.zoo / prterror.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  6KB  |  153 lines

  1. #ifndef LINT
  2. /* @(#) prterror.c 2.8 88/01/31 18:48:17 */
  3. static char sccsid[]="@(#) prterror.c 2.8 88/01/31 18:48:17";
  4. #endif /* LINT */
  5.  
  6. /*
  7. The contents of this file are hereby released to the public domain.
  8.  
  9.                                  -- Rahul Dhesi 1986/11/14
  10.  
  11. */
  12. #include "options.h"
  13. #ifndef    OK_STDIO
  14. #include <stdio.h>
  15. #define    OK_STDIO
  16. #endif
  17. #include "various.h"
  18. /* General error handler.  Input format:
  19.  
  20.    parameter 1:  'w', 'e', or 'f'.
  21.  
  22.       'm':  message
  23.       'M':  message without preceding identification
  24.       'w':  WARNING
  25.       'e':  ERROR
  26.       'f':  FATAL
  27.       'F':  FATAL but program doesn't exist immediately
  28.  
  29.    All text printed is preceded by "Zoo:  " or "Ooz:  "  depending
  30.    upon conditional compilation, except in the case of 'M' messages
  31.    which are printed without any text being added.
  32.  
  33.    For messages, the text supplied is printed if and only if the global
  34.    variable "quiet" is zero.  Control then returns to the caller.
  35.  
  36.    For warnings, errors, and fatal errors, the variable "quiet" is used
  37.     as follows.  Warning messages are suppressed if quiet > 1;  error
  38.     messages are suppressed if quiet > 2.  Fatal error messages are 
  39.     never suppressed--doing so would be a bit risky.
  40.  
  41.    For warnings and errors, the error message is preceded by the "WARNING:"
  42.    or "ERROR".  The error message is printed and control returns to the
  43.    caller.
  44.  
  45.    For fatal errors, the error message is preceded by "FATAL:" and an
  46.    error message is printed.  If the option was 'f', the program exits with 
  47.    a status of 1.  If the option was 'F', control returns to the caller and 
  48.    it is assumed that the caller will do any cleaning up necessary and then 
  49.    exit with an error status.
  50.  
  51.    parameter 2:  The format control string for printf.   
  52.    parameters 3 and 4 are passed along to printf.
  53.  
  54.     NOTE
  55.    (a) printf() is always supplied parameters 3 through 6, even if they 
  56.     were not on the parameter list passed to prterror().  It is assumed 
  57.     that printf() will only use as many as are specified by the format 
  58.     string.  There is a small chance that on some machines, this will cause 
  59.     some kind of stack exception (e.g. if the hardware maintains tag 
  60.     bits in each word on the stack and doesn't allow certain types of 
  61.     data to be arbitrarily accessed).  This is just a theory so far.
  62.  
  63.     (b) Parameter passing relies on consecutive small parameters being
  64.     properly interpreted as a single larger parameter when needed.
  65.     Eventually var_args should be used, but not all systems probably
  66.     have it at the moment.
  67.  
  68.     (c) All messages, whether informative or error, are sent to standard
  69.     output via printf.  It might be a good idea to eventually send 'e' and
  70.     'f' class messages to the standard error stream.  Best would be
  71.     some way of telling if standard output and standard error are not
  72.     the same device, so that we could always send error messages to
  73.     standard error, and also duplicate them to standard output if 
  74.     different from standard error.  There seems to be no way
  75.     of doing this in the general case.
  76. */
  77.  
  78. extern int quiet;
  79.  
  80. /* These declarations must be equivalent to those in errors.i */
  81. char no_match[] = "No files matched.\n";
  82. char failed_consistency[] = "Archive header failed consistency check.\n";
  83. char invalid_header[] = "Invalid or corrupted archive.\n";
  84. char internal_error[]="Internal error.\n";
  85. char disk_full[]      = "I/O error or disk full.\n";
  86. char bad_directory[]  = "Directory entry in archive is invalid.\n";
  87. char no_memory[] = "Ran out of memory.\n";
  88. char too_many_files[] = "Some filenames ignored -- can only handle %d.\n";
  89. char packfirst[] = "Old format archive -- please pack first with P command.\n";
  90. char garbled[] = "Command is garbled.\n";
  91. char start_ofs[] = "Starting at %ld (offset %ld)\n";
  92.  
  93. #ifndef OOZ
  94. char wrong_version[]=
  95.    "Zoo %d.%d or later is needed to fully manipulate this archive.\n";
  96. char cant_process[] =
  97.    "The rest of the archive (%lu bytes) cannot be processed.\n";
  98. char option_ignored[] = "Ignoring option %c.\n";
  99. char inv_option[] = "Option %c is invalid.\n";
  100. char bad_crc[] = "\007Bad CRC, %s probably corrupted\n";
  101. #endif
  102.  
  103. #ifdef OOZ
  104. char could_not_open[] = "Could not open ";
  105. #else
  106. char could_not_open[] = "Could not open %s.\n";
  107. #endif
  108.  
  109. #ifdef LINT_ARGS
  110. /* defined in zoofns.h but we don't want to include that and waste time */
  111. void prterror (int, char *, MORE);
  112. void zooexit (int);
  113. #endif
  114.  
  115.  
  116. /*VARARGS2*/
  117. void prterror(level, format, a, b, c, d)
  118. register int level;
  119. char *format, *a, *b, *c, *d;
  120.  
  121. {
  122.    char string[120];       /* local format string */
  123.    *string = '\0';         /* get a null string to begin with */
  124.  
  125. #ifdef OOZ
  126.    strcpy (string, "Ooz:  ");
  127. #else
  128.    strcpy (string, "Zoo:  ");
  129. #endif
  130.  
  131.    switch (level) {
  132.       case 'M': *string = '\0';                    /* fall through to 'm' */
  133.       case 'm': if (quiet) return; break;
  134.       case 'w': 
  135.             if (quiet > 1) return;
  136.             strcat (string, "WARNING:  "); break;
  137.       case 'e': 
  138.             if (quiet > 2) return;
  139.             strcat (string, "ERROR:  ");   break;
  140.       case 'F':
  141.       case 'f': strcat (string, "FATAL:  ");   break;
  142.       default: prterror ('f', internal_error);  /* slick recursive call */
  143.    }
  144.  
  145.    strcat (string, format);      /* just append supplied message */
  146.  
  147.    printf (string, a, b, c, d);   /* and print the whole thing */
  148.     fflush (stdout);
  149.  
  150.    if (level == 'f')       /* and abort on fatal error 'f' but not 'F' */
  151.       zooexit (1);
  152. }
  153.