abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bar.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc/util/abc_global.h"
#include "base/main/main.h"
#include "bar.h"

Go to the source code of this file.

Data Structures

struct  Bar_Progress_t_
 DECLARATIONS ///. More...
 

Functions

static void Bar_ProgressShow (Bar_Progress_t *p, char *pString)
 
static void Bar_ProgressClean (Bar_Progress_t *p)
 
Bar_Progress_tBar_ProgressStart (FILE *pFile, int nItemsTotal)
 FUNCTION DEFINITIONS ///. More...
 
void Bar_ProgressUpdate_int (Bar_Progress_t *p, int nItemsCur, char *pString)
 
void Bar_ProgressStop (Bar_Progress_t *p)
 

Function Documentation

void Bar_ProgressClean ( Bar_Progress_t p)
static

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

Synopsis [Cleans the progress bar before quitting.]

Description []

SideEffects []

SeeAlso []

Definition at line 174 of file bar.c.

175 {
176  int i;
177  if ( p == NULL )
178  return;
179  if ( Abc_FrameIsBatchMode() )
180  return;
181  for ( i = 0; i <= p->posTotal; i++ )
182  fprintf( p->pFile, " " );
183  fprintf( p->pFile, "\r" );
184  fflush( stdout );
185 }
ABC_DLL int Abc_FrameIsBatchMode()
Definition: mainFrame.c:92
int posTotal
Definition: bar.c:40
FILE * pFile
Definition: bar.c:42
void Bar_ProgressShow ( Bar_Progress_t p,
char *  pString 
)
static

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 144 of file bar.c.

145 {
146  int i;
147  if ( p == NULL )
148  return;
149  if ( Abc_FrameIsBatchMode() )
150  return;
151  if ( pString )
152  fprintf( p->pFile, "%s ", pString );
153  for ( i = (pString? strlen(pString) + 1 : 0); i < p->posCur; i++ )
154  fprintf( p->pFile, "-" );
155  if ( i == p->posCur )
156  fprintf( p->pFile, ">" );
157  for ( i++ ; i <= p->posTotal; i++ )
158  fprintf( p->pFile, " " );
159  fprintf( p->pFile, "\r" );
160  fflush( stdout );
161 }
ABC_DLL int Abc_FrameIsBatchMode()
Definition: mainFrame.c:92
int posTotal
Definition: bar.c:40
FILE * pFile
Definition: bar.c:42
int posCur
Definition: bar.c:41
int strlen()
Bar_Progress_t* Bar_ProgressStart ( FILE *  pFile,
int  nItemsTotal 
)

FUNCTION DEFINITIONS ///.

MACRO 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 66 of file bar.c.

67 {
68  Bar_Progress_t * p;
69  Abc_Frame_t * pFrame;
70  pFrame = Abc_FrameReadGlobalFrame();
71  if ( pFrame == NULL )
72  return NULL;
73  if ( !Abc_FrameShowProgress(pFrame) ) return NULL;
74  p = ABC_ALLOC( Bar_Progress_t, 1 );
75  memset( p, 0, sizeof(Bar_Progress_t) );
76  p->pFile = pFile;
77  p->nItemsTotal = nItemsTotal;
78  p->posTotal = 78;
79  p->posCur = 1;
80  p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
81  Bar_ProgressShow( p, NULL );
82  return p;
83 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nItemsNext
Definition: bar.c:38
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
static void Bar_ProgressShow(Bar_Progress_t *p, char *pString)
Definition: bar.c:144
int posTotal
Definition: bar.c:40
DECLARATIONS ///.
Definition: bar.c:36
FILE * pFile
Definition: bar.c:42
int nItemsTotal
Definition: bar.c:39
ABC_DLL int Abc_FrameShowProgress(Abc_Frame_t *p)
Definition: mainFrame.c:265
int posCur
Definition: bar.c:41
ABC_DLL Abc_Frame_t * Abc_FrameReadGlobalFrame()
Definition: mainFrame.c:616
void Bar_ProgressStop ( Bar_Progress_t p)

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

Synopsis [Stops the progress bar.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file bar.c.

127 {
128  if ( p == NULL ) return;
129  Bar_ProgressClean( p );
130  ABC_FREE( p );
131 }
static void Bar_ProgressClean(Bar_Progress_t *p)
Definition: bar.c:174
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Bar_ProgressUpdate_int ( Bar_Progress_t p,
int  nItemsCur,
char *  pString 
)

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

Synopsis [Updates the progress bar.]

Description []

SideEffects []

SeeAlso []

Definition at line 96 of file bar.c.

97 {
98  if ( p == NULL ) return;
99  if ( nItemsCur < p->nItemsNext )
100  return;
101  if ( nItemsCur >= p->nItemsTotal )
102  {
103  p->posCur = 78;
104  p->nItemsNext = 0x7FFFFFFF;
105  }
106  else
107  {
108  p->posCur += 7;
109  p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
110  }
111  Bar_ProgressShow( p, pString );
112 }
int nItemsNext
Definition: bar.c:38
static void Bar_ProgressShow(Bar_Progress_t *p, char *pString)
Definition: bar.c:144
int posTotal
Definition: bar.c:40
int nItemsTotal
Definition: bar.c:39
int posCur
Definition: bar.c:41