summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt16
-rw-r--r--Makefile7
-rw-r--r--src/base/cmd/cmdPlugin.c115
3 files changed, 97 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c829f4a2..f07fe7d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,13 @@ include(CMakeParseArguments)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
+function(addprefix var prefix)
+ foreach( s ${ARGN} )
+ list(APPEND tmp "-I${s}")
+ endforeach()
+ set(${var} ${tmp} PARENT_SCOPE)
+endfunction()
+
# filter out flags that are not appropriate for the compiler being used
function(target_compile_options_filtered target visibility)
foreach( flag ${ARGN} )
@@ -26,9 +33,12 @@ endfunction()
project(abc)
if(READLINE_FOUND MATCHES TRUE)
- addprefix(READLINE_INCLUDES_FLAGS "-I" ${READLINE_INCLUDES})
- list(APPEND ABC_READLINE_FLAGS "ABC_READLINE_INCLUDES=${READLINE_INCLUDES_FLAGS}")
- list(APPEND ABC_READLINE_FLAGS "ABC_READLINE_LIBRARIES=${READLINE_LIBRARIES}")
+ addprefix(ABC_READLINE_INCLUDES_FLAGS "-I" ${READLINE_INCLUDES})
+ string(REPLACE ";" " " ABC_READLINE_INCLUDES_FLAGS "${ABC_READLINE_INCLUDES_FLAGS}")
+ list(APPEND ABC_READLINE_FLAGS "ABC_READLINE_INCLUDES=${ABC_READLINE_INCLUDES_FLAGS}")
+
+ string(REPLACE ";" " " ABC_READLINE_LIBRARIES_FLAGS "${READLINE_LIBRARIES}")
+ list(APPEND ABC_READLINE_FLAGS "ABC_READLINE_LIBRARIES=${ABC_READLINE_LIBRARIES_FLAGS}")
elseif(READLINE_FOUND MATCHES FALSE)
list(APPEND ABC_READLINE_FLAGS "ABC_USE_NO_READLINE=1")
endif()
diff --git a/Makefile b/Makefile
index cd1d0edd..4b5190d0 100644
--- a/Makefile
+++ b/Makefile
@@ -73,13 +73,6 @@ ifndef ABC_USE_NO_READLINE
$(info $(MSG_PREFIX)Using libreadline)
endif
-# whether to use libreadline
-ifndef ABC_USE_NO_READLINE
- CFLAGS += -DABC_USE_READLINE
- LIBS += -lreadline
- $(info $(MSG_PREFIX)Using libreadline)
-endif
-
# whether to compile with thread support
ifdef ABC_USE_NO_PTHREADS
CFLAGS += -DABC_USE_PTHREADS
diff --git a/src/base/cmd/cmdPlugin.c b/src/base/cmd/cmdPlugin.c
index 37a28e63..51378653 100644
--- a/src/base/cmd/cmdPlugin.c
+++ b/src/base/cmd/cmdPlugin.c
@@ -641,38 +641,63 @@ int Cmd_CommandAbcPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv )
***********************************************************************/
int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv )
{
- FILE * pFile;
+ int fPath, fVerbose;
+ int fd = -1, RetValue = -1, c;
+ FILE * pFile = NULL;
+ char * pStrDirBin = NULL, * pStrSection = NULL;
+ Vec_Str_t * sCommandLine = NULL;
+ char * pTempFile = NULL;
char pBuffer[1000];
- char * pCommandLine;
- char * pTempFile;
- char * pStrDirBin, * pStrSection;
- int fd, RetValue;
- if ( argc != 3 )
+ // set defaults
+ fPath = 0;
+ fVerbose = 0;
+
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "vph" ) ) != EOF )
{
- Abc_Print( -1, "Wrong number of arguments.\n" );
+ switch ( c )
+ {
+ case 'p':
+ fPath ^= 1;
+ break;
+ case 'v':
+ fVerbose ^= 1;
+ break;
+ default:
goto usage;
}
- // collect arguments
+ }
+
+ if ( argc != globalUtilOptind + 2 )
+ goto usage;
+
pStrDirBin = argv[argc-2];
pStrSection = argv[argc-1];
// check if the file exists
- if ( (pFile = fopen( pStrDirBin, "r" )) == NULL )
+ if ( !fPath )
{
-// Abc_Print( -1, "Cannot run the binary \"%s\".\n", pStrDirBin );
-// goto usage;
- return 0;
+ FILE* pFile = fopen( pStrDirBin, "r" );
+
+ if ( !pFile )
+ {
+ Abc_Print( ABC_ERROR, "Cannot run the binary \"%s\". File does not exist.\n", pStrDirBin );
+ goto cleanup;
}
+
fclose( pFile );
+ }
// create temp file
fd = Util_SignalTmpFile( "__abctmp_", ".txt", &pTempFile );
+
if ( fd == -1 )
{
- Abc_Print( -1, "Cannot create a temporary file.\n" );
- goto usage;
+ Abc_Print( ABC_ERROR, "Cannot create a temporary file.\n" );
+ goto cleanup;
}
+
#ifdef WIN32
_close( fd );
#else
@@ -680,52 +705,80 @@ int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv )
#endif
// get command list
- pCommandLine = ABC_ALLOC( char, 100 + strlen(pStrDirBin) + strlen(pTempFile) );
-// sprintf( pCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile );
- sprintf( pCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile );
- RetValue = Util_SignalSystem( pCommandLine );
- if ( RetValue == -1 )
+ sCommandLine = Vec_StrAlloc(1000);
+
+ Vec_StrPrintF(sCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile );
+ Vec_StrPush(sCommandLine, '\0');
+
+ if(fVerbose)
{
- Abc_Print( -1, "Command \"%s\" did not succeed.\n", pCommandLine );
- ABC_FREE( pCommandLine );
- ABC_FREE( pTempFile );
- goto usage;
+ Abc_Print(ABC_VERBOSE, "Running command %s\n", Vec_StrArray(sCommandLine));
+ }
+
+ RetValue = Util_SignalSystem( Vec_StrArray(sCommandLine) );
+
+ if ( RetValue != 0 )
+ {
+ Abc_Print( ABC_ERROR, "Command \"%s\" failed.\n", Vec_StrArray(sCommandLine) );
+ goto cleanup;
}
- ABC_FREE( pCommandLine );
// create commands
pFile = fopen( pTempFile, "r" );
+
if ( pFile == NULL )
{
Abc_Print( -1, "Cannot open file with the list of commands.\n" );
- ABC_FREE( pTempFile );
- goto usage;
+
+ RetValue = -1;
+ goto cleanup;
}
+
while ( fgets( pBuffer, 1000, pFile ) != NULL )
{
if ( pBuffer[strlen(pBuffer)-1] == '\n' )
pBuffer[strlen(pBuffer)-1] = 0;
+
Cmd_CommandAdd( pAbc, pStrSection, pBuffer, Cmd_CommandAbcPlugIn, 1 );
-// plugin_commands.push(Pair(cmd_name, binary_name));
+
Vec_PtrPush( pAbc->vPlugInComBinPairs, Extra_UtilStrsav(pBuffer) );
Vec_PtrPush( pAbc->vPlugInComBinPairs, Extra_UtilStrsav(pStrDirBin) );
-// printf( "Creating command %s with binary %s\n", pBuffer, pStrDirBin );
+
+ if ( fVerbose )
+ {
+ Abc_Print(ABC_VERBOSE, "Creating command %s with binary %s\n", pBuffer, pStrDirBin);
}
+ }
+
+cleanup:
+
+ if( pFile )
fclose( pFile );
+
+ if( pTempFile )
Util_SignalTmpFileRemove( pTempFile, 0 );
+
+ Vec_StrFreeP(&sCommandLine);
+
ABC_FREE( pTempFile );
- return 0;
+
+ return RetValue;
+
usage:
- Abc_Print( -2, "usage: load_plugin <plugin_dir\\binary_name> <section_name>\n" );
+
+ Abc_Print( -2, "usage: load_plugin [-pvh] <plugin_dir\\binary_name> <section_name>\n" );
Abc_Print( -2, "\t loads external binary as a plugin\n" );
+ Abc_Print( -2, "\t-p : toggle searching the command in PATH [default = %s].\n", fPath? "yes": "no" );
+ Abc_Print( -2, "\t-v : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
+
return 1;
}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
-