home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / k95source / p_error.c < prev    next >
C/C++ Source or Header  |  2002-01-20  |  4KB  |  142 lines

  1. /*****************************************************************************/
  2. /*             Copyright (c) 1994 by Jyrki Salmi <jytasa@jyu.fi>             */
  3. /*        You may modify, recompile and distribute this file freely.         */
  4. /*****************************************************************************/
  5.  
  6. /*
  7.    Error routines used to report errors occurred in the P.DLL as well as
  8.    in the P.EXE.
  9. */
  10.  
  11. #include "ckcdeb.h"
  12. #ifndef NOXFER
  13. #include "ckcker.h"
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. #ifdef OS2
  20. #ifdef NT
  21. #include <windows.h>
  22. #define APIRET DWORD
  23. #else
  24. #define INCL_DOSMISC
  25. #include <os2.h>
  26. #undef COMMENT
  27. #include "ckocon.h"
  28. #endif /* OS2 */
  29. #endif /* NT */
  30.  
  31. #include "p_type.h"
  32. #include "p_errmsg.h"
  33. #include "ckcnet.h"
  34.  
  35. /* Report an error occurred in the OS/2 API */
  36.  
  37. VOID
  38. #ifdef CK_ANSIC
  39. os2_error(U32 num,
  40.                U32 ret_code,
  41.                U32 module,
  42.                U32 line_num,
  43.                U8 *opt_arg)
  44. #else
  45. os2_error(num,ret_code,module,line_num,opt_arg)
  46.      U32 num;
  47.      U32 ret_code;
  48.      U32 module;
  49.      U32 line_num;
  50.      U8 *opt_arg;
  51. #endif
  52. {
  53.  
  54.     UCHAR buf[4096];
  55.     UCHAR buf2[4096];
  56.  
  57. #ifdef OS2
  58. #ifdef NT
  59.     sprintf(buf, "Win32 Error %lu:%lu@%lu:%lu: %s",
  60.              num, ret_code,             /* First %lu:%lu */
  61.              module, line_num,          /* Second %lu:%lu */
  62.              os2_error_msg[num - 1]);
  63.     /* Show the verbal description */
  64.     sprintf(buf2, buf, opt_arg);
  65.  
  66.     if (ret_code != 0) {
  67.         ckstrncat(buf2,", Win32 reports: ",4096);
  68.         /* need to add format message call */
  69.         if ( FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  70.                             NULL,
  71.                             ret_code,
  72.                             MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
  73.                             buf,
  74.                             4096,
  75.                             (va_list *) NULL
  76.                             ) )
  77.         {
  78.             ckstrncat(buf2,buf,4096);
  79.         }
  80.         else
  81.         {
  82.             ckstrncat(buf2,"Couldn't read error message.",4096);
  83.         }
  84.     }
  85. #else /* not NT */
  86.     APIRET rc=0;
  87.     ULONG  msg_len=0;
  88.  
  89.     sprintf(buf, "OS/2 Error %lu:%lu@%lu:%lu: %s",
  90.              num, ret_code,             /* First %lu:%lu */
  91.              module, line_num,          /* Second %lu:%lu */
  92.              os2_error_msg[num - 1]);
  93.     /* Show the verbal description */
  94.     sprintf(buf2, buf, opt_arg);
  95.     if (ret_code != 0) {
  96.         ckstrncat(buf2,", OS/2 reports: ",4096);
  97.         rc = DosGetMessage(NULL,
  98.                             0,
  99.                             buf,
  100.                             4096,
  101.                             ret_code,
  102.                             "OSO001.MSG",
  103.                             &msg_len);
  104.         if (rc) {
  105.             ckstrncat(buf2,
  106.             "Couldn't read error message from file OSO001.MSG which is a part of OS/2 and usually located in \\OS2\\SYSTEM directory.",
  107.                        4096);
  108.         } else {
  109.             ckstrncat(buf2, buf,4096);
  110.         }
  111.     }
  112.  
  113. #endif /* NT */
  114.     debug(F110,"p_error",buf2,0);
  115.     ckscreen(SCR_ST,ST_ERR,0l,buf2);
  116. #endif /* OS2 */
  117. }
  118.  
  119. #ifdef XYZ_DLL
  120. /* Report an error occurred in the TCP/IP API */
  121.  
  122. VOID tcpip_error(U32 num,
  123.                  U32 ret_code,
  124.                  U32 module,
  125.                  U32 line_num,
  126.                  U8 *opt_arg) {
  127.  
  128.   fprintf(stderr, "\rTCP/IP Error %lu:%lu@%lu:%lu: ",
  129.           num, ret_code,                /* First %lu:%lu */
  130.           module, line_num);            /* Second %lu:%lu */
  131.   /* Show the verbal description */
  132.   fprintf(stderr, tcpip_error_msg[num - 0x30], opt_arg);
  133.   if (ret_code != 0) {
  134.     fprintf(stderr, ", API reports: %d\n\n",ret_code);
  135.   } else
  136.     fprintf(stderr, "\n");
  137.  
  138.   /*exit(1);*/
  139. }
  140. #endif /* XYZ_DLL */
  141. #endif /* NOXFER */
  142.