void SDLNet_UDP_AddSocket(SDLNet_SocketSet set, UDPsocket socket) { //fprintf(stderr, "SDLNet_UDP_AddSocket\n"); SocketSet_Impl* impl = ToImpl(set); UDPsocket_Impl** head = &impl->udp_sockets_head; UDPsocket_Impl** tail = &impl->udp_sockets_tail; SListAppend(head, tail, ToImpl(socket)); }
void SDLNet_UDP_Send(UDPsocket socket, int channel, UDPpacket* packet) { //fprintf(stderr, "SDLNet_UDP_Send (socket=%p, channel=%u, len=%u)\n", socket, channel, packet->len); if (channel < 0) { fprintf(stderr, "channel < 0 not supported!\n"); return; } // Send to the other channel. channel = (channel + 1) % 2; UDPsocket_Impl* impl = ToImpl(socket); UDPpacket** head = &impl->channels[channel].packet_head; UDPpacket** tail = &impl->channels[channel].packet_tail; SListAppend(head, tail, CopyPacket(packet)); }
void SingleLinkedList<T>::quickSort(){ Node *temp, *temp2; SingleLinkedList l1, l2; if (pHead == pTail) return; temp = pHead; pHead = pHead->pNext; while (pHead != NULL){ temp2 = pHead; if (temp2->data >= temp->data){ l1.addHead(temp2->data); removeHead(); } else{ l2.addHead(temp2->data); removeHead(); } } l1.quickSort(); l2.quickSort(); SListAppend(l1); addHead(temp->data); SListAppend2(l2); }
static void create_new_entry(SAddendum *addendum, s_erc *error) { SMap *features = NULL; SList *phones = NULL; int i; SObject *stringObject = NULL; S_CLR_ERR(error); /* create a word features map */ features = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Failed to create new 'SMapList' object")) goto quit_error; /* now create a phones list */ phones = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Failed to create new 'SListList' object")) goto quit_error; SMapSetObject(features, "phones", S_OBJECT(phones), error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Failed to initialize new 'SListList' object")) { S_DELETE(phones, "create_new_entry", error); goto quit_error; } /* add the phones to list */ for (i = 0; test_word_phones[i] != NULL; i++) { /* create a string object */ stringObject = SObjectSetString(test_word_phones[i], error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Call to \"SObjectSetString\" failed")) goto quit_error; /* add string object to list */ SListAppend(phones, stringObject, error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Call to \"SListAppend\" failed")) { S_DELETE(stringObject, "create_new_entry", error); goto quit_error; } } /* add entry to addendum */ S_ADDENDUM_CALL(addendum, add_word)(addendum, test_word, features, error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Call to method \"add_word\" failed")) goto quit_error; return; quit_error: if (features != NULL) S_DELETE(features, "create_new_entry", error); }
static void Run(const SUttProcessor *self, SUtterance *utt, s_erc *error) { SG2P *g2p = NULL; SLexicon *lexicon = NULL; SAddendum *addendum = NULL; SSyllabification *syllab = NULL; const SRelation *wordRel; SRelation *syllableRel = NULL; SRelation *sylStructRel = NULL; SRelation *segmentRel = NULL; SItem *wordItem; char *downcase_word; SList *phones; s_bool syllabified; SList *syllablesPhones; SItem *sylStructureWordItem; SItem *syllableItem; SItem *sylStructSylItem; SItem *segmentItem; SIterator *sylItr = NULL; SIterator *phoneItr = NULL; const SObject *phone; s_bool is_present; S_CLR_ERR(error); s_get_lexical_objects(self, utt, &g2p, &lexicon, &addendum, &syllab, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_get_lexical_objects\" failed")) goto quit_error; /* we require the word relation */ is_present = SUtteranceRelationIsPresent(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit_error; if (!is_present) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to find 'Word' relation in utterance"); goto quit_error; } wordRel = SUtteranceGetRelation(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceGetRelation\" failed")) goto quit_error; /* create relations */ syllableRel = SUtteranceNewRelation(utt, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; sylStructRel = SUtteranceNewRelation(utt, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; segmentRel = SUtteranceNewRelation(utt, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; /* start at the first item in the word relation, cast away * const, we want to add daughter items. * iterate over the word relation and fill in the * phones and the associated structure. */ wordItem = (SItem*)SRelationHead(wordRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; while (wordItem != NULL) { /* get word and downcase it */ downcase_word = s_strlwr(s_strdup(SItemGetName(wordItem, error), error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to down-case word item")) goto quit_error; if (downcase_word == NULL || s_strcmp(downcase_word, "", error) == 0) goto continue_cycle; phones = NULL; syllabified = FALSE; /* get phone sequence for word */ if (addendum != NULL) { phones = S_ADDENDUM_CALL(addendum, get_word)(addendum, downcase_word, NULL, &syllabified, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"get_word\" (SAddendum) failed")) goto quit_error; } if ((phones == NULL) && (lexicon != NULL)) { phones = S_LEXICON_CALL(lexicon, get_word)(lexicon, downcase_word, NULL, &syllabified, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"get_word\" (SLexicon) failed")) goto quit_error; } if ((phones == NULL) && (g2p != NULL)) { phones = S_G2P_CALL(g2p, apply)(g2p, downcase_word, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"apply\" (SG2P) failed")) goto quit_error; } if (phones == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get phone sequence for word '%s'", downcase_word); S_FREE(downcase_word); continue; } S_FREE(downcase_word); /* syllabify phone sequence */ if (syllabified == FALSE) { if (syllab != NULL) { syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab, wordItem, phones, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"syllabify\" failed")) goto quit_error; S_DELETE(phones, "Run", error); } else { syllablesPhones = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to create new 'SList' object")) goto quit_error; SListAppend(syllablesPhones, S_OBJECT(phones), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SListAppend\" failed")) goto quit_error; } } else syllablesPhones = (SList*)phones; /* create new syllable structure word item, shares content * with word item. */ sylStructureWordItem = SRelationAppend(sylStructRel, wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; /* iterate over syllables */ sylItr = S_ITERATOR_GET(syllablesPhones, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_ITERATOR_GET\" failed")) goto quit_error; while (sylItr != NULL) { /* new item in syllable relation */ syllableItem = SRelationAppend(syllableRel, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; SItemSetName(syllableItem, "syl", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetName\" failed")) goto quit_error; /* daughter of above item, but in SylStructure */ sylStructSylItem = SItemAddDaughter(sylStructureWordItem, syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAddDaughter\" failed")) goto quit_error; /* iterate over phones and add segments */ phoneItr = S_ITERATOR_GET((SList*)SIteratorObject(sylItr, error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_ITERATOR_GET/SIteratorObject\" failed")) goto quit_error; while (phoneItr != NULL) { phone = SIteratorObject(phoneItr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SIteratorObject\" failed")) goto quit_error; segmentItem = SRelationAppend(segmentRel, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; SItemSetName(segmentItem, SObjectGetString(phone, error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetName/SObjectGetString\" failed")) goto quit_error; SItemAddDaughter(sylStructSylItem, segmentItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAddDaughter\" failed")) goto quit_error; phoneItr = SIteratorNext(phoneItr); } sylItr = SIteratorNext(sylItr); } S_DELETE(syllablesPhones, "Run", error); continue_cycle: wordItem = SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } /* here all is OK */ return; /* error clean-up code */ quit_error: if (syllableRel != NULL) { SUtteranceDelRelation(utt, "Syllable", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (sylStructRel != NULL) { SUtteranceDelRelation(utt, "SylStructure", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (segmentRel != NULL) { SUtteranceDelRelation(utt, "Segment", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (sylItr != NULL) S_DELETE(sylItr, "Run", error); if (phoneItr != NULL) S_DELETE(phoneItr, "Run", error); self = NULL; }
static const SObject *MapPyValGet(const SMap *self, const char *key, s_erc *error) { SMapPy *pMap = (SMapPy*)self; PyObject *pKey; PyObject *pobject; SObject *tmp; S_CLR_ERR(error); S_CHECK_PY_MAP(pMap, "MapPyValGet"); pKey = s_set_pyobject_str(key, error); if (S_CHK_ERR(error, S_CONTERR, "MapPyValGet", "Call to \"s_set_pyobject_str\" failed")) return NULL; /* borrowed reference */ pobject = PyDict_GetItem(S_PY_DICT(pMap), pKey); if (pobject == NULL) { char *py_error = s_get_python_error_str(); if (py_error) { S_CTX_ERR(error, S_FAILURE, "MapPyValGet", "Call to \"PyObject_GetItem\" failed. Reported error: %s", py_error); S_FREE(py_error); } else { S_CTX_ERR(error, S_FAILURE, "MapPyValGet", "Call to \"PyObject_GetItem\" failed"); } /* decrement reference of pKey */ Py_XDECREF(pKey); return NULL; } /* decrement reference of pKey */ Py_XDECREF(pKey); /* convert to Speect object type */ tmp = s_pyobject_2_sobject(pobject, error); if (S_CHK_ERR(error, S_CONTERR, "MapPyValGet", "Call to \"s_pyobject_2_sobject\" failed")) return NULL; /* add to list of "const" objects */ SListAppend(pMap->staticObjects, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "MapPyValGet", "Call to \"SListAppend\" failed")) return NULL; return (const SObject*)tmp; /* for S_CHECK_PY_MAP */ failure: return NULL; }
int main(int argc, char **argv) { s_erc error = S_SUCCESS; /* the syllabification can be started from the voice */ const SVoice *voice = NULL; SRelation *wordRel = NULL; SUtterance *utt = NULL; SItem *wordItem = NULL; SList *phones = NULL; SList *syllablesPhones = NULL; char* buffer = NULL; size_t buffer_size = 0; ssize_t buffer_length = 0; /* Config type will handle the command line input */ struct Config config = {0}; SPCT_PRINT_AND_WAIT("parsing options, press ENTER\n"); parse_arguments(&argc, argv, &config); SPCT_PRINT_AND_WAIT("going to initialize speect, press ENTER\n"); /* * initialize speect */ error = speect_init(NULL); if (error != S_SUCCESS) { printf("Failed to initialize Speect\n"); return 1; } SPCT_PRINT_AND_WAIT("initialized speect, loading voice, press ENTER\n"); /* load voice */ voice = s_vm_load_voice(config.voicefile, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"s_vm_load_voice\" failed")) goto quit; SPCT_PRINT_AND_WAIT("loaded voice, doing syllabification, press ENTER\n"); const SUttProcessor *uttProc = SVoiceGetUttProc(voice, "LexLookup", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SVoiceGetUttProc\" failed")) goto quit; utt = S_NEW(SUtterance, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"S_NEW\" failed")) goto quit; /* Utterance initialization */ SUtteranceInit(&utt, voice, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SUtteranceInit\" failed")) goto quit; /* Create new relation */ wordRel = SUtteranceNewRelation(utt, "Word", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"NewRelation\" failed")) goto quit; wordItem = SRelationAppend(wordRel, NULL, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SRelationAppend\" failed")) goto quit; SItemSetName(wordItem, "", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SItemSetName\" failed")) goto quit; SPCT_PRINT_AND_WAIT("load syllabification function, press ENTER\n"); SSyllabification* syllab = (SSyllabification*)SVoiceGetData(voice , "syllabification", &error); if (syllab == NULL) { syllab = (SSyllabification*)SMapGetObjectDef(uttProc -> features , "_syll_func", NULL, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SMapGetObjectDef\" failed")) goto quit; } SPCT_PRINT_AND_WAIT("everything ready to perform syllabification, press ENTER\n"); char inter_buffer[MAX_PHONEME_LENGTH+1] = {0}; buffer_length = getline(&buffer, &buffer_size, stdin); while (buffer_length != -1) { phones = S_LIST(S_NEW(SListList, &error)); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"S_NEW\" failed")) goto quit; int j = 0; while (buffer[j] != '\0') { int k; int inter_buffer_c; if (!isspace(buffer[j])) { inter_buffer[0] = buffer[j]; k = j + 1; inter_buffer_c = 1; while (!isspace(buffer[k]) && inter_buffer_c < MAX_PHONEME_LENGTH) { inter_buffer[inter_buffer_c] = buffer[k]; inter_buffer_c++; k++; } j += (inter_buffer_c - 1); inter_buffer[inter_buffer_c] = '\0'; /* for each phoneme in the line, put it in 'ph' */ SObject* ph = SObjectSetString(inter_buffer, &error); /* then add ph to the phoneme list */ SListAppend(phones, ph, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SListAppend\" failed")) goto quit; } j++; } SPCT_PRINT_AND_WAIT("run syllabification on next phones string, press ENTER\n"); syllablesPhones = NULL; syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab, wordItem, phones, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"syllabify\" failed")) goto quit; /* PRINT LOOP */ uint32 k = 0; SIterator *itr_syllablesPhones = S_ITERATOR_GET(syllablesPhones, &error); if (S_CHK_ERR(&error, S_CONTERR, "Run", "Execution of \"S_ITERATOR_GET\" failed")) goto quit; size_t syllables_list_size = SListSize(syllablesPhones, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SListSize\" failed")) goto quit; while (itr_syllablesPhones != NULL) { const SList* syl_list = (const SList*) SIteratorObject(itr_syllablesPhones, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SIteratorObject\" failed")) goto quit; size_t syl_list_size = SListSize(syl_list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SListSize\" failed")) goto quit; uint32 l = 0; SIterator *itr_syl_list = S_ITERATOR_GET(syl_list, &error); while (itr_syl_list != NULL) { const SObject* ph = SIteratorObject(itr_syl_list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SIteratorObject\" failed")) goto quit; const char* phone_string = SObjectGetString(ph, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SObjectGetString\" failed")) goto quit; fprintf(stdout, "%s", phone_string); if (l < syl_list_size - 1){ fprintf(stdout, " "); } itr_syl_list = SIteratorNext(itr_syl_list); l++; } if (k < syllables_list_size - 1) { fprintf(stdout, " - "); } itr_syllablesPhones = SIteratorNext(itr_syllablesPhones); k++; } fprintf(stdout, "\n"); if (syllablesPhones != NULL) S_DELETE(syllablesPhones, "main", &error); if (phones != NULL) S_DELETE(phones, "main", &error); phones = NULL; buffer_length = getline(&buffer, &buffer_size, stdin); } quit: SPCT_PRINT_AND_WAIT("deleting iteration support structures, press ENTER\n"); if (buffer != NULL) free(buffer); if (phones != NULL) S_DELETE(phones, "main", &error); if (syllablesPhones != NULL) S_DELETE(syllablesPhones, "main", &error); SPCT_PRINT_AND_WAIT("deleting utterance, press ENTER\n"); if (utt != NULL) S_DELETE(utt, "main", &error); SPCT_PRINT_AND_WAIT("deleting voice, press ENTER\n"); if (voice != NULL) S_DELETE(voice, "main", &error); SPCT_PRINT_AND_WAIT("quitting speect, press ENTER\n"); /* * quit speect */ error = speect_quit(); if (error != S_SUCCESS) { printf("Call to 'speect_quit' failed\n"); return 1; } SPCT_PRINT_AND_WAIT("done, press ENTER\n"); return 0; }
static void read_g2p_rewrites_zeros(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error) { uint32 id; SList *tmpZeros; size_t list_size; SIterator *itr; s_bool container_exhausted; s_gzero *tmp; S_CLR_ERR(error); /* read S_G2PREWRITES_EBML_ZEROS container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"container\" failed")) return; /* create a temporary SList storage */ tmpZeros = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Failed to create new 'SList' object")) return; while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"container_at_end\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } if (container_exhausted) break; /* peek id */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"peek_id\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } switch(id) { case S_G2PREWRITES_EBML_ZEROS_SYMBOL: { char *symbol; symbol = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"read_utf8\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* put symbol in list */ SListAppend(tmpZeros, SObjectSetString(symbol, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListAppend\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_FREE(symbol); return; } S_FREE(symbol); break; } case S_G2PREWRITES_EBML_ZEROS_REPLACEMENT: { char *replacement; replacement = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"read_utf8\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* put replacement in list */ SListAppend(tmpZeros, SObjectSetString(replacement, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListAppend\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_FREE(replacement); return; } S_FREE(replacement); break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_g2p_rewrites_zeros", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"element_skip\" failed")) return; } } /* get list size */ list_size = SListSize(tmpZeros, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListSize\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* make sure it is divisible by 2 */ if (list_size%2 != 0) { S_CTX_ERR(error, S_FAILURE, "read_g2p_rewrites_zeros", "Number of read symbol/replacement zero's not divisible by 2"); S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* create zeros structure */ g2p->zeros = S_CALLOC(s_gzero, list_size + 1); if (g2p->zeros == NULL) { S_FTL_ERR(error, S_MEMERROR, "read_g2p_rewrites_zeros", "Failed to allocate memory for 's_gzero' object"); S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } itr = S_ITERATOR_GET(tmpZeros, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } tmp = g2p->zeros; while (itr != NULL) { const char *symbol; const char *replacement; symbol = SObjectGetString(SIteratorObject(itr, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SIteratorObject/SObjectGetString\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } tmp->symbol = s_strdup(symbol, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"s_strdup\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } itr = SIteratorNext(itr); if (itr == NULL) { S_CTX_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Expected replacement zero is NULL"); S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } replacement = SObjectGetString(SIteratorObject(itr, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListIterator/SObjectGetString\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } tmp->replacement = s_strdup(replacement, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"s_strdup\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } itr = SIteratorNext(itr); tmp++; } S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; }
static void read_g2p_rewrites_rules(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error) { uint32 id; s_bool container_exhausted; SList *graphemeRuleList = NULL; SG2PRewritesRule *rule = NULL; S_CLR_ERR(error); /* read S_G2PREWRITES_EBML_RULES_CONTAINER container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container\" failed")) return; /* create rules SMap */ g2p->rules = S_MAP(S_NEW(SMapHashTable, error)); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Failed to create new 'SMap' object")) return; /* 64 should be enough for graphemes */ SMapHashTableResize(S_MAPHASHTABLE(g2p->rules), 64, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Call to \"SMapHashTableResize\" failed")) { S_DELETE(g2p->rules, "read_g2p_rewrites_rules", error); return; } while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container_at_end\" failed")) return; if (container_exhausted) break; /* peek id */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"peek_id\" failed")) return; switch(id) { case S_G2PREWRITES_EBML_RULES_GRAPHEME: { char *grapheme; grapheme = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; /* create rule list for this grapheme */ graphemeRuleList = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Failed to create new 'SList' object")) return; /* add it to the rules SMap */ SMapSetObject(g2p->rules, grapheme, S_OBJECT(graphemeRuleList), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Call to \"SMapSetObject\" failed")) { S_DELETE(graphemeRuleList, "read_g2p_rewrites_rules", error); S_FREE(grapheme); return; } S_FREE(grapheme); break; } case S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER: { /* read S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container\" failed")) return; while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container_at_end\" failed")) return; if (container_exhausted) break; /* peek id */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"peek_id\" failed")) return; switch(id) { case S_G2PREWRITES_EBML_SINGLE_RULE_LEFT_CONTEXT: { /* elements are ordered so we create a rule here */ rule = S_NEW(SG2PRewritesRule, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Failed to create new 'SG2PRewritesRule' object")) return; /* add it to the list */ SListAppend(graphemeRuleList, S_OBJECT(rule), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Call to \"SListAppend\" failed")) { S_DELETE(rule, "read_g2p_rewrites_rules", error); return; } rule->left_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; break; } case S_G2PREWRITES_EBML_SINGLE_RULE_RIGHT_CONTEXT: { rule->right_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; break; } case S_G2PREWRITES_EBML_SINGLE_RULE_PHONEME: { rule->phone = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_g2p_rewrites_rules", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"element_skip\" failed")) return; } } break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_g2p_rewrites_rules", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"element_skip\" failed")) return; } } return; }
static void add_info(SList *info, float start, float end, const char *name, s_erc *error) { SList *itemList = NULL; SObject *tmp = NULL; S_CLR_ERR(error); itemList = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Failed to create new list for item info")) goto quit; tmp = SObjectSetFloat(start, error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SObjectSetFloat\" failed")) goto quit; SListAppend(itemList, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SListAppend\" failed")) goto quit; tmp = SObjectSetFloat(end, error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SObjectSetFloat\" failed")) goto quit; SListAppend(itemList, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SListAppend\" failed")) goto quit; tmp = SObjectSetString(name, error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SObjectSetString\" failed")) goto quit; SListAppend(itemList, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SListAppend\" failed")) goto quit; tmp = NULL; SListAppend(info, S_OBJECT(itemList), error); if (S_CHK_ERR(error, S_CONTERR, "add_info", "Call to \"SListAppend\" failed")) goto quit; itemList = NULL; quit: if (itemList != NULL) S_DELETE(itemList, "add_info", error); if (tmp != NULL) S_DELETE(tmp, "add_info", error); }