Exemplo n.º 1
0
int main (int argc, char *argv[])
{
#ifndef DEBUG
    if (argc!=3)
        printf("txt2bmp converter\nusage: txt2bmp textfile bmpfile\n"), exit(1);
    AnsiString textfile(argv[1]);
    AnsiString bmpfile(argv[2]);
#else
    AnsiString textfile("1.txt");
    AnsiString bmpfile("1.bmp");
#endif
    convert(textfile, bmpfile);
    return 0;
}
Exemplo n.º 2
0
void MessageOutput::saveContent()
{
  KURL url=KFileDialog::getSaveURL(QDir::currentDirPath(),
    i18n("*.log|Log Files (*.log)\n*|All Files"), this, i18n("Save Log File"));
  if (url.isEmpty())
    return;

  QFileInfo fileinfo(url.path());
  if (fileinfo.exists() && KMessageBox::warningContinueCancel(0,
      i18n("<qt>File<br><b>%1</b><br>already exists. Overwrite it?</qt>")
      .arg(url.path()), QString::null, i18n("Overwrite")) == KMessageBox::Cancel)
    return;

  QFile file(url.path());
  if (!file.open(IO_WriteOnly)) {
     KMessageBox::error(0, i18n("<qt>Cannot save log file<br><b>%1</b></qt>")
         .arg(url.url()));
     return;
   }

   QTextStream textfile(&file);
   textfile << content();
   file.close();

}
Exemplo n.º 3
0
void PrintGeometry(TPZGeoMesh * gmesh){
    std::stringstream text_name;
    std::stringstream vtk_name;
    text_name   << "geometry" << ".txt";
    vtk_name    << "geometry" << ".vtk";
    std::ofstream textfile(text_name.str().c_str());
    gmesh->Print(textfile);
    std::ofstream vtkfile(vtk_name.str().c_str());
    TPZVTKGeoMesh::PrintGMeshVTK(gmesh, vtkfile, true);
}
MAPA::MAPA(char nombredefichero1[], char nombredefichero2[], char nombredefichero3[]){
    //Obtención de los datos del fichero
    Datos dato1,dato2;
    //info_ciudad info;
    int cuenta = 0;
    ifstream textfile(nombredefichero1);
    ifstream textfile2(nombredefichero2);
    ifstream textfile3(nombredefichero3);
    int a1, p,l,l1;
    int a2, k;
    int a3, predi;
    if (textfile.is_open() && textfile2.is_open() && textfile3.is_open()) {
        textfile >> (int&) a1; //lee el tamaño de la matriz1
        textfile2 >> (int&) a2; //lee el tamaño de la matriz2
        textfile3 >> (int&) a3; //lee el tamaño de la matriz3
        if (a1 == a2 && a2 == a3) {
            LISTA.resize(a1+1);
            //cout << "A:" << a1 << endl;
            numero_ciudades = a1;
            numero_caminos = 0;
            l1=1;
            for (int i = 1; i <= numero_ciudades; i++) {
                //cout << "------------NUEVA LÍNEA DE LA MATRIZ-------------" << endl;
                l = 0;
                for (int j = 0; j < numero_ciudades; j++) {
                    textfile >> (int&) p;
                    textfile2 >> (int&) k;
                    //cout << p << " ";
                    textfile3 >> (int&) predi;
                    LISTA[l1].prediccion.push_back(predi);
                    //cout << j;
                    if (p == 1) {
                        //cout <<endl << p << " = P" << endl;
                        
                        //cout << "J: " << j+1 << " " << endl;
                        LISTA[l1].a_que_ciudades_puede_ir.push_back(j+1);
                        LISTA[l1].kilometros.push_back(k);
                        LISTA[l1].posicion_en_la_matriz.push_back(j);
                        LISTA[l1].ciudad_padre = 0;
                        LISTA[l1].visitado = false;
                        cuenta++;
                        //cout << p << "  ";
                        l++;
                    }
                }
                //cout << endl;
                numero_caminos = numero_caminos + l;
                l1= l1+1;
            }
        }
Exemplo n.º 5
0
bool SceneXMLParser::loadTextFileIntoString( const std::string& filename, std::string& filecontents )
{
  // Attempt to open the text file for reading
  std::ifstream textfile(filename.c_str(),std::ifstream::in);
  if(!textfile) return false;

  // Read the entire file into a single string
  std::string line;
  while(getline(textfile,line)) filecontents.append(line);

  textfile.close();

  return true;
}
Exemplo n.º 6
0
void RefInterface::readConfigFile()
{

    QStringList stringlist;
    QFile textfile(":/Config.txt");
    QTextStream ts(&textfile);
    if(!textfile.open(QIODevice::ReadOnly))
    {
        //qDebug()<<"config file not opened";
    }
    else
    {
    while(true)
    {
        QString line = ts.readLine();
        if(line.isNull())
        {
            break;
        }
        else
        {
            stringlist.append(line);
        }
    }

    x0 = stringlist.at(0).toFloat();
    y0 = stringlist.at(1).toFloat();
    z0 = stringlist.at(2).toFloat();
    x1 = stringlist.at(3).toFloat();
    y1 = stringlist.at(4).toFloat();
    z1 = stringlist.at(5).toFloat();
    x2 = stringlist.at(6).toFloat();
    y2 = stringlist.at(7).toFloat();
    z2 = stringlist.at(8).toFloat();
    x3 = stringlist.at(9).toFloat();
    y3 = stringlist.at(10).toFloat();
    z3 = stringlist.at(11).toFloat();
    oldx = stringlist.at(12).toFloat();
    oldy = stringlist.at(13).toFloat();
    oldz = stringlist.at(14).toFloat();
    destNode = stringlist.at(15).toInt();
    radioPort.append(stringlist.at(16).toLocal8Bit());
    radioPort1.append(stringlist.at(17).toLocal8Bit());
    r0 = stringlist.at(18).toFloat();
    r1 = stringlist.at(19).toFloat();
    r2 = stringlist.at(20).toFloat();
    r3 = stringlist.at(21).toFloat();
    }
}
Exemplo n.º 7
0
void get_traffic_statistics(const char *whichiptables, int ipv6)
{
 char *str,*cmd;
 int downloadflag = 0;
 traffic_detected = 0;

 textfile(Pipe,str) *line,*lines=NULL;
 string(str,STRLEN);
 string(cmd,STRLEN);

 sprintf(cmd,"%s -L -v -x -n -t mangle", whichiptables);
 shell(cmd);
 input(str,STRLEN)
 {
  create(line,Pipe);
  line->str=str;
  string(str,STRLEN);
  append(line,lines);
 }
Exemplo n.º 8
0
std::vector<RWInstruction> Helper::readIntructionsFile(std::string filePath) {
        
    std::ifstream textfile(filePath);
    std::vector<RWInstruction> instructions;
    
    int cpuid; Address address; std::string read;
        
    while(textfile >> cpuid >> address >> read) {
        
        RWInstruction instruction = RWInstruction();
        
        instruction.address = address;
        instruction.cpuid = cpuid;
        if (read == "r")
            instruction.isRead = true;
        else instruction.isRead = false;
        
        instructions.push_back(instruction);
    }
    
    return instructions;
}
//---------------------------------------------------------------
// CNativeMmsUtility::readFileIntoBuffer
// @see header
//---------------------------------------------------------------
void CNativeMmsUtility::readFileIntoBuffer(const QString& filepath,
                                           QString& returnbuf)
{
#ifdef _DEBUG_TRACES_
    qDebug() << " Enter CNativeMmsUtility::readFileIntoBuffer";
#endif

    QFile textfile(filepath);
    if (textfile.open(QIODevice::ReadOnly))
    {
        while (!textfile.atEnd())
        {
            QByteArray line = textfile.readLine();
            returnbuf.append(line);
        }
    }

#ifdef _DEBUG_TRACES_
    qDebug() << " Exit CNativeMmsUtility::readFileIntoBuffer";
#endif

    return;
}
Exemplo n.º 10
0
/**************************************************************
 * *  This main function creates a vector of randomly generated integers
 * *  for use in testing the implementations of Algorithms 1-4. The first part measures
 * *  the running time in ms for each Algorithm for display. The second part tests
 * *  input output by reading input from a specified text file, running each Algorithm
 * *  on this input, and writing the results to another specified text file.
 * ***************************************************************/
int main(int argc, char* argv[]){	

	std::string filename;
	std::string outputfilename;


	/* The first argument (argc) is the number of elements in the array so we should have two elements the program name and file name 
	Credit: http://www.site.uottawa.ca/~lucia/courses/2131-05/labs/Lab3/CommandLineArguments.html
	*/
    if(argc != 2)
    {
        std::cout << "Please enter an input filename." << std::endl << std::endl;
        exit(1);
    }
	/* which is the second argument (argv). The second argument is always an array of char*, */
    else
    {      
        filename = std::string(argv[1]);
		std::string tempoutputfilename = std::string(argv[1]);
		//http://www.cplusplus.com/reference/string/string/length/
		int strsize = tempoutputfilename.length() - 4;
		/* http://www.cplusplus.com/reference/string/string/operator+/ 
		http://www.cplusplus.com/reference/string/string/substr/ */
		outputfilename = (tempoutputfilename.substr(0, strsize)) + "change.txt";
		std::cout << outputfilename << std::endl;
	}
	//cout << filename << endl;
	/* Stream class provided by C++ to read from files
	Credit: http://www.cplusplus.com/doc/tutorial/files/*/
	/* In order to open a file with a stream object we use its member function open
     * http://stackoverflow.com/questions/16552753/no-matching-function-ifstream-open */
        std::ifstream textfile(filename);
	/* To check if a file stream was successful opening a file, you can do it by calling to member is_open
	Credit: http://www.cplusplus.com/doc/tutorial/files/*/
    if(!textfile.is_open())
    {
        std::cout << "The file could not be opened." << std::endl;
        textfile.close();
        exit(1);
    }
	/* Call function to put first alternating lines as the coin set input and the second alternating lines as total change V */
    std::vector< std::vector<int> > coinsetinput;
    std::vector<int> changevalueV;
    getinput( textfile, coinsetinput, changevalueV );
    textfile.close();

	/* Stream class to write on files
	Credit: http://www.cplusplus.com/doc/tutorial/files/*/	
    /*http://stackoverflow.com/questions/16552753/no-matching-function-ifstream-open*/
    std::ofstream textfile2(outputfilename);

    if(!textfile2.is_open())
    {
        std::cout << "Cannot open for writing. Check the permissions of the directory." << std::endl;
        textfile2.close();
        exit(1);
    }
	 /*Display a babel for brute force algorithm time trial 
    std::cout << "Testing changeslow...." << std::endl;
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        // Run brute force algorithm on input numbers from first to last element 
		std::vector<int> coinCount;
		runtimetrial( changeslow, coinsetinput.at(i), changevalueV.at(i), coinCount );
    }
	// Display a babel for greedy algorithm time trial 
    std::cout << "Testing changegreedy...." << std::endl;
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        // Run greedy algorithm on input numbers from first to last element 
		std::vector<int> coinCount;
        runtimetrial( changegreedy, coinsetinput.at(i), changevalueV.at(i), coinCount);
    }
    // Display a babel for dynamic programming algorithm time trial 
    std::cout << "Testing changedp...." << std::endl;
    //for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
         Run greedy algorithm on input numbers from first to last element 
		
    }*/
	/* Call function to output is to be written to text file 
    textfile2 << "Brute Force \n\n";
	 // Run changeslow algorithm on input numbers
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        std::vector<int> coinCount;
        int minCoins = changeslow( coinsetinput.at(i), changevalueV.at(i), coinCount );
        writeResults( textfile2, coinCount, minCoins );
    }
	// Call function to output is to be written to text file 
    textfile2 << "Greedy\n\n";
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        std::vector<int> coinCount;
        int minCoins = changegreedy(coinsetinput.at(i), changevalueV.at(i), coinCount);
        writeResults( textfile2, coinCount, minCoins );
    }
	// Call function to output is to be written to text file */
    textfile2 << "Dynamic Programming\n\n";
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
		if(!coinsetinput.at(i).empty()){
			printf("\n\n%d Results %d\n", i, i);
			struct coinChange result; 
            std::vector<int> curVec ( coinsetinput.at(i) );            
            Changedp::dpChange(curVec, changevalueV.at(i), result);	
			for(unsigned int y = 0; y<coinsetinput.at(i).size(); ++y){
				printf("%d\t", coinsetinput.at(i).at(y));
			}
			printf("\nmin coins = %d\tSumVal = %d\tResult array\n", result.coins, changevalueV.at(i));
			for(unsigned int y = 0; y<result.resultVec.size(); ++y){
				printf("%d\t", result.resultVec.at(y));
			}		

			writeResults( textfile2, result.resultVec, result.coins );
		}
	}
    textfile2.close();	
}
Exemplo n.º 11
0
// read system and user mailcaps and other files
void wxMimeTypesManagerImpl::Initialize(int mailcapStyles,
                                        const wxString& sExtraDir)
{
#ifdef __VMS
    // XDG tables are never installed on OpenVMS
    return;
#else

    // Read MIME type - extension associations
    LoadXDGGlobs( "/usr/share/mime/globs" );
    LoadXDGGlobs( "/usr/local/share/mime/globs" );

    // Load desktop files for XDG, and then override them with the defaults.
    // We will override them one desktop file at a time, rather
    // than one mime type at a time, but it should be a reasonable
    // heuristic.
    {
        wxString xdgDataHome = wxGetenv("XDG_DATA_HOME");
        if ( xdgDataHome.empty() )
            xdgDataHome = wxGetHomeDir() + "/.local/share";
        wxString xdgDataDirs = wxGetenv("XDG_DATA_DIRS");
        if ( xdgDataDirs.empty() )
        {
            xdgDataDirs = "/usr/local/share:/usr/share";
            if (mailcapStyles & wxMAILCAP_GNOME)
                xdgDataDirs += ":/usr/share/gnome:/opt/gnome/share";
            if (mailcapStyles & wxMAILCAP_KDE)
                xdgDataDirs += ":/usr/share/kde3:/opt/kde3/share";
        }
        if ( !sExtraDir.empty() )
        {
           xdgDataDirs += ':';
           xdgDataDirs += sExtraDir;
        }

        wxArrayString dirs;
        wxStringTokenizer tokenizer(xdgDataDirs, ":");
        while ( tokenizer.HasMoreTokens() )
        {
            wxString p = tokenizer.GetNextToken();
            dirs.Add(p);
        }
        dirs.insert(dirs.begin(), xdgDataHome);

        wxString defaultsList;
        size_t i;
        for (i = 0; i < dirs.GetCount(); i++)
        {
            wxString f = dirs[i];
            if (f.Last() != '/') f += '/';
            f += "applications/defaults.list";
            if (wxFileExists(f))
            {
                defaultsList = f;
                break;
            }
        }

        // Load application files and associate them to corresponding mime types.
        size_t nDirs = dirs.GetCount();
        for (size_t nDir = 0; nDir < nDirs; nDir++)
        {
            wxString dirStr = dirs[nDir];
            if (dirStr.Last() != '/') dirStr += '/';
            dirStr += "applications";
            LoadXDGAppsFilesFromDir(dirStr);
        }

        if (!defaultsList.IsEmpty())
        {
            wxArrayString deskTopFilesSeen;

            wxMimeTextFile textfile(defaultsList);
            if ( textfile.Open() )
            {
                int nIndex = textfile.pIndexOf( wxT("[Default Applications]") );
                if (nIndex != wxNOT_FOUND)
                {
                    for (i = nIndex+1; i < textfile.GetLineCount(); i++)
                    {
                        if (textfile.GetLine(i).Find(wxT("=")) != wxNOT_FOUND)
                        {
                            wxString desktopFile = textfile.GetCmd(i);

                            if (deskTopFilesSeen.Index(desktopFile) == wxNOT_FOUND)
                            {
                                deskTopFilesSeen.Add(desktopFile);
                                size_t j;
                                for (j = 0; j < dirs.GetCount(); j++)
                                {
                                    wxString desktopPath = dirs[j];
                                    if (desktopPath.Last() != '/') desktopPath += '/';
                                    desktopPath += "applications/";
                                    desktopPath += desktopFile;

                                    if (wxFileExists(desktopPath))
                                        LoadXDGApp(desktopPath);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
#endif
}