Пример #1
0
// the functions below can be used to save
// the content of the dabase to the script file.
void Eliza::save_data() {
	scriptfile.open("script.txt", std::ios::out);
	if(scriptfile.fail()) {
		throw std::string("Can't save data");
	}
	saveComment(comments[0]);
	saveTopic(signOn, "S");
	
	saveComment(comments[1]);
	saveTransposTable();
	saveCorrections();
	saveComment(comments[2]);
	
	saveTopic(nullResponse, "N");
	saveComment(comments[3]);
	
	saveTopic(subjectRecall, "M");
	saveComment(comments[4]);

	saveTopic(noKeyWord, "X");
	saveComment(comments[5]);

	saveTopic(topicChanger, "Z");
	saveComment(comments[6]);

	saveTopic(inputRepeat, "W");
	saveComment(comments[7]);

	saveKeyWords();

	scriptfile.flush();
	scriptfile.close();
}
Пример #2
0
// the functions below can be used to save
// the content of the dabase to the script file.
void ofxEliza::save( string _scriptFile, string _unknownFile ){
    if( m_bNewData ) {
        scriptfile.open( ofToDataPath(_scriptFile).c_str(), std::ios::out);
        if(scriptfile.fail()) {
            throw std::string("Can't save data");
        }
        saveComment(comments[0]);
        saveTopic(signOn, "S");
        
        saveComment(comments[1]);
        saveTransposTable();
        saveCorrections();
        saveComment(comments[2]);
        
        saveTopic(nullResponse, "N");
        saveComment(comments[3]);
        
        saveTopic(subjectRecall, "M");
        saveComment(comments[4]);
        
        saveTopic(noKeyWord, "X");
        saveComment(comments[5]);
        
        saveTopic(topicChanger, "Z");
        saveComment(comments[6]);
        
        saveTopic(inputRepeat, "W");
        saveComment(comments[7]);
        
        saveKeyWords();
        
        scriptfile.flush();
        scriptfile.close();
    }
    saveUnknownSentences(_unknownFile);
}
Пример #3
0
int main(void) {

int retcode;
unsigned int count;
fileHandleType fh;
int useraccount;
void *message;
int messagetype;
newUserMessageType *newuser;
loginMessageType *loginuser;
newPostMessageType *newPost;
addCommentMessageType *newComment;
unsigned int postID;
int responseCode;
unsigned int nextPostID = 100;
unsigned int sessionToken;
char *postText;
int postSize;
int endIt;
    
    // using a small blocksize of 256 bytes because postings are small and this is more efficient
    retcode = initFileSystem(512, 512, 512*2000);

    securityIDFileHandle = -1;

    if (retcode != 0) {

        printf("Error making filesystem.\n");
        _terminate(-1);
    }

    retcode = makeMemoryFile("sticky.posts", 0x4347C000 + 1536, 160*16,  1,  ROOT_ID );

    if ( retcode != 0 ) {

        printf("Error making posts.log\n");
        _terminate(-1);
    }

    retcode = makeMemoryFile("initialPostID.mem", 0x4347C000, 4, 1, ROOT_ID );

    if ( retcode != 0 ) {

        printf("Error making posts.log\n");
        _terminate(-1);
    }

	retcode = createFile("Users.db", REGULAR, ROOT_ID);	
    
    if ( retcode != 0 ) {

        printf("Error making Users.db\n");
        _terminate(-1);
    }

    retcode = createFile("posts.log", REGULAR, ROOT_ID);

    if ( retcode != 0 ) {

        printf("Error making posts.log\n");
        _terminate(-1);
    }

    // seed the first postID with magic page data.  After this they just increase by 1 each time
    fh = openFile("initialPostID.mem", ROOT_ID);

    if ( fh < 0 ) {

        printf("Error opening initialPostID.mem\n");
        _terminate(-1);
    }
    readFile(fh, (void *)&nextPostID, sizeof(nextPostID), 0, 0, ROOT_ID);
    nextPostID &= 0x0fffffff;

    // we'll never re-seed the postID so just delete the file
    deleteFile(fh, ROOT_ID);

    // this file will allow us to get semi-random userID's from the magic page.  It is kept open and a new ID is 
    // read whenever a new account is created
    retcode = makeMemoryFile("UserIDs.mem", 0x4347C004, 1532, 1, ROOT_ID );

    if ( retcode != 0 ) {

        printf("Error making UserIDs.mem\n");
        _terminate(-1);
    }

    retcode = allocate(1024, 0, &message);

    if (retcode != 0) {

        _terminate(-1);
    }

    endIt = 0;

    while (!endIt) {

    	messagetype = receiveMessage(message);

    	switch (messagetype) {

    			// add a new user
    		case 0xa0:

    			newuser = (newUserMessageType *)message;

    			if (create_user(newuser->name, newuser->password, newuser->fullname) >= 0 ) {

    				responseCode = 0;
    				
    			}
    			else {

    				responseCode = -1;

    			}

    			sendResponse((void *)&responseCode, sizeof(responseCode));

    			break;

    			// authenticate a user
    		case 0xb0:

    			loginuser = (loginMessageType *)message;
    			useraccount = authenticate(loginuser->name, loginuser->password);

    			sendResponse((void *)&useraccount, sizeof(useraccount));

    			break;

    			// retrieve a single post to this user's feed
    		case 0xc0:

                sessionToken = *(unsigned int *)message;

                retcode = newFeedPost(sessionToken, &postText, &postSize);

                if (retcode == 0 ) {

                    sendResponse((void *)postText, postSize);
                    deallocate((void *)postText, postSize);
                }
                else {

                    retcode = -1;
                    sendResponse((void *)&retcode, sizeof(retcode));

                }
    			break;

    			 // record a new post from the user
    		case 0xd0:

                newPost = (newPostMessageType *)message;

                retcode = savePost(nextPostID, newPost->sessionToken, newPost->post);

                if (retcode == 0) {

                    retcode = nextPostID;
                    ++nextPostID;
                }
                else {

                    retcode = -1;
                }

                sendResponse((void *)&retcode, sizeof(retcode));

    			break;

                // comment on a post
            case 0xe0:

                newComment = (addCommentMessageType *)message;

                retcode = saveComment(newComment->postID, newComment->commenterID, newComment->comment);

                sendResponse((void *)&retcode, sizeof(retcode));

                break;

                // retrieve a specific post by its ID--this will include any comments as well
            case 0xf0:

                postID = *(unsigned int *)message;

                if ( postID < 16 ) {

                     retcode = sendStickPost( postID );
                }
                else {

                    retcode = retrievePost( postID, 1 , &postText, &postSize);

                    if (retcode == 0) {

                        sendResponse((void *)postText, postSize);
                        deallocate((void *)postText, postSize);
                    }
                }

                if ( retcode == -1 ) {

                    sendResponse((void *)&retcode, sizeof(retcode));

                }
                // response sent by the retrievePost() function
                break;

            case 100:

                endIt = 1;
                break;

    		default:

                endIt = 1;

    			break;

    	} //switch


    } // while (1)

    printf("BYE!\n");

}  // main  
Пример #4
0
 //Make a new comment
 Comment::Comment(UserID poster, std::string commtext, int cid) : chainID(cid), id(generateUnusedFileName("Comments/")), commentPoster(poster), comment(commtext)
 {
   saveComment();
 }