abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cmdLoad.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cmdApi.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [External procedures of the command package.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: cmdApi.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "base/main/mainInt.h"
23 #include "cmd.h"
24 #include "cmdInt.h"
25 #include "misc/util/utilSignal.h"
26 
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// DECLARATIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 ////////////////////////////////////////////////////////////////////////
34 /// FUNCTION DEFINITIONS ///
35 ////////////////////////////////////////////////////////////////////////
36 
37 /**Function********************************************************************
38 
39  Synopsis []
40 
41  Description []
42 
43  SideEffects []
44 
45  SeeAlso []
46 
47 ******************************************************************************/
48 int CmdCommandLoad( Abc_Frame_t * pAbc, int argc, char ** argv )
49 {
50  Vec_Str_t * vCommand;
51  FILE * pFile;
52  int i;
53  vCommand = Vec_StrAlloc( 100 );
54  Vec_StrAppend( vCommand, "abccmd_" );
55  Vec_StrAppend( vCommand, argv[0] );
56  Vec_StrAppend( vCommand, ".exe" );
57  Vec_StrPush( vCommand, 0 );
58  // check if there is the binary
59  if ( (pFile = fopen( Vec_StrArray(vCommand), "r" )) == NULL )
60  {
61  Vec_StrFree( vCommand );
62  Abc_Print( -1, "Cannot run the binary \"%s\".\n\n", Vec_StrArray(vCommand) );
63  return 1;
64  }
65  fclose( pFile );
66  Vec_StrPop( vCommand );
67  // add other arguments
68  for ( i = 1; i < argc; i++ )
69  {
70  Vec_StrAppend( vCommand, " " );
71  Vec_StrAppend( vCommand, argv[i] );
72  }
73  Vec_StrPush( vCommand, 0 );
74  // run the command line
75  if ( Util_SignalSystem( Vec_StrArray(vCommand) ) )
76  {
77  Vec_StrFree( vCommand );
78  Abc_Print( -1, "The following command has returned non-zero exit status:\n" );
79  Abc_Print( -1, "\"%s\"\n", Vec_StrArray(vCommand) );
80  return 1;
81  }
82  Vec_StrFree( vCommand );
83  return 0;
84 }
85 
86 /**Function*************************************************************
87 
88  Synopsis []
89 
90  Description []
91 
92  SideEffects []
93 
94  SeeAlso []
95 
96 ***********************************************************************/
97 #if defined(WIN32) && !defined(__cplusplus)
98 
99 #include <direct.h>
100 
101 
102 // these structures are defined in <io.h> but are for some reason invisible
103 typedef unsigned long _fsize_t; // Could be 64 bits for Win32
104 
105 struct _finddata_t {
106  unsigned attrib;
107  time_t time_create; // -1 for FAT file systems
108  time_t time_access; // -1 for FAT file systems
109  time_t time_write;
110  _fsize_t size;
111  char name[260];
112 };
113 
114 extern long _findfirst( char *filespec, struct _finddata_t *fileinfo );
115 extern int _findnext( long handle, struct _finddata_t *fileinfo );
116 extern int _findclose( long handle );
117 
118 //extern char * _getcwd( char * buffer, int maxlen );
119 //extern int _chdir( const char *dirname );
120 
121 /**Function*************************************************************
122 
123  Synopsis [Collect file names ending with .exe]
124 
125  Description []
126 
127  SideEffects []
128 
129  SeeAlso []
130 
131 ***********************************************************************/
133 {
134  Vec_Ptr_t * vFileNames;
135  struct _finddata_t c_file;
136  long hFile;
137  if( (hFile = _findfirst( "*.exe", &c_file )) == -1L )
138  {
139 // Abc_Print( 0, "No files with extention \"%s\" in the current directory.\n", "exe" );
140  return NULL;
141  }
142  vFileNames = Vec_PtrAlloc( 100 );
143  do {
144  Vec_PtrPush( vFileNames, Extra_UtilStrsav( c_file.name ) );
145  } while( _findnext( hFile, &c_file ) == 0 );
146  _findclose( hFile );
147  return vFileNames;
148 }
149 
150 #else
151 
152 /**Function*************************************************************
153 
154  Synopsis [Collect file names ending with .exe]
155 
156  Description []
157 
158  SideEffects []
159 
160  SeeAlso []
161 
162 ***********************************************************************/
164 {
165  return NULL;
166 }
167 
168 #endif
169 
170 
171 /**Function*************************************************************
172 
173  Synopsis []
174 
175  Description []
176 
177  SideEffects []
178 
179  SeeAlso []
180 
181 ***********************************************************************/
182 void Load_Init( Abc_Frame_t * pAbc )
183 {
184  Vec_Ptr_t * vFileNames;
185  char * pName, * pStop;
186  int i;
187  vFileNames = CmdCollectFileNames();
188  if ( vFileNames == NULL )
189  return;
190  Vec_PtrForEachEntry( char *, vFileNames, pName, i )
191  {
192  if ( strncmp( pName, "abccmd_", 7 ) )
193  continue;
194  // get the command name
195 // pName[6] = '!';
196  pStop = strstr( pName + 7, "." );
197  if ( pStop )
198  *pStop = 0;
199  // add the command
200  Cmd_CommandAdd( pAbc, "ZZ", pName+7, CmdCommandLoad, 0 );
201 // printf( "Loaded command \"%s\"\n", pName+7 );
202  }
203  Vec_PtrFreeFree( vFileNames );
204 }
205 
206 /**Function*************************************************************
207 
208  Synopsis []
209 
210  Description []
211 
212  SideEffects []
213 
214  SeeAlso []
215 
216 ***********************************************************************/
217 void Load_End( Abc_Frame_t * pAbc )
218 {
219 }
220 
221 
222 ////////////////////////////////////////////////////////////////////////
223 /// END OF FILE ///
224 ////////////////////////////////////////////////////////////////////////
225 
226 
228 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_NAMESPACE_IMPL_START int CmdCommandLoad(Abc_Frame_t *pAbc, int argc, char **argv)
DECLARATIONS ///.
Definition: cmdLoad.c:48
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
void Load_End(Abc_Frame_t *pAbc)
Definition: cmdLoad.c:217
static void Vec_PtrFreeFree(Vec_Ptr_t *p)
Definition: vecPtr.h:569
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition: cmdApi.c:63
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
static char Vec_StrPop(Vec_Str_t *p)
Definition: vecStr.h:558
char * Extra_UtilStrsav(const char *s)
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
static void Vec_StrAppend(Vec_Str_t *p, const char *pString)
Definition: vecStr.h:645
char * strstr()
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
char * name
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int size
Definition: cuddSign.c:86
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Vec_Ptr_t * CmdCollectFileNames()
Definition: cmdLoad.c:163
int strncmp()
ABC_NAMESPACE_IMPL_START int Util_SignalSystem(const char *cmd)
DECLARATIONS ///.
Definition: utilSignal.c:46
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Load_Init(Abc_Frame_t *pAbc)
Definition: cmdLoad.c:182