00001
00021 #include "mainInt.h"
00022
00023
00024
00025
00029
00030 static int TypeCheck( Abc_Frame_t * pAbc, char * s);
00031
00035
00036 #ifndef _LIB
00037
00049 int main( int argc, char * argv[] )
00050 {
00051 Abc_Frame_t * pAbc;
00052 char sCommandUsr[500], sCommandTmp[100], sReadCmd[20], sWriteCmd[20], c;
00053 char * sCommand, * sOutFile, * sInFile;
00054 int fStatus = 0;
00055 bool fBatch, fInitSource, fInitRead, fFinalWrite;
00056
00057
00058 #ifdef _DEBUG
00059 _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
00060 #endif
00061
00062
00063
00064
00065
00066
00067 pAbc = Abc_FrameGetGlobalFrame();
00068
00069
00070 fBatch = 0;
00071 fInitSource = 1;
00072 fInitRead = 0;
00073 fFinalWrite = 0;
00074 sInFile = sOutFile = NULL;
00075 sprintf( sReadCmd, "read" );
00076 sprintf( sWriteCmd, "write" );
00077
00078 Extra_UtilGetoptReset();
00079 while ((c = Extra_UtilGetopt(argc, argv, "c:hf:F:o:st:T:x")) != EOF) {
00080 switch(c) {
00081 case 'c':
00082 strcpy( sCommandUsr, globalUtilOptarg );
00083 fBatch = 1;
00084 break;
00085
00086 case 'f':
00087 sprintf(sCommandUsr, "source %s", globalUtilOptarg);
00088 fBatch = 1;
00089 break;
00090
00091 case 'F':
00092 sprintf(sCommandUsr, "source -x %s", globalUtilOptarg);
00093 fBatch = 1;
00094 break;
00095
00096 case 'h':
00097 goto usage;
00098 break;
00099
00100 case 'o':
00101 sOutFile = globalUtilOptarg;
00102 fFinalWrite = 1;
00103 break;
00104
00105 case 's':
00106 fInitSource = 0;
00107 break;
00108
00109 case 't':
00110 if ( TypeCheck( pAbc, globalUtilOptarg ) )
00111 {
00112 if ( !strcmp(globalUtilOptarg, "none") == 0 )
00113 {
00114 fInitRead = 1;
00115 sprintf( sReadCmd, "read_%s", globalUtilOptarg );
00116 }
00117 }
00118 else {
00119 goto usage;
00120 }
00121 fBatch = 1;
00122 break;
00123
00124 case 'T':
00125 if ( TypeCheck( pAbc, globalUtilOptarg ) )
00126 {
00127 if (!strcmp(globalUtilOptarg, "none") == 0)
00128 {
00129 fFinalWrite = 1;
00130 sprintf( sWriteCmd, "write_%s", globalUtilOptarg);
00131 }
00132 }
00133 else {
00134 goto usage;
00135 }
00136 fBatch = 1;
00137 break;
00138
00139 case 'x':
00140 fFinalWrite = 0;
00141 fInitRead = 0;
00142 fBatch = 1;
00143 break;
00144
00145 default:
00146 goto usage;
00147 }
00148 }
00149
00150 if ( fBatch )
00151 {
00152 pAbc->fBatchMode = 1;
00153
00154 if (argc - globalUtilOptind == 0)
00155 {
00156 sInFile = NULL;
00157 }
00158 else if (argc - globalUtilOptind == 1)
00159 {
00160 fInitRead = 1;
00161 sInFile = argv[globalUtilOptind];
00162 }
00163 else
00164 {
00165 Abc_UtilsPrintUsage( pAbc, argv[0] );
00166 }
00167
00168
00169 if ( fInitSource )
00170 {
00171 Abc_UtilsSource( pAbc );
00172 }
00173
00174 fStatus = 0;
00175 if ( fInitRead && sInFile )
00176 {
00177 sprintf( sCommandTmp, "%s %s", sReadCmd, sInFile );
00178 fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
00179 }
00180
00181 if ( fStatus == 0 )
00182 {
00183
00184 fStatus = Cmd_CommandExecute( pAbc, sCommandUsr );
00185 if ( (fStatus == 0 || fStatus == -1) && fFinalWrite && sOutFile )
00186 {
00187 sprintf( sCommandTmp, "%s %s", sWriteCmd, sOutFile );
00188 fStatus = Cmd_CommandExecute( pAbc, sCommandTmp );
00189 }
00190 }
00191
00192 }
00193 else
00194 {
00195
00196
00197 Abc_UtilsPrintHello( pAbc );
00198
00199
00200 if ( fInitSource )
00201 {
00202 Abc_UtilsSource( pAbc );
00203 }
00204
00205
00206 while ( !feof(stdin) )
00207 {
00208
00209
00210 sCommand = Abc_UtilsGetUsersInput( pAbc );
00211
00212
00213 fStatus = Cmd_CommandExecute( pAbc, sCommand );
00214
00215
00216 if ( fStatus == -1 || fStatus == -2 )
00217 break;
00218 }
00219 }
00220
00221
00222 if ( fStatus < 0 )
00223 {
00224 Abc_Stop();
00225 }
00226 return 0;
00227
00228 usage:
00229 Abc_UtilsPrintHello( pAbc );
00230 Abc_UtilsPrintUsage( pAbc, argv[0] );
00231 return 1;
00232 }
00233
00234 #endif
00235
00253 void Abc_Start()
00254 {
00255 Abc_Frame_t * pAbc;
00256
00257 #ifdef _DEBUG
00258 _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
00259 #endif
00260
00261 pAbc = Abc_FrameGetGlobalFrame();
00262
00263
00264 }
00265
00277 void Abc_Stop()
00278 {
00279 Abc_Frame_t * pAbc;
00280 pAbc = Abc_FrameGetGlobalFrame();
00281
00282 Abc_FrameEnd( pAbc );
00283
00284 Abc_FrameDeallocate( pAbc );
00285 }
00286
00297 static int TypeCheck( Abc_Frame_t * pAbc, char * s )
00298 {
00299 if (strcmp(s, "blif") == 0)
00300 return 1;
00301 else if (strcmp(s, "bench") == 0)
00302 return 1;
00303 else if (strcmp(s, "pla") == 0)
00304 return 1;
00305 else if (strcmp(s, "none") == 0)
00306 return 1;
00307 else {
00308 fprintf( pAbc->Err, "unknown type %s\n", s );
00309 return 0;
00310 }
00311 }
00312
00316
00317