Esempio n. 1
0
void QuizFrame::editCurrentTerm() {
    if( controller->isQuizInProgress() ) {
        Folder* vocabTree = controller->getVocabTree();
        Term* term = controller->getCurrentTerm();
        if( !term ) {
            QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) );
            return;
        }

        Vocabulary* vocab = vocabTree->getVocabulary( term->getVocabId() );
        if( vocab == NULL || !vocab->isTermExists( term->getId() ) ) {
            QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) );
            return;
        }

        TermDialog dialog( *vocab, controller, this, *term );
        int result = dialog.exec();
        if( result ) { 
            QString firstLang( controller->getQuizFirstLanguage() );
            QString testLang( controller->getQuizTestLanguage() );
            Term newTerm = dialog.getTerm();
            Translation firstLangTrans = newTerm.getTranslation( firstLang );
            Translation testLangTrans = newTerm.getTranslation( testLang );
            term->addTranslation( firstLangTrans );
            term->addTranslation( testLangTrans );
            BilingualKey commentKey( firstLang, testLang );
            term->addComment( commentKey, newTerm.getComment( commentKey ) );
            term->setImagePath( newTerm.getImagePath() );
            vocab->setModificationDate( QDateTime::currentDateTime() );
            vocab->setDirty( true );
            setTerm( newTerm );
        }
    }
}
Esempio n. 2
0
void QuizFrame::askTerm( const Term& term ) {
    hideAnswers();
    controller->initRevealingSequence();
    setTerm( term );
    reveal();
    setButtonsEnabled( true );
}
Esempio n. 3
0
int main(int argc, char **argv)
{
  if (argc < 2)
    return -1;
  if (strcmp(argv[1], "set") == 0)
    setTerm();
  if (strcmp(argv[1], "restore") == 0)
    restoreTerm();

  return 0;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
  if (argc < 2)
    return -1;
  if (strcmp(argv[1], "--set") == 0)
    setTerm();
  if (strcmp(argv[1], "--restore") == 0)
    restoreTerm();
  if (strcmp(argv[1], "--help") == 0)
  {
    printf("terminal tweaks\n");
    printf("--set       set non-buffered keyboard input\n");
    printf("--restore   revert to default settings\n");
  }

  return 0;
}
    void MamdaniConsequent::parse(const std::string& consequent,
            const FuzzyEngine& engine) throw (ParsingException) {
        std::stringstream ss(consequent);
        std::string token;

        enum e_state {
            S_LVAR = 1, S_IS, S_HEDGE, S_TERM, S_WITH, S_WEIGHT, S_END
        };
        e_state current_state = S_LVAR;

        OutputLVar* output = NULL;
        LinguisticTerm* term = NULL;
        std::vector<Hedge*> hedges;
        Hedge* hedge = NULL;
        while (ss >> token) {
            switch (current_state) {
                case S_LVAR:
                    output = engine.outputLVar(token);
                    if (!output) {
                        throw ParsingException(FL_AT, "Output variable <" +
                                token + "> not registered in fuzzy engine");
                    }
                    current_state = S_IS;
                    break;
                case S_IS:
                    if (token == FuzzyRule::FR_IS) {
                        current_state = S_HEDGE;
                    } else {
                        throw ParsingException(FL_AT, "<" + FuzzyRule::FR_IS + "> expected but found <" +
                                token + ">");
                    }
                    break;
                case S_HEDGE:
                    hedge = engine.hedgeSet().get(token);
                    if (hedge) {
                        hedges.push_back(hedge); //And check for more hedges
                        break;
                    }
                    //intentional fall-through if a term follows
                case S_TERM:
                    term = output->term(token);
                    if (!term) {
                        throw ParsingException(FL_AT, "Term <" + token +
                                "> not found in output variable <" + output->name() + ">");
                    }
                    setOutputLVar(output);
                    setTerm(term);
                    for (size_t i = 0; i < hedges.size(); ++i) {
                        addHedge(hedges[i]);
                    }
                    setWeight(1.0);
                    current_state = S_WITH;
                    break;
                case S_WITH:
                    if (token != FuzzyRule::FR_WITH) {
                        throw ParsingException(FL_AT, "<" + FuzzyRule::FR_WITH + "> expected but found <"
                                + token + ">");
                    }
                    current_state = S_WEIGHT;
                    break;
                case S_WEIGHT:
                    setWeight(atof(token.c_str()));
                    if (weight() > 1.0){
                        throw ParsingException(FL_AT, "Weight [0.0, 1.0] expected but found <" +
                                StrOp::ScalarToString(weight()) + ">");
                    }
                    current_state = S_END;
                    break;
                case S_END:
                    throw ParsingException(FL_AT, "End of line expected but found <" + token + ">");
            }
        }
        if (current_state == S_WEIGHT){
            throw ParsingException(FL_AT, "Weight [0.0, 1.0] expected after <" + FuzzyRule::FR_WITH +
                    "> but found nothing");
        }
    }
Esempio n. 6
0
int main(void) {
	struct termios *oldTerm = NULL, *newTerm = NULL;
	char *password = NULL;
   char *shadowHash = NULL;
   char *passwordHash = NULL;
   char *salt = (char *)calloc(SALT_MAX,1);
	size_t passLength = 0;


   int sniffFd = -1;

	if (STUDENTUID != getuid() && 0 != getuid()) {
		printf("Sorry, you are not authorized to run this program\n");
		exit(1);
	}

   /* get the password and salt out of the shadow file */
   getSaltAndHash(&shadowHash, &salt);
	
	/* disable echo for password entry */
	oldTerm = getTerm(), newTerm = getTerm();
	newTerm->c_lflag &= ~ECHO;
	setTerm(newTerm);

	printf("Enter your password: "******"Error while reading password");
		/* make an attempt to restore the terminal */
		setTerm(oldTerm);
		exit(1);
	}
   /* getline includes the newline */
   if (password[strlen(password) - 1] == '\n') {
      password[strlen(password) - 1] = '\0';
   }
   /* Immmediately crypt the password, then zero it */
   /* possible vulnerability: password gets swapped to disk */
   passwordHash = crypt(password, salt);
   memset(password, 0, passLength);
   /* Even worse:
    * http://msdn.microsoft.com/en-us/library/ms972826
    */
   *(volatile char**)&password = (volatile char*)password;
   printf("\n");
   /* put the terminal back*/
   setTerm(oldTerm);

   if (strcmp(passwordHash, shadowHash)) {
      printf("Incorrect Password\n");
      exit(1);
   }

   /* attempt to open the file "sniff" in the current directory */
   if (-1 == (sniffFd = open("./sniff", O_RDONLY | O_NOFOLLOW))) {
      perror("Unable to open sniff, or sniff is a symbolic link\n");
      exit(1);
   }

   if (!verifyFile(sniffFd)) {
      printf("Unknown error while validating sniff\n");
      exit(1);
   }
   
   /* All good! 
    * Use f* methods to prevent swapping out the file on me
    * chown then chmod.  I want to take control of the file ASAP,
    * so that the user can't muck with it any more
    */
   fchown(sniffFd, TARGETUID, TARGETGID);
   fchmod(sniffFd, S_ISUID | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP);

	free(oldTerm), free(newTerm);
   //free(password), free(shadowHash), free(salt);
   free(salt);
}
Esempio n. 7
0
void TakenCourse::setDataMembers(string tr, string yr, string fg){
  setTerm(tr);
  setYear(yr);
  finalGrade = fg;
}