abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilProgress.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [extraUtilProgress.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [extra]
8 
9  Synopsis [Progress bar.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: extraUtilProgress.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include <stdio.h>
22 #include "extra.h"
23 #include "base/main/main.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
33 {
34  int nItemsNext; // the number of items for the next update of the progress bar
35  int nItemsTotal; // the total number of items
36  int posTotal; // the total number of positions
37  int posCur; // the current position
38  FILE * pFile; // the output stream
39 };
40 
41 static void Extra_ProgressBarShow( ProgressBar * p, char * pString );
42 static void Extra_ProgressBarClean( ProgressBar * p );
43 
44 ////////////////////////////////////////////////////////////////////////
45 /// FUNCTION DEFINITIONS ///
46 ////////////////////////////////////////////////////////////////////////
47 
48 /**Function*************************************************************
49 
50  Synopsis [Starts the progress bar.]
51 
52  Description [The first parameter is the output stream (pFile), where
53  the progress is printed. The current printing position should be the
54  first one on the given line. The second parameters is the total
55  number of items that correspond to 100% position of the progress bar.]
56 
57  SideEffects []
58 
59  SeeAlso []
60 
61 ***********************************************************************/
62 ProgressBar * Extra_ProgressBarStart( FILE * pFile, int nItemsTotal )
63 {
64  ProgressBar * p;
65  if ( !Abc_FrameShowProgress(Abc_FrameGetGlobalFrame()) ) return NULL;
66  p = ABC_ALLOC( ProgressBar, 1 );
67  memset( p, 0, sizeof(ProgressBar) );
68  p->pFile = pFile;
69  p->nItemsTotal = nItemsTotal;
70  p->posTotal = 78;
71  p->posCur = 1;
72  p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
73  Extra_ProgressBarShow( p, NULL );
74  return p;
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Updates the progress bar.]
80 
81  Description []
82 
83  SideEffects []
84 
85  SeeAlso []
86 
87 ***********************************************************************/
88 void Extra_ProgressBarUpdate_int( ProgressBar * p, int nItemsCur, char * pString )
89 {
90  if ( p == NULL ) return;
91  if ( nItemsCur < p->nItemsNext )
92  return;
93  if ( nItemsCur >= p->nItemsTotal )
94  {
95  p->posCur = 78;
96  p->nItemsNext = 0x7FFFFFFF;
97  }
98  else
99  {
100  p->posCur += 7;
101  p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
102  }
103  Extra_ProgressBarShow( p, pString );
104 }
105 
106 
107 /**Function*************************************************************
108 
109  Synopsis [Stops the progress bar.]
110 
111  Description []
112 
113  SideEffects []
114 
115  SeeAlso []
116 
117 ***********************************************************************/
119 {
120  if ( p == NULL ) return;
122  ABC_FREE( p );
123 }
124 
125 /**Function*************************************************************
126 
127  Synopsis [Prints the progress bar of the given size.]
128 
129  Description []
130 
131  SideEffects []
132 
133  SeeAlso []
134 
135 ***********************************************************************/
136 void Extra_ProgressBarShow( ProgressBar * p, char * pString )
137 {
138  int i;
139  if ( p == NULL )
140  return;
141  if ( Abc_FrameIsBatchMode() )
142  return;
143  if ( pString )
144  fprintf( p->pFile, "%s ", pString );
145  for ( i = (pString? strlen(pString) + 1 : 0); i < p->posCur; i++ )
146  fprintf( p->pFile, "-" );
147  if ( i == p->posCur )
148  fprintf( p->pFile, ">" );
149  for ( i++ ; i <= p->posTotal; i++ )
150  fprintf( p->pFile, " " );
151  fprintf( p->pFile, "\r" );
152  fflush( stdout );
153 }
154 
155 /**Function*************************************************************
156 
157  Synopsis [Cleans the progress bar before quitting.]
158 
159  Description []
160 
161  SideEffects []
162 
163  SeeAlso []
164 
165 ***********************************************************************/
167 {
168  int i;
169  if ( p == NULL )
170  return;
171  if ( Abc_FrameIsBatchMode() )
172  return;
173  for ( i = 0; i <= p->posTotal; i++ )
174  fprintf( p->pFile, " " );
175  fprintf( p->pFile, "\r" );
176  fflush( stdout );
177 }
178 
179 ////////////////////////////////////////////////////////////////////////
180 /// END OF FILE ///
181 ////////////////////////////////////////////////////////////////////////
182 
183 
185 
char * memset()
static void Extra_ProgressBarShow(ProgressBar *p, char *pString)
static Llb_Mgr_t * p
Definition: llb3Image.c:950
ABC_DLL int Abc_FrameIsBatchMode()
Definition: mainFrame.c:92
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Extra_ProgressBarStop(ProgressBar *p)
DECLARATIONS ///.
void Extra_ProgressBarUpdate_int(ProgressBar *p, int nItemsCur, char *pString)
static void Extra_ProgressBarClean(ProgressBar *p)
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void * Abc_FrameGetGlobalFrame()
Definition: mainFrame.c:593
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
ABC_DLL int Abc_FrameShowProgress(Abc_Frame_t *p)
Definition: mainFrame.c:265
#define ABC_FREE(obj)
Definition: abc_global.h:232
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int strlen()