abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bar.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [bar.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: bar.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "misc/util/abc_global.h"
26 #include "base/main/main.h"
27 #include "bar.h"
28 
30 
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// DECLARATIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
37 {
38  int nItemsNext; // the number of items for the next update of the progress bar
39  int nItemsTotal; // the total number of items
40  int posTotal; // the total number of positions
41  int posCur; // the current position
42  FILE * pFile; // the output stream
43 };
44 
45 static void Bar_ProgressShow( Bar_Progress_t * p, char * pString );
46 static void Bar_ProgressClean( Bar_Progress_t * p );
47 
48 ////////////////////////////////////////////////////////////////////////
49 /// FUNCTION DEFINITIONS ///
50 ////////////////////////////////////////////////////////////////////////
51 
52 /**Function*************************************************************
53 
54  Synopsis [Starts the progress bar.]
55 
56  Description [The first parameter is the output stream (pFile), where
57  the progress is printed. The current printing position should be the
58  first one on the given line. The second parameters is the total
59  number of items that correspond to 100% position of the progress bar.]
60 
61  SideEffects []
62 
63  SeeAlso []
64 
65 ***********************************************************************/
66 Bar_Progress_t * Bar_ProgressStart( FILE * pFile, int nItemsTotal )
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 }
84 
85 /**Function*************************************************************
86 
87  Synopsis [Updates the progress bar.]
88 
89  Description []
90 
91  SideEffects []
92 
93  SeeAlso []
94 
95 ***********************************************************************/
96 void Bar_ProgressUpdate_int( Bar_Progress_t * p, int nItemsCur, char * pString )
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 }
113 
114 
115 /**Function*************************************************************
116 
117  Synopsis [Stops the progress bar.]
118 
119  Description []
120 
121  SideEffects []
122 
123  SeeAlso []
124 
125 ***********************************************************************/
127 {
128  if ( p == NULL ) return;
129  Bar_ProgressClean( p );
130  ABC_FREE( p );
131 }
132 
133 /**Function*************************************************************
134 
135  Synopsis [Prints the progress bar of the given size.]
136 
137  Description []
138 
139  SideEffects []
140 
141  SeeAlso []
142 
143 ***********************************************************************/
144 void Bar_ProgressShow( Bar_Progress_t * p, char * pString )
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 }
162 
163 /**Function*************************************************************
164 
165  Synopsis [Cleans the progress bar before quitting.]
166 
167  Description []
168 
169  SideEffects []
170 
171  SeeAlso []
172 
173 ***********************************************************************/
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 }
186 
187 ////////////////////////////////////////////////////////////////////////
188 /// END OF FILE ///
189 ////////////////////////////////////////////////////////////////////////
190 
191 
193 
char * memset()
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 Bar_ProgressUpdate_int(Bar_Progress_t *p, int nItemsCur, char *pString)
Definition: bar.c:96
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
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Bar_ProgressClean(Bar_Progress_t *p)
Definition: bar.c:174
DECLARATIONS ///.
Definition: bar.c:36
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
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
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL Abc_Frame_t * Abc_FrameReadGlobalFrame()
Definition: mainFrame.c:616
int strlen()
void Bar_ProgressStop(Bar_Progress_t *p)
Definition: bar.c:126
Bar_Progress_t * Bar_ProgressStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Definition: bar.c:66