home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / U4ERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-19  |  6.0 KB  |  239 lines

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