abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mainUtils.c File Reference
#include "base/abc/abc.h"
#include "mainInt.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START char * 
DateReadFromDateString (char *datestr)
 DECLARATIONS ///. More...
 
char * Abc_UtilsGetVersion (Abc_Frame_t *pAbc)
 FUNCTION DEFINITIONS ///. More...
 
char * Abc_UtilsGetUsersInput (Abc_Frame_t *pAbc)
 
void Abc_UtilsPrintHello (Abc_Frame_t *pAbc)
 
void Abc_UtilsPrintUsage (Abc_Frame_t *pAbc, char *ProgName)
 
void Abc_UtilsSource (Abc_Frame_t *pAbc)
 

Function Documentation

char* Abc_UtilsGetUsersInput ( Abc_Frame_t pAbc)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 70 of file mainUtils.c.

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 }
VOID_HACK exit()
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
char* Abc_UtilsGetVersion ( Abc_Frame_t pAbc)

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 52 of file mainUtils.c.

53 {
54  static char Version[1000];
55  sprintf(Version, "%s (compiled %s %s)", ABC_VERSION, __DATE__, __TIME__);
56  return Version;
57 }
char * sprintf()
#define ABC_VERSION
INCLUDES ///.
Definition: mainInt.h:47
void Abc_UtilsPrintHello ( Abc_Frame_t pAbc)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file mainUtils.c.

105 {
106  fprintf( pAbc->Out, "%s\n", pAbc->sVersion );
107 }
void Abc_UtilsPrintUsage ( Abc_Frame_t pAbc,
char *  ProgName 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file mainUtils.c.

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 }
void Abc_UtilsSource ( Abc_Frame_t pAbc)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 152 of file mainUtils.c.

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 }
char * Extra_UtilFileSearch(char *file, char *path, char *mode)
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * getenv()
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
char * DateReadFromDateString ( char *  datestr)
static

DECLARATIONS ///.

CFile****************************************************************

FileName [mainUtils.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [The main package.]

Synopsis [Miscellaneous utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
mainUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

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

Synopsis [Returns the date in a brief format assuming its coming from the program `date'.]

Description [optional]

SideEffects []

Definition at line 271 of file mainUtils.c.

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 }
char * sprintf()
static int result
Definition: cuddGenetic.c:125