コード例 #1
0
int main()
{
	for (size_t n = 0; n <= 10; ++n)
	{
		std::vector< std::string > parentheses = generate_parentheses(n);

		for (const std::string& str : parentheses)
		{
			assert(is_valid_string(str) == true);
		}

		std::cout << "passed tests for parentheses strings of length " << n << std::endl;
	}

	return 0;
}
コード例 #2
0
ファイル: text.c プロジェクト: GammaWatt/Pacman
void draw_text(SDL_Surface *surface, const char *text, int x, int y)
{
	if (!is_valid_string(text))
	{
		printf("The string contains invalid characters: %s\n", text);
		printf("aborting\n");
		exit(1);
	}

	SDL_Rect location;
	location.x = x;
	location.y = y;

	char c;

	while ((c = *text++))
	{
		SDL_Surface *charSurface = get_surface(c);

		SDL_BlitSurface(charSurface, NULL, surface, &location);
		location.x = location.x + charSurface->w;
	}
}
コード例 #3
0
ファイル: xspf.c プロジェクト: ivan-dives/audacious-plugins
static void xspf_add_node(xmlNodePtr node, TupleValueType type,
        gboolean isMeta, const gchar *xspfName, const gchar *strVal,
        const gint intVal)
{
    gchar tmps[64];
    xmlNodePtr tmp;

    if (isMeta) {
        tmp = xmlNewNode(NULL, (xmlChar *) "meta");
        xmlSetProp(tmp, (xmlChar *) "rel", (xmlChar *) xspfName);
    } else
        tmp = xmlNewNode(NULL, (xmlChar *) xspfName);

    switch (type) {
        case TUPLE_STRING:;
            gchar * subst;
            if (is_valid_string (strVal, & subst))
                xmlAddChild (tmp, xmlNewText ((xmlChar *) strVal));
            else
            {
                xmlAddChild (tmp, xmlNewText ((xmlChar *) subst));
                g_free (subst);
            }
            break;

        case TUPLE_INT:
            g_snprintf(tmps, sizeof(tmps), "%d", intVal);
            xmlAddChild(tmp, xmlNewText((xmlChar *) tmps));
            break;

        default:
            break;
    }

    xmlAddChild(node, tmp);
}
コード例 #4
0
ファイル: parser.c プロジェクト: raskanskyz/Assembler
/********************************************//**
 * Name:
 *  parse_line
 *
 * Params:
 *  *comp - A pointer to a compiler.
 *
 * Description:
 *  This function will parse the lines.
 *  it will is the standard libraries strtok() function
 *  to break the line in to tokens for further processing.
 *
 * Return:
 *  1 There was a problem parsing the line.
 *  0 The line was parsed successfully.
 *
 ***********************************************/
int parse_line(Compiler *comp) {

	//Create local copy of line so strtok() doesn't destroy the original.
	char *symbol = NULL;
	char *locLine = (char *) malloc(sizeof(char) * MAX_LINE_LEN);
	strcpy(locLine, comp->line);
	char *token = strtok(locLine, " \r\t\n");

	//Check if the line is empty, if it is stop the processing.
	if (token == NULL)
		return 0;

	//Check if the line is a comment, if it is stop the processing.
	if (strstr(token, ";") != NULL)
		return 0;

	//Check if optional label exists, if it does set symbol parameter, and get next token.
	if ((strstr(token, ":")) != NULL) {
		symbol = token;
		CUT_LAST_CHAR(symbol);
		token = strtok(NULL, " \r\t\n");
	}

	//Check if the line is .entry
	if (strstr(comp->line, ".entry") != NULL) {
		token = strtok(NULL, " \r\t\n");
		add_entry(comp, token);
		if (symbol != NULL)
			add_symbol(comp, symbol, DATA);
		return 0;
	}

	//Check if the line is .extern
	if (strstr(comp->line, ".extern") != NULL) {
		token = strtok(NULL, " \r\t\n");
		add_extern(comp, token);
		if (symbol != NULL)
			add_symbol(comp, symbol, DATA);
		return 0;
	}

	//Check if the line is .data
	if (strstr(comp->line, ".data") != NULL) {
		if (symbol != NULL)
			add_symbol(comp, symbol, DATA);
		token = strtok(NULL, " \r\t\n");
		add_data(comp, atoi(token));
		return 0;
	}

	//Check if the line is .string
	if (strstr(comp->line, ".string") != NULL) {
		if (symbol != NULL)
			add_symbol(comp, symbol, DATA);
		token = strtok(NULL, " \r\t\n");
		if (is_valid_string(token))
			add_string(comp, token);
		else
			add_error(comp, comp->fileName, comp->lineIdx, "Missing \"\n");
		return 0;
	}

	//if we got here the the line is code, if it has an optional symbol add it to symbol table.
	if (symbol != NULL)
		add_symbol(comp, symbol, CODE);

	//Add code to the compiler and check if the addition was successful.
	if (!add_code(comp, token, strtok(NULL, " \r\t\n"), strtok(NULL, ","))) {

		//Update the codeLen and dataLen fields
		comp->codeLen = comp->IC;
		comp->dataLen = comp->DC;
		free(locLine);
		return 0;
	}
	add_error(comp, comp->fileName, comp->lineIdx,
			"Incorrect line definition.");
	return 1;
}
コード例 #5
0
ファイル: html.c プロジェクト: hcrute/SHEMP-Firmware
void parse_http_request(uint8_t * request) {
	uint8_t ssid_error = FALSE;
	uint8_t pass_error = FALSE;
	uint8_t host_ip_error = FALSE;

	// First, have to parse it
	if(html_GET(temp_varchar, request, "SSID=")) {
		if(is_valid_string(temp_varchar)) {
			add_new_ssid(temp_varchar, strlen((char *)temp_varchar));
		} else {
			ssid_error = TRUE;
		}
	}
	if(html_GET(temp_varchar, request, "PASS="******"HOST="))  {
		if(is_valid_string(temp_varchar)) {
			if(number_of_characters_in_string(temp_varchar, '.') == 3) {
				// If the number of '.' in the host is equal to 3
				add_new_host_ip(temp_varchar, strlen((char *)temp_varchar));
			} else {
				add_new_host_name(temp_varchar, strlen((char *)temp_varchar));
			}

		} else {
			host_ip_error = TRUE;
		}
	}

	if(html_GET(temp_varchar, request, "reset=")) {
		reset_setup_info();
	}



	html_reset();

	// We use HTTP write instead of HTML write, because this is the HTTP header
	http_write((uint8_t *)http_header, STRLEN(http_header));

	// Had to be broken into multiple parts
	html_write((uint8_t *)html_header_01, STRLEN(html_header_01));
	html_write((uint8_t *)html_header_02, STRLEN(html_header_02));
	html_write((uint8_t *)html_header_03, STRLEN(html_header_03));


	if(have_new_ssid() && have_new_pass() && have_new_host_ip()) {
		html_write((uint8_t *)html_instructions_02, STRLEN(html_instructions_02));
	} else {
		html_write((uint8_t *)html_instructions_01, STRLEN(html_instructions_01));
	}

	if(get_number_of_slaves()) {
		html_write((uint8_t *)html_number_of_slaves_prefix, STRLEN(html_number_of_slaves_prefix));
		write_int_to_string(html_number_of_slaves_field,get_number_of_slaves()+1);
		html_write((uint8_t *)html_number_of_slaves_field, strlen((char *)html_number_of_slaves_field));
		html_write((uint8_t *)html_number_of_slaves_suffix, STRLEN(html_number_of_slaves_suffix));
	}


	// SSID Row
	html_write((uint8_t *)html_ssid_prefix, STRLEN(html_ssid_prefix));
	if(have_new_ssid()) {
		html_write((uint8_t *)get_new_ssid(), strlen((char *)get_new_ssid()));
	} else {
		html_write((uint8_t *)html_ssid_form, STRLEN(html_ssid_form));
		if(ssid_error) html_write((uint8_t *)html_input_error, STRLEN(html_input_error));
	}
	html_write((uint8_t *)html_ssid_suffix, STRLEN(html_ssid_suffix));



	// PASS Row
	html_write((uint8_t *)html_pass_prefix, STRLEN(html_pass_prefix));
	if(have_new_pass()) {
		html_write((uint8_t *)get_new_pass(), strlen((char *)get_new_pass()));
	} else {
		html_write((uint8_t *)html_pass_form, STRLEN(html_pass_form));
		if(pass_error) html_write((uint8_t *)html_input_error, STRLEN(html_input_error));
	}
	html_write((uint8_t *)html_pass_suffix, STRLEN(html_pass_suffix));


	// PASS Row
	html_write((uint8_t *)html_host_ip_prefix, STRLEN(html_host_ip_prefix));
	if(have_new_host_ip()) {
		html_write((uint8_t *)get_new_host_ip(), strlen((char *)get_new_host_ip()));
	} else if (have_new_host_name()) {
		html_write((uint8_t *)get_new_host_name(), strlen((char *)get_new_host_name()));
	} else {
		html_write((uint8_t *)html_host_ip_form, STRLEN(html_host_ip_form));
		if(host_ip_error) html_write((uint8_t *)html_input_error, STRLEN(html_input_error));
	}
	html_write((uint8_t *)html_host_ip_suffix, STRLEN(html_host_ip_suffix));

	if(have_new_ssid() && have_new_pass() && (have_new_host_ip() || have_new_host_name())) {
		complete_setup();
	} else {
		html_write((uint8_t *)html_submit_button, STRLEN(html_submit_button));
	}





	html_write((uint8_t *)html_footer, STRLEN(html_footer));

	html_send();

	return;
}