/*****************************************************************************/ /* */ /* UNIT: NTL1_Print_Error (Level 1 library routine) */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 28 JUN 94 Version 1.0 */ /* */ /* Function: */ /* */ /* Procedure receives an error buffer of predefined structure and outputs */ /* its contents in human-readable form. In addition, if the kind of error is */ /* "FATAL", it forcibly terminates the program */ /* */ /*****************************************************************************/ #include #include #include "ntl1.h" /*****************************************************************************/ errind NTL1_Print_Error (errind error_buffer) { if (error_buffer != NULL) { /* So there is some error to be reported */ fprintf (stderr, "------------------------------------------------------\n"); switch (error_buffer -> kind) { case SYSTEM_ERROR: { fprintf (stderr, "Error type: SYSTEM Error code: "); break; } case FATAL_ERROR: { fprintf (stderr, "Error type: FATAL Error code: "); break; } case USER_ERROR: { fprintf (stderr, "Error type: ERROR Error code: "); break; } case WARNING: { fprintf (stderr, "Error type: WARNING Error code: "); break; } default: { fprintf (stderr, "PROBLEM: Unknown error type (%d) in print.\n", error_buffer -> kind); exit (1); /* If trouble in code detected in error reporting, no choice */ } } if (error_buffer -> code == -1) fprintf (stderr, "ERR_NO_FILE\n"); else if (error_buffer -> code == -2) fprintf (stderr, "ERR_FILE_FORMAT\n"); else if (error_buffer -> code == -3) fprintf (stderr, "ERR_BUFFER_OVERFLOW\n"); else if (error_buffer -> code == -4) fprintf (stderr, "ERR_ILLEGAL_INVOCATION\n"); else if (error_buffer -> code == -5) fprintf (stderr, "ERR_BAD_STRUCTURE\n"); else if (error_buffer -> code == -6) fprintf (stderr, "ERR_ILLEGAL_CODE\n"); else if (error_buffer -> code == -7) fprintf (stderr, "ERR_BAD_REFERENCE\n"); else if (error_buffer -> code == -8) fprintf (stderr, "ERR_NO_VALUE\n"); else if (error_buffer -> code == -9) fprintf (stderr, "ERR_BAD_VALUE\n"); else fprintf (stderr, "ERR_UNKNOWN\n"); if (error_buffer -> message != NULL) { fprintf (stderr, "DESCRIPTION: %s\n", error_buffer -> message); free (error_buffer -> message); error_buffer -> message = NULL; } fprintf (stderr, "Error description code: %d\n", error_buffer -> description); fprintf (stderr, "------------------------------------------------------\n"); /* Decide on the kind of reported error whether program should terminate */ if ((error_buffer -> kind == SYSTEM_ERROR) || (error_buffer -> kind == FATAL_ERROR)) exit (1); else { free (error_buffer); return NULL; /* Indicate release of the error buffer */ } } }