Index: 1.3.1-release.6/src/prcserror.cc *** 1.3.1-release.6/src/prcserror.cc Fri, 26 Apr 2002 18:24:52 +0400 jmacd (prcs/1_prcserror.cc 1.8.1.11.1.3.1.7.1.11.2.2 644) --- 1.3.1-release.6(w)/src/prcserror.cc Fri, 26 Apr 2002 18:26:45 +0400 jmacd (prcs/1_prcserror.cc 1.8.1.11.1.3.1.7.1.11.2.2 644) *************** *** 52,59 **** stdiobuf stdout_stream(STDOUT_FILENO); stdiobuf stderr_stream(STDERR_FILENO); #else ! stdiobuf stdout_stream(stdout); ! stdiobuf stderr_stream(stderr); #endif /* if defined(__APPLE__) */ strstreambuf query_stream; --- 52,59 ---- stdiobuf stdout_stream(STDOUT_FILENO); stdiobuf stderr_stream(STDERR_FILENO); #else ! filebuf stdout_stream(stdout, ios::out); ! filebuf stderr_stream(stderr, ios::out); #endif /* if defined(__APPLE__) */ strstreambuf query_stream; *************** *** 101,117 **** { line_buffer.append(c); if(isspace(c)) ! xsputn(NULL, 0); return 1; } int PrettyStreambuf::xsputn(const char* s0, int n0) { - #ifndef __GNUG__ - # define xsputn sputn - #endif - if (dont_print && *dont_print) return n0; --- 101,113 ---- { line_buffer.append(c); if(isspace(c)) ! sputn(NULL, 0); return 1; } int PrettyStreambuf::xsputn(const char* s0, int n0) { if (dont_print && *dont_print) return n0; *************** *** 137,147 **** if(!new_line) { for(int j = prefix.length(); j; j -= 1) { ! forward->xsputn(" ", 1); col += 1; } } else { ! forward->xsputn(prefix.cast(), prefix.length()); col += prefix.length(); } --- 133,143 ---- if(!new_line) { for(int j = prefix.length(); j; j -= 1) { ! forward->sputn(" ", 1); col += 1; } } else { ! forward->sputn(prefix.cast(), prefix.length()); col += prefix.length(); } *************** *** 161,208 **** if(wordlen == 0) { if(*s == '\n' || (col + 1 > width)) { new_line = false; ! forward->xsputn("\n", 1); advance_buffer(s, n, col, 1); col = 0; } else { ! forward->xsputn(s, 1); advance_buffer(s, n, col, 1); } } else if(wordlen + col <= width) { ! forward->xsputn(s, wordlen); advance_buffer(s, n, col, wordlen); } else if((wordlen + prefix.length() >= width) && (col == prefix.length())) { ! forward->xsputn(s, wordlen); advance_buffer(s, n, col, wordlen); } else if(wordlen == 1 && col == width) { new_line = false; ! forward->xsputn(s, 1); advance_buffer(s, n, col, wordlen); ! forward->xsputn("\n", 1); col = 0; } else { new_line = false; ! forward->xsputn("\n", 1); col = 0; } } } return n; - - #ifndef __GNUG__ - # undef xsputn - #endif } int PrettyStreambuf::sync() { ! xsputn(NULL, 0); ! #ifdef __GNUG__ ! return forward->sync(); ! #else return forward->pubsync(); - #endif } static int tty_width(int fileno) --- 157,196 ---- if(wordlen == 0) { if(*s == '\n' || (col + 1 > width)) { new_line = false; ! forward->sputn("\n", 1); advance_buffer(s, n, col, 1); col = 0; } else { ! forward->sputn(s, 1); advance_buffer(s, n, col, 1); } } else if(wordlen + col <= width) { ! forward->sputn(s, wordlen); advance_buffer(s, n, col, wordlen); } else if((wordlen + prefix.length() >= width) && (col == prefix.length())) { ! forward->sputn(s, wordlen); advance_buffer(s, n, col, wordlen); } else if(wordlen == 1 && col == width) { new_line = false; ! forward->sputn(s, 1); advance_buffer(s, n, col, wordlen); ! forward->sputn("\n", 1); col = 0; } else { new_line = false; ! forward->sputn("\n", 1); col = 0; } } } return n; } int PrettyStreambuf::sync() { ! sputn(NULL, 0); return forward->pubsync(); } static int tty_width(int fileno) *************** *** 220,232 **** void re_query() { - #ifdef __GNUG__ - stdout_stream.xsputn(re_query_message, re_query_len); - stdout_stream.sync(); - #else stdout_stream.sputn(re_query_message, re_query_len); stdout_stream.pubsync(); - #endif } void continue_handler(SIGNAL_ARG_TYPE) --- 208,215 ---- *************** *** 324,334 **** { PrettyStreambuf& ps = ((PrettyOstream&)o).ostreambuf(); - #ifdef __GNUG__ - ps.xsputn(NULL, 0); - #else ps.sputn(NULL, 0); - #endif ps.set_column(col); return o; --- 307,313 ---- *************** *** 389,395 **** Dstring spaces(' ', diff); bool cb = set_fill_break(false); ! xsputn(spaces.cast(), diff); set_fill_break(cb); return col0; --- 368,374 ---- Dstring spaces(' ', diff); bool cb = set_fill_break(false); ! sputn(spaces.cast(), diff); set_fill_break(cb); return col0; *************** *** 405,418 **** { PrettyStreambuf &ps = ((PrettyOstream&)s).ostreambuf(); - #ifdef __GNUG__ - ps.xsputn("\n", 1); - #else ps.sputn("\n", 1); - #endif ps.reset_column(); return s; } --- 384,395 ---- { PrettyStreambuf &ps = ((PrettyOstream&)s).ostreambuf(); ps.sputn("\n", 1); ps.reset_column(); + ps.pubsync (); + return s; } *************** *** 420,433 **** { PrettyStreambuf &ps = ((PrettyOstream&)s).ostreambuf(); - #ifdef __GNUG__ - ps.xsputn(".\n", 2); - #else ps.sputn(".\n", 2); - #endif ps.reset_column(); return s; } --- 397,408 ---- { PrettyStreambuf &ps = ((PrettyOstream&)s).ostreambuf(); ps.sputn(".\n", 2); ps.reset_column(); + ps.pubsync (); + return s; } *************** *** 439,444 **** --- 414,421 ---- ps.reset_column(); + ps.pubsync (); + return s; } *************** *** 454,465 **** /* QueryOstream */ QueryOstream::QueryOstream(strstreambuf* base_stream0, PrettyStreambuf* query_stream0, ! stdiobuf* stdout_stream0, ! stdiobuf* stderr_stream0) ! : ! #ifndef __GNUG__ ! ios(query_stream0), ! #endif PrettyOstream(query_stream0, NoError), base_stream(base_stream0), query_stream(query_stream0), --- 431,439 ---- /* QueryOstream */ QueryOstream::QueryOstream(strstreambuf* base_stream0, PrettyStreambuf* query_stream0, ! filebuf *stdout_stream0, ! filebuf *stderr_stream0) ! :ios(query_stream0), PrettyOstream(query_stream0, NoError), base_stream(base_stream0), query_stream(query_stream0), *************** *** 516,550 **** ostream& QueryOstream::string_query_manip(const char* message) { - #ifndef __GNUG__ - # define xsputn sputn - # define sync pubsync - # define seekoff(p,w) pubseekoff((p),(w), ios::out) - #endif if(option_force_resolution && option_be_silent) { /* silence */ } else if(option_force_resolution) { *this << " -- " << default_input << prcsendl; string_val = PrConstCharPtrError(default_input); ! stderr_stream->xsputn(base_stream->str(), base_stream->out_waiting()); ! stderr_stream->sync(); } else if(option_report_actions) { *this << " -- " << default_input << prcsendl; string_val = PrConstCharPtrError(default_input); ! stdout_stream->xsputn(base_stream->str(), base_stream->out_waiting()); ! stdout_stream->sync(); } else { *this << "[" << default_input << "] " << message; ! query_stream->sync(); re_query_message = base_stream->str(); re_query_len = base_stream->out_waiting(); while(true) { ! stdout_stream->xsputn(re_query_message, re_query_len); ! stdout_stream->sync(); Dstring *ans = new Dstring; /* leak */ --- 490,519 ---- ostream& QueryOstream::string_query_manip(const char* message) { if(option_force_resolution && option_be_silent) { /* silence */ } else if(option_force_resolution) { *this << " -- " << default_input << prcsendl; string_val = PrConstCharPtrError(default_input); ! stderr_stream->sputn(base_stream->str(), base_stream->out_waiting()); ! stderr_stream->pubsync(); } else if(option_report_actions) { *this << " -- " << default_input << prcsendl; string_val = PrConstCharPtrError(default_input); ! stdout_stream->sputn(base_stream->str(), base_stream->out_waiting()); ! stdout_stream->pubsync(); } else { *this << "[" << default_input << "] " << message; ! query_stream->pubsync(); re_query_message = base_stream->str(); re_query_len = base_stream->out_waiting(); while(true) { ! stdout_stream->sputn(re_query_message, re_query_len); ! stdout_stream->pubsync(); Dstring *ans = new Dstring; /* leak */ *************** *** 570,587 **** query_stream->reset_column(); base_stream->freeze(0); ! base_stream->seekoff(0, ios::beg); option_count = 0; force_option = 0; bang_flag = NULL; help_string = NULL; return *this; - #ifndef __GNUG__ - # undef xsputn - # undef sync - # undef seekoff - #endif } ostream& QueryOstream::help_manip(const char* message) --- 539,551 ---- query_stream->reset_column(); base_stream->freeze(0); ! base_stream->pubseekoff(0, ios::beg, ios::out); option_count = 0; force_option = 0; bang_flag = NULL; help_string = NULL; return *this; } ostream& QueryOstream::help_manip(const char* message) *************** *** 592,602 **** ostream& QueryOstream::query_manip(const char* message) { - #ifndef __GNUG__ - # define xsputn sputn - # define sync pubsync - # define seekoff(p,w) pubseekoff((p),(w), ios::out) - #endif if(force_option != 0 && option_force_resolution) { for (int i = 0; i < option_count; i += 1) { if (force_option == options[i].let) { --- 556,561 ---- *************** *** 611,634 **** val = options[default_option].val; } else if(option_report_actions) { *this << report_message << dotendl; ! query_stream->sync(); ! stdout_stream->xsputn(base_stream->str(), base_stream->out_waiting()); ! stdout_stream->sync(); val = options[default_option].val; } else if(option_force_resolution) { *this << force_message << dotendl; ! query_stream->sync(); ! stderr_stream->xsputn(base_stream->str(), base_stream->out_waiting()); ! stderr_stream->sync(); val = options[default_option].val; } else if(bang_flag && bang_flag->flag) { *this << force_message << dotendl; ! query_stream->sync(); ! stdout_stream->xsputn(base_stream->str(), base_stream->out_waiting()); ! stdout_stream->sync(); val = options[default_option].val; } else { char query_buf[40]; --- 570,593 ---- val = options[default_option].val; } else if(option_report_actions) { *this << report_message << dotendl; ! query_stream->pubsync(); ! stdout_stream->sputn(base_stream->str(), base_stream->out_waiting()); ! stdout_stream->pubsync(); val = options[default_option].val; } else if(option_force_resolution) { *this << force_message << dotendl; ! query_stream->pubsync(); ! stderr_stream->sputn(base_stream->str(), base_stream->out_waiting()); ! stderr_stream->pubsync(); val = options[default_option].val; } else if(bang_flag && bang_flag->flag) { *this << force_message << dotendl; ! query_stream->pubsync(); ! stdout_stream->sputn(base_stream->str(), base_stream->out_waiting()); ! stdout_stream->pubsync(); val = options[default_option].val; } else { char query_buf[40]; *************** *** 657,663 **** *this << message << query_buf; ! query_stream->sync(); re_query_message = base_stream->str(); re_query_len = base_stream->out_waiting(); --- 616,622 ---- *this << message << query_buf; ! query_stream->pubsync(); re_query_message = base_stream->str(); re_query_len = base_stream->out_waiting(); *************** *** 666,673 **** char c; int found = false; ! stdout_stream->xsputn(re_query_message, re_query_len); ! stdout_stream->sync(); c = get_user_char(); --- 625,632 ---- char c; int found = false; ! stdout_stream->sputn(re_query_message, re_query_len); ! stdout_stream->pubsync(); c = get_user_char(); *************** *** 718,735 **** query_stream->reset_column(); base_stream->freeze(0); ! base_stream->seekoff(0, ios::beg); force_option = 0; option_count = 0; bang_flag = NULL; help_string = NULL; return *this; - #ifndef __GNUG__ - # undef xsputn - # undef sync - # undef seekoff - #endif } ostream& __omanip_query(ostream& s, const char* message) { --- 677,689 ---- query_stream->reset_column(); base_stream->freeze(0); ! base_stream->pubseekoff(0, ios::beg, ios::out); force_option = 0; option_count = 0; bang_flag = NULL; help_string = NULL; return *this; } ostream& __omanip_query(ostream& s, const char* message) { Index: 1.3.1-release.6/src/dstring.cc *** 1.3.1-release.6/src/dstring.cc Fri, 26 Apr 2002 18:22:42 +0400 jmacd (prcs/0_dstring.cc 1.2.1.3.1.1.1.6.2.3 644) --- 1.3.1-release.6(w)/src/dstring.cc Fri, 26 Apr 2002 18:25:50 +0400 jmacd (prcs/0_dstring.cc 1.2.1.3.1.1.1.6.2.3 644) *************** *** 25,38 **** #include "prcs.h" ! #if defined(__GNUG__) || defined(__MWERKS__) ! #if defined(__GNUG__) ! #include ! #else ! #include "be-strstream.h" ! #endif ! static ostrstream sprintfbuf; ! #endif ostream& operator<<(ostream& os, const Dstring* S) { --- 25,37 ---- #include "prcs.h" ! static strstreambuf sprintfbuf; ! ! /* I used to use strstreambuf::vform to get printf-like formatting ! * into a growing buffer, but that's been taken away. So there's ! * this, which can buffer-overrun. @@@ */ ! const int DSTRSZ = (1<<12); ! char hack_buf[DSTRSZ]; ostream& operator<<(ostream& os, const Dstring* S) { *************** *** 61,75 **** va_start(args, fmt); sprintfbuf.freeze(0); ! #ifdef __GNUG__ ! sprintfbuf.rdbuf()->seekoff(0, ios::beg); ! #else ! sprintfbuf.rdbuf()->pubseekoff(0, ios::beg, ios::out); ! #endif ! ! sprintfbuf.vform(fmt, args); ! sprintfbuf << '\0'; append(sprintfbuf.str()); --- 60,71 ---- va_start(args, fmt); sprintfbuf.freeze(0); ! sprintfbuf.pubseekoff(0, ios::beg, ios::out); ! hack_buf[DSTRSZ-1] = '\0'; ! vsprintf(hack_buf, fmt, args); ! ASSERT('\0' == hack_buf[DSTRSZ-1], "Output buffer bounds exceeded"); ! sprintfbuf.sputn (hack_buf, strlen (hack_buf) + 1); append(sprintfbuf.str()); *************** *** 85,99 **** truncate(0); sprintfbuf.freeze(0); ! #ifdef __GNUG__ ! sprintfbuf.rdbuf()->seekoff(0, ios::beg); ! #else ! sprintfbuf.rdbuf()->pubseekoff(0, ios::beg, ios::out); ! #endif ! ! sprintfbuf.vform(fmt, args); ! sprintfbuf << '\0'; append(sprintfbuf.str()); --- 81,92 ---- truncate(0); sprintfbuf.freeze(0); ! sprintfbuf.pubseekoff(0, ios::beg, ios::out); ! hack_buf[DSTRSZ-1] = '\0'; ! vsprintf(hack_buf, fmt, args); ! ASSERT('\0' == hack_buf[DSTRSZ-1], "Output buffer bounds exceeded"); ! sprintfbuf.sputn (hack_buf, strlen (hack_buf)+1); append(sprintfbuf.str()); Index: 1.3.1-release.6/src/include/prcs.h *** 1.3.1-release.6/src/include/prcs.h Thu, 07 Feb 2002 07:57:16 +0300 jmacd (prcs/0_prcs.h 1.16.1.15.1.6.1.12.1.21.1.2 644) --- 1.3.1-release.6(w)/src/include/prcs.h Fri, 26 Apr 2002 18:25:50 +0400 jmacd (prcs/0_prcs.h 1.16.1.15.1.6.1.12.1.21.1.2 644) *************** *** 41,48 **** #include "utils.h" } ! #include ! #include #ifdef NULL #undef NULL --- 41,80 ---- #include "utils.h" } ! #include ! #include ! #include ! #include ! ! using std::ostream; ! using std::streambuf; ! using std::char_traits; ! using std::basic_streambuf; ! using std::filebuf; ! using std::ofstream; ! using std::ifstream; ! using std::cout; ! using std::cerr; ! using std::ios; ! using std::stringbuf; ! using std::string; ! using std::ostringstream; ! ! /* Backwards C++ compatibility, thanks to Lars Duening ! * I can't explain why I used so many different, overlapping C++ ! * features to begin with. */ ! class strstreambuf : public stringbuf { ! private: ! string tmpstr; // holds result of str() ! public: ! int out_waiting() { return pptr() - pbase() - (0 == *pptr() ? 1 : 0); } ! const char * str() { ! tmpstr = stringbuf::str(); ! return tmpstr.c_str(); ! } ! void freeze(int n=1) ! { ASSERT(n==0, "strstreambuf::freeze(1) not implemented."); } ! }; #ifdef NULL #undef NULL Index: 1.3.1-release.6/src/include/prcserror.h *** 1.3.1-release.6/src/include/prcserror.h Fri, 26 Apr 2002 18:24:52 +0400 jmacd (prcs/1_prcserror.h 1.14.1.5.1.11.2.1 644) --- 1.3.1-release.6(w)/src/include/prcserror.h Fri, 26 Apr 2002 18:27:48 +0400 jmacd (prcs/1_prcserror.h 1.14.1.5.1.11.2.1 644) *************** *** 24,46 **** #define _PRCSERROR_H_ - #include - #include - #if defined(__GNUG__) - # if defined(__APPLE__) - # include - typedef filebuf stdiobuf; - # else - # include - # endif /* if defined(__APPLE__) */ - # include - #else - # include - typedef filebuf stdiobuf; - # include "be-strstream.h" - #endif - - extern "C" { #include #include --- 24,29 ---- *************** *** 291,299 **** * streambuf from breaking lines at whitespace inside the quotes. * It forwards all output to another stremabuf. Currently, there * are three of these used in PRCS. The ostream prcserror's ! * streambuf forwards its output to a stdiobuf(stderr). The * ostream prcsout's streambuf forwards its output to a ! * stdiobuf(stdout). The ostream prcsquery's streambuf forwards * its output to a ostrstreambuf, since prcsquery doesn't know * whether to send its output to stdout or stderr until the query * is received. */ --- 274,282 ---- * streambuf from breaking lines at whitespace inside the quotes. * It forwards all output to another stremabuf. Currently, there * are three of these used in PRCS. The ostream prcserror's ! * streambuf forwards its output to a filebuf(stderr). The * ostream prcsout's streambuf forwards its output to a ! * filebuf(stdout). The ostream prcsquery's streambuf forwards * its output to a ostrstreambuf, since prcsquery doesn't know * whether to send its output to stdout or stderr until the query * is received. */ *************** *** 310,318 **** const char* fill_prefix() const; bool fill_pretty() const; - #ifndef __GNUG__ protected: ! #endif virtual int xsputn(const char* s, int n); virtual int overflow(int c = EOF); virtual int sync(); --- 293,300 ---- const char* fill_prefix() const; bool fill_pretty() const; protected: ! virtual int xsputn(const char* s, int n); virtual int overflow(int c = EOF); virtual int sync(); *************** *** 335,352 **** class PrettyOstream : public ostream { public: PrettyOstream(PrettyStreambuf* stream, ErrorToken err) ! : ! #ifndef __GNUG__ ! ios(stream), ! #endif ! ostream(stream), _buf(stream), _err(err) { } PrettyOstream(PrettyStreambuf* stream, NonErrorToken err) ! : ! #ifndef __GNUG__ ! ios(stream), ! #endif ! ostream(stream), _buf(stream), _err(err) { } PrettyStreambuf& ostreambuf() const { return *_buf; } PrVoidError error() const { return _err; } --- 317,330 ---- class PrettyOstream : public ostream { public: PrettyOstream(PrettyStreambuf* stream, ErrorToken err) ! :ostream(stream), ! _buf(stream), ! _err(err) { } PrettyOstream(PrettyStreambuf* stream, NonErrorToken err) ! : ostream(stream), ! _buf(stream), ! _err(err) { } PrettyStreambuf& ostreambuf() const { return *_buf; } PrVoidError error() const { return _err; } *************** *** 457,464 **** public: QueryOstream(strstreambuf *base_stream0, PrettyStreambuf* query_stream0, ! stdiobuf* stdout_stream0, ! stdiobuf* stderr_stream0); /* * Manipulator methods. --- 435,442 ---- public: QueryOstream(strstreambuf *base_stream0, PrettyStreambuf* query_stream0, ! filebuf *stdout_stream0, ! filebuf *stderr_stream0); /* * Manipulator methods. *************** *** 481,487 **** strstreambuf *base_stream; PrettyStreambuf* query_stream; ! stdiobuf *stdout_stream, *stderr_stream; PrCharError val; PrConstCharPtrError string_val; --- 459,465 ---- strstreambuf *base_stream; PrettyStreambuf* query_stream; ! filebuf *stdout_stream, *stderr_stream; PrCharError val; PrConstCharPtrError string_val; *************** *** 499,514 **** extern char const default_fail_query_message[]; ! #if !defined(__GNUG__) && !defined(__MWERKS__) template class omanip { ostream& (*_f)(ostream&, TP); TP _a; public: omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) { } ! friend ostream& operator<<(ostream& o, const omanip& m); }; ! #endif ostream& __omanip_query(ostream& s, const char* message); omanip query(const char* message); --- 477,499 ---- extern char const default_fail_query_message[]; ! template class omanip; ! ! template ostream& operator<< (ostream& o, const omanip& m); ! template class omanip { ostream& (*_f)(ostream&, TP); TP _a; public: omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) { } ! friend ostream& operator<< <>(ostream& o, const omanip& m); }; ! ! template ostream& operator<< (ostream& o, const omanip& m) ! { ! return (*m._f)(o, m._a); ! } ostream& __omanip_query(ostream& s, const char* message); omanip query(const char* message); Index: 1.3.1-release.6/src/prcserror.tl *** 1.3.1-release.6/src/prcserror.tl Sun, 31 Oct 1999 07:26:02 +0300 jmacd (prcs/0_prcserror.tl 1.1.1.6.1.3.1.8 644) --- 1.3.1-release.6(w)/src/prcserror.tl Fri, 26 Apr 2002 18:27:03 +0400 jmacd (prcs/0_prcserror.tl 1.1.1.6.1.3.1.8 644) *************** *** 52,66 **** template class PrError; template class PrError; - #if defined(__GNUG__) && __GNUC__ >= 2 && __GNUC_MINOR__ < 8 - #define WACK - #else - #define WACK <> - #endif - #define MkTemplate(errtype, tclass) \ template const errtype& \ ! operator<< WACK(tclass&, const errtype&) #if defined(PRCS_DEVEL) && defined(__GNUG__) MkTemplate(NprError, FILE*); --- 52,60 ---- template class PrError; template class PrError; #define MkTemplate(errtype, tclass) \ template const errtype& \ ! operator<< <>(tclass&, const errtype&) #if defined(PRCS_DEVEL) && defined(__GNUG__) MkTemplate(NprError, FILE*); *************** *** 96,102 **** #undef MkTemplate #define MkTemplate(tclass) \ template class omanip; \ ! template ostream& operator<< WACK(ostream&, const omanip&) MkTemplate(const char*); MkTemplate(CharAndStr); --- 90,96 ---- #undef MkTemplate #define MkTemplate(tclass) \ template class omanip; \ ! template ostream& operator<< <>(ostream&, const omanip&) MkTemplate(const char*); MkTemplate(CharAndStr);