home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / util / boot / yourfault / src / getdeferrors.c next >
Encoding:
C/C++ Source or Header  |  1995-06-09  |  1.9 KB  |  84 lines

  1. #include <exec/types.h>
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <string.h>
  5.  
  6. /* proto and pragma for dosPrivate5...
  7.  * dosPrivate5 is now refered to as "InternalFault()" from now on...
  8.  */
  9. STRPTR InternalFault(LONG code);
  10. #pragma libcall DOSBase InternalFault 3d2 101
  11.  
  12. /* file to which the strings are output... */
  13. #define FILENAME "DefErrors.fault"
  14.  
  15. /* Minimum error code to test */
  16. #define MIN_ERROR -300
  17.  
  18. /* Maximum error code to test */
  19. #define MAX_ERROR 500
  20.  
  21. void main( void )
  22. {
  23.     STRPTR s2;
  24.     
  25.     if (DOSBase->dl_lib.lib_Version < 36)
  26.         return;
  27.     
  28.     /* Alloc a string buffer */
  29.     if( s2 = AllocVec(1024, MEMF_CLEAR) )
  30.     {
  31.         BPTR outfile;
  32.         if( outfile = Open(FILENAME, MODE_NEWFILE) )
  33.         {
  34.             LONG n;
  35.             STRPTR s, outs;
  36.             /* print a header */
  37.             FPrintf(outfile, "#\n"
  38.                              "# FaultStrings file created by GetDefErrors\n"
  39.                              "# for use with YourFault, ©Lee Kindness.\n"
  40.                              "#\n"
  41.                              "#\n");
  42.     
  43.             /* test all codes between MIN_ERROR and MAX_ERROR */
  44.             for(n = MIN_ERROR; n <= MAX_ERROR; n++)
  45.             {
  46.                 if( s = InternalFault(n))
  47.                 {
  48.                     /* valid error string... */
  49.  
  50.                     /* check if the string contains any '\n' */
  51.                     if( strchr(s, '\n' ) )
  52.                     {
  53.                         STRPTR temps;
  54.                         #define FINDCHAR '\n'
  55.                         #define REPLACECHAR '^'
  56.  
  57.                         
  58.                         /* copy the string... */
  59.                         strcpy(s2, s);
  60.                         /* replace all FINDCHAR */
  61.                         temps = s2;
  62.                         while(*temps != '\0')
  63.                         {
  64.                             if(*temps == FINDCHAR)
  65.                                 *temps = REPLACECHAR;
  66.                             temps++;
  67.                         }
  68.                         outs = s2;
  69.                     } else
  70.                         outs = s;
  71.                     
  72.                     /* output a comment above it with number */
  73.                     /* output the actual number:string */
  74.                     /* and space the output with a comment line */
  75.                     FPrintf(outfile, "#\t(%ld)\n"
  76.                                      "%ld:%s\n"
  77.                                      "#\n", n, n, outs);
  78.                 }
  79.             }
  80.             Close(outfile);
  81.         }
  82.         FreeVec(s2);
  83.     }
  84. }