Ejemplo n.º 1
0
	void TextInput::appendText(char text)
	{
		if (mMaxCharacters > 0 && mText->length() >= mMaxCharacters || !validateChar(text))
		{
			return;
		}
		if (text == 8 || text == 127)
		{
			return;
		}
		else if (text == 13)
		{
			text = '\n';
		}
		else if (text < ' ' && text != '\t')
		{
			return;
		}
		static char buff[2];
		buff[0] = text;
		buff[1] = '\0';
		std::string str = getText();
		str.insert(mInputPosition, buff);
		mText->setText(str);
		fireChangeEvent();
		updateInputCursor(1);
	}
Ejemplo n.º 2
0
void PGuiVirtualMachine::readChar()
{
    std::cout << "GUI readNumber" << std::endl;
    QString read;
    do {
      read = QInputDialog::getText(
        0, "Piet input reading", "Enter a character:");
    } while (!validateChar(read));
    stack->instrPush(read.toInt());
}
Ejemplo n.º 3
0
	bool TextInput::validateText(const char *input)
	{
		if (!input)
		{
			return false;
		}
		if (mRestriction == NONE)
		{
			return true;
		}
		char c = input[0];
		int i = 0;
		while (c != '\0')
		{
			if (!validateChar(c))
			{
				return false;
			}
			c = input[++i];
		}
		return true;
	}
Ejemplo n.º 4
0
void AddNew::processInput(string inputString)
{
    // Holds the value entered by the user for this menu
    static int menuChoiceInt;
    static char menuChoiceChar;
    
    // Holds whether the entered value is valid
    static bool isValidInt; 
    static bool isValidChar;
    
    isValidInt = validateInt(inputString, &menuChoiceInt);
    isValidChar = validateChar(inputString, &menuChoiceChar);
    
    if(isValidInt)
    {
        if(isOption(menuChoiceInt))
        {
            // You need to find a way to associate values with menu selections
            // This more general than assuming the order that is setup in setActions()
            
            //process();
            if(menuChoiceInt == 1)
            {
                //change(MenuSystem::ENTERDIR);
                kill();
            }
            else if(menuChoiceInt == 2)
            {
                cout << "trying to switch to enter dir..." << endl;
                change(MenuSystem::ENTERDIR);
                //kill();
            }
            else if(menuChoiceInt == 3)
            {
                //change(MenuSystem::REMOVEDIR);
                kill();
            }
            else
            {
                process();
            }
        }
    }
    else if(isValidChar)
    {
        if(Menu::isOption(menuChoiceChar))
        {
            MenuSystem::MenuType menuType = getOption(menuChoiceChar)->getValue();
            if(menuType == MenuSystem::EXIT)
            {
                kill();
            }
            else if(menuType == MenuSystem::ADDREMOVE)
            {                
                // Assuming there are no more menus for now
                change(MenuSystem::ADDREMOVE);
            }
        }
        else
        {
            printInvalidAndProcess();
        }
    }
    else
    {
        printInvalidAndProcess();
    }

}
//================
//Function: long writeFile(int new_conn_file_d,const char* fileName)
//Description: General function to open file and send contents to server.  Keeps track of size
// in long variable.  Checks for valid characters, and initally removes newlines.  Will append newline
// to the end of file.  Once finished sending entire file contents, send key to server (22done22)
// to signify we are done sending.  
//================
long writeFile(int new_conn_file_d,const char* fileName)
{
    
    FILE *fptr;
    int sending=1;
    char buffer[BUFSIZE];
    int lup, found_char;
    long file_size = 0;
    char get_char;
    int valid_char;
    int new_line_found;
    ssize_t send_status;
    
    fptr = fopen(fileName,"r");
    if(fptr == NULL)
    {
        errorMsgExit("Cannot open file.\n");
    }
    memset(buffer,0,BUFSIZE);   //Clear buffer
    do
    {
        found_char=0;
        new_line_found=0;  //Initally set found_char and new line found to 0
        
        for(lup=0; lup < BUFSIZE-2; lup++)  //Allow two spaces for buffer (/n and '0')
        {
            get_char = fgetc(fptr);  //Retrieve sequential charater from file
            valid_char = validateChar(get_char);  //Make sure valid character
            if(valid_char==0 && get_char !=EOF)//If character is invalid (and not EOF), error
            {
                strcpy(buffer,"invalid");
                send_status=send(new_conn_file_d,buffer,sizeof(buffer),0);
                close(new_conn_file_d);
                errorMsgExit("Client exit, invalid character.\n");
            }

            if(get_char==EOF) 
            {

                buffer[lup-new_line_found]='\n';  //Add newline to end.
                file_size = ftell(fptr);  //Get current file size
                sending=0;
                break;
            }
            else if(get_char=='\n')
            {
 //////               printf("New line found in lup: %i\n",lup);
                new_line_found++;
            }
            else
            {
                found_char++;
                buffer[lup-new_line_found]=get_char;
            }
        }
        
        if(found_char >0)
        {
 //////           printf("SEND: %s\n",buffer);
            send_status=send(new_conn_file_d,buffer,sizeof(buffer),0);
            if(send_status <= 0)
            {
                fprintf(stderr,"Error sending.\n");
            }
            memset(buffer,0,BUFSIZE);
        }
        
        
        
    }while(sending==1);
    strcpy(buffer,"22done22");  //Key for server to signify we are done sending.
    
    send_status=send(new_conn_file_d,buffer,sizeof(buffer),0);  //send key
    fclose(fptr);
    return file_size;
}