Back to index

im-sdk  12.3.91
perror.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #if defined(HAVE_DGETTEXT) && defined(HAVE_LIBINTL_H)
00003 #include <libintl.h>
00004 #endif /* HAVE_DGETTEXT && HAVE_LIBINTL_H */
00005 
00006 #include <iiimp.h>
00007 
00008 
00009 #if defined(HAVE_DGETTEXT)
00010 #define IIIMF_MESSAGE_DOMAIN       "libiiimf"
00011 #endif /* HAVE_DGETTEXT */
00012 
00013 
00014 static const char *
00015 status_string(IIIMF_status status)
00016 {
00017     switch (status) {
00018     case IIIMF_STATUS_FAIL:
00019        return "fail";
00020     case IIIMF_STATUS_SUCCESS:
00021        return "success";
00022 
00023     case IIIMF_STATUS_MALLOC:
00024        return "memory allocation error";
00025     case IIIMF_STATUS_ARGUMENT:
00026        return "argument error";
00027 
00028     case IIIMF_STATUS_CONFIG:
00029        return "configuration error";
00030     case IIIMF_STATUS_ROLE:
00031        return "role violation";
00032 
00033     case IIIMF_STATUS_OPCODE:
00034        return "invalid opcode";
00035     case IIIMF_STATUS_SEQUENCE_REQUEST:
00036        return "sequence: request error";
00037     case IIIMF_STATUS_SEQUENCE_REPLY:
00038        return "sequence: reply error";
00039     case IIIMF_STATUS_SEQUENCE_ROLE:
00040        return "sequence: role error";
00041     case IIIMF_STATUS_SEQUENCE_STATE:
00042        return "sequence: state error";
00043     case IIIMF_STATUS_SEQUENCE_NEST:
00044        return "sequence: message nesting level exeeds the limit";
00045 
00046     case IIIMF_STATUS_IM_INVALID:
00047        return "invalid IM";
00048 
00049     case IIIMF_STATUS_STREAM:
00050        return "stream error";
00051     case IIIMF_STATUS_STREAM_SEND:
00052        return "stream send error";
00053     case IIIMF_STATUS_STREAM_RECEIVE:
00054        return "stream receive error";
00055     case IIIMF_STATUS_PACKET:
00056        return "packet error";
00057     case IIIMF_STATUS_INVALID_ID:
00058        return "invalid ID";
00059     case IIIMF_STATUS_TIMEOUT:
00060        return "timeout";
00061 
00062     default:
00063        return "unknown";
00064     }
00065 }
00066 
00067 
00068 void
00069 iiimf_perror(IIIMF_status status, const char * str)
00070 {
00071     const char *     p;
00072 #if defined(HAVE_DGETTEXT) && defined(IIIMF_MESSAGE_DIRNAME)
00073     char *           dirname;
00074 #endif /* HAVE_DGETTEXT && IIIMF_MESSAGE_DIRNAME */
00075 
00076     p = status_string(status);
00077 
00078 #if defined(HAVE_DGETTEXT)
00079 #if defined(IIIMF_MESSAGE_DIRNAME)
00080     dirname = bindtextdomain(IIIMF_MESSAGE_DOMAIN, NULL);
00081     bindtextdomain(IIIMF_MESSAGE_DOMAIN, IIIMF_MESSAGE_DIRNAME);
00082 #endif /* IIIMF_MESSAGE_DOMAIN */
00083     p = dgettext(IIIMF_MESSAGE_DOMAIN, p);
00084 #endif /* HAVE_DGETTEXT */
00085 
00086     if ((NULL == str) || ('\0' == *str)) {
00087        (void)fprintf(stderr, "%s\n", p);
00088     } else {
00089        (void)fprintf(stderr, "%s: %s\n", str, p);
00090     }
00091 
00092 #if defined(HAVE_DGETTEXT) && defined(IIIMF_MESSAGE_DIRNAME)
00093     if (NULL != dirname) {
00094        bindtextdomain(IIIMF_MESSAGE_DOMAIN, dirname);
00095     }
00096 #endif /* HAVE_DGETTEXT && IIIMF_MESSAGE_DOMAIN */
00097 
00098     return;
00099 }
00100 
00101 
00102 /* Local Variables: */
00103 /* c-file-style: "iiim-project" */
00104 /* End: */