Example #1
0
int solve(FILE *f) {
	SymbolTable *table = NULL;
	int i;
	
	table = createSymbolTable(makeDictionaryEntry, compareDictionaryEntry);
	getTableData(f, table);
	findWords(table);

	dropSymbolTable(table);
	return 0;
}
Example #2
0
int solve(FILE *f) {
	SymbolTable *table = NULL;
	int i;
	
	table = createSymbolTable(makeDomainEntry, compareDomainEntry);
	getTableData(f, table);
	do {
		findWords(table);
		printf("Do you want to continue?\n");
	} while(getContinueRequest() != 'N');

	dropSymbolTable(table);
	return 0;
}
Example #3
0
void PropertyManager::parsePerBlockProperties(BlockProperties& properties)
{
	luabridge::LuaRef perBlock = properties.luaRef["perBlock"];

	LuaTableData& perBlockLuaProperties = getTableData(perBlock);

	properties.perBlockProperties.reserve(perBlockLuaProperties.data.size());
	for (std::pair<luabridge::LuaRef, luabridge::LuaRef> r : perBlockLuaProperties.data)
	{
		//TODO: error checking.
		std::string key(r.first);	// name of the lua variable
		std::string value(r.second);// value of the lua variable
		unsigned pos = value.find("(");
		unsigned pos2 = value.find(")");
		std::string valueType = value.substr(0, pos); //value before ( and )
		std::string valueValue = value.substr(pos + 1, (pos2 - pos - 1)); //get value in between ( and )

		BlockPropertyValueType type;
		int defaultVal = NULL;
		// Get the default value
		// Parse all the different possible types
		if (valueType == LUA_INT_NAME)
		{
			type = BlockPropertyValueType::LUA_INT;
			defaultVal = std::atoi(valueValue.c_str());
			perBlock[key] = (int) defaultVal;
		}
		else if (valueType == LUA_BOOL_NAME)
		{
			type = BlockPropertyValueType::LUA_BOOL;
			defaultVal = (int) (valueValue == "true");
		}
		else if (valueType == LUA_FLOAT_NAME)
		{
			type = BlockPropertyValueType::LUA_FLOAT;
			float f = (float) atof(valueValue.c_str());
			defaultVal = *(int*) &f;
		}
		else
		{
			assert(false && "Unsupported type");
		}
		//printf("key: %s \n", key.c_str());

		properties.perBlockProperties.push_back(PerBlockProperty(key, r.second, type, defaultVal));
	}
}
Example #4
0
int main() {
    system("gpio load i2c");
    sqlite3 *database;
    sqlite3_open("database.sqlite", &database);
    wiringPiSetupGpio();
    mcp23017Setup(100, 0x20);
    getTableData(database);
    pinMode(22, OUTPUT);
    pinMode(101, OUTPUT);
    while (1) {
        digitalWrite(101, 1);
        digitalWrite(22, 1);
        delay(1000);
        digitalWrite(101, 0);
        digitalWrite(22, 0);
        delay(1000);
    }
}
Example #5
0
void PropertyManager::parseEvents(BlockProperties& properties)
{
	luabridge::LuaRef events = properties.luaRef["events"];
	LuaTableData eventList = getTableData(events);

	for (std::pair<luabridge::LuaRef, luabridge::LuaRef> e : eventList.data)
	{
		//TODO: check not nil etc.
		luabridge::LuaRef triggerRef = e.second["trigger"];
		std::string triggerStr = triggerRef;
		triggerStr.erase(std::remove_if(triggerStr.begin(), triggerStr.end(), isspace), triggerStr.end());	//remove all spaces

		int leftEnd;
		int rightBegin;
		EventEvaluator eval;
		int idx = 0;
		//find evaluator and left/right value string split points
		for (auto it = triggerStr.begin(); it != triggerStr.end(); ++it, ++idx)	
		{
			char c = *it;
			if (c == '>')
			{
				//check >=
				char next = *(it + 1);
				if (next == '=')
				{
					leftEnd = idx;
					eval = GREATEREQUALS;
					rightBegin = idx + 2;
					break;
				}
				else
				{
					leftEnd = idx;
					eval = GREATER;
					rightBegin = idx + 1;
					break;
				}
			}
			else if (c == '<')
			{
				//check <=
				char next = *(it + 1);
				if (next == '=')
				{
					leftEnd = idx;
					eval = LESSEQUALS;
					rightBegin = idx + 2;
					break;
				}
				else
				{
					leftEnd = idx;
					eval = LESS;
					rightBegin = idx + 1;
					break;
				}
			}
			else if (c == '=')
			{
				//check ==
				char next = *(it + 1);
				if (next == '=')
				{
					leftEnd = idx;
					eval = EQUAL;
					rightBegin = idx + 2;
					break;
				}
				else
				{
					assert(false && "invalid expression, did you type = instead of == ?");
					break;
				}
			}
		}

		std::string left = triggerStr.substr(0, leftEnd);
		std::string right = triggerStr.substr(rightBegin, triggerStr.size());

		BlockPropertyValue leftProp = parseBlockPropertyValue(left, properties);
		BlockPropertyValue rightProp = parseBlockPropertyValue(right, properties);
		
		luabridge::LuaRef eventRef = e.second["event"];
		BlockEventTrigger trigger(leftProp, rightProp, eval, eventRef);

#ifdef _DEBUG
		assert(rightProp.type != LUA_TICKCOUNTER && "Only left side of trigger may be a tickCount");	//TODO: fix?
		if (leftProp.type == LUA_TICKCOUNTER)
		{
			assert(eval == EQUAL && "tickCount may only use == expression");
			assert(rightProp.type == LUA_INT && "tickCount may only be compared with an integer type");
		}
#endif //_DEBUG

		properties.events.push_back(trigger);
		//printf("trigger: %i, %i, %i \n", trigger.left.type, trigger.right.type, trigger.eval);
	}
}