abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cmdInt.h File Reference
#include "base/main/mainInt.h"
#include "cmd.h"

Go to the source code of this file.

Data Structures

struct  MvCommand
 INCLUDES ///. More...
 
struct  MvAlias
 

Functions

void CmdCommandAliasAdd (Abc_Frame_t *pAbc, char *sName, int argc, char **argv)
 MACRO DEFINITIONS ///. More...
 
void CmdCommandAliasPrint (Abc_Frame_t *pAbc, Abc_Alias *pAlias)
 
char * CmdCommandAliasLookup (Abc_Frame_t *pAbc, char *sCommand)
 
void CmdCommandAliasFree (Abc_Alias *p)
 
int CmdCommandDispatch (Abc_Frame_t *pAbc, int *argc, char ***argv)
 
const char * CmdSplitLine (Abc_Frame_t *pAbc, const char *sCommand, int *argc, char ***argv)
 
int CmdApplyAlias (Abc_Frame_t *pAbc, int *argc, char ***argv, int *loop)
 
char * CmdHistorySubstitution (Abc_Frame_t *pAbc, char *line, int *changed)
 
FILE * CmdFileOpen (Abc_Frame_t *pAbc, char *sFileName, char *sMode, char **pFileNameReal, int silent)
 
void CmdFreeArgv (int argc, char **argv)
 
char ** CmdAddToArgv (int argc, char **argv)
 
void CmdCommandFree (Abc_Command *pCommand)
 
void CmdCommandPrint (Abc_Frame_t *pAbc, int fPrintAll, int fDetails)
 
void CmdPrintTable (st__table *tTable, int fAliases)
 

Function Documentation

char** CmdAddToArgv ( int  argc,
char **  argv 
)

Function*************************************************************

Synopsis [Frees the previously allocated argv array.]

Description []

SideEffects []

SeeAlso []

Definition at line 512 of file cmdUtils.c.

513 {
514  char ** argv2;
515  int i;
516  argv2 = ABC_ALLOC( char *, argc + 1 );
517  argv2[0] = Extra_UtilStrsav( "read" );
518 // argv2[0] = Extra_UtilStrsav( "&r" );
519  for ( i = 0; i < argc; i++ )
520  argv2[i+1] = Extra_UtilStrsav( argv[i] );
521  return argv2;
522 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
int CmdApplyAlias ( Abc_Frame_t pAbc,
int *  argcp,
char ***  argvp,
int *  loop 
)

Function*************************************************************

Synopsis [Replaces parts of the command line string by aliases if given.]

Description []

SideEffects []

SeeAlso []

Definition at line 267 of file cmdUtils.c.

268 {
269  int i, argc, stopit, added, offset, did_subst, subst, fError, newc, j;
270  const char *arg;
271  char **argv, **newv;
272  Abc_Alias *alias;
273 
274  argc = *argcp;
275  argv = *argvp;
276  stopit = 0;
277  for ( ; *loop < 200; ( *loop )++ )
278  {
279  if ( argc == 0 )
280  return 0;
281  if ( stopit != 0 || st__lookup( pAbc->tAliases, argv[0], (char **) &alias ) == 0 )
282  {
283  return 0;
284  }
285  if ( strcmp( argv[0], alias->argv[0] ) == 0 )
286  {
287  stopit = 1;
288  }
289  ABC_FREE( argv[0] );
290  added = alias->argc - 1;
291 
292  /* shift all the arguments to the right */
293  if ( added != 0 )
294  {
295  argv = ABC_REALLOC( char *, argv, argc + added );
296  for ( i = argc - 1; i >= 1; i-- )
297  {
298  argv[i + added] = argv[i];
299  }
300  for ( i = 1; i <= added; i++ )
301  {
302  argv[i] = NULL;
303  }
304  argc += added;
305  }
306  subst = 0;
307  for ( i = 0, offset = 0; i < alias->argc; i++, offset++ )
308  {
309  arg = CmdHistorySubstitution( pAbc, alias->argv[i], &did_subst );
310  if ( arg == NULL )
311  {
312  *argcp = argc;
313  *argvp = argv;
314  return ( 1 );
315  }
316  if ( did_subst != 0 )
317  {
318  subst = 1;
319  }
320  fError = 0;
321  do
322  {
323  arg = CmdSplitLine( pAbc, arg, &newc, &newv );
324  /*
325  * If there's a complete `;' terminated command in `arg',
326  * when split_line() returns arg[0] != '\0'.
327  */
328  if ( arg[0] == '\0' )
329  { /* just a bunch of words */
330  break;
331  }
332  fError = CmdApplyAlias( pAbc, &newc, &newv, loop );
333  if ( fError == 0 )
334  {
335  fError = CmdCommandDispatch( pAbc, &newc, &newv );
336  }
337  CmdFreeArgv( newc, newv );
338  }
339  while ( fError == 0 );
340  if ( fError != 0 )
341  {
342  *argcp = argc;
343  *argvp = argv;
344  return ( 1 );
345  }
346  added = newc - 1;
347  if ( added != 0 )
348  {
349  argv = ABC_REALLOC( char *, argv, argc + added );
350  for ( j = argc - 1; j > offset; j-- )
351  {
352  argv[j + added] = argv[j];
353  }
354  argc += added;
355  }
356  for ( j = 0; j <= added; j++ )
357  {
358  argv[j + offset] = newv[j];
359  }
360  ABC_FREE( newv );
361  offset += added;
362  }
363  if ( subst == 1 )
364  {
365  for ( i = offset; i < argc; i++ )
366  {
367  ABC_FREE( argv[i] );
368  }
369  argc = offset;
370  }
371  *argcp = argc;
372  *argvp = argv;
373  }
374 
375  fprintf( pAbc->Err, "** cmd warning: alias loop\n" );
376  return 1;
377 }
const char * CmdSplitLine(Abc_Frame_t *pAbc, const char *sCommand, int *argc, char ***argv)
Definition: cmdUtils.c:181
char ** argv
Definition: cmdInt.h:55
int argc
Definition: cmdInt.h:54
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
Definition: cmdInt.h:51
int CmdCommandDispatch(Abc_Frame_t *pAbc, int *pargc, char ***pargv)
Definition: cmdUtils.c:93
int strcmp()
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
void CmdFreeArgv(int argc, char **argv)
Definition: cmdUtils.c:485
#define ABC_FREE(obj)
Definition: abc_global.h:232
int CmdApplyAlias(Abc_Frame_t *pAbc, int *argcp, char ***argvp, int *loop)
Definition: cmdUtils.c:267
char * CmdHistorySubstitution(Abc_Frame_t *pAbc, char *line, int *changed)
Definition: cmdUtils.c:390
void CmdCommandAliasAdd ( Abc_Frame_t pAbc,
char *  sName,
int  argc,
char **  argv 
)

MACRO DEFINITIONS ///.

FUNCTION DEFINITIONS ///

MACRO DEFINITIONS ///.

CFile****************************************************************

FileName [cmdAlias.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures dealing with aliases in the command package.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
cmdAlias.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file cmdAlias.c.

47 {
48  Abc_Alias * pAlias;
49  int fStatus, i;
50 
51  pAlias = ABC_ALLOC(Abc_Alias, 1);
52  pAlias->sName = Extra_UtilStrsav(sName);
53  pAlias->argc = argc;
54  pAlias->argv = ABC_ALLOC(char *, pAlias->argc);
55  for(i = 0; i < argc; i++)
56  pAlias->argv[i] = Extra_UtilStrsav(argv[i]);
57  fStatus = st__insert( pAbc->tAliases, pAlias->sName, (char *) pAlias );
58  assert(!fStatus);
59 }
char ** argv
Definition: cmdInt.h:55
int argc
Definition: cmdInt.h:54
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
Definition: cmdInt.h:51
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
char * sName
Definition: cmdInt.h:53
#define assert(ex)
Definition: util_old.h:213
void CmdCommandAliasFree ( Abc_Alias pAlias)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 113 of file cmdAlias.c.

114 {
115  CmdFreeArgv( pAlias->argc, pAlias->argv );
116  ABC_FREE(pAlias->sName);
117  ABC_FREE(pAlias);
118 }
char ** argv
Definition: cmdInt.h:55
int argc
Definition: cmdInt.h:54
void CmdFreeArgv(int argc, char **argv)
Definition: cmdUtils.c:485
char * sName
Definition: cmdInt.h:53
#define ABC_FREE(obj)
Definition: abc_global.h:232
char* CmdCommandAliasLookup ( Abc_Frame_t pAbc,
char *  sCommand 
)

Function********************************************************************

Synopsis [required]

Description [optional]

SideEffects [required]

SeeAlso [optional]

Definition at line 92 of file cmdAlias.c.

93 {
94  Abc_Alias * pAlias;
95  char * value;
96  if (! st__lookup( pAbc->tAliases, sCommand, &value))
97  return sCommand;
98  pAlias = (Abc_Alias *) value;
99  return pAlias->argv[0];
100 }
char ** argv
Definition: cmdInt.h:55
Definition: cmdInt.h:51
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
int value
void CmdCommandAliasPrint ( Abc_Frame_t pAbc,
Abc_Alias pAlias 
)

Function********************************************************************

Synopsis [required]

Description [optional]

SideEffects [required]

SeeAlso [optional]

Definition at line 72 of file cmdAlias.c.

73 {
74  int i;
75  fprintf(pAbc->Out, "%-15s", pAlias->sName);
76  for(i = 0; i < pAlias->argc; i++)
77  fprintf( pAbc->Out, " %s", pAlias->argv[i] );
78  fprintf( pAbc->Out, "\n" );
79 }
char ** argv
Definition: cmdInt.h:55
int argc
Definition: cmdInt.h:54
char * sName
Definition: cmdInt.h:53
int CmdCommandDispatch ( Abc_Frame_t pAbc,
int *  pargc,
char ***  pargv 
)

Function*************************************************************

Synopsis [Executes one command.]

Description []

SideEffects []

SeeAlso []

Definition at line 93 of file cmdUtils.c.

94 {
95  int argc = *pargc;
96  char ** argv = *pargv;
97  char ** argv2;
98 
99  Abc_Ntk_t * pNetCopy;
100  int (*pFunc) ( Abc_Frame_t *, int, char ** );
101  Abc_Command * pCommand;
102  char * value;
103  int fError;
104  double clk;
105 
106  if ( argc == 0 )
107  return 0;
108 
109  if ( cmdCheckShellEscape( pAbc, argc, argv ) == 1 )
110  return 0;
111 
112  // get the command
113  if ( ! st__lookup( pAbc->tCommands, argv[0], (char **)&pCommand ) )
114  { // the command is not in the table
115  // if there is only one word with an extension, assume this is file to be read
116  if ( argc == 1 && strstr( argv[0], "." ) )
117  {
118  // add command 'read' assuming that this is the file name
119  argv2 = CmdAddToArgv( argc, argv );
120  CmdFreeArgv( argc, argv );
121  argc = argc+1;
122  argv = argv2;
123  *pargc = argc;
124  *pargv = argv;
125  if ( ! st__lookup( pAbc->tCommands, argv[0], (char **)&pCommand ) )
126  assert( 0 );
127  }
128  else
129  {
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" );
133  return 1;
134  }
135  }
136 
137  // get the backup network if the command is going to change the network
138  if ( pCommand->fChange )
139  {
140  if ( pAbc->pNtkCur && Abc_FrameIsFlagEnabled( "backup" ) )
141  {
142  pNetCopy = Abc_NtkDup( pAbc->pNtkCur );
143  Abc_FrameSetCurrentNetwork( pAbc, pNetCopy );
144  // swap the current network and the backup network
145  // to prevent the effect of resetting the short names
147  }
148  }
149 
150  // execute the command
151  clk = Extra_CpuTimeDouble();
152  pFunc = (int (*)(Abc_Frame_t *, int, char **))pCommand->pFunc;
153  fError = (*pFunc)( pAbc, argc, argv );
154  pAbc->TimeCommand += Extra_CpuTimeDouble() - clk;
155 
156  // automatic execution of arbitrary command after each command
157  // usually this is a passive command ...
158  if ( fError == 0 && !pAbc->fAutoexac )
159  {
160  if ( st__lookup( pAbc->tFlags, "autoexec", &value ) )
161  {
162  pAbc->fAutoexac = 1;
163  fError = Cmd_CommandExecute( pAbc, value );
164  pAbc->fAutoexac = 0;
165  }
166  }
167  return fError;
168 }
typedefABC_NAMESPACE_HEADER_START struct MvCommand Abc_Command
INCLUDES ///.
Definition: cmd.h:39
ABC_DLL void Abc_FrameSwapCurrentAndBackup(Abc_Frame_t *p)
Definition: mainFrame.c:451
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
ABC_DLL void Abc_FrameSetCurrentNetwork(Abc_Frame_t *p, Abc_Ntk_t *pNet)
Definition: mainFrame.c:396
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
double Extra_CpuTimeDouble()
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
char * strstr()
char ** CmdAddToArgv(int argc, char **argv)
Definition: cmdUtils.c:512
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
void CmdFreeArgv(int argc, char **argv)
Definition: cmdUtils.c:485
ABC_DLL int Abc_FrameIsFlagEnabled(char *pFlag)
Definition: mainFrame.c:113
int value
#define assert(ex)
Definition: util_old.h:213
int cmdCheckShellEscape(Abc_Frame_t *pAbc, int argc, char **argv)
FUNCTION DEFINITIONS ///.
Definition: cmdUtils.c:50
void CmdCommandFree ( Abc_Command pCommand)

Function*************************************************************

Synopsis [Frees the previously allocated command.]

Description []

SideEffects []

SeeAlso []

Definition at line 535 of file cmdUtils.c.

536 {
537  ABC_FREE( pCommand->sGroup );
538  ABC_FREE( pCommand->sName );
539  ABC_FREE( pCommand );
540 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
void CmdCommandPrint ( Abc_Frame_t pAbc,
int  fPrintAll,
int  fDetails 
)

Function*************************************************************

Synopsis [Prints commands alphabetically by group.]

Description []

SideEffects []

SeeAlso []

Definition at line 554 of file cmdUtils.c.

555 {
556  const char *key;
557  char *value;
558  st__generator * gen;
559  Abc_Command ** ppCommands;
560  Abc_Command * pCommands;
561  int nCommands, iGroupStart, i, j;
562  char * sGroupCur;
563  int LenghtMax, nColumns, iCom = 0;
564  FILE *backupErr = pAbc->Err;
565 
566  // put all commands into one array
567  nCommands = st__count( pAbc->tCommands );
568  ppCommands = ABC_ALLOC( Abc_Command *, nCommands );
569  i = 0;
570  st__foreach_item( pAbc->tCommands, gen, &key, &value )
571  {
572  pCommands = (Abc_Command *)value;
573  if ( fPrintAll || pCommands->sName[0] != '_' )
574  ppCommands[i++] = pCommands;
575  }
576  nCommands = i;
577 
578  // sort command by group and then by name, alphabetically
579  qsort( (void *)ppCommands, nCommands, sizeof(Abc_Command *),
580  (int (*)(const void *, const void *)) CmdCommandPrintCompare );
581  assert( CmdCommandPrintCompare( ppCommands, ppCommands + nCommands - 1 ) <= 0 );
582 
583  // get the longest command name
584  LenghtMax = 0;
585  for ( i = 0; i < nCommands; i++ )
586  if ( LenghtMax < (int)strlen(ppCommands[i]->sName) )
587  LenghtMax = (int)strlen(ppCommands[i]->sName);
588  // get the number of columns
589  nColumns = 79 / (LenghtMax + 2);
590 
591  // print the starting message
592  fprintf( pAbc->Out, " Welcome to ABC compiled on %s %s!", __DATE__, __TIME__ );
593 
594  // print the command by group
595  sGroupCur = NULL;
596  iGroupStart = 0;
597  pAbc->Err = pAbc->Out;
598  for ( i = 0; i < nCommands; i++ )
599  if ( sGroupCur && strcmp( sGroupCur, ppCommands[i]->sGroup ) == 0 )
600  { // this command belongs to the same group as the previous one
601  if ( iCom++ % nColumns == 0 )
602  fprintf( pAbc->Out, "\n" );
603  // print this command
604  fprintf( pAbc->Out, " %-*s", LenghtMax, ppCommands[i]->sName );
605  }
606  else
607  { // this command starts the new group of commands
608  // start the new group
609  if ( fDetails && i != iGroupStart )
610  { // print help messages for all commands in the previous groups
611  fprintf( pAbc->Out, "\n" );
612  for ( j = iGroupStart; j < i; j++ )
613  {
614  char *tmp_cmd;
615  fprintf( pAbc->Out, "\n" );
616  // fprintf( pAbc->Out, "--- %s ---\n", ppCommands[j]->sName );
617  tmp_cmd = ABC_ALLOC(char, strlen(ppCommands[j]->sName)+4);
618  (void) sprintf(tmp_cmd, "%s -h", ppCommands[j]->sName);
619  (void) Cmd_CommandExecute( pAbc, tmp_cmd );
620  ABC_FREE(tmp_cmd);
621  }
622  fprintf( pAbc->Out, "\n" );
623  fprintf( pAbc->Out, " ----------------------------------------------------------------------" );
624  iGroupStart = i;
625  }
626  fprintf( pAbc->Out, "\n" );
627  fprintf( pAbc->Out, "\n" );
628  fprintf( pAbc->Out, "%s commands:\n", ppCommands[i]->sGroup );
629  // print this command
630  fprintf( pAbc->Out, " %-*s", LenghtMax, ppCommands[i]->sName );
631  // remember current command group
632  sGroupCur = ppCommands[i]->sGroup;
633  // reset the command counter
634  iCom = 1;
635  }
636  if ( fDetails && i != iGroupStart )
637  { // print help messages for all commands in the previous groups
638  fprintf( pAbc->Out, "\n" );
639  for ( j = iGroupStart; j < i; j++ )
640  {
641  char *tmp_cmd;
642  fprintf( pAbc->Out, "\n" );
643  // fprintf( pAbc->Out, "--- %s ---\n", ppCommands[j]->sName );
644  tmp_cmd = ABC_ALLOC(char, strlen(ppCommands[j]->sName)+4);
645  (void) sprintf(tmp_cmd, "%s -h", ppCommands[j]->sName);
646  (void) Cmd_CommandExecute( pAbc, tmp_cmd );
647  ABC_FREE(tmp_cmd);
648  }
649  }
650  pAbc->Err = backupErr;
651  fprintf( pAbc->Out, "\n" );
652  ABC_FREE( ppCommands );
653 }
typedefABC_NAMESPACE_HEADER_START struct MvCommand Abc_Command
INCLUDES ///.
Definition: cmd.h:39
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static ABC_NAMESPACE_IMPL_START int CmdCommandPrintCompare(Abc_Command **ppC1, Abc_Command **ppC2)
DECLARATIONS ///.
Definition: cmdUtils.c:666
int strcmp()
#define st__count(table)
Definition: st.h:71
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
enum keys key
int value
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
#define assert(ex)
Definition: util_old.h:213
int strlen()
FILE* CmdFileOpen ( Abc_Frame_t pAbc,
char *  sFileName,
char *  sMode,
char **  pFileNameReal,
int  silent 
)

Function*************************************************************

Synopsis [Opens the file with path (now, disabled).]

Description []

SideEffects []

SeeAlso []

Definition at line 408 of file cmdUtils.c.

409 {
410  char * sRealName, * sPathUsr, * sPathLib, * sPathAll;
411  FILE * pFile;
412 
413  if (strcmp(sFileName, "-") == 0) {
414  if (strcmp(sMode, "w") == 0) {
415  sRealName = Extra_UtilStrsav( "stdout" );
416  pFile = stdout;
417  }
418  else {
419  sRealName = Extra_UtilStrsav( "stdin" );
420  pFile = stdin;
421  }
422  }
423  else {
424  sRealName = NULL;
425  if (strcmp(sMode, "r") == 0) {
426 
427  /* combine both pathes if exist */
428  sPathUsr = Cmd_FlagReadByName(pAbc,"open_path");
429  sPathLib = Cmd_FlagReadByName(pAbc,"lib_path");
430 
431  if ( sPathUsr == NULL && sPathLib == NULL ) {
432  sPathAll = NULL;
433  }
434  else if ( sPathUsr == NULL ) {
435  sPathAll = Extra_UtilStrsav( sPathLib );
436  }
437  else if ( sPathLib == NULL ) {
438  sPathAll = Extra_UtilStrsav( sPathUsr );
439  }
440  else {
441  sPathAll = ABC_ALLOC( char, strlen(sPathLib)+strlen(sPathUsr)+5 );
442  sprintf( sPathAll, "%s:%s",sPathUsr, sPathLib );
443  }
444  if ( sPathAll != NULL ) {
445  sRealName = Extra_UtilFileSearch(sFileName, sPathAll, "r");
446  ABC_FREE( sPathAll );
447  }
448  }
449  if (sRealName == NULL) {
450  sRealName = Extra_UtilTildeExpand(sFileName);
451  }
452 
453  if ((pFile = fopen(sRealName, sMode)) == NULL) {
454  if (! silent) {
455 // perror(sRealName);
456  Abc_Print( 1, "Cannot open file \"%s\".\n", sRealName );
457  }
458  }
459  else
460  {
461  // print the path/name of the resource file 'abc.rc' that is being loaded
462  if ( !silent && strlen(sRealName) >= 6 && strcmp( sRealName + strlen(sRealName) - 6, "abc.rc" ) == 0 )
463  Abc_Print( 1, "Loading resource file \"%s\".\n", sRealName );
464  }
465  }
466  if ( pFileNameReal )
467  *pFileNameReal = sRealName;
468  else
469  ABC_FREE(sRealName);
470 
471  return pFile;
472 }
char * Extra_UtilFileSearch(char *file, char *path, char *mode)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
int strcmp()
char * sprintf()
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
char * Extra_UtilTildeExpand(char *fname)
char * Cmd_FlagReadByName(Abc_Frame_t *pAbc, char *flag)
DECLARATIONS ///.
Definition: cmdFlag.c:47
void CmdFreeArgv ( int  argc,
char **  argv 
)

Function*************************************************************

Synopsis [Frees the previously allocated argv array.]

Description []

SideEffects []

SeeAlso []

Definition at line 485 of file cmdUtils.c.

486 {
487  int i;
488  for ( i = 0; i < argc; i++ )
489  ABC_FREE( argv[i] );
490  ABC_FREE( argv );
491 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
char* CmdHistorySubstitution ( Abc_Frame_t pAbc,
char *  line,
int *  changed 
)

Function*************************************************************

Synopsis [Performs history substitution (now, disabled).]

Description []

SideEffects []

SeeAlso []

Definition at line 390 of file cmdUtils.c.

391 {
392  // as of today, no history substitution
393  *changed = 0;
394  return line;
395 }
void CmdPrintTable ( st__table tTable,
int  fAliases 
)

Function*************************************************************

Synopsis [Comparision function used for sorting commands.]

Description []

SideEffects []

SeeAlso []

Definition at line 722 of file cmdUtils.c.

723 {
724  st__generator * gen;
725  const char ** ppNames;
726  const char * key;
727  char* value;
728  int nNames, i;
729 
730  // collect keys in the array
731  ppNames = ABC_ALLOC( const char *, st__count(tTable) );
732  nNames = 0;
733  st__foreach_item( tTable, gen, &key, &value )
734  ppNames[nNames++] = key;
735 
736  // sort array by name
737  qsort( (void *)ppNames, nNames, sizeof(char *),
738  (int (*)(const void *, const void *))CmdNamePrintCompare );
739 
740  // print in this order
741  for ( i = 0; i < nNames; i++ )
742  {
743  st__lookup( tTable, ppNames[i], &value );
744  if ( fAliases )
746  else
747  fprintf( stdout, "%-15s %-15s\n", ppNames[i], value );
748  }
749  ABC_FREE( ppNames );
750 }
Definition: cmdInt.h:51
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
for(p=first;p->value< newval;p=p->next)
#define st__count(table)
Definition: st.h:71
int CmdNamePrintCompare(char **ppC1, char **ppC2)
Definition: cmdUtils.c:706
void * Abc_FrameGetGlobalFrame()
Definition: mainFrame.c:593
void CmdCommandAliasPrint(Abc_Frame_t *pAbc, Abc_Alias *pAlias)
Definition: cmdAlias.c:72
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
#define ABC_FREE(obj)
Definition: abc_global.h:232
enum keys key
int value
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
#define const
Definition: zconf.h:196
const char* CmdSplitLine ( Abc_Frame_t pAbc,
const char *  sCommand,
int *  argc,
char ***  argv 
)

Function*************************************************************

Synopsis [Splits the command line string into individual commands.]

Description []

SideEffects []

SeeAlso []

Definition at line 181 of file cmdUtils.c.

182 {
183  const char *p, *start;
184  char c;
185  int i, j;
186  char *new_arg;
187  Vec_Ptr_t * vArgs;
188  int single_quote, double_quote;
189 
190  vArgs = Vec_PtrAlloc( 10 );
191 
192  p = sCommand;
193  for ( ;; )
194  {
195  // skip leading white space
196  while ( isspace( ( int ) *p ) )
197  {
198  p++;
199  }
200 
201  // skip until end of this token
202  single_quote = double_quote = 0;
203  for ( start = p; ( c = *p ) != '\0'; p++ )
204  {
205  if ( c == ';' || c == '#' || isspace( ( int ) c ) )
206  {
207  if ( !single_quote && !double_quote )
208  {
209  break;
210  }
211  }
212  if ( c == '\'' )
213  {
214  single_quote = !single_quote;
215  }
216  if ( c == '"' )
217  {
218  double_quote = !double_quote;
219  }
220  }
221  if ( single_quote || double_quote )
222  {
223  ( void ) fprintf( pAbc->Err, "** cmd warning: ignoring unbalanced quote ...\n" );
224  }
225  if ( start == p )
226  break;
227 
228  new_arg = ABC_ALLOC( char, p - start + 1 );
229  j = 0;
230  for ( i = 0; i < p - start; i++ )
231  {
232  c = start[i];
233  if ( ( c != '\'' ) && ( c != '\"' ) )
234  {
235  new_arg[j++] = isspace( ( int ) c ) ? ' ' : start[i];
236  }
237  }
238  new_arg[j] = '\0';
239  Vec_PtrPush( vArgs, new_arg );
240  }
241 
242  *argc = vArgs->nSize;
243  *argv = (char **)Vec_PtrReleaseArray( vArgs );
244  Vec_PtrFree( vArgs );
245  if ( *p == ';' )
246  {
247  p++;
248  }
249  else if ( *p == '#' )
250  {
251  for ( ; *p != 0; p++ ); // skip to end of line
252  }
253  return p;
254 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static void ** Vec_PtrReleaseArray(Vec_Ptr_t *p)
Definition: vecPtr.h:259