src/misc/extra/extraUtilProgress.c File Reference

#include <stdio.h>
#include "extra.h"
Include dependency graph for extraUtilProgress.c:

Go to the source code of this file.

Data Structures

struct  ProgressBarStruct

Functions

static void Extra_ProgressBarShow (ProgressBar *p, char *pString)
static void Extra_ProgressBarClean (ProgressBar *p)
ProgressBarExtra_ProgressBarStart (FILE *pFile, int nItemsTotal)
void Extra_ProgressBarUpdate_int (ProgressBar *p, int nItemsCur, char *pString)
void Extra_ProgressBarStop (ProgressBar *p)

Function Documentation

void Extra_ProgressBarClean ( ProgressBar p  )  [static]

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

Synopsis [Cleans the progress bar before quitting.]

Description []

SideEffects []

SeeAlso []

Definition at line 162 of file extraUtilProgress.c.

00163 {
00164     int i;
00165     if ( p == NULL ) return;
00166     for ( i = 0; i <= p->posTotal; i++ )
00167         fprintf( p->pFile, " " );
00168     fprintf( p->pFile, "\r" );
00169     fflush( stdout );
00170 }

void Extra_ProgressBarShow ( ProgressBar p,
char *  pString 
) [static]

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

Synopsis [Prints the progress bar of the given size.]

Description []

SideEffects []

SeeAlso []

Definition at line 135 of file extraUtilProgress.c.

00136 {
00137     int i;
00138     if ( p == NULL ) return;
00139     if ( pString )
00140         fprintf( p->pFile, "%s ", pString );
00141     for ( i = (pString? strlen(pString) + 1 : 0); i < p->posCur; i++ )
00142         fprintf( p->pFile, "-" );
00143     if ( i == p->posCur )
00144         fprintf( p->pFile, ">" );
00145     for ( i++  ; i <= p->posTotal; i++ )
00146         fprintf( p->pFile, " " );
00147     fprintf( p->pFile, "\r" );
00148     fflush( stdout );
00149 }

ProgressBar* Extra_ProgressBarStart ( FILE *  pFile,
int  nItemsTotal 
)

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 []

Definition at line 58 of file extraUtilProgress.c.

00059 {
00060     ProgressBar * p;
00061     extern int Abc_FrameShowProgress( void * p );
00062     extern void * Abc_FrameGetGlobalFrame();
00063 
00064     if ( !Abc_FrameShowProgress(Abc_FrameGetGlobalFrame()) ) return NULL;
00065     p = ALLOC( ProgressBar, 1 );
00066     memset( p, 0, sizeof(ProgressBar) );
00067     p->pFile       = pFile;
00068     p->nItemsTotal = nItemsTotal;
00069     p->posTotal    = 78;
00070     p->posCur      = 1;
00071     p->nItemsNext  = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
00072     Extra_ProgressBarShow( p, NULL );
00073     return p;
00074 }

void Extra_ProgressBarStop ( ProgressBar p  ) 

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

Synopsis [Stops the progress bar.]

Description []

SideEffects []

SeeAlso []

Definition at line 117 of file extraUtilProgress.c.

00118 {
00119     if ( p == NULL ) return;
00120     Extra_ProgressBarClean( p );
00121     FREE( p );
00122 }

void Extra_ProgressBarUpdate_int ( ProgressBar p,
int  nItemsCur,
char *  pString 
)

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

Synopsis [Updates the progress bar.]

Description []

SideEffects []

SeeAlso []

Definition at line 87 of file extraUtilProgress.c.

00088 {
00089     if ( p == NULL ) return;
00090     if ( nItemsCur < p->nItemsNext )
00091         return;
00092     if ( nItemsCur >= p->nItemsTotal )
00093     {
00094         p->posCur = 78;
00095         p->nItemsNext = 0x7FFFFFFF;
00096     }
00097     else
00098     {
00099         p->posCur += 7;
00100         p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
00101     }
00102     Extra_ProgressBarShow( p, pString );
00103 }


Generated on Tue Jan 5 12:19:15 2010 for abc70930 by  doxygen 1.6.1