//-----------<Search particular text in files>-------------- bool CTextSearch::searchFile(std::string filename) { FileSystem::File sourcefile(filename); sourcefile.open(FileSystem::File::in); if (!sourcefile.isGood()) { std::lock_guard<std::mutex> l(ioLock); std::cout << "\n Can't open file " << sourcefile.name(); std::cout << "\n Here's what the program can't find:\n " << FileSystem::Path::getFullFileSpec(sourcefile.name()); return false; } while (sourcefile.isGood()) { if (!sourcefile.isGood()) break; std::string buffer = sourcefile.getLine(); unsigned int loc = buffer.find(keyWords); if (loc != std::string::npos) { sourcefile.close(); return true; } } sourcefile.close(); return false; }
QMap<QString, StelLocation> StelLocationMgr::loadCitiesBin(const QString& fileName) const { QMap<QString, StelLocation> res; QString cityDataPath; try { cityDataPath = StelFileMgr::findFile(fileName); } catch (std::runtime_error& e) { return res; } QFile sourcefile(cityDataPath); if (!sourcefile.open(QIODevice::ReadOnly)) { qWarning() << "ERROR: Could not open location data file: " << cityDataPath; return res; } if (fileName.endsWith(".gz")) { QIODevice* d = KFilterDev::device(&sourcefile, "application/x-gzip", false); d->open(QIODevice::ReadOnly); QDataStream in(d); in.setVersion(QDataStream::Qt_4_6); in >> res; d->close(); delete d; return res; }
int Parser::add_file(std::string _filename) { if (!Lexer::getInstance().add_file(_filename)) { return 0; } tree.define_root(sourcefile()); tree.print_preorder(); }
void ASTNode::warning (const char *format, ...) { va_list ap; va_start (ap, format); std::string errmsg = format ? Strutil::vformat (format, ap) : "unknown warning"; va_end (ap); m_compiler->warning (sourcefile(), sourceline(), "%s", errmsg.c_str()); }
void ASTNode::error (const char *format, ...) { va_list ap; va_start (ap, format); std::string errmsg = format ? Strutil::vformat (format, ap) : "syntax error"; va_end (ap); m_compiler->error (sourcefile(), sourceline(), "%s", errmsg.c_str()); }
void GenesisCopyWindow::Copy(const char *filename, const char *destination, const char *destfilename) //////////////////////////////////////////////////////////////////////// { BEntry sourcefile(filename); BString text; if (sourcefile.InitCheck()==B_OK) { /* BString text; text.SetTo(""); text << filename << "\n" << destination; BAlert *myAlert = new BAlert("Copy debug",text.String(),"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); myAlert->Go(); */ if (sourcefile.IsDirectory()) { if (IsRecursiveCopy(filename, destination)) { BString text; text << "Recursive copy not allowed.\nPlease check the destination folder."; BAlert *myAlert = new BAlert("Copy",text.String(),"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); myAlert->Go(); Close(); kill_thread(m_CopyThread); } CopyDirectory(filename, destination, destfilename); } else if (sourcefile.IsSymLink()) CopyLink(filename,destination, destfilename); else CopyFile(filename, destination, destfilename); } else if (!m_SkipAllCopyError) { text << "Error while initializing file:\n\n" << filename; BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Skip all","Skip",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT); myAlert->SetShortcut(0, B_ESCAPE); switch (myAlert->Go()) { case 0: Close(); kill_thread(m_CopyThread); break; case 1: m_SkipAllCopyError = true; break; } } }
void CK_FileMerger::on_btnStart_clicked() { QFile sourcefile(this); QFile targetfile(ui->lineTarget->text()); targetfile.open(QIODevice::WriteOnly|QIODevice::Text); QTextStream out(&targetfile); out.setCodec("UTF-8"); //자바스타일 이터레이터 선언 QStringListIterator itrFiles(strlstSourcefileNames); while (itrFiles.hasNext()) { sourcefile.setFileName(itrFiles.next().toLocal8Bit().constData()); ui->lstSource->addItem(sourcefile.fileName()); if(sourcefile.open(QFile::ReadOnly|QFile::Text)) { //한글사용을 위해 fromLocal8Bit함수 사용 QString text = QString::fromLocal8Bit(sourcefile.readAll()); //엔터키 정리 text = text.simplified(); //title list를 뽑아내는 함수 titleExtract() QStringList* strlstTitles; strlstTitles = titleExtract(text); //body list를 뽑아내는 함수 bodyExtract(), 나중에 <header>...</header>는 제거한다. QStringList* strlstBodies; strlstBodies = bodyExtract(text); for(int i=0; i<strlstTitles->length();++i) { QString txt = strlstTitles->at(i); if(!txt.isEmpty()){ ui->txtSource->setPlainText(txt+" is being processed."); out<<txt<<"\t"<<strlstBodies->at(1)<<"\n"; ui->txtSource->appendPlainText(txt+" is compiled over."); } } ui->lineSource->setText(sourcefile.fileName()); } sourcefile.close(); } //ui->txtSource->appendPlainText("\r\n"); out<<"\n"; targetfile.close(); }
Source::Source(SpatialMesh& Space, AngularMesh& Angle) { // TODO Auto-generated constructor stub RHS.resize(Angle.ns); q.resize(Angle.ns); for (register int i = 0; i < Angle.ns; i++){ RHS[i].resize(Space.nt); q[i].resize(Space.ne); for (register int j = 0; j < Space.nt; j++){ RHS[i][j].resize(3); } for (register int j = 0; j < Space.ne; j++){ q[i][j].resize(2); } } // Assembly light source // Variables double temp; DMATRIX location; DVECTOR intensity; // Main body std::fstream sourcefile("./source.txt", std::ios_base::in); sourcefile >> temp; lumin.type = (int) temp; if (lumin.type != 0){ sourcefile >> temp; lumin.n = (int) temp; lumin.i.resize(lumin.n); if (lumin.type == 3){ // isotropic nodal source everywhere for (int j = 0; j < lumin.n; j++ ){ lumin.i[j].resize(3); for ( int k = 0 ; k < 3; k++){ sourcefile >> lumin.i[j][k]; } } sourcefile.close(); } else { // type is 1 or 2 if (lumin.type == 1){
LocationMap StelLocationMgr::loadCitiesBin(const QString& fileName) { QMap<QString, StelLocation> res; QString cityDataPath = StelFileMgr::findFile(fileName); if (cityDataPath.isEmpty()) return res; QFile sourcefile(cityDataPath); if (!sourcefile.open(QIODevice::ReadOnly)) { qWarning() << "ERROR: Could not open location data file: " << QDir::toNativeSeparators(cityDataPath); return res; } if (fileName.endsWith(".gz")) { QDataStream in(StelUtils::uncompress(sourcefile.readAll())); in.setVersion(QDataStream::Qt_4_6); in >> res; return res; }
int main(int argc, char *argv[]) { QString sourcefilename; QString targetfilename; QCoreApplication app( argc, argv ); for ( int i = 1; i < argc; ++i ) { if ( strcmp( argv[ i ], "-o" ) != 0 ) continue; targetfilename = QString(argv[i+1]); sourcefilename = QString(argv[i+2]); qDebug() << "Source: " << sourcefilename; qDebug() << "Target: " << targetfilename; QFile sourcefile( sourcefilename ); sourcefile.open( QIODevice::ReadOnly ); // Read the data serialized from the file. QTextStream sourcestream( &sourcefile ); sourcestream.setCodec("UTF-8"); QFile targetfile( targetfilename ); targetfile.open( QIODevice::ReadWrite ); QTextStream targetstream( &targetfile ); targetstream.setCodec("UTF-8"); // gzFile gzDoc = gzopen( targetfilename.toLatin1(), "w"); // QTextStream targetstream( new QString() ); targetstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" << "<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n" << "<Document> \n"; targetstream << " <Schema name=\"MarblePlacemark\" parent=\"Placemark\"> \n"; targetstream << " <SimpleField name=\"pop\" type=\"int\"></SimpleField> \n"; targetstream << " <SimpleField name=\"role\" type=\"string\"></SimpleField> \n"; targetstream << " </Schema> \n"; targetstream << "\n"; QString rawline; QString nameString; QString latString; QString lonString; QString popString; QString roleString; QString description; float lat; float lon; int population; QStringList splitline; while ( !sourcestream.atEnd() ) { rawline = sourcestream.readLine(); // if ( !rawline.startsWith("\"E\"|\"m\"|\"" ) ) { if ( !rawline.startsWith("\"V\"|\"V\"|\"" ) ) { continue; } rawline = rawline.replace( "\"|", "|" ); rawline = rawline.replace( "|\"", "|" ); if ( rawline.startsWith('\"') && rawline.endsWith('\"') ) { rawline = rawline.left( rawline.length() - 1 ); rawline = rawline.right( rawline.length() - 2 ); } splitline = rawline.split('|'); nameString = splitline[2]; latString = splitline[3]; lonString = splitline[4]; popString = splitline[10]; roleString = splitline[18]; description = splitline[19]; // if ( roleString == "SF" ) continue; QString marbleRoleString = 'o'; if ( roleString == "AA" || roleString == "SF" ) marbleRoleString = "c"; if ( roleString == "ME" || roleString == "OC" || roleString == "LC" || roleString == "SI" ) marbleRoleString = "a"; if ( roleString == "MO" ) marbleRoleString = "m"; if ( roleString == "VA" ) marbleRoleString = "v"; population = (int) ( 1000.0 * popString.toFloat() ); lon = lonString.toFloat(); if ( lon > 180.0 ) lon = lon - 360.0; if ( rawline.startsWith("\"M\"|\"M\"|\"" ) || rawline.startsWith("\"V\"|\"V\"|\"" ) ) { lon = -lon; } lat = latString.toFloat(); description = description.remove('"'); targetstream << " <MarblePlacemark> \n"; targetstream << " <name>" << escapeXml( nameString ) << "</name> \n"; targetstream << " <role>" << escapeXml( marbleRoleString ) << "</role> \n"; targetstream << " <pop>" << escapeXml( QString::number( population ) ) << "</pop> \n"; targetstream << " <description>" << escapeXml( description ) << "</description> \n"; targetstream << " <Point>\n" << " <coordinates>" << escapeXml( QString::number( lon ) ) << "," << escapeXml( QString::number( lat ) ) << "</coordinates> \n" << " </Point> \n"; targetstream << " </MarblePlacemark> \n"; } targetstream << "</Document> \n" << "</kml> \n"; qDebug("..."); sourcefile.close(); targetfile.close(); qDebug("Finished!"); return 0; } qDebug(" iau2kml -o targetfile sourcefile"); app.exit(); }
//: Returns OS_SUCCESS if file copied ok. // see OsFile for more return codes OsStatus OsFileSystem::copy(const OsPath& source, const OsPath& dest) { OsFile sourcefile(source); return sourcefile.copy(dest); }
int main(int argc, char *argv[]) { QCoreApplication app( argc, argv ); for ( int i = 1; i < argc; ++i ) { if ( strcmp( argv[ i ], "-o" ) != 0 ) continue; const QString targetfilename = QString( argv[i+1] ); const QString sourcefilename = QString( argv[i+2] ); const QString supportfilename = QString( argv[i+3] ); const QString timezonefilename = QString( argv[i+4] ); qDebug() << "Source: " << sourcefilename; qDebug() << "Support: " << supportfilename; qDebug() << "Target: " << targetfilename; qDebug() << "Timezone: " << timezonefilename; QFile sourcefile( sourcefilename ); sourcefile.open( QIODevice::ReadOnly ); // Read the data serialized from the file. QTextStream sourcestream( &sourcefile ); sourcestream.setCodec("UTF-8"); QFile targetfile( targetfilename ); targetfile.open( QIODevice::WriteOnly ); QTextStream targetstream( &targetfile ); targetstream.setCodec("UTF-8"); QFile supportfile( supportfilename ); supportfile.open( QIODevice::ReadOnly ); QTextStream supportstream( &supportfile ); supportstream.setCodec("UTF-8"); QFile timezonefile( timezonefilename ); timezonefile.open( QIODevice::ReadOnly ); QTextStream timezonestream( &timezonefile ); timezonestream.setCodec("UTF-8"); // gzFile gzDoc = gzopen( targetfilename.toLatin1(), "w"); // QTextStream targetstream( new QString() ); targetstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" << "<kml xmlns=\"http://earth.google.com/kml/2.1\"> \n" << "<Document> \n"; QString state; QString gmt; QString dst; while ( !sourcestream.atEnd() ) { const QString rawline = sourcestream.readLine(); const QStringList splitline = rawline.split('\t'); const QString name = splitline[1]; const QString latstring = splitline[4]; const QString lngstring = splitline[5]; const QString role = splitline[7]; const QString country = splitline[8]; const QString statecode = splitline[10]; const QString popstring = splitline[14]; const QString elestring = splitline[16]; const QString timezone = splitline[17]; supportstream.seek(0); while ( !supportstream.atEnd() ) { const QString supportrawline = supportstream.readLine(); const QStringList supportsplitline = supportrawline.split('\t'); if(supportsplitline[0] == (country + '.' +statecode)) { state = supportsplitline[1]; break; } } timezonestream.seek(0); timezonestream.readLine(); while ( !timezonestream.atEnd() ) { const QString timezonerawline = timezonestream.readLine(); const QStringList timezonesplitline = timezonerawline.split('\t'); if( timezonesplitline[0] == timezone ) { gmt = timezonesplitline[1]; dst = timezonesplitline[2]; break; } } const int gmtoffset = ( int ) ( gmt.toFloat() * 100 ); const int dstoffset = ( int ) ( dst.toFloat() * 100 ) - gmtoffset; if(role != "PPLX") { targetstream << " <Placemark> \n"; targetstream << " <name>" << escapeXml( name ) << "</name> \n"; targetstream << " <state>" << escapeXml( state ) << "</state> \n"; targetstream << " <CountryNameCode>" << escapeXml( country.toUpper() ) << "</CountryNameCode>\n"; targetstream << " <role>" << escapeXml( role ) << "</role> \n"; targetstream << " <pop>" << escapeXml( popstring ) << "</pop> \n"; targetstream << " <Point>\n" << " <coordinates>" << escapeXml( lngstring ) << "," << escapeXml( latstring ) << "," << escapeXml( elestring ) << "</coordinates> \n" << " </Point> \n"; targetstream << " <ExtendedData>\n" << " <Data name=\"gmt\">\n" << " <value>" << escapeXml( QString::number( gmtoffset ) ) << "</value>\n" << " </Data>\n"; if( dstoffset ) { targetstream << " <Data name=\"dst\">\n" << " <value>" << escapeXml( QString::number( dstoffset) ) << "</value>\n" << " </Data>\n"; } targetstream << " </ExtendedData>\n"; targetstream << " </Placemark> \n"; } } targetstream << "</Document> \n" << "</kml> \n"; qDebug("Putting"); // gzputs( gzDoc, targetstream.readAll().toUtf8() ); // gzclose( gzDoc ); sourcefile.close(); targetfile.close(); supportfile.close(); timezonefile.close(); qDebug("Finished!"); return 0; } qDebug(" asc2kml -o targetfile sourcefile supporfile timezonefile"); app.exit(); }
void FileSignAndEncryption::on_okButton2_clicked() { ui->warningLabel2->setText(""); if (ui->sourceFileEdit2->text().startsWith("~/") || ui->destinationFileEdit2->text().startsWith("~/")) { ui->warningLabel2->setText("Seul les chemins absolus sont autorisés."); return; } if (ui->sourceFileEdit2->text() == ui->destinationFileEdit2->text()) { ui->warningLabel2->setText("Vous ne pouvez pas utiliser le même fichier source et destination."); return; } QFile sourcefile(ui->sourceFileEdit2->text()); if (!sourcefile.exists()) { ui->warningLabel2->setText("Le fichier source n'existe pas."); return; } QFileInfo sourceFileInfo(sourcefile); if (!sourceFileInfo.isReadable()) { ui->warningLabel2->setText("Vous n'avez pas les droits de lecture sur le fichier source."); return; } QFile destinationfile(ui->destinationFileEdit2->text()); if (destinationfile.exists()) { if (!destinationfile.remove()) { ui->warningLabel2->setText("Impossible d'écraser le fichier existant. Veuillez modifier la destination."); return; } } QFileInfo destinationFileInfo(destinationfile); QFileInfo destinationDirInfo(destinationFileInfo.absoluteDir().path()); if (!destinationDirInfo.isWritable()) { ui->warningLabel2->setText("Vous n'avez pas les droits d'écriture sur le dossier destination."); return; } // On récupère l'indice des lignes selectionnées QModelIndexList selectedIndex = ui->tableWidgetRecipient2->selectionModel()->selectedIndexes(); QList<int> rowIndexes; for (QModelIndex index : selectedIndex) { if (!rowIndexes.contains(index.row())) { rowIndexes.append(index.row()); } } // On récupère l'indice des lignes selectionnées pour le signataire QModelIndexList selectedIndexSign = ui->tableWidgetSign->selectionModel()->selectedIndexes(); QList<int> rowIndexesSign; for (QModelIndex index : selectedIndexSign) { if (!rowIndexesSign.contains(index.row())) { rowIndexesSign.append(index.row()); } } if (rowIndexes.count() == 0) { ui->warningLabel2->setText("Vous devez sélectionner au moins un destinaire."); return; } if (rowIndexesSign.count() == 0) { ui->warningLabel2->setText("Vous devez sélectionner un signataire."); return; } /* Utilisé pour paramétré les intéractions car gpg est tellement * intelligent qu'il les demandes dans l'ordre inverse pour le cas anonyme */ QList<int> reverseRowIndexes; reverseRowIndexes.reserve(rowIndexes.size()); std::reverse_copy(rowIndexes.begin(), rowIndexes.end(), std::back_inserter(reverseRowIndexes)); QStringList opt; opt << "--command-fd=0" << "--status-fd=1" << "-a" << "--sign" << "--default-key " + ui->tableWidgetSign->item(rowIndexesSign[0], 0)->text() << "--output" << ui->destinationFileEdit2->text(); QString cmd = "-e"; QStringList arg; arg << ui->sourceFileEdit2->text(); QStringList interactions; if (ui->anonymousCheckBox->isChecked()) { for (int i : rowIndexes) { opt << "-R \"" + ui->tableWidgetRecipient2->item(i, 0)->text() + " <" + ui->tableWidgetRecipient2->item(i, 1)->text() + ">\""; } for (int i : reverseRowIndexes) { if (ui->tableWidgetRecipient2->item(i, 3)->text() == GpgObject::validityToStr(VALIDITY_NO_VALUE) || ui->tableWidgetRecipient2->item(i, 3)->text() == GpgObject::validityToStr(VALIDITY_UNDEFINED)) { interactions << "y"; } } } else { for (int i : rowIndexes) { interactions << ui->tableWidgetRecipient2->item(i, 0)->text() + " <" + ui->tableWidgetRecipient2->item(i, 1)->text() + ">"; if (ui->tableWidgetRecipient2->item(i, 3)->text() == GpgObject::validityToStr(VALIDITY_NO_VALUE) || ui->tableWidgetRecipient2->item(i, 3)->text() == GpgObject::validityToStr(VALIDITY_UNDEFINED)) { interactions << "y"; } } interactions << ""; } Action action(cmd, arg, opt, interactions); m_manager->setAction(action); connect(m_manager, &GPGManager::finished, this, &FileSignAndEncryption::onEncryptionCompleted); m_manager->execute(); }
//: Returns OS_SUCCESS if file copied ok. // see OsFile for more return codes OsStatus OsFileSystemWnt::copy(const OsPathWnt& source, const OsPathWnt& dest) { OsFileWnt sourcefile(source); return sourcefile.copy(dest); }