Beispiel #1
0
void Command::add(
		const char	*command_name,
		const char	*desc,
		bool		(* func_ptr)(u32, char **)
	)
{
	Command_t *e, *p, *n;
	u32 h;

	h = calculateStringHash(command_name) % RC_COMMAND_HASH_SIZE;

	e = command_hash[h];

	while (e) {

		if (strcmp(e->name, command_name) == 0) {
			remove(command_name);
			break;
		}

		e = (Command_t *) e->hash_next;
	}

	n = new Command_t;

	n->name = duplicateString(command_name);
	n->desc = duplicateString(desc);
	n->funcptr = func_ptr;
	n->hash_next = command_hash[h];
	n->list_next = 0;
	command_hash[h] = n;

	e = command_head;
	p = 0;

	while (e) {

		if (strcmp(e->name, command_name) > 0) {
			n->list_next = e;

			if (p) {
				p->list_next = n;
			} else {
				command_head = n;
			}

			return;
		}

		p = e;
		e = (Command_t *) e->list_next;
	}

	if (p) {
		p->list_next = n;
	} else {
		command_head = n;
	}

}
Beispiel #2
0
Resource* ResourceList::getResource(
		const char			*id
	)
{
	u32 hash = calculateStringHash(id);
	/* Check hash table for resource */
	u32 h = hash % length;

	Resource *c = list[h];

	while (c) {
		if (c->hash == hash && strcmp(c->identifier, id) == 0) {

			/* Object found */
			c->n_refs++;

			return c;
		}

		c = c->next;
	}

	/* The object was not found */

	return 0;
}
Beispiel #3
0
void Command::remove(
		const char	*command_name
	)
{
	Command_t *e, *p;
	u32 h = calculateStringHash(command_name) % RC_COMMAND_HASH_SIZE;

	e = command_hash[h];
	p = 0;

	while (e) {

		if (strcmp(e->name, command_name) == 0) {

			if (p) {
				p->hash_next = e->hash_next;
			} else {
				command_hash[h] = e->hash_next;
			}

			break;
		}

		p = e;
		e = e->hash_next;
	}

	e = command_head;
	p = 0;

	while (e) {

		if (strcmp(e->name, command_name) == 0) {

			if (p) {
				p->list_next = e->list_next;
			} else {
				command_head = e->list_next;
			}

			free(e->name);
			delete e;

			return;
		}

		p = e;
		e = e->list_next;
	}

}
Resource::Resource(
		const char				*nidentifier,
		u32						purge_level,
		ResourceType			rtype
	)
{
	if (!nidentifier || *nidentifier == 0)
		REPORT_WARNING("No resource identifier given");

	broken = false;

	next = 0;
	identifier = duplicateString(nidentifier);
	hash = calculateStringHash(identifier);

	purgeLevel = purge_level;

	type = rtype;
}
Beispiel #5
0
static void drawHandler(GL_PageControls_TypeDef* pThis, _Bool force)
{
	// Setup unlikely values to start
	static uint32_t lastOnAirHash = 0;
	static uint32_t lastTxHash = 0;
	static uint32_t lastKeyboardHash = 0;
	static uint32_t lastCallHash = 0;
	static uint32_t lastNameHash = 0;
	extern unsigned char NewChar;


//	uint32_t curOnAirHash = calculateStringHash((char*) LCD_buffer);
	uint32_t curTxHash = calculateStringHash(XmitBuffer);
	uint32_t curKeyboardHash = calculateStringHash((char*) kybd_string);
	uint32_t curCallHash = calculateStringHash(Get_Contact(0));
	uint32_t curNameHash = calculateStringHash(Get_Contact(1));

	// Redraw only when needed:
	//_Bool redrawTitle = force;
	_Bool redrawOnAirBuffer = force || NewChar != 0;
//	_Bool redrawOnAirBuffer = force || lastOnAirHash != curOnAirHash;
	_Bool redrawTxBuffer = force || lastTxHash != curTxHash;
	_Bool redrawKeyboardBuffer = force || lastKeyboardHash != curKeyboardHash;
	_Bool redrawCallBuffer = force || lastCallHash != curCallHash;
	_Bool redrawNameBuffer = force || lastNameHash != curNameHash;

	int x = pThis->objCoordinates.MinX;
	int y = pThis->objCoordinates.MinY;

	// Display title:
	//if (redrawTitle) {
	//	// Title
	//	GL_SetFont(FONT_TITLE);
	//	GL_SetTextColor(TITLE_COLOUR);
	//	GL_SetBackColor(TITLE_BACKGROUND);
	//	GL_PrintString(x + OFFSETX_TITLE, y + OFFSETY_TITLE, "Rx/Tx/Keyboard PSK Data:", 0);
//
	//}

	// Display Call
	if (redrawCallBuffer){
	GL_SetFont(GL_FONTOPTION_8x16);
	GL_SetBackColor(LCD_COLOR_BLACK);
	GL_SetTextColor(LCD_COLOR_WHITE);
	GL_PrintString(25, 170,Get_Contact(0), 0);
	lastCallHash = curCallHash;
	}

	//Display Name
	if (redrawNameBuffer) {
	GL_SetFont(GL_FONTOPTION_8x16);
	GL_SetBackColor(LCD_COLOR_BLACK);
	GL_SetTextColor(LCD_COLOR_WHITE);
	//GL_PrintString(175, 170,Get_Contact(1), 0);
	GL_PrintString(151, 170,Get_Contact(1), 0);
	lastNameHash = curNameHash;
	}
	// Display the on-air buffer
	// (Was previously displayed in main())
	GL_SetFont(FONT_DATA);
	GL_SetTextColor(DATA_COLOUR);
	GL_SetBackColor(DATA_BACKGROUND);
	if (redrawOnAirBuffer) {
		DisplayText (NewChar);
		NewChar = 0;
//		GL_PrintString(x + OFFSETX_ONAIR, y + OFFSETY_ONAIR, (char*) LCD_buffer, 0);
//		lastOnAirHash = curOnAirHash;
	}

	// Display the Queue
	if (redrawTxBuffer) {
		//GL_PrintString(x + OFFSETX_TX, y + OFFSETY_TX, XmitBuffer, 0);
		//lastTxHash = curTxHash;
	}

	// Display the keyboard buffer
	if (redrawKeyboardBuffer) {
		//GL_PrintString(x + OFFSETX_KEYBOARD, y + OFFSETY_KEYBOARD, (char*) kybd_string, 0);
		//lastKeyboardHash = curKeyboardHash;
	}
}
Beispiel #6
0
void Command::run(
		char		*str
	)
{
	char *p;
	char *orig = str;

//	static const char delim[] = " \t";
	u32 i, k, n_args;
//	char buf[RC_CONSOLE_MAX_LINE_WIDTH];
	char *cmd;
	char *argbuf[RC_COMMAND_MAX_ARGS]; /* Command + RC_CONSOLE_MAX_ARGS args */

	bool success = false;
	bool in_quotes = false;

	Command_t *e;
	u32 h, len;

#ifdef RC_LOG_FRENZY
	printf("Command: %s\n", str);
#endif

	while (*str && (*str == ' ' || *str == '\t'))
		str++;

	if (*str == '/') {
		str++;
	} else {
		Console::log(orig);
		return;
	}

	p = str;

	len = strlen(str);

	if (len == 0) {

		REPORT_WARNING("No command given");
		return;
	}

	Console::log(orig);

	k = 0;

	while (*p) {
		if (*p == ' ' || *p == '\t') {
			break;
		}

		p++;
		k++;
	}

	cmd = new char[k + 1];
	strncpy(cmd, str, k);
	cmd[k] = 0;

	/* Search for command */
	h = calculateStringHash(cmd) % RC_COMMAND_HASH_SIZE;

	e = command_hash[h];

	while (e) {
		if (strcmp(e->name, cmd) == 0) {
			break;
		}

		e = e->hash_next;
	}

	if (!e) {
		REPORT_WARNING("Command %s not found", cmd);
		return;
	}

	/* Parse arguments */
	str += k;

	i = 0;

	while (*str && *str != '\n' && *str != '\r' && i < RC_COMMAND_MAX_ARGS) {
		k = 0;
		in_quotes = false;

		while (*str && (*str == ' ' || *str == '\t'))
			str++;

		if (*str == '\"') {
			in_quotes = true;
			str++;
		}

		p = str;

		while (*p) {
			if ((*p == ' ' || *p == '\t') && !in_quotes) {
				break;
			} else if (*p == '\"' && in_quotes) {
				break;
			} else if (*p == 0) {
				break;
			}

			p++;
			k++;
		}

		argbuf[i] = new char[k + 1];
		strncpy(argbuf[i], str, k);
		argbuf[i][k] = 0;

		if (in_quotes)
			k++;

		str += k;
		i++;
	}

	n_args = i;

	success	= e->funcptr(n_args, argbuf);

	if (!success) {
		REPORT_WARNING("Command %s failed", cmd);
		Console::log("Usage: %s", e->desc);
	}

	delete cmd;

	for (i = 0; i < n_args; i++)
		delete argbuf[i];

}
    //--------------------------------------------------------------------
	GeneratedSaxParser::StringHash Utils::calculateStringHash( const ParserChar* text, bool& failed )
	{
		failed = false;
		return calculateStringHash(text);
	}