Commit 127a0e19 by lvzhengyang

makes the user-defined tcl cmd seen by Tcl terminal

parent c0c3a467
......@@ -5,6 +5,9 @@
## TODO
* make TCL to recognize my configured commands
* cannot find the extern defined char* minieda_swig_tcl_inits
* add OpenDB
* with swig
......
......@@ -6,3 +6,5 @@ export CMAKE_INCLUDE_PATH="$PWD/pkgs/boost_1_78_0/:$CMAKE_INCLUDE_PATH"
# export CMAKE_LIBRARY_PATH="/workspace/S/lvzhengyang/_install/lib:$CMAKE_LIBRARY_PATH"
export CMAKE_LIBRARY_PATH="$PWD/pkgs/lib"
export CMAKE_LIBRARY_PATH="$PWD/pkgs/boost_1_78_0/stage/lib:$CMAKE_LIBRARY_PATH"
export CMAKE_PREFIX_PATH="$PWD/pkgs:$CMAKE_PREFIX_PATH"
......@@ -3,6 +3,11 @@
#include "utl/MakeLogger.h"
#include "utl/Logger.h"
#include "utl/tcl_utl.h"
namespace eda {
extern const char *minieda_swig_tcl_inits[];
}
// Swig uses C linkage for init functions.
extern "C" {
......@@ -16,6 +21,8 @@ extern const char* metrics_filename;
namespace eda {
using utl::evalTclInit;
MiniEda::MiniEda()
: tcl_interp_(nullptr),
logger_(nullptr)
......@@ -59,6 +66,8 @@ void MiniEda::init(Tcl_Interp* interp)
// Init components.
Minieda_swig_Init(interp);
// Import TCL scripts
evalTclInit(interp, eda::minieda_swig_tcl_inits);
// defined in MakeModuleXX.h
initLogger(logger_, interp);
......
......@@ -50,9 +50,9 @@ using eda::getLogger;
namespace eda {
void delete_all_memory()
void logger_echo(const char* usr_input)
{
eda::deleteAllMemory();
getLogger()->info(utl::EDA, 1, usr_input);
}
}
......
proc delete_all_memory { } {
eda::delete_all_memory
proc logger_echo { usr_input } {
eda::logger_echo $usr_input
}
......@@ -130,7 +130,7 @@ function(swig_lib)
set(LANG_INIT ${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}-${ARG_LANGUAGE}InitVar.cc)
add_custom_command(OUTPUT ${LANG_INIT}
COMMAND ${MINIEDA_HOME}/etc/TclEncode.tcl ${LANG_INIT} ${ARG_NAME}_${ARG_LANGUAGE}_inits ${ARG_SCRIPTS}
COMMAND ${MINIEDA_HOME}/src/etc/TclEncode.tcl ${LANG_INIT} ${ARG_NAME}_${ARG_LANGUAGE}_inits ${ARG_SCRIPTS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${ARG_SCRIPTS}
)
......
......@@ -24,6 +24,7 @@ target_sources(utl
PRIVATE
src/Logger.cpp
src/MakeLogger.cpp
src/tcl_utl.cpp
)
target_include_directories(utl
......
......@@ -64,7 +64,7 @@ namespace utl {
X(IFP) \
X(MPL) \
X(ODB) \
X(ORD) \
X(EDA) \
X(PAR) \
X(PDN) \
X(PDR) \
......
#pragma once
struct Tcl_Interp;
namespace utl {
// TCL init files are encoded into the string init using the three
// digit decimal equivalent for each ascii character. This function
// unencodes the string and evals it. This packages the TCL init
// files as part of the executable so they don't have to be shipped as
// separate files that have to be located and loaded at run time.
void evalTclInit(Tcl_Interp *interp, const char *inits[]);
char* unencode(const char *inits[]);
} // namespace utl
#include <tcl.h>
#include <string.h>
#include <stdlib.h>
#include "utl/tcl_utl.h"
namespace utl {
void evalTclInit(Tcl_Interp *interp,
const char *inits[])
{
char *unencoded = unencode(inits);
if (Tcl_Eval(interp, unencoded) != TCL_OK) {
// Get a backtrace for the error.
Tcl_Eval(interp, "$errorInfo");
const char *tcl_err = Tcl_GetStringResult(interp);
fprintf(stderr, "Error: TCL init script: %s.\n", tcl_err);
fprintf(stderr, " Try deleting TclInitVar.cc and rebuilding.\n");
exit(0);
}
delete [] unencoded;
}
char* unencode(const char *inits[])
{
size_t length = 0;
for (const char **e = inits; *e; e++) {
const char *init = *e;
length += strlen(init);
}
char *unencoded = new char[length / 3 + 1];
char *u = unencoded;
for (const char **e = inits; *e; e++) {
const char *init = *e;
size_t init_length = strlen(init);
for (const char *s = init; s < &init[init_length]; s += 3) {
char code[4] = {s[0], s[1], s[2], '\0'};
char ch = atoi(code);
*u++ = ch;
}
}
*u = '\0';
return unencoded;
}
} // namespace utl
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment