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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Cmd_HistoryAddCommand (Abc_Frame_t *p, const char *command)
 DECLARATIONS ///. More...
 
void Cmd_HistoryRead (Abc_Frame_t *p)
 
void Cmd_HistoryWrite (Abc_Frame_t *p, int Limit)
 
void Cmd_HistoryPrint (Abc_Frame_t *p, int Limit)
 

Function Documentation

ABC_NAMESPACE_IMPL_START void Cmd_HistoryAddCommand ( Abc_Frame_t p,
const char *  command 
)

DECLARATIONS ///.

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

FileName [cmdHist.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures working with history.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 48 of file cmdHist.c.

49 {
50  int nLastLooked = 10; // do not add history if the same entry appears among the last entries
51  int nLastSaved = 1000; // when saving a file, save no more than this number of last entries
52  char Buffer[ABC_MAX_STR];
53  int Len;
54  if ( p->fBatchMode )
55  return;
56  Len = strlen(command);
57  strcpy( Buffer, command );
58  if ( Buffer[Len-1] == '\n' )
59  Buffer[Len-1] = 0;
60  if ( strlen(Buffer) > 3 &&
61  strncmp(Buffer,"set",3) &&
62  strncmp(Buffer,"unset",5) &&
63  strncmp(Buffer,"time",4) &&
64  strncmp(Buffer,"quit",4) &&
65  strncmp(Buffer,"alias",5) &&
66 // strncmp(Buffer,"source",6) &&
67  strncmp(Buffer,"history",7) && strncmp(Buffer,"hi ", 3) && strcmp(Buffer,"hi") &&
68  Buffer[strlen(Buffer)-1] != '?' )
69  {
70  char * pStr = NULL;
71  int i, Start = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory) - nLastLooked );
72  // do not enter if the same command appears among nLastLooked commands
73  Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Start )
74  if ( !strcmp(pStr, Buffer) )
75  break;
76  if ( i == Vec_PtrSize(p->aHistory) )
77  { // add new entry
78  Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
79  Cmd_HistoryWrite( p, nLastSaved );
80  }
81  else
82  { // put at the end
83  Vec_PtrRemove( p->aHistory, pStr );
84  Vec_PtrPush( p->aHistory, pStr );
85  }
86  }
87 }
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
void Cmd_HistoryWrite(Abc_Frame_t *p, int Limit)
Definition: cmdHist.c:131
char * Extra_UtilStrsav(const char *s)
int strcmp()
#define ABC_MAX_STR
Definition: mainInt.h:50
if(last==0)
Definition: sparse_int.h:34
#define Len
Definition: deflate.h:78
char * strcpy()
int strncmp()
int strlen()
void Cmd_HistoryPrint ( Abc_Frame_t p,
int  Limit 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 161 of file cmdHist.c.

162 {
163 #if defined(WIN32)
164  char * pStr;
165  int i;
166  Limit = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory)-Limit );
167  printf( "================== Command history ==================\n" );
168  Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Limit )
169  printf( "%s\n", pStr );
170  printf( "=====================================================\n" );
171 #endif
172 }
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
void Cmd_HistoryRead ( Abc_Frame_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 100 of file cmdHist.c.

101 {
102 #if defined(WIN32)
103  char Buffer[ABC_MAX_STR];
104  FILE * pFile;
105  assert( Vec_PtrSize(p->aHistory) == 0 );
106  pFile = fopen( "abc.history", "rb" );
107  if ( pFile == NULL )
108  return;
109  while ( fgets( Buffer, ABC_MAX_STR, pFile ) != NULL )
110  {
111  int Len = strlen(Buffer);
112  if ( Buffer[Len-1] == '\n' )
113  Buffer[Len-1] = 0;
114  Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
115  }
116  fclose( pFile );
117 #endif
118 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
char * Extra_UtilStrsav(const char *s)
#define ABC_MAX_STR
Definition: mainInt.h:50
#define Len
Definition: deflate.h:78
#define assert(ex)
Definition: util_old.h:213
int strlen()
void Cmd_HistoryWrite ( Abc_Frame_t p,
int  Limit 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 131 of file cmdHist.c.

132 {
133 #if defined(WIN32)
134  FILE * pFile;
135  char * pStr;
136  int i;
137  pFile = fopen( "abc.history", "wb" );
138  if ( pFile == NULL )
139  {
140  Abc_Print( 0, "Cannot open file \"abc.history\" for writing.\n" );
141  return;
142  }
143  Limit = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory)-Limit );
144  Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Limit )
145  fprintf( pFile, "%s\n", pStr );
146  fclose( pFile );
147 #endif
148 }
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313