Exemplo n.º 1
0
void CDownloads_History::ApplyFilter_imp(fsDldHistRecFilter *f, int *piProgress)
{
	DeleteAllRecords ();

	ShowWindow (SW_HIDE);

	std::vector <fsDLHistoryRecordPtr> v;

	m_mgr->Lock ();

	try {
	int cRecs = m_mgr->GetRecordCount ();
	for (int i = cRecs-1; i >= 0; i--)
	{
		fsDLHistoryRecord* rec = m_mgr->GetRecord (i);
		if (f->IsSatisfies (rec))
			v.push_back (rec);

		if (piProgress)
			*piProgress = int (float (cRecs-i) / cRecs * 100);

	}
	} catch (...) {}

	m_mgr->Unlock ();

	for (size_t i = 0; i < v.size (); i++)
		AddRecord (v [i]);

	ShowWindow (SW_SHOW);
}
Exemplo n.º 2
0
bool DizList::AddDizText(const string& Name,const string& ShortName,const string& DizText)
{
	DeleteDiz(Name,ShortName);
	string strQuotedName = Name;
	QuoteSpaceOnly(strQuotedName);
	return AddRecord(FormatString()<<fmt::LeftAlign()<<fmt::MinWidth(Opt.Diz.StartPos>1?Opt.Diz.StartPos-2:0)<<strQuotedName<<L" "<<DizText);
}
Exemplo n.º 3
0
void
ProcessFiles(void)
{
	int i;

	if (NQuotaRecs == 0) {
		if (NFiles != 0)
			AddRecord(SAM_QUOTA_ADMIN, -1);
		AddRecord(SAM_QUOTA_GROUP, -1);
		AddRecord(SAM_QUOTA_USER, -1);
	}
	if (NFiles == 0 && NQuotaOps == 0)
		ReadSamFSes();
	for (i = 0; i < NFiles && !Err; i++)
		ProcessRecords(FileList[i]);
}
Exemplo n.º 4
0
/*
 * -G user/GID
 */
void
ProcGroupArg(char *grp)
{
	struct group *pg;

	pg = getgrnam(grp);
	if (pg)
		AddRecord(SAM_QUOTA_GROUP, pg->gr_gid);
	else if (NumericStr(grp))
		AddRecord(SAM_QUOTA_GROUP, atoi(grp));
	else {
		fprintf(stderr, "%s:  unrecognized group name or ID: '%s'\n",
		    Program, grp);
		Err++;
	}
}
Exemplo n.º 5
0
void NFCRecordLogic::OnObjectRecordEntry(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen)
{
	NFGUID nPlayerID;
	NFMsg::MultiObjectRecordList xMsg;
	if (!NFINetModule::ReceivePB(nSockIndex, nMsgID, msg, nLen, xMsg, nPlayerID))
	{
		return;
	}

	for(int i = 0; i < xMsg.multi_player_record_size(); i++)
	{
		const NFMsg::ObjectRecordList &data = xMsg.multi_player_record(i);
		NFGUID id = NFINetModule::PBToNF(data.player_id());

		NF_SHARE_PTR<NFIObject> object = g_pKernelModule->GetObject(id);
		for(int j = 0; j < data.record_list_size(); j++)
		{
			const NFMsg::ObjectRecordBase &objectRecord = data.record_list(j);
			const std::string &strRecordName = data.record_list(j).record_name();
			for(int k = 0; k < objectRecord.row_struct_size(); k++)
			{
				AddRecord(object, strRecordName, objectRecord.row_struct(k));
			}
		}
	}
}
Exemplo n.º 6
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QTextCodec *utfcodec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForTr(utfcodec);
    QTextCodec::setCodecForCStrings(utfcodec);

    base = QSqlDatabase::addDatabase("QSQLITE"); //указываем тип базы

    ui->statusBar->addWidget(&stBar);

    connect(ui->tableView, SIGNAL(clicked(QModelIndex)), SLOT(TableRead(QModelIndex)));
    connect(ui->ButtonSave, SIGNAL(clicked()), SLOT(SaveBaseAll()));
    connect(ui->ButtonDelete, SIGNAL(clicked()), SLOT(DeleteRecord()));
    connect(ui->ButtonSearch, SIGNAL(clicked()), SLOT(Search()));
    connect(ui->ButtonDeleteFilter, SIGNAL(clicked()), SLOT(NoSearch()));
    connect(ui->ActionTruncate, SIGNAL(triggered()), SLOT(Truncate()));
    connect(ui->ButtonAddRecord, SIGNAL(clicked()), SLOT(AddRecord()));
    connect(ui->ActionNewBackup, SIGNAL(triggered()), SLOT(SaveBackup()));
    connect(ui->ActionLoadBackup, SIGNAL(triggered()), SLOT(LoadBackup()));
    connect(ui->AboutBase, SIGNAL(triggered()), SLOT(AboutBase()));
    connect(ui->ActionConvert, SIGNAL(triggered()), SLOT(ConvertFromOperaNotes()));
    connect(ui->ActionOpenBase, SIGNAL(triggered()), SLOT(OpenBase()));

    setAcceptDrops(true);
}
Exemplo n.º 7
0
/*
 * -U user/UID
 */
void
ProcUserArg(char *user)
{
	struct passwd *pw;

	pw = getpwnam(user);
	if (pw)
		AddRecord(SAM_QUOTA_USER, pw->pw_uid);
	else if (NumericStr(user))
		AddRecord(SAM_QUOTA_USER, atoi(user));
	else {
		fprintf(stderr, "%s:  unrecognized user name or ID: '%s'\n",
		    Program, user);
		Err++;
	}
}
Exemplo n.º 8
0
void Y_add_record(int nArgs)
{
  IOStream *file;
  HistoryInfo *history;
  Dimension *dims;
  double *time= 0;
  long *ncyc= 0, *address= 0;
  long nRecs= 0;
  int flags;
  Symbol *stack= sp-nArgs+1;
  if (nArgs<1 || nArgs>4)
    YError("add_record requires between one and four arguments");

  file= YGetFile(stack++);
  if (stack<=sp) {
    time= YGet_D(stack++, 1, &dims);
    if (time) nRecs= TotalNumber(dims);
    if (stack<=sp) {
      ncyc= YGet_L(stack++, 1, &dims);
      if (ncyc) {
        if (nRecs) {
          if (nRecs!=TotalNumber(dims))
            YError("inconsistent number of ncycs in add_record");
        } else {
          nRecs= TotalNumber(dims);
        }
      }
      if (stack<=sp) {
        address= YGet_L(stack++, 1, &dims);
        if (address) {
          if (nRecs) {
            if (nRecs!=TotalNumber(dims))
              YError("inconsistent number of addresses in add_record");
          } else {
            nRecs= TotalNumber(dims);
          }
        }
      }
    }
  }

  /* if this file has no history, add one */
  history= file->history;
  if (!history) history= AddHistory(file, 0L);

  /* if no records were specified, current record becomes none */
  if (!nRecs) history->recNumber= -1;

  /* add the specified records */
  flags= (time? 1 : 0)|(ncyc? 2 : 0);
  while (nRecs--) {
    AddRecord(history, flags, time? time[0]:0.0, ncyc? ncyc[0]:0L,
              (address && address[0]>=0)? address[0]:-1L);
    if (time) time++;
    if (ncyc) ncyc++;
    if (address) address++;
  }
  if (history->nRecords>0) JumpRecord(history, history->nRecords-1);
}
Exemplo n.º 9
0
void CReportCtrl::FillRecordset(_RecordsetPtr &rst,FillRecordAux funcAux)
{ 
	if (rst != NULL)
		while (!rst->adoEOF)
		{
			FieldsPtr fields = rst->Fields;
			CXTPReportRecord *pRec = new CXTPReportRecord();
			for (int i=0; i<m_nColCount; ++i)
			{
				if (m_cols[i].fmt ==FmtIdOnly)
					pRec->SetBookmark(fields->Item[m_cols[i].field]->Value);
				else
					pRec->AddItem(RecordItemFromCol(m_cols[i],fields->Item[m_cols[i].field]->Value));

			}

			PutRecordAux(pRec);
			if (funcAux != NULL)
				funcAux(fields,pRec);

			AddRecord(pRec);
			rst->MoveNext();
		}

	if (m_nOpFlag & OpAdd)
	{
		m_pAddOpRecord = new CXTPReportRecord();
		for (int i=0; i<m_nColCount; ++i)
		{
			const ColInfo &col= m_cols[i];
			
			if (m_cols[i].fmt != FmtIdOnly)
			{
				CXTPReportRecordItem *pItem = new CXTPReportRecordItem();
				pItem->HasCheckbox(col.check);
				m_pAddOpRecord->AddItem(pItem); 
			}
		}

		PutAddRecordAux();
		AddRecord(m_pAddOpRecord);
	}

	Populate();
}
void
CacheIndexContextIterator::AddRecords(
  const nsTArray<CacheIndexRecord *> &aRecords)
{
  // We need to add one by one so that those with wrong context are ignored.
  for (uint32_t i = 0; i < aRecords.Length(); ++i) {
    AddRecord(aRecords[i]);
  }
}
// adds a new record with the data in the CRecordObject, returns the ID that was assigned to it
// use MakeNewEmptyRecord() to create the empty record, then you can fill in the fields and
// call this func to add it to the database
RecIDT	//** Thread Safe **
ADataStore::AddRecord(CRecord* inRecP) {
	ASSERT(inRecP != nil);	// еее pass by reference
	DB_DEBUG("AddRecord()");
	RecIDT id = 0;
	AutoLockRecord lock(inRecP);	// this will automatically unlock the record when it goes out
	DatabaseRec* p = inRecP->GetRecordDataPtr(); // of scope, whether normally or from an exception
	id = AddRecord(p);
	return id;
}
void CWndLog::OnForceUpdate()
{
	DeleteAllItems ();

	if (m_pEvMgr)
	{
		int cEvents = m_pEvMgr->GetEventCount ();
		for (int i = 0; i < cEvents; i++)
			AddRecord (m_pEvMgr->GetEvent (i));	
	}
}
Exemplo n.º 13
0
/*
 * -A #
 */
void
ProcAdminArg(char *arg)
{
	if (NumericStr(arg))
		AddRecord(SAM_QUOTA_ADMIN, atoi(arg));
	else {
		fprintf(stderr, "%s:  unrecognized admin ID: '%s'\n",
		    Program, arg);
		Err++;
	}
}
Exemplo n.º 14
0
void TOrdEntryForm::UpdateIfModified()
{
  if (OrderWasModified()) {
    switch (RecState) {
      case rsEdit : UpdateRecord(); break;
      case rsNew  : AddRecord(); break;
    }
    OvcVirtualListbox1->Repaint();
    DataListIsModified = true;
  }
}
Exemplo n.º 15
0
//*****************************************************************************
// Apply a delta record to a table, generically.
//*****************************************************************************
__checkReturn
HRESULT
CMiniMdRW::ApplyTableDelta(
    CMiniMdRW &mdDelta,     // Interface to MD with the ENC delta.
    ULONG      ixTbl,       // Table index to update.
    RID        iRid,        // RID of the changed item.
    int        fc)          // Function code of update.
{
    HRESULT hr = S_OK;
    void   *pRec;           // Record in existing MetaData.
    void   *pDeltaRec;      // Record if Delta MetaData.
    RID     newRid;         // Rid of new record.

    // Get the delta record.
    IfFailGo(mdDelta.GetDeltaRecord(ixTbl, iRid, &pDeltaRec));
    // Get the record from the base metadata.
    if (iRid > m_Schema.m_cRecs[ixTbl])
    {   // Added record.  Each addition is the next one.
        _ASSERTE(iRid == m_Schema.m_cRecs[ixTbl] + 1);
        switch (ixTbl)
        {
        case TBL_TypeDef:
            IfFailGo(AddTypeDefRecord(reinterpret_cast<TypeDefRec **>(&pRec), &newRid));
            break;
        case TBL_Method:
            IfFailGo(AddMethodRecord(reinterpret_cast<MethodRec **>(&pRec), &newRid));
            break;
        case TBL_EventMap:
            IfFailGo(AddEventMapRecord(reinterpret_cast<EventMapRec **>(&pRec), &newRid));
            break;
        case TBL_PropertyMap:
            IfFailGo(AddPropertyMapRecord(reinterpret_cast<PropertyMapRec **>(&pRec), &newRid));
            break;
        default:
            IfFailGo(AddRecord(ixTbl, &pRec, &newRid));
            break;
        }
        IfNullGo(pRec);
        _ASSERTE(iRid == newRid);
    }
    else
    {   // Updated record.
        IfFailGo(getRow(ixTbl, iRid, &pRec));
    }

    // Copy the record info.
    IfFailGo(ApplyRecordDelta(mdDelta, ixTbl, pDeltaRec, pRec));

ErrExit:
    return hr;
} // CMiniMdRW::ApplyTableDelta
Exemplo n.º 16
0
bool
CacheIndexIterator::ReplaceRecord(CacheIndexRecord *aOldRecord,
                                  CacheIndexRecord *aNewRecord)
{
  LOG(("CacheIndexIterator::ReplaceRecord() [this=%p, oldRecord=%p, "
       "newRecord=%p]", this, aOldRecord, aNewRecord));

  if (RemoveRecord(aOldRecord)) {
    AddRecord(aNewRecord);
    return true;
  }

  return false;
}
Exemplo n.º 17
0
void TOrdEntryForm::ReadFile(TFileName OrderFile)
{
  ifstream DataFile(OrderFile.c_str());
  if (!DataFile) return;

  // avoid painting while file is loaded
  LockWindowUpdate(Handle);
  while (!DataFile.read((char *)&TR, sizeof(TR)).eof()) {
    AddRecord();
  }
  LockWindowUpdate(0);
  DataFile.close();
  OvcVirtualListbox1->Repaint();
  OvcVirtualListbox1->ItemIndex = 0;
}
Exemplo n.º 18
0
void NFCRecordLogic::OnAddRow(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen)
{
	NFGUID nPlayerID;
	NFMsg::ObjectRecordAddRow xMsg;
	if (!NFINetModule::ReceivePB(nSockIndex, nMsgID, msg, nLen, xMsg, nPlayerID))
	{
		return;
	}
	
	NF_SHARE_PTR<NFIObject> object = g_pKernelModule->GetObject(NFINetModule::PBToNF(xMsg.player_id()));
	NF_SHARE_PTR<NFIRecordManager> recordMgr = object->GetRecordManager();

	for(int i = 0; i < xMsg.row_data_size(); i++)
	{
		AddRecord(object, xMsg.record_name(), xMsg.row_data(i));
	}
}
BOOL CWriteMonitorResult::Run()
{
	vector<CFileAction *>::iterator iter;
	vector<CFileAction *> ListCopy;
	while(!m_bExit)
	{
		EnterCriticalSection(&g_FileActionListCS);
		ListCopy.assign(g_MonotorFileActionList.begin(),g_MonotorFileActionList.end());
		g_MonotorFileActionList.clear();
		LeaveCriticalSection(&g_FileActionListCS);

		if (ListCopy.empty())
		{
			Sleep(1000);
			continue;
		}
		
		iter = ListCopy.begin(); 
		for (iter;iter!=ListCopy.end();)
		{
			if (m_bExit)
				break;

			if ((*iter)->m_Type == CFileAction::AC_ADD)
				AddRecord(*iter);

			else if ((*iter)->m_Type == CFileAction::AC_DEL)
				RemoveRecord(*iter);

			else if ((*iter)->m_Type == CFileAction::AC_RENAME)
				ModifyRecord(*iter);

			iter = ListCopy.erase(iter);
		}

		for (size_t i=0;i< ListCopy.size();i++)
			delete ListCopy[i];

		ListCopy.clear();
	}
	
	return TRUE;
}
Exemplo n.º 20
0
DizList::desc_map::iterator DizList::AddRecord(const string& DizText)
{
	string::const_iterator NameBegin, NameEnd, DescBegin;

	if (DizText.front() == L'"')
	{
		NameBegin = DizText.cbegin() + 1;
		NameEnd = std::find(NameBegin, DizText.cend(), L'"');
		DescBegin = NameEnd == DizText.cend()? NameEnd : NameEnd + 1;
	}
	else
	{
		NameBegin = DizText.cbegin();
		NameEnd = std::find_if(ALL_CONST_RANGE(DizText), IsSpace);
		DescBegin = NameEnd;
	}

	return AddRecord(string(NameBegin, NameEnd), string(DescBegin, DizText.end()));
}
// updates, or adds if doesn't already exist
RecIDT	//** Thread Safe **
ADataStore::WriteRecord(CRecord* inRecP) {
	ASSERT(inRecP != nil);	// еее pass by reference
	DB_DEBUG("WriteRecord("<<inRecP->GetRecordID()<<")");
	bool addIt = false;
	RecIDT id = inRecP->GetRecordID();
	AutoLockRecord lock(inRecP);	// automatically unlock the record as we exit this code block
	DatabaseRec* p = inRecP->GetRecordDataPtr();
	Try_{
		UpdateRecord(p);
	}
	Catch_(err) {
		if (err != dbItemNotFound) {
			Throw_(err);
		} else {
			addIt = true;
	    }
	}
	if (addIt) {
		id = AddRecord(p);
    }
	return id;
}
Exemplo n.º 22
0
/*===========================================================================
 *
 * Class CSrEspFile Method - CSrRecord* CreateNewRecord (Type);
 *
 * Creates and adds a new record to the file as given by the input
 * record type. The new record is returned.
 *
 *=========================================================================*/
CSrRecord* CSrEspFile::CreateNewRecord (const srrectype_t Type) {
  CSrRecord* pRecord;
  bool	     Result;
  
  pRecord = CreateSrRecord(Type);
  pRecord->InitializeNew();
  pRecord->SetParent(this);

  Result = AddRecord(pRecord);
  if (!Result) return (NULL);
  
	/* Set the header record reference */
  if (pRecord->GetRecordType() == SR_NAME_TES4) 
  {
    m_pHeader = SrCastClass(CSrTes4Record, pRecord);
  }
   	/* Update the overall record count */
  else if (m_pHeader != NULL) 
  {
    m_pHeader->ModRecordCount(1);
  }

  return (pRecord);
}
Exemplo n.º 23
0
//
// Global Classes
//
RDRecording::RDRecording(int id,bool create)
{
  RDSqlQuery *q;
  QString sql;

  if(id<0) {
    rec_id=AddRecord();
    create=false;
  }
  else {
    rec_id=id;
  }

  if(create) {
    sql=QString().sprintf("select ID from RECORDINGS where ID=%d",rec_id);
    q=new RDSqlQuery(sql);
    if(q->size()!=1) {
      delete q;
      sql=QString().sprintf("insert into RECORDINGS set ID=%d",rec_id);
      q=new RDSqlQuery(sql);
    }
    delete q;
  }
}
Exemplo n.º 24
0
int
main(int ac, char *av[])
{
	int c;
	struct timeval tp;
#ifdef DEBUG
	char *optstr = "A:ab:def:G:ghikOpt:U:uwx:z";
#else	/* DEBUG */
	char *optstr = "A:ab:ef:G:ghikOpt:U:uwx:";
#endif	/* DEBUG */

	Program = av[0];

	gettimeofday(&tp, NULL);
	Now = tp.tv_sec;

	while ((c = getopt(ac, av, optstr)) != EOF) {
		switch (c) {
		case 'A':	/* arg (admin set) */
			OptFlags |= OPTA;
			ProcAdminArg(optarg);
			break;

		case 'a':
			OptFlags |= OPTa;
			AddRecord(SAM_QUOTA_ADMIN, -1);
			break;

		case 'b':	/* arg (block count) */
			OptFlags |= OPTb;
			ProcBlockArg(optarg);
			break;

#ifdef DEBUG
		case 'd':
			OptFlags |= OPTd;
			dflag++;
			break;
#endif	/* DEBUG */

		case 'e':
			OptFlags |= OPTe;
			eflag++;
			pflag++;
			break;

		case 'f':	/* arg (file count) */
			OptFlags |= OPTf;
			ProcFileArg(optarg);
			break;

		case 'G':	/* arg (group ID) */
			OptFlags |= OPTG;
			ProcGroupArg(optarg);
			break;

		case 'g':
			OptFlags |= OPTg;
			AddRecord(SAM_QUOTA_GROUP, getegid());
			break;

		case 'h':	/* help.  No return */
			Help(0);
			break;

		case 'i':
			OptFlags |= OPTi;
			iflag = INIT_LIMITS_ZERO;
			break;

		case 'k':
			OptFlags |= OPTk;
			kflag++;
			break;

		case 'O':	/* Don't print total counts */
			OptFlags |= OPTO;
			tflag = 0;
			break;

		case 'p':
			OptFlags |= OPTp;
			pflag++;
			break;

		case 't':	/* arg (grace period) */
			OptFlags |= OPTt;
			ProcTimeArg(optarg);
			break;

		case 'U':	/* arg (user ID) */
			OptFlags |= OPTU;
			ProcUserArg(optarg);
			break;

		case 'u':
			OptFlags |= OPTu;
			AddRecord(SAM_QUOTA_USER, geteuid());
			break;

		case 'w':
			OptFlags |= OPTw;
			wflag = 0;
			break;

		case 'x':	/* arg (expiry) */
			OptFlags |= OPTx;
			ProcExpireArg(optarg);
			break;

#ifdef DEBUG
		case 'z':
			OptFlags |= OPTz;
			iflag = INIT_ALL_ZERO;
			break;
#endif	/* DEBUG */

		default:
			Help(1);
		}
	}

	for (; optind < ac; optind++) {
		ProcFile(av[optind]);
	}

	/*
	 *	Check options for validity.
	 */
#define	TWOBITS(a, b, c) ((a & (b | c)) == (b | c))

	if (OptFlags & OPTMASK_Set) {
		if (NFiles == 0 || (OptFlags & (OPTa | OPTg | OPTu))) {
			fprintf(stderr,
			    "%s:  The options require a file.\n", Program);
			Help(1);
		}

	} else {	/* just reporting */
	}
	if (TWOBITS(OptFlags, OPTa, OPTA) || TWOBITS(OptFlags, OPTg, OPTG) ||
	    TWOBITS(OptFlags, OPTu, OPTU)) {
		fprintf(stderr, "%s:  Incorrect option usage.\n", Program);
		Help(1);
	}

	if (!Err)
		ProcessFiles();
	return (Err ? 10 : 0);
}
Exemplo n.º 25
0
void DizList::Read(const string& Path, const string* DizName)
{
	Reset();

	struct DizPreRedrawItem : public PreRedrawItem
	{
		DizPreRedrawItem() : PreRedrawItem(PR_ReadingMsg) {}
	};

	SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique<DizPreRedrawItem>());
	const wchar_t *NamePtr=Global->Opt->Diz.strListNames.data();

	for (;;)
	{
		if (DizName)
		{
			strDizFileName = *DizName;
		}
		else
		{
			strDizFileName = Path;

			if (!PathCanHoldRegularFile(strDizFileName))
				break;

			string strArgName;
			NamePtr = GetCommaWord(NamePtr, strArgName);

			if (!NamePtr)
				break;

			AddEndSlash(strDizFileName);
			strDizFileName += strArgName;
		}

		os::fs::file DizFile;
		if (DizFile.Open(strDizFileName,GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING))
		{
			clock_t StartTime=clock();
			uintptr_t CodePage=CP_DEFAULT;
			bool bSigFound=false;

			if (!GetFileFormat(DizFile,CodePage,&bSigFound,false) || !bSigFound)
				CodePage = Global->Opt->Diz.AnsiByDefault ? CP_ACP : CP_OEMCP;

			GetFileString GetStr(DizFile, CodePage);

			auto LastAdded = DizData.end(); 
			string DizText;
			while (GetStr.GetString(DizText))
			{
				if (!(DizData.size() & 127) && clock() - StartTime > CLOCKS_PER_SEC)
				{
					SetCursorType(false, 0);
					PR_ReadingMsg();

					if (CheckForEsc())
						break;
				}

				RemoveTrailingSpaces(DizText);

				if (!DizText.empty())
				{
					if(!IsSpace(DizText.front()))
					{
						LastAdded = AddRecord(DizText);
					}
					else
					{
						if (LastAdded != DizData.end())
						{
							LastAdded->second.emplace_back(DizText);
						}
					}
				}
			}

			OrigCodePage=CodePage;
			Modified=false;
			DizFile.Close();
			return;
		}

		if (DizName)
			break;
	}

	Modified=false;
	strDizFileName.clear();
}
Exemplo n.º 26
0
void DizList::Read(const string& Path, const string* DizName)
{
	Reset();
	TPreRedrawFuncGuard preRedrawFuncGuard(DizList::PR_ReadingMsg);
	const wchar_t *NamePtr=Opt.Diz.strListNames;

	for (;;)
	{
		if (DizName)
		{
			strDizFileName = *DizName;
		}
		else
		{
			strDizFileName = Path;

			if (!PathCanHoldRegularFile(strDizFileName))
				break;

			string strArgName;

			if (!(NamePtr=GetCommaWord(NamePtr,strArgName)))
				break;

			AddEndSlash(strDizFileName);
			strDizFileName += strArgName;
		}

		File DizFile;
		if (DizFile.Open(strDizFileName,GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING))
		{
			GetFileString GetStr(DizFile);
			wchar_t *DizText;
			int DizLength;
			clock_t StartTime=clock();
			uintptr_t CodePage=CP_DEFAULT;
			bool bSigFound=false;

			if (!GetFileFormat(DizFile,CodePage,&bSigFound,false) || !bSigFound)
				CodePage = Opt.Diz.AnsiByDefault ? CP_ACP : CP_OEMCP;

			while (GetStr.GetString(&DizText, CodePage, DizLength) > 0)
			{
				if (!(DizCount & 127) && clock()-StartTime>1000)
				{
					SetCursorType(FALSE,0);
					PR_ReadingMsg();

					if (CheckForEsc())
						break;
				}

				RemoveTrailingSpaces(DizText);

				if (*DizText)
					AddRecord(DizText);
			}

			OrigCodePage=CodePage;
			Modified=false;
			DizFile.Close();
			return;
		}

		if (DizName)
			break;
	}

	Modified=false;
	strDizFileName.Clear();
}
Exemplo n.º 27
0
//*****************************************************************************
// Insert a Record into the pool.  The index of the Record before which to
// insert is specified.  Shifts all records down.  Return a pointer to the
// new record.
//*****************************************************************************
void *RecordPool::InsertRecord(			// New record, or NULL.
	ULONG		iLocation)				// [IN] Insert record before this.
{
	StgPoolSeg	*pCurSeg;				// Current segment.
	StgPoolSeg	*pPrevSeg;				// Previous segment.
	BYTE		*pSegEnd;				// Last record in a segment.
	BYTE		*pFrom;					// A copy/move source.
	ULONG		cbMove;					// Bytes to move.
	void		*pNew;					// New record.

	// Notice the case of appending.
	if (iLocation == static_cast<ULONG>(Count()+1))
		return AddRecord();

	// If past end or before beginning, invalid.
	if (iLocation > static_cast<ULONG>(Count()) || iLocation == 0)
	{
		_ASSERTE(!"Invalid location for record insertion");
		return 0;
	}

	// This code works by allocating a new record at the end.
	// The last record is moved to the new end record.
	// Working backwards through the chained segments,
	//     shift the segment by one record, so the empty record
	//      is at the start of the segment instead of the end.
	// 	   copy the last record of the previous segment to the
	//      newly emptied first record of the current segment.
	// When the segment containing the insert point is finally
	//  reached, its last record is empty (from above loop), so
	//  shift from the insertion point to the end-1 by one record.


	// Current last record.
	pCurSeg = m_pCurSeg;
	pSegEnd = reinterpret_cast<BYTE*>(GetRecord(Count()));

	// Add an empty record to the end of the heap.
	if ((pNew = AddRecord()) == 0) return 0;

	// Copy the current last record to the new record.
	memcpy(pNew, pSegEnd, m_cbRec);

	// While the insert location is prior to the current segment,
	while (iLocation < GetIndexForRecord(pCurSeg->m_pSegData))
	{
		// Shift the segment up by one record.
		cbMove = (ULONG)(pSegEnd - pCurSeg->m_pSegData);
		memmove(pCurSeg->m_pSegData+m_cbRec, pCurSeg->m_pSegData, cbMove);

		// Find the previous segment.
		pPrevSeg = this;
		while (pPrevSeg->m_pNextSeg != pCurSeg)
			pPrevSeg = pPrevSeg->m_pNextSeg;

		// Copy the final record of the previous segment to the start of this one.
		pSegEnd = pPrevSeg->m_pSegData+pPrevSeg->m_cbSegNext-m_cbRec;
		memcpy(pCurSeg->m_pSegData, pSegEnd, m_cbRec);

		// Make the previous segment the current segment.
		pCurSeg = pPrevSeg;
	}

	// Shift at the insert location, forward by one.
	pFrom = reinterpret_cast<BYTE*>(GetRecord(iLocation));
	cbMove = (ULONG)(pSegEnd - pFrom);
	memmove(pFrom+m_cbRec, pFrom, cbMove);

	return pFrom;
} // void *RecordPool::InsertRecord()
Exemplo n.º 28
0
void NcursesExamine(Connection *conn, const char *file)
{
	int y = 0, down = 0, selection = 0; 
	int input;
	char examine_buf[MAX_DATA];
	char *arg1, *arg2;

	struct Information *rows = conn->core->db->rows;

	int *free_index = &(conn->core->cnf->free_index);
	int *delete_index = &(conn->core->cnf->delete_index);
	int *size = &(conn->core->cnf->size);

	mvwprintw(body, 0, 0, "%-2d %-10s %-10s", rows[0].index,
			rows[0].name, rows[0].phone);

	do {
		DisplayMode("Mode: Examine");
		/* debug
		   getyx(body, gety, getx);

		   mvprintw(maxy - 10, maxx - 30, 
		   "\ny = %d\nx = %d\ndown = %d\n", y, x, down);
		   mvprintw(maxy - 7, maxx - 30, 
		   "\ngety = %d\ngetx = %d\n", gety, getx);
		   mvprintw(maxy - 10, maxx - 30, 
		   "\ny = %d\nx = %d\ndown = %d\n", y, x, down);
		   refresh();
		 */

		PREFRESH_SCROLL;

		input = getchar();

		switch(input) {

			case 'a':
				touchwin(add);
				wrefresh(add);
				echo();
				wmove(add, 1, 1);
				wrefresh(add);
				wgetnstr(add, examine_buf, MAX_DATA);
				arg1 = strtok(examine_buf, " ");
				arg2 = strtok(NULL, " ");
				if ((arg1 == NULL) || (arg2 == NULL)) {
					DisplayError("name or phone is empty\n");
				} else {
					AddRecord(conn, &selection, arg1, arg2);
					DatabaseWrite(conn, file);
				}
				noecho();
				ClearLine(add);
				RefreshdbList(conn);
				break;

			case 'I':
				touchwin(add);
				wrefresh(add);
				echo();
				wmove(add, 1, 1);
				wrefresh(add);
				wgetnstr(add, examine_buf, MAX_DATA);
				arg1 = strtok(examine_buf, " ");
				arg2 = strtok(NULL, " ");
				if (arg1) {
					AddInsert(conn, &selection, arg1, arg2);
					DatabaseWrite(conn, file);
				}
				noecho();
				ClearLine(add);
				RefreshdbList(conn);
				break;

			case 'd':
				DeleteRecord(conn, &selection);
				DatabaseWrite(conn, file);
				RefreshdbList(conn);
				break;

			case 'D':
				DeleteInsert(conn, &selection);
				DatabaseWrite(conn, file);
				RefreshdbList(conn);
				break;

			case 'f':
				touchwin(find);
				wrefresh(find);
				echo();
				wmove(find, 1, 1);
				wrefresh(find);
				wgetnstr(find, examine_buf, MAX_DATA);
				arg1 = strtok(examine_buf, " ");
				if (arg1) {
					wmove(body, 0, 0);
					werase(body);
					DatabaseFind(conn, arg1, body);
					PREFRESH_SCROLL;
					getch();
				}
				noecho();
				ClearLine(find);
				RefreshdbList(conn);
				break;


				//case KEY_DOWN:
			case 'j':
				if (y != (maxy / 2) + 3) y++;
				wmove(body, y, 0);
				selection++;
				RefreshdbList(conn);
				if (y == (maxy / 2) + 3) down++;
				if (selection > (*size) - 1) {
					selection = 0;
					y = 0;
					down = 0;
				}
				ExamineSelection(&selection, conn);
				break;

				//case KEY_UP:
			case 'k':
				if (y != 0) y--;
				selection--;
				RefreshdbList(conn);
				if ((y == 0) && (down != 0)) down--;
				if (selection < 0) {
					selection = (*size) - 1;
					y = (*size) / 2;
					down = (*size) / 2;
				}
				ExamineSelection(&selection, conn);
				break;

			case 'r':
				touchwin(resize);
				wrefresh(resize);
				echo();
				wmove(resize, 1, 1);
				wrefresh(resize);
				wgetnstr(resize, examine_buf, MAX_DATA);
				arg1 = strtok(examine_buf, " ");
				if (arg1) {
					int i = atoi(arg1);
					if (i == *size) {
						DisplayError("database size is already that size\n");
					} else if (i <= *free_index || i <= (*delete_index) + 1) {
						DisplayError("cannot resize below valid records\n");
					} else {
						DatabaseResize(conn, &i);
						DatabaseWrite(conn, file);
					}
				}
				noecho();
				ClearLine(resize);
				RefreshdbList(conn);
				break;

			case 'A':
				DatabaseArrange(conn);
				DatabaseWrite(conn, file);
				RefreshdbList(conn);
				break;

			case 's':
				DatabaseSort(conn);
				DatabaseWrite(conn, file);
				RefreshdbList(conn);
				break;

			default:
				break;
		}

	} while (input != 'q');

	RefreshdbList(conn);
	PREFRESH_SCROLL;
}
Exemplo n.º 29
0
void NcursesConsole(Connection *conn, const char *file)
{
	char console_buf[MAX_DATA];
	char *arg1, *arg2, *arg3, *arg4; 

	int *free_index = &(conn->core->cnf->free_index);
	int *delete_index = &(conn->core->cnf->delete_index);
	int *size = &(conn->core->cnf->size);

	wmove(console, 1, 1);
	touchwin(console);
	wrefresh(console);
	napms(100);
	wbkgd(border_console, COLOR_PAIR(5));
	touchwin(border_console);
	wrefresh(border_console);
	touchwin(console);
	wrefresh(console);
	echo();

	do {
		DisplayMode("Mode: Console");
		wmove(body, 0, 0);
		werase(body);
		DatabaseList(conn, body);
		PREFRESH;

		wgetnstr(console, console_buf, MAX_DATA);
		arg1 = strtok(console_buf, " ");
		arg2 = strtok(NULL, " ");
		arg3 = strtok(NULL, " ");
		arg4 = strtok(NULL, " ");

		ClearLine(console);

		if (arg1 != NULL) {

			if (strncmp(arg1, "add", 1) == 0) {
				if (arg4 == NULL) {
					if ((arg2 == NULL) || (arg3 == NULL)) {
						DisplayError("name or phone is empty\n");
					} else
						AddRecord(conn, NULL, arg2, arg3);
				} else {
					int i = atoi(arg2);
					if (i > *size || i < 0) {
						DisplayError("index out of bounds\n");
					} else {
						if ((arg3 == NULL) || (arg4 == NULL)) {
							DisplayError("name or phone is empty\n");
						} else {
							AddRecord(conn, &i, arg3, arg4);
						}
					}
				}
				DatabaseWrite(conn, file);
			}
			if (strncmp(arg1, "Insert", 1) == 0) {
				if (arg4 == NULL) {
					AddInsert(conn, NULL, arg2, arg3);
				} else {
					int i = atoi(arg2);
					if (i > *size || i < 0) {
						DisplayError("index out of bounds\n");
					} else {
						AddInsert(conn, &i, arg3, arg4);
					}
				}
				DatabaseWrite(conn, file);
			}
			if (strncmp(arg1, "delete", 1) == 0) {
				if (*free_index == 0 && *delete_index == 0) {
					DisplayError("database is already empty\n");
				} else if (arg2 == NULL) {
					DeleteRecord(conn, NULL);
				} else {
					int i = atoi(arg2);
					DeleteRecord(conn, &i);
				}
				DatabaseWrite(conn, file);
			}
			if (strncmp(arg1, "Delete", 1) == 0) {
				if (*free_index == 0 && *delete_index == 0) {
					DisplayError("database is already empty\n");
				} else if (arg2 == NULL) {
					DeleteInsert(conn, NULL);
				} else {
					int i = atoi(arg2);
					DeleteInsert(conn, &i);
				}
				DatabaseWrite(conn, file);
			}
			if (strncmp(arg1, "resize", 1) == 0) {
				int i = atoi(arg2);
				if (i == *size) {
					DisplayError("database size is already that size\n");
				} else if (i <= *free_index || i <= (*delete_index) + 1) {
					DisplayError("cannot resize below valid records\n");
				} else {
					DatabaseResize(conn, &i);
					DatabaseWrite(conn, file);
				}
			}
			if (strncmp(arg1, "Arrange", 1) == 0) {
				DatabaseArrange(conn);
				DatabaseWrite(conn, file);
			}
			if (strncmp(arg1, "sort", 1) == 0) {
				DatabaseSort(conn);
				DatabaseWrite(conn, file);
			}
			if (strncmp(arg1, "find", 1) == 0) {
				wmove(body, 0, 0);
				werase(body);
				DatabaseFind(conn, arg2, body);
				PREFRESH;
				getch();
			}
		} else
			break;
	} while (strncmp(arg1, "quit", 1) != 0);

	wbkgd(border_console, COLOR_PAIR(2));
	wrefresh(border_console);
	touchwin(console);
	wrefresh(console);
	noecho();
}
Exemplo n.º 30
0
void TOrdEntryForm::UpdateRecord()
{
  DataList->Delete(OvcVirtualListbox1->ItemIndex);
  AddRecord();
  RecState = rsDefault;
}