abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mainUtils.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mainUtils.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [The main package.]
8 
9  Synopsis [Miscellaneous utilities.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: mainUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "mainInt.h"
23 
24 #ifdef ABC_USE_READLINE
25 #include <readline/readline.h>
26 #include <readline/history.h>
27 #endif
28 
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// DECLARATIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 static char * DateReadFromDateString( char * datestr );
36 
37 ////////////////////////////////////////////////////////////////////////
38 /// FUNCTION DEFINITIONS ///
39 ////////////////////////////////////////////////////////////////////////
40 
41 /**Function*************************************************************
42 
43  Synopsis []
44 
45  Description []
46 
47  SideEffects []
48 
49  SeeAlso []
50 
51 ***********************************************************************/
53 {
54  static char Version[1000];
55  sprintf(Version, "%s (compiled %s %s)", ABC_VERSION, __DATE__, __TIME__);
56  return Version;
57 }
58 
59 /**Function*************************************************************
60 
61  Synopsis []
62 
63  Description []
64 
65  SideEffects []
66 
67  SeeAlso []
68 
69 ***********************************************************************/
71 {
72  static char Prompt[5000];
73  sprintf( Prompt, "abc %02d> ", pAbc->nSteps );
74 #ifdef ABC_USE_READLINE
75  {
76  static char * line = NULL;
77  if (line != NULL) ABC_FREE(line);
78  line = readline(Prompt);
79  if (line == NULL){ printf("***EOF***\n"); exit(0); }
80  add_history(line);
81  return line;
82  }
83 #else
84  {
85  char * pRetValue;
86  fprintf( pAbc->Out, "%s", Prompt );
87  pRetValue = fgets( Prompt, 5000, stdin );
88  return Prompt;
89  }
90 #endif
91 }
92 
93 /**Function*************************************************************
94 
95  Synopsis []
96 
97  Description []
98 
99  SideEffects []
100 
101  SeeAlso []
102 
103 ***********************************************************************/
105 {
106  fprintf( pAbc->Out, "%s\n", pAbc->sVersion );
107 }
108 
109 /**Function*************************************************************
110 
111  Synopsis []
112 
113  Description []
114 
115  SideEffects []
116 
117  SeeAlso []
118 
119 ***********************************************************************/
120 void Abc_UtilsPrintUsage( Abc_Frame_t * pAbc, char * ProgName )
121 {
122  fprintf( pAbc->Err, "\n" );
123  fprintf( pAbc->Err,
124  "usage: %s [-c cmd] [-f script] [-h] [-o file] [-s] [-t type] [-T type] [-x] [-b] [file]\n",
125  ProgName);
126  fprintf( pAbc->Err, " -c cmd\texecute commands `cmd'\n");
127  fprintf( pAbc->Err, " -q cmd\texecute commands `cmd' quietly\n");
128  fprintf( pAbc->Err, " -C cmd\texecute commands `cmd', then continue in interactive mode\n");
129  fprintf( pAbc->Err, " -F script\texecute commands from a script file and echo commands\n");
130  fprintf( pAbc->Err, " -f script\texecute commands from a script file\n");
131  fprintf( pAbc->Err, " -h\t\tprint the command usage\n");
132  fprintf( pAbc->Err, " -o file\tspecify output filename to store the result\n");
133  fprintf( pAbc->Err, " -s\t\tdo not read any initialization file\n");
134  fprintf( pAbc->Err, " -t type\tspecify input type (blif_mv (default), blif_mvs, blif, or none)\n");
135  fprintf( pAbc->Err, " -T type\tspecify output type (blif_mv (default), blif_mvs, blif, or none)\n");
136  fprintf( pAbc->Err, " -x\t\tequivalent to '-t none -T none'\n");
137  fprintf( pAbc->Err, " -b\t\trunning in bridge mode\n");
138  fprintf( pAbc->Err, "\n" );
139 }
140 
141 /**Function*************************************************************
142 
143  Synopsis []
144 
145  Description []
146 
147  SideEffects []
148 
149  SeeAlso []
150 
151 ***********************************************************************/
153 {
154 #ifdef WIN32
155  if ( Cmd_CommandExecute(pAbc, "source abc.rc") )
156  {
157  if ( Cmd_CommandExecute(pAbc, "source ..\\abc.rc") == 0 )
158  printf( "Loaded \"abc.rc\" from the parent directory.\n" );
159  else if ( Cmd_CommandExecute(pAbc, "source ..\\..\\abc.rc") == 0 )
160  printf( "Loaded \"abc.rc\" from the grandparent directory.\n" );
161  }
162 #else
163 
164 #if 0
165  {
166  char * sPath1, * sPath2;
167 
168  // If .rc is present in both the home and current directories, then read
169  // it from the home directory. Otherwise, read it from wherever it's located.
170  sPath1 = Extra_UtilFileSearch(".rc", "~/", "r");
171  sPath2 = Extra_UtilFileSearch(".rc", ".", "r");
172 
173  if ( sPath1 && sPath2 ) {
174  /* ~/.rc == .rc : Source the file only once */
175  (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
176  }
177  else {
178  if (sPath1) {
179  (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
180  }
181  if (sPath2) {
182  (void) Cmd_CommandExecute(pAbc, "source -s .rc");
183  }
184  }
185  if ( sPath1 ) ABC_FREE(sPath1);
186  if ( sPath2 ) ABC_FREE(sPath2);
187 
188  /* execute the abc script which can be open with the "open_path" */
189  Cmd_CommandExecute( pAbc, "source -s abc.rc" );
190  }
191 #endif
192 
193 #ifdef ABC_PYTHON_EMBED
194  if ( getenv("ABC_PYTHON_ABC_RC") )
195  {
196  /* read script file from $ABC_PYTHON_ABC_RC */
197 
198  char * sPath = getenv("ABC_PYTHON_ABC_RC");
199 
200  if (sPath){
201  char * sCmd = ABC_ALLOC(char, strlen(sPath) + 50);
202  (void) sprintf(sCmd, "source -s %s", sPath);
203  (void) Cmd_CommandExecute(pAbc, sCmd);
204  ABC_FREE(sCmd);
205  }
206  }
207  else
208 #endif /* #ifdef ABC_PYTHON_EMBED */
209 
210  {
211  char * sPath1, * sPath2;
212  char * home;
213 
214  // If .rc is present in both the home and current directories, then read
215  // it from the home directory. Otherwise, read it from wherever it's located.
216  home = getenv("HOME");
217  if (home){
218  char * sPath3 = ABC_ALLOC(char, strlen(home) + 2);
219  (void) sprintf(sPath3, "%s/", home);
220  sPath1 = Extra_UtilFileSearch(".abc.rc", sPath3, "r");
221  ABC_FREE(sPath3);
222  }else
223  sPath1 = NULL;
224 
225  sPath2 = Extra_UtilFileSearch(".abc.rc", ".", "r");
226 
227  if ( sPath1 && sPath2 ) {
228  /* ~/.rc == .rc : Source the file only once */
229  char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
230  (void) sprintf(tmp_cmd, "source -s %s", sPath1);
231  // (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
232  (void) Cmd_CommandExecute(pAbc, tmp_cmd);
233  ABC_FREE(tmp_cmd);
234  }
235  else {
236  if (sPath1) {
237  char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
238  (void) sprintf(tmp_cmd, "source -s %s", sPath1);
239  // (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
240  (void) Cmd_CommandExecute(pAbc, tmp_cmd);
241  ABC_FREE(tmp_cmd);
242  }
243  if (sPath2) {
244  char *tmp_cmd = ABC_ALLOC(char, strlen(sPath2)+12);
245  (void) sprintf(tmp_cmd, "source -s %s", sPath2);
246  // (void) Cmd_CommandExecute(pAbc, "source -s .abc.rc");
247  (void) Cmd_CommandExecute(pAbc, tmp_cmd);
248  ABC_FREE(tmp_cmd);
249  }
250  }
251  if ( sPath1 ) ABC_FREE(sPath1);
252  if ( sPath2 ) ABC_FREE(sPath2);
253 
254  /* execute the abc script which can be open with the "open_path" */
255  Cmd_CommandExecute( pAbc, "source -s abc.rc" );
256  }
257 
258 #endif //WIN32
259 }
260 
261 /**Function********************************************************************
262 
263  Synopsis [Returns the date in a brief format assuming its coming from
264  the program `date'.]
265 
266  Description [optional]
267 
268  SideEffects []
269 
270 ******************************************************************************/
271 char * DateReadFromDateString( char * datestr )
272 {
273  static char result[25];
274  char day[10];
275  char month[10];
276  char zone[10];
277  char *at;
278  int date;
279  int hour;
280  int minute;
281  int second;
282  int year;
283 
284  if (sscanf(datestr, "%s %s %2d %2d:%2d:%2d %s %4d",
285  day, month, &date, &hour, &minute, &second, zone, &year) == 8) {
286  if (hour >= 12) {
287  if (hour >= 13) hour -= 12;
288  at = "PM";
289  }
290  else {
291  if (hour == 0) hour = 12;
292  at = "AM";
293  }
294  (void) sprintf(result, "%d-%3s-%02d at %d:%02d %s",
295  date, month, year % 100, hour, minute, at);
296  return result;
297  }
298  else {
299  return datestr;
300  }
301 }
302 
303 
304 
305 ////////////////////////////////////////////////////////////////////////
306 /// END OF FILE ///
307 ////////////////////////////////////////////////////////////////////////
308 
309 
311 
VOID_HACK exit()
char * Abc_UtilsGetUsersInput(Abc_Frame_t *pAbc)
Definition: mainUtils.c:70
char * Extra_UtilFileSearch(char *file, char *path, char *mode)
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
void Abc_UtilsSource(Abc_Frame_t *pAbc)
Definition: mainUtils.c:152
static ABC_NAMESPACE_IMPL_START char * DateReadFromDateString(char *datestr)
DECLARATIONS ///.
Definition: mainUtils.c:271
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Abc_UtilsPrintHello(Abc_Frame_t *pAbc)
Definition: mainUtils.c:104
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
char * getenv()
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * sprintf()
#define ABC_VERSION
INCLUDES ///.
Definition: mainInt.h:47
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
static int result
Definition: cuddGenetic.c:125
void Abc_UtilsPrintUsage(Abc_Frame_t *pAbc, char *ProgName)
Definition: mainUtils.c:120
char * Abc_UtilsGetVersion(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition: mainUtils.c:52