diff --git a/util/ReportTcl.cc b/util/ReportTcl.cc index 5c02796d..ade08849 100644 --- a/util/ReportTcl.cc +++ b/util/ReportTcl.cc @@ -1,33 +1,33 @@ // OpenSTA, Static Timing Analyzer // Copyright (c) 2020, Parallax Software, Inc. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include "ReportTcl.hh" -#include #include +#include namespace sta { -using ::Tcl_Channel; -using ::Tcl_GetChannelType; -using ::Tcl_ChannelType; using ::ClientData; -using ::Tcl_GetChannelInstanceData; -using ::Tcl_DriverOutputProc; +using ::Tcl_Channel; using ::Tcl_ChannelOutputProc; +using ::Tcl_ChannelType; +using ::Tcl_DriverOutputProc; +using ::Tcl_GetChannelInstanceData; +using ::Tcl_GetChannelType; extern "C" { @@ -38,153 +38,166 @@ extern "C" { #endif static int -encapOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, - int *errorCodePtr); +encapOutputProc(ClientData instanceData, + CONST84 char *buf, + int toWrite, + int *errorCodePtr); static int -encapErrorOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, - int *errorCodePtr); +encapErrorOutputProc(ClientData instanceData, + CONST84 char *buf, + int toWrite, + int *errorCodePtr); static int encapCloseProc(ClientData instanceData, Tcl_Interp *interp); static int -encapSetOptionProc(ClientData instanceData, Tcl_Interp *interp, - CONST84 char *optionName, CONST84 char *value); +encapSetOptionProc(ClientData instanceData, + Tcl_Interp *interp, + CONST84 char *optionName, + CONST84 char *value); static int -encapGetOptionProc(ClientData instanceData, Tcl_Interp *interp, - CONST84 char *optionName, Tcl_DString *dsPtr); +encapGetOptionProc(ClientData instanceData, + Tcl_Interp *interp, + CONST84 char *optionName, + Tcl_DString *dsPtr); static int -encapInputProc(ClientData instanceData, char *buf, int bufSize, - int *errorCodePtr); +encapInputProc(ClientData instanceData, + char *buf, + int bufSize, + int *errorCodePtr); static int -encapSeekProc(ClientData instanceData, long offset, int seekMode, - int *errorCodePtr); +encapSeekProc(ClientData instanceData, + long offset, + int seekMode, + int *errorCodePtr); static void encapWatchProc(ClientData instanceData, int mask); static int -encapGetHandleProc(ClientData instanceData, int direction, - ClientData *handlePtr); +encapGetHandleProc(ClientData instanceData, + int direction, + ClientData *handlePtr); static int encapBlockModeProc(ClientData instanceData, int mode); } // extern "C" #ifdef TCL_CHANNEL_VERSION_5 Tcl_ChannelType tcl_encap_type_stdout = { - const_cast("file"), - TCL_CHANNEL_VERSION_4, - encapCloseProc, - encapInputProc, - encapOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr, // handlerProc - nullptr, // wideSeekProc - nullptr, // threadActionProc - nullptr // truncateProc + const_cast("file"), + TCL_CHANNEL_VERSION_4, + encapCloseProc, + encapInputProc, + encapOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr, // handlerProc + nullptr, // wideSeekProc + nullptr, // threadActionProc + nullptr // truncateProc }; Tcl_ChannelType tcl_encap_type_stderr = { - const_cast("file"), - TCL_CHANNEL_VERSION_4, - encapCloseProc, - encapInputProc, - encapErrorOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr, // handlerProc - nullptr, // wideSeekProc - nullptr, // threadActionProc - nullptr // truncateProc + const_cast("file"), + TCL_CHANNEL_VERSION_4, + encapCloseProc, + encapInputProc, + encapErrorOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr, // handlerProc + nullptr, // wideSeekProc + nullptr, // threadActionProc + nullptr // truncateProc }; #else #ifdef TCL_CHANNEL_VERSION_4 // Tcl 8.4.12 Tcl_ChannelType tcl_encap_type_stdout = { - const_cast("file"), - TCL_CHANNEL_VERSION_4, - encapCloseProc, - encapInputProc, - encapOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr, // handlerProc - nullptr, // wideSeekProc - nullptr // threadActionProc + const_cast("file"), + TCL_CHANNEL_VERSION_4, + encapCloseProc, + encapInputProc, + encapOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr, // handlerProc + nullptr, // wideSeekProc + nullptr // threadActionProc }; Tcl_ChannelType tcl_encap_type_stderr = { - const_cast("file"), - TCL_CHANNEL_VERSION_4, - encapCloseProc, - encapInputProc, - encapErrorOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr, // handlerProc - nullptr, // wideSeekProc - nullptr // threadActionProc + const_cast("file"), + TCL_CHANNEL_VERSION_4, + encapCloseProc, + encapInputProc, + encapErrorOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr, // handlerProc + nullptr, // wideSeekProc + nullptr // threadActionProc }; #else #ifdef TCL_CHANNEL_VERSION_3 // Tcl 8.4 Tcl_ChannelType tcl_encap_type_stdout = { - const_cast("file"), - TCL_CHANNEL_VERSION_3, - encapCloseProc, - encapInputProc, - encapOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr, // handlerProc - nullptr // wideSeekProc + const_cast("file"), + TCL_CHANNEL_VERSION_3, + encapCloseProc, + encapInputProc, + encapOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr, // handlerProc + nullptr // wideSeekProc }; Tcl_ChannelType tcl_encap_type_stderr = { - const_cast("file"), - TCL_CHANNEL_VERSION_3, - encapCloseProc, - encapInputProc, - encapErrorOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr, // handlerProc - nullptr // wideSeekProc + const_cast("file"), + TCL_CHANNEL_VERSION_3, + encapCloseProc, + encapInputProc, + encapErrorOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr, // handlerProc + nullptr // wideSeekProc }; #else @@ -192,68 +205,68 @@ Tcl_ChannelType tcl_encap_type_stderr = { // Tcl 8.3.2 Tcl_ChannelType tcl_encap_type_stdout = { - const_cast("file"), - TCL_CHANNEL_VERSION_2, - encapCloseProc, - encapInputProc, - encapOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr // handlerProc + const_cast("file"), + TCL_CHANNEL_VERSION_2, + encapCloseProc, + encapInputProc, + encapOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr // handlerProc }; Tcl_ChannelType tcl_encap_type_stderr = { - const_cast("file"), - TCL_CHANNEL_VERSION_2, - encapCloseProc, - encapInputProc, - encapErrorOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr, // close2Proc - encapBlockModeProc, - nullptr, // flushProc - nullptr // handlerProc + const_cast("file"), + TCL_CHANNEL_VERSION_2, + encapCloseProc, + encapInputProc, + encapErrorOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr, // close2Proc + encapBlockModeProc, + nullptr, // flushProc + nullptr // handlerProc }; #else // Tcl 8.2 Tcl_ChannelType tcl_encap_type_stdout = { - const_cast("file"), - encapBlockModeProc, - encapCloseProc, - encapInputProc, - encapOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr // close2Proc + const_cast("file"), + encapBlockModeProc, + encapCloseProc, + encapInputProc, + encapOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr // close2Proc }; Tcl_ChannelType tcl_encap_type_stderr = { - const_cast("file"), - encapBlockModeProc, - encapCloseProc, - encapInputProc, - encapErrorOutputProc, - encapSeekProc, - encapSetOptionProc, - encapGetOptionProc, - encapWatchProc, - encapGetHandleProc, - nullptr // close2Proc + const_cast("file"), + encapBlockModeProc, + encapCloseProc, + encapInputProc, + encapErrorOutputProc, + encapSeekProc, + encapSetOptionProc, + encapGetOptionProc, + encapWatchProc, + encapGetHandleProc, + nullptr // close2Proc }; #endif @@ -264,12 +277,8 @@ Tcl_ChannelType tcl_encap_type_stderr = { //////////////////////////////////////////////////////////////// ReportTcl::ReportTcl() : - Report(), - interp_(nullptr), - tcl_stdout_(nullptr), - tcl_stderr_(nullptr), - tcl_encap_stdout_(nullptr), - tcl_encap_stderr_(nullptr) + Report(), interp_(nullptr), tcl_stdout_(nullptr), tcl_stderr_(nullptr), + tcl_encap_stdout_(nullptr), tcl_encap_stderr_(nullptr) { } @@ -290,10 +299,16 @@ ReportTcl::setTclInterp(Tcl_Interp *interp) interp_ = interp; tcl_stdout_ = Tcl_GetStdChannel(TCL_STDOUT); tcl_stderr_ = Tcl_GetStdChannel(TCL_STDERR); - tcl_encap_stdout_ = Tcl_StackChannel(interp, &tcl_encap_type_stdout, this, - TCL_WRITABLE, tcl_stdout_); - tcl_encap_stderr_ = Tcl_StackChannel(interp, &tcl_encap_type_stderr, this, - TCL_WRITABLE, tcl_stderr_); + tcl_encap_stdout_ = Tcl_StackChannel(interp, + &tcl_encap_type_stdout, + this, + TCL_WRITABLE, + tcl_stdout_); + tcl_encap_stderr_ = Tcl_StackChannel(interp, + &tcl_encap_type_stderr, + this, + TCL_WRITABLE, + tcl_stderr_); } size_t @@ -315,9 +330,10 @@ ReportTcl::printTcl(Tcl_Channel channel, const char *buffer, size_t length) Tcl_DriverOutputProc *output_proc = Tcl_ChannelOutputProc(ch_type); int error_code; ClientData clientData = Tcl_GetChannelInstanceData(channel); - return output_proc(clientData, const_cast(buffer), - static_cast(length), - &error_code); + return output_proc(clientData, + const_cast(buffer), + length, + &error_code); } // Tcl_Main can eval multiple commands before the flushing the command @@ -389,19 +405,20 @@ ReportTcl::redirectStringEnd() //////////////////////////////////////////////////////////////// static int -encapOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, - int *) +encapOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, int *) { - ReportTcl *report = reinterpret_cast(instanceData); - return static_cast(report->printString(buf, toWrite)); + ReportTcl *report = reinterpret_cast(instanceData); + return report->printString(buf, toWrite); } static int -encapErrorOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, - int *) +encapErrorOutputProc(ClientData instanceData, + CONST84 char *buf, + int toWrite, + int *) { - ReportTcl *report = reinterpret_cast(instanceData); - return static_cast(report->printString(buf, toWrite)); + ReportTcl *report = reinterpret_cast(instanceData); + return report->printString(buf, toWrite); } static int @@ -413,7 +430,7 @@ encapInputProc(ClientData, char *, int, int *) static int encapCloseProc(ClientData instanceData, Tcl_Interp *) { - ReportTcl *report = reinterpret_cast(instanceData); + ReportTcl *report = reinterpret_cast(instanceData); report->logEnd(); report->redirectFileEnd(); report->redirectStringEnd(); @@ -455,4 +472,4 @@ encapBlockModeProc(ClientData, int) return 0; } -} // namespace +} // namespace sta