ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cmdHist.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "base/main/mainInt.h"
23#include "cmd.h"
24#include "cmdInt.h"
25
27
28
32
33#define ABC_USE_HISTORY 1
34
38
50void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command )
51{
52 int nLastLooked = 10; // do not add history if the same entry appears among the last entries
53 int nLastSaved = 10000; // when saving a file, save no more than this number of last entries
54 char Buffer[ABC_MAX_STR];
55 int Len;
56 if ( p->fBatchMode )
57 return;
58 Len = strlen(command);
59 strcpy( Buffer, command );
60 if ( Len > 0 && Buffer[Len-1] == '\n' )
61 Buffer[Len-1] = 0;
62 if ( strlen(Buffer) > 3 &&
63 strncmp(Buffer,"set",3) &&
64 strncmp(Buffer,"unset",5) &&
65 strncmp(Buffer,"time",4) &&
66 strncmp(Buffer,"quit",4) &&
67 strncmp(Buffer,"alias",5) &&
68 strncmp(Buffer,"source abc.rc",13) &&
69 strncmp(Buffer,"source ..\\abc.rc",16) &&
70 strncmp(Buffer,"history",7) && strncmp(Buffer,"hi ", 3) && strcmp(Buffer,"hi") &&
71 Buffer[strlen(Buffer)-1] != '?' )
72 {
73 char * pStr = NULL;
74 int i, Start = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory) - nLastLooked );
75 // do not enter if the same command appears among nLastLooked commands
76 Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Start )
77 if ( !strcmp(pStr, Buffer) )
78 break;
79 if ( i == Vec_PtrSize(p->aHistory) )
80 { // add new entry
81 Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
82 Cmd_HistoryWrite( p, nLastSaved );
83 }
84 else
85 { // put at the end
86 Vec_PtrRemove( p->aHistory, pStr );
87 Vec_PtrPush( p->aHistory, pStr );
88 }
89 }
90}
91
104{
105#if defined(ABC_USE_HISTORY)
106 char Buffer[ABC_MAX_STR];
107 FILE * pFile;
108 assert( Vec_PtrSize(p->aHistory) == 0 );
109 pFile = fopen( "abc.history", "rb" );
110 if ( pFile == NULL )
111 return;
112 while ( fgets( Buffer, ABC_MAX_STR, pFile ) != NULL )
113 {
114 int Len = strlen(Buffer);
115 if ( Buffer[Len-1] == '\n' )
116 Buffer[Len-1] = 0;
117 Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
118 }
119 fclose( pFile );
120#endif
121}
122
134void Cmd_HistoryWrite( Abc_Frame_t * p, int Limit )
135{
136#if defined(ABC_USE_HISTORY)
137 FILE * pFile;
138 char * pStr;
139 int i;
140 pFile = fopen( "abc.history", "wb" );
141 if ( pFile == NULL )
142 {
143 Abc_Print( 0, "Cannot open file \"abc.history\" for writing.\n" );
144 return;
145 }
146 Limit = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory)-Limit );
147 Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Limit )
148 fprintf( pFile, "%s\n", pStr );
149 fclose( pFile );
150#endif
151}
152
164void Cmd_HistoryPrint( Abc_Frame_t * p, int Limit )
165{
166#if defined(ABC_USE_HISTORY)
167 char * pStr;
168 int i;
169 Limit = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory)-Limit );
170 printf( "================== Command history ==================\n" );
171 Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Limit )
172 printf( "%s\n", pStr );
173 printf( "=====================================================\n" );
174#endif
175}
176
181
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
void Cmd_HistoryWrite(Abc_Frame_t *p, int Limit)
Definition cmdHist.c:134
void Cmd_HistoryPrint(Abc_Frame_t *p, int Limit)
Definition cmdHist.c:164
void Cmd_HistoryRead(Abc_Frame_t *p)
Definition cmdHist.c:103
void Cmd_HistoryAddCommand(Abc_Frame_t *p, const char *command)
FUNCTION DEFINITIONS ///.
Definition cmdHist.c:50
#define Len
Definition deflate.h:78
Cube * p
Definition exorList.c:222
char * Extra_UtilStrsav(const char *s)
#define ABC_MAX_STR
Definition mainInt.h:52
#define assert(ex)
Definition util_old.h:213
int strncmp()
int strlen()
int strcmp()
char * strcpy()
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57