summaryrefslogtreecommitdiffstats
path: root/src/misc/bar
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-01-21 04:30:10 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2012-01-21 04:30:10 -0800
commit8014f25f6db719fa62336f997963532a14c568f6 (patch)
treec691ee91a3a2d452a2bd24ac89a8c717beaa7af7 /src/misc/bar
parentc44cc5de9429e6b4f1c05045fcf43c9cb96437b5 (diff)
downloadabc-8014f25f6db719fa62336f997963532a14c568f6.tar.gz
abc-8014f25f6db719fa62336f997963532a14c568f6.tar.bz2
abc-8014f25f6db719fa62336f997963532a14c568f6.zip
Major restructuring of the code.
Diffstat (limited to 'src/misc/bar')
-rw-r--r--src/misc/bar/bar.c187
-rw-r--r--src/misc/bar/bar.h78
-rw-r--r--src/misc/bar/module.make1
3 files changed, 266 insertions, 0 deletions
diff --git a/src/misc/bar/bar.c b/src/misc/bar/bar.c
new file mode 100644
index 00000000..565a969e
--- /dev/null
+++ b/src/misc/bar/bar.c
@@ -0,0 +1,187 @@
+/**CFile****************************************************************
+
+ FileName [bar.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [extra]
+
+ Synopsis [Progress bar.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: bar.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "src/misc/util/abc_global.h"
+#include "src/base/main/main.h"
+#include "bar.h"
+
+ABC_NAMESPACE_IMPL_START
+
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+struct Bar_Progress_t_
+{
+ int nItemsNext; // the number of items for the next update of the progress bar
+ int nItemsTotal; // the total number of items
+ int posTotal; // the total number of positions
+ int posCur; // the current position
+ FILE * pFile; // the output stream
+};
+
+static void Bar_ProgressShow( Bar_Progress_t * p, char * pString );
+static void Bar_ProgressClean( Bar_Progress_t * p );
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Starts the progress bar.]
+
+ Description [The first parameter is the output stream (pFile), where
+ the progress is printed. The current printing position should be the
+ first one on the given line. The second parameters is the total
+ number of items that correspond to 100% position of the progress bar.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Bar_Progress_t * Bar_ProgressStart( FILE * pFile, int nItemsTotal )
+{
+ Bar_Progress_t * p;
+ Abc_Frame_t * pFrame;
+ pFrame = Abc_FrameReadGlobalFrame();
+ if ( pFrame == NULL )
+ return NULL;
+ if ( !Abc_FrameShowProgress(pFrame) ) return NULL;
+ p = ABC_ALLOC( Bar_Progress_t, 1 );
+ memset( p, 0, sizeof(Bar_Progress_t) );
+ p->pFile = pFile;
+ p->nItemsTotal = nItemsTotal;
+ p->posTotal = 78;
+ p->posCur = 1;
+ p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
+ Bar_ProgressShow( p, NULL );
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Updates the progress bar.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bar_ProgressUpdate_int( Bar_Progress_t * p, int nItemsCur, char * pString )
+{
+ if ( p == NULL ) return;
+ if ( nItemsCur < p->nItemsNext )
+ return;
+ if ( nItemsCur >= p->nItemsTotal )
+ {
+ p->posCur = 78;
+ p->nItemsNext = 0x7FFFFFFF;
+ }
+ else
+ {
+ p->posCur += 7;
+ p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
+ }
+ Bar_ProgressShow( p, pString );
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Stops the progress bar.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bar_ProgressStop( Bar_Progress_t * p )
+{
+ if ( p == NULL ) return;
+ Bar_ProgressClean( p );
+ ABC_FREE( p );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the progress bar of the given size.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bar_ProgressShow( Bar_Progress_t * p, char * pString )
+{
+ int i;
+ if ( p == NULL ) return;
+ if ( pString )
+ fprintf( p->pFile, "%s ", pString );
+ for ( i = (pString? strlen(pString) + 1 : 0); i < p->posCur; i++ )
+ fprintf( p->pFile, "-" );
+ if ( i == p->posCur )
+ fprintf( p->pFile, ">" );
+ for ( i++ ; i <= p->posTotal; i++ )
+ fprintf( p->pFile, " " );
+ fprintf( p->pFile, "\r" );
+ fflush( stdout );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Cleans the progress bar before quitting.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bar_ProgressClean( Bar_Progress_t * p )
+{
+ int i;
+ if ( p == NULL ) return;
+ for ( i = 0; i <= p->posTotal; i++ )
+ fprintf( p->pFile, " " );
+ fprintf( p->pFile, "\r" );
+ fflush( stdout );
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
+ABC_NAMESPACE_IMPL_END
+
diff --git a/src/misc/bar/bar.h b/src/misc/bar/bar.h
new file mode 100644
index 00000000..c66e302e
--- /dev/null
+++ b/src/misc/bar/bar.h
@@ -0,0 +1,78 @@
+/**CFile****************************************************************
+
+ FileName [bar.h]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Progress bar.]
+
+ Synopsis [External declarations.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: bar.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#ifndef ABC__aig__bar__bar_h
+#define ABC__aig__bar__bar_h
+
+
+#ifdef _WIN32
+#define inline __inline // compatible with MS VS 6.0
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// INCLUDES ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// PARAMETERS ///
+////////////////////////////////////////////////////////////////////////
+
+
+
+ABC_NAMESPACE_HEADER_START
+
+
+#define BAR_PROGRESS_USE 1
+
+////////////////////////////////////////////////////////////////////////
+/// BASIC TYPES ///
+////////////////////////////////////////////////////////////////////////
+
+typedef struct Bar_Progress_t_ Bar_Progress_t;
+
+////////////////////////////////////////////////////////////////////////
+/// MACRO DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/*=== bar.c ==========================================================*/
+extern Bar_Progress_t * Bar_ProgressStart( FILE * pFile, int nItemsTotal );
+extern void Bar_ProgressStop( Bar_Progress_t * p );
+extern void Bar_ProgressUpdate_int( Bar_Progress_t * p, int nItemsCur, char * pString );
+
+static inline void Bar_ProgressUpdate( Bar_Progress_t * p, int nItemsCur, char * pString ) {
+ if ( BAR_PROGRESS_USE && p && (nItemsCur < *((int*)p)) ) return; Bar_ProgressUpdate_int(p, nItemsCur, pString); }
+
+
+
+
+ABC_NAMESPACE_HEADER_END
+
+
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
diff --git a/src/misc/bar/module.make b/src/misc/bar/module.make
new file mode 100644
index 00000000..7234e386
--- /dev/null
+++ b/src/misc/bar/module.make
@@ -0,0 +1 @@
+SRC += src/misc/bar/bar.c