53 if (argv[0][0] ==
'!')
55 const int size = 4096;
58 strncpy (buffer, &argv[0][1], size);
59 for (i = 1; i < argc; ++i)
62 strncat (buffer, argv[i], size);
65 strncpy (buffer,
"/bin/sh", size);
66 RetValue =
system (buffer);
96 char ** argv = *pargv;
113 if ( !
st__lookup( pAbc->tCommands, argv[0], (
char **)&pCommand ) )
116 if ( argc == 1 &&
strstr( argv[0],
"." ) )
125 if ( !
st__lookup( pAbc->tCommands, argv[0], (
char **)&pCommand ) )
130 fprintf( pAbc->Err,
"** cmd error: unknown command '%s'\n", argv[0] );
131 fprintf( pAbc->Err,
"(this is likely caused by using an alias defined in \"abc.rc\"\n" );
132 fprintf( pAbc->Err,
"without having this file in the current or parent directory)\n" );
138 if ( pCommand->fChange )
152 pFunc = (int (*)(
Abc_Frame_t *, int,
char **))pCommand->pFunc;
153 fError = (*pFunc)( pAbc, argc, argv );
158 if ( fError == 0 && !pAbc->fAutoexac )
160 if (
st__lookup( pAbc->tFlags,
"autoexec", &value ) )
183 const char *
p, *start;
188 int single_quote, double_quote;
196 while ( isspace( (
int ) *p ) )
202 single_quote = double_quote = 0;
203 for ( start = p; ( c = *
p ) !=
'\0'; p++ )
205 if ( c ==
';' || c ==
'#' || isspace( (
int ) c ) )
207 if ( !single_quote && !double_quote )
214 single_quote = !single_quote;
218 double_quote = !double_quote;
221 if ( single_quote || double_quote )
223 ( void ) fprintf( pAbc->Err,
"** cmd warning: ignoring unbalanced quote ...\n" );
228 new_arg =
ABC_ALLOC(
char, p - start + 1 );
230 for ( i = 0; i < p - start; i++ )
233 if ( ( c !=
'\'' ) && ( c !=
'\"' ) )
235 new_arg[j++] = isspace( (
int ) c ) ?
' ' : start[i];
242 *argc = vArgs->nSize;
249 else if ( *p ==
'#' )
251 for ( ; *p != 0; p++ );
269 int i, argc, stopit, added, offset, did_subst, subst, fError, newc, j;
277 for ( ; *loop < 200; ( *loop )++ )
281 if ( stopit != 0 ||
st__lookup( pAbc->tAliases, argv[0], (
char **) &alias ) == 0 )
290 added = alias->
argc - 1;
296 for ( i = argc - 1; i >= 1; i-- )
298 argv[i + added] = argv[i];
300 for ( i = 1; i <= added; i++ )
307 for ( i = 0, offset = 0; i < alias->
argc; i++, offset++ )
316 if ( did_subst != 0 )
328 if ( arg[0] ==
'\0' )
339 while ( fError == 0 );
350 for ( j = argc - 1; j > offset; j-- )
352 argv[j + added] = argv[j];
356 for ( j = 0; j <= added; j++ )
358 argv[j + offset] = newv[j];
365 for ( i = offset; i < argc; i++ )
375 fprintf( pAbc->Err,
"** cmd warning: alias loop\n" );
410 char * sRealName, * sPathUsr, * sPathLib, * sPathAll;
413 if (
strcmp(sFileName,
"-") == 0) {
414 if (
strcmp(sMode,
"w") == 0) {
425 if (
strcmp(sMode,
"r") == 0) {
431 if ( sPathUsr == NULL && sPathLib == NULL ) {
434 else if ( sPathUsr == NULL ) {
437 else if ( sPathLib == NULL ) {
442 sprintf( sPathAll,
"%s:%s",sPathUsr, sPathLib );
444 if ( sPathAll != NULL ) {
449 if (sRealName == NULL) {
453 if ((pFile = fopen(sRealName, sMode)) == NULL) {
456 Abc_Print( 1,
"Cannot open file \"%s\".\n", sRealName );
462 if ( !silent &&
strlen(sRealName) >= 6 &&
strcmp( sRealName +
strlen(sRealName) - 6,
"abc.rc" ) == 0 )
463 Abc_Print( 1,
"Loading resource file \"%s\".\n", sRealName );
467 *pFileNameReal = sRealName;
488 for ( i = 0; i < argc; i++ )
494 char ** argvNew =
ABC_ALLOC(
char *, argc );
496 for ( i = 0; i < argc; i++ )
519 for ( i = 0; i < argc; i++ )
561 int nCommands, iGroupStart, i, j;
563 int LenghtMax, nColumns, iCom = 0;
564 FILE *backupErr = pAbc->Err;
567 nCommands =
st__count( pAbc->tCommands );
573 if ( fPrintAll || pCommands->sName[0] !=
'_' )
574 ppCommands[i++] = pCommands;
579 qsort( (
void *)ppCommands, nCommands,
sizeof(
Abc_Command *),
585 for ( i = 0; i < nCommands; i++ )
586 if ( LenghtMax < (
int)
strlen(ppCommands[i]->sName) )
587 LenghtMax = (int)
strlen(ppCommands[i]->sName);
589 nColumns = 79 / (LenghtMax + 2);
592 fprintf( pAbc->Out,
" Welcome to ABC compiled on %s %s!", __DATE__, __TIME__ );
597 pAbc->Err = pAbc->Out;
598 for ( i = 0; i < nCommands; i++ )
599 if ( sGroupCur &&
strcmp( sGroupCur, ppCommands[i]->sGroup ) == 0 )
601 if ( iCom++ % nColumns == 0 )
602 fprintf( pAbc->Out,
"\n" );
604 fprintf( pAbc->Out,
" %-*s", LenghtMax, ppCommands[i]->sName );
609 if ( fDetails && i != iGroupStart )
611 fprintf( pAbc->Out,
"\n" );
612 for ( j = iGroupStart; j < i; j++ )
615 fprintf( pAbc->Out,
"\n" );
618 (void)
sprintf(tmp_cmd,
"%s -h", ppCommands[j]->sName);
622 fprintf( pAbc->Out,
"\n" );
623 fprintf( pAbc->Out,
" ----------------------------------------------------------------------" );
626 fprintf( pAbc->Out,
"\n" );
627 fprintf( pAbc->Out,
"\n" );
628 fprintf( pAbc->Out,
"%s commands:\n", ppCommands[i]->sGroup );
630 fprintf( pAbc->Out,
" %-*s", LenghtMax, ppCommands[i]->sName );
632 sGroupCur = ppCommands[i]->sGroup;
636 if ( fDetails && i != iGroupStart )
638 fprintf( pAbc->Out,
"\n" );
639 for ( j = iGroupStart; j < i; j++ )
642 fprintf( pAbc->Out,
"\n" );
645 (void)
sprintf(tmp_cmd,
"%s -h", ppCommands[j]->sName);
650 pAbc->Err = backupErr;
651 fprintf( pAbc->Out,
"\n" );
672 RetValue =
strcmp( pC1->sGroup, pC2->sGroup );
680 if ( pC1->sName[0] !=
'_' && pC2->sName[0] ==
'_' )
682 if ( pC1->sName[0] ==
'_' && pC2->sName[0] !=
'_' )
685 RetValue =
strcmp( pC1->sName, pC2->sName );
708 return strcmp( *ppC1, *ppC2 );
725 const char ** ppNames;
734 ppNames[nNames++] =
key;
737 qsort( (
void *)ppNames, nNames,
sizeof(
char *),
741 for ( i = 0; i < nNames; i++ )
747 fprintf( stdout,
"%-15s %-15s\n", ppNames[i], value );
typedefABC_NAMESPACE_HEADER_START struct MvCommand Abc_Command
INCLUDES ///.
ABC_DLL void Abc_FrameSwapCurrentAndBackup(Abc_Frame_t *p)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
const char * CmdSplitLine(Abc_Frame_t *pAbc, const char *sCommand, int *argc, char ***argv)
void CmdCommandPrint(Abc_Frame_t *pAbc, int fPrintAll, int fDetails)
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
#define ABC_REALLOC(type, obj, num)
ABC_DLL void Abc_FrameSetCurrentNetwork(Abc_Frame_t *p, Abc_Ntk_t *pNet)
int CmdCommandDispatch(Abc_Frame_t *pAbc, int *pargc, char ***pargv)
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
#define ABC_ALLOC(type, num)
void CmdPrintTable(st__table *tTable, int fAliases)
static ABC_NAMESPACE_IMPL_START int CmdCommandPrintCompare(Abc_Command **ppC1, Abc_Command **ppC2)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
int CmdNamePrintCompare(char **ppC1, char **ppC2)
#define ABC_NAMESPACE_IMPL_END
char ** CmdAddToArgv(int argc, char **argv)
void * Abc_FrameGetGlobalFrame()
FILE * CmdFileOpen(Abc_Frame_t *pAbc, char *sFileName, char *sMode, char **pFileNameReal, int silent)
static void Abc_Print(int level, const char *format,...)
#define ABC_NAMESPACE_IMPL_START
void CmdCommandAliasPrint(Abc_Frame_t *pAbc, Abc_Alias *pAlias)
char ** CmdDupArgv(int argc, char **argv)
int st__lookup(st__table *table, const char *key, char **value)
void CmdFreeArgv(int argc, char **argv)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
ABC_DLL int Abc_FrameIsFlagEnabled(char *pFlag)
#define st__foreach_item(table, gen, key, value)
char * Abc_UtilStrsav(char *s)
char * Cmd_FlagReadByName(Abc_Frame_t *pAbc, char *flag)
DECLARATIONS ///.
int cmdCheckShellEscape(Abc_Frame_t *pAbc, int argc, char **argv)
FUNCTION DEFINITIONS ///.
void CmdCommandFree(Abc_Command *pCommand)
int CmdApplyAlias(Abc_Frame_t *pAbc, int *argcp, char ***argvp, int *loop)
static void Vec_PtrFree(Vec_Ptr_t *p)
char * CmdHistorySubstitution(Abc_Frame_t *pAbc, char *line, int *changed)
static void ** Vec_PtrReleaseArray(Vec_Ptr_t *p)