Пример #1
0
int main(int argc, char **argv) {
    
    words = argv;
    word_count = argc;
    
    if (argc == 1)
        return EXIT_SUCCESS;
    
    // Set details and run basic test on all sentences
    if (!set_sentence_details()) {
        printf("Incorrect input\n");
        return EXIT_FAILURE;
    }
    
    // Process all sentences
    for (int i = 0; i < nb_of_sentences; ++i) {
    
        // Clear definition output before processing sentence
        for (int j = 0; j < MAX_DEF_LENGTH; ++j)
            definition[j] = '\0';
        
        if (!process_sentence(i)) {
            printf("Incorrect input\n");
            return EXIT_FAILURE;
        }
        
        char * this_definition = malloc(MAX_DEF_LENGTH * sizeof(char));
        strcpy(this_definition, definition);
        
        // Add definition to final output
        add_to_output(this_definition);
    }
    
    // Print out all definitions
    for (int i = 0; i < nb_of_output_definitions; ++i)
        printf("%s\n", output_definitions[i]);
    
    return EXIT_SUCCESS;
}
Пример #2
0
/// Processes the data read from the device.
///
/// @exception std::length_error Too many characters read for the sentence.
///   Maybe the end of line was missed or left out.
void nmea_reader::process_nmea()
{
	switch (raw) {
		case '\r':
			break;
		case '\n': // end of sentence
			process_sentence(sentence);
			sentence.clear();
			break;
		default:
			// ignore invalid characters. if this makes the sentence incomplete,
			// the sentence would have been invalid anyway. the result will be
			// an invalid sentence or a std::length_error.
			if ((raw <= 32) || (raw >= 127))
				return;

			if (sentence.size() > nmea::sentence::max_length)
				throw std::length_error{"sentence size to large. receiving NMEA data?"};
			sentence += raw;
			break;
	}
}