static void fixSelectionSpecification (ClassInfo *class1, int *n1, ClassInfo *class2, int *n2, ClassInfo *class3, int *n3) { /* * Function: * sort the specification pairs *class(i), *n(i) according to class name, with null classes at the end. * Postconditions: * if (*class2) !! *class1; * if (*class3) !! *class2; * (*class1) -> className <= (*class2) -> className <= (*class3) -> className; * Usage: * Called by praat_addAction () and praat_removeAction (). */ /* Fix unusual input bubblewise. */ if (! *class1 && *class2) { *class1 = *class2; *n1 = *n2; *class2 = nullptr; *n2 = 0; } if (! *class2 && *class3) { *class2 = *class3; *n2 = *n3; *class3 = nullptr; *n3 = 0; if (! *class1 && *class2) { *class1 = *class2; *n1 = *n2; *class2 = nullptr; *n2 = 0; } } /* Now: if *class3, then *class2, and if *class2, then *class1. * Bubble-sort the input by class name. */ if (*class2 && str32cmp ((*class1) -> className, (*class2) -> className) > 0) { ClassInfo helpClass1 = *class1; *class1 = *class2; *class2 = helpClass1; int helpN1 = *n1; *n1 = *n2; *n2 = helpN1; } if (*class3 && str32cmp ((*class2) -> className, (*class3) -> className) > 0) { ClassInfo helpClass2 = *class2; *class2 = *class3; *class3 = helpClass2; int helpN2 = *n2; *n2 = *n3; *n3 = helpN2; if (str32cmp ((*class1) -> className, (*class2) -> className) > 0) { ClassInfo helpClass1 = *class1; *class1 = *class2; *class2 = helpClass1; int helpN1 = *n1; *n1 = *n2; *n2 = helpN1; } } }
bool Melder_str32equ_firstCharacterCaseInsensitive (const char32 *string1, const char32 *string2) { if (string1 == NULL) string1 = U""; if (string2 == NULL) string2 = U""; if (*string1 == U'\0') return *string2 == U'\0'; if (*string1 == *string2) return ! str32cmp (string1 + 1, string2 + 1); if (sizeof (wchar_t) == 2) { if (*string1 > 65536 || *string2 > 65536) return false; if (towlower ((char16) *string1) != towlower ((char16) *string2)) return false; } else { if (towlower ((int32) *string1) != towlower ((int32) *string2)) return false; } return ! str32cmp (string1 + 1, string2 + 1); }
static void updateWidgets (CategoriesEditor me) { // all buttons except undo & redo long size = ( (Categories) my data)->size; bool insert = false, insertAtEnd = true, replace = false, remove = false; bool moveUp = false, moveDown = false; long posCount; autoNUMvector<long> posList (GuiList_getSelectedPositions (my list, & posCount), 1); if (posList.peek()) { long firstPos = posList[1], lastPos = posList[posCount]; bool contiguous = ( lastPos - firstPos + 1 == posCount ); moveUp = contiguous && firstPos > 1; moveDown = contiguous && lastPos < size; my position = firstPos; remove = true; replace = true; //insertAtEnd = false; if (posCount == 1) { insert = true; //if (posList[1] == size) insertAtEnd = true; if (size == 1 && ! str32cmp (CategoriesEditor_EMPTYLABEL, OrderedOfString_itemAtIndex_c ((OrderedOfString) my data, 1))) { remove = false; } } } GuiThing_setSensitive (my insert, insert); GuiThing_setSensitive (my insertAtEnd, insertAtEnd); GuiThing_setSensitive (my replace, replace); GuiThing_setSensitive (my remove, remove); GuiThing_setSensitive (my moveUp, moveUp); GuiThing_setSensitive (my moveDown, moveDown); if (my history) { updateUndoAndRedoMenuItems (me); } notifyNumberOfSelected (me); }
void structButtonEditor :: v_draw () { Graphics_clearWs (our graphics.get()); switch (show) { case 1: for (long i = 1, n = praat_getNumberOfMenuCommands (); i <= n; i ++) { Praat_Command cmd = praat_getMenuCommand (i); if (str32equ (cmd -> window, U"Objects")) drawMenuCommand (this, praat_getMenuCommand (i), i); } break; case 2: for (long i = 1, n = praat_getNumberOfMenuCommands (); i <= n; i ++) { Praat_Command cmd = praat_getMenuCommand (i); if (str32equ (cmd -> window, U"Picture")) drawMenuCommand (this, praat_getMenuCommand (i), i); } break; case 3: for (long i = 1, n = praat_getNumberOfMenuCommands (); i <= n; i ++) { Praat_Command cmd = praat_getMenuCommand (i); if (! str32equ (cmd -> window, U"Objects") && ! str32equ (cmd -> window, U"Picture")) drawMenuCommand (this, praat_getMenuCommand (i), i); } break; case 4: for (long i = 1, n = praat_getNumberOfActions (); i <= n; i ++) { Praat_Command cmd = praat_getAction (i); const char32 *klas = cmd -> class1 -> className; if (str32cmp (klas, U"N") < 0) drawAction (this, praat_getAction (i), i); } break; case 5: for (long i = 1, n = praat_getNumberOfActions (); i <= n; i ++) { Praat_Command cmd = praat_getAction (i); const char32 *klas = cmd -> class1 -> className; if (str32cmp (klas, U"N") >= 0) drawAction (this, praat_getAction (i), i); } break; } }
void Confusion_getFractionCorrect (Confusion me, double *fraction, long *numberOfCorrect) { *fraction = NUMundefined; *numberOfCorrect = -1; double c = 0.0, ct = 0.0; for (long i = 1; i <= my numberOfRows; i++) { for (long j = 1; j <= my numberOfColumns; j++) { if (! my rowLabels[i] || ! my columnLabels[j]) { return; } ct += my data[i][j]; if (str32cmp (my rowLabels[i], my columnLabels[j]) == 0) { c += my data[i][j]; } } } if (ct != 0.0) { *fraction = c / ct; } *numberOfCorrect = (long) floor (c); }
WordList Strings_to_WordList (Strings me) { try { long totalLength = 0; /* * Check whether the strings are generic and sorted. */ for (long i = 1; i <= my numberOfStrings; i ++) { char32 *string = my strings [i], *p; for (p = & string [0]; *p; p ++) { if (*p > 126) Melder_throw (U"String \"", string, U"\" not generic.\nPlease convert to backslash trigraphs first."); } if (i > 1 && str32cmp (my strings [i - 1], string) > 0) { Melder_throw (U"String \"", string, U"\" not sorted.\nPlease sort first."); } totalLength += str32len (string); } autoWordList thee = Thing_new (WordList); thy length = totalLength + my numberOfStrings; thy string = Melder_calloc (char32, thy length + 1); /* * Concatenate the strings into the word list. */ char32 *q = thy string; for (long i = 1; i <= my numberOfStrings; i ++) { long length = str32len (my strings [i]); str32cpy (q, my strings [i]); q += length; *q ++ = '\n'; } *q = U'\0'; Melder_assert (q - thy string == thy length); return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not converted to WordList."); } }
static int compare (SimpleString me, SimpleString thee) { return str32cmp (my string, thy string); }
int PairProbability_compare (PairProbability me, PairProbability thee) noexcept { return str32cmp (my string1, thy string1); }
int SimpleString_compare (SimpleString me, SimpleString thee) noexcept { return str32cmp (my string, thy string); }
int Melder_cmp (const char32 *string1, const char32 *string2) { if (string1 == NULL) string1 = U""; if (string2 == NULL) string2 = U""; return str32cmp (string1, string2); }
static int compare (PairProbability me, PairProbability thee) throw () { return str32cmp (my string1, thy string1); }