void doMiddle(struct cart *theCart)
/* Set up pretty web display and save cart in global. */
{
char *key = NULL;
char *file = NULL;

cart = theCart;

key = cartOptionalString(cart, "key");
if (isValidKey(key))
    {
    file = cartOptionalString(cart, "file");
    if(NULL == file)
        {
        printIndexFile();
        }
    else
        {
        printFile(file);
        }
    }
else
    {
    cartWebStart(theCart, database, "SECURE CGI \n");
    cartRemove(cart, "key");
    printf("INVALID KEY\n");
    cartWebEnd();
    }
}
Ejemplo n.º 2
0
/*! \brief Handle a note being released on our keyboard display
 *
 *  \param key the key being releassed
 */
void Piano::handleKeyRelease( int key )
{
	if( isValidKey( key ) )
	{
		m_midiEvProc->processInEvent( MidiEvent( MidiNoteOff, -1, key, 0 ) );
		m_pressedKeys[key] = false;
	}
}
bool IdToObjectMapBase::find(KeyType key, void** value) const {
    size_t slot = probeKeys(mKeys, mShift, key);
    if (!isValidKey(mKeys[slot])) {
        *value = NULL;
        return false;
    }
    *value = mValues[slot];
    return true;
}
Ejemplo n.º 4
0
/*! \brief Turn a key on or off
 *
 *  \param key the key number to change
 *  \param state the state to set the key to
 */
void Piano::setKeyState( int key, bool state )
{
	if( isValidKey( key ) )
	{
		m_pressedKeys[key] = state;

		emit dataChanged();
	}
}
Ejemplo n.º 5
0
void validateCLI(int argc, char *key) {
    if (argc != 2) {
        printf("Must supply a single key! Exiting.\n");
        exit(1);
    }
    if (!isValidKey(key)) {
        printf("Key cannot contain non-alphabetical characters! Exiting.\n");
        exit(1);
    }
}
void* IdToObjectMapBase::remove(KeyType key) {
    size_t slot = probeKeys(mKeys, mShift, key);
    if (!isValidKey(mKeys[slot]))
        return NULL;

    void* result = mValues[slot];
    mValues[slot] = NULL;
    mKeys[slot] = kTombstone;
    mCount--;
    return result;
}
Ejemplo n.º 7
0
/*! \brief Handle a note being pressed on our keyboard display
 *
 *  \param key the key being pressed
 */
void Piano::handleKeyPress( int key, int midiVelocity )
{
	if( midiVelocity == -1 )
	{
		midiVelocity = m_instrumentTrack->midiPort()->baseVelocity();
	}
	if( isValidKey( key ) )
	{
		m_midiEvProc->processInEvent( MidiEvent( MidiNoteOn, -1, key, midiVelocity ) );
		m_pressedKeys[key] = true;
	}
}
void IdToObjectMapBase::resize(size_t newSize) {
    int ret = capacityCompare(mShift, newSize);
    if (!ret)
        return;

    size_t oldCapacity = 1U << mShift;
    size_t newShift = mShift;

    if (ret < 0) {
        // Capacity is too small and must be increased.
        do {
            if (newShift == kMaxShift)
                break;
            ++newShift;
        } while (capacityCompare(newShift, newSize) < 0);
    } else {
        // Capacity is too large and must be decreased.
        do {
            if (newShift == kMinShift)
                break;
            newShift--;
        } while (capacityCompare(newShift, newSize) > 0);
    }
    if (newShift == mShift)
        return;

    // Allocate new arrays.
    size_t newCapacity = 1U << newShift;
    KeyType* newKeys = static_cast<KeyType*>(
            ::calloc(sizeof(newKeys[0]), newCapacity));
    void** newValues = static_cast<void**>(
            ::calloc(sizeof(newValues[0]), newCapacity));
    for (size_t n = 0; n < newCapacity; ++n)
        newKeys[n] = kInvalidKey;

    // Copy old entries into new arrays.
    for (size_t n = 0; n < oldCapacity; ++n) {
        KeyType key = mKeys[n];
        if (isValidKey(key)) {
            size_t newSlot = probeKeys(newKeys, newShift, key);
            newKeys[newSlot] = key;
            newValues[newSlot] = mValues[n];
        }
    }

    // Swap arrays, and get rid of old ones.
    ::free(mKeys);
    ::free(mValues);
    mKeys = newKeys;
    mValues = newValues;
    mShift = newShift;
}
Ejemplo n.º 9
0
int SimpleKey::ScanKey()
{
	int key;
	int resultKey = -1;

	key = pollingKey();

	switch (keystatus)
	{
	// 按键空闲状态
	case Key_Idle:
		if (isValidKey(key))
		{
			keystatus = Key_Debounce;
			keyBackup = key;
			timer.reset();
		}
		break;

		// 按键去抖中
	case Key_Debounce:
		if (key != keyBackup)
		{
			keystatus = Key_Idle;
		}
		else if (timer.read_ms() > KEY_DEBOUNCE)
		{
			// 去抖成功,发送按键按下键值;
			resultKey = keyBackup;
			keystatus = Key_Pressed;
		}
		break;

		// 等待按键松开
	case Key_Pressed:
		if (key == -1 || key != keyBackup)
		{
			keystatus = Key_Idle;
		}
		break;

	default:
		break;
	}
	return (resultKey);
}
void* IdToObjectMapBase::set(KeyType key, void* value) {
    if (!value)
        return remove(key);

    size_t slot = probeKeys(mKeys, mShift, key);
    void* result;
    if (isValidKey(mKeys[slot])) {
        result = mValues[slot];
        mValues[slot] = value;
    } else {
        mKeys[slot] = key;
        mValues[slot] = value;
        result = NULL;
        mCount++;
        resize(mCount);
    }
    return result;
}
Ejemplo n.º 11
0
/**
 * Generate string [--mode=MODE] or [-m MODE] from the given arguements.
 * The string will be preceded by a space.
 * @param arg Define the arguement to convert.
 * @param useShort Define if consider short arguement or long.
 * @return Return the usage string formatted as requested.
**/
std::string svutArgp::genUsageParam(const svutArgDef & arg,bool useShort) const
{
	stringstream res;

	if (useShort ==true && isValidKey(arg.key))
	{
		if (arg.valueType == "NONE")
			res << " [-" << arg.key << "]";
		else
			res << " [-" << arg.key << " " << arg.valueType << "]";
	} else if (useShort == false) {
		if (arg.valueType == "NONE")
			res << " [--" << arg.name << "]";
		else
			res << " [--" << arg.key << "=" << arg.valueType << "]";
	}

	return res.str();
}
Ejemplo n.º 12
0
/**
 * Generate and return the help string for the given arguement.
 * @param arg Define the arguement for wich to generate the help line.
 * @param columns Define the term width to consider for line splitting.
 * @return Return the generated string.
**/
string svutArgp::formatArgumentHelp(svutArgDef arg,int columns) const
{
	stringstream res;
	stringstream tmp;

	//setup keys mode
	bool hasShort = isValidKey(arg.key);
	bool hasLong = ! arg.name.empty();

	//base padding
	res << SVUT_HELP_BASE_PADDING;

	//short arg
	if (hasShort)
		res << '-' << arg.key;
	else
		res << "  ";

	//separator
	if (hasShort && hasLong)
		res << ", --";
	else
		res << "  --";

	//long name
	res.width(25);
	res.fill(' ');
	res.setf(ios::left);
	tmp << arg.name;
	if (arg.valueType != "NONE")
		tmp << '=' << arg.valueType;
	res << tmp.str();

	//description
	res << arg.descr;

	//cut lines on columns and return
	return breakLines(res.str(),columns,SVUT_HELP_PADDING);
}
Ejemplo n.º 13
0
void setDateTime(void)
{
	// keep track of LCD pos
	int row, col;
	row = 0;
	col = 2;
	// number is the number entered
	int number;
	// counter to keep track of how many digits entered
	int counter = 0;
	// number to keep track of the number so far
	int userInput = 0;
	char buf[1]; 
	do 
	{
		while(col < 10 || row != 1)
		{
			pos_lcd(row, col);
			number = get_key();
			if(isValidKey(number))
			{
				sprintf(buf, "%i", number);
				put_str_lcd(buf);
				wait_avr(400);

				if(col >= 11 && row == 0)
				{
					row++;
					col = 2;
				}
				else if(col <= 11)
				{
					col++;
					if(col == 4 || col == 7)
						col++;
				}
					
				counter++;
				if(counter%2 == 0 && counter != 6)
					userInput += number;
				else if(counter == 5)
					userInput = 1000*number;
				else if(counter == 6)
					userInput += 100*number;
				else if(counter == 7)
					userInput += 10*number;
				else 
					userInput = 10*number;
			
			}
			if(counter == 2)
				Month = userInput;
			else if(counter == 4)
				Day = userInput;
			else if(counter == 8)
				Year = userInput;
			else if(counter == 10)
				Hour = userInput;
			else if(counter == 12)
				Minutes = userInput;
			else if(counter == 14)
				Seconds = userInput;
		}
		if(!isValidDate(Day, Month, Year))
		{
			clr_lcd();
			sprintf(buf, "%s", "invalid date");
			put_str_lcd(buf);
			wait_avr(2000);
			row = 0;
			col = 2;

			// counter to keep track of how many digits entered
			counter = 0;
			// number to keep track of the number so far
			userInput = 0;
			resetLCD();
		}
	}while(!isValidDate(Day, Month, Year));


	while(1)
	{
		wait_avr(1000);
		incrementTime();
		pos_lcd(0, 2);
		sprintf(buf, "%02i/%02i/%02i", Month, Day, Year);
		put_str_lcd(buf);
		pos_lcd(1, 2);
		sprintf(buf, "%02i:%02i:%02i", Hour, Minutes, Seconds);
		put_str_lcd(buf);
	}	
}
Ejemplo n.º 14
0
bool PreferencesManager::isBuilderExtensionValueExist(const QString& PluginName, const QString& Key)
{
  QString GroupName = "openfluid.builder.extensions:"+PluginName;

  return isValidKey(GroupName,Key);
}