void pho_h_wrapper(sqlite3_context *ctx, int n_values, sqlite3_value **value) { // check for NULL values, return NULL if input string is NULL if(sqlite3_value_type(value[0]) == SQLITE_NULL) { sqlite3_result_null(ctx); return; } const unsigned char *str1 = sqlite3_value_text(value[0]); int str1len = strlen(str1) + 1; // save string length with(!) delimiter char *dest = (char*) R_alloc(sizeof(char), str1len); #ifdef DEBUG Rprintf("String: %s\n", str1); #endif int result; /* Cast removes const qualifier, avoids warning. This is okay because phonet does not write to first arg unless it is equal to the second */ result = phonet((unsigned char *) str1, dest, str1len, 1); /* throw error if phonet fails (result <0) */ if (result < 0) { sqlite3_result_error(ctx, "phonet() terminated with an error", -1); return; } #ifdef DEBUG Rprintf("Ergebnis von phonet(): %s\n", dest); #endif sqlite3_result_text(ctx, dest, -1, SQLITE_STATIC); }
void pho_h(char ** src, char ** dst, int * length) { int l=*length; for (;l--;) // count down from length-1 to 0 { int str_len=strlen(src[l]); dst[l]=(char *) R_alloc(sizeof(char),str_len+1); // allocate dst string phonet (src[l], dst[l], str_len+1, 1); } }
int main(int argc, char ** argv) { // Applying options Options options(argc, argv); // Creating the pool of phonemes PhonemePool pool(options.get_phoneme_file().c_str()); srand(options.get_seed()); if(options.get_help()) Options::print_help(); // make sure the phoneme file was successfully read if(!pool.read_success()) return 1; // Creating and Printing Phonets for(unsigned i_phonet = 0; i_phonet < options.get_num_words(); ++i_phonet) { std::cout << "=========={Phonet}" << std::endl; Phonet phonet(pool, options.get_min_length(), options.get_max_length()); std::cout << phonet << std::endl; if(options.get_pronunciation()) { std::cout << "----------[Pronunciation]" << std::endl; phonet.print_pronunciation(); std::cout << std::endl; } if(options.get_num_spellings() > 0) { std::cout << "----------[Spelling]" << std::endl; for(unsigned i_spelling = 0; i_spelling < options.get_num_spellings(); ++i_spelling) { phonet.print_spelling(); std::cout << std::endl; } } } return 0; }