54 if (argv[0][0] ==
'!')
59 const int size = 4096;
62 strncpy (buffer, &argv[0][1], size);
63 for (i = 1; i < argc; ++i)
66 strncat (buffer, argv[i], size);
69 strncpy (buffer,
"/bin/sh", size);
70 RetValue =
system (buffer);
100 char ** argv = *pargv;
117 if ( !
st__lookup( pAbc->tCommands, argv[0], (
char **)&pCommand ) )
120 if ( argc == 1 &&
strstr( argv[0],
"." ) )
129 if ( !
st__lookup( pAbc->tCommands, argv[0], (
char **)&pCommand ) )
134 fprintf( pAbc->Err,
"** cmd error: unknown command '%s'\n", argv[0] );
135 fprintf( pAbc->Err,
"(this is likely caused by using an alias defined in \"abc.rc\"\n" );
136 fprintf( pAbc->Err,
"without having this file in the current or parent directory)\n" );
142 if ( pCommand->fChange )
156 pFunc = (int (*)(
Abc_Frame_t *, int,
char **))pCommand->pFunc;
157 fError = (*pFunc)( pAbc, argc, argv );
162 if ( fError == 0 && !pAbc->fAutoexac )
187 const char *
p, *start;
192 int single_quote, double_quote;
194 vArgs = Vec_PtrAlloc( 10 );
200 while ( isspace( (
int ) *
p ) )
206 single_quote = double_quote = 0;
207 for ( start =
p; ( c = *
p ) !=
'\0';
p++ )
209 if ( c ==
';' || c ==
'#' || isspace( (
int ) c ) )
211 if ( !single_quote && !double_quote )
218 single_quote = !single_quote;
222 double_quote = !double_quote;
225 if ( single_quote || double_quote )
227 ( void ) fprintf( pAbc->Err,
"** cmd warning: ignoring unbalanced quote ...\n" );
234 for ( i = 0; i <
p - start; i++ )
237 if ( ( c !=
'\'' ) && ( c !=
'\"' ) )
239 new_arg[j++] = isspace( (
int ) c ) ?
' ' : start[i];
243 Vec_PtrPush( vArgs, new_arg );
246 *argc = vArgs->nSize;
247 *argv = (
char **)Vec_PtrReleaseArray( vArgs );
248 Vec_PtrFree( vArgs );
253 else if ( *
p ==
'#' )
255 for ( ; *
p != 0;
p++ );
273 int i, argc, stopit, added, offset, did_subst, subst, fError, newc, j;
281 for ( ; *loop < 200; ( *loop )++ )
285 if ( stopit != 0 ||
st__lookup( pAbc->tAliases, argv[0], (
char **) &alias ) == 0 )
289 if (
strcmp( argv[0], alias->argv[0] ) == 0 )
294 added = alias->argc - 1;
300 for ( i = argc - 1; i >= 1; i-- )
302 argv[i + added] = argv[i];
304 for ( i = 1; i <= added; i++ )
311 for ( i = 0, offset = 0; i < alias->argc; i++, offset++ )
320 if ( did_subst != 0 )
332 if ( arg[0] ==
'\0' )
343 while ( fError == 0 );
354 for ( j = argc - 1; j > offset; j-- )
356 argv[j + added] = argv[j];
360 for ( j = 0; j <= added; j++ )
362 argv[j + offset] = newv[j];
369 for ( i = offset; i < argc; i++ )
379 fprintf( pAbc->Err,
"** cmd warning: alias loop\n" );
414 char * sRealName, * sPathUsr, * sPathLib, * sPathAll;
417 if (
strcmp(sFileName,
"-") == 0) {
418 if (
strcmp(sMode,
"w") == 0) {
429 if (
strcmp(sMode,
"r") == 0) {
435 if ( sPathUsr == NULL && sPathLib == NULL ) {
438 else if ( sPathUsr == NULL ) {
441 else if ( sPathLib == NULL ) {
446 sprintf( sPathAll,
"%s:%s",sPathUsr, sPathLib );
448 if ( sPathAll != NULL ) {
453 if (sRealName == NULL) {
457 if ((pFile = fopen(sRealName, sMode)) == NULL) {
460 Abc_Print( 1,
"Cannot open file \"%s\".\n", sRealName );
466 if ( !silent &&
strlen(sRealName) >= 6 &&
strcmp( sRealName +
strlen(sRealName) - 6,
"abc.rc" ) == 0 )
467 Abc_Print( 1,
"Loading resource file \"%s\".\n", sRealName );
471 *pFileNameReal = sRealName;
492 for ( i = 0; i < argc; i++ )
498 char ** argvNew =
ABC_ALLOC(
char *, argc );
500 for ( i = 0; i < argc; i++ )
501 argvNew[i] = Abc_UtilStrsav( argv[i] );
523 for ( i = 0; i < argc; i++ )
565 int nCommands, iGroupStart, i, j;
567 int LenghtMax, nColumns, iCom = 0;
568 FILE *backupErr = pAbc->Err;
571 nCommands =
st__count( pAbc->tCommands );
577 if ( fPrintAll || pCommands->sName[0] !=
'_' )
578 ppCommands[i++] = pCommands;
583 qsort( (
void *)ppCommands, (
size_t)nCommands,
sizeof(
Abc_Command *),
584 (
int (*)(
const void *,
const void *)) CmdCommandPrintCompare );
585 assert( CmdCommandPrintCompare( ppCommands, ppCommands + nCommands - 1 ) <= 0 );
589 for ( i = 0; i < nCommands; i++ )
590 if ( LenghtMax < (
int)
strlen(ppCommands[i]->sName) )
591 LenghtMax = (int)
strlen(ppCommands[i]->sName);
593 nColumns = 79 / (LenghtMax + 2);
596 fprintf( pAbc->Out,
" Welcome to ABC compiled on %s %s!", __DATE__, __TIME__ );
601 pAbc->Err = pAbc->Out;
602 for ( i = 0; i < nCommands; i++ )
603 if ( sGroupCur &&
strcmp( sGroupCur, ppCommands[i]->sGroup ) == 0 )
605 if ( iCom++ % nColumns == 0 )
606 fprintf( pAbc->Out,
"\n" );
608 fprintf( pAbc->Out,
" %-*s", LenghtMax, ppCommands[i]->sName );
613 if ( fDetails && i != iGroupStart )
615 fprintf( pAbc->Out,
"\n" );
616 for ( j = iGroupStart; j < i; j++ )
619 fprintf( pAbc->Out,
"\n" );
622 (void)
sprintf(tmp_cmd,
"%s -h", ppCommands[j]->sName);
626 fprintf( pAbc->Out,
"\n" );
627 fprintf( pAbc->Out,
" ----------------------------------------------------------------------" );
630 fprintf( pAbc->Out,
"\n" );
631 fprintf( pAbc->Out,
"\n" );
632 fprintf( pAbc->Out,
"%s commands:\n", ppCommands[i]->sGroup );
634 fprintf( pAbc->Out,
" %-*s", LenghtMax, ppCommands[i]->sName );
636 sGroupCur = ppCommands[i]->sGroup;
640 if ( fDetails && i != iGroupStart )
642 fprintf( pAbc->Out,
"\n" );
643 for ( j = iGroupStart; j < i; j++ )
646 fprintf( pAbc->Out,
"\n" );
649 (void)
sprintf(tmp_cmd,
"%s -h", ppCommands[j]->sName);
654 pAbc->Err = backupErr;
655 fprintf( pAbc->Out,
"\n" );
676 RetValue =
strcmp( pC1->sGroup, pC2->sGroup );
684 if ( pC1->sName[0] !=
'_' && pC2->sName[0] ==
'_' )
686 if ( pC1->sName[0] ==
'_' && pC2->sName[0] !=
'_' )
689 RetValue =
strcmp( pC1->sName, pC2->sName );
729 const char ** ppNames;
738 ppNames[nNames++] =
key;
741 qsort( (
void *)ppNames, (
size_t)nNames,
sizeof(
char *),
745 for ( i = 0; i < nNames; i++ )
751 fprintf( stdout,
"%-15s %-15s\n", ppNames[i],
value );
767void Gia_ManKissatCall(
Abc_Frame_t * pAbc,
char * pFileName,
char * pArgs,
int nConfs,
int nTimeLimit,
int fSat,
int fUnsat,
int fPrintCex,
int fVerbose )
769 char Command[1000], Buffer[100];
770 char * pNameWin =
"kissat.exe";
771 char * pNameUnix =
"kissat";
772 char * pKissatName = NULL;
795 pKissatName = pNameWin;
797 pKissatName = pNameUnix;
800 sprintf( Command,
"%s", pKissatName );
806 if ( !pArgs || (
strcmp(pArgs,
"-h") &&
strcmp(pArgs,
"--help")) )
813 strcat( Command,
" --sat" );
815 strcat( Command,
" --unsat" );
818 sprintf( Buffer,
" --conflicts=%d", nConfs );
819 strcat( Command, Buffer );
823 sprintf( Buffer,
" --time=%d", nTimeLimit );
824 strcat( Command, Buffer );
827 strcat( Command, pFileName );
830 printf(
"Running command: %s\n", Command );
833 fprintf( stdout,
"The following command has returned a strange exit status:\n" );
834 fprintf( stdout,
"\"%s\"\n", Command );
852 static char pScript[1000];
int c;
854 for ( c = 0; c < nParts; c++ ) {
855 strcat( pScript, pComms[rand() % nComms] );
858 strcat( pScript,
"print_stats" );
866 char * pComms[6] = {
"balance",
"rewrite",
"rewrite -z",
"refactor",
"refactor -z",
"resub" };
868 for ( i = 0; i < nIters; i++ )
876 Abc_Print( 1,
"Something did not work out with the command \"%s\".\n", pScript );
885 Abc_Print( 1,
"Something did not work out with the command \"%s\".\n", pScript );
892 if ( Abc_NtkNodeNum(pCur) < Abc_NtkNodeNum(pBest) ) {
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
ABC_DLL void Abc_FrameSetBatchMode(int Mode)
ABC_DLL Abc_Ntk_t * Abc_FrameReadNtk(Abc_Frame_t *p)
ABC_DLL int Abc_FrameIsBatchMode()
ABC_DLL int Abc_FrameIsFlagEnabled(char *pFlag)
ABC_DLL void Abc_FrameSetCurrentNetwork(Abc_Frame_t *p, Abc_Ntk_t *pNet)
ABC_DLL void Abc_FrameSwapCurrentAndBackup(Abc_Frame_t *p)
ABC_NAMESPACE_IMPL_START typedef signed char value
void CmdCommandAliasPrint(Abc_Frame_t *pAbc, Abc_Alias *pAlias)
void Gia_ManKissatCall(Abc_Frame_t *pAbc, char *pFileName, char *pArgs, int nConfs, int nTimeLimit, int fSat, int fUnsat, int fPrintCex, int fVerbose)
int CmdCommandDispatch(Abc_Frame_t *pAbc, int *pargc, char ***pargv)
int cmdCheckShellEscape(Abc_Frame_t *pAbc, int argc, char **argv)
FUNCTION DEFINITIONS ///.
void Cmd_CommandSGen(Abc_Frame_t *pAbc, int nParts, int nIters, int fVerbose)
FILE * CmdFileOpen(Abc_Frame_t *pAbc, char *sFileName, char *sMode, char **pFileNameReal, int silent)
char ** CmdDupArgv(int argc, char **argv)
void CmdCommandFree(Abc_Command *pCommand)
char ** CmdAddToArgv(int argc, char **argv)
const char * CmdSplitLine(Abc_Frame_t *pAbc, const char *sCommand, int *argc, char ***argv)
char * CmdHistorySubstitution(Abc_Frame_t *pAbc, char *line, int *changed)
int CmdNamePrintCompare(char **ppC1, char **ppC2)
char * Cmd_GenScript(char **pComms, int nComms, int nParts)
void CmdCommandPrint(Abc_Frame_t *pAbc, int fPrintAll, int fDetails)
int CmdApplyAlias(Abc_Frame_t *pAbc, int *argcp, char ***argvp, int *loop)
void CmdPrintTable(st__table *tTable, int fAliases)
void CmdFreeArgv(int argc, char **argv)
char * Cmd_FlagReadByName(Abc_Frame_t *pAbc, char *flag)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct MvCommand Abc_Command
INCLUDES ///.
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
int st__lookup(st__table *table, const char *key, char **value)
#define st__foreach_item(table, gen, key, value)
ABC_NAMESPACE_IMPL_START int Util_SignalSystem(const char *cmd)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.