home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spiele Shareware / os2games.iso / os2games / addons / gi / c / tools / error.cpp next >
Encoding:
C/C++ Source or Header  |  1993-04-15  |  3.6 KB  |  143 lines

  1. /*-------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   ERROR.CPP  : Allgemeine Fehler-Basis-Klasse                           */
  4. /*                                                                         */
  5. /*   Version    : V2.00                                                    */
  6. /*                                                                         */
  7. /*   Date       : 15.10.91                                                 */
  8. /*                                                                         */
  9. /*   Copyright  : RF for Animal                                            */
  10. /*                                                                         */
  11. /*-------------------------------------------------------------------------*/
  12. /*
  13.     History:
  14.  
  15.     16.08.91    RF  Neu-Design
  16.     30.09.91    RF    Falls in " eingekleidet, wird nur dies ausgegeben
  17.     15.10.92    RF    Als Klasse    
  18.     20.10.92    RF    ErrorShow gibt Pointer auf globale Variable
  19.     15.04.93    MH  Portierung auf 32 Bit
  20. */
  21. #define INCL_DOSMISC
  22. #define INCL_DOSPROCESS
  23. #include <os2.h>
  24. #include <error.hpp>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28.  
  29. #define MAXLINE        200
  30. /*-------- Globals ---------------------------------------------------------*/
  31. const char  *set    = "ERRORFILE";        // Name der Environmentvariablen
  32. char        unknown[20]    = "Error: ";
  33. const  char    white[]    = { 32, 9, 10, 11, 12, 13, 0 };
  34. char        line[MAXLINE];
  35.  
  36. /*--------------------------------------------------------------------------*/
  37. char *ErrorInit ()
  38.     {
  39.     PPIB ppib;
  40.     PTIB ptib;
  41.     char        *env;
  42.  
  43.     DosGetInfoBlocks (&ptib, &ppib);
  44.     env = ppib->pib_pchenv;
  45.     while (*env)
  46.         {
  47.         strupr (env);
  48.         if (strncmp (env, set, strlen(set)) == 0)
  49.             return (strchr (env, '=')+1);
  50.  
  51.         env += strlen(env)+1;
  52.         }
  53.     return (NULL);
  54.     }
  55. /*--------------------------------------------------------------------------*/
  56. unsigned GetNum (char *line)
  57.     {
  58.     int     num=0;
  59.     char    *p;
  60.     char    bakline[MAXLINE];
  61.  
  62.     strcpy (bakline, line);
  63.  
  64.     /*---- Skip leading spaces ----*/
  65.     strtok (bakline, white);
  66.  
  67.     /*---- Process word ----*/
  68.     do
  69.         {
  70.         p = strtok (NULL, white);
  71.         }
  72.     while (p && (num = atoi (p)) == 0);
  73.  
  74.     return (num);
  75.     }
  76. /*--------------------------------------------------------------------------*/
  77. char *GetText (char *line)
  78.     {
  79.     char    *s1, *s2;
  80.     
  81.     s1 = strchr (line, 0x22);
  82.     if (s1)
  83.         {
  84.         s1++;
  85.         s2 = strchr (s1, 0x22);
  86.         if (s2)
  87.             {
  88.             *s2=0x00;
  89.             return (s1);
  90.             }
  91.         }
  92.     return (line);
  93.     }
  94. /*--------------------------------------------------------------------------*/
  95. char *ScanFile (char *filename, unsigned no)
  96.     {
  97.     FILE    *f;
  98.  
  99.     if ((f = fopen (filename, "r")) == NULL)
  100.         return (NULL);
  101.  
  102.     
  103.  
  104.     fgets (line, MAXLINE, f);
  105.  
  106.     while (!feof (f) && GetNum (line) != no)
  107.         fgets (line, MAXLINE, f);
  108.  
  109.     if (feof (f))
  110.         return (NULL);
  111.  
  112.     fclose (f);
  113.     return (GetText (line));
  114.     }
  115. /*--------------------------------------------------------------------------*/
  116. char *ErrorShow (unsigned num)
  117.     {
  118.     char    *nl, *nr, *out;
  119.     
  120.     nl = ErrorInit ();
  121.     if (!nl)
  122.         return (itoa(num, &unknown[7], 10));
  123.  
  124.     nr = strchr (nl, ';');
  125.     while (nr)
  126.         {
  127.         *nr=0x00;
  128.         out = ScanFile (nl, num);
  129.         if (out)
  130.             return (out);
  131.             
  132.         nl = nr+1;
  133.         nr = strchr (nl, ';');
  134.         }
  135.     out = ScanFile (nl, num);
  136.     if (out)
  137.         return (out);
  138.         
  139.     return (itoa(num, &unknown[7], 10));
  140.     }
  141. /*--------------------------------------------------------------------------*/
  142.  
  143.