From 5978ccdb52394f2e92df41a895335eced0c4fe7a Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Thu, 21 Dec 2023 12:16:33 +0900 Subject: [PATCH] Updating sleep command to wait for file. --- src/base/cmd/cmd.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index 5a752a5d49..a18387acde 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -244,6 +244,7 @@ int CmdCommandTime( Abc_Frame_t * pAbc, int argc, char **argv ) int CmdCommandSleep( Abc_Frame_t * pAbc, int argc, char **argv ) { abctime clkStop; + char * pFileName = NULL; int c, nSecs = 1; Extra_UtilGetoptReset(); while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF ) @@ -267,15 +268,25 @@ int CmdCommandSleep( Abc_Frame_t * pAbc, int argc, char **argv ) goto usage; } } + + if ( argc == globalUtilOptind + 1 ) { + FILE * pFile = NULL; + pFileName = argv[globalUtilOptind]; + while ( (pFile = fopen(pFileName, "rb")) == NULL ); + if ( pFile != NULL ) + fclose( pFile ); + } + clkStop = Abc_Clock() + nSecs * CLOCKS_PER_SEC; while ( Abc_Clock() < clkStop ); return 0; usage: - fprintf( pAbc->Err, "usage: sleep [-N ] [-h]\n" ); - fprintf( pAbc->Err, " puts ABC to sleep for the given time\n" ); - fprintf( pAbc->Err, "-N num time in seconds [default = %d]\n", nSecs ); - fprintf( pAbc->Err, "-h print the command usage\n" ); + fprintf( pAbc->Err, "usage: sleep [-N ] [-h] \n" ); + fprintf( pAbc->Err, "\t puts ABC to sleep for some time\n" ); + fprintf( pAbc->Err, "\t-N num : time duration in seconds [default = %d]\n", nSecs ); + fprintf( pAbc->Err, "\t-h : toggle printing the command usage\n" ); + fprintf( pAbc->Err, "\t : (optional) waiting begins after the file is created\n" ); return 1; } /**Function********************************************************************