Example #1
0
void EventAddress::parseAddress (const ssi_char_t *address) {

    if (address == 0 || address[0] == '\0') {
        return;
    }

    size_t len = strlen (address);

    ssi_char_t *chunks[2];

    if (address[0] == '@') {
        chunks[0] = 0;
        chunks[1] = ssi_strcpy (address + 1);
    } else if (address[len-1] == '@') {
        chunks[0] = ssi_strcpy (address);
        chunks[0][len-1] = '\0';
        chunks[1] = 0;
    } else {
        ssi_size_t n_chunks = ssi_split_string_count (address, '@');
        if (n_chunks != 2) {
            ssi_wrn ("malformed event address '%s'", address);
            return;
        }
        ssi_split_string (2, chunks, address, '@');
    }

    parseNames (chunks[0], _n_events, &_events);
    parseNames (chunks[1], _n_sender, &_sender);

    delete[] chunks[0];
    delete[] chunks[1];
}
Example #2
0
/* Find all important data nodes in
 * this individual's GEDCOM sub-tree
 * @n = Individual's first child node
 */
void GIndiEntry::parseIndiData(GNode * n) {
    while (n) {
        // Name
        if (!_nameNode && n->type() == TYPE_NAME) {
            parseNames(n);
        }
        // Sex
        else if (!_sexNode && n->type() == TYPE_SEX) {
            _sexNode = n;
        }
        // Birth
        else if (!_birthDateNode && n->type() == TYPE_BIRTH) {
            parseBirth(n);
        }
        // Death
        else if (!_deathDateNode && n->type() == TYPE_DEATH) {
            parseDeath(n);
        }
        // Family (Child)
        else if (n->type() == TYPE_FAMC) {
            // Check adoption status
            GNode * m = n->firstChild();
            bool isAdoptiveFam = false;
            // Check other properties under family
            while (m) {
                if (m->type() == TYPE_PEDI && m->data() == PROP_ADOPTED) {
                    isAdoptiveFam = true;
                    break;
                }
                m = m->next();
            }
            // Prefer natural family in the family tree
            if (!_famcNode || !isAdoptiveFam) {
                _famcNode = n;
                _adopted = isAdoptiveFam;
            }
        }
        // Family (Parent)
        else if (n->type() == TYPE_FAMS) {
            // First marriage
            if (!_famsNode) {
                _famsNode = n;
            }
            // Second marriage
            else if (!_marriages) {
                _marriages = new QStringList();
                _marriages->append(_famsNode->data());
                _marriages->append(n->data());
            }
            // Third, fourth, ...
            else {
                _marriages->append(n->data());
            }
        }
        n = n->next();
    }
}
Example #3
0
long solution()
{
	long result = 0;
	auto names = parseNames(loadFile("problem22/names.txt"));
	std::sort(names.begin(), names.end());

	for(size_t pos = 0; pos < names.size(); ++pos)
		//+1 because 0-based array
		result += nameScore(pos+1, names.at(pos));
	
	return result;
}
Example #4
0
void Request::process(IRC *Connection)
{
	uint32_t i;
	switch (Command)
	{
		case RPL_MOTDSTART:
		case RPL_MOTD:
		case RPL_MOTDEND:
		case RPL_WELCOME:
		case RPL_YOURHOST:
		case RPL_CREATED:
			con->printf("%s\n", Parameters[1]);
			break;
		case CMD_NOTICE:
			con->printf("%s => %s\n", Parameters[0], Parameters[1]);
			break;
		case CMD_MESG:
			con->printf("%s: <%s> %s\n", Prefix, Parameters[0], Parameters[1]);
			handleMesg(Connection);
			break;
		case CMD_MODE:
			con->printf("Mode change for %s => ", Parameters[0]);
			for (i = 1; i < Parameters.size(); i++)
				con->printf("%s ", Parameters[i]);
			con->printf("\n");
			break;
		case RPL_TOPIC:
			con->printf("Topic for channel %s: %s\n", Parameters[1], Parameters[2]);
			break;
		case RPL_NAMEREPLY:
			con->printf("People on channel %s: %s\n", Parameters[Parameters.size() - 2], Parameters[Parameters.size() - 1]);
			parseNames();
			break;
		case CMD_QUIT:
			con->printf("%s has quit IRC: %s\n", Prefix, Parameters[0]);
			break;
		case RPL_INFO:
		case RPL_BOUNCE:
		{
			std::string msg;
			for (i = 1; i < Parameters.size(); i++)
				msg.append(Parameters[i]).append(" ");
			con->printf("%s\n", msg.c_str());
			break;
		}
		default:
			for (i = 0; i < Parameters.size(); i++)
				con->printf("%s ", Parameters[i]);
			con->printf("\n");
	}
}
Example #5
0
void loadSchemePack(uint32_t id, uint32_t loc) {
    ResHandle scheme = resource_get_handle(id);
    size_t len = resource_size(scheme);
    uint8_t* data = malloc(sizeof(uint8_t) * len);
    resource_load(scheme, data, len);
    pack = parseSchemePack(data);
    free(data);
    ResHandle loca = resource_get_handle(loc);
    len = resource_size(loca);
    data = malloc(sizeof(uint8_t) * len);
    resource_load(loca, data, len);
    pack->names = parseNames(data, &(pack->namesLen));
    free(data);
}
Example #6
0
void EventAddress::setEvents (const ssi_char_t *names) {
    parseNames (names, _n_events, &_events);
}
Example #7
0
void EventAddress::setSender (const ssi_char_t *names) {
    parseNames (names, _n_sender, &_sender);
}
/*
 Function: Reads discovered devices from UART and saves them into specific array.
 Returns: 
 Parameters: 
	inquiryTime: wait for module answer during this time.
	MAX_DEVICES: Maximum number of deviced to discover.
	name: Enables friendly name scan.
	limit: Enables limited scan.
 Values: 
*/
void  WaspBT_Pro::waitInquiryAnswer(long inquiryTime, uint16_t MAX_DEVICES, bool name, bool limited) 
{
	delay(100);
	char dummy[4];						// Keyword
	char block[BLOCK_SIZE+1];				// Block with MAC, CoD y RSSI
	char number[4];
	bool totalFound=false;
	char total[4];	
	total[3]='\0';
	int a;
		
	Utils.setLED(LED1, LED_ON);  // Inquiry while led on
    	
	long previous=millis();
	while( (millis()-previous<inquiryTime) && numberOfDevices < MAX_DEVICES ) 
	{
		for(uint8_t zz=0;zz<BLOCK_SIZE;zz++) block[zz]=' ';	// Clear array
	
		// Looks for keyword and save device.		
		if (serialAvailable(1))	{
			dummy[0]=serialRead(1);	
			if (dummy[0]=='I'){
				while(serialAvailable(1)<2);
				dummy[1]=serialRead(1);	
				if (dummy[1]=='A'){
					dummy[2]=serialRead(1);	
					if (dummy[2]=='L'){
						while(serialAvailable(1)<BLOCK_SIZE);
						for(uint8_t x=0;x<BLOCK_SIZE;x++) block[x]= serialRead(1);	
						// Saves device
						parseBlock(block);						
						numberOfDevices++;
						#ifdef DEBUG_MODE
						printBuffer2();
						#endif
					}
				}
			}
			// Search inquiry end
			if ((dummy[0]=='Y')&&(!totalFound)){ 
				while(serialAvailable(1)<2);
				dummy[1]=serialRead(1);	
				if (dummy[1]==' '){
					// If here, total found.
					totalFound=true;
					while(serialAvailable(1)<3);
					total[0]=serialRead(1);
					total[1]=serialRead(1);
					total[2]=serialRead(1);
				}
			}
		}

	// Condition to avoid an overflow (DO NOT REMOVE)
    	if( millis()-previous < 0 ) previous=millis();
	}
	#ifdef ENABLE_FRIENDLY_NAME
	// If name, parse names
	if (name) parseNames();
	#endif

	if (!limited){
		sprintf(number, "%02u", numberOfDevices);
		#ifdef DEBUG_MODE
		// Compare total of devices found and total of devices saved. 
		a = Utils.array2long(total);
		if (a!=numberOfDevices){
			USB.println("+Maybe dev lost+");
		}
			USB.print("inquiried:");
			USB.print(a);
			USB.print("; saved:");
			USB.println(number);
		#endif

		if(!(SD.append(INQFILE,TOTAL))){
			#ifdef DEBUG_MODE
			USB.print(ERRORSD1);
			#endif
		}
		if(!(SD.appendln(INQFILE,number))){
			#ifdef DEBUG_MODE
			USB.println(ERRORSD1);
			#endif
		}
	}
    	Utils.setLED(LED1, LED_OFF);  // Inquiry while led on
   	
}