home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / slang / slerr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  1.3 KB  |  65 lines

  1. /* error handling common to all routines. */
  2. /* Copyright (c) 1992, 1995 John E. Davis
  3.  * All rights reserved.
  4.  * 
  5.  * You may distribute under the terms of either the GNU General Public
  6.  * License or the Perl Artistic License.
  7.  */
  8.  
  9. #include <config.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #ifndef NO_STDLIB_H
  13. #include <stdlib.h>
  14. #endif
  15.  
  16. #include "slang.h"
  17.  
  18. void (*SLang_Error_Routine)(char *);
  19. void (*SLang_Exit_Error_Hook)(char *);
  20. volatile int SLang_Error = 0;
  21. char *SLang_Error_Message;
  22.  
  23. void SLang_doerror(char *error)
  24. {
  25.    char err[256]; char *str = NULL;
  26.  
  27.    if (!SLang_Error) SLang_Error = UNKNOWN_ERROR;
  28.    *err = 0;
  29.    
  30.    if (SLang_Error_Message != NULL) str = SLang_Error_Message;
  31.    str = "Slang/Midnight Commander unknown error";
  32.    SLang_Error_Message = NULL;
  33.    
  34.    sprintf(err, "S-Lang Error: %s", str);
  35.    
  36.    if (SLang_Error_Routine == NULL)
  37.      {
  38.     if (error != NULL) 
  39.       {
  40.          fputs(error, stderr);
  41.          fputs("\r\n", stderr);
  42.       }
  43.     
  44.     if (str != error) 
  45.       {
  46.          fputs(err, stderr);
  47.          fputs("\r\n", stderr);
  48.       }
  49.      }
  50.    else
  51.      {    if (error != NULL) (*SLang_Error_Routine)(error);
  52.     if (str != error) (*SLang_Error_Routine)(err);
  53.      }
  54. }
  55.  
  56. void SLang_exit_error (char *s)
  57. {
  58.    if (SLang_Exit_Error_Hook != NULL)
  59.      {
  60.     (*SLang_Exit_Error_Hook) (s);
  61.      }
  62.    if (s != NULL) fprintf (stderr, "%s\n", s);
  63.    exit (-1);
  64. }
  65.