LOCAL PatternNode *copyPatternNode(PatternNode *patternNode, void *userData ) { PatternNode *newPatternNode; Errors error; assert(patternNode != NULL); UNUSED_VARIABLE(userData); // allocate pattern node newPatternNode = LIST_NEW_NODE(PatternNode); if (newPatternNode == NULL) { HALT_INSUFFICIENT_MEMORY(); } newPatternNode->string = String_duplicate(patternNode->string); // create pattern error = Pattern_init(&newPatternNode->pattern, patternNode->string, patternNode->pattern.type, patternNode->pattern.flags ); if (error != ERROR_NONE) { String_delete(newPatternNode->string); LIST_DELETE_NODE(newPatternNode); return NULL; } return newPatternNode; }
Errors EntryList_appendCString(EntryList *entryList, EntryTypes type, const char *pattern, PatternTypes patternType ) { EntryNode *entryNode; #if defined(PLATFORM_LINUX) #elif defined(PLATFORM_WINDOWS) String string; #endif /* PLATFORM_... */ Errors error; assert(entryList != NULL); assert(pattern != NULL); // allocate entry node entryNode = LIST_NEW_NODE(EntryNode); if (entryNode == NULL) { HALT_INSUFFICIENT_MEMORY(); } entryNode->type = type; entryNode->string = String_newCString(pattern); // init pattern #if defined(PLATFORM_LINUX) error = Pattern_initCString(&entryNode->pattern, pattern, patternType, PATTERN_FLAG_NONE ); #elif defined(PLATFORM_WINDOWS) // escape all '\' by '\\' string = String_newCString(pattern); String_replaceAllCString(string,STRING_BEGIN,"\\","\\\\"); error = Pattern_init(&entryNode->pattern, string, patternType, PATTERN_FLAG_IGNORE_CASE ); // free resources String_delete(string); #endif /* PLATFORM_... */ if (error != ERROR_NONE) { String_delete(entryNode->string); LIST_DELETE_NODE(entryNode); return error; } // add to list List_append(entryList,entryNode); return ERROR_NONE; }
autoPattern Pattern_create (long ny, long nx) { try { autoPattern me = Thing_new (Pattern); Pattern_init (me.get(), ny, nx); return me; } catch (MelderError) { Melder_throw (U"Pattern not created."); } }
LOCAL EntryNode *copyEntryNode(EntryNode *entryNode, void *userData ) { EntryNode *newEntryNode; #if defined(PLATFORM_LINUX) #elif defined(PLATFORM_WINDOWS) String string; #endif /* PLATFORM_... */ Errors error; assert(entryNode != NULL); UNUSED_VARIABLE(userData); // allocate entry node newEntryNode = LIST_NEW_NODE(EntryNode); if (newEntryNode == NULL) { HALT_INSUFFICIENT_MEMORY(); } // create entry newEntryNode->type = entryNode->type; newEntryNode->string = String_duplicate(entryNode->string); #if defined(PLATFORM_LINUX) error = Pattern_init(&newEntryNode->pattern, entryNode->string, entryNode->pattern.type, PATTERN_FLAG_NONE ); #elif defined(PLATFORM_WINDOWS) // escape all '\' by '\\' string = String_duplicate(entryNode->string); String_replaceAllCString(string,STRING_BEGIN,"\\","\\\\"); error = Pattern_init(&newEntryNode->pattern, string, entryNode->pattern.type|, PATTERN_FLAG_IGNORE_CASE ); // free resources String_delete(string); #endif /* PLATFORM_... */ if (error != ERROR_NONE) { String_delete(newEntryNode->string); LIST_DELETE_NODE(newEntryNode); return NULL; } return newEntryNode; }
Any Pattern_create (long ny, long nx) { Pattern me = Thing_new (Pattern); if (! me || ! Pattern_init (me, ny, nx)) forget (me); return me; }