Beispiel #1
0
bool SaveFile::open(OpenMode flags)
{
    QFile ofi(m_finalFileName);
    // Check whether the existing file is writable
    if (ofi.exists() && !ofi.open(QIODevice::ReadWrite)) {
        setErrorString(ofi.errorString());
        return false;
    }

    setAutoRemove(false);
    setFileTemplate(m_finalFileName);
    if (!QTemporaryFile::open(flags))
        return false;

    m_finalized = false; // needs clean up in the end
    if (ofi.exists()) {
        setPermissions(ofi.permissions()); // Ignore errors
    } else {
        Permissions permAll = QFile::ReadOwner
                | QFile::ReadGroup
                | QFile::ReadOther
                | QFile::WriteOwner
                | QFile::WriteGroup
                | QFile::WriteOther;

        // set permissions with respect to the current umask
        setPermissions(permAll & ~m_umask);
    }

    return true;
}
Beispiel #2
0
void HWDrawInfo::DispatchRenderHacks()
{
	TMap<int, gl_subsectorrendernode*>::Pair *pair;
	TMap<int, gl_floodrendernode*>::Pair *fpair;
	TMap<int, gl_subsectorrendernode*>::Iterator ofi(otherFloorPlanes);
	GLFlat glflat;
	glflat.section = nullptr;
	while (ofi.NextPair(pair))
	{
		auto sec = hw_FakeFlat(&Level->sectors[pair->Key], in_area, false);
		glflat.ProcessSector(this, sec, SSRF_RENDERFLOOR | SSRF_PLANEHACK);
	}

	TMap<int, gl_subsectorrendernode*>::Iterator oci(otherCeilingPlanes);
	while (oci.NextPair(pair))
	{
		auto sec = hw_FakeFlat(&Level->sectors[pair->Key], in_area, false);
		glflat.ProcessSector(this, sec, SSRF_RENDERCEILING | SSRF_PLANEHACK);
	}

	TMap<int, gl_floodrendernode*>::Iterator ffi(floodFloorSegs);
	while (ffi.NextPair(fpair))
	{
		auto sec = hw_FakeFlat(&Level->sectors[fpair->Key], in_area, false);
		glflat.ProcessSector(this, sec, SSRF_RENDERFLOOR | SSRF_FLOODHACK);
	}

	TMap<int, gl_floodrendernode*>::Iterator fci(floodCeilingSegs);
	while (fci.NextPair(fpair))
	{
		auto sec = hw_FakeFlat(&Level->sectors[fpair->Key], in_area, false);
		glflat.ProcessSector(this, sec, SSRF_RENDERCEILING | SSRF_FLOODHACK);
	}
}
Beispiel #3
0
void main()
{
	fstream ifile,ofile;
	settings u,t;
	char ch,user1[20],pass1[20];
	int a=1,b,c,d,e;
again:
	int i = mainmenu();
	switch(i)
	{
case 1:
	{
newuser:
		/* adding a user */
		clrscr();
	ofile.open("settings.dat",ios::binary|ios::out|ios::app);
	u.getuser();
	if(u.usercheck()==1){cout<<"\n Sorry  User already exists!returning to main menu...";ofile.close();getch();goto newuser;}
	ofile.write((char*)&u,sizeof(u));
	ofile.close();
	cout<<"\n User added.press m to return to main menu ";
	cin>>ch;
	if(ch == 'm')
	goto again;
	break;
	}
case 2:
{
	/* searching for user */
	clrscr();
	gotoxy(30,15);cout<<" Enter username:"******"settings.dat",ios::binary | ios::in);
	while(!ifile.eof())
	{
	ifile.read((char*)&u,sizeof(u));
	if(strcmp(u.username,user1) == 0)
	{a=0;break;}}
	if(a==0) {gotoxy(30,17); cout<<user1;}
	else {gotoxy(30,17);cout<<"\n not found";}
	ifile.close();
	cout<<"\n Press m to return to main menu";
	cin>>ch;
	if(ch=='m')
	goto again;
}
deluser:
case 3:
{	/* deleting user */
	clrscr();
	gotoxy(20,13);cout<<"\n Entet details of the user to delete: ";
	t.getuser();
	if(t.usercheck()==0){cout<<"\n user not found"; getch();goto again;}
	ifstream ifi("settings.dat",ios::binary);
	ofstream ofi("newsettings.dat",ios::binary);
	while(!ifi.eof())
	{
	ifi.read((char*)&u,sizeof(u));
	if(strcmp(t.username,u.username)!=0)
		ofi.write((char*)&u,sizeof(u));
	}
	ifi.close();
	ofi.close();
	remove("settings.dat");
	rename("newsettings.dat","settings.dat");
	cout<<"\n user deleted.. press m to return to main menu";
	cin>>ch;
	if(ch=='m')
	goto again;
	break;

}

case 4:
{       clrscr();
	gotoxy(30,10);cout<<" the existing users :";
	ifstream file("settings.dat",ios::binary);
	if(file)
	{
	gotoxy(30,12);cout<<"username       password";
	while(file.read((char*)&u,sizeof(u)))
       {
	gotoxy(30,16+i);cout<<u.username<<"\t\t"<<u.password;
	i+=2;
	}
	file.close();
	}
	cout<<"\n Press m to return to main menu";
	cin>>ch;
	if(ch=='m')
	goto again;
}
case 5:
{ofile.open("newsettings.dat",ios::binary|ios::in);
ofile.close();
remove("settings.dat");
rename("newsettings.dat","settings.dat");
goto again;
}
}
}
bool LexicalReorderingTableTree::Create(std::istream& inFile,
                                        const std::string& outFileName)
{
  std::string line;
  //TRACE_ERR("Entering Create...\n");
  std::string
  ofn(outFileName+".binlexr.srctree"),
      oft(outFileName+".binlexr.tgtdata"),
      ofi(outFileName+".binlexr.idx"),
      ofsv(outFileName+".binlexr.voc0"),
      oftv(outFileName+".binlexr.voc1");


  FILE *os = fOpen(ofn.c_str(),"wb");
  FILE *ot = fOpen(oft.c_str(),"wb");

  //TRACE_ERR("opend files....\n");

  typedef PrefixTreeSA<LabelId,OFF_T> PSA;
  PSA *psa = new PSA;
  PSA::setDefault(InvalidOffT);
  WordVoc* voc[3];

  LabelId currFirstWord = InvalidLabelId;
  IPhrase currKey;

  Candidates         cands;
  std::vector<OFF_T> vo;
  size_t lnc = 0;
  size_t numTokens    = 0;
  size_t numKeyTokens = 0;
  while(getline(inFile, line)) {
    ++lnc;
    if(0 == lnc % 10000) {
      TRACE_ERR(".");
    }
    IPhrase key;
    Scores   score;

    std::vector<std::string> tokens = TokenizeMultiCharSeparator(line, "|||");
    std::string w;
    if(1 == lnc) {
      //do some init stuff in the first line
      numTokens = tokens.size();
      if(tokens.size() == 2) { //f ||| score
        numKeyTokens = 1;
        voc[0] = new WordVoc();
        voc[1] = 0;
      } else if(3 == tokens.size() || 4 == tokens.size()) { //either f ||| e ||| score or f ||| e ||| c ||| score
        numKeyTokens = 2;
        voc[0] = new WordVoc(); //f voc
        voc[1] = new WordVoc(); //e voc
        voc[2] = voc[1];        //c & e share voc
      }
    } else {
      //sanity check ALL lines must have same number of tokens
      CHECK(numTokens == tokens.size());
    }
    size_t phrase = 0;
    for(; phrase < numKeyTokens; ++phrase) {
      //conditioned on more than just f... need |||
      if(phrase >=1) {
        key.push_back(PrefixTreeMap::MagicWord);
      }
      std::istringstream is(tokens[phrase]);
      while(is >> w) {
        key.push_back(voc[phrase]->add(w));
      }
    }
    //collect all non key phrases, i.e. c
    std::vector<IPhrase> tgt_phrases;
    tgt_phrases.resize(numTokens - numKeyTokens - 1);
    for(size_t j = 0; j < tgt_phrases.size(); ++j, ++phrase) {
      std::istringstream is(tokens[numKeyTokens + j]);
      while(is >> w) {
        tgt_phrases[j].push_back(voc[phrase]->add(w));
      }
    }
    //last token is score
    std::istringstream is(tokens[numTokens-1]);
    while(is >> w) {
      score.push_back(atof(w.c_str()));
    }
    //transform score now...
    std::transform(score.begin(),score.end(),score.begin(),TransformScore);
    std::transform(score.begin(),score.end(),score.begin(),FloorScore);
    std::vector<Scores> scores;
    scores.push_back(score);

    if(key.empty()) {
      TRACE_ERR("WARNING: empty source phrase in line '"<<line<<"'\n");
      continue;
    }
    //first time inits
    if(currFirstWord == InvalidLabelId) {
      currFirstWord = key[0];
    }
    if(currKey.empty()) {
      currKey = key;
      //insert key into tree
      CHECK(psa);
      PSA::Data& d = psa->insert(key);
      if(d == InvalidOffT) {
        d = fTell(ot);
      } else {
        TRACE_ERR("ERROR: source phrase already inserted (A)!\nline(" << lnc << "): '" << line << "\n");
        return false;
      }
    }
    if(currKey != key) {
      //ok new key
      currKey = key;
      //a) write cands for old key
      cands.writeBin(ot);
      cands.clear();
      //b) check if we need to move on to new tree root
      if(key[0] != currFirstWord) {
        // write key prefix tree to file and clear
        PTF pf;
        if(currFirstWord >= vo.size()) {
          vo.resize(currFirstWord+1,InvalidOffT);
        }
        vo[currFirstWord] = fTell(os);
        pf.create(*psa, os);
        // clear
        delete psa;
        psa = new PSA;
        currFirstWord = key[0];
      }
      //c) insert key into tree
      CHECK(psa);
      PSA::Data& d = psa->insert(key);
      if(d == InvalidOffT) {
        d = fTell(ot);
      } else {
        TRACE_ERR("ERROR: source phrase already inserted (A)!\nline(" << lnc << "): '" << line << "\n");
        return false;
      }
    }
    cands.push_back(GenericCandidate(tgt_phrases, scores));
  }
  if (lnc == 0) {
    TRACE_ERR("ERROR: empty lexicalised reordering file\n" << std::endl);
    return false;
  }
  //flush remainders
  cands.writeBin(ot);
  cands.clear();
  //process last currFirstWord
  PTF pf;
  if(currFirstWord >= vo.size()) {
    vo.resize(currFirstWord+1,InvalidOffT);
  }
  vo[currFirstWord] = fTell(os);
  pf.create(*psa,os);
  delete psa;
  psa=0;

  fClose(os);
  fClose(ot);
  /*
  std::vector<size_t> inv;
  for(size_t i = 0; i < vo.size(); ++i){
    if(vo[i] == InvalidOffT){
      inv.push_back(i);
    }
  }
  if(inv.size()) {
    TRACE_ERR("WARNING: there are src voc entries with no phrase "
        "translation: count "<<inv.size()<<"\n"
        "There exists phrase translations for "<<vo.size()-inv.size()
        <<" entries\n");
  }
  */
  FILE *oi = fOpen(ofi.c_str(),"wb");
  fWriteVector(oi,vo);
  fClose(oi);

  if(voc[0]) {
    voc[0]->Write(ofsv);
    delete voc[0];
  }
  if(voc[1]) {
    voc[1]->Write(oftv);
    delete voc[1];
  }
  return true;
}