Ejemplo n.º 1
0
int InputMask::findInMask( int pos, bool forward, bool findSeparator, QChar searchChar ) const
{
    if ( pos >= m_maxLength || pos < 0 )
        return -1;

    int end = forward ? m_maxLength : -1;
    int step = forward ? 1 : -1;
    int i = pos;

    while ( i != end )
    {
        if ( findSeparator )
        {
            if ( m_maskData[ i ].separator && m_maskData[ i ].maskChar == searchChar )
                return i;
        }
        else
        {
            if ( !m_maskData[ i ].separator )
            {
                if ( searchChar.isNull() )
                    return i;
                else if ( isValidInput( searchChar, m_maskData[ i ].maskChar ) )
                    return i;
            }
        }
        i += step;
    }
    return -1;
}
////////////////////////////////////////////////////////////////////////////////////
//////	pvHttpDownloadInput implementation
////////////////////////////////////////////////////////////////////////////////////
bool pvHttpDownloadInput::getValidMediaData(INPUT_DATA_QUEUE &aDataInQueue, PVMFSharedMediaDataPtr &aMediaData, bool &isEOS)
{
    isEOS = false; //aMediaData.Bind(iCurrentInputMediaData);

    do
    {
        // There should be at least one media msg in the queue
        if (aDataInQueue.empty()) return false;

        // Check if the next incoming media msg is an EOS or not
        // Introducing a boolean variable aEOSMsg is for simulating connection shutdown cases
        bool aEOSMsg = aDataInQueue[0]->getFormatID() == PVMF_MEDIA_CMD_EOS_FORMAT_ID;
        if (aEOSMsg)
        {
            isEOS = true;
            aDataInQueue.erase(aDataInQueue.begin());
            return true;
        }

        convertToPVMFMediaData(iCurrentInputMediaData, aDataInQueue[0]);
        aDataInQueue.erase(aDataInQueue.begin());
    }
    while (isValidInput() == false);

    aMediaData.Bind(iCurrentInputMediaData);
    return true;
}
void main() {
	char * P = (char *)malloc(sizeof(char) * 100);
	int index = 0;
	char digit;
	printf("Enter the P: \n");
	while ((digit = getchar()) == '0');

	if (digit != '\n') {
		P[index++] = digit;
		while ((digit = getchar()) != '\n') {
			P[index] = digit;
			index++;
		}
		P[index] = '\0';
		if (isValidInput(P)) {
			int K;
			printf("Enter K: ");
			scanf("%d", &K);
			char Q[10000] = "";
			while (K > 0) {
				formQ(Q, P);
				K--;
			}
			Q[length(Q)] = '\0';
			printf("The number %s ", Q);
			testCases(P, index);
		}
		else
			printf("The given number is not a valid number .\n");
	}
	else
		printf("0 is divisible by 3.\n");
	_getch();
	return 0;
}
Ejemplo n.º 4
0
int main()
{
	// read integers
	int a, b;
	
	printf("Please enter the first integer between 1 and 100: ");
	if (!isValidInput(a = getint()))
	{
		printf("Invalid Input\n");
		return -1;
	}
		
	printf("Please enter the second integer between 1 and 100: ");	
	if (!isValidInput(b = getint()))
	{
		printf("Invalid Input\n");
		return -1;
	}
	
	// compute greatest common divisor
	//printf("%d, %d\n", a, b);
	int i, gcd = 1;
	for (i = 1; i <= a && i <= b; i++)
	{
		//printf("a mod %d = %d\nb mod %d = %d\n", i, a % i, i, b % i);
		if (a % i == 0 && b % i == 0)
		{
			gcd = i;
		}
	}
	printf("%d\n", gcd);
	
	if (gcd == 1)
	{
		printf("relatively prime\n");
	}
	
	return 0;
}
Ejemplo n.º 5
0
/**
 * Plays the next human turn
 * @param board to be used
 */
void playHuman(char board[9])
{
    int input;
    std::string inStr;

    std::cout << "Your Turn" << std::endl;
    printInputBoard(board);

    std::cout << "Where do you want to place your mark? [0-8]" << std::endl;

    do
    {
        std::cout << ">";
        std::getline(std::cin, inStr);
        input = atoi(inStr.c_str());
        if(!isValidInput(board, input))
            std::cout << "Please enter a valid location." << std::endl;
    }while(!isValidInput(board, input));

    board[input] = 'x';

    std::cout << std::endl;
}
Ejemplo n.º 6
0
result_t* _doAction(transaction_t *t, 
					result_t* (*action)(transaction_t *t),
					bool (*isValidInput)(int,int),
					int account1, int account2)
{	
	if (!init_done) 
		return notStartedError();
				
	if (!isValidInput(account1, account2))		
		return invalidAccountError();
	
	result_t* ret = action(t);
	writeAccounts();
	return ret;
}
Ejemplo n.º 7
0
	void Lexer::compile() {
		if( isCompiled() )
			throw AlreadyCompiledException();

		createTable_();

		foreach(Rule &r, rules_) {
			assert( r.inState != S_UNCHANGED );
			assert( isValidInput(r.input) );
			assert( r.action.toState != S_UNCHANGED );
			
			if( isClass(r.input) ) {
				String& cl = getClass_(r.input);
				foreach( char ch, cl )
					getAction_(r.inState, ch) = r.action;
			} else if( r.input == I_DEFAULT )
Ejemplo n.º 8
0
int main (void) {
  char *command = NULL;
  node *root = NULL;

  command = malloc(sizeof(char) * BUFFER_SIZE);

  srand(time(NULL));

  do {
    printMenu();
    scanf("%s", command);

    // 'z' will skip the rest of the loop,
    // and fail the continuing condition (hopefully)
    if (!isValidInput(command[0])) {
      if (DEBUG) printf("command not recognized. (%c)\n", command[0]);
      continue;
    }

    switch(command[0]) {
      case 'i':
        root = captureInsertion(root, command);
        break;
      case 'r':
        root = captureRepeating(root, command);
        break;
      case 'p':
        capturePrint(root, command);
        break;
      case 'f':
        captureFind(root, command);
        break;
      case 'd':
        root = captureDelete(root, command);
        break;
      case 'q':
        root = insertDefaults(root);
        break;
    }
    
  } while (command[0] != 'z');

  free(command);

  return 0;
}
Ejemplo n.º 9
0
	void Lexer::addRule( State inState, Input input, Action action ) {
		if( isCompiled() )
			throw AlreadyCompiledException();

		if( inState == S_UNCHANGED || !isValidInput(input) )
			throw InvalidRuleException();

		if( inState >= nStates_ )
			nStates_ = inState + 1;

		if( action.toState == S_UNCHANGED )
			action.toState = inState;
		else if( action.toState >= nStates_ )
			nStates_ = action.toState + 1;

		Rule r = { inState, input, action };
		rules_.push_back(r);
	}
Ejemplo n.º 10
0
//Creates an input box that allows the user to enter a string and returns it:
std::string inputBox()
{
    //Initialises the colour pairs:
    init_pair(4, COLOR_WHITE, COLOUR);
    init_pair(5, COLOR_WHITE, COLOR_RED);

    //Resize the input box:
    inputbox.width = screenX / 2;
    inputbox.height = screenY / 4;
    inputbox.x = ((screenX / 2) - (inputbox.width / 2));
    inputbox.y = ((screenY / 2) - (inputbox.height / 2));
    inputbox.window = newwin(inputbox.height, inputbox.width, inputbox.y, inputbox.x);

    //Set the background:
    wbkgd(inputbox.window, COLOR_PAIR(4));

    //The start position of the text entry box:
    unsigned int boxX = 2;
    unsigned int boxY = 2;
    unsigned int boxWidth = inputbox.width - 4;

    //The position of the buttons:
    unsigned int button1X = (inputbox.width / 4) - 2;
    unsigned int button2X = ((inputbox.width / 4) * 3) - 3;
    unsigned int buttonY = inputbox.height - 2;

    int input = 0, selection = 0;
    std::string inputStr = "";

    //The loop is indefinite, and ends when the user
    //presses '<OK>' or '<CANCEL>':
    while(1)
    {
        //Colours the text entry box red:
        mvwchgat(inputbox.window, boxX, boxY, boxWidth, A_NORMAL, 5, NULL);

        //Prints the text the user has entered:
        wattron(inputbox.window, COLOR_PAIR(5));
        mvwprintw(inputbox.window, boxY, boxX, "%s", inputStr.c_str());
        wattroff(inputbox.window, COLOR_PAIR(5));

        //Checks and highlights what area is currently selected:
        switch(selection)
        {
        //The text box:
        case 0:
            curs_set(1);
            mvwprintw(inputbox.window, buttonY, button1X, "%s", "<OK>");
            mvwprintw(inputbox.window, buttonY, button2X, "%s", "<CANCEL>");
            wmove(inputbox.window, boxY, (boxX + inputStr.size()));
            break;

        //The '<OK>' button:
        case 1:
            curs_set(0);
            wattron(inputbox.window, COLOR_PAIR(5));
            mvwprintw(inputbox.window, buttonY, button1X, "%s", "<OK>");
            wattroff(inputbox.window, COLOR_PAIR(5));
            mvwprintw(inputbox.window, buttonY, button2X, "%s", "<CANCEL>");
            break;

        //The '<CANCEL>' button:
        case 2:
            curs_set(0);
            wattron(inputbox.window, COLOR_PAIR(5));
            mvwprintw(inputbox.window, buttonY, button2X, "%s", "<CANCEL>");
            wattroff(inputbox.window, COLOR_PAIR(5));
            mvwprintw(inputbox.window, buttonY, button1X, "%s", "<OK>");
            break;
        }

        //Refreshes the inputbox:
        wrefresh(inputbox.window);

        //Gets the input to check for the Tab key:
        input = getch();

        //If the input is tab, change the selection:
        if(char(input) == '\t')
        {
            switch(selection)
            {
            case 0:
                selection = 1;
                break;
            case 1:
                selection = 2;
                break;
            case 2:
                selection = 0;
                break;
            default:
                selection = 0;
            }
        }
        //If the input is Enter, close the box and
        //return a value based on the selection:
        else if(char(input) == '\n')
        {
            switch(selection)
            {
            //The user has clicked '<OK>', return the
            //contents of the text box:
            case 1:
                wclear(inputbox.window);
                wrefresh(inputbox.window);
                if(inputStr.size() == 0) return NULL;
                else return inputStr;
                break;

            //The user has clicked '<CANCEL>', return
            //nothing:
            case 2:
                wclear(inputbox.window);
                wrefresh(inputbox.window);
                return "";
                break;
            }
        }
        //If the user has pressed backspace, attempt to delete some of the input:
        else if((input == KEY_BACKSPACE) || (input == KEY_DC))
        {
            //If we're editing the input, backspace deletes a character off the end:
            if((selection == 0) && (inputStr.length() > 0))
            {
                inputStr.erase(inputStr.length() - 1);

                //Clear the box and redraw it:
                wclear(inputbox.window);
                wbkgd(inputbox.window, COLOR_PAIR(4));
            }
        }
        else
            //Otherwise, check if the input is an alphanumeric character, and if so,
            //add it to the end of our input string:
            if(isValidInput(input) && (selection == 0))
                inputStr += input;
    }
}
Ejemplo n.º 11
0
StateID State::queryTransition(InputID input) const {
	assert(isValidInput(input));
	return _transitions.find(input)->second;
}
Ejemplo n.º 12
0
QString InputMask::maskString( uint pos, const QString &str, bool clear ) const
{
    if ( pos >= ( uint ) m_maxLength )
        return QString::fromLatin1( "" );

    QString fill;
    fill = clear ? clearString( 0, m_maxLength ) : m_text;

    uint strIndex = 0;
    QString s = QString::fromLatin1( "" );
    int i = pos;
    while ( i < m_maxLength )
    {
        if ( strIndex < str.length() )
        {
            if ( m_maskData[ i ].separator )
            {
                s += m_maskData[ i ].maskChar;
                if ( str[ ( int ) strIndex ] == m_maskData[ i ].maskChar )
                    strIndex++;
                ++i;
            }
            else
            {
                if ( isValidInput( str[ ( int ) strIndex ], m_maskData[ i ].maskChar ) )
                {
                    switch ( m_maskData[ i ].caseMode )
                    {
                    case MaskInputData::Upper:
                        s += str[ ( int ) strIndex ].upper();
                        break;
                    case MaskInputData::Lower:
                        s += str[ ( int ) strIndex ].lower();
                        break;
                    default:
                        s += str[ ( int ) strIndex ];
                    }
                    ++i;
                }
                else
                {
                    // search for separator first
                    int n = findInMask( i, TRUE, TRUE, str[ ( int ) strIndex ] );
                    if ( n != -1 )
                    {
                        if ( str.length() != 1 || i == 0 || ( i > 0 && ( !m_maskData[ i - 1 ].separator || m_maskData[ i - 1 ].maskChar != str[ ( int ) strIndex ] ) ) )
                        {
                            s += fill.mid( i, n - i + 1 );
                            i = n + 1; // update i to find + 1
                        }
                    }
                    else
                    {
                        // search for valid m_blank if not
                        n = findInMask( i, TRUE, FALSE, str[ ( int ) strIndex ] );
                        if ( n != -1 )
                        {
                            s += fill.mid( i, n - i );
                            switch ( m_maskData[ n ].caseMode )
                            {
                            case MaskInputData::Upper:
                                s += str[ ( int ) strIndex ].upper();
                                break;
                            case MaskInputData::Lower:
                                s += str[ ( int ) strIndex ].lower();
                                break;
                            default:
                                s += str[ ( int ) strIndex ];
                            }
                            i = n + 1; // updates i to find + 1
                        }
                    }
                }
                strIndex++;
            }
        }
        else
            break;
    }

    return s;
}
Ejemplo n.º 13
0
BOOL
IPv6rdIF_SetParamStringValue(
        ANSC_HANDLE hInsContext,
        char        *ParamName,
        char        *pString
        )
{
    PCOSA_CONTEXT_LINK_OBJECT       pLinkObject = (PCOSA_CONTEXT_LINK_OBJECT)hInsContext;
    PCOSA_DML_IPV6RD_IF             pEntry = (PCOSA_DML_IPV6RD_IF)pLinkObject->hContext;
    char v4addr[16];
    ULONG addlen;
    char tmp[128];
    ANSC_STATUS ret=ANSC_STATUS_FAILURE;

    if (!pLinkObject || !pEntry)
        return FALSE;

    if (AnscEqualString(ParamName, "Alias", TRUE))
    {
    char wrapped_inputparam[256]={0};
	ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam ));
	if(ANSC_STATUS_SUCCESS != ret)
	    return FALSE;

        AnscCopyString(pEntry->Alias, wrapped_inputparam);
        return TRUE;
    }
    else if (AnscEqualString(ParamName, "BorderRelayIPv4Addresses", TRUE))
    {
    char wrapped_inputparam[256]={0};
	ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam ));
	if(ANSC_STATUS_SUCCESS != ret)
	    return FALSE;
        AnscCopyString(pEntry->BorderRelayIPv4Addr, wrapped_inputparam);
        return TRUE;
    }
    else if (AnscEqualString(ParamName, "SPIPv6Prefix", TRUE))
    {
    char wrapped_inputparam[256]={0};
	ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam ));
	if(ANSC_STATUS_SUCCESS != ret)
	    return FALSE;

        AnscCopyString(pEntry->SPIPv6Prefix, wrapped_inputparam);
        return TRUE;
    }
    else if (AnscEqualString(ParamName, "AddressSource", TRUE))
    {
    char wrapped_inputparam[256]={0};
	ret=isValidInput(pString,wrapped_inputparam, AnscSizeOfString(pString), sizeof( wrapped_inputparam ));
	if(ANSC_STATUS_SUCCESS != ret)
	    return FALSE;

        if (( '\0' == wrapped_inputparam[ 0 ] ) || \
			( _ansc_strlen(wrapped_inputparam) == 0) 
		   )
        {
            AnscCopyString(pEntry->AddressSource, "");
            return TRUE;
        }

        addlen = sizeof(v4addr);
        _ansc_sprintf(tmp, "%sIPAddress", wrapped_inputparam);
        if (g_GetParamValueString(g_pDslhDmlAgent, tmp, v4addr, &addlen) != 0)
        {
            CcspTraceWarning(("IPv6rdIF_SetParamStringValue: fail to get %s\n", tmp));
            return FALSE;
        }

        AnscCopyString(pEntry->AddressSource, v4addr);
        /* AnscCopyString(pEntry->AddressSource, pString); */
        return TRUE;
    }

    return FALSE;
}