Commit 1c865bf2 by Niklas Een

Added -C to command line for running commands, then staying in interactive mode

parent 784a3579
...@@ -90,14 +90,14 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -90,14 +90,14 @@ int Abc_RealMain( int argc, char * argv[] )
char * sCommand; char * sCommand;
int fStatus = 0; int fStatus = 0;
int c, fBatch, fInitSource, fInitRead, fFinalWrite; int c, fBatch, fInitSource, fInitRead, fFinalWrite;
// added to detect memory leaks // added to detect memory leaks
// watch for {,,msvcrtd.dll}*__p__crtBreakAlloc() // watch for {,,msvcrtd.dll}*__p__crtBreakAlloc()
// (http://support.microsoft.com/kb/151585) // (http://support.microsoft.com/kb/151585)
#if defined(_DEBUG) && defined(_MSC_VER) #if defined(_DEBUG) && defined(_MSC_VER)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif #endif
// Npn_Experiment(); // Npn_Experiment();
// Npn_Generate(); // Npn_Generate();
...@@ -136,15 +136,20 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -136,15 +136,20 @@ int Abc_RealMain( int argc, char * argv[] )
sInFile = sOutFile = NULL; sInFile = sOutFile = NULL;
sprintf( sReadCmd, "read" ); sprintf( sReadCmd, "read" );
sprintf( sWriteCmd, "write" ); sprintf( sWriteCmd, "write" );
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ((c = Extra_UtilGetopt(argc, argv, "c:hf:F:o:st:T:xb")) != EOF) { while ((c = Extra_UtilGetopt(argc, argv, "c:C:hf:F:o:st:T:xb")) != EOF) {
switch(c) { switch(c) {
case 'c': case 'c':
strcpy( sCommandUsr, globalUtilOptarg ); strcpy( sCommandUsr, globalUtilOptarg );
fBatch = 1; fBatch = 1;
break; break;
case 'C':
strcpy( sCommandUsr, globalUtilOptarg );
fBatch = 2;
break;
case 'f': case 'f':
sprintf(sCommandUsr, "source %s", globalUtilOptarg); sprintf(sCommandUsr, "source %s", globalUtilOptarg);
fBatch = 1; fBatch = 1;
...@@ -154,20 +159,20 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -154,20 +159,20 @@ int Abc_RealMain( int argc, char * argv[] )
sprintf(sCommandUsr, "source -x %s", globalUtilOptarg); sprintf(sCommandUsr, "source -x %s", globalUtilOptarg);
fBatch = 1; fBatch = 1;
break; break;
case 'h': case 'h':
goto usage; goto usage;
break; break;
case 'o': case 'o':
sOutFile = globalUtilOptarg; sOutFile = globalUtilOptarg;
fFinalWrite = 1; fFinalWrite = 1;
break; break;
case 's': case 's':
fInitSource = 0; fInitSource = 0;
break; break;
case 't': case 't':
if ( TypeCheck( pAbc, globalUtilOptarg ) ) if ( TypeCheck( pAbc, globalUtilOptarg ) )
{ {
...@@ -182,7 +187,7 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -182,7 +187,7 @@ int Abc_RealMain( int argc, char * argv[] )
} }
fBatch = 1; fBatch = 1;
break; break;
case 'T': case 'T':
if ( TypeCheck( pAbc, globalUtilOptarg ) ) if ( TypeCheck( pAbc, globalUtilOptarg ) )
{ {
...@@ -197,17 +202,17 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -197,17 +202,17 @@ int Abc_RealMain( int argc, char * argv[] )
} }
fBatch = 1; fBatch = 1;
break; break;
case 'x': case 'x':
fFinalWrite = 0; fFinalWrite = 0;
fInitRead = 0; fInitRead = 0;
fBatch = 1; fBatch = 1;
break; break;
case 'b': case 'b':
Abc_FrameSetBridgeMode(); Abc_FrameSetBridgeMode();
break; break;
default: default:
goto usage; goto usage;
} }
...@@ -220,7 +225,7 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -220,7 +225,7 @@ int Abc_RealMain( int argc, char * argv[] )
} }
else if ( fBatch && sCommandUsr[0] ) else if ( fBatch && sCommandUsr[0] )
Abc_Print( 1, "ABC command line: \"%s\".\n\n", sCommandUsr ); Abc_Print( 1, "ABC command line: \"%s\".\n\n", sCommandUsr );
if ( fBatch ) if ( fBatch )
{ {
pAbc->fBatchMode = 1; pAbc->fBatchMode = 1;
...@@ -239,20 +244,20 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -239,20 +244,20 @@ int Abc_RealMain( int argc, char * argv[] )
{ {
Abc_UtilsPrintUsage( pAbc, argv[0] ); Abc_UtilsPrintUsage( pAbc, argv[0] );
} }
// source the resource file // source the resource file
if ( fInitSource ) if ( fInitSource )
{ {
Abc_UtilsSource( pAbc ); Abc_UtilsSource( pAbc );
} }
fStatus = 0; fStatus = 0;
if ( fInitRead && sInFile ) if ( fInitRead && sInFile )
{ {
sprintf( sCommandTmp, "%s %s", sReadCmd, sInFile ); sprintf( sCommandTmp, "%s %s", sReadCmd, sInFile );
fStatus = Cmd_CommandExecute( pAbc, sCommandTmp ); fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
} }
if ( fStatus == 0 ) if ( fStatus == 0 )
{ {
/* cmd line contains `source <file>' */ /* cmd line contains `source <file>' */
...@@ -263,9 +268,15 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -263,9 +268,15 @@ int Abc_RealMain( int argc, char * argv[] )
fStatus = Cmd_CommandExecute( pAbc, sCommandTmp ); fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
} }
} }
if (fBatch == 2){
fBatch = 0;
pAbc->fBatchMode = 0;
}
} }
else
if ( !fBatch )
{ {
// start interactive mode // start interactive mode
...@@ -273,28 +284,28 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -273,28 +284,28 @@ int Abc_RealMain( int argc, char * argv[] )
Abc_UtilsPrintHello( pAbc ); Abc_UtilsPrintHello( pAbc );
// print history of the recent commands // print history of the recent commands
Cmd_HistoryPrint( pAbc, 10 ); Cmd_HistoryPrint( pAbc, 10 );
// source the resource file // source the resource file
if ( fInitSource ) if ( fInitSource )
{ {
Abc_UtilsSource( pAbc ); Abc_UtilsSource( pAbc );
} }
// execute commands given by the user // execute commands given by the user
while ( !feof(stdin) ) while ( !feof(stdin) )
{ {
// print command line prompt and // print command line prompt and
// get the command from the user // get the command from the user
sCommand = Abc_UtilsGetUsersInput( pAbc ); sCommand = Abc_UtilsGetUsersInput( pAbc );
// execute the user's command // execute the user's command
fStatus = Cmd_CommandExecute( pAbc, sCommand ); fStatus = Cmd_CommandExecute( pAbc, sCommand );
// stop if the user quitted or an error occurred // stop if the user quitted or an error occurred
if ( fStatus == -1 || fStatus == -2 ) if ( fStatus == -1 || fStatus == -2 )
break; break;
} }
} }
#ifdef ABC_PYTHON_EMBED #ifdef ABC_PYTHON_EMBED
{ {
...@@ -305,9 +316,9 @@ int Abc_RealMain( int argc, char * argv[] ) ...@@ -305,9 +316,9 @@ int Abc_RealMain( int argc, char * argv[] )
// if the memory should be freed, quit packages // if the memory should be freed, quit packages
// if ( fStatus < 0 ) // if ( fStatus < 0 )
{ {
Abc_Stop(); Abc_Stop();
} }
return 0; return 0;
usage: usage:
Abc_UtilsPrintHello( pAbc ); Abc_UtilsPrintHello( pAbc );
......
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