/* * Display the given table in the specified SP. */ void DisplayTable(HWND hWndParent, LPTCGDRIVE hDrive) { TCGAUTH TcgAuth; LPTABLE Table; BOOL RetVal; BYTE Sp[8]; BYTE TableUid[8]; /* Query the user for the SP to activate. */ RetVal = GetSP(hWndParent, hDrive, Sp, Caption); /* If the user cancelled the query, return. */ if(RetVal == FALSE) { return; } /* Query the user for the authority to use. */ RetVal = GetUserAuthInfo(hWndParent, hDrive, Sp, NULL, Caption, &TcgAuth); /* If the user cancelled the query, return. */ if(RetVal == FALSE) { return; } /* Read the table of tables. */ Table = ReadTableNoSession(hDrive, Sp, TABLE_TABLE.Uid, &TcgAuth); /* If there was a problem, return. */ if(Table == NULL) { MessageBox(hWndParent, _T("An error occurred reading the table of tables."), Caption, MB_OK); return; } /* Query the user for the table to display. */ RetVal = GetTable(hWndParent, Table, TableUid); /* Free the table. */ FreeTable(Table); /* If the user cancelled the query, return. */ if(RetVal == FALSE) { return; } /* Read the selected table. */ Table = ReadTableNoSession(hDrive, Sp, TableUid, &TcgAuth); /* If there was a problem, return. */ if(Table == NULL) { MessageBox(hWndParent, _T("An error occurred reading the selected table."), Caption, MB_OK); return; } /* Display the table. */ DisplayGenericTable(hWndParent, Table, _T("Table Display"), NULL); /* Free up used memory. */ FreeTable(Table); }
NLM_EXTERN Boolean SendTextToFile (FILE *f, CharPtr text, ParPtr parFmt, ColPtr colFmt) { Uint2 cnt; Uint2 cntr; Boolean rsult; Int2 start; TablePtr tptr; rsult = TRUE; start = 0; cntr = StringLen (text); cnt = MIN (cntr, 64000); cnt = SkipPastNewLine (text + start, cnt); while (cnt > 0) { tptr = TableSegment (text + start, cnt, parFmt, colFmt); if (! SaveTableToFile (tptr, f)) { rsult = FALSE; } FreeTable (tptr); start += cnt; cntr -= cnt; cnt = MIN (cntr, 64000); cnt = SkipPastNewLine (text + start, cnt); } return rsult; }
void CscopeTab::Clear() { if (m_table) { //free the old table FreeTable(); } m_dataviewModel->Clear(); }
TAppDictionary::~TAppDictionary() { if (NumEntries != 0 && Table) { FreeTable(Table); Table = NULL; NumEntries = 0; } }
void CscopeTab::BuildTable(CScopeResultTable_t *table) { if ( !table ) { return; } if (m_table) { // Free the old table FreeTable(); } m_table = table; m_dataviewModel->Clear(); wxStringSet_t insertedItems; CScopeResultTable_t::iterator iter = m_table->begin(); for (; iter != m_table->end(); ++iter ) { wxString file = iter->first; wxVector<wxVariant> cols; cols.push_back( CScoptViewResultsModel::CreateIconTextVariant(file, GetBitmap(file)) ); cols.push_back(wxString()); cols.push_back(wxString()); wxDataViewItem fileItem = m_dataviewModel->AppendItem( wxDataViewItem(0), cols, NULL); // Add the entries for this file CScopeEntryDataVec_t* vec = iter->second; for ( size_t i=0; i<vec->size(); ++i ) { CscopeEntryData entry = vec->at(i); // Dont insert duplicate entries to the match view wxString display_string; display_string << _("Line: ") << entry.GetLine() << wxT(", ") << entry.GetScope() << wxT(", ") << entry.GetPattern(); if(insertedItems.find(display_string) == insertedItems.end()) { insertedItems.insert(display_string); cols.clear(); cols.push_back( CScoptViewResultsModel::CreateIconTextVariant(entry.GetScope(), wxNullBitmap) ); cols.push_back( (wxString() << entry.GetLine()) ); cols.push_back( (wxString() << entry.GetPattern()) ); m_dataviewModel->AppendItem( fileItem, cols, new CscopeTabClientData(entry) ); } } } FreeTable(); }
void CloseRand2D(void) /* Zamkniecie generatora 2D */ { if(DystVector!=NULL) { free((void *)DystVector); DystVector=NULL; } if(DystMatrix!=NULL) { FreeTable(DystMatrix,GlobTimeSize); DystMatrix=NULL; } GlobTimeSize=GlobFreqSize=0; }
int main(int argc, char *argv[]) { char buf[LINE_LEN]; /* word string buffer */ char fileName[LINE_LEN]; /* file name buffer */ int howManyBins; /* number of bins to create */ TABLE *hashTable; /* pointer to hash table */ FILE *fp; /* Read file name from command line */ if (argc < MIN_ARGS || sscanf(argv[FILE_ARG_IX], BUFFMT "s", fileName) != 1) { fprintf(stderr, "No file name specified on command line\n"); return EXIT_FAILURE; } fp = OpenFile(fileName); /* Read bin count from command line */ if (sscanf(argv[BINS_ARG_IX], "%d", &howManyBins) != 1) { fprintf(stderr, "No bin count specified on command line\n"); return EXIT_FAILURE; } hashTable = CreateTable((size_t)howManyBins); /* allocate table array */ /* * The following loop will read one string at a time from stdin until * EOF is reached. For each string read the BuildList function will * be called to update the hash table. */ while (fscanf(fp, BUFFMT "s", buf) != EOF) /* get string from file */ { /* find appropriate bin */ BIN *bin = &hashTable->firstBin[HashFunction(buf, (size_t)howManyBins)]; NODE *newStart = BuildTree(bin->firstNode, buf, bin); /* put string in list */ bin->firstNode = newStart; } fclose(fp); PrintTable(hashTable); /* print all strings */ FreeTable(hashTable); /* free the table */ return(EXIT_SUCCESS); }
int InicGen2D(float func(int,int),int TimeSize,int FreqSize,int Srand) { /* Inicjacja generatora liczb z 2D rozkladu p-stwa func(x,y) */ register int i,j; float sum,norma=0.0F; if((DystMatrix=MakeTable(TimeSize,FreqSize))==NULL) return -1; if((DystVector=(float *)malloc(TimeSize*sizeof(float)))==NULL) { FreeTable(DystMatrix,TimeSize); DystMatrix=NULL; return -1; } if(Srand==0) SRAND(0U); else SRAND((unsigned short)time(NULL)); GlobTimeSize=TimeSize; GlobFreqSize=FreqSize; for(i=0 ; i<TimeSize ; i++) /* Generacja rozkladu p-stwa + normalizacja */ for(j=0 ; j<FreqSize ; j++) { const float ftmp=func(i,j); /* Wartosci ujemne nie maja interpretacji */ norma+=DystMatrix[i][j]=((ftmp<0.0F) ? 1.0F : ftmp); } for(i=0,sum=0.0F ; i<FreqSize ; i++) /* Dystrybuanta brzegowa */ sum+=DystMatrix[0][i]; DystVector[0]=sum/norma; for(i=1 ; i<TimeSize ; i++) { for(j=0,sum=0.0F ; j<FreqSize ; j++) sum+=DystMatrix[i][j]; DystVector[i]=DystVector[i-1]+sum/norma; } for(i=0 ; i<TimeSize ; i++) /* Dystrybuanty warunkowe */ { for(j=0,sum=0.0F ; j<FreqSize ; j++) sum+=DystMatrix[i][j]; DystMatrix[i][0]/=sum; for(j=1 ; j<FreqSize ; j++) DystMatrix[i][j]=DystMatrix[i][j-1]+DystMatrix[i][j]/sum; } return 0; }
TAppDictionaryEntry *TAppDictionary::GrowTable(int Increment) { int OldNumEntries = NumEntries; TAppDictionaryEntry * OldInstanceDataTable = Table; NumEntries = NumEntries + Increment; Table = AllocTable(NumEntries); // copy old table to new location _fmemcpy(Table, OldInstanceDataTable, OldNumEntries * sizeof(TAppDictionaryEntry)); FreeTable(OldInstanceDataTable); // return pointer to first entry in new block return &Table[OldNumEntries]; }
/* * Test a user entered password against all users and all SPs. */ void TestPassword(HWND hWndParent, LPTCGDRIVE hDrive) { LPTABLECELL SpCell; LPTABLECELL UserCell; TCGAUTH TcgAuth; LPTABLE SpTable; LPTABLE UserTable; LPBYTE UserName; LPBYTE SpName; TCHAR Text[1000]; DWORD Count; BOOL Result; int SpRows; int UserRows; int i, j; /* Query the user for the password. */ Result = GetPassword(hWndParent, hDrive, &TcgAuth); /* If the user cancels, just return. */ if(Result == FALSE) { return; } /* Get the list of SPs on the drive. */ SpTable = GetSpTable(hDrive); /* Verify the table. */ if(SpTable == NULL) { MessageBox(hWndParent, _T("There was an error reading the SP table."), _T("Password Test"), MB_ICONERROR | MB_OK); return; } /* For each SP, get a list of users within the SP. */ Count = 0; SpRows = GetRows(SpTable); for(i=0; i<SpRows; i++) { /* Get the table cell. */ SpCell = GetTableCell(SpTable, i, 0); /* Get a list of users. */ UserTable = GetUserTable(hDrive, SpCell->Bytes); /* Verify the table. */ if(UserTable == NULL) { MessageBox(hWndParent, _T("There was an error reading a user table."), _T("Password Test"), MB_ICONERROR | MB_OK); continue; } /* Loop through users. */ UserRows = GetRows(UserTable); for(j=0; j<UserRows; j++) { /* Get the table cell. */ UserCell = GetTableCell(UserTable, j, 0); /* Copy the authority. */ memcpy(TcgAuth.Authority, UserCell->Bytes, sizeof(TcgAuth.Authority)); /* Check the authorization value. */ Result = CheckAuth(hDrive, SpCell->Bytes, &TcgAuth); /* If it works, notify the user. */ if(Result) { SpName = GetName(SpTable, i); UserName = GetName(UserTable, j); wsprintf(Text, _T("Password verified for user '%s' in SP '%s'"), UserName, SpName); MessageBox(hWndParent, Text, _T("Password Test"), MB_OK); Count++; } } /* Free up memory. */ FreeTable(UserTable); } /* If the password did not verify at all, notify the user. */ if(Count == 0) { MessageBox(hWndParent, _T("The password was not verified."), _T("Password Test"), MB_OK); } else { MessageBox(hWndParent, _T("Password verification complete."), _T("Password Test"), MB_OK); } /* Free up memory. */ FreeTable(SpTable); }
CGraphmatFile :: ~CGraphmatFile() { assert (m_pDicts); if (m_pDicts) delete m_pDicts; FreeTable(); };
// Reading the Unicode cache bool LoadUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash) { UNICODE_CACHE c, t; BUF *b; UINT i, num; IO *io; wchar_t name[MAX_PATH]; UCHAR binhash[MD5_SIZE]; UCHAR binhash_2[MD5_SIZE]; // Validate arguments if (strfilename == NULL || hash == NULL) { return false; } GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash); io = FileOpenW(name, false); if (io == NULL) { return false; } b = FileToBuf(io); if (b == NULL) { FileClose(io); return false; } SeekBuf(b, 0, 0); FileClose(io); Hash(binhash, b->Buf, b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0, false); Copy(binhash_2, ((UCHAR *)b->Buf) + (b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0), MD5_SIZE); if (Cmp(binhash, binhash_2, MD5_SIZE) != 0) { FreeBuf(b); return false; } Zero(&c, sizeof(c)); UniToStr(c.StrFileName, sizeof(c.StrFileName), strfilename); c.StrFileSize = strfilesize; DisableNetworkNameCache(); GetMachineName(c.MachineName, sizeof(c.MachineName)); EnableNetworkNameCache(); c.OsType = GetOsInfo()->OsType; Copy(c.hash, hash, MD5_SIZE); #ifdef OS_UNIX GetCurrentCharSet(c.CharSet, sizeof(c.CharSet)); #else // OS_UNIX { UINT id = MsGetThreadLocale(); Copy(c.CharSet, &id, sizeof(id)); } #endif // OS_UNIX Zero(&t, sizeof(t)); ReadBuf(b, &t, sizeof(t)); if (Cmp(&c, &t, sizeof(UNICODE_CACHE)) != 0) { FreeBuf(b); return false; } num = ReadBufInt(b); FreeTable(); TableList = NewList(CmpTableName); for (i = 0;i < num;i++) { UINT len; TABLE *t = ZeroMalloc(sizeof(TABLE)); len = ReadBufInt(b); t->name = ZeroMalloc(len + 1); ReadBuf(b, t->name, len); len = ReadBufInt(b); t->str = ZeroMalloc(len + 1); ReadBuf(b, t->str, len); len = ReadBufInt(b); t->unistr = ZeroMalloc((len + 1) * sizeof(wchar_t)); ReadBuf(b, t->unistr, len * sizeof(wchar_t)); Add(TableList, t); } FreeBuf(b); Sort(TableList); return true; }
// Read a string table from the buffer bool LoadTableFromBuf(BUF *b) { char *tmp; char prefix[MAX_SIZE]; LIST *replace_list = NULL; UINT i; // Validate arguments if (b == NULL) { return false; } // If the table already exists, delete it FreeTable(); // Create a list TableList = NewList(CmpTableName); Zero(prefix, sizeof(prefix)); replace_list = NewListFast(NULL); // Read the contents of the buffer line by line while (true) { TABLE *t; bool ok = true; tmp = CfgReadNextLine(b); if (tmp == NULL) { break; } if (tmp[0] == '$') { char key[128]; char value[MAX_SIZE]; if (GetKeyAndValue(tmp, key, sizeof(key), value, sizeof(value), " \t")) { if (StartWith(key, "$") && EndWith(key, "$") && StrLen(key) >= 3) { TABLE *t; wchar_t univalue[MAX_SIZE]; wchar_t uniname[MAX_SIZE]; t = ZeroMalloc(sizeof(TABLE)); Zero(univalue, sizeof(univalue)); Utf8ToUni(univalue, sizeof(univalue), value, StrLen(value)); StrToUni(uniname, sizeof(uniname), key); t->name = (char *)CopyUniStr(uniname); t->unistr = CopyUniStr(univalue); Add(replace_list, t); // Found a replacement definition ok = false; } } } if (ok) { t = ParseTableLine(tmp, prefix, sizeof(prefix), replace_list); if (t != NULL) { // Register Insert(TableList, t); } } Free(tmp); } for (i = 0;i < LIST_NUM(replace_list);i++) { TABLE *t = LIST_DATA(replace_list, i); Free(t->name); Free(t->str); Free(t->unistr); Free(t); } ReleaseList(replace_list); return true; }