home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-1.ZIP / SOURCE.ZIP / U4ERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-10  |  5.7 KB  |  235 lines

  1.  
  2. /* u4error.c   (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
  3.  
  4.    Prints all error messages.
  5.    Only routine where 'printf' is called.
  6.    Exits for all errors.
  7.    Adjust for a different error routine.
  8. */
  9.  
  10. #include "u4error.h"
  11.  
  12. #ifdef  WINDOWS_L
  13.    #define  WINDOWS
  14. #endif
  15. #ifdef  WINDOWS_G
  16.    #define  WINDOWS
  17. #endif
  18.  
  19. int  v4error ;
  20.  
  21. #ifdef WINDOWS
  22.    /* Microsoft Windows Error Handling */
  23.  
  24.    #include "windows.h"
  25.  
  26.    u4error( error_num )
  27.    int   error_num ;
  28.    {
  29.       v4error =  error_num ;
  30.       if (  error_num == E_INTERNAL )
  31.          FatalExit( error_num ) ;
  32.  
  33.       return( 0 ) ;
  34.    }
  35.  
  36. #else
  37.  
  38. #include "d4base.h"
  39. #include "w4.h"
  40.  
  41. #include <stdlib.h>
  42. #if defined(TURBO)
  43.    #include <stdarg.h>
  44. #else
  45.    #include <varargs.h>
  46. #endif
  47.  
  48. #ifndef UNIX
  49.    #include <io.h>
  50. #endif
  51.  
  52. #ifndef  NOIO
  53.    extern int  v4default_window ;
  54. #endif
  55.  
  56. #define  C_LEFT   10
  57.  
  58. typedef struct
  59. {
  60.    int   error_num ;
  61.    char *error_data ;
  62. }  ERROR_DATA ;
  63.  
  64. ERROR_DATA error_data[] =
  65. {
  66.    /* General Disk Access Errors */
  67.    { E_CREATE,    "Creating File" },
  68.    { E_OPEN,      "Opening File" },
  69.    { E_READ,      "Reading from File" },
  70.    { E_WRITE,     "Writing to File" },
  71.    { E_CLOSE,     "Closing File" },
  72.  
  73.    /* Database Specific Errors */
  74.    { E_BAD_DBF,   "File is not a Database:" },
  75.    { E_D_MISSING, "No Open Database" },
  76.    { E_REC_LENGTH,"Record Length is Too Large" },
  77.    { E_CHANGE_SIZE,"Changing Database Size" },
  78.  
  79.    /* Index File Specific Errors */
  80.    { E_INDEX,     "Building Index File" }, 
  81.    { E_I_CLOSE,   "Closing Index File" }, 
  82.    { E_BAD_NDX,   "File is not an Index File" },
  83.    { E_I_MISSING, "Index File is Missing a Key" },
  84.    { E_I_RECORD,  "Index File Record does not Exist" },
  85.    { E_UNIQUE,    "Key is not Unique" },
  86.    { E_I_TYPE,    "Key Evaluates to Logical Result" },
  87.    { E_I_CHANGED, "Key Length or Type has Changed" },
  88.    { E_KEY_LEN,   "Key Length over 100 Characters" },
  89.    { E_NO_INDEX,  "Seek on Database with no Index File" },
  90.  
  91.    /* Multi-User Errors */
  92.    { E_LOCK,      "Locking a File" },
  93.    { E_UNLOCK,    "Unlocking a File" },
  94.  
  95.    /* Expression Evaluation Errors */
  96.    { E_BASE_NAME, "Database not Located while Evaluating Expression" },
  97.    { E_COMPILE_NULL, "Executing Null Expression" },
  98.    { E_EXPECT,    "Expecting \",\" or \")\" while Evaluating Expression" },
  99.    { E_COMPLETE,  "Expression is not Complete" },
  100.    { E_DATE,      "Illegal Date" },
  101.    { E_OVERFLOW,  "Overflow while Evaluating Expression" },
  102.    { E_TYPE,      "Parameter or Operator has the Wrong Type" },
  103.    { E_RIGHT,     "Right Bracket Missing in Expression" },
  104.    { E_FUNCTION,  "Unrecognized Function in Expression" },
  105.    { E_OPERATOR,  "Unrecognized Operator in Expression" },
  106.    { E_VALUE,     "Unrecognized Value in Expression"} ,
  107.    { E_STRING_LONG,"Unterminated String in Expression"} ,
  108.  
  109.    /* Memo File Errors */
  110.    { E_EDITOR,    "Editing Memo File with Editor"} ,
  111.    { E_MEMO_NAME, "Memo File Name Inconsistency"} ,
  112.    { E_MEMO_SIZE, "Memo File Entry is over 32767 Bytes"},
  113.  
  114.    /* Windowing and Menuing Errors */
  115.    { E_WINDOW_REF,"Illegal Window Reference Number"},
  116.  
  117.    /* Extended Routine Errors */
  118.    { E_RELATING,  "Relating Databases" } ,
  119.    { E_CONTROL,   "No Controlling Database" } ,
  120.    { E_RELATED,   "Illegal Related Database" } ,
  121.  
  122.    /* Memory Error */
  123.    { E_MEMORY,    "Out of Memory"} ,
  124.    { E_ALLOCATE,  "Memory Allocation Error"} ,
  125.  
  126.    /* Internal Error */
  127.    { E_INTERNAL,  "Overwritten Memory"} ,
  128. } ;
  129.  
  130. void  error_out( char * ) ;
  131.  
  132. #ifdef  NOIO
  133.    void  error_out( ptr )
  134.    char *ptr ;
  135.    {
  136.       write( 0, "\n", 1 ) ;
  137.       write( 0, ptr, strlen(ptr) ) ;
  138.    }
  139. #endif
  140.  
  141. #ifdef TURBO
  142.    u4error( error_num, msg )
  143.    int   error_num ;
  144.    char *msg ;
  145. #else
  146.    u4error( error_num, va_alist )
  147.    int   error_num ;
  148.    va_dcl
  149. #endif
  150. {
  151.    int      keyboard, i, start_window ;
  152.    va_list  arg_marker  ;
  153.    char    *ptr ;
  154.  
  155.    #ifdef NOIO
  156.       char  buffer[40] ;
  157.    #endif
  158.  
  159.    v4error    =  error_num ;
  160.  
  161.    #ifdef NOIO
  162.       error_out( "Error Number: " ) ;
  163.       ltoa( (long) error_num, buffer, 10 ) ;
  164.       error_out( buffer ) ;
  165.       error_out( "" ) ;
  166.    #else
  167.       if ( v4default_window < 0 )
  168.       {
  169.      write( 0, "\nError Number: 980, No Error Window", 35 ) ;
  170.      w4exit(1) ;
  171.       }
  172.  
  173.       start_window =  w4select(-1) ;
  174.       w4activate( v4default_window ) ;
  175.       w4clear( 0 ) ;
  176.       w4( w4row()+1, C_LEFT, "Error Number:") ;
  177.       w4int( w4row(), w4col(), error_num, 7 ) ;
  178.       w4position( w4row()+1, C_LEFT) ;
  179.    #endif
  180.  
  181.    for ( i=0; i < sizeof(error_data)/sizeof(ERROR_DATA); i++ )
  182.       if ( error_data[i].error_num == error_num )
  183.       {
  184.      #ifdef NOIO
  185.         error_out( error_data[i].error_data ) ;
  186.      #else
  187.         w4( w4row()+1, C_LEFT, error_data[i].error_data ) ;
  188.      #endif
  189.      break ;
  190.       }
  191.  
  192.    #ifdef  TURBO
  193.       va_start( arg_marker, msg ) ;
  194.       ptr =  msg ;
  195.    #else
  196.       va_start( arg_marker ) ;
  197.       ptr =  va_arg(arg_marker, char *) ;
  198.    #endif
  199.  
  200.    for (; ptr != (char *) 0; ptr =  va_arg(arg_marker, char *))
  201.    {
  202.       #ifdef NOIO
  203.      error_out( ptr ) ;
  204.       #else
  205.      w4( w4row()+1, C_LEFT, ptr ) ;
  206.       #endif
  207.    }
  208.  
  209.    #ifdef NOIO
  210.       error_out( "Press a key ..." ) ;
  211.       keyboard =  getch() ;
  212.    #else
  213.       w4( w4row()+2, C_LEFT, "Press a key ...") ;
  214.       w4cursor( w4row(), w4col() ) ;
  215.       keyboard =  g4char() ;
  216.       w4cursor( -1,-1 ) ;
  217.    #endif
  218.  
  219.    if ( error_num == E_MEMORY || error_num == E_INTERNAL || error_num == E_ALLOCATE )
  220.    #ifdef NOIO
  221.       exit( 1 ) ;
  222.    #else
  223.       w4exit( 1 ) ;
  224.    #endif
  225.  
  226.    #ifndef NOIO
  227.       w4deactivate( v4default_window ) ;
  228.       w4select( start_window ) ;
  229.    #endif
  230.  
  231.    return( keyboard ) ;
  232. }
  233.  
  234. #endif
  235.