00001
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <errno.h>
00015 #include <string.h>
00016
00017 #include "CTB.hxx"
00018 #include "CTBretcode.hxx"
00019
00056
00058
00059 static bool text_defined(const char* c_text)
00060 {
00061 return c_text && c_text[0];
00062 }
00063
00064
00066
00067 static void print_message(ostream& os, const char* c_pref, const char* c_text)
00068 {
00069 CTBint i_len = strlen(c_text);
00070
00071 os << c_pref;
00072 os << c_text;
00073
00074 if (i_len > 0 && c_text[i_len-1] != '\n') os << endl;
00075 return;
00076 }
00077
00078
00080
00096 void CTBretcode::ToStream(ostream& os) const
00097 {
00098 if (!text_defined(mc_text1) && mi_errno == 0) {
00099 os << "Return code: " << mi_code << endl;
00100
00101 } else {
00102 if (!text_defined(mc_text1)) {
00103 print_message(os,"",strerror(mi_errno));
00104
00105 } else {
00106 print_message(os,"",mc_text1);
00107 if (text_defined(mc_text2)) {
00108 print_message(os,"- ",mc_text2);
00109 if (text_defined(mc_text3)) {
00110 print_message(os,"- ",mc_text3);
00111 }
00112 }
00113 if (mi_errno != 0) {
00114 print_message(os,"",strerror(mi_errno));
00115 }
00116 }
00117 }
00118 return;
00119 }
00120
00121
00123
00132 CTBretcode::operator const char* () const
00133 {
00134 const char* c_text = 0;
00135
00136 if (mi_code) {
00137 if (text_defined(mc_text1)) {
00138 c_text = mc_text1;
00139 } else {
00140 c_text = (mi_errno != 0) ? strerror(mi_errno) : "";
00141 }
00142 }
00143
00144 return c_text;
00145 }
00146
00147
00148
00149 #if (defined(CTB__OutLine) || defined(CTBretcode__OutLine))
00150 #define inline
00151 #include "CTBretcode.icc"
00152 #undef inline
00153 #endif