// Read (Object) //------------------------------------------------------------------------------ RefObject * TextReader::Read() { // Load if ( ReadLines() == false ) { return nullptr; } if ( m_RootObject ) { Object * obj = DynamicCast< Object >( m_RootObject ); ASSERT( obj ); ReflectionInfo::RegisterRootObject( obj ); } // ResolveWeakRefs ResolveWeakRefs(); // Init auto end = m_ObjectsToInit.End(); for ( auto it=m_ObjectsToInit.Begin(); it!=end; ++it ) { ( *it )->Init(); } return m_RootObject; }
int main() { // open e-mail text data char *p = ReadLines("log1"); int points=spam_points(p); if(points >= 20) { puts("High level of spam rank"); } else if(points > 10) { puts("Medium level of spam rank"); } else if(points < 10) { puts("Low level of spam rank"); } if(p!=NULL) { free(p); p=NULL; } return 0; }
void FillUsers(void) { FILE *file; int i; file = fopen("USERS", "r"); if(file == NULL) { perror("Failed to open \"USERS\""); } else { ReadLines(file); rewind(file); users = malloc(LINES * sizeof(struct _users)); for(i = 0; i < LINES; i++) { fscanf(file, "%s\t\t%s\r\n", users[i].name, users[i].code); } fclose(file); } }
// search matchs in file char *Search_for(char * NameFile,char *regex) { long int count=0; int match=0; char *lineBuffer=xcalloc(1,1), *buffer2=ReadLines(NameFile), *ptr= strtok(buffer2,"\n"); char tmpline[2128]; Dead_Space(ptr); while(ptr!=NULL) { match=match_test(ptr,regex); if(match) { lineBuffer=xrealloc(lineBuffer,strlen(lineBuffer)+2256); snprintf(tmpline,2127," Line: %ld - %s\n",count,ptr); strncat(lineBuffer,tmpline,2255); } ptr = strtok (NULL, "\n"); count++; } xfree((void **)&ptr); return lineBuffer; }
void SortFile(FULL_CHAR *infile, FULL_CHAR *outfile) { LINE *lines; int lines_len; FILE *in_fp, *out_fp; debug2(DEX, D, "SortFile(%s, %s)", infile, outfile); /* open input file */ in_fp = fopen( (char *) infile, READ_BINARY); if( in_fp == (FILE *) NULL ) Error(45, 5, "cannot open index file %s for reading", FATAL, no_fpos, outfile); /* open output file */ out_fp = fopen( (char *) outfile, WRITE_BINARY); if( out_fp == (FILE *) NULL ) Error(45, 6, "cannot open index file %s for writing", FATAL, no_fpos, outfile); /* read lines, sort them, and write them out again sorted */ lines = ReadLines(in_fp, infile, (FULL_CHAR *) NULL, &lines_len); SortLines(lines, lines_len); fclose(in_fp); WriteLines(out_fp, lines, lines_len); fclose(out_fp); }
void forky_fichs(char* fichero_tst){ char *file_out, *file_ok; int fd_out, test_correct; int pid; file_out=ExtensionFile(fichero_tst, OUT); file_ok=ExtensionFile(fichero_tst, OK); fd_out=CreatFile(file_out); pid=fork(); switch(pid){ case -1: err(1, "cant create more forks"); case 0: ReadLines(fichero_tst, fd_out); exit(EXIT_SUCCESS); default: wait(NULL); //lo de los ficheros test_correct=check_ok(file_out, file_ok, fd_out); if(test_correct){ printf("%s: Test correcto\n", fichero_tst ); }else{ printf("%s: Test incorrecto\n", fichero_tst); } } close(fd_out); }
void PlatformerScene::editorBtnOpenPressed_callback(string filename) { string level = GameSettings::GetStr("LevelData_" + filename); if (level == "") { log("Level [" + filename + "] does not exist. Cannot load."); return; } editorLoadMap(ReadLines(level)); }
void Player::initPlayer(ClipEntry& clipEntry) { this->clipEntry = &clipEntry; clipMaskFileNames = ReadLines(Config.GetForegroundFolder(clipEntry)); frameNumber = clipEntry.GetFrameCount(); cout << "frameNumber: " << frameNumber << endl; startFrameNumber = 0; nowFrameNumber = 0; waitKeyNumber = 32; nowSequenceNumber = 0; weightPath = Config.GetWeightsPath(clipEntry); weightW = 1000; weightH = 200; sequencePath = Config.GetSequencePath(clipEntry); initWeight(); initSequence(); namedWindow("Display", CV_WINDOW_AUTOSIZE); namedWindow("Foreground", CV_WINDOW_AUTOSIZE); namedWindow("Weight", CV_WINDOW_AUTOSIZE); createTrackbar("Frame", "Weight", 0, frameNumber-1, changeBar, (void*)this); setTrackbarPos("Frame", "Weight", nowFrameNumber); createTrackbar("Speed", "Weight", 0, 6, changeSpeed, (void*)this); setTrackbarPos("Speed", "Weight", 3); if(clipEntry.Type == ClipType::Video){ Mat frame; int num = 11; while(num--) clipEntry.Video.read(frame); } showFrame(s[0],1); loop(); }
BOOL OpenChartVer1 (HANDLE hFile, DISKCHART *pDiskChart, PGRAPHSTRUCT pGraph) { // OpenChartVer1 bDelayAddAction = TRUE ; pGraph->Visual = pDiskChart->Visual ; pGraph->gOptions = pDiskChart->gOptions ; pGraph->gMaxValues = pDiskChart->gMaxValues ; pGraph->bManualRefresh = pDiskChart->bManualRefresh ; pGraphs->gInterval = (INT) (pGraph->gOptions.eTimeInterval * (FLOAT) 1000.0) ; ReadLines (hFile, pDiskChart->dwNumLines, &(pGraph->pSystemFirst), &(pGraph->pLineFirst), IDM_VIEWCHART) ; bDelayAddAction = FALSE ; GraphAddAction () ; return (TRUE) ; } // OpenChartVer1
bool wxDiagram::LoadFile(const wxString& filename) { wxBeginBusyCursor(); wxExprDatabase database(wxExprInteger, _T("id")); if (!database.Read(filename)) { wxEndBusyCursor(); return false; } DeleteAllShapes(); database.BeginFind(); wxExpr *header = database.FindClauseByFunctor(_T("diagram")); if (header) OnHeaderLoad(database, *header); // Scan through all clauses and register the ids wxNode *node = database.GetFirst(); while (node) { wxExpr *clause = (wxExpr *)node->GetData(); long id = -1; clause->GetAttributeValue(_T("id"), id); wxRegisterId(id); node = node->GetNext(); } ReadNodes(database); ReadContainerGeometry(database); ReadLines(database); OnDatabaseLoad(database); wxEndBusyCursor(); return true; }
int _cdecl wmain(int argc, LPCWSTR argv[]) { g_reverse = (argc == 2 && 0 == _wcsicmp(argv[1], L"-reverse")); line *first = ReadLines(); LPWSTR *lines = nullptr; int count = 0; for (auto current = first; current != nullptr; current = current->next) { count++; } if (count == 0) { goto Cleanup; } lines = new LPWSTR[count]; if (lines == nullptr) { ERR(L"Out of memory"); goto Cleanup; } auto current = first; for (int i = 0; i < count; i++) { lines[i] = current->text; current = current->next; } qsort(lines, count, sizeof(lines[0]), shellsort); for (int i = 0; i < count; i++) { LOG(L"%s", lines[i]); } Cleanup: DeleteLines(first); delete [] lines; return 0; }
/*-----------------------------------------------------------------------------*/ int16 bp_LoadBatch( int8 * pcString, TScriptFiles ** pptFiles) { int16 iStatus = BP_OK; if ((_ptFile = fopen(pcString, "rt")) == NULL) { /* ERROR */ iStatus = BP_FILE_CANNOT_BE_OPENED; } else { iStatus = ReadLines(pptFiles); if (fclose(_ptFile) == 0) { /* File couldn't be closed, what went wrong ?? */ } } return iStatus; }
void fly_to_analyse(char *path, char *config) { char *p = ReadLines(config); char *last=p; char title[128],description[512],reference[512],match[1024],relevance[512]; int result=0,sz=0; while(!result && strlen(last)>16) { switch (parse_eggs(&p, &last)) { case TITLE: sz = p - last; memset(title,0,127); snprintf(title,127,"%.*s", sz, last); strcpy(title,ClearStr(title,10)); break; case DESCRIPTION: sz = p - last; memset(description,0,511); snprintf(description,511,"%.*s", sz, last); strcpy(description,ClearStr(description,16)); break; case REFERENCE: sz = p - last - 1; memset(reference,0,511); snprintf(reference,511,"%.*s", sz, last); strcpy(reference,ClearStr(reference,14)); break; case RELEVANCE: sz = p - last; memset(relevance,0,511); snprintf(relevance,511,"%.*s", sz, last); strcpy(relevance,ClearStr(relevance,14)); break; case MATCH: sz = p - last; memset(match,0,1023); snprintf(match,1023,"%.*s", sz, last); strcpy(match,ClearStr(match,10)); char *result2=Search_for(path,match); // TODO* need validate before print out if(result2!=NULL) if(strlen(result2)>8) { fprintf(stdout,"\n-------------------\n %sTitle:%s %s \n %sDescription:%s %s \n %sRelevance:%s %s \n %sReference:%s %s \n %sMatch:%s %s \n%s%s%s\n",YELLOW,LAST,title,YELLOW,LAST,description,YELLOW,LAST,relevance,YELLOW,LAST,reference,YELLOW,LAST,match,CYAN,result2,LAST); if(log_file != NULL) { FILE *arq; arq=fopen(log_file,"a"); if ( arq == NULL ) { DEBUG("error in XML file %s",log_file); perror("Error "); exit(-1); } fprintf(arq,"<report_mosca>\n <Path>%s</Path>\n <Module>%s</Module>\n <Title>%s</Title>\n <Description>%s</Description>\n <Level>%s</Level>\n <Reference>%s</Reference>\n <Match>%s</Match>\n <Result>%s</Result>\n</report_mosca>\n\n",path,config,title,description,relevance,reference,match,result2); if( fclose(arq) == EOF ) { DEBUG("error in Write() file %s",log_file); perror("Error "); exit(-1); } arq=NULL; } } xfree((void **)&result2); break; case END: result=1; break; } } }
BOOL ProcessFiles(LPTSTR Path) { WIN32_FIND_DATA FindFile; PEXTENSION_INFO Info; TCHAR SearchPath[256]; TCHAR FileName[256]; TCHAR *Ext; HANDLE SearchHandle; BOOL More; Info = ExtInfoList; while (Info != NULL) { Ext = Info->ExtName; do { ZeroMemory (&FindFile, sizeof (FindFile)); _tcscpy (SearchPath, Path); _tcscat (SearchPath, _T("\\*.")); _tcscat (SearchPath, Ext); _tcscpy (FindFile.cFileName, SearchPath); SearchHandle = FindFirstFile (SearchPath, &FindFile); if (SearchHandle != INVALID_HANDLE_VALUE) { More = TRUE; while (More) { if (!(FindFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { _tcscpy (FileName, Path); _tcscat (FileName, _T("\\")); _tcscat (FileName, FindFile.cFileName); if (LoadFile (FileName)) { PFILE_INFO StatInfo; StatInfo = AddFile (FindFile.cFileName, Info); if (!StatInfo) { _tprintf (_T("Not enough free memory.\n")); return FALSE; } ReadLines (StatInfo); Info->FileCount++; Info->LineCount += StatInfo->LineCount; Info->EmptyLines += StatInfo->EmptyLines; CleanupAfterFile(); } } More = FindNextFile (SearchHandle, &FindFile); } FindClose (SearchHandle); } Ext += _tcslen(Ext) + 1; } while(*Ext != _T('\0')); Info = Info->Next; } return TRUE; }
void Query::Execute() { std::ostream& output = GetEnvironment().GetOutputStream(); if (m_isSingleQuery) { output << "Processing query \"" << m_query << "\"" << std::endl; auto instrumentation = QueryRunner::Run(m_query.c_str(), GetEnvironment().GetSimpleIndex(), GetEnvironment().GetCompilerMode(), GetEnvironment().GetCacheLineCountMode()); output << "Results:" << std::endl; CsvTsv::CsvTableFormatter formatter(output); QueryInstrumentation::Data::FormatHeader(formatter); instrumentation.Format(formatter); } else { CHECK_NE(*GetEnvironment().GetOutputDir().c_str(), '\0') << "Output directory not set. " << "Please use the 'cd' command to set an " << "output directory"; output << "Processing queries from log at \"" << m_query << "\"" << std::endl; std::string const & filename = m_query; auto fileSystem = Factories::CreateFileSystem(); // TODO: Use environment file system auto queries = ReadLines(*fileSystem, filename.c_str()); const size_t c_threadCount = GetEnvironment().GetThreadCount(); const size_t c_iterations = 1; auto statistics = QueryRunner::Run(GetEnvironment().GetSimpleIndex(), GetEnvironment().GetOutputDir().c_str(), c_threadCount, queries, c_iterations, GetEnvironment().GetCompilerMode(), GetEnvironment().GetCacheLineCountMode()); output << "Results:" << std::endl; statistics.Print(output); // TODO: unify this with the fileManager that's passed into // QueryRunner::Run. auto outFileManager = Factories::CreateFileManager(GetEnvironment().GetOutputDir().c_str(), GetEnvironment().GetOutputDir().c_str(), GetEnvironment().GetOutputDir().c_str(), GetEnvironment().GetSimpleIndex().GetFileSystem()); auto outSummary = outFileManager->QuerySummaryStatistics().OpenForWrite(); statistics.Print(*outSummary); } }
void fly_to_analyse(char *path, char *config) { char *p = ReadLines(config); char *last=p; char *result2=NULL; char title[128],description[512],reference[512],match[128],relevance[512]; int result=0,sz=0; while(!result) switch (parse_eggs(&p, &last)) { case TITLE: sz = p - last; memset(title,0,127); snprintf(title,127,"%.*s", sz, last); // DEBUG("%s\n",title); strcpy(title,ClearStr(title,10)); break; case DESCRIPTION: sz = p - last; memset(description,0,511); snprintf(description,511,"%.*s", sz, last); strcpy(description,ClearStr(description,16)); break; case REFERENCE: sz = p - last - 1; memset(reference,0,511); snprintf(reference,511,"%.*s", sz, last); strcpy(reference,ClearStr(reference,14)); break; case RELEVANCE: sz = p - last; memset(relevance,0,511); snprintf(relevance,511,"%.*s", sz, last); strcpy(relevance,ClearStr(relevance,14)); break; /* TODO* fix bug when test first rule of egg file */ case MATCH: sz = p - last; memset(match,0,127); snprintf(match,127,"%.*s", sz, last); strcpy(match,ClearStr(match,10)); result2=Search_for(path,match); // TODO* need validate before print out if(strlen(result2)>8) { fprintf(stdout,"\n-------------------\n %sTitle:%s %s \n %sDescription:%s %s \n %sRelevance:%s %s \n %sReference:%s %s \n %sMatch:%s %s \n%s%s%s\n",YELLOW,LAST,title,YELLOW,LAST,description,YELLOW,LAST,relevance,YELLOW,LAST,reference,YELLOW,LAST,match,CYAN,result2,LAST); if(log_file != NULL) { // TODO* call one time write()... optimize WriteFile(log_file," Path: "); WriteFile(log_file,path); WriteFile(log_file,"\n Module: "); WriteFile(log_file,config); WriteFile(log_file,"\n Title: "); WriteFile(log_file,title); WriteFile(log_file,"\n Description: "); WriteFile(log_file,description); WriteFile(log_file,"\n reference: "); WriteFile(log_file,reference); WriteFile(log_file,"\n Match: "); WriteFile(log_file,match); WriteFile(log_file,"\n Result: \n"); WriteFile(log_file,result2); } } break; case END: result=1; break; } }
void Query::Execute() { std::ostream& output = GetEnvironment().GetOutputStream(); try { if (m_queryCommand == QueryOne) { output << "Processing query \"" << m_query << "\"" << std::endl; auto instrumentation = QueryRunner::Run(m_query.c_str(), GetEnvironment().GetSimpleIndex(), GetEnvironment().GetCompilerMode(), GetEnvironment().GetCacheLineCountMode()); output << "Results:" << std::endl; CsvTsv::CsvTableFormatter formatter(output); QueryInstrumentation::Data::FormatHeader(formatter); instrumentation.Format(formatter); } else if (m_queryCommand == QueryDocs) { output << "Processing query \"" << m_query << "\"" << std::endl; BitFunnel::QueryInstrumentation instrumentation; auto resultsBuffer = BitFunnel::ResultsBuffer(GetEnvironment().GetSimpleIndex().GetIngestor().GetDocumentCount()); auto streammap = BitFunnel::Factories::CreateStreamConfiguration(); auto queryEngine = BitFunnel::Factories::CreateQueryEngine(GetEnvironment().GetSimpleIndex(), *streammap); auto tree = queryEngine->Parse(m_query.c_str()); instrumentation.FinishParsing(); if (tree != nullptr) { queryEngine->Run(tree, instrumentation, resultsBuffer); } output << "Results:" << std::endl; CsvTsv::CsvTableFormatter formatter(output); QueryInstrumentation::Data::FormatHeader(formatter); instrumentation.GetData().Format(formatter); output << std::endl << "Document Ids" << std::endl; for (auto result : resultsBuffer) { output << result.GetHandle().GetDocId() << std::endl; } } else { CHECK_NE(*GetEnvironment().GetOutputDir().c_str(), '\0') << "Output directory not set. " << "Please use the 'cd' command to set an " << "output directory"; output << "Processing queries from log at \"" << m_query << "\"" << std::endl; std::string const & filename = m_query; auto fileSystem = Factories::CreateFileSystem(); // TODO: Use environment file system auto queries = ReadLines(*fileSystem, filename.c_str()); const size_t c_threadCount = GetEnvironment().GetThreadCount(); const size_t c_iterations = 1; auto statistics = QueryRunner::Run(GetEnvironment().GetSimpleIndex(), GetEnvironment().GetOutputDir().c_str(), c_threadCount, queries, c_iterations, GetEnvironment().GetCompilerMode(), GetEnvironment().GetCacheLineCountMode()); output << "Results:" << std::endl; statistics.Print(output); // TODO: unify this with the fileManager that's passed into // QueryRunner::Run. auto outFileManager = Factories::CreateFileManager(GetEnvironment().GetOutputDir().c_str(), GetEnvironment().GetOutputDir().c_str(), GetEnvironment().GetOutputDir().c_str(), GetEnvironment().GetSimpleIndex().GetFileSystem()); auto outSummary = outFileManager->QuerySummaryStatistics().OpenForWrite(); statistics.Print(*outSummary); } } catch (RecoverableError e) { output << "Error: " << e.what() << std::endl; } catch (Logging::CheckException e) { output << "Error: " << e.GetMessage().c_str() << std::endl; } }