home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / xpk / xpk_source / xpkmaster / fault.c < prev    next >
C/C++ Source or Header  |  1998-04-27  |  2KB  |  84 lines

  1. #ifndef XPKMASTER_FAULT_C
  2. #define XPKMASTER_FAULT_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        fault.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: fault.c 1.6 (26.03.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Error message generators
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   27.12.96 : added parts of Fault functions
  15.  1.2   28.12.96 : finished the two Fault functions
  16.  1.3   31.03.97 : added new error (XPKERR_UNKNOWN);
  17.  1.4   02.04.97 : renamed to fault.c, removed geterror
  18.  1.5   21.02.98 : uses new style register definition
  19.  1.6   26.03.98 : some optimizations and a bug fix
  20. */
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include "xpkmaster.h"
  25. #include "texts.h"
  26.  
  27. ASM(BOOL) LIBXpkPrintFault(REG(d0, LONG code), REG(a0, STRPTR header))
  28. {
  29.   STRPTR a[2], fmt = "%s: %s\n";
  30.  
  31.   if(code > 0 || code < MINERROR)
  32.     code = XPKERR_UNKNOWN;
  33.  
  34.   a[1] = XpkErrs[-code];
  35.  
  36.   if((a[code = 0] = header))
  37.   {
  38.     ++code; fmt += 4;
  39.   }
  40.  
  41.   if(VPrintf(fmt, &a[code]) == -1)
  42.     return 0;  /* error */
  43.   else
  44.     return -1; /* ok */
  45. }
  46.  
  47. ASM(ULONG) LIBXpkFault(REG(d0, LONG code), REG(a0, STRPTR header),
  48.     REG(a1, STRPTR buffer), REG(d1, ULONG size))
  49. {
  50.   ULONG ssize = 0;
  51.  
  52.   if(size > 1 && buffer)
  53.   {
  54.     STRPTR string;
  55.  
  56.     if(code > 0 || code < MINERROR)
  57.       code = XPKERR_UNKNOWN;
  58.  
  59.     string = XpkErrs[-code];
  60.  
  61.     if((ssize = strlen(string)) > --size) /* remove 1 for 0-byte from size */
  62.       ssize = size;
  63.     size -= ssize;
  64.  
  65.     if(header && (code = strlen(header)) + 2 <= size)
  66.     {
  67.       CopyMem(header, buffer, code);
  68.       buffer[code++] = ':';
  69.       buffer[code++] = ' ';
  70.       buffer += code;
  71.     }
  72.     else
  73.       code = 0;
  74.  
  75.     CopyMem(string, buffer, ssize);
  76.     buffer[ssize] = 0;
  77.     ssize += code;
  78.   }
  79.  
  80.   return ssize;
  81. }
  82.  
  83. #endif /* XPKMASTER_FAULT_C */
  84.