home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / YourFaultv1r2.lha / YourFault / Source.LhA / src / GetDefErrors.c next >
Encoding:
C/C++ Source or Header  |  1995-06-07  |  1.6 KB  |  74 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. void main( void )
  16. {
  17.     LONG n;
  18.     STRPTR s, s2, outs;
  19.     BPTR outfile;
  20.     
  21.     if (DOSBase->dl_lib.lib_Version < 36)
  22.         return;
  23.     
  24.     /* Alloc a string buffer */
  25.     if( s2 = AllocVec(1024, MEMF_CLEAR) )
  26.     {
  27.         if( outfile = Open(FILENAME, MODE_NEWFILE) )
  28.         {
  29.             /* print a header */
  30.             FPrintf(outfile, "#\n"
  31.                              "# FaultStrings file created by GetDefErrors\n"
  32.                              "# for use with YourFault, ©Lee Kindness.\n"
  33.                              "#\n"
  34.                              "#\n");
  35.     
  36.             /* test all codes between -200 and 400 */
  37.             for(n = -200; n <= 400; n++)
  38.             {
  39.                 if( s = InternalFault(n))
  40.                 {
  41.                     /* valid error string... */
  42.  
  43.                     /* check if the string contains any '\n' */
  44.                     if( strchr(s, '\n' ) )
  45.                     {
  46.                         STRPTR temps;
  47.                         
  48.                         /* copy the string... */
  49.                         strcpy(s2, s);
  50.                         /* replace all \n */
  51.                         temps = s2;
  52.                         while(*temps != '\0')
  53.                         {
  54.                             if(*temps == '\n')
  55.                                 *temps = '^';
  56.                             temps++;
  57.                         }
  58.                         outs = s2;
  59.                     } else
  60.                         outs = s;
  61.                     
  62.                     /* output a comment above it with number */
  63.                     /* output the actual number:string */
  64.                     /* and space the output with a comment line */
  65.                     FPrintf(outfile, "#\t(%ld)\n"
  66.                                      "%ld:%s\n"
  67.                                      "#\n", n, n, outs);
  68.                 }
  69.             }
  70.             Close(outfile);
  71.         }
  72.         FreeVec(s2);
  73.     }
  74. }