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
29 ABC_NAMESPACE_IMPL_START
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 ***********************************************************************/
Abc_UtilsGetVersion(Abc_Frame_t * pAbc)52 char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc )
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 ***********************************************************************/
Abc_UtilsGetUsersInput(Abc_Frame_t * pAbc)70 char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc )
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 ***********************************************************************/
Abc_UtilsPrintHello(Abc_Frame_t * pAbc)104 void Abc_UtilsPrintHello( Abc_Frame_t * pAbc )
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 ***********************************************************************/
Abc_UtilsPrintUsage(Abc_Frame_t * pAbc,char * ProgName)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] [-q cmd] [-C cmd] [-Q 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, " -Q cmd\texecute commands `cmd' quietly, then continue in interactive mode\n");
130 fprintf( pAbc->Err, " -F script\texecute commands from a script file and echo commands\n");
131 fprintf( pAbc->Err, " -f script\texecute commands from a script file\n");
132 fprintf( pAbc->Err, " -h\t\tprint the command usage\n");
133 fprintf( pAbc->Err, " -o file\tspecify output filename to store the result\n");
134 fprintf( pAbc->Err, " -s\t\tdo not read any initialization file\n");
135 fprintf( pAbc->Err, " -t type\tspecify input type (blif_mv (default), blif_mvs, blif, or none)\n");
136 fprintf( pAbc->Err, " -T type\tspecify output type (blif_mv (default), blif_mvs, blif, or none)\n");
137 fprintf( pAbc->Err, " -x\t\tequivalent to '-t none -T none'\n");
138 fprintf( pAbc->Err, " -b\t\trunning in bridge mode\n");
139 fprintf( pAbc->Err, "\n" );
140 }
141
142 /**Function*************************************************************
143
144 Synopsis []
145
146 Description []
147
148 SideEffects []
149
150 SeeAlso []
151
152 ***********************************************************************/
Abc_UtilsSource(Abc_Frame_t * pAbc)153 void Abc_UtilsSource( Abc_Frame_t * pAbc )
154 {
155 #ifdef WIN32
156 if ( Cmd_CommandExecute(pAbc, "source abc.rc") )
157 {
158 if ( Cmd_CommandExecute(pAbc, "source ..\\abc.rc") == 0 )
159 printf( "Loaded \"abc.rc\" from the parent directory.\n" );
160 else if ( Cmd_CommandExecute(pAbc, "source ..\\..\\abc.rc") == 0 )
161 printf( "Loaded \"abc.rc\" from the grandparent directory.\n" );
162 }
163 #else
164
165 #if 0
166 {
167 char * sPath1, * sPath2;
168
169 // If .rc is present in both the home and current directories, then read
170 // it from the home directory. Otherwise, read it from wherever it's located.
171 sPath1 = Extra_UtilFileSearch(".rc", "~/", "r");
172 sPath2 = Extra_UtilFileSearch(".rc", ".", "r");
173
174 if ( sPath1 && sPath2 ) {
175 /* ~/.rc == .rc : Source the file only once */
176 (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
177 }
178 else {
179 if (sPath1) {
180 (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
181 }
182 if (sPath2) {
183 (void) Cmd_CommandExecute(pAbc, "source -s .rc");
184 }
185 }
186 if ( sPath1 ) ABC_FREE(sPath1);
187 if ( sPath2 ) ABC_FREE(sPath2);
188
189 /* execute the abc script which can be open with the "open_path" */
190 Cmd_CommandExecute( pAbc, "source -s abc.rc" );
191 }
192 #endif
193
194 {
195 char * sPath1, * sPath2;
196 char * home;
197
198 // If .rc is present in both the home and current directories, then read
199 // it from the home directory. Otherwise, read it from wherever it's located.
200 home = getenv("HOME");
201 if (home){
202 char * sPath3 = ABC_ALLOC(char, strlen(home) + 2);
203 (void) sprintf(sPath3, "%s/", home);
204 sPath1 = Extra_UtilFileSearch(".abc.rc", sPath3, "r");
205 ABC_FREE(sPath3);
206 }else
207 sPath1 = NULL;
208
209 sPath2 = Extra_UtilFileSearch(".abc.rc", ".", "r");
210
211 if ( sPath1 && sPath2 ) {
212 /* ~/.rc == .rc : Source the file only once */
213 char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
214 (void) sprintf(tmp_cmd, "source -s %s", sPath1);
215 // (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
216 (void) Cmd_CommandExecute(pAbc, tmp_cmd);
217 ABC_FREE(tmp_cmd);
218 }
219 else {
220 if (sPath1) {
221 char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
222 (void) sprintf(tmp_cmd, "source -s %s", sPath1);
223 // (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
224 (void) Cmd_CommandExecute(pAbc, tmp_cmd);
225 ABC_FREE(tmp_cmd);
226 }
227 if (sPath2) {
228 char *tmp_cmd = ABC_ALLOC(char, strlen(sPath2)+12);
229 (void) sprintf(tmp_cmd, "source -s %s", sPath2);
230 // (void) Cmd_CommandExecute(pAbc, "source -s .abc.rc");
231 (void) Cmd_CommandExecute(pAbc, tmp_cmd);
232 ABC_FREE(tmp_cmd);
233 }
234 }
235 if ( sPath1 ) ABC_FREE(sPath1);
236 if ( sPath2 ) ABC_FREE(sPath2);
237
238 /* execute the abc script which can be open with the "open_path" */
239 Cmd_CommandExecute( pAbc, "source -s abc.rc" );
240 }
241
242 #endif //WIN32
243 }
244
245 /**Function********************************************************************
246
247 Synopsis [Returns the date in a brief format assuming its coming from
248 the program `date'.]
249
250 Description [optional]
251
252 SideEffects []
253
254 ******************************************************************************/
DateReadFromDateString(char * datestr)255 char * DateReadFromDateString( char * datestr )
256 {
257 static char result[25];
258 char day[10];
259 char month[10];
260 char zone[10];
261 char *at;
262 int date;
263 int hour;
264 int minute;
265 int second;
266 int year;
267
268 if (sscanf(datestr, "%s %s %2d %2d:%2d:%2d %s %4d",
269 day, month, &date, &hour, &minute, &second, zone, &year) == 8) {
270 if (hour >= 12) {
271 if (hour >= 13) hour -= 12;
272 at = "PM";
273 }
274 else {
275 if (hour == 0) hour = 12;
276 at = "AM";
277 }
278 (void) sprintf(result, "%d-%3s-%02d at %d:%02d %s",
279 date, month, year % 100, hour, minute, at);
280 return result;
281 }
282 else {
283 return datestr;
284 }
285 }
286
287
288
289 ////////////////////////////////////////////////////////////////////////
290 /// END OF FILE ///
291 ////////////////////////////////////////////////////////////////////////
292
293
294 ABC_NAMESPACE_IMPL_END
295