00001
00021 #include "mainInt.h"
00022
00023 #ifndef _WIN32
00024 #include "readline/readline.h"
00025 #endif
00026
00030 static char * DateReadFromDateString(char * datestr);
00031
00035
00047 char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc )
00048 {
00049 static char Version[1000];
00050 sprintf(Version, "%s (compiled %s %s)", ABC_VERSION, __DATE__, __TIME__);
00051 return Version;
00052 }
00053
00065 char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc )
00066 {
00067 static char Buffer[1000], Prompt[1000];
00068 sprintf( Prompt, "abc %02d> ", pAbc->nSteps );
00069 #ifdef _WIN32
00070 fprintf( pAbc->Out, "%s", Prompt );
00071 fgets( Buffer, 999, stdin );
00072 return Buffer;
00073 #else
00074 static char* line = NULL;
00075 if (line != NULL) free(line);
00076 line = readline(Prompt);
00077 if (line == NULL){ printf("***EOF***\n"); exit(0); }
00078 add_history(line);
00079 return line;
00080 #endif
00081 }
00082
00094 void Abc_UtilsPrintHello( Abc_Frame_t * pAbc )
00095 {
00096 fprintf( pAbc->Out, "%s\n", pAbc->sVersion );
00097 }
00098
00110 void Abc_UtilsPrintUsage( Abc_Frame_t * pAbc, char * ProgName )
00111 {
00112 fprintf( pAbc->Err, "\n" );
00113 fprintf( pAbc->Err,
00114 "usage: %s [-c cmd] [-f script] [-h] [-o file] [-s] [-t type] [-T type] [-x] [file]\n",
00115 ProgName);
00116 fprintf( pAbc->Err, " -c cmd\texecute commands `cmd'\n");
00117 fprintf( pAbc->Err, " -F script\texecute commands from a script file and echo commands\n");
00118 fprintf( pAbc->Err, " -f script\texecute commands from a script file\n");
00119 fprintf( pAbc->Err, " -h\t\tprint the command usage\n");
00120 fprintf( pAbc->Err, " -o file\tspecify output filename to store the result\n");
00121 fprintf( pAbc->Err, " -s\t\tdo not read any initialization file\n");
00122 fprintf( pAbc->Err, " -t type\tspecify input type (blif_mv (default), blif_mvs, blif, or none)\n");
00123 fprintf( pAbc->Err, " -T type\tspecify output type (blif_mv (default), blif_mvs, blif, or none)\n");
00124 fprintf( pAbc->Err, " -x\t\tequivalent to '-t none -T none'\n");
00125 fprintf( pAbc->Err, "\n" );
00126 }
00127
00139 void Abc_UtilsSource( Abc_Frame_t * pAbc )
00140 {
00141 #ifdef WIN32
00142 if ( Cmd_CommandExecute(pAbc, "source abc.rc") )
00143 {
00144 if ( Cmd_CommandExecute(pAbc, "source ..\\abc.rc") == 0 )
00145 printf( "Loaded \"abc.rc\" from the parent directory.\n" );
00146 else if ( Cmd_CommandExecute(pAbc, "source ..\\..\\abc.rc") == 0 )
00147 printf( "Loaded \"abc.rc\" from the grandparent directory.\n" );
00148 }
00149 #else
00150
00151 #if 0
00152 {
00153 char * sPath1, * sPath2;
00154
00155
00156
00157 sPath1 = Extra_UtilFileSearch(".rc", "~/", "r");
00158 sPath2 = Extra_UtilFileSearch(".rc", ".", "r");
00159
00160 if ( sPath1 && sPath2 ) {
00161
00162 (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
00163 }
00164 else {
00165 if (sPath1) {
00166 (void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
00167 }
00168 if (sPath2) {
00169 (void) Cmd_CommandExecute(pAbc, "source -s .rc");
00170 }
00171 }
00172 if ( sPath1 ) FREE(sPath1);
00173 if ( sPath2 ) FREE(sPath2);
00174
00175
00176 Cmd_CommandExecute( pAbc, "source -s abc.rc" );
00177 }
00178 #endif
00179
00180 {
00181 char * sPath1, * sPath2;
00182 char * home;
00183
00184
00185
00186 home = getenv("HOME");
00187 if (home){
00188 char * sPath3 = ALLOC(char, strlen(home) + 2);
00189 (void) sprintf(sPath3, "%s/", home);
00190 sPath1 = Extra_UtilFileSearch(".abc.rc", sPath3, "r");
00191 FREE(sPath3);
00192 }else
00193 sPath1 = NULL;
00194
00195 sPath2 = Extra_UtilFileSearch(".abc.rc", ".", "r");
00196
00197 if ( sPath1 && sPath2 ) {
00198
00199 (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
00200 }
00201 else {
00202 if (sPath1) {
00203 (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
00204 }
00205 if (sPath2) {
00206 (void) Cmd_CommandExecute(pAbc, "source -s .abc.rc");
00207 }
00208 }
00209 if ( sPath1 ) FREE(sPath1);
00210 if ( sPath2 ) FREE(sPath2);
00211
00212
00213 Cmd_CommandExecute( pAbc, "source -s abc.rc" );
00214 }
00215
00216 #endif //WIN32
00217 {
00218
00219 char * pName;
00220 int i;
00221 Vec_PtrForEachEntry( pAbc->aHistory, pName, i )
00222 free( pName );
00223 pAbc->aHistory->nSize = 0;
00224 }
00225 }
00226
00237 char *
00238 DateReadFromDateString(
00239 char * datestr)
00240 {
00241 static char result[25];
00242 char day[10];
00243 char month[10];
00244 char zone[10];
00245 char *at;
00246 int date;
00247 int hour;
00248 int minute;
00249 int second;
00250 int year;
00251
00252 if (sscanf(datestr, "%s %s %2d %2d:%2d:%2d %s %4d",
00253 day, month, &date, &hour, &minute, &second, zone, &year) == 8) {
00254 if (hour >= 12) {
00255 if (hour >= 13) hour -= 12;
00256 at = "PM";
00257 }
00258 else {
00259 if (hour == 0) hour = 12;
00260 at = "AM";
00261 }
00262 (void) sprintf(result, "%d-%3s-%02d at %d:%02d %s",
00263 date, month, year % 100, hour, minute, at);
00264 return result;
00265 }
00266 else {
00267 return datestr;
00268 }
00269 }
00270
00271
00272
00276
00277