Exemplo n.º 1
0
//jump to line n in functions
bool MapBuilder::jumpToLine(int n, ifstream &lookFile, ofstream &putFile){ 
   bool newLine = false;   
   
   lookFile.seekg(ios_base::beg); //set cursor to the beginning
   int counter = 0;
   while((n < counter) && (!file.eof())){ //search for n new lines
      if(findsNLChar(lookFile)){ //if you find a new line
         counter++;         //count that
      }
   }
   
   if(!lookFile.eof()){ //if we got to the end before making n lines
      return false; //we never made it
   }
   
   putFile.seekp(lookFile.tellg()); //put the putting pointer to where looking pointer is
   return true;     //successfully got to line n
}
Exemplo n.º 2
0
bool
csv_fwrite (ofstream &fp, string src)
{
  if (fp == NULL || fp.eof())
    return false;

  fp << '"';

  for (unsigned int i = 0; i < src.length(); i++) {
    if (src[i] == '"') {
      fp << '"';
    }
    fp << src[i];
  }

  fp << '"';

  return true;
}
Exemplo n.º 3
0
int KiCadSCH::patchFile(ofstream &oFile)
{
    string iline, oline, last_oline;
    modiFile_t currentpatch;
    int line_n;
    unsigned i;
    unsigned olineNbr = 0;

    iSCHfile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    oFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);

    try{
        last_oline = "";
        for(line_n=0; true; line_n++){
            getline(iSCHfile, iline);
            oline = iline;
            currentpatch.add = false;
            currentpatch.del = false;
            currentpatch.line = "";
            currentpatch.lineNbr = 0;
            for(i=0;i<patchvec.size();i++){
                if(line_n == patchvec[i].lineNbr){
                    currentpatch = patchvec[i];
                    patchvec[i].prevline = last_oline;
                    if(currentpatch.add){
                        oFile << currentpatch.line << endl;
                        olineNbr++;
                        patchvec[i].olineNbr = olineNbr;
                    }
                }
            }
            if(!currentpatch.del){
                oFile << oline << endl;
                last_oline = oline;
                olineNbr++;
                if(patchvec.size()>i){ // if patchvec is empty
                    patchvec[i].olineNbr = olineNbr;
                }
            }else{
                if(patchvec.size()<i) patchvec[i].deletedline = oline;
            }
        }
    }
    catch(std::fstream::failure e){
        if(iSCHfile.bad()) return -1;
        if(oFile.bad()) return -2;
        if(iSCHfile.fail()) return -1;
        if(oFile.fail()) return -2;
        if(iSCHfile.eof()){
            iSCHfile.clear();
            iSCHfile.seekg(0, ios::beg);
            return 0;
        }
        if(oFile.eof()) {
            oFile.clear();
            return -2;
        }
        return -255;
    }
    return 0;
}