Esempio n. 1
0
int main(void)
{
	int shift = 0;
	char* pSentence = NULL;
	char* pEncrypted = NULL;

	pSentence = getSentence();
	shift = getShift();
	pEncrypted = caesarShiftCipher(pSentence, shift);

	puts("\nOriginal Sentence: ");
	puts(pSentence);
	puts("\nEncrypted Sentence: ");
	puts(pEncrypted);

	return 0;
}
Esempio n. 2
0
int main()
{
    char string[MAX_STRING_SIZE], longestWord[MAX_STRING_SIZE] = {'\0'};
    int numWords, longestWordCount;
    getSentence(string);
    
    /* Just to see if everything is ok... */
    printf("\n\n\nThe sentence: \"");
    print_string(string, strlen(string), 0);
    printf("\"\n");
    
    numWords = numberOfWords(string, strlen(string));
    printf("\nNumber of words: %d\n", numWords);

    longestWordCount = func_longestWord(string, longestWord, strlen(string));
    printf("\nLongest word: \"");
    print_string(longestWord, longestWordCount, 0);
    printf("\" (%d characters).\n", longestWordCount);
    
    return 0;
}
Esempio n. 3
0
string Kernel::respond(const string &input, const string &id, Responder *r, int, bool srai, const string &prefix) {
	if (!srai) {
		recursionDepth = 0;
		timingResponse = timerMillis();
	}
	//	I want this to be configurable...
	if (++recursionDepth > maxRecursiveDepth) {
		predicates->addHistory("that", id, "");
		cerr << "AIML contains an infinite loop" << endl;
		cerr << "Input involved in loop: " << input << endl;
		return "";
	}
	string currentResponse = "", buffer = "";
	Match *m = NULL;
	if (!srai) {
		predicates->addHistory("input", id, input);
	}
	string sentence, inString = input;
	while (!(sentence = getSentence(inString)).empty()) {
		sentence = trim(sentence);
		string originalInput = sentence;
		if (sentence.length() < 1) {
			continue;
		}
		sentence = prefix + " " + Substituter::substitute(sentence);
		string context = predicates->getValue("context", id);
		context = Substituter::substitute(context);
		string that = predicates->getValue("that", id);
		if (!srai) {
			StringTokenizer stThat(that, ".?!");
			while (stThat.hasMoreTokens()) {
				string t = stThat.nextToken();
				t = trim(t);
				if (!t.empty()) {
					that = t;
					predicates->addHistory("that", id, that);
				}
			}
		}
		that = Substituter::substitute(that);
		string topic = predicates->getValue("topic", id);
		topic = Substituter::substitute(topic);
		if (that.empty()) {
			that = "*";
		}
		if (topic.empty()) {
			topic = "*";
		}
		if (context.empty()) {
			context = "*";
		}
	
		//--	DEBUGGING LINE
		string ktr = sentence + "\n";
		getStream("Kernel")->Read(ktr.c_str());
	
		m = match(context, sentence, that, topic);
		if (m == NULL) {
				cerr << "There is no match for input: " << sentence << endl;
		} else {
			cerr << endl;
			cerr << "INPUT: " << originalInput << endl;
			cerr << "MATCH PATH: " << m->getPath() << endl;
			cerr << "FILENAME: " << m->getNode()->getActualTemplate()->getFilename() << endl;
			
			string tmpl = "<template>" + m->getTemplate() + "</template>";
			strstream ss;
			ss << tmpl << endl;
			
			SaxParser *p = new SaxParser(new Parser());
			p->parse(ss);
			
			currentResponse = Kernel::process(m, ((Parser *)p->getListener())->getRoot(), r, id);
			
			predicates->setValue("beforethat", id, that);
			predicates->setValue("that", id, currentResponse);
			
			delete p;
		}
		if (m != NULL) {
			delete m;
			if (srai) {
				--recursionDepth;
				return currentResponse;
			} else {
				buffer += currentResponse + " ";
			}
		}
	}
	string result = Substituter::substitute(buffer, "output");
	--recursionDepth;
	if (!srai) {
		timingResponse = timerMillis() - timingResponse;
		cerr << "TIME: " << timingResponse << "ms" << endl;
	}
	//--	DEBUGGING LINE
	string ktw = result + "\n";
	getStream("Kernel")->Write(ktw.c_str());
	if (trimming) {
		return trim(result, " \t\r\n");
	}
	return result;
}
bool ONScripterLabel::executeSystemYesNo( int caller, int file_no )
{
    current_font = &menu_font;

    text_info.fill( 0, 0, 0, 0 );
    dirty_rect.fill( screen_width, screen_height );

    char name[64] = {'\0'};

    if ( caller == SYSTEM_SAVE ){
        SaveFileInfo save_file_info;
        searchSaveFile( save_file_info, file_no );
        sprintf( name, getMessageString(MESSAGE_SAVE_CONFIRM),
                 save_item_name,
                 save_file_info.sjis_no );
    }
    else if ( caller == SYSTEM_LOAD ){
        SaveFileInfo save_file_info;
        searchSaveFile( save_file_info, file_no );
        sprintf( name, getMessageString(MESSAGE_LOAD_CONFIRM),
                 save_item_name,
                 save_file_info.sjis_no );
    }
    else if ( caller ==  SYSTEM_RESET )
        strcpy( name, getMessageString(MESSAGE_RESET_CONFIRM) );
    else if ( caller ==  SYSTEM_END )
        strcpy( name, getMessageString(MESSAGE_END_CONFIRM) );


    menu_font.num_xy[0] = strlen(name)/2;
    menu_font.num_xy[1] = 3;
    menu_font.top_xy[0] = (ContractPos(screen_width) - menu_font.num_xy[0] * menu_font.pitch_xy[0]) / 2;
    menu_font.top_xy[1] = (ContractPos(screen_height) - menu_font.num_xy[1] * menu_font.pitch_xy[1]) / 2;
    menu_font.setXY(0, 0);
    //Mion: fixed the menu title bug noted in the past by Seung Park:
    // the menu title must be drawn close to last during refresh,
    // not in the textwindow, since there could be sprites above the
    // window if windowback is used.
    if (system_menu_title){
        dirty_rect.add( system_menu_title->pos );
        delete system_menu_title;
        system_menu_title = NULL;
    }
    system_menu_title = getSentence( name, &menu_font, 1, false );

    flush( refreshMode() );

    int offset1 = strlen(name)/5;
    int offset2 = strlen(name)/2 - offset1;
    strcpy( name, getMessageString(MESSAGE_YES) );
    menu_font.setXY(offset1-2, 2);
    ButtonLink *button = getSelectableSentence( name, &menu_font, false );
    root_button_link.insert( button );
    button->no = 1;

    strcpy( name, getMessageString(MESSAGE_NO) );
    menu_font.setXY(offset2, 2);
    button = getSelectableSentence( name, &menu_font, false );
    root_button_link.insert( button );
    button->no = 2;

    flush( refreshMode() );

    refreshMouseOverButton();

    event_mode = WAIT_BUTTON_MODE;
    do waitEventSub(-1);
    while (current_button_state.button == 0);

    deleteButtonLink();
    if (system_menu_title){
        dirty_rect.add( system_menu_title->pos );
        delete system_menu_title;
        system_menu_title = NULL;
    }

    if ( current_button_state.button == 1 ){ // yes is selected
        if ( menuselectvoice_file_name[MENUSELECTVOICE_YES] )
            playSound(menuselectvoice_file_name[MENUSELECTVOICE_YES],
                      SOUND_WAVE|SOUND_OGG, false, MIX_WAVE_CHANNEL);
        return true;
    }
    else{
        if ( menuselectvoice_file_name[MENUSELECTVOICE_NO] )
            playSound(menuselectvoice_file_name[MENUSELECTVOICE_NO],
                      SOUND_WAVE|SOUND_OGG, false, MIX_WAVE_CHANNEL);
        return false;
    }
}
void ONScripterLabel::executeSystemSave()
{
    current_font = &menu_font;

    text_info.fill( 0, 0, 0, 0 );

    menu_font.num_xy[0] = (strlen(save_item_name)+1)/2+2+13;
    menu_font.num_xy[1] = num_save_file+2;
    menu_font.top_xy[0] = (ContractPos(screen_width) - menu_font.num_xy[0] * menu_font.pitch_xy[0]) / 2;
    menu_font.top_xy[1] = (ContractPos(screen_height) - menu_font.num_xy[1] * menu_font.pitch_xy[1]) / 2;
    menu_font.setXY((menu_font.num_xy[0] - (strlen( save_menu_name )+1) / 2 ) / 2, 0);
    //Mion: fixed the menu title bug noted in the past by Seung Park:
    // the menu title must be drawn close to last during refresh,
    // not in the textwindow, since there could be sprites above the
    // window if windowback is used.
    if (system_menu_title){
        dirty_rect.add( system_menu_title->pos );
        delete system_menu_title;
        system_menu_title = NULL;
    }
    system_menu_title = getSentence( save_menu_name, &menu_font, 1, false );
    menu_font.newLine();

    flush( refreshMode() );

    bool nofile_flag;
    int slen = strlen(save_item_name);
    char *buffer = new char[ slen + (slen % 2) + 30 + 3 ];

    for ( unsigned int i=1 ; i<=num_save_file ; i++ ){
        SaveFileInfo save_file_info;
        searchSaveFile( save_file_info, i );
        menu_font.setXY( (menu_font.num_xy[0] - ((strlen( save_item_name )+1) / 2 + 15) ) / 2 );

        if ( save_file_info.valid ){
            sprintf( buffer, getMessageString(MESSAGE_SAVE_EXIST),
                     save_item_name,
                     save_file_info.sjis_no,
                     save_file_info.sjis_month,
                     save_file_info.sjis_day,
                     save_file_info.sjis_hour,
                     save_file_info.sjis_minute );
            nofile_flag = false;
        }
        else{
            sprintf( buffer, getMessageString(MESSAGE_SAVE_EMPTY),
                     save_item_name,
                     save_file_info.sjis_no );
            nofile_flag = true;
        }
        ButtonLink *button = getSelectableSentence( buffer, &menu_font, false, nofile_flag );
        root_button_link.insert( button );
        button->no = i;
        flush( refreshMode() );
    }
    delete[] buffer;

    refreshMouseOverButton();

    event_mode = WAIT_BUTTON_MODE;
    do waitEventSub(-1);
    while (current_button_state.button == 0);

    deleteButtonLink();
    if (system_menu_title){
        dirty_rect.add( system_menu_title->pos );
        delete system_menu_title;
        system_menu_title = NULL;
    }

    if ( current_button_state.button > 0 ){
        int file_no = current_button_state.button;
        if (executeSystemYesNo( SYSTEM_SAVE, file_no )){
            saveSaveFile( file_no );
            leaveSystemCall();
        }
        return;
    }

    leaveSystemCall();
}